Here you can find the source of rgbToGray(int colorIn)
static public int rgbToGray(int colorIn)
//package com.java2s; //License from project: Open Source License public class Main { public static final int BLUE_MASK = 0xff; public static final int GREEN_MASK = 0xff00; public static final int RED_MASK = 0xff0000; public static final int GREEN_OFFSET = 8; public static final int RED_OFFSET = 16; /** Change an RGB color to a gray value. * // w w w .j av a2 s . co m * Based on the perceived contribution to the brightness. * */ static public int rgbToGray(int colorIn) { int red = (colorIn & RED_MASK) >> RED_OFFSET; //red int green = (colorIn & GREEN_MASK) >> GREEN_OFFSET; //green int blue = colorIn & BLUE_MASK; //blue double brightness = 0.3 * red + 0.59 * green + 0.11 * blue; return (int) brightness; } }