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:
Bitmap RGB Array - Newbie
Started by hug-hes, Dec 05 2006 02:46 PM
6 replies to this topic
#1
Posted 05 December 2006 - 02:46 PM
#2
Posted 05 December 2006 - 03:54 PM
Assuming your bitmap stores 32-bits per component u would do it as follows.
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!
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!
#3
Posted 05 December 2006 - 03:56 PM
can u explain what this means?
#4
Posted 05 December 2006 - 04:01 PM
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.
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.
#5
Posted 05 December 2006 - 04:10 PM
thanku for your help!
I am still having trouble loading my bitmap file
I am still having trouble loading my bitmap file
#6
Posted 05 December 2006 - 04:14 PM
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 :)
#7
Posted 05 December 2006 - 04:16 PM
I will check it out thanks
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











