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

24,278

Solution 1

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.

You probably want something like this:

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

Solution 2

The Color struct has .A, .R, .G and .B fields.

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

Solution 3

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
Share:
24,278
vaichidrewar
Author by

vaichidrewar

@Bloomreach

Updated on November 14, 2020

Comments

  • vaichidrewar
    vaichidrewar over 3 years

    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?

    how to do this color name to numeric RGB value conversion

  • nantito
    nantito about 13 years
    A super-tiiiiny correction: Color struct has those values. And the properties of Colors class (aka the Named colors) return a Color struct :)
  • Paul Creasey
    Paul Creasey about 13 years
    @nantito, The Named colors are just static properties of the Color structure that return struct, there are no classes involved.
  • nantito
    nantito about 13 years
    Yes. But Named colors are also properties of the Colors class. But anyhow, my point was that Color is a struct in the first period. The rest was just an addition. All set and clear! Thanks.
  • MusiGenesis
    MusiGenesis about 13 years
    @nantito: not that tiny - I am shamed. I don't really tend to notice whether something I'm working with in .Net is a class or a struct, so long as that difference doesn't affect whatever it is I'm trying to accomplish.