I'm trying to determine if an image is a simple black and white image, or if it has color (using Java). If it has color, I need to display a warning message to the user that the color will be lost.
The BufferedImage class has a method int getRGB(int x, int y)
that returns a hex integer representing the color of the pixel at (x, y) (and another method that returns a matrix of pixels). From that you can get the r, g, and b values like so:
int r = (0x00ff0000 & rgb) >> 16; int g = (0x0000ff00 & rgb) >> 8; int b = (0x000000ff & rgb);
and then check whether they are all equal for every pixel in the image. If r == g == b for every pixel, then it's in gray scale.
That's the first thing that comes to mind. I'm not sure if there would be some kind of gray scale flag set when reading in an image.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With