Is a question about M$ Visual C++ appropriate to this group?
I would like to know if there is any function (or whatever) that saves a
bitmap to a file. Something as simple as...
BOOL SaveBitmapToFile(CBitmap & cbmp, CString & filename);
In the program below, I copy the screen to a CBitmap [or I hope to;
I haven't tested it, since I can't write it to a file O:-)], but then
I can't write it to the file :-(
Alberto Monteiro
void MyView::OnFileSaveAs()
{
CWnd *wnd = (CWnd *)this; // necessary to get the CDC *
CDC *pDC = this->GetDC(); // get CDC * associated to Window
CDC pDC1; // other CDC
CBitmap *old_bmp, new_bmp; // bitmaps using MFC
BITMAP bmp; // bitmap that doesn't use MFC
if (pDC1.CreateCompatibleDC(pDC) == FALSE)
return; // error
if (new_bmp.CreateCompatibleBitmap(pDC,
pDC->GetDeviceCaps(HORZRES),
pDC->GetDeviceCaps(VERTRES)) == FALSE)
return; // error
/* Select the bitmaps into the compatible DC. */
if ((old_bmp = pDC1.SelectObject(&new_bmp)) == NULL)
return; // error
/*
* Copy color data for the entire display into a
* bitmap that is selected into a compatible DC.
*/
new_bmp.GetBitmap(&bmp); // BITMAP is needed to get bm.information
if (pDC1.BitBlt(0, 0, bmp.bmWidth, bmp.bmHeight,
pDC, bmp.bmWidth, bmp.bmHeight, SRCCOPY) == FALSE)
return; // error
// Start Dialog to create output file
static char szFilter[] =
"BMP File (*.bmp) | *.bmp ||";
CFileDialog fdlg(FALSE, NULL, NULL, NULL, szFilter);
CString name;
if (fdlg.DoModal() == IDOK) {
name = fdlg.GetPathName();
SaveBitmapToFile(new_bmp, name); // How can I do this???
}
pDC1.SelectObject(old_bmp); // restore old object to save memory
}
---
þ SLMR 2.1a þ Sendo animal preferi ser o predador (Raimundos)
--- FMail/386 1.02
---------------
* Origin: CentroIn! +55-21-205-0281, 41 lines, 24h, RJ/Brazil (4:802/21)
|