PDA

View Full Version : Bitmap RGB Array - Newbie


hug-hes
12-05-2006, 06:46 AM
I need to write a C++ program to give me the RGB values for a bitmap image so that I can calculate different areas of colours in the image.

Any help would be appreciated!!:yes:

Goz
12-05-2006, 07:54 AM
Assuming your bitmap stores 32-bits per component u would do it as follows.


unsigned int uRGB = ((unsigned int*)pBitmap)[x + (y * width)];
unsigned char uR = (uRGB & 0x00ff0000) >> 16;
unsigned char uG = (uRGB & 0x0000ff00) >> 8;
unsigned char uB = (uRGB & 0x000000ff) >> 0;


Of course this assumes that its 32-bit and that R, G and B are in that order. If not you have to modify that basic algorithm a little bit.

Hope that helps!

hug-hes
12-05-2006, 07:56 AM
can u explain what this means?

Goz
12-05-2006, 08:01 AM
Ok .. "width" is the bitmap's width. "x" is the x coordinate position and "y" is the y coordinate position.

The code above looks up a 32-bit value from the bitmap at (x,y) and then breaks the value up into individual RGB components.

hug-hes
12-05-2006, 08:10 AM
thanku for your help!

I am still having trouble loading my bitmap file

Goz
12-05-2006, 08:14 AM
Hmmm ... if you are trying to load a .bmp directly you may find www.wotsit.org useful. It describes numerous file formats ... including the bmp format :)

hug-hes
12-05-2006, 08:16 AM
I will check it out thanks