Graphics.drawImage Is Not Printed Properly

ID: Q183196


The information in this article applies to:
  • Microsoft Internet Explorer for Windows 95
  • Microsoft Java Virtual Machine build 4.79.2339


SYMPTOMS

When you print a double-buffered Java program in Windows 95, the output is printed in black and white.


STATUS

Microsoft has confirmed this to be a problem in Internet Explorer 4.01 for Windows 95.


MORE INFORMATION

Steps to Reproduce

To reproduce this behavior, create an image, paint to the graphics object obtained from the Image.getGraphics()function, and then copy the image to the graphics object passed to public void print() by using Graphics.drawImage().

The following Java example reproduces this problem:

   import java.applet.Applet;
   import java.awt.*;

   public class PrintTest extends Applet
   {
       protected Color c[] = new Color[8];
       {
           c[0] = Color.blue;
           c[1] = Color.cyan;
           c[2] = Color.green;
           c[3] = Color.magenta;
           c[4] = Color.orange;
           c[5] = Color.pink;
           c[6] = Color.red;
           c[7] = Color.yellow;
       }

       public void paintDoubleBuffered(Graphics g)
       {
           Dimension d = getSize();
           Image i = createImage(d.width,d.height);
           Graphics tg = i.getGraphics();
           paintDirect(tg);
           g.drawImage(i,0,0,this);
       }

       public void paintDirect(Graphics g)
       {
           Dimension d = getSize();
           int yinc = (int)((float)d.height / (float)c.length + 0.5);
           for (int i = 0; i < c.length; i++) {
               g.setColor(c[i]);
               g.fillRect(0,i*yinc,d.width,yinc);
           }
       }

       public void paint(Graphics g)
       {
           paintDoubleBuffered(g);
       }

       public void print(Graphics g)
       {
         // to workaround:
           // uncomment the next line
         // comment the one after it

           //paintDirect(g);
           paintDoubleBuffered(g);
       }
   } 

Additional query words: msjava virtual machine applet

Keywords : kbprg kbprint msiew95
Version : WINDOWS:
Platform : WINDOWS
Issue type : kbprb


Last Reviewed: August 30, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.