我一直在尋找一種快速方法,將藍色「陰影」的閾值直觀地轉換爲整數值。使用這個圖表和一些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();
謝謝您的建議。
這是不是很清楚你在這裏問什麼。什麼是「藍色」?藍色什麼時候停止變藍並且變成藍綠色? –
有2^24種顏色,所以不是所有的名字,謝天謝地。如果你在ADA中編碼,他們可能都有名字。無論如何,既然你的色調將是主觀的,那麼我會建議你自己編寫常量並應用它們。 – nicomp
準備好一組預定義的顏色(或者使用已經存在的顏色,比如系統顏色),然後計算測試顏色和每組顏色之間的歐氏距離。 – jdphenix