为什么使用 JavaIO 加载此 jpg 会导致 CMMException? [英] Why does loading this jpg using JavaIO give CMMException?

查看:46
本文介绍了为什么使用 JavaIO 加载此 jpg 会导致 CMMException?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ImageIO.read(imagePath) 与这个文件给出了一个 CMMException,为什么 Java 不能处理这个看似有效的文件 http://www.jthink.net/jaikoz/scratch/front.jpg

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)

推荐答案

我想我已经解决了你的问题.我检查了您链接的图像( http://www.jthink.net/jaikoz/scratch/前面.jpg).由于 Exif 和 JFIF 标准.

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.

当您执行类似 ImageIO.read('some file') 之类的操作时,它会调用默认的 sun jpeg 实现 com.sun.imageio.plugins.jpeg.JPEGImageReader.过去在加载 JFIF 文件时遇到问题BUG 6488904(查看对结束).

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).

根据规范,Exif 和JFIF 要求他们各自的应用程序标记段必须是SOI 之后的第一个(APP1 和 APP0),所以实际上是不可能的符合 JPEG 文件的规范符合两种标准.

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.

虽然早有报道

解决方法是使用 JAI 库(https://jai.dev.java.net/binary-builds.html#Release_builds).我使用的是 Java(无本机加速) 版本.

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();

希望这会有所帮助.

这篇关于为什么使用 JavaIO 加载此 jpg 会导致 CMMException?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆