Unable to read JPEG image using ImageIO.read(File file)

Malakim picture Malakim · Mar 9, 2010 · Viewed 74.9k times · Source

I'm having problems reading this one JPEG file using ImageIO.read(File file) - it throws an exception with the message "Unsupported Image Type".

I have tried other JPEG images, and they seem to work fine.

The only differance I've been able to spot is that this file seems to include a thumbnail - is that known to cause problems with ImageIO.read()?

Troublesome image

EDIT:

Added the resulting image:

Strange colors

Answer

haraldK picture haraldK · Apr 22, 2013

Old post, but for future reference:

Inspired by this question and links found here, I've written a JPEGImageReader plugin for ImageIO that supports CMYK color models (both with original color model, or implicitly converted to RGB on read). The reader also does proper color conversion, using the ICC profile embedded in the JPEG stream, in contrast to other solutions mentioned here.

It's plain Java and does not require JAI. The source code and binary distributions are freely available at github.com/haraldk/TwelveMonkeys, and is covered by a BSD-style license.

Once you have it installed, it allows you to read CMYK JPEGs using ImageIO.read(...) like this:

File cmykJPEGFile = new File(/*path*/);
BufferedImage image = ImageIO.read(cmykJPEGFile);

I.e.: In most cases, it's not necessary to modify your code.