用Java读取JPEG [英] Reading JPEGs in Java
问题描述
我正在尝试将JPEG放入BufferedImage
中以显示在JPanel
上.但是,javax.imageio.ImageIO.read()
似乎对其处理的JPEG非常挑剔,经常抛出IIOException
.几乎在所有您想命名的图像阅读器中,相同的JPEG都能很好地打开.
I'm attempting to get a JPEG into a BufferedImage
to display on a JPanel
. However, javax.imageio.ImageIO.read()
seems to be very fussy about the JPEGs it processes, often throwing an IIOException
. The same JPEGs open fine in pretty much any image reader you'd care to name.
我看过Apache的 Sanselan 和答案建议使用com.sun.image.codec.jpeg.JPEGCodec
,但Java中已弃用5,并在7中消失.
I've looked at Apache's Sanselan and JAI. But Sanselan can't process JPEGs and JAI isn't available for 64-bit Windows platforms and doesn't seem to be maintained (the last update was in 2006). A previous answer on StackOverflow suggested com.sun.image.codec.jpeg.JPEGCodec
, but this was deprecated in Java 5 and has disappeared in 7.
这些是我唯一的选择吗?真的不存在能够将JPEG可靠地读取到BufferedImage
的Java库吗?
Are these my only options? Are there really no Java libraries capable of robustly reading JPEGs into a BufferedImage
?
推荐答案
旧版工具包方法,例如 getImage 比ImageIO
更宽大.
Legacy Toolkit methods such as createImage and getImage are known to be more lenient than ImageIO
.
Werner Randelshofer还写了服务提供商使用ImageIO
读取CMYK JPEG.
Werner Randelshofer also wrote a Service Provider to read CMYK JPEGs with ImageIO
.
通过结合这两种方法(尝试所有可能的ImageReader
,然后回退到Toolkit
),您将能够处理合理数量的JPEG图像.
By combining both approaches (try every possible ImageReader
and then fallback to Toolkit
) you will be able to handle a reasonable number of JPEG Images.
使用CMYK配置文件读取JPEG 可能是一个有趣的读物.
Reading JPEGs with CMYK profile may be a interesting read.
这篇关于用Java读取JPEG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!