[英]Color List In A Image
I need most used 30 color list from a image... I get it but there is alot of color tone's and i can't get main colors. 我需要从图像中使用最多的30种颜色列表...我知道了,但是有很多色调,而且我无法获得主要颜色。 for example picture has red color but i can't get red color.
例如图片有红色,但我不能得到红色。
What can i do? 我能做什么?
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 + "'> </div>");
}
file.Close();
RGB is composed of three primary colors: Red, Green, Blue. RGB由三种原色组成:红色,绿色,蓝色。 Each of them has a value in the range 0-255.
它们每个的值都在0-255之间。 Colors RGB (0,255,0), RGB (0,254,0), RGB (0,253,0), RGB (2,254,2) look the same, but in fact they are different.
颜色RGB(0,255,0),RGB(0,254,0),RGB(0,253,0),RGB(2,254,2)看起来相同,但实际上它们是不同的。 Perhaps you should add the tolerance range of colors.
也许您应该添加颜色的公差范围。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.