How do I get the color from a hexadecimal color code using .NET?

前端 未结 16 775
不思量自难忘°
不思量自难忘° 2020-11-22 06:45

How can I get a color from a hexadecimal color code (e.g. #FFDFD991)?

I am reading a file and am getting a hexadecimal color code. I need to create the

16条回答
  •  旧巷少年郎
    2020-11-22 06:55

    Assuming you mean the HTML type RGB codes (called Hex codes, such as #FFCC66), use the ColorTranslator class:

    System.Drawing.Color col = System.Drawing.ColorTranslator.FromHtml("#FFCC66");
    

    If, however you are using an ARGB hex code, you can use the ColorConverter class from the System.Windows.Media namespace:

    Color col = ColorConverter.ConvertFromString("#FFDFD991") as Color;
    //or      = (Color) ColorConverter.ConvertFromString("#FFCC66") ;
    

提交回复
热议问题