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

前端 未结 16 1132
不思量自难忘°
不思量自难忘° 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 07:18

    I needed to convert a HEX color code to a System.Drawing.Color, specifically a shade of Alice Blue as a background on a WPF form and found it took longer than expected to find the answer:

    using System.Windows.Media;
    

    --

    System.Drawing.Color myColor = System.Drawing.ColorTranslator.FromHtml("#EFF3F7");
    this.Background = new SolidColorBrush(System.Windows.Media.Color.FromArgb(myColor.A, myColor.R, myColor.G, myColor.B));
    

提交回复
热议问题