上代码:
HObject hImage;//待读取的图像
CString strFilter = _T("Image Files (*.bmp)|*.bmp|BMP File (*.bmp)|*.bmp|PNG File (*.png)|*.png|JPG File (*.jpg)|*.jpg|All Files (*.*)|*.*||");//路径中包含的格式
CFileDialog dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, strFilter);
if (dlg.DoModal() == IDOK)
{
CString cstrImagePath = dlg.GetPathName();//获取当前选择图像路径
USES_CONVERSION;
char* chFilename = T2A(cstrImagePath);
ReadImage(&hImage, chFilename); //读取图像
}
注意上文中CFileDialog dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, strFilter);
TRUE: 代表当前是选择文件的
FALSE:代表当前是将内存中的文件覆盖到该文件上保存
对应的操作应该是Save
CString strFilter = _T("Image Files (*.bmp)|*.bmp|BMP File (*.bmp)|*.bmp|PNG File (*.png)|*.png|JPG File (*.jpg)|*.jpg|All Files (*.*)|*.*||");//路径中包含的格式
CFileDialog dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, strFilter);
if (dlg.DoModal() == IDOK)
{
CString str_totalPath = dlg.GetPathName();
str_totalPath += ".bmp";
USES_CONVERSION;
char* Filename = T2A(str_totalPath);
if (m_crtImage.IsInitialized())
{
WriteImage(m_crtImage, "bmp", 0, Filename);//保存图像
}
}