Knowledge Base

Graphics.drawImage Is Not Printed Properly

Article ID: 183196

Article Last Modified on 12/1/2003


APPLIES TO


This article was previously published under Q183196

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: kbprint kbprogramming kbprb KB183196