Convert color to byte value

后端 未结 4 925
南方客
南方客 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:06

    You can get the byte values of a .NET Color object with:

    byte red = color.R;
    byte green = color.G;
    byte blue = color.B;
    

    That gives you 3 bytes. I don't know how you expect to get a single byte value. Colors are (AFAIK) almost never represented by single bytes.

提交回复
热议问题