I want to get System.Drawing.Color
value in ARGB Hex format, e.g. Color.Red
as ffff0000
in an easy way.
In general, it can be obtained from the Name
property of the System.Drawing.Color
struct:
using System.Drawing;
var color = ColorTranslator.FromHtml("#ff0000");
Console.WriteLine(color.Name);
output: ffff0000
But there is a problem if the value is provided as known color:
using System.Drawing;
var color = Color.Red;
Console.WriteLine(color.Name);
output: Red
I applied the solution from this question to convert System.Drawing.Color
value to RGB code and I prefixed the code with ff
for alpha channel:
var c = System.Drawing.Color.Red;
Console.WriteLine("ff" + c.R.ToString("X2") + c.G.ToString("X2") + c.B.ToString("X2"));
output: ffff0000
but I found another solution that can be used to get ARGB value as Hex code (see the answer below).