Tom Rider
Tom Rider

Reputation: 2815

Generate a color object from string color

I want to convert RGB string to hex-color code. For example :

   string rgb = rgb(0, 0, 255);

From above RGB I want to get:

   string hex = #0000FF;

Upvotes: 0

Views: 143

Answers (2)

PaulB
PaulB

Reputation: 24382

Use the built in ColorTranslator.ToHtml

string hex = ColorTranslator.ToHtml(myColor);

Upvotes: 1

Prasanna
Prasanna

Reputation: 4703

Simply like this

string hex = "#" + rgb.R.ToString("X2") + rgb.G.ToString("X2") + rgb.B.ToString("X2");

Upvotes: 0

Related Questions