Convert color to byte value

后端 未结 4 918
南方客
南方客 2021-01-28 15:28

In C#, how can I convert a Color object into a byte value?

For example, the color #FFF would be converted to the value 255

4条回答
  •  被撕碎了的回忆
    2021-01-28 16:12

    You can use ConvertFromString() method from ColorConverter class.

    Attempts to convert a string to a Color.

    Return Value
    Type: System.Object
    A Color that represents the converted text.
    

    ColorConverter c = new ColorConverter();
    Color color = (Color)c.ConvertFromString("#FFF");
    Console.WriteLine(color.Name);
    

提交回复
热议问题