javax.imageio.IIOException: Unsupported Image Type

Apache's JIRA Issue Tracker | Ludovic Davoine | 3 years ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    I have a PDF with CMYK images inside and i need to extract the images in the RGB format. But the PDJpeg class seems to not work correctly; the colors are bad. Example: - Original image in te PDF : http://ludoda.free.fr/IMAGE_IN_PDF.jpg - Extracted image: http://ludoda.free.fr/IMAGE_EXTRACTED.jpg You can download the PDF : http://ludoda.free.fr/PORSCHE_CMYK.PDF and try my simple Test Case (I'm using PDFbox 1.8.5): {code} import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.util.Iterator; import java.util.List; import java.util.Map; import javax.imageio.ImageIO; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.PDResources; import org.apache.pdfbox.pdmodel.graphics.xobject.PDJpeg; import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObject; import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectImage; public class TestCase { public static void main(String[] args) { try { System.out.println("START EXTRACTING IMAGES..."); read_pdf(); System.out.println("COMPLETE"); } catch (IOException ex) { System.out.println("" + ex); } } public static void read_pdf() throws IOException { PDDocument document = null; document = PDDocument.load("C:\\temp\\PORSCHE_CMYK.pdf"); @SuppressWarnings("unchecked") List<PDPage> pages = document.getDocumentCatalog().getAllPages(); Iterator<PDPage> iter = pages.iterator(); int i =1; while (iter.hasNext()) { PDPage page = (PDPage) iter.next(); PDResources resources = page.getResources(); Map<String, PDXObject> pageImages = resources.getXObjects(); if (pageImages != null) { Iterator<String> imageIter = pageImages.keySet().iterator(); while (imageIter.hasNext()) { String key = (String) imageIter.next(); if(pageImages.get(key) instanceof PDXObjectImage) { PDJpeg image = (PDJpeg) pageImages.get(key); // Test 1 : write2file image.write2file("C:\\workspace\\JAVA_PDFTools\\temp\\image" + i); // Test 2: getRGBImage BufferedImage bimage=image.getRGBImage(); File outputfile = new File("C:\\workspace\\JAVA_PDFTools\\temp\\image" + i+"_buffered.jpg"); ImageIO.write(bimage, "jpg", outputfile); i ++; } } } } } } {code}

    Apache's JIRA Issue Tracker | 3 years ago | Ludovic Davoine
    javax.imageio.IIOException: Unsupported Image Type
  2. 0

    I have a PDF with CMYK images inside and i need to extract the images in the RGB format. But the PDJpeg class seems to not work correctly; the colors are bad. Example: - Original image in te PDF : http://ludoda.free.fr/IMAGE_IN_PDF.jpg - Extracted image: http://ludoda.free.fr/IMAGE_EXTRACTED.jpg You can download the PDF : http://ludoda.free.fr/PORSCHE_CMYK.PDF and try my simple Test Case (I'm using PDFbox 1.8.5): {code} import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.util.Iterator; import java.util.List; import java.util.Map; import javax.imageio.ImageIO; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.PDResources; import org.apache.pdfbox.pdmodel.graphics.xobject.PDJpeg; import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObject; import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectImage; public class TestCase { public static void main(String[] args) { try { System.out.println("START EXTRACTING IMAGES..."); read_pdf(); System.out.println("COMPLETE"); } catch (IOException ex) { System.out.println("" + ex); } } public static void read_pdf() throws IOException { PDDocument document = null; document = PDDocument.load("C:\\temp\\PORSCHE_CMYK.pdf"); @SuppressWarnings("unchecked") List<PDPage> pages = document.getDocumentCatalog().getAllPages(); Iterator<PDPage> iter = pages.iterator(); int i =1; while (iter.hasNext()) { PDPage page = (PDPage) iter.next(); PDResources resources = page.getResources(); Map<String, PDXObject> pageImages = resources.getXObjects(); if (pageImages != null) { Iterator<String> imageIter = pageImages.keySet().iterator(); while (imageIter.hasNext()) { String key = (String) imageIter.next(); if(pageImages.get(key) instanceof PDXObjectImage) { PDJpeg image = (PDJpeg) pageImages.get(key); // Test 1 : write2file image.write2file("C:\\workspace\\JAVA_PDFTools\\temp\\image" + i); // Test 2: getRGBImage BufferedImage bimage=image.getRGBImage(); File outputfile = new File("C:\\workspace\\JAVA_PDFTools\\temp\\image" + i+"_buffered.jpg"); ImageIO.write(bimage, "jpg", outputfile); i ++; } } } } } } {code}

    Apache's JIRA Issue Tracker | 3 years ago | Ludovic Davoine
    javax.imageio.IIOException: Unsupported Image Type
  3. 0

    Issue with posters (r2346)

    GitHub | 2 years ago | Omertron
    javax.imageio.IIOException: Unsupported Image Type
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Issues when reindexing from scratch with r2589

    GitHub | 2 years ago | Omertron
    javax.imageio.IIOException: Unsupported Image Type

  1. serious2monkeys 3 times, last 5 months ago
  2. rexgreenza 10 times, last 6 months ago
  3. ptrstovka 2 times, last 11 months ago
16 unregistered visitors
Not finding the right solution?
Take a tour to get the most out of Samebug.

Tired of useless tips?

Automated exception search integrated into your IDE

Root Cause Analysis

  1. javax.imageio.IIOException

    Unsupported Image Type

    at com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal()
  2. Java RT
    ImageIO.read
    1. com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(Unknown Source)
    2. com.sun.imageio.plugins.jpeg.JPEGImageReader.read(Unknown Source)
    3. javax.imageio.ImageIO.read(Unknown Source)
    4. javax.imageio.ImageIO.read(Unknown Source)
    4 frames
  3. Apache PDFBox
    PDStream.getByteArray
    1. org.apache.pdfbox.filter.JPXFilter.decode(JPXFilter.java:56)
    2. org.apache.pdfbox.cos.COSStream.doDecode(COSStream.java:342)
    3. org.apache.pdfbox.cos.COSStream.doDecode(COSStream.java:254)
    4. org.apache.pdfbox.cos.COSStream.getUnfilteredStream(COSStream.java:188)
    5. org.apache.pdfbox.pdmodel.common.PDStream.createInputStream(PDStream.java:232)
    6. org.apache.pdfbox.pdmodel.common.PDStream.getByteArray(PDStream.java:510)
    6 frames