Saving PNG: Specify bit-depth and resolution
Posted on 2004-03-21
I'm trying to figure out how to save images. I read in files, create a cropped image and write it out, but the file-size of the result is larger than the original!
This turns out to be because the original bit depth is changed (1 to 24). I see no apparent way of specifying the bit depth of the written image. Also, the resolution changes from 300 dpi to 150, which is a bad thing in this case. I currently use
ImageIO.write(img, "png", file);
to write the image where img is a BufferedImage and file is a File.
I have no problems with downloading packages from Sun or elsewhere.
Certainly, I'd be interested in having the possibility of specifying custom bit depths and resolutions, but a solution to this specific "bit depth: 1 and resolution: 300 dpi"-problem is appreciated and 'enough' for getting the points. :-)