开发者

Error with setCompressionType

Is there someone that can help to correct this code?

I'm working with JAI and I'm trying to compress JPG file to Losse-less here's my code

     `ImageWriter writer= (JPEGImageWriter) ImageIO.getImageWritersByFormatName("jpeg").next();
     javax.imageio.plugins.jpeg.JPEGImageWriteParam param = (JPEGImageWriteParam)                  
     writer.getDefaultWriteParam();
     param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
     param.setCompressionType("JPEG-LOSSLESS");`

It's always error in this part 开发者_JAVA技巧 param.setCompressionType("JPEG-LOSSLESS"); the error is java.lang.IllegalArgumentException: Unknown compression type! at javax.imageio.ImageWriteParam.setCompressionType(ImageWriteParam.java:1023)


You can only use compression types that are supported. Check which are supported by param.getCompressionTypes().

Other then that, try this code (using newer jpeg lossless standard JPEG-LS):

ImageWriter writer = 
    (ImageWriter) ImageIO.getImageWritersByFormatName("jpeg").next();
ImageWriteParam param= writer.getDefaultWriteParam();
param.setCompressionMode(param.MODE_EXPLICIT);
param.setCompressionType("JPEG-LS");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜