Try to check the encoding of the JPEG. ImageIO
can’t read CMYK-encoded jpeg images for example.
AFAIK, ImageIO hasn’t been updated for years, so you’d like to try and use the official alternative/extension: JAI ImageIO.
Unforutnately, JAI ImageIO needs some native libraries installed into the JRE, which might be unwanted.
We do the following:
- use Apache Sanselan to detect, whether it’s a JPEG
- since Sanselan can’t read and write JPEG, use the plain old AWT
JPEGCodec
:JPEGCodec.createJPEGDecoder(...)
- to convert CMYK to RGB, we then get the raster of the read
BufferedImage
and manually convert it (you could use ICC profiles, but the manual conversion fits our needs)
Here’s a question of mine that resulted of the fact that ImageIO
doesn’t support all types of JPEG images, and I there stated a little more of my findings of why you get that message: Pure Java alternative to JAI ImageIO for detecting CMYK images