如何在 vb.net 中获得颜色的 RGB 数值等价物

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5837996/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 15:28:56  来源:igfitidea点击:

how to get RGB numerical equivalent of color in vb.net

vb.netwinformscolorsbackground-colorcolor-scheme

提问by vaichidrewar

net there are many standard colors are available . But how to know there numerical value. I want those numerical values so that by changing those I can obtain the required shades which are not available as standard colors.

网有许多标准颜色可供选择。但是如何知道那里的数值。我想要这些数值,以便通过更改这些数值,我可以获得所需的色调,而这些色调不能作为标准颜色使用。

E.g for black we know numerical RGB equivalent is 0, 0, 0 But what are RGB values for olive color?

例如,对于黑色,我们知道数字 RGB 等效值是 0, 0, 0 但是橄榄色的 RGB 值是多少?

how to do this color name to numeric RGB value conversion

如何将此颜色名称转换为数字 RGB 值

回答by MusiGenesis

The Colorstruct has .A, .R, .Gand .Bfields.

Color结构有.A.R.G.B领域。

For example:

例如:

Dim color As Color = Color.Olive
Dim r As Integer = color.R
Dim g As Integer = color.G
Dim b As Integer = color.B

回答by Bobort

Since all of the colors are of the Color object, you simply need to instantiate the color and call the Color methods that you want to.

由于所有颜色都属于 Color 对象,因此您只需实例化颜色并调用所需的 Color 方法。

You probably want something like this:

你可能想要这样的东西:

Console.Write(Color.Olive.R & " " & Color.Olive.G & " " & Color.Olive.B)

回答by user1390931

Public Function Color2Integer(ByVal c As Color) As Integer
     Return c.ToArgb
End Function

Public Function Integer2Color(ByVal colorValue As Integer) As Color
    Return Color.FromArgb(colorValue)
End Function