Why does loading this jpg using JavaIO give CMMException?

前端 未结 3 1549
说谎
说谎 2020-12-19 04:29

ImageIO.read(imagePath) with this file gives a CMMException, why cant Java cope with this seemingly valid file http://www.jthink.net/jaikoz/scratch/front.jpg



        
相关标签:
3条回答
  • 2020-12-19 05:07

    Old post, but for future reference:

    Inspired by this question and links found here, I've written a JPEGImageReader plugin for ImageIO that supports JPEG images with these kind of "bad" ICC color profiles (the "issue" is the rendering intent in the ICC profile is incompatible with Java's ColorConvertOp). It's plain Java and does not require JAI. The source code is freely available at:

    https://github.com/haraldk/TwelveMonkeys/tree/master/imageio/imageio-jpeg

    0 讨论(0)
  • 2020-12-19 05:24

    BTW, this problem is fixed in JDK8 (notice the commit at the bottom of http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7064516). I've confirmed that a pre-release build of JDK8 properly loads images that JDK7 fails on as described above.

    0 讨论(0)
  • 2020-12-19 05:26

    I think I got the hang of your problem. I checked the image you linked ( http://www.jthink.net/jaikoz/scratch/front.jpg ). Its due to Exif and JFIF standard.

    when you are doing something like ImageIO.read('some file') it invokes the default sun jpeg implementation com.sun.imageio.plugins.jpeg.JPEGImageReader. Which used to have issues loading JFIF files BUG 6488904 (check the comment towards the end).

    According to spec, both Exif and JFIF demands that their respective application marker segment must be the first right after SOI (APP1 and APP0) , so it is actually not possible per spec for an JPEG file to be compliant with both standards.

    Though it was reported long time back

    The workaround is to use JAI library (https://jai.dev.java.net/binary-builds.html#Release_builds). I am using Java (no native acceleration) version.

    SeekableStream seekableStream =  new FileSeekableStream(new File("front.jpg"));
    ParameterBlock pb = new ParameterBlock();
    pb.add(seekableStream);
    
    BufferedImage image = JAI.create("jpeg", pb).getAsBufferedImage();
    

    hope this will help.

    0 讨论(0)
提交回复
热议问题