使用JAI压缩GIF图像

时间:2014-07-07 11:28:02

标签: compression gif javax.imageio jai

Original GIF Image Output GIF Image

我正在使用JAI(image-io)压缩图像。当我为GIF图像做的时候,有时压缩GIF图像尺寸比原始图像更多。

BufferedImage image = ImageIO.read(fileObject);
 File compressedImageFile = new File("compressed-"+destination.getName());
              OutputStream os =new FileOutputStream(compressedImageFile);
final ImageOutputStream ios = ImageIO.createImageOutputStream(os);
final ImageWriter gifWriter = new GIFImageWriter(gifSPI);
final ImageWriteParam iwp = gifWriter.getDefaultWriteParam();
iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
iwp.setCompressionType(compression);
iwp.setCompressionQuality(compressionRate);

gifWriter.setOutput(ios);
gifWriter.write(null, new IIOImage(image, null, null), iwp);
System.out.println("After Compression in GIF WRITER >>>>>>> " + ios.length()/1024 );      
ios.flush();
gifWriter.dispose()

有什么想法吗?

0 个答案:

没有答案