1. 程式人生 > >圖片壓縮時 某個 jpeg圖片 報錯 Unsupported Image Type

圖片壓縮時 某個 jpeg圖片 報錯 Unsupported Image Type

ImageIO.read 讀取某個圖片的時候報錯  Unsupported Image Type。

其他的同類型圖片沒問題。查詢發現是這樣的:預設的模式是CMYK模式(注意,這是給印刷機用的)。在影象-->模式中改為RGB模式才是顯示器用的

對應的網站:http://stackoverflow.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