RonMexico
asked on
C++ / MFC, rendering to a local CPaintDC and saving to file
So, as I said in an earlier post I've been trying to write some MFC C++ code to (1) create a CPaintDC, (2) render to it, and (3) save it to file as a BMP or DIB. And I haven't been able to get this to work, surprisingly.
The code I've cobbled together from doc and samples is below, but for some reason it just outputs a black/null square. (I should be drawing a green square.)
Can anyone see any problems with this code?
Thanks *very* much for any help.
The code I've cobbled together from doc and samples is below, but for some reason it just outputs a black/null square. (I should be drawing a green square.)
Can anyone see any problems with this code?
Thanks *very* much for any help.
void CMFCApplication_TestDIBDlg::OnBnClickedButton1()
{
CPaintDC dc(this);
CRect rc;
GetClientRect(rc);
dc.FillSolidRect(rc, 0x0000FF00); // aarrggbb ; green
HBITMAP m_hBmp;
LPBYTE pBits;
BITMAPINFO bmi;
memset(&bmi, 0, sizeof(BITMAPINFO));
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = rc.Width();
bmi.bmiHeader.biHeight = -rc.Height(); // top-down
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 32;
bmi.bmiHeader.biCompression = BI_RGB;
m_hBmp = CreateDIBSection(dc, &bmi, DIB_RGB_COLORS, (void**)&pBits, NULL, NULL);
CImage image;
image.Attach(m_hBmp);
image.Save(L"c:\\dum.bmp", Gdiplus::ImageFormatBMP);
MessageBox(L"Done", L"debug", 0);
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.