MFC+Halcon混合编程,图像读入,显示和存储


1.建立对话框工程(字符集:多字节字符集

.配置属性:

(1)配置属性-》c++-》常规-》附加库目录,加入:D:\Program Files\MVTec\HALCON-12.0\include\halconcpp;D:\Program Files\MVTec\HALCON-12.0\include;

(2)配置属性-》链接器-》常规-》附加库目录,加入:D:\Program Files\MVTec\HALCON-12.0\lib\x64-win64;

(3)配置属性-》链接器-》输入-》附加依赖项,加入:halconcpp.lib3.Halcon调用,需在Dlg.h或调用文件中加入#include"HalconCpp.h"using namespace HalconCpp;

4.(1)在主窗口中显示在对话框中添加按钮,并添加响应函数(Dlg.cpp),函数如下:

char* pcsun = "图片文件(*.bmp *.png *.jpg)|*.bmp;*.png;*jpg|All Files (*.*)|*.*||";

CFileDialog OpenDialog(TRUE, NULL, 0, OFN_OVERWRITEPROMPT, pcsun, NULL);

if (OpenDialog.DoModal() == IDCANCEL) return; /

/返回带文件名的路径,并传递给编辑控件变量

CString str = OpenDialog.GetPathName();

char* ch = (char*)LPCTSTR(str);

HObject m_hoImage; ReadImage(&m_hoImage, ch);

HTuple hv_WindowHandle; HTuple hv_Width, hv_Height;

GetImageSize(m_hoImage, &hv_Height, &hv_Width);

Hlong MainWndID = (Hlong)m_hWnd;

OpenWindow(0, 0, hv_Height, hv_Width , MainWndID, "", "", &hv_WindowHandle);

SetPart(m_htWindow, 0, 0, width, height);// DispObj(m_hoImage, m_htWindow);

    主窗口显示

(2)picture control里面显示,也是在读图按钮里面添加响应函数代码:

char* pcsun = "图片文件(*.bmp *.png *.jpg)|*.bmp;*.png;*jpg|All Files (*.*)|*.*||";

CFileDialog OpenDialog(TRUE, NULL, 0, OFN_OVERWRITEPROMPT, pcsun, NULL);

if (OpenDialog.DoModal() == IDCANCEL) return; //返回带文件名的路径,并传递给编辑控件变量

CString str = OpenDialog.GetPathName(); char* ch = (char*)LPCTSTR(str); HObject m_hoImage; ReadImage(&m_hoImage, ch);

HTuple width, height;

GetImageSize(m_hoImage, &height, &width);

CRect rtWindow;

HWND hImgWnd = GetDlgItem(IDC_BMPWINDOW)->m_hWnd; GetDlgItem(IDC_BMPWINDOW)->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); ![显示如图](https://img-blog.csdn.net/20160528175720424)

阅读更多
想对作者说点什么? 我来说一句

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

不良信息举报

MFC+Halcon混合编程,图像读入,显示和存储

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭