我想获取最接近以下列表的颜色:
static List<Color> clist = new List<Color>()
{
Color.Black, Color.Brown, Color.Blue, Color.Green, Color.Red, Color.Yellow,
Color.Gray, Color.Indigo, Color.Orange, Color.Pink, Color.Turquoise, Color.White
};
我可以这样获得最接近的颜色,但我想根据颜色的亮度和饱和度添加:浅/深/鲜艳/明亮:
static string closestColor2(List<Color> colors, Color target)
{
var colorDiffs = colors.Select(n => ColorDiff(n, target)).Min(n => n);
int x = colors.FindIndex(n => ColorDiff(n, target) == colorDiffs);
return colors[x].ToString();
}
static int ColorDiff(Color c1, Color c2)
{
return (int)Math.Sqrt((c1.R - c2.R) * (c1.R - c2.R)
+ (c1.G - c2.G) * (c1.G - c2.G)
+ (c1.B - c2.B) * (c1.B - c2.B));
}