【发布时间】:2011-07-09 11:32:32
【问题描述】:
我正在为第二个屏幕开发一个任务栏(类似于 displayfusion)。
但是,我很难从图标中获得正确的平均颜色。例如谷歌浏览器/当我将它悬停在主任务栏上时,它的背景变成黄色。使用我的代码,它变成橙色/红色。
这就是现在的样子:
如何获得正确的主色/平均色?
我使用这段代码来计算平均颜色:
public static Color getDominantColor(Bitmap bmp)
{
//Used for tally
int r = 0;
int g = 0;
int b = 0;
int total = 0;
for (int x = 0; x < bmp.Width; x++)
{
for (int y = 0; y < bmp.Height; y++)
{
Color clr = bmp.GetPixel(x, y);
r += clr.R;
g += clr.G;
b += clr.B;
total++;
}
}
//Calculate average
r /= total;
g /= total;
b /= total;
return Color.FromArgb(r, g, b);
}
【问题讨论】:
-
这里有一个类似的问题:*.com/questions/5823854/…