我遇到这样的问题。(jdk1.4.2_07)
查了资料,好像说是JDK的BUG,难道就没有办法了?
jpg:http://member.ycn.com/~emu/keiler16.jpg
public class MyTest {
public static void main(String[] args) throws IOException {
File  im_filenew = new File("C:/eclipse/workspace/keiler16.jpg");  //请用绝对路径
BufferedImage image = null;
try {
image = ImageIO.read(im_filenew);
} catch (IOException e) {
e.printStackTrace();
}
int i = image.getHeight();
}
抛出以下异常:
java.lang.IllegalArgumentException: Invalid ICC Profile Data
at java.awt.color.ICC_Profile.getInstance(ICC_Profile.java:705)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.setImageData(JPEGImageReader.java:585)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.readImageHeader(Native Method)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.readNativeHeader(JPEGImageReader.java:543)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.checkTablesOnly(JPEGImageReader.java:298)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.gotoImage(JPEGImageReader.java:420)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.readHeader(JPEGImageReader.java:536)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(JPEGImageReader.java:869)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.read(JPEGImageReader.java:853)
at javax.imageio.ImageIO.read(ImageIO.java:1384)
at javax.imageio.ImageIO.read(ImageIO.java:1306)
at jp.co.rct.jj.fujiyama.krw.common.MyTest.main(MyTest.java:69)更详细描述如下:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6245283
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6404011
国外人没有解决。我们国内高手解决可以不?

解决方案 »

  1.   

    再次说明:
    http://member.ycn.com/~emu/keiler16.jpg的图片的颜色空间(colorspace)为CMYK模式;
    就是上述 ImageIO.read()方法抛出异常的原因。
    一般情况为RGB模式。
      

  2.   

    这个应该不算bug吧
    只能说明java不支持cmyk模式的jpg
    就好像java不支持写gif文件
    java压缩不支持带密码的zip
    java压缩不支持rar
    支持的标准不同
      

  3.   

    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6404011
    上述有这样写:
    The fix idea is to catch IllegalArgumentException which is thrown by 
     ICC_Profile and handle image without taking into account invalid color
     profile.
    所以我想这样做:
    try {
    image = ImageIO.read(im_filenew);
    } catch (IllegalArgumentException e) {
    ICC_Profile ICC_pf=
    ICC_Profile.getInstance("D:/TEST/200706/2295/JAICMM/CMYK.pf");
    ICC_ColorSpace ICC_ClSpace= new ICC_ColorSpace(ICC_pf);
    // TODO 读图片但不知道怎么做
    //.....

    其中*.pf色彩文件从http://java.sun.com/products/java-media/jai/downloads/download-1_0_2.html可取得。
      

  4.   

    在别的地方,看见一个解决方案》
    在ImageIO.read方法前,把jpg图片文件从写,就不会有问题。