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

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

    There is also this neat little extension method:

    static class ExtensionMethods
    {
        public static Color ToColor(this uint argb)
        {
            return Color.FromArgb((byte)((argb & -16777216)>> 0x18),      
                                  (byte)((argb & 0xff0000)>> 0x10),   
                                  (byte)((argb & 0xff00) >> 8),
                                  (byte)(argb & 0xff));
        }
    }
    

    In use:

    Color color = 0xFFDFD991.ToColor();
    

提交回复
热议问题