#### Archived

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

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

## 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 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;File.Read(&Header,14,1);File.Read(&Info,40,1);/* 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 datagEndianFixLittle(Header.OffBits);gEndianFixLittle(Header.Type);gEndianFixLittle(Info.Width);gEndianFixLittle(Info.Height);gEndianFixLittle(Info.BitCount);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;This->SetBytesPP(BytesPP);This->SetWidth(Info.Width);This->SetHeight(Info.Height);This->SetData(gNewArray(gByte,DataSize));This->SetFreeMem(true);if(Shift == 0) {	File.Read(This->GetData(),1,DataSize);} else { // Yeah, padding...	for(unsigned int a=0; a<Info.Height; ++a) {		File.Read(This->GetData(),1,ByteWidth);		File.Seek(Shift,SEEK_CUR);	}}This->SetFormat(External::BGR);This->FlipVert();

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 on other sites
What headers / libs do I need to use that?

[edited by - The Reindeer Effect on June 2, 2002 10:13:07 PM]

##### Share on other sites
Sorry about the ''update right after I post'' thing, I hit reply too quickly.
quote:
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 on other sites
ttt

-------------------
The Reindeer Effect

##### Share on other sites
Allright, thanks.

-------------------
The Reindeer Effect

##### Share on other sites
AHHHHHHH ... I think it was because I thought that only the pixel data was in little endian.

-------------------
The Reindeer Effect