【问题标题】:How to check if two colors are close to each other?如何检查两种颜色是否彼此接近?
【发布时间】:2018-10-27 08:18:54
【问题描述】:

有没有办法检查一种颜色是否接近另一种颜色?

例如,一种颜色(比如#D4FFA9)是否接近绿色?

类似:

布尔值areColorsClose(int colorOne, int colorTwo) {}

【问题讨论】:

  • “有没有办法”?是的。定义“接近”对您意味着什么(例如比 RGB 颜色立方体中的某个距离更接近)并分别对其进行编程。
  • 将 rgb 转换为 hsv 并检查 h 部分
  • @Henry #D4FFA9 和 #4E9B00 都是绿色,第一个是浅色的,第二个是深色的,我的意思是前面所说的两种颜色是否相近? (以浅绿色和深绿色为例)
  • @pskink 你能详细说明一下吗?
  • android.graphics.Color官方文档

标签: android rgb android-color rbga


【解决方案1】:

你可以从另一个中减去一个,例如:

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.

你需要先决定你认为接近的东西:)

【讨论】:

  • 这将使红色通道的差异高于绿色通道的差异,并且远高于蓝色通道的差异。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-20
  • 2013-09-01
  • 1970-01-01
  • 2010-10-04
相关资源
最近更新 更多