Read CMYK Image in Java

If you read a CMYK image format using ImageIO, you will get CMMException:Invalid image format error. Obviously, the only pure Java way of Implementation is with JPEGDecoder, which is deprecated.

So you have to use JAI to get rid of this issue. But there is no need to read images using JAI always. So i come up with this code, which will read CMYK images only if there is an error.  Some of you might already knew about this, but for starters it might save some time.

storedImage =;
} catch(CMMException ce) {
SeekableStream seekableStream = new FileSeekableStream(destination);
ParameterBlock pb = new ParameterBlock();
storedImage = JAI.create("jpeg", pb).getAsBufferedImage();

One thought on “Read CMYK Image in Java

  1. hi thank you for this code.
    Can you tell me how to use JAI ? (where can i download a jar containing this class)
    Same question for FileSeekableStream.

    And i see it that SeekableStream exists in two package : org.apache.batik.ext.awt.image.codec.util.SeekableStream and org.apache.xmlgraphics.image.codec.util.SeekableStream.
    Wich one do you use?

    thank you in advance!


If you have any queries feel free to write to author

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s