VC++(MFC) VS2015 picture save image [從畫面元件存成圖片]
VC++(MFC) VS2015 picture save image [從畫面元件存成圖片]
資料來源: https://blog.csdn.net/A478257115/article/details/53031799
void CIdCardDlg::PictureSave(UINT ID) { CWnd* bmpShow = GetDlgItem(ID); CDC *pdc = bmpShow->GetDC(); CImage imag;//#include "atlimage.h" 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(); //文件路径 } */ CString picturePath="test.jpg"; HRESULT hResult = imag.Save(picturePath); //保存图片 ReleaseDC(pdc); imag.ReleaseDC(); }