This discussion is archived
2 Replies Latest reply: Nov 5, 2012 8:19 AM by 29594 RSS

Error saving TIF image with JPEG compression (IndexColorModel)

29594 Newbie
Currently Being Moderated
Hi all,
i recently came upon the following error:
 javax.imageio.IIOException: Metadata components != number of destination bands
     at com.sun.imageio.plugins.jpeg.JPEGImageWriter.checkSOFBands(
     at com.sun.imageio.plugins.jpeg.JPEGImageWriter.writeOnThread(
     at com.sun.imageio.plugins.jpeg.JPEGImageWriter.write(
trying to save a tif file with jpeg compression. The code used is this:
  public static void main(String[] args) throws Exception{
    String s = "c:/sample images/gray_bug/graybug.tif";
    BufferedImage bi = File(s));
    File outFile = new File(s + "-out.tif");
    ImageWriter writer = (ImageWriter)ImageIO.getImageWritersByFormatName("TIF").next();
    ImageOutputStream ios = ImageIO.createImageOutputStream(outFile);
    TIFFImageWriteParam writeParam = new TIFFImageWriteParam(Locale.ENGLISH);
    IIOImage iioImage = new IIOImage(bi, null, null);
    writer.write(null, iioImage, writeParam);      
The test image that creates the problem can be found here:

Any ideas what might be wrong?
I am using imageio 1.2-pre-dr-b04 and JDK 1.6.

  • 1. Re: Error saving TIF image with JPEG compression (IndexColorModel)
    gimbal2 Guru
    Currently Being Moderated
    I can't help you but here's an exercise for you. When you get an exception you can't explain yourself, try posting it in Google. With a catch: remove anything from the error message that is specific to you like a classname or a specific value.

    In this case there is nothing specific in the error message so try a search for "javax.imageio.IIOException: Metadata components != number of destination bands". One thing is for sure: you're not the first to run into this error.
  • 2. Re: Error saving TIF image with JPEG compression (IndexColorModel)
    29594 Newbie
    Currently Being Moderated
    Thanks, already did that before posting here, but I can't find any information (although Google now brings this question in top 3 results...)

    I traced the code and see where it comes from, yet i have absolutely no idea why it happens. Strange thing is that saving the BufferedImage as JPG works!


  • Correct Answers - 10 points
  • Helpful Answers - 5 points