Trouble with loading bitmaps (old school)

Started by
1 comment, last by Zackie62 22 years, 2 months ago
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
Advertisement
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
*push*

This topic is closed to new replies.

Advertisement