Jump to content
  • Advertisement


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

The Reindeer Effect

Loading A BMP

This topic is 5981 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 am having some problems with a little project of mine. I really haven''t learned C file I/O functions the way I should have I assume. Anyways ... I can load the BITMAPFILEHEADER and BITMAPINFOHEADER just fine. Since it is a 24-bit bmp, I assume that means that there is no pallete. So I go directly onto trying to load the pixel data ... but I have no clue how to. I had planned to store the pixel data in - BYTE* pData; Whenever I find the biWidth and biHeight, I do - pData = new BYTE[ 3 * biWidth * biHeight]. Then: temp = 3 * biWidth * biHeight; for( int i = 0; i < temp; i++) fread( &pData, sizeof( BYTE ), 1, in ); for some reason I am having problems ... cuz I impelented a test. I tried to output all the data basically the same way i got it, cept i used fwrite( .. ); When I try to open the file, it says not a current bmp file formay. After tinkering for 20 minutes, I have only managed to make a 593 mb file, the original is like 50k ------------------- The Reindeer Effect

Share this post

Link to post
Share on other sites
Here's my code for reading Windows bitmaps. It's fairly easy to understand, even though it's very non-standard code:

using namespace gPixmapFormat;

gImageWinBmpHeader Header;
gImageWinBmpInfoHeader Info;
unsigned int ByteWidth, BytesPP, DataSize, Shift;


/* This doesn't ever seem to work for me ;)
if(Header.OffBits > (14 + 40))
File.Seek(Header.OffBits - (14 + 40),SEEK_CUR);

// Flip little endian data to native endian data


if(Header.Type != 0x4D42) {
gError("This isn't a Win32 bitmap.");
if(Info.BitCount != 24) {
gError("This bit depth isn't supported.");

BytesPP = Info.BitCount/8;
ByteWidth = Info.Width * BytesPP;
DataSize = ByteWidth * Info.Height;
Shift = ByteWidth % 4;


if(Shift == 0) {
} else { // Yeah, padding...

for(unsigned int a=0; a<Info.Height; ++a) {



About that last part: Are you loading and saving it in binary mode (the default in Windows is text mode)?

[edited by - Null and Void on June 2, 2002 10:10:05 PM]

Share this post

Link to post
Share on other sites
Sorry about the ''update right after I post'' thing, I hit reply too quickly.
Original post by The Reindeer Effect
What headers / libs do I need to use that?

Well, you''d need most of my GTW engine . I was posting it as a ''reference'' for you to go by. Some notes: My file functions are based directly off the C file I/O functions (but they throw exceptions on error), and my gWinBmp*Header structs are just like the Win32 API''s BITMAP*HEADER structs (I needed my own copy to maintain portability).

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!