This topic is now archived and is closed to further replies.


Loading bitmaps

Recommended Posts

Arghhh! Loading images is so hard. Currently I''m loading bitmaps, and have loaded the file header and info (which includes infoheader and rgbquad structures). All done correctly, i''ve checked the bit depth and all that rot with it -- just assume..., And now I need to find the actual image data. I''ve got it to something like: fseek(file, -imagesize, SEEK_END); but then how would I read it in? It''s a 24 bit bitmap, where, how, etc, do I retreive and store the actual pixel information? I need some help bad... Thanks! Sponge99

Share this post

Link to post
Share on other sites

unsigned char * imagedata;
imagedata = new unsigned char[SizeOfData];
fread(imagedata, sizeof(unsigned char), SizeOfData, fp);

every 3 bytes in the imagedata buffer = 1 pixel;

Byte 1 = Red
Byte 2 = Green
Byte 3 = Blue

Share this post

Link to post
Share on other sites
Here's the code I have:
BYTE * bmpbuffer = (BYTE*) malloc(bmi.bmiHeader.biSizeImage);
memset(&bmpbuffer, 0, bmi.bmiHeader.biSizeImage);
fseek(bmpfile, -(int)bmi.bmiHeader.biSizeImage, SEEK_END);
fread(&bmpbuffer, bmi.bmiHeader.biSizeImage, 1, bmpfile);

memset(&ddsd, 0, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);

USHORT * vid = (USHORT*) ddsd.lpSurface;

for (x = y = i = 0; y < bmi.bmiHeader.biHeight; x++)
vid[x+y*(ddsd.lPitch >> 1)] = RGB16BIT_565(bmpbuffer[i*3+0],bmpbuffer[i*3+1],bmpbuffer[i*3+2]);

if (x > bmi.bmiHeader.biWidth)
x = -1; // will be ++'ed



So...I'm reading all of the image data (correct?) into a buffer, defined as the size of bytes of the image. Then, each three bytes in that buffer should be the RGB (in bmp, BGR?) values. When I use this code, it writes a bunch of junk pixels. I don't get it!! What's goin' wrong?

The bmp is 24-bit, not compressed (RGB compression value)


Edited by - Sponge99 on August 7, 2001 9:43:49 AM

Share this post

Link to post
Share on other sites