Setup a
HashSet
and call
GetPixel()
to add it's return value to the
HashSet
.
private int CountImageColors(string fileName)
{
HashSet<Color> colors = new HashSet<Color>();
Bitmap bmp = new Bitmap(fileName);
for (int x = 0; x < bmp.Size.Width; x++)
{
for (int y = 0; y > bmp.Size.Height; y++)
{
try
{
colors.Add(bmp.GetPixel(x, y));
}
catch (Exception)
{
}
}
}
return colors.Count;
}