487

Reading JCS_YCCK images using ImageIO

Question:

I'm using 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.

Recommend

  • Image won't appear in JLabel
  • Change ImageIcon being displayed in JFrame
  • Setting a path when creating a new File in Java
  • create ZPL to print a PNG-image with JAVA
  • Python Pillow: Make gradient for transparency
  • How to Cache Images Dynamically-Generated with PHP?
  • Httpclient multipart/form-data post image and json same time
  • how to download csv with fusion charts in codeigniter
  • Iterating over a container bidirectionally
  • Hibernate: Inheritance and relationship mapping + generics
  • unrecognized selector isPitched called
  • Return null in boolean to checkbox state converter in XAML
  • Python: Split a String Field into 3 Separate Fields using Lambda
  • Azure table query partial partitionkey guid match
  • JSF2.0 + Primefaces 3.0.1 + jquery 1.6.4 + p:commandLink + IE8 throws Unexpected call to method or p
  • maven jboss-as:start A required class was missing … org/sonaty…/ArtifactResolutionException
  • Matplotlib save file as JPEG encoder error
  • Read the values from XML file
  • Is there a way to call library thread-local init/cleanup on thread creation/destruction?
  • Zend Framework bassed projects
  • MVVM: Image Bind Source from FileOpenPicker
  • MAVEN : Run Multiple Maven Project using Maven Test
  • How do I add a File Type Association in a Windows Phone 8.1 app manifest?
  • Losing my session variables
  • TFS - how do I sum child task hours to parent
  • SIP API media codecs
  • ZipList with Scalaz
  • jquery validation - waiting for remote check to complete
  • Where these are stored?
  • rewrite uppercase url to lowercase url htaccess
  • Does Apportable support to build library binary (.a/.so)?
  • Can't delete or rename original file after resizing
  • Remove changes from one element when event occurs on another element?
  • How do I superscript characters in a UIButton?
  • Jetty 9 HashLoginService
  • Display images in Django
  • Problem deserializing objects from cache on MyBatis 3/Java
  • What is Eclipse's Declaration View used for?
  • Java applet as stand-alone Windows application?
  • jQuery tmpl and DataLink beta