JDK-4909439 : Printing of translucent images is at image resolution, not printer resolution.
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 1.4.1_04,1.4.2
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2000,windows_xp
  • CPU: x86
  • Submitted: 2003-08-20
  • Updated: 2006-03-02
  • Resolved: 2006-03-02
Related Reports
Duplicate :  
Description
Attached is a test case which prints out 3 lines of text over a semi-transparent PNG image. 

The printout shows clearly that the portion of text rendered over the image is different from the rest outside of the image.

GIF and JPG images are apparently not affected by this problem (not tested).

Comments
EVALUATION As part of fixing 6301927:Java 1.4.2 does not print labels of buttons when using Windows XP Style the code that redraws transparent images was changed to use a higher resolution, up to device resolution if memory thresholds aren't exceeded. So this problem should now be fixed and I am closing it as a dup of that other bug.
02-03-2006

WORK AROUND A workaround which involves the use of BufferedImage to redraw the image as an opaque image and send the opaque image to the printer has been identified. However, this will only work if text is rendered OVER the image. Anything underneath the image cannot show through (as it is now an opaque image). If the latter is the issue you may want to trigger raster printing Add the following code at the top of the print() method (caveat raster printing is slower : see bug 4314221 Printing using colors with alpha values is slow ) Graphics2D g2 = (Graphics2D)g; g2.translate(pageFormat.getImageableX(), pageFormat.getImageableY()); Color alphaWhite = new Color(255,255,255,1); g.setColor(alphaWhite); g.drawLine(0,0,1,1); // this MUST be within the imageable area this will draw an almost wholly transparent white pixel in the very top left corner and its JUST enough to trigger raster printing. This has the advantage you can do this only on pages that you know have translucent images so only those pages that really need it. The rest of the pages will print the normal (quicker) way ###@###.### 2003-09-25 ============================
25-09-2003

EVALUATION The image is "translucent" ie it has a full alpha channel - not just the simple bitmask transparency of a GIF. Text over translucent images (those with partially transparent pixels - ie NOT bitmask transparency) may be drawn at image resolution. This is the compromise of the work detailed in 4300123. The workaround is to take the image and redraw it as an opaque image and send the opaque image to the printer. I've attached a revised version of your program which does this and the results look perfect. This workaround is fine so long as you aren't expecting rendering UNDER the image to show through. Also its only necessary to do this for TRANSLUCENT images. ie all GIFS and JPEGS are fine, its just some PNG images that may have translucency. ###@###.### 2003-08-20 ============================
20-08-2003