作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有两种颜色,如何检查它们是否是相同颜色但只是深浅不同?我一直在尝试,但我似乎无法弄清楚,我真的不知道我在做什么哈哈...这就是我到目前为止所拥有的:
import java.awt.Color;
public class Sandbox {
public Sandbox() {
Color c = new Color(5349322);
int r, g, b;
r = c.getBlue();
g = c.getGreen();
b = c.getRed();
System.out.println("Red: " + r);
System.out.println("Green: " + g);
System.out.println("Blue: " + b);
}
private boolean FindColorTol(int intTargetColor, int Tolerance) {
Color targetColor = new Color(intTargetColor);
Color imgColor = new Color(5349322);
int targetRED = targetColor.getBlue(),
targetGREEN = targetColor.getGreen(),
targetBLUE = targetColor.getRed(),
imgRED = imgColor.getBlue(),
imgGREEN = imgColor.getGreen(),
imgBLUE = imgColor.getRed();
return false;
}
private int getLargest(int...values) {
int largest = 0;
for(int i = 0; i < values.length; i++) {
if(values.length > i + 1) {
if(values[i] > values[i + 1])
largest = values[i];
else
largest = values[i + 1];
}
}
return largest;
}
public static void main(String[] args) {
new Sandbox();
}
}
还有,为什么 Color.getRed() 返回蓝色的值,而 Color.getBlue() 返回红色的值?我用它来查找 RGB 值:http://www.colorschemer.com/online.html
我正在尝试使用它来查找图像中的指定颜色。
最佳答案
在 colour theory ,阴影是通过将一种颜色与不同量的黑色混合得到的。因此,您可以通过标准化它们的值来轻松检查两个 RGB 三元组是否对应于相同颜色的不同色调
max1 = max(r1,g1,b1);
max2 = max(r2,g2,b2);
if ( approxEQ(r1/max1,r2/max2,DELTA) &&
approxEQ(g1/max1,g2/max2,DELTA) &&
approxEQ(b1/max1,b2/max2,DELTA) ) {
/* Same colour, different shades */
}
(显然,max(a,b,c)
返回三个参数中最大的一个,approxEQ(a,b,d)
返回 如果
,否则为 false。)|a-b|≤d
则为 true
如果您也想检查色调,最好 converting your RGB values to HSV or HSL .
关于java - 比较颜色深浅?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19916971/
我是一名优秀的程序员,十分优秀!