MFC利用halcon以及cimage在picture control控件上面显示图片
2017-05-22 11:14
459 查看
本人为利用halcon做软件开发的新手,提供在picture control控件上面显示图片的两种简单方法
一、利用cimage
程序如下:
char* pcsun = "图片文件(*.bmp *.png *.jpg)|*.bmp;*.png;*jpg|All Files (*.*)|*.*||";
CFileDialog OpenDialog(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_ALLOWMULTISELECT,
_T("Image files(*.png; *.jpg)|*.png;*.jpg|All files(*.*)|*.*||"), NULL);
if (OpenDialog.DoModal() == IDCANCEL) return; //返回带文件名的路径,并传递给编辑控件变量
CString str = OpenDialog.GetPathName();
char* ch = (char*)LPCTSTR(str);
CRect rect;
CImage image;
image.Load(str);
GetDlgItem(IDC_PIC1)->GetWindowRect(&rect); //将客户区选中到控件表示的矩形区域内
CWnd *pWnd = NULL;
pWnd = GetDlgItem(IDC_PIC1);//获取控件句柄
pWnd->GetClientRect(&rect);//获取句柄指向控件区域的大小
CDC *pDc = NULL;
pDc = pWnd->GetDC();//获取picture的DC
image.Draw(pDc->m_hDC, rect);//将图片绘制到picture表示的区域内
ReleaseDC(pDc);
二、利用halcon
程序如下:
HObject m_hoImage;
HTuple width, height;
ReadImage(&m_hoImage, ch);
GetImageSize(m_hoImage, &height, &width);
CRect rtWindow;
HWND hImgWnd = GetDlgItem(IDC_PIC1)->m_hWnd;
GetDlgItem(IDC_PIC1)->GetClientRect(&rtWindow);
HTuple m_htWindow;
OpenWindow(rtWindow.left, rtWindow.top, rtWindow.Width(), rtWindow.Height(), (Hlong)hImgWnd, "visible", "", &m_htWindow);
SetPart(m_htWindow, 0, 0, width, height);//
DispObj(m_hoImage, m_htWindow);
以上两种方法均可实现图片的读取及其显示,效果图如下:
一、利用cimage
程序如下:
char* pcsun = "图片文件(*.bmp *.png *.jpg)|*.bmp;*.png;*jpg|All Files (*.*)|*.*||";
CFileDialog OpenDialog(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_ALLOWMULTISELECT,
_T("Image files(*.png; *.jpg)|*.png;*.jpg|All files(*.*)|*.*||"), NULL);
if (OpenDialog.DoModal() == IDCANCEL) return; //返回带文件名的路径,并传递给编辑控件变量
CString str = OpenDialog.GetPathName();
char* ch = (char*)LPCTSTR(str);
CRect rect;
CImage image;
image.Load(str);
GetDlgItem(IDC_PIC1)->GetWindowRect(&rect); //将客户区选中到控件表示的矩形区域内
CWnd *pWnd = NULL;
pWnd = GetDlgItem(IDC_PIC1);//获取控件句柄
pWnd->GetClientRect(&rect);//获取句柄指向控件区域的大小
CDC *pDc = NULL;
pDc = pWnd->GetDC();//获取picture的DC
image.Draw(pDc->m_hDC, rect);//将图片绘制到picture表示的区域内
ReleaseDC(pDc);
二、利用halcon
程序如下:
HObject m_hoImage;
HTuple width, height;
ReadImage(&m_hoImage, ch);
GetImageSize(m_hoImage, &height, &width);
CRect rtWindow;
HWND hImgWnd = GetDlgItem(IDC_PIC1)->m_hWnd;
GetDlgItem(IDC_PIC1)->GetClientRect(&rtWindow);
HTuple m_htWindow;
OpenWindow(rtWindow.left, rtWindow.top, rtWindow.Width(), rtWindow.Height(), (Hlong)hImgWnd, "visible", "", &m_htWindow);
SetPart(m_htWindow, 0, 0, width, height);//
DispObj(m_hoImage, m_htWindow);
以上两种方法均可实现图片的读取及其显示,效果图如下:
相关文章推荐
- MFC利用CImage类将图片显示到Picture控件上
- MFC中 利用OpenCv显示图片到Picture Control控件
- MFC利用CImage类将图片显示到Picture控件上
- OpenCV 2.2版本号以上显示图片到 MFC 的 Picture Control 控件中
- 利用MFC中的picture control 控件显示图像
- 知乎上有一个问题“在mfc框架中,有上面方法能直接将opencv2.0库中的Mat格式图片传递到Picture Control”中显示?
- opencv学习笔记(二)vs2010+opencv2.3.1 mfc的实现---利用图片控件显示
- OpenCV 2.2版本以上显示图片到 MFC 的 Picture Control 控件中
- OpenCV 2.2版本以上显示图片到 MFC 的 Picture Control 控件中
- MFC CImage 类加载图片显示到控件
- vs2015+opencv3.2+mfc读取摄像头显示在图片控件Picture Control
- VS2017 MFC的Picture Control控件显示opencv3.3图片的方法
- MFC 对话框中的picture control 控件显示图片
- [ MFC ] 对话框动态控件的创建 在Picture Control控件上显示图片 [大三TJB_708]
- OpenCV 2.2版本以上显示图片到 MFC 的 Picture Control 控件中
- 在 MFC 框架中,有什么方法能直接将 OpenCV 2.0 库中 Mat 格式的图片传递到 Picture Control(图片控件)显示?
- 自适应MFC中的picture control 控件来显示文件路径中的图片
- 利用CvvImage类在MFC控件中显示图片
- MFC picture control控件不失真自适应图片显示
- MFC Picture Control 自适应控件大小显示图片,失真和不失真