我一直在寻找一种快速方法,将蓝色“阴影”的阈值直观地转换为整数值。使用这个图表和一些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