Convert rgb color value in int to greyscale - Android android.graphics

Android examples for android.graphics:Color

Description

Convert rgb color value in int to greyscale

Demo Code

public class Main{

    public static int rgb2greyscale(int color) {
        if (color > 256 * 256 * 256) {
            color = color % (256 * 256 * 256);
        }/*w w  w . j a  v  a  2  s.c  o m*/
        int r = color / 256 / 256;
        int g = (color - r * 256 * 256) / 256;
        int b = color - r * 256 * 256 - g * 256;
        return (int) (0.299 * r + 0.587 * g + 0.114 * b);
    }

}

Related Tutorials