开发者

Reading specific image MetaData efficiently using javax.imageio

开发者 https://www.devze.com 2023-03-20 21:53 出处:网络
I\'m trying to read a PNG image using javax.imageio and then extract the bit-depth and color-type meta data.

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);
while(itr.hasNext开发者_高级运维())
{
    ImageReader reader = itr.next();
    reader.setInput(stream);
    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)?


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();
0

精彩评论

暂无评论...
验证码 换一张
取 消