I’m trying to save this image to disk in correct format but not able to find the correct way of doing it in Java2D and using ImageIO to write the image to disk.
If you have used photoshop you can use “save for web…” and save image as PNG24 or PNG8. I want to save it as PNG8 so that the output image looks like this:
http://gamadu.com/temp/epg/example1.png
and not like this:
http://gamadu.com/temp/epg/example2.png
I do not want translucency. I want translucent pixels to have a black matte.
Here’s roughly what I am currently doing:
BufferedImage image= new BufferedImage(width, height, BufferedImage.BITMASK);
// do image editing.
// flush.
ImageIO.write(image, "PNG", targetImageFile);
This however saves the image as translucent, although BITMASK clearly states that transparency is either 1 or 0.
So, I tried to use BufferedImage.TYPE_BYTE_INDEXED, but the problem with that is that the background color ends up black and not transparent!
What’s the right way to create and save an image as PNG8?