//保存
void CCameraLinkTestDlg::OnBnClickedSave()
{
// TODO: 在此添加控件通知处理程序代码
if (mat.empty())
{
MessageBox(_T("请先进行图片捕获!"));
return;
}
SYSTEMTIME str;
GetLocalTime(&str);
CString timePath;
CString img = _T("Image");
CString cs = _T("-");
CString cs1 = _T("__");
//用当前时间创建默认图片名称
timePath.Format(_T("%s%s%2d%s%02d%s%02d%s%02d%s%02d%s%02d"), img, cs1, str.wYear, cs, str.wMonth, cs, str.wDay, cs1, str.wHour, cs, str.wMinute, cs, str.wSecond);
TCHAR szFilter[] = _T("JPG图片(*.jpg)|*.jpg|BMP图片(*.bmp)|*.bmp|PNG图片(*.png)|*.png|JPEG图片(*.jpeg)|*.jpeg|DIB图片(*dib)|*.dib|PBM图片(*.pbm)|*.pbm||");
CFileDialog fileDlg(FALSE, _T("jpg"), timePath, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter, this);
CString strFilePath;
// 显示保存文件对话框
if (IDOK == fileDlg.DoModal())
{
// 如果点击了文件对话框上的“保存”按钮,则将选择的文件路径显示到编辑框里
strFilePath = fileDlg.GetPathName();
vector<int> compression_params;
std::string STDStr(CW2A(strFilePath.GetString()));
imwrite(STDStr, imgOf8bit, compression_params);
}
}
MFC: Click the button to save the picture
Guess you like
Origin blog.csdn.net/qq_41498261/article/details/105030308
Recommended
Ranking