gpt4 book ai didi

android - 如何检查android中的颜色亮度?

转载 作者:太空狗 更新时间:2023-10-29 16:41:58 25 4
gpt4 key购买 nike

如何在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: Determining if text color will blend in with the background?

关于android - 如何检查android中的颜色亮度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16312792/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com