Search code examples
c#colorsnumbersdrawingbrushes

Convert int to System.Drawing.Brushes.SomeColor?


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.


Solution

  • 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);