太及时了
这里主要涉及到的知识点为Qt的数据类型转为halcon的数据类型。
GBK.h文件为外部添加头文件,是实现中文转换的文件
需要将GBK.h文件放在工程目录下,并添加以下代码
#include "GBK.h"
#include "halconcpp.h"
#include "String.h"
using namespace HalconCpp;
int test3::OnBtnReadLocalImage(bool checked)
{
QString QfilePath = QFileDialog::getOpenFileName(this, GBK::ToUnicode("选择文件"),"d:/","Image(*.png *.jpg *.bmp");
if (0==QfilePath.length())
{
return -1;
}
string str = QfilePath.toLocal8Bit();
char filePath[100];
strcpy(filePath, str.c_str());
ReadImage(&ho_Image, filePath);
HTuple ho_Width, ho_Height;
GetImageSize(ho_Image, &ho_Width, &ho_Height);
SetPart(hv_WindowHandle, 0,0,ho_Height, ho_Width);
DispObj(ho_Image,hv_WindowHandle);
return 0;
}