C# and Halcon joint programming how to make the picture displayed in the Halcon window adapt to the size of the window control

C# and Halcon joint programming how to make the picture displayed in the Halcon window adapt to the size of the window control

  Add a Halcon window control hWindowControl to the winform form. If you want to display a picture on the control, only part of the picture will appear, but not fully displayed in the current window, as shown in the following figure:
Insert picture description here        (The left side is the PictureBox control Is displayed in, the right is displayed in the Halcon window control)

The solution is as follows:

定义窗口句柄的两步:
            HTuple hWind;//hWind为窗口句柄
            hWind = hWindowControl1.HalconWindow;//hWindowControl1为Halcon窗口控件的Name
            
            HTuple Height, Width;
            HObject ho_Image;
            // 初始化本地和输出图片变量
            HOperatorSet.GenEmptyObj(out ho_Image);
            ho_Image.Dispose();
            HOperatorSet.ReadImage(out ho_Image, "C:/Users/asus-pc/Desktop/images/Luka.jpeg");
            HOperatorSet.GetImageSize(ho_Image, out Width, out Height);
            //修改显示的图像部分,将图片的高度和宽度分别作为要显示部分的右下角的行高度和列宽度
            HOperatorSet.SetPart(hWind, 0, 0, Height - 1, Width - 1);
            HOperatorSet.DispObj(ho_Image, hWind);

About the operator set_part:
  set_part(:: WindowHandle, Row1, Column1, Row2, Column2
  :) set_part modifies the part of the image displayed in the window. Among them, WindowHandle is the window handle, (Row1, Column1) represents the row height and column width of the upper left corner of the image part to be displayed, and (Row2, Column2) represents the row height and column width of the lower right corner of the image part to be displayed.

Guess you like

Origin blog.csdn.net/Kevin_Sun777/article/details/108535306