图像中的颜色列表

本文关键字:列表 颜色 图像 | 更新日期: 2023-09-27 18:27:50

我需要图像中最常用的30种颜色列表。。。我明白了,但有很多色调,我找不到主色调。例如,图片是红色的,但我不能得到红色。

我能做什么?

Dictionary<string,int> d = new Dictionary<string, int>();
Bitmap bmp = (Bitmap)Bitmap.FromFile("c:''test.jpg");
for (int x = 0; x < bmp.Width; x++)
{
    for (int y = 0; y < bmp.Height; y++)
    {
        Color c = bmp.GetPixel(x, y);
        var hexColor = c.R.ToString("X") + c.G.ToString("X") + c.B.ToString("X");
        if (d.ContainsKey(hexColor))
        {
            d[hexColor] = ++d[hexColor]; 
        }
        else
        {
            d.Add(hexColor, 1);
        }
    }
}

var items = (from pair in d
    orderby pair.Value descending
    select pair);
System.IO.StreamWriter file =
   new System.IO.StreamWriter("c:''colors.html",false);
foreach (var v in items)
{
    file.WriteLine("<div style='width:50px;height:50px;float:left;margin-right:10px;background-color:#" + v.Key + "'>&nbsp;</div>");
}
file.Close();

图像中的颜色列表

RGB由三种原色组成:红、绿、蓝。它们中的每一个都具有在0-255范围内的值。颜色RGB(0255,0)、RGB(0254,0)、GB(0253,0)和RGB(2254,2)看起来相同,但实际上不同。也许你应该增加颜色的公差范围。