从图像获取一个配色方案 [英] Getting a Colour Scheme from an Image
问题描述
我要开发像一个这里功能的基本工具。我将采取一些网页的截图,并从那里我希望在前五名最流行的色彩,并从那里不知何故决定颜色是否是一个很好的搭配。
I want to develop a basic tool like the one featured here. I will be taking screenshots of a number of web pages and from there I wish to take the top five most popular colours and from there somehow decide whether the colours are a good match.
我想用C#这个工具和一些研究之后,我发现lockbits。我的第一个想法是拍摄图像,然后让每个像素的颜色,但我不确定这是否会给我我想要的结果,以及如何使最流行的颜色六个名单。
I want to write this tool in C# and after a bit of research I discovered lockbits. My first idea was to take an image and then get the colour of each pixel, but I am unsure as to whether this will give me the results I desire and how to make six lists of the most popular colours.
在这里任何人都可以提供意见,以我将如何创建一个程序做类似上述程序的东西,这将图像中,将选择图像中使用的前五种颜色?
Can anyone here provide advice as to how I would create a program to do something similar to the program above, that will take in an image and will select the top five colours used in the image?
推荐答案
嗯..使用缩略图(16×16 32×32等),并从中选择颜色像
Well.. Use a thumbnail image (16x16, 32x32 etc) and select from it the colors like
更新的代码:
private void button1_Click(object sender, EventArgs e)
{
int thumbSize = 32;
Dictionary<Color, int> colors = new Dictionary<Color, int>();
Bitmap thumbBmp =
new Bitmap(pictureBox1.BackgroundImage.GetThumbnailImage(
thumbSize, thumbSize, ThumbnailCallback, IntPtr.Zero));
//just for test
pictureBox2.Image = thumbBmp;
for (int i = 0; i < thumbSize; i++)
{
for (int j = 0; j < thumbSize; j++)
{
Color col = thumbBmp.GetPixel(i, j);
if (colors.ContainsKey(col))
colors[col]++;
else
colors.Add(col, 1);
}
}
List<KeyValuePair<Color, int>> keyValueList =
new List<KeyValuePair<Color, int>>(colors);
keyValueList.Sort(
delegate(KeyValuePair<Color, int> firstPair,
KeyValuePair<Color, int> nextPair)
{
return nextPair.Value.CompareTo(firstPair.Value);
});
string top10Colors = "";
for (int i = 0; i < 10; i++)
{
top10Colors += string.Format("\n {0}. {1} > {2}",
i, keyValueList[i].Key.ToString(), keyValueList[i].Value);
flowLayoutPanel1.Controls[i].BackColor = keyValueList[i].Key;
}
MessageBox.Show("Top 10 Colors: " + top10Colors);
}
public bool ThumbnailCallback() { return false; }
这篇关于从图像获取一个配色方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!