Hi,
I would like to merge a 24-bit PNG with transparent areas on top of another
image.
I'm successful doing that with JAI, but not with Java 2D. The areas that are
supposed to be transparent in the PNG are not transparent on the merged
image.
It works in Java 2D when my top image is a 8-bit PNG or GIF file.
I'd prefer using Java 2D if I could get it to work somehow. Maybe it's not
possible?
With JAI:
-> I load the image with
javax.media.jai.PlanarImage src javax.media.jai.JAI.create("FileLoad",
"top.png");
-> Then I check how many bands it has
int bands = src.getNumBands();
-> and it returns 4; and when I merge it the transparent areas work fine
With Java 2D:
-> I load the image with
BufferedImage bi = javax.imageio.ImageIO.read(new java.io.File("top.png"));
-> Then I check how many bands it has
int bands = bi.getRaster().getNumBands();
-> and it returns 3! Where did the alpha channel go?
-> type of image:
bi.getType()
-> returns 0 = TYPE_CUSTOM, why is that, shouldn't it be TYPE_INT_ARGB?
bi.toString()
-> [EMAIL PROTECTED]:
type = 0
ColorModel: #pixelBits = 24 numComponents = 3 color space =
[EMAIL PROTECTED]
transparency = 1
has alpha = false
isAlphaPre = false
ByteInterleavedRaster: width = 300 height = 300 #numDataElements 3
dataOff[0] = 0
-> Then I merge the 2 images with
Graphics2D g = biBottom.createGraphics();
g.drawImage(biBottom, 0, 0, null);
Composite c = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f);
g.setComposite(c);
g.drawImage(bi, 0, 0, null);
-> and I tried (to force it being a 4 band image)
-> I load the image with
Image image = Toolkit.getDefaultToolkit().getImage("top.png");
BufferedImage bi = new BufferedImage(300,300, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = bi.createGraphics();
g.drawImage(image, 0, 0, null);
g.dispose();
-> Then I check how many bands it has
int bands = bi.getRaster().getNumBands();
-> and it returns 4, but the alpha channel doesn't seem to be correct. When
I merge the image the transparent areas become white.
-> and I also tried (to force it being a 4 band image)
-> I load the image with
BufferedImage bi = javax.imageio.ImageIO.read(new java.io.File("top.png"));
BufferedImage b = new BufferedImage( bi.getWidth(), bi.getHeight(),
BufferedImage.TYPE_INT_ARGB );
ColorConvertOp xformOp = new ColorConvertOp( null );
xformOp.filter( bi, b );
bi = b;
-> Then I check how many bands it has
int bands = bi.getRaster().getNumBands();
-> and it returns 4, but the alpha channel doesn't seem to be correct. When
I merge the image the transparent areas become white.
It seems to me that when I read in the PNG file using Java 2D the alpha
channel is missing. What am I doing wrong?
Thanks so much for any help,
Adelheid
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".