JDK-4941225 : drawImage to a printer under Windows 2000, 16bpp messes up image
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 1.4.2
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2003-10-21
  • Updated: 2003-10-21
  • Resolved: 2003-10-21
Related Reports
Duplicate :  
Relates :  
Description

Name: rl43681			Date: 10/21/2003


FULL PRODUCT VERSION :
java version "1.4.2_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_01-b06)
Java HotSpot(TM) Client VM (build 1.4.2_01-b06, mixed mode)

FULL OS VERSION :
Microsoft Windows 2000 [Version 5.00.2195]

EXTRA RELEVANT SYSTEM CONFIGURATION :
The system is running in 16bpp. This bug does not occur if the system is running in 32bpp

A DESCRIPTION OF THE PROBLEM :
Under Windows 2000, 16bpp, when performing a drawImage to the printer Graphics object, certain colors do not show up (including black).  Specifically colors in the image without a positive blue component do not print. Switching to 32bpp is a workaround, but of course many clients do not have video cards supporting 32bpp. This is not related to the type of the original image.

This bug seems almost identical to bug 4386065, which is marked closed.



STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
javac PrintImageTest.java
java PrintImageTest

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
A printout consisting of a series of concentric square representing (from the outside inward) red, green, blue, yellow, cyan, magenta, white, and a black block in the center. A black box surrounds the outer square.  (My printer is black and white.)
ACTUAL -
A printout consisting of a series of concentric squares. However, the red, green, yellow, and black squares print as white.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
// The "PrintImageTest" class.

// If the program is running on Windows 2000 and 16bpp,
// the printed image will be missing the red, green, yellow,
// and black colors in the printed image.  Note it does scale
// properly into the Canvas.

import java.awt.*;
import java.awt.event.*;
import java.awt.print.*;
import java.text.*;
import java.util.*;

public class PrintImageTest extends Frame
{
    MyCanvas c;

    public PrintImageTest ()
    {
        super ("PrintImageTest");

        // Create the image
        c = new MyCanvas ();
        Button b = new Button ("Print The Image");
        b.addActionListener (c);
        add ("North", b);
        add ("South", c);
        pack ();
        show ();
    } // PrintImageTest constructor


    public static void main (String[] args)
    {
        new PrintImageTest ();
    } // main method
} // PrintImageTest class

class MyCanvas extends Canvas implements ActionListener, Printable
{
    Image img;

    public MyCanvas ()
    {
        setSize (400, 400);
    } // MyCanvas constructor


    public void addNotify ()
    {
        super.addNotify ();
        img = createImage (100, 100);
        Graphics g = img.getGraphics ();
        g.setColor (new Color (255, 0, 0));
        g.fillRect (0, 0, 100, 100);
        g.setColor (new Color (0, 255, 0));
        g.fillRect (5, 5, 90, 90);
        g.setColor (new Color (0, 0, 255));
        g.fillRect (10, 10, 80, 80);
        g.setColor (new Color (255, 255, 0));
        g.fillRect (15, 15, 70, 70);
        g.setColor (new Color (0, 255, 255));
        g.fillRect (20, 20, 60, 60);
        g.setColor (new Color (255, 0, 255));
        g.fillRect (25, 25, 50, 50);
        g.setColor (new Color (255, 255, 255));
        g.fillRect (30, 30, 40, 40);
        g.setColor (new Color (0, 0, 0));
        g.fillRect (35, 35, 30, 30);
    } // addNotify method


    public void paint (Graphics g)
    {
        // Draw the image scaled to the screen
        g.drawImage (img, 0, 0, 400, 400, this);
    } // paint method


    public void actionPerformed (ActionEvent e)
    {
        // Print the image
        PrinterJob printerJob = PrinterJob.getPrinterJob ();
        Book book = new Book ();
        book.append (this, new PageFormat ());
        printerJob.setPageable (book);
        if (!printerJob.printDialog ())
        {
            return;
        }

        try
        {
            printerJob.print ();
        }
        catch (PrinterException exception)
        {
            System.err.println ("Printing error: " + exception);
        }
    } // actionPerformed method


    public int print (Graphics g, PageFormat format, int pageIndex)
    {
        if (pageIndex > 0)
        {
            return Printable.NO_SUCH_PAGE;
        }

        int left = (int) format.getImageableX ();
        int top = (int) format.getImageableY ();

        // Draw the image
        g.drawImage (img, left, top, (int) format.getImageableWidth (),
                (int) format.getImageableWidth (), this);
                
        // Draw a rect around the image
        g.drawRect (left, top, (int) format.getImageableWidth (),
                (int) format.getImageableWidth ());
                
        return Printable.PAGE_EXISTS;
    } // print method
} // MyCanvas class

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Switch to 32bpp causes the printout to occur correctly.

I have not yet found Java code that will workaround this problem.
(Incident Review ID: 216962) 
======================================================================

Comments
EVALUATION Fixed in Tiger b22 as part of fixing 4886732. See also 4733565. ###@###.### 2003-10-21 ===================================
21-10-2003