Advertisement

How can i write a CBitmap or HBitmap to disk?

Started by August 23, 2001 04:01 AM
3 comments, last by Zeke 23 years, 5 months ago
Im not sure what Im doing wrong but I just cant get this to work. These are the steps im taking:

//i do :
//FullImage is a CBitmap*....CBitmap* FullImage=new CBitmap();
//
BITMAP bmp;
//
FullImage->GetBitmap(&bmp);
//
//for some reason the bmp.biBits is empty so i do this:
//
LPBYTE lpBits = (LPBYTE) GlobalAlloc(GMEM_FIXED,        
                            bmInfo.bmiHeader.biSizeImage);
//
FullImage->GetBitmapBits( bmInfo.bmiHeader.biSizeImage, 
                         (LPVOID) lpBits ) ;
//
//lpBits isnt empty however it has some weird symbols if I look
//at it in the quick watch window while debugging????
//
BITMAPFILEHEADER bmfh;//i fill this in
BITMAPINFO bmInfo;//i fill this in
//
//then write out the bitmap fileheader and bitmapinfoheader
//File is a CFile
//
File.Write(&bmfh,sizeof(BITMAPFILEHEADER))
File.Write(&bmInfo.bmiHeader,sizeof(bmInfo.bmiHeader));
//
//then write out the bitmap bits
File.Write((LPSTR)lpBits,bmInfo.bmiHeader.biSizeImage);

     
Everything seems to go fine and i open up my newly created bmp in mspaint but its empty just a blank white bmp with the correct dimmensions but no picture. If instead of writing it to file I display it in a CListCtrl it shows up fine. The reason I ask about how to do thid with a HBITMAP is because I can get the HBITMAP associated with the CBitmap by using the CBitmap::operator HBITMAP() but i dont know how to save that to disk either. Can anyone tell me what im doing wrong? Thanks for any help you can offer
Just my thoughts take them as you will. "People spend too much time thinking about the past, whatever else it is, its gone"-Mel Gibson, Man Without A Face
CBitmap is a class.. It contains code. It''s should not be saved to disk.
------------------------------------------------------------I wrote the best video game ever, then I woke up...
Advertisement
CBitmaps not really good. Take Nehe's 6th tutorial, he shows a nice way of loading a bmp, and its alot cleaner. there also a function called write bmp you need to use. and glGetPixels

"I''ve sparred with creatures from the nine hells themselves... I barely plan on breaking a sweat here, today."~Drizzt Do''Urden

Edited by - Drizzt DoUrden on August 23, 2001 12:16:45 AM
------------------------------Put THAT in your smoke and pipe it
Galileo430>I know CBitmap is a class, what I meant was how do I save the bitmap that is attached or whatever to the CBitmap.

Drizzt DoUrden>Thanks for the tip but ive figured out how to do it now.

Thanks for the replies

Just my thoughts take them as you will. "People spend too much time thinking about the past, whatever else it is, its gone"-Mel Gibson, Man Without A Face
Please don''t confuse a "DIB" with a regular "BMP" or device-dependent bitmap...
VK

This topic is closed to new replies.

Advertisement