• Advertisement
Sign in to follow this  

extracting data from a bitmap

This topic is 4047 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a bitmap class which i can use to open bitmap files and i can extract the rgb data from it when it is an 8 bit file but im not sure how to get the rgb data from a 24 bit file. Heres what ive tried so far and it doesnt work properly. fileBody is a char * pointing to the file data, bmih is the bitmapinfoheader and the x and y are the coordinates of the point to find.

returnColour.setRed(fileBody[(y * bmih.biWidth) + (x*4)]);
returnColour.setGreen(fileBody[(y * bmih.biWidth) + (x*4)+1]);
returnColour.setBlue(fileBody[(y * bmih.biWidth) + (x*4)+2]);


Share this post


Link to post
Share on other sites
Advertisement
Well, according to one of my books, the answer is


blue = fileBody[index*3+0]
green= fileBody[index*3+1]
red = fileBody[index*3+2]



where index is 'pointing' to the next pixel, as in a for loop. As far as the y*width and the x being the equivalent for the index, your code might work if you just change the 4's to 3's. But, then again, I haven't messed with this stuff in quite a bit, so. :p Hope that helps.

Share this post


Link to post
Share on other sites
All you have to do to get a color is (remembering that bitmaps are 24-bit BGR files, rather than RGB) is...

blue = fileBody[ (y*width+x)*3 + 0];
green = fileBody[ (y*width+x)*3 + 1];
red = fileBody[ (y*width+x)*3 + 2];

Hope that helps,
~Zix

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement