Convert int to System.Drawing.Brushes.SomeColor?

1.6k Views Asked by At

I imagine those System.Drawing.Brushes.SomeColor can eventually break down to some numbers, or vectors perhaps, such as 0 is black and 255 is white in a 8-bit gray scale representation.

So I am wondering is there any chance an integer can be converted to System.Drawing.Brushes.SomeColor? Or perhaps an integer array like (a,a,a), where int a = someNumber;

Thanks.

2

There are 2 best solutions below

0
On BEST ANSWER

You can use the Color.ToArgb and Color.FromArgb to convert color values to integers:

int blueInt = System.Drawing.Color.Blue.ToArgb();
var colorBlue = System.Drawing.Color.FromArgb(blueInt);

You can create a solid brush from a color like so:

SolidBrush sb = new SolidBrush(blueColor);
0
On

You cant convert an integer directly, but you can create one from an RGB set:

Color.FromArgb (MSDN)

Will take an set of ints as you expect, one for red, one for green, and one for blue. A different overload of that method allows you to specify the alpha value.

You then create a brush from the color:

Brush myBrush = new SolidBrush(myColor);

(MSDN)