Question

I need a way to determine the type of this BufferedImage in java (Binary, Gray, 24 bit color, 8 bit color) ?

It is something like BufferedImage.getType() method ,that returns an integer that determines that ,but I need a way to handle that. And if there is an Algorithm that detects it like the color is grey if red=green=blue and so on. I will be thankful if you tell me about it

All regards

Was it helpful?

Solution

Either, as you suggest, use BufferedImage.getType() (you can find what the int return values mean, in the API doc).

Or, use BufferedImage.getColorModel() to get more information, like ColorSpace (ColorModel.getColorSpace()) to determine color space type, like RGB, CMYK or Gray, or special color spaces, like sRGB, AdobeRGB, PhotoYCC, IEXYZ, Lab etc.

If you need to figure out if your image in 24/32 bit depth with RGB color model really is all gray, you are out of luck, and instead have to loop though all the pixel values and see if R == G == B (perhaps with a small threshold).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top