Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

Graphics.drawImage Is Not Printed Properly


View products that this article applies to.

This article was previously published under Q183196

↑ Back to the top


Symptoms

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

↑ Back to the top


Status

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

↑ Back to the top


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

↑ Back to the top


Keywords: kbprb, kbprint, kbprogramming, KB183196

↑ Back to the top

Article Info
Article ID : 183196
Revision : 3
Created on : 12/1/2003
Published on : 12/1/2003
Exists online : False
Views : 496