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.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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: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.