【问题标题】:Color List In A Image图像中的颜色列表
【发布时间】:2014-12-20 21:18:25
【问题描述】:

我需要图像中最常用的 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();

【问题讨论】:

    标签: c# image gdi


    【解决方案1】:

    RGB 由三种原色组成:红、绿、蓝。它们中的每一个都有一个 0-255 范围内的值。颜色 RGB (0,255,0)、RGB (0,254,0)、RGB (0,253,0)、RGB (2,254,2) 看起来一样,但实际上它们是不同的。也许您应该添加颜色的公差范围。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-08
      • 2011-11-20
      相关资源
      最近更新 更多