Public Group

extracting data from a bitmap

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

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 on other sites
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 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 on other sites
YES! \o/

I knew I was on the right track. =D I haven't gone complete downhill...

1. 1
2. 2
3. 3
frob
15
4. 4
5. 5

• 20
• 12
• 13
• 14
• 81
• Forum Statistics

• Total Topics
632144
• Total Posts
3004414

×