Take the 2-minute tour ×

I'm trying to read a PNG image using javax.imageio and then extract the bit-depth and color-type meta data.

Right now I'm using:

Iterator<ImageReader> itr = ImageIO.getImageReaders(stream);
    ImageReader reader = itr.next();
    IIOMetadata md = reader.getImageMetadata(0);

But after this point I'm stuck. It seems the only way to read the MetaData is by converting it to an XML tree using md.getAsTree, but iterating over the whole tree just to find the two fields I'm interested in seems very inefficient.

Is there any way to get only those fields in an efficient way (a hashtable or something of the sort)?

share|improve this question
add comment

1 Answer

I use sanselan (which is now being brought into the apache commons but that isn't complete yet) to read metadata.

            ImageInfo image_info = Sanselan.getImageInfo(imageFile);
            int bitDepth = image_info.getBitsPerPixel();
            int colorType = image_info.getColorType();
share|improve this answer
add comment

Your Answer


