-1

I am trying to get string of color information from an image, but how to get that information from RGB value like this one:Tool tip in excel color selector

Please help me or tell me what can I do to get string information from RGB color.

NV Linh
  • 3
  • 4
  • 3
    None of that exist in C#. The best you can do is `Color.ToString()` but that will only output text for KnownColors: https://learn.microsoft.com/en-us/dotnet/api/system.drawing.knowncolor?view=net-7.0. Just FYI: That excel dialog is based on the Theme: https://support.microsoft.com/en-us/office/change-a-theme-and-make-it-the-default-in-word-or-excel-c846f997-968e-4daa-b2d4-42bd2afef904#bkmk_create with only 12 base colors and then 6 gradients generated for each color. That is a palette that won't be able to capture any of the color range found in an image. – rene May 25 '23 at 06:50
  • 1
    There are 256*256*256, so over 16 million possible RGB colors. It seems unlikely that any language has such many words for colors. – Klaus Gütter May 25 '23 at 07:03

1 Answers1

0

You could use a dictionary to map color values to either names or known X11 colors. But there is nothing builtin for office like colors.

To do any more advanced processing you likely need to convert RGB to HSL. This give you separate channels for Hue, Saturation, and Lightness. You would then need to define ranges for each name, i.e. if(hue > 100 && hue < 140) return "green"

But that will likely quickly become complicated, since a specific color is in effect section of a color volume, and different people will disagree about where the borders are. How dark does something need to be before you would call it black? So I would take a long hard think about what you really want to do, and if there are any other ways to do it.

JonasH
  • 28,608
  • 2
  • 10
  • 23