halcon学习之路(一)之显示图片

版权声明:本文为博主原创文章,未经博主允许不得转载。如有问题,欢迎指正。 https://blog.csdn.net/weixin_43197380/article/details/89418819

代码:

    HObject  ho_Image;
    HTuple HWindowID;
    CRect Rect;
    HTuple m_HWindowID;
    HTuple m_ImageWidth,m_ImageHeight;
    //显示静态图片
    ReadImage(&ho_Image, "C:/Users/lenovo/Desktop/test.jpg");
    CWnd * pWnd = GetDlgItem( IDC_STATIC);
    HWindowID = (Hlong)pWnd->m_hWnd;//获取父窗口句柄
    pWnd->GetWindowRect(&Rect);
    OpenWindow(0,0,Rect.Width(),Rect.Height(),HWindowID,"visible","",&m_HWindowID );    
    GetImageSize(ho_Image, &m_ImageWidth, &m_ImageHeight);
    SetPart(m_HWindowID,0,0,m_ImageHeight-1,m_ImageWidth-1);
    DispObj(ho_Image, m_HWindowID);

注:
(1)OpenWindow():将PictureControl控件的大小传给m_HWindowID,作为开辟的Halcon窗口的大小,这样两个窗口可以叠加在一起了。
(2) GetImageSize():获取ho_Image图片的尺寸
(3)SetPart()函数:是调整图片在窗口中的位置(设定图片左上角坐标和右下角坐标)
格式:

void SetPart(const HTuple& WindowHandle, const HTuple& Row1, const HTuple& Column1, const HTuple& Row2, const HTuple& Column2)

其中
1)const HTuple& WindowHandle:窗口句柄
2)(Row1,Column1)(Row2,Column2):要显示的图像部件的左上角和右下角

猜你喜欢

转载自blog.csdn.net/weixin_43197380/article/details/89418819
今日推荐