Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C#/CSS: Convert bytes to CSS hex string

Tags:

c#

hex

byte

Let's say I have these bytes:

byte red = 0;
byte green = 0;
byte blue = 255;

And I want to turn it into the six-character string hex representation you see in CSS (e.g. "#0000ff"):

How can I do this?

like image 780
FoobarisMaximus Avatar asked Jul 07 '11 03:07

FoobarisMaximus


1 Answers

Color c = Color.FromArgb(red, green, blue);
var hexColor = System.Drawing.ColorTranslator.ToHtml(c);

should produce "0000FF"

See MSDN

like image 71
Bala R Avatar answered Sep 28 '22 10:09

Bala R