Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
i have image
this image has colors
how i can add this image to byte array
to get number of color in byte
thanks for any help
Posted
Comments
Sandeep Mewara 11-Feb-11 9:25am    
Not clear.

Setup a HashSet and call GetPixel() to add it's return value to the HashSet.

C#
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;
}
 
Share this answer
 
v7
Comments
Sergey Alexandrovich Kryukov 11-Feb-11 13:05pm    
Ultimate solution? A 5.
--SA
TweakBird 11-Feb-11 13:44pm    
Good one. have a 5.
BillW33 21-Aug-12 12:23pm    
Nice answer, +5
Member 11499903 13-Mar-15 2:03am    
i upload a image using textbox,button and picturebox.Now i have to find the color of an image and say what color its.I want this coding in c#.send the answer its urgent
Assuming you have the image as a Bitmap object, you can call GetPixel.

See http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.getpixel.aspx[^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 11-Feb-11 13:04pm    
Enough said (or, may be not enough, see John's answer), a 5.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900