为什么使用 JavaIO 加载此 jpg 会给出 CMMException?
ImageIO.read(imagePath) 与此文件给出了 CMMException,为什么 Java 不能处理这个看似有效的文件 http://www.jthink.net/jaikoz/scratch/front.jpg
java.awt.color.CMMException: Invalid image format
at sun.awt.color.CMM.checkStatus(Unknown Source)
at sun.awt.color.ICC_Transform.<init>(Unknown Source)
at java.awt.image.ColorConvertOp.filter(Unknown Source)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.acceptPixels(Unknown Source)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.readImage(Native Method)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(Unknown Source)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.read(Unknown Source)
at javax.imageio.ImageIO.read(Unknown Source)
at javax.imageio.ImageIO.read(Unknown Source)
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
java.awt.color.CMMException: Invalid image format
at sun.awt.color.CMM.checkStatus(Unknown Source)
at sun.awt.color.ICC_Transform.<init>(Unknown Source)
at java.awt.image.ColorConvertOp.filter(Unknown Source)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.acceptPixels(Unknown Source)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.readImage(Native Method)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(Unknown Source)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.read(Unknown Source)
at javax.imageio.ImageIO.read(Unknown Source)
at javax.imageio.ImageIO.read(Unknown Source)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我想我已经解决了你的问题。我检查了您链接的图像( http://www.jthink.net/jaikoz/scratch /front.jpg )。这是由于 Exif 和 JFIF 标准。
当您执行诸如
ImageIO.read('some file')
之类的操作时,它会调用默认的 sun jpeg 实现com.sun.imageio.plugins.jpeg.JPEGImageReader
。曾经在加载 JFIF 文件时遇到问题BUG 6488904(检查对结尾)。虽然很久以前就有报道说
解决方法是使用 JAI 库 (https:/ /jai.dev.java.net/binary-builds.html#Release_builds)。我正在使用Java(无本机加速)版本。
希望这会有所帮助。
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 implementationcom.sun.imageio.plugins.jpeg.JPEGImageReader
. Which used to have issues loading JFIF files BUG 6488904 (check the comment towards the end).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.
hope this will help.
顺便说一句,这个问题在 JDK8 中已得到修复(请注意 https:// 底部的提交bugs.java.com/bugdatabase/view_bug?bug_id=7064516)。我已经确认 JDK8 的预发布版本 可以正确加载 JDK7 失败的图像如上所述。
BTW, this problem is fixed in JDK8 (notice the commit at the bottom of https://bugs.java.com/bugdatabase/view_bug?bug_id=7064516). I've confirmed that a pre-release build of JDK8 properly loads images that JDK7 fails on as described above.
旧帖子,但供将来参考:
受此问题和此处找到的链接的启发,我为 ImageIO 编写了一个 JPEGImageReader 插件,它支持具有此类“不良”ICC 颜色配置文件的 JPEG 图像(“问题”是中的渲染意图) ICC 配置文件与 Java 的 ColorConvertOp 不兼容)。它是纯 Java,不需要 JAI。源代码可免费获取:
https://github.com/haraldk /TwelveMonkeys/tree/master/imageio/imageio-jpeg
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