Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4895467

JPEG Writer throws an IIOException when trying to reuse it

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 5.0
    • 1.4.0
    • client-libs
    • tiger
    • generic
    • generic
    • Verified

        I am creating a JPEG writer and writing a TYPE_INT_RGB image to a file. After this, i am calling writer.reset(). I am creating a new ImageOutputStream (out of a newly created file) and setting it to the same writer and using the same writer to write another buffered image which is of type TYPE_INT_ARGB. In this case, I am getting an IIOException saying Metadata components are not equal to number of destination bands. The above scenario works fine if both the images are either RGB or ARGB. Unable to write a RGB after ARGB and vice versa.

        Any ImageWriter must be reusable and the user should not be expected to create a new writer for each write operation. In the above scenario, the only workaround is to create the JPEGWriter again and the existing writer could not be reused to write another image inspite of restoring it to its initial state.

        This is reproducible on Solaris and Win32 right from JDK1.4+.

        I have attached a sample code. Execute the same application as follows.
        java WriterReuseTest <imgformat>
        This will throw an IIOException at the console.

        The exception thrown:
        javax.imageio.IIOException: Metadata components != number of destination bands
         at com.sun.imageio.plugins.jpeg.JPEGImageWriter.checkSOFBands(JPEGImageWriter.java:1162)
         at com.sun.imageio.plugins.jpeg.JPEGImageWriter.write(JPEGImageWriter.java:611)
         at javax.imageio.ImageWriter.write(ImageWriter.java:591)
         at WriterReuseTest.<init>(WriterReuseTest.java:69)
         at WriterReuseTest.main(WriterReuseTest.java:101)

              campbell Christopher Campbell (Inactive)
              pmohansunw Praveen Mohan (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: