如何从RGB值中获取颜色名称、重点颜色和较浅或较深的比例在C#中?

huangapple go评论91阅读模式
英文:

How to get color name, accent color and lighter or darker ratio from RGB value in C#?

问题

我正在尝试从图像中获取颜色信息的字符串,但如何从像这样的RGB值中获取信息:Excel颜色选择器中的工具提示。请帮助我或告诉我如何从RGB颜色获取字符串信息。

英文:

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.

答案1

得分: 0

你可以使用字典将颜色值映射到名称或已知的X11颜色。但是对于类似办公室的颜色,没有内置的选项。

要进行更高级的处理,你可能需要将RGB转换为HSL。这将为你提供单独的色相、饱和度和亮度通道。然后你需要为每个名称定义范围,例如 if(hue > 100 && hue < 140) return "green"

但是这可能很快变得复杂,因为特定的颜色实际上是颜色体积的一部分,不同的人对边界的看法会不同。在你称其为黑色之前,某物需要有多暗?因此,我建议你认真考虑你真正想要做什么,以及是否有其他方法可以实现它。

英文:

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 &gt; 100 &amp;&amp; hue &lt; 140) return &quot;green&quot;

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.

huangapple
  • 本文由 发表于 2023年5月25日 14:29:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/76329465.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定