Save memory DC to file

Started by
3 comments, last by SiCrane 15 years, 3 months ago
I am drawing to a memory DC and I need to save it as BMP file... what is the function for this? Thanks
Advertisement
There's no Win32 function to do that unfortunately (Like LoadImage()), but there's plenty of code samples to do that on Google. This One looks promising.
hmmm... microsoft could have make it less complicated

Thanks for the link! The code works but leaks somewhere in SaveBMPFile function.
Quote:Original post by davidcoleman
hmmm... microsoft could have make it less complicated

Thanks for the link! The code works but leaks somewhere in SaveBMPFile function.
Hmm, so it does. You'll need to delete[] lpbi and lpvBits before exiting the function (Which is in all those return 0; cases), or use a std::vector<char> and have them automatically destroyed when they go out of scope (Which is what I'd recommend if you're using C++).
There are less complicated ways to do it. Ex: use GDI+'s Bitmap::FromHBITMAP to create a Bitmap object and then use the Save() member function to save it to a file.

This topic is closed to new replies.

Advertisement