How are individual pixels represented in memory?

John Zukowski

Each pixel is stored as a 32 bit integer (int). The int packs four unsigned bytes within it, one for each of the alpha, red, green, and blue (ARGB) color planes, in that order.

32 bit pixel

To get at each value, you would use a masking operation and a bit shift :

int alpha = (pixel & 0xff000000) >> 24;
int red   = (pixel & 0x00ff0000) >> 16;
int green = (pixel & 0x0000ff00) >> 8;
int blue  = (pixel & 0x000000ff) >> 0;

Keep in mind that you cannot store each value in a byte as bytes are signed.

0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact