qt 显示halcon图片,放大缩小

我是使用qlabel来显示图片的。

  1 获取图片

   直接读取已有的图片,这是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());
	 }

2  绑定label的id

    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]);

3 确定图片的尺寸并显示

 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);是确定显示图片在显示窗口的大小

4 结果 

 完全显示图片

qt 显示halcon图片,放大缩小_第1张图片

 

 

你可能感兴趣的:(qt 显示halcon图片,放大缩小)