Graphics.drawImage Is Not Printed Properly (183196)



The information in this article applies to:

  • Microsoft Internet Explorer 1.0 for Windows 95
  • Microsoft Internet Explorer 2.0 for Windows 95
  • Microsoft Internet Explorer 3.0 for Windows 95
  • Microsoft Internet Explorer 3.01 for Windows 95
  • Microsoft Internet Explorer 3.02 for Windows 95
  • Microsoft Internet Explorer 4.0 for Windows 95
  • Microsoft Internet Explorer 4.01 for Windows 95
  • Microsoft Internet Explorer 5.0 for Windows 95
  • Microsoft Internet Explorer 5.01 for Windows 95
  • Microsoft Internet Explorer 5.5 for Windows 95
  • Microsoft Internet Explorer 3.x for Windows 95
  • Microsoft Internet Explorer 4.x for Windows 95
  • Microsoft virtual machine

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);
       }
   }
				

Modification Type:MajorLast Reviewed:12/1/2003
Keywords:kbprb kbprint kbProgramming KB183196