Android examples for Graphics:Color Operation
get Color Shade Comparison
public class Main { /**/*from w ww .j a v a 2 s. c om*/ * ((r2 - r1)2 + (g2 - g1)2 + (b2 - b1)2)1/2 */ public static double getColorShadeComparison(int inputColor, int comparisonColor) { int inputColorRed = getRedFromColor(inputColor); int inputColorGreen = getGreenFromColor(inputColor); int inputColorBlue = getBlueFromColor(inputColor); int comparisonColorRed = getRedFromColor(comparisonColor); int comparisonColorGreen = getGreenFromColor(comparisonColor); int comparisonColorBlue = getBlueFromColor(comparisonColor); return Math.pow((Math.pow((comparisonColorRed - inputColorRed), 2f) + Math.pow((comparisonColorGreen - inputColorGreen), 2f) + Math.pow(comparisonColorBlue - inputColorBlue, 2f)), 0.5f); } public static int getRedFromColor(int color) { return (color >> 16) & 0xFF; } public static int getGreenFromColor(int color) { return (color >> 8) & 0xFF; } public static int getBlueFromColor(int color) { return color & 0xFF; } }