Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save a CBitmap to .bmp file

I'm working with a CBitmap object using a CDC. When I'm finished with it I want to save it to a file. I have seen something about a process with that code LINK:

CFile file;
if(file.Open(szFileName, CFile::modeCreate | CFile::modeWrite))
{ 
    file.Write(&bh, sizeof(BITMAPFILEHEADER));
    file.Write(&(bi.bmiHeader), sizeof(BITMAPINFOHEADER));
    file.Write(lpBitmapBits, 3 * nWidth * nHeight);
    file.Close();
}

My doubt is about BITMAPFILEHEADER and BITMAPINFOHEADER. How can I fill them with a given CBitmap or CDC?

like image 318
jabujavi Avatar asked Oct 21 '25 04:10

jabujavi


1 Answers

You could try this:

CImage image;

image.Attach(CDCvar.GetCurrentBitmap());
image.Save(_T(".\\test.bmp"), Gdiplus::ImageFormatBMP);
like image 96
barbarity Avatar answered Oct 25 '25 12:10

barbarity



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!