繁体   English   中英

有没有比较颜色的更好方法?

[英]Is there a better way to compare colors?

所以我一直在努力比较颜色。 我想说的是,这不是蓝色,紫色,橙色等等的阴影。不一定是纯色。

我从网上尝试过的一些解决方案是投射Color对象.ToArgb()并检查该值是否大于或小于对应的值。 就像if (Color.ToArgb() < -13107000 && Color.ToArgb() > -15000000) // Color is blueish

但这已被证明是无效的。 除非有一些颜色图表,否则我不知道在哪里可以轻松找到这些值。 我的方向完全错误了吗? 请建议如何正确比较C#中的颜色(可能未命名)。

我正在寻找一种快速的方法,以可视方式将蓝色“阴影”的阈值转换为其整数值。 使用此图表和一些C#代码以及@jdphenix的建议,我能够做到这一点。

在此处输入图片说明

    private Color FromHex(string hex)
    {
        if (hex.StartsWith("#"))
            hex = hex.Substring(1);

        if (hex.Length != 6) throw new Exception("Color not valid");

        return Color.FromArgb(
            int.Parse(hex.Substring(0, 2), System.Globalization.NumberStyles.HexNumber),
            int.Parse(hex.Substring(2, 2), System.Globalization.NumberStyles.HexNumber),
            int.Parse(hex.Substring(4, 2), System.Globalization.NumberStyles.HexNumber));
    }

将两者放在一起:

            // Starting blue threshold, or whatever your desired threshold is
            Color BlueLowThreshold = FromHex("#00B4FF");
            int blueLowThreshold = BlueLowThreshold.ToArgb();
            // Ending blue threshold, or whatever your desired end threshold is
            Color BlueHighThreshold = FromHex("#5000FF");
            int blueHighThreshold = BlueHighThreshold.ToArgb();

谢谢你的建议。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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