Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6696292

Printing transformed images accuracy problems

    XMLWordPrintable

    Details

    • Subcomponent:
      2d
    • Resolved In Build:
      b28
    • CPU:
      x86
    • OS:
      windows_2000, windows_xp
    • Verification:
      Verified

      Backports

        Description

        FULL PRODUCT VERSION :
        java version "1.6.0_06"
        Java(TM) SE Runtime Environment (build 1.6.0_06-b02)
        Java HotSpot(TM) Client VM (build 10.0-b22, mixed mode, sharing)

        ADDITIONAL OS VERSION INFORMATION :
        Microsoft Windows XP Home Edition Version 2002 Service Pack 2

        EXTRA RELEVANT SYSTEM CONFIGURATION :
        Problem shows on multiple printers

        A DESCRIPTION OF THE PROBLEM :
        When printing an image using a transform that has non-integer scale factors, the resizing algorithm in JDK 1.6 distorts the image so that the output is not usable when image accuracy is important.

        This is especially evident when printing the image of a barcode. After printing, the image of the barcode is not recognizable by a barcode reader.

          From indirect evidence, it seems that the image is being transformed first to 72 DPI and then to the printer's native resolution (300 and 600 DPI in our test cases). When the image is downsampled and then upsampled, it will naturally cause unnecessary distortion in the output image.

        The problem is not present in JDK 1.4.2 and JDK 1.5.0, it seems that the image is resized directly to the output resolution.

        We tried using all permutations of rendering hints, with no success.

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        In a class that implements Printable:

        - Load a JPEG image of a barcode.
        - Create an AffineTransform object that has non-integer scaling factors. In our test case, we use "new AffineTransform (1.08, 0, 0, 0.648, 72, 72)"
        - Send the image to the printer using graphics.drawImage (img, xform, null).

        - We have a sample barcode image that can be used to test this.

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        The image should be transformed without loss of significant quality, results should be as good as JDK 1.4.2 and JDK 1.5.0.
        ACTUAL -
        The output image is distorted so that it is not recognized by a barcode reader.

        ERROR MESSAGES/STACK TRACES THAT OCCUR :
        No error message.

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        /*
         * Created on Apr 25, 2008
         *
         */
        package printJPEG;

        import java.awt.Graphics;
        import java.awt.Graphics2D;
        import java.awt.RenderingHints;
        import java.awt.geom.AffineTransform;
        import java.awt.image.BufferedImage;
        import java.awt.print.PageFormat;
        import java.awt.print.Printable;
        import java.awt.print.PrinterException;
        import java.awt.print.PrinterJob;
        import java.io.File;

        import javax.imageio.ImageIO;

        public class PrintJPEG implements Printable
        {
            public static void main (String [] args)
            {
                try
                {
                    // Print Java Version
                    System.out.println (System.getProperty("java.version"));

                    // Create printer job
                    PrinterJob pJob = PrinterJob.getPrinterJob();
                    pJob.setPrintable (new PrintJPEG());
                    pJob.print();
                }
                catch (Throwable t)
                {
                    t.printStackTrace();
                }
            }
            
            public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException
            {
                if (pageIndex == 0)
                {
                    Graphics2D g2d = (Graphics2D)graphics;
                    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
                    g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
                    g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
                    
                    try
                    {
                        // Load the JPEG image
                        BufferedImage jpegImage = ImageIO.read(new File ("c:\\test.jpg"));

                        AffineTransform xform = new AffineTransform (1.08, 0, 0, 0.648, 72, 72);
                        g2d.drawImage (jpegImage, xform, null);
                        
                        return Printable.PAGE_EXISTS;
                    }
                    catch (Throwable t)
                    {
                        throw new PrinterException ("Error printing JPEG: " + t.getMessage());
                    }
                }
                else
                {
                    return Printable.NO_SUCH_PAGE;
                }
            }
        }

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

        CUSTOMER SUBMITTED WORKAROUND :
        Have not been able to find a workaround.

        Release Regression From : 5.0
        The above release value was the last known release where this
        bug was not reproducible. Since then there has been a regression.

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                prr Philip Race
                Reporter:
                igor Igor Nekrestyanov (Inactive)
                Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: