繁体   English   中英

C#色彩匹配

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM