How to check color brightness in android?
android
Solution
You Should try this....
public static boolean isBrightColor(int color) {
if (android.R.color.transparent == color)
return true;
boolean rtnValue = false;
int[] rgb = { Color.red(color), Color.green(color), Color.blue(color) };
int brightness = (int) Math.sqrt(rgb[0] * rgb[0] * .241 + rgb[1]
* rgb[1] * .691 + rgb[2] * rgb[2] * .068);
// color is light
if (brightness >= 200) {
rtnValue = true;
}
return rtnValue;
}
reference: Android/Java: Determining if text color will blend in with the background?
Problem
How to check brightness in android? I have an integer value of color.I wanna check this color is dark color or light color base on integer value of color. ``` if (checkColor == Color.RED || checkColor == Color.BLACK) { //set fore color is white } else { //set fore color is black } ``` instead of above code, i wanna change ``` if (!isBrightColor(checkColor)) { //set fore color is white } else { //set fore color is black } private boolean isBrightColor(int checkColor){ boolean rtnValue; //How to check this color is bright or dark return rtnValue; } ```