Archived

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

Zackie62

Trouble with loading bitmaps (old school)

Recommended Posts

Hello everybody, I am currently working on an own bitmap loader for direct draw 7 with C++. I dont''t want to use the win32 api func loadimage()! Here is my current code: int LoadBitmap(char* filename,LPDIRECTDRAWSURFACE7 surface) { BITMAPFILEHEADER bitmapfileheader; BITMAPINFOHEADER bitmapinfoheader; FILE *file; HDC hdc; file = fopen(filename,"rb"); if(file == NULL) { LogPrint("Can''t find the file!"); return(0); } fread(&bitmapfileheader,sizeof(BITMAPFILEHEADER),1,file); fread(&bitmapinfoheader,sizeof(BITMAPINFOHEADER),1,file); ///How can I load the bitmap data here ///and create a HBITMAP with it? fclose(file); return(1); } I would be very happy if someone could help me with my problem! If you have any questions or suggestions post it right here! Thanks in advance! Bye, Zackie62

Share this post


Link to post
Share on other sites
I would just use the API. Newer BMP files can actually be disguised jpeg and png files, and writing all that code to decompress them yourself is not fun. If you are just dealing with old 24 bit uncompressed bitmap files, then after you read in the header, just read in the rest of the file into a buffer in memory (the rest of the file is just triple bytes of RGB). You can figure out the size of the buffer by looking at the length of the file (file length - size of headers) or by getting the dimensions of the image from the header (width * hieght * 3 bytes per pixel). Now use CreateDIBSection and pass it your bitmapinfoheader and a pointer to you buffer containing the pixel information and you get back a HBITMAP.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wcesdkr/htm/_wcesdk_win32_createdibsection.asp

Share this post


Link to post
Share on other sites