如何在android中检查亮度?
我有一个整数值的颜色。我想根据颜色的整数值检查该颜色是深色还是浅色。
if (checkColor == Color.RED || checkColor == Color.BLACK) {
//set fore color is white
} else {
//set fore color is black
}
我想改变而不是上面的代码
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;
}
你应该尝试这个......
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;
}
参考:Android/Java:确定文本颜色是否会与背景融合? https://stackoverflow.com/questions/7785510/android-java-determining-if-text-color-will-blend-in-with-the-background?rq=1
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)