I'm using Java Advanced Imaging to read and write JPEG2000
images in java. When debugging in Intellij, I can view the BufferedImage
and see that it's transparent. So I can stack layers on top of each other. But when I write it to a file, the background is always black. Is it something I'm doing wrong? Or is it the writer that's the problem? Do I need to be doing something specific with the J2KImageWriteParam
regarding encoding etc? Unfortunately I'm fairly new to handling images programmatically, and there is little to no information or support for jpeg2000
that I can find.
BufferedImage image = ImageIO.read(new File("image.jp2"));
BufferedImage tmpImage = new BufferedImage(
image.getWidth(), image.getHeight(), BufferedImage.TYPE_4BYTE_ABGR_PRE
);
Graphics2D g = (Graphics2D) tmpImage.getGraphics();
g.setComposite(AlphaComposite.Clear);
g.fillRect(0, 0, image.getWidth(), image.getHeight());
g.setComposite(AlphaComposite.Src);
g.drawImage(image, 0, 0, null);
ImageIO.write(tmpImage, "jpeg2000", new File("outputImage.jp2"));
g.dispose();