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