java - How to get image's (in a file) number of channels (color depth)? -
here have example on how image's dimensions file: https://stackoverflow.com/a/12164026/258483
the method uses imagereader
tries not read entire image if not required.
is there similar method obtain image's color depth, 3 colored image , 1 b/w image?
i found imagereader#getrawimagetype(int)
method. correct way?
yes,
you can use imagereader.getrawimagetype(imageno)
. method work of time. unfortunately, in cases return null
, notably jpeg images encoded ycbcr (instead of rgb), , common case jpeg...
another way same information, use image meta data object, , @ standard metadata format, information:
iiometadata metadata = imagereader.getimagemetadata(imageno); if (metadata.isstandardformatsupported()) { // true bundled formats iiometadatanode root = (iiometadatanode) imagemetadata.getastree("javax_imageio_1.0"); // either (as pseudo-xpath): // /chroma/numchannels[@value], number of channels, 3 rgb // /data/bitspersample[@value], bits per sample, typically 8,8,8 24 bit rgb }
you can @ standard format documentation , iiometadatanode
api doc more information.
Comments
Post a Comment