Java tutorial
//package com.java2s; //License from project: Apache License import android.graphics.Color; public class Main { public static int getScrimColor(int background) { double a = getLuminance(background); if ((int) (a * 100) <= 50) // it was so close... return Color.BLACK; else return Color.WHITE; } private static double getLuminance(int color) { int r = (color & 0xff0000) >> 16; int g = (color & 0xff00) >> 8; int b = color & 0xff; return getLuminance(r, g, b); } private static double getLuminance(int r, int g, int b) { // Counting the perceptive luminance - human eye favors green color... return (0.299 * r + 0.587 * g + 0.114 * b) / 255; } }