要在Cimprocess_2Dlg.h中添加:#include
void Cimprocess_2Dlg::Onsave()
{
// TODO: 在此添加命令处理程序代码
CWnd* bmpShow = GetDlgItem(IDC_ShowEdge);
CDC *pdc = bmpShow->GetDC();
//CImage imag;
ATL::CImage imag; //标识符以防不明确
CRect rect;
GetClientRect(&rect); //获取画布大小
bmpShow->GetWindowRect(&rect);
imag.Create(rect.Width(), rect.Height(), 32);
::BitBlt(imag.GetDC(), 0, 0, rect.Width(), rect.Height(), pdc->m_hDC, 0, 0, SRCCOPY);
TCHAR szFilter[] = _T("jpg file(*.jpg)|*.jpg|bmp file(*.bmp)|*.bmp|所有文件(*.*)|*.*||"); //文件格式过滤
// 构造保存文件对话框
CFileDialog fileDlg(FALSE, _T("jpg"), _T("*.jpg"), OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter, this);
fileDlg.m_ofn.lpstrTitle = _T("保存图像"); //保存对话窗口标题名
CString picturePath;
if (IDOK == fileDlg.DoModal()) //按下确认键
{
picturePath = fileDlg.GetPathName(); //文件路径
}
HRESULT hResult = imag.Save(picturePath); //保存图片
ReleaseDC(pdc);
imag.ReleaseDC();
}