bernie2436
bernie2436

Reputation: 23941

how can i find the names and RGB values of colors in a .net Palette

I've got a chart showing data as a part of a vb.net forms application. The Chart object makes a really pretty picture, but I need it to match the color scheme on the rest of the UI. How do I get the RGB values for the palette?

Debug.Print(Chart1.Palette.Chocolate.WHAT ARE THE RGB COLORS??!)

Edit 1

Note: Chocolate is both the name of a color and the name of a .net Palette The post above refers to Chocolate the Palette, which contains multiple colors.

Upvotes: 2

Views: 8390

Answers (2)

Olivier Jacot-Descombes
Olivier Jacot-Descombes

Reputation: 112772

The struct System.Drawing.Color has static properties with webcolors:

Color c = System.Drawing.Color.Chocolate;
int r = c.R;
int g = c.G;
int b = c.B;

This will return color names:

foreach (string colorName in Enum.GetNames(typeof(System.Drawing.KnownColor))) {
    Console.WriteLine(colorName);
}

The ToString() method of System.Drawing.Color will return a color name if the color is a known color, otherwise A, R, G, B values:

System.Drawing.Color.Chocolate.ToString()  --> "Color [Chocolate]"
System.Drawing.Color.FromArgb(254).ToString()  --> "Color [A=0, R=0, G=0, B=254]"

A palette is a selected set of colors. This is a palette:

enter image description here

This is another palette:

enter image description here


Finally I found the answer by using .NET Reflector: In the System.Web.UI.DataVisualization.Charting.Utilities namespace there is an internal static class ChartPaletteColors. Since it is internal you can't access it. But reflector shows how the color palettes are initialized. Form this I got the following palettes:

Berry = { BlueViolet, MediumOrchid, RoyalBlue, MediumVioletRed, Blue, BlueViolet, Orchid, MediumSlateBlue, ARGB(0xc0, 0, 0xc0), MediumBlue, Purple }
BrightPastel = { ARGB(0x41, 140, 240), ARGB(0xfc, 180, 0x41), ARGB(0xe0, 0x40, 10), ARGB(5, 100, 0x92), ARGB(0xbf, 0xbf, 0xbf), ARGB(0x1a, 0x3b, 0x69), ARGB(0xff, 0xe3, 130), ARGB(0x12, 0x9c, 0xdd), ARGB(0xca, 0x6b, 0x4b), ARGB(0, 0x5c, 0xdb), ARGB(0xf3, 210, 0x88), ARGB(80, 0x63, 0x81), ARGB(0xf1, 0xb9, 0xa8), ARGB(0xe0, 0x83, 10), ARGB(120, 0x93, 190) }
Chocolate = { Sienna, Chocolate, DarkRed, Peru, Brown, SandyBrown, SaddleBrown, ARGB(0xc0, 0x40, 0), Firebrick, ARGB(0xb6, 0x5c, 0x3a) }
Default = { Green, Blue, Purple, Lime, Fuchsia, Teal, Yellow, Gray, Aqua, Navy, Maroon, Red, Olive, Silver, Tomato, Moccasin }
Earth = { ARGB(0xff, 0x80, 0), DarkGoldenrod, ARGB(0xc0, 0x40, 0), OliveDrab, Peru, ARGB(0xc0, 0xc0, 0), ForestGreen, Chocolate, Olive, LightSeaGreen, SandyBrown, ARGB(0, 0xc0, 0), DarkSeaGreen, Firebrick, SaddleBrown, ARGB(0xc0, 0, 0) }
Excel = { ARGB(0x99, 0x99, 0xff), ARGB(0x99, 0x33, 0x66), ARGB(0xff, 0xff, 0xcc), ARGB(0xcc, 0xff, 0xff), ARGB(0x66, 0, 0x66), ARGB(0xff, 0x80, 0x80), ARGB(0, 0x66, 0xcc), ARGB(0xcc, 0xcc, 0xff), ARGB(0, 0, 0x80), ARGB(0xff, 0, 0xff), ARGB(0xff, 0xff, 0), ARGB(0, 0xff, 0xff), ARGB(0x80, 0, 0x80), ARGB(0x80, 0, 0), ARGB(0, 0x80, 0x80), ARGB(0, 0, 0xff) }
Fire = { Gold, Red, DeepPink, Crimson, DarkOrange, Magenta, Yellow, OrangeRed, MediumVioletRed, ARGB(0xdd, 0xe2, 0x21) }
Light = { Lavender, LavenderBlush, PeachPuff, LemonChiffon, MistyRose, Honeydew, AliceBlue, WhiteSmoke, AntiqueWhite, LightCyan }
Pastel = { SkyBlue, LimeGreen, MediumOrchid, LightCoral, SteelBlue, YellowGreen, Turquoise, HotPink, Khaki, Tan, DarkSeaGreen, CornflowerBlue, Plum, CadetBlue, PeachPuff, LightSalmon }
SeaGreen = { SeaGreen, MediumAquamarine, SteelBlue, DarkCyan, CadetBlue, MediumSeaGreen, MediumTurquoise, LightSteelBlue, DarkSeaGreen, SkyBlue }
SemiTransparent = { ARGB(150, 0xff, 0, 0), ARGB(150, 0, 0xff, 0), ARGB(150, 0, 0, 0xff), ARGB(150, 0xff, 0xff, 0), ARGB(150, 0, 0xff, 0xff), ARGB(150, 0xff, 0, 0xff), ARGB(150, 170, 120, 20), ARGB(80, 0xff, 0, 0), ARGB(80, 0, 0xff, 0), ARGB(80, 0, 0, 0xff), ARGB(80, 0xff, 0xff, 0), ARGB(80, 0, 0xff, 0xff), ARGB(80, 0xff, 0, 0xff), ARGB(80, 170, 120, 20), ARGB(150, 100, 120, 50), ARGB(150, 40, 90, 150) }

The GrayScale palette is determined by: gray value = 200 - (i * 11) where i ranges from 0 to 15.

Upvotes: 4

George Johnston
George Johnston

Reputation: 32278

Chocolate is within the System.Drawing.KnownColor enumeration. Hence you can do the following to get it's ARGB values, e.g.

Dim c As Color = Color.FromKnownColor(KnownColor.Chocolate)
Byte a = c.A
Byte r = c.R
Byte g = c.G
Byte b = c.B

Or simply,

Color.FromKnownColor(KnownColor.Chocolate).A ...

Upvotes: 1

Related Questions