有没有办法检查一种颜色是否接近另一种颜色?
例如,一种颜色(比如#D4FFA9
(是否接近绿色?
类似于:
布尔areColorsClose(int colorOne, int colorTwo) {}
您可以从另一个中减去一个,例如:
int color1 = 0x7fffff;
int color2 = 0x000123;
int color_difference = color1 - color2;
然后决定你认为什么是"彼此接近":
if (color_difference <= [your acceptable difference]){
// Colors are close.
}else //Colors are too different.
这两种颜色都是绿色的:0x08ff76和0x04b252
它们的差异是:44d24
if (color_difference <= 44d24){
// Colors are close.
}else //Colors are too different.
您需要先决定您认为关闭的内容:(