Best way to represent a color in a SQL Database?

前端 未结 6 1147
情歌与酒
情歌与酒 2021-01-12 04:14

If I am using .Net and SQL Server 2008, what is the best way for me to store a color in the database, should I use ToString or convert it to an integer, or something else?

6条回答
  •  一向
    一向 (楼主)
    2021-01-12 04:21

    Depends so much on the type of color you want to store. Eg. if it is from a fixed palette then a short int or even an unsigned byte might be sufficient.

    3 byte RGB or 4 byte ARGB (A=alpha, ie. transparency) could fit into 32 bit, so a 32 bit unsigned integer type would work. This is the standard for most applications. However, you might want more - in which case a 64 bit unsigned integer might be required.

    Alternatively, if you want to modify or query the color according to its components, I would store each component as its own unsigned int (ie. Red, Green, Blue, Alpha fields).

提交回复
热议问题