0

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;
Bridge
  • 29,818
  • 9
  • 60
  • 82
Tom Rider
  • 2,747
  • 7
  • 42
  • 65

2 Answers2

1

Use the built in ColorTranslator.ToHtml

string hex = ColorTranslator.ToHtml(myColor);
PaulB
  • 23,264
  • 14
  • 56
  • 75
0

Simply like this

string hex = "#" + rgb.R.ToString("X2") + rgb.G.ToString("X2") + rgb.B.ToString("X2");
Prasanna
  • 4,583
  • 2
  • 22
  • 29