Halcon库内部默认采用了UTF-8编码来表示字符串,而中文系统的locale一般都是GB2312(zh_CN.GB2312)或者GBK(zh_CN.GBK)
那么解决乱码就需要针对本地编码转换到UTF-8或者修改Halcon库的默认编码为locale编码,都是可以的,优先选UTF-8。
这里我们用QT字符串QString代表路径,读取dxf实现代码演示:
一、UTF8默认编码(推荐):
- QString strDxf = "D:\\匹配轮廓.dxf";
- HTuple hv_DxfStatus;
- HObject ho_DxfContours;
- ReadContourXldDxf(&ho_DxfContours, strDxf.toUtf8().data(), HTuple(), HTuple(), &hv_DxfStatus);
复制代码 这里是不能禁用Halcon默认的UTF8编码哦!
二、禁用Halcon的UTF8编码再转换到本地8位编码后传入:
- if(IsHcppInterfaceStringEncodingUtf8())
- SetHcppInterfaceStringEncodingIsUtf8(false);
复制代码- QString strDxf = "D:\\匹配轮廓.dxf";
- HTuple hv_DxfStatus;
- HObject ho_DxfContours;
- ReadContourXldDxf(&ho_DxfContours, strDxf.toLocal8Bit().toStdString().data(), HTuple(), HTuple(), &hv_DxfStatus);
复制代码
|