[英]C# Color Matching
你能幫我配色嗎
我試圖搜索一些無法正常運行的代碼
我的邏輯如下所示,可調整的公差是最接近顏色的5%或10%:
Red and Light Red = True
Red and Dark Red = True
Red and black = False
這是我的代碼,但效果不佳
public static bool MatchArgb(int Argb1, int Argb2, int tolerance)
{
Color c1 = Color.FromArgb(Argb1);
Color c2 = Color.FromArgb(Argb2);
return Math.Abs(c1.R - c2.R) <= tolerance ^
Math.Abs(c1.G - c2.G) <= tolerance ^
Math.Abs(c1.B - c2.B) <= tolerance;
}
public static bool MatchColor(Color c1, Color c2, int tolerance)
{
return Math.Abs(c1.R - c2.R) <= tolerance ^
Math.Abs(c1.G - c2.G) <= tolerance ^
Math.Abs(c1.B - c2.B) <= tolerance;
}
檢查在Paint.NET中如何完成此操作可能是一個好主意。 我在這里找到了它的克隆以及相應的源代碼: Pinta / Flood Tool
private static bool CheckColor (ColorBgra a, ColorBgra b, int tolerance)
{
int sum = 0;
int diff;
diff = a.R - b.R;
sum += (1 + diff * diff) * a.A / 256;
diff = a.G - b.G;
sum += (1 + diff * diff) * a.A / 256;
diff = a.B - b.B;
sum += (1 + diff * diff) * a.A / 256;
diff = a.A - b.A;
sum += diff * diff;
return (sum <= tolerance * tolerance * 4);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.