Opencv在MFC中打开任意路径的图片

版权声明:本文为博主原创文章,转载请注明出处 https://blog.csdn.net/thecentry。 https://blog.csdn.net/thecentry/article/details/72808689
void CopencvtestDlg::OnBnClickedOpenImage()
{
	CString filter;
	filter = "All Files (*.*)|*.*|JPGtu图片(*.jpg)|*.jpg|BMP图像(*.bmp)|*.bmp|PNG图片(*.png)|*.png||";
	CFileDialog dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY, filter);
	if (dlg.DoModal() != IDOK)
	{
		MessageBoxA(NULL, "does not chose image", "ss", IDOK);
		return;
	}
	path = dlg.GetPathName();

//	MessageBox(path);//调试、显示选择路径

	path.Replace(_T("\\"), _T("\\\\"));//转移字符的转换
	
	char path1[100] ;
	memset(path1, 0, sizeof(path1));
	int k = path.GetAllocLength();
	

//	memcpy(path1,path,30);
	for (int i = 0; path[i] != 0; i++)
	{
		path1[i] = path[i];
	}
	
//	MessageBox(path);//调试路径
	MessageBoxA(NULL,path1, "ss", IDOK);//显示我所得到的路径
	Mat src;
	src = imread(path1);
	if (!src.data)
	{
		MessageBoxA(NULL,"could not load it","ss",IDOK);
		return;
	}
	imshow("1", src);

}

阅读更多 登录后自动展开
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页