一,参考资料
PNG结构说明 http://homepage2.nifty.com/sophia0/png.html
JavaSample http://www.java.net/node/707282
JavaSource http://www.docjar.com/html/api/com/sun/imageio/plugins/png/PNGMetadata.java.html
二,JavaSample
private void writeImageLocal(final String fileName, final BufferedImage image) throws Exception {
if (fileName == null || "".equals(fileName.trim())) {
throw new Exception("fileName is null or empty");
}
if (image == null) {
throw new Exception("BufferedImage is null");
}
PNGMetadata png = new PNGMetadata();
png.bKGD_present = true;
png.bKGD_colorType = 2;
png.bKGD_red = 123;
png.bKGD_green = 123;
png.bKGD_blue = 123;
IIOImage iioImage = new IIOImage(image, null, png);
ImageWriter writer = ImageIO.getImageWritersByFormatName("png").next();
writer.setOutput(ImageIO.createImageOutputStream(new File(fileName)));
writer.write(iioImage);
writer.dispose();
}
三,链接中有一个查看PNG结构的工具。
// END
分享到:
评论