-
Bug
-
Resolution: Fixed
-
P4
-
6
-
b17
-
x86
-
windows_vista
-
Verified
FULL PRODUCT VERSION :
java version "1.6.0_02"
Java(TM) SE Runtime Environment (build 1.6.0_02-b06)
Java HotSpot(TM) Client VM (build 1.6.0_02-b06, mixed mode)
A DESCRIPTION OF THE PROBLEM :
1.) printing a BufferedImage of type TYPE_INT_ARGB
This image will not print transparent. It will print a multiplied color value. You can see the effect if you comment out the line "writeRead( img );" If you comment in the line then the image will be save on disk as png and read. If you print the read-write image then the transparent is printing correctly. I see no difference between the both images. Both are BufferedImage. Both include the same image data. There is also no documentation on BufferedImage that I should use a specific type for using with printing.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
- Run the attached code
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Transparent image shows text behind
ACTUAL -
Text behind transparent image does not show
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.*;
import java.awt.image.BufferedImage;
import java.awt.print.*;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
//import com.inet.viewer.ViewerUtils;
public class TestPrintImage {
public static void main( String[] args ) {
try {
PrinterJob pj=PrinterJob.getPrinterJob();
pj.setPrintable(new MyPrintable());
//pj.print();
} catch (Exception ex) {
ex.printStackTrace();
}
}
static class MyPrintable implements Printable {
public int print( Graphics g, PageFormat pf, int pageIndex ) throws PrinterException{
if( pageIndex != 0 )
return NO_SUCH_PAGE;
Graphics2D g2 = (Graphics2D)g;
g2.translate( pf.getImageableX(), pf.getImageableY() );
g2.setRenderingHint( RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON );
g2.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
//g2.setRenderingHint( RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY );
g2.setFont( new Font( "SansSerif", Font.PLAIN, 12 ) );
g2.setColor( Color.BLACK );
g2.drawString( "This is text 1.", 0, 20 ); // under the image
BufferedImage img = new BufferedImage( 100, 100, BufferedImage.TYPE_INT_ARGB );
Graphics gImg = img.createGraphics();
gImg.setColor( new Color( 192, 192, 192, 80 ) );
gImg.fillRect( 0, 0, 100, 100 );
gImg.setColor( Color.BLACK );
gImg.drawRect( 0, 0, 99, 99 );
gImg.dispose();
try {
//img = writeRead( img );
g2.drawImage( img, 10, 0, 90, 90, null ); // draw the image
} catch( Exception e ) {
e.printStackTrace();
}
g2.drawString( "This is text 2.", 0, 50 ); // over the image
g2.drawString( "This is text 3.", 0, 200 ); // outsite the image
return PAGE_EXISTS;
}
}
static BufferedImage writeRead(BufferedImage img) throws Exception{
File file = File.createTempFile( "tmp", null );
ImageIO.write( img, "png", file );
img = ImageIO.read( file );
System.out.println(file.getParent());
//file.delete();
return img;
}
}
---------- END SOURCE ----------
java version "1.6.0_02"
Java(TM) SE Runtime Environment (build 1.6.0_02-b06)
Java HotSpot(TM) Client VM (build 1.6.0_02-b06, mixed mode)
A DESCRIPTION OF THE PROBLEM :
1.) printing a BufferedImage of type TYPE_INT_ARGB
This image will not print transparent. It will print a multiplied color value. You can see the effect if you comment out the line "writeRead( img );" If you comment in the line then the image will be save on disk as png and read. If you print the read-write image then the transparent is printing correctly. I see no difference between the both images. Both are BufferedImage. Both include the same image data. There is also no documentation on BufferedImage that I should use a specific type for using with printing.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
- Run the attached code
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Transparent image shows text behind
ACTUAL -
Text behind transparent image does not show
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.*;
import java.awt.image.BufferedImage;
import java.awt.print.*;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
//import com.inet.viewer.ViewerUtils;
public class TestPrintImage {
public static void main( String[] args ) {
try {
PrinterJob pj=PrinterJob.getPrinterJob();
pj.setPrintable(new MyPrintable());
//pj.print();
} catch (Exception ex) {
ex.printStackTrace();
}
}
static class MyPrintable implements Printable {
public int print( Graphics g, PageFormat pf, int pageIndex ) throws PrinterException{
if( pageIndex != 0 )
return NO_SUCH_PAGE;
Graphics2D g2 = (Graphics2D)g;
g2.translate( pf.getImageableX(), pf.getImageableY() );
g2.setRenderingHint( RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON );
g2.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
//g2.setRenderingHint( RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY );
g2.setFont( new Font( "SansSerif", Font.PLAIN, 12 ) );
g2.setColor( Color.BLACK );
g2.drawString( "This is text 1.", 0, 20 ); // under the image
BufferedImage img = new BufferedImage( 100, 100, BufferedImage.TYPE_INT_ARGB );
Graphics gImg = img.createGraphics();
gImg.setColor( new Color( 192, 192, 192, 80 ) );
gImg.fillRect( 0, 0, 100, 100 );
gImg.setColor( Color.BLACK );
gImg.drawRect( 0, 0, 99, 99 );
gImg.dispose();
try {
//img = writeRead( img );
g2.drawImage( img, 10, 0, 90, 90, null ); // draw the image
} catch( Exception e ) {
e.printStackTrace();
}
g2.drawString( "This is text 2.", 0, 50 ); // over the image
g2.drawString( "This is text 3.", 0, 200 ); // outsite the image
return PAGE_EXISTS;
}
}
static BufferedImage writeRead(BufferedImage img) throws Exception{
File file = File.createTempFile( "tmp", null );
ImageIO.write( img, "png", file );
img = ImageIO.read( file );
System.out.println(file.getParent());
//file.delete();
return img;
}
}
---------- END SOURCE ----------