3

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?

honk
  • 9,137
  • 11
  • 75
  • 83
jabujavi
  • 477
  • 5
  • 15

1 Answers1

6

You could try this:

CImage image;

image.Attach(CDCvar.GetCurrentBitmap());
image.Save(_T(".\\test.bmp"), Gdiplus::ImageFormatBMP);
barbarity
  • 2,420
  • 1
  • 21
  • 29