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 :
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.
The output image is distorted so that it is not recognized by a barcode reader.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
No error message.
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
* Created on Apr 25, 2008
public class PrintJPEG implements Printable
public static void main (String  args)
// Print Java Version
// Create printer job
PrinterJob pJob = PrinterJob.getPrinterJob();
pJob.setPrintable (new PrintJPEG());
catch (Throwable t)
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException
if (pageIndex == 0)
Graphics2D g2d = (Graphics2D)graphics;
// 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);
catch (Throwable t)
throw new PrinterException ("Error printing JPEG: " + t.getMessage());
---------- 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.