利用mfc的picture control显示一个图片,读取图片等操作利用Halcon完成。
点击显示图片按钮,利用CFileDialog类获取图片路径。
然后用Halcon函数,可是picture control没有反应。
void CMCFLearningCaseDlg::OnBnClickedPictureButton()
{
// TODO: 在此添加控件通知处理程序代码
//得到图片文件路径
TCHAR szFilters[] = _T("图片文件(.bmp .png .jpg)/.bmp;.png;*jpg/All Files (.)/.*||");
CFileDialog fileDlg(TRUE, NULL, NULL, OFN_FILEMUSTEXIST | OFN_HIDEREADONLY, szFilters,NULL);
CString pathName;
HImage Image;
HTuple Width, Height;
if (fileDlg.DoModal() == IDOK)
{
pathName = fileDlg.GetPathName();
}
//显示路径
MessageBox(pathName);
//CString改成char*
int len = WideCharToMultiByte(CP_ACP, 0, pathName, -1, NULL, 0, NULL, NULL);
char *ptxtTemp = new char[len + 1];
WideCharToMultiByte(CP_ACP, 0, pathName, -1, ptxtTemp, len, NULL, NULL);
//读取图片
Image.ReadImage(ptxtTemp);
//得到图片尺寸
Image.GetImageSize(&Width, &Height);
//窗口句柄获取
HWND hImgWnd = GetDlgItem(IDC_PICTURE_STATIC)->m_hWnd;
CRect rtWindow;
GetDlgItem(IDC_PICTURE_STATIC)->GetClientRect(&rtWindow);
HWindow m_htWindow;
//打开一个窗口并显示图片
m_htWindow.OpenWindow(rtWindow.left, rtWindow.top, rtWindow.Height(), rtWindow.Width(), (Hlong)hImgWnd, "visible", "");
m_htWindow.SetPart(0, 0, Width.I(), Height.I());
Image.DispImage(m_htWindow);
}