Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello.

I am VERY new to C#. Is there a function that will give me a count of the distinct colors in a bitmap? How about a function that lists all these distinct colors?

Many thanks!
Posted

A slow but sure approach to this would be to get every pixel in the bitmap and store the color of this pixel. This way you will be able to get all colors that make your bitmap.

Search on the internet and you should get some samples to get a pixel on your bitmap.
 
Share this answer
 
I was hoping to do this with a byte array. I created the byte array but I'm having issues retrieving the RGB values. Am I on the wrong track? Thanks!
 
Share this answer
 
There is no single function built in to the .Net framework to give you histogram data like this for a bitmap. If you are using the System.Drawing.Bitmap[^] class, you can use the LockBits[^] method to get an BitmapData[^] object with a pointer to the image data and all the information you need about how to access it.
 
Share this answer
 

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