Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Store RGB values in database

I never had to do this before and never even thought about this before. How can i or what is the best way of storing RGB values in the database.

I thought of couple of options. The most obvious one being 3 byte columns to store the R,G and the B.(I dont want to go this route) Another option is to store it in a 32 bit int column. ( I am leaning towards this one)

or may be i am just missing something trivial.

like image 916
ps. Avatar asked Nov 24 '09 22:11

ps.


People also ask

Why is RGB 255 not 256?

Each channel (Red, Green, and Blue are each channels) is 8 bits, so they are each limited to 256, in this case 255 since 0 is included.

What data type is RGB?

Java's Color data type represents color values using the RGB color model where a color is defined by three integers (each between 0 and 255) that represent the intensity of the red, green, and blue components of the color. Other color values are obtained by mixing the red, blue and green components.

Why are RGB values 255?

In RGB, a color is defined as a mixture of pure red, green, and blue lights of various strengths. Each of the red, green and blue light levels is encoded as a number in the range 0.. 255, with 0 meaning zero light and 255 meaning maximum light.


1 Answers

The "wasted" space of 32-bit integer column would allow you to store an alpha channel as well, should the need ever arise for it.

like image 125
mwcz Avatar answered Oct 04 '22 03:10

mwcz