I am creating an IIS from the given jpg image and getting the corresponding reader from ImageIO. Calling ImageReader.getImageTypes(0) returns 4 ImageTypeSpecifiers (2 types of 3BYTE_BGR, 1 BYTE_GRAY and 1 TYPE_CUSTOM). I am setting the destination type to the first returned image type specifier by calling param.setDestinationType(typeSpecifier) and using this param to read the image. ImageReader throws IIOException saying the destination type specified in the param does not match.
This is incorrect. The first type specifier returned by getImageTypes() is supposed to be the most appropriate destination type for the given image. Setting the destination type to the second type specifier in the returned array works fine (which is also 3BYTE_BGR).
javax.imageio.IIOException: Destination type from ImageReadParam does not match!
This is reproducible on all platforms atleast since 1.4.2.
I have attached a sample test. Execute the sample test, passing the given image as an argument. You would see the original image loaded in the top (labelled 'Original'). This is read through Toolkit API. Below that, you are supposed to see a grid of 3x3 images (total 9 images). First image on the first row would be the output of setDestinationType, second one on the first row would be setDestination (typeSpecifier.createBufferedImage) and third image on the first row would be setDestination (new BufferedImage(x,y, type.getBufImageType())). The first image will not be loaded in this case because of the above exception.
Second and third rows represents the second and third image type specifiers returned by getImageTypes(). TYPE_CUSTOM is skipped since it takes huge time to load the image.