Reading JPEGs in Java

不问归期 提交于 2020-01-14 09:59:08

问题


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.

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.

Are these my only options? Are there really no Java libraries capable of robustly reading JPEGs into a BufferedImage?


回答1:


Legacy Toolkit methods such as createImage and getImage are known to be more lenient than ImageIO.

Werner Randelshofer also wrote a Service Provider to read CMYK JPEGs with ImageIO.

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.

Reading JPEGs with CMYK profile may be a interesting read.



来源:https://stackoverflow.com/questions/11552838/reading-jpegs-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!