打开图片:
void CImageProDlg::OnImageopen() { // TODO: 在此添加命令处理程序代码 Invalidate(); CFileDialog dlg(TRUE, NULL, NULL, OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_READONLY, TEXT("Supported Types (*.jpg;*.png;*.gif;*.bmp;...)|*.jpg;*.png;*.gif;*.bmp|Tiff(*.tiff;*.tif)|*.tiff;*.tif|All Files(*.*)|*.*||"), NULL); dlg.m_ofn.nFilterIndex = 1; dlg.m_ofn.hwndOwner = m_hWnd; dlg.m_ofn.lStructSize = sizeof(OPENFILENAME); dlg.m_ofn.lpstrTitle = TEXT("Opening Image...\0"); dlg.m_ofn.nMaxFile = MAX_PATH; if (dlg.DoModal() == IDOK) { m_path = dlg.GetPathName(); m_capacity = TRUE; UpdateData(FALSE); } else return; //左边图片控件显示图片 //string s_path(m_path.GetBuffer()); //这样就要#include <string.h> char *s_path; s_path = m_path.GetBuffer(m_path.GetLength()); //将CString转化为Char * 格式 //m_StaticPath.SetWindowTextA(m_path); //将图片路径显示到静态文本控件 Mat Mat_image = imread(s_path, 1); SavedImage = Mat_image; //全局变量 IplImage image = Mat_image; DrawPicToHDC(&image, ID_SHOWLEFT); }
保存图片:
(需输入完整路径,包括拓展名)
void CImageProDlg::OnSaveas() { // TODO: 在此添加命令处理程序代码 if (m_capacity) { CFileDialog dlg(FALSE, NULL, NULL, OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_READONLY, TEXT("Supported Types (*.jpg;*.png;*.gif;*.bmp;...)|*.jpg;*.png;*.gif;*.bmp|Tiff(*.tiff;*.tif)|*.tiff;*.tif|All Files(*.*)|*.*||"), NULL); dlg.m_ofn.nFilterIndex = 1; dlg.m_ofn.hwndOwner = m_hWnd; dlg.m_ofn.lStructSize = sizeof(OPENFILENAME); dlg.m_ofn.lpstrTitle = TEXT("Saving Image...[Meantime input extension name! ]\0"); dlg.m_ofn.nMaxFile = MAX_PATH; CString strPath(""), strExt(""); char write[10000]; if (dlg.DoModal() == IDOK) { strPath = dlg.GetPathName(); //文件名 char *s_path; s_path = strPath.GetBuffer(strPath.GetLength()); imwrite(s_path, SavedImage); strPath.ReleaseBuffer(); } } else MessageBox("还未选择原始图片,无法保存图片!"); }
时间: 2024-10-01 01:38:22