Is it possible to determine the hexadecimal colour value for an image in C#, if the image is a single block colour?
I have a load of colour chart images, and need to put them into a table with the requisite hex value attached. Unfortunately, the file name is useless to determine this.
Regards
Moo
I would use Bitmap.GetPixel to get the color and then convert it to hex using ColorTranslator.ToHtml.
// Load the bitmap
Bitmap bitmap = new Bitmap("test.gif");
// Get color from top left corner
Color color = bitmap.GetPixel(0, 0);
// Convert it to hex
String htmlColor = System.Drawing.ColorTranslator.ToHtml(color);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With