ImageIO.read to process uploaded image files. The code is similar to
BufferedImage bufferedImage = ImageIO.read(new ByteArrayInputStream(image.getContents()));
I've managed to solve most of the issues, but this one has left me clueless. The uploaded image has a
JCS_YCCK profile, as defined in
com.sun.imageio.plugins.jpeg.JPEG, which is not supported by
com.sun.imageio.plugins.jpeg.JPEGImageReader. This leads to a nice stack trace similar to:
Caused by: javax.imageio.IIOException: Unsupported Image Type at com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(JPEGImageReader.java:910) at com.sun.imageio.plugins.jpeg.JPEGImageReader.read(JPEGImageReader.java:885) at javax.imageio.ImageIO.read(ImageIO.java:1422) at javax.imageio.ImageIO.read(ImageIO.java:1326) at com.example.ImageWriter.resizeEmbeddableImageInPlace(ImageWriter.java:231)
How can I process this type of JPEG using Java's ImageIO?<hr />
<em>Update</em>: I've tried Commons-Sanselan, indicated by an answer, but unfortunately it does not support JPEG files:
org.apache.sanselan.ImageReadException: Sanselan cannot read or write JPEG images. at org.apache.sanselan.formats.jpeg.JpegImageParser.getBufferedImage(JpegImageParser.java:90) at org.apache.sanselan.Sanselan.getBufferedImage(Sanselan.java:1264) at org.apache.sanselan.Sanselan.getBufferedImage(Sanselan.java:1231)Answer1:
One possible solution is to use the Java Advanced Imaging Image IO extensions. When properly installed, the conversion works out of the box.
The problem is that it does not play well with Maven, so I've asked <a href="https://stackoverflow.com/questions/1209583/using-java-advanced-imaging-with-maven" rel="nofollow">Using Java Advanced Imaging with Maven</a>. If that works out, this answer will be accepted.Answer2:
I don't know for ImageIO, but you could use the <a href="http://commons.apache.org/sanselan/" rel="nofollow">Commons Sanselan library</a>, which offers easy ways to access all sorts of images.