3

I have the following problem. We have an Webservice with Upload Function for images. When you try to upload certain images, it just fails. These images have the right MIMETYPE, they are not CMYK (at least GIMP say they are in RGB). The thrown Exception is: "Unsupported Image Type"! The problem occurs, when trying to start this command:

BufferedImage img = ImageIO.read(new ByteArrayInputStream(image.getData()));

I dig a little deeper and the real exception gets thrown with the ImageIO.read(ImageInputStream stream), when he tries to close the stream again!

public static BufferedImage read(ImageInputStream stream)
    throws IOException {
    if (stream == null) {
        throw new IllegalArgumentException("stream == null!");
    }

    Iterator iter = getImageReaders(stream);
    if (!iter.hasNext()) {
        return null;
    }

    ImageReader reader = (ImageReader)iter.next();
    ImageReadParam param = reader.getDefaultReadParam();
    reader.setInput(stream, true, true);
    BufferedImage bi;
    try {
        bi = reader.read(0, param);
    } finally {
        reader.dispose();
        stream.close();
    }
    return bi;
}

An Image throwing the exception is this for example:
Image that crashes

I hope someone can help me figure out, why this crashes and how to fix it!

DonMarco
  • 405
  • 2
  • 14
  • 34

1 Answers1

2

The attached picture has CMYK color model. Try to convert it to RGB.

This question can be useful: How to convert from CMYK to RGB in Java correctly?

Community
  • 1
  • 1
user1411778
  • 461
  • 1
  • 5
  • 12