🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Reading a bitmap

Started by
1 comment, last by ThaUnknownProgga 24 years, 5 months ago
I''m trying to read a bitmap file. I''m trying to read it but reading in the different parts and putting it together with a call to CreateDIBitmap. Yes I know it would be easy to let API handle it but I don''t want to do it that way. Here''s where I''m getting some problems. I am trying to read the main data of the bitmap, the section with all the colors. I know the bitmap is 24 bit. // bmfh is BITMAPFILEHEADER structure, correctly read in // lpBits is BYTE* SetFilePointer(hBitmapFile, bmfh.bfOffBits, NULL, FILE_BEGIN); lpBits = new BYTE[(bmfh.bfSize - bmfh.bfOffBits)]; ZeroMemory(lpBits, (bmfh.bfSize - bmfh.bfOffBits)); ReadFile(hBitmapFile, (LPVOID)lpBits, (bmfh.bfSize-bmfh.bfOffBits), &dwRead, (LPOVERLAPPED)NULL); However when I try to call CreateDIBitmap it doesn''t work. I think it''s because that above code doesn''t read in the bitmap correctly. help?
Advertisement
Ok, since noone answered that, how about just ghelping me out with some info on reading a bitmap in the way I was asking, without using LoadFile or whatever, reading in each individual part and stuff. Preferably withouf MFCs
Make sure that the header structure is getting read in correctly. I found problems with doing it this way at first because I was reading into a structure. The funny thing with C and C++ is that they will pad structures to better byte or word align the data for more efficient reading and writing. So the data that you read into the structure may be misaligned, which will cause the offset and size params to be wrong, possibly. You might want to see what all the params of your structure are to make sure it is beign read right.

If it is not, then you have to read from the file for each member in the structure.

Also, windows bitmaps, should have a 54 byte header, I believe. So your image size in the structure should be the sizze of your file minus 54 bytes.

This topic is closed to new replies.

Advertisement