我是使用qlabel来显示图片的。
直接读取已有的图片,这是4张不一样大的图片
HObject himage1[6];
for (int i = 0; i < 4; i++)
{
QString str = QDir::currentPath() + "/Data/I" + QString::number(i+1) + ".bmp";
HalconCpp::ReadImage(&himage1[i], str.toStdString().c_str());
}
HTuple hv_WindowID[6];
HTuple hv_WindowID2[6];
//获取label的id
MainWndID = (Hlong)this->ui.label->winId();
//这里的611和441是label的大小,刚好是打开的图像窗口和label一样大
// 链接label和显示窗口
OpenWindow(0, 0, 611, 441, MainWndID, "visible", "", &hv_WindowID[0]);
MainWndID = (Hlong)this->ui.label_2->winId();
OpenWindow(0, 0, 611, 441, MainWndID, "visible", "", &hv_WindowID[1]);
MainWndID = (Hlong)this->ui.label_7->winId();
OpenWindow(0, 0, 611, 441, MainWndID, "visible", "", &hv_WindowID[2]);
MainWndID = (Hlong)this->ui.label_9->winId();
OpenWindow(0, 0, 611, 441, MainWndID, "visible", "", &hv_WindowID[3]);
MainWndID = (Hlong)this->ui.label_10->winId();
OpenWindow(0, 0, 611, 441, MainWndID, "visible", "", &hv_WindowID[4]);
MainWndID = (Hlong)this->ui.label_11->winId();
OpenWindow(0, 0, 611, 441, MainWndID, "visible", "", &hv_WindowID[5]);
for (int i = 0; i < 4; i++)
{
//获取图片大小
HTuple x, y;
GetImageSize(himage1[i],&x,&y);
//根据图片确定窗口的显示大小
SetPart(hv_WindowID[i], 0, 0, y, x);
//根据label的大小完整显示图片
DispObj(himage1[i], hv_WindowID[i]);
}
重点: OpenWindow(0, 0, 611, 441, MainWndID, "visible", "", &hv_WindowID[0]); 是确定显示窗口的大小
SetPart(hv_WindowID[i], 0, 0, y, x);是确定显示图片在显示窗口的大小
完全显示图片