while(...)
{
Color crPixel;//假设这个是遍历得到的每个像素颜色值
....
if (mapSt.ContainsKey(crPixel))
{
mapSt[crPixel]=mapSt[crPixel]+1;
}
else
{
mapSt[crPixel]=1;
}
}
//mapSt里就是每个颜色值的像素数目,取出最多一个就可以
Color crMax;
int nMaxCount=-1;
bool bSet=false;
foreach(KeyValuePair<Color,int> rPair in mapSt)
{
if (!bSet||rPair.Value>nMaxCount)
{
crMax=rPair.Key;
nMaxCount=rPair.Value;
}
}