图片压缩时 某个 jpeg图片 报错 Unsupported Image Type

时间:2021-08-12 21:23:24

ImageIO.read 读取某个图片的时候报错  Unsupported Image Type。

其他的同类型图片没问题。查询发现是这样的:默认的模式是CMYK模式(注意,这是给印刷机用的)。在图像-->模式中改为RGB模式才是显示器用的

对应的网站:http://*.com/questions/2408613/unable-to-read-jpeg-image-using-imageio-readfile-file 


最好的解决方案如下,采用 twelvemonkeys 的相关组件。代码不用任何修改


使用方法。

maven中加上对应的dependency,

web.xml中加上   

 <listener>
        <display-name>ImageIO service provider loader/unloader</display-name>
        <listener-class>com.twelvemonkeys.servlet.image.IIOProviderContextListener</listener-class>
    </listener>

Old post, but for future reference:

Inspired by this question and links found here, I've written a JPEGImageReader plugin for ImageIO that supports CMYK color models (both with original color model, or implicitly converted to RGB on read). The reader also does proper color conversion, using the ICC profile embedded in the JPEG stream, in contrast to other solutions mentioned here.

It's plain Java and does not require JAI. The source code and binary distributions is freely available atgithub.com/haraldk/TwelveMonkeys.

Once you have it installed, it allows you to read CMYK JPEGs using ImageIO.read(...) like this:

File cmykJPEGFile = new File(/*path*/);
BufferedImage image = ImageIO.read(cmykJPEGFile);

I.e.: In most cases, it's not necessary to modify your code.



参考其他网站:http://blog.csdn.net/shixing_11/article/details/6897871

http://www.doc88.com/p-58261301281.html


http://www.oschina.net/p/evathumber/similar_projects?lang=19&sort=time&p=1