簡體   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