26.1、.NET与Halcon混合编程(鼠标绘制区域)

方法:《26、.NET与Halcon混合编程》中的action函数中新增代'************中的码即可

 

 

Private Sub action()

 

' Local iconic variables

Dim ho_Image12 As HObject = Nothing '定义一个图形变量

 

' Local control variables

Dim hv_Width As HTuple = Nothing, hv_Height As HTuple = Nothing '定义宽度与高度控制变量-用来存放图像的大小

Dim hv_WindowHandle As HTuple = Nothing '定义句柄

 

' Initialize local and output iconic variables

HOperatorSet.GenEmptyObj(ho_Image12) '

 

ho_Image12.Dispose()

HOperatorSet.ReadImage(ho_Image12, New HTuple("C:/12.jpg"))

 

HOperatorSet.GetImageSize(ho_Image12, hv_Width, hv_Height)

 

Dim jubing As Integer = CType(AxHWindowXCtrl1.HalconWindow.HalconID, Integer)

hv_WindowHandle = CType(jubing, HTuple)

 

HOperatorSet.SetPart(hv_WindowHandle, 0, 0, hv_Height, hv_Width) '适应窗口显示

 

 

HOperatorSet.DispObj(ho_Image12, hv_WindowHandle) '第一个参数是要显示的图形,第二个参数是显示的句柄

 

'**************************************************************************************** '*************************************************************************************** '****************************************************************************************

 

'定义一个区域对象和一个图像对象,并创建分配内存

Dim ho_ImageReduced As HObject = Nothing

Dim ho_Region As HObject = Nothing

HOperatorSet.GenEmptyObj(ho_Region)

HOperatorSet.GenEmptyObj(ho_ImageReduced)

'清空

ho_Region.Dispose()

ho_ImageReduced.Dispose()

'获取焦点

AxHWindowXCtrl1.Focus()

'绘制区域,当运行到这里,程序会卡主。直到用鼠标在hv_WindowHandle控件上绘制完区域右键单击确定后

HOperatorSet.DrawRegion(ho_Region, hv_WindowHandle)

'利用绘制出来的区域剪裁区域

HOperatorSet.ReduceDomain(ho_Image12, ho_Region, ho_ImageReduced)

'把原来图形窗口的图像清空

HOperatorSet.ClearWindow(hv_WindowHandle)

'显示图像

 

HOperatorSet.DispObj(ho_ImageReduced, hv_WindowHandle)

 

'清空图像内存

ho_Region.Dispose()

ho_ImageReduced.Dispose()

ho_Image12.Dispose()

'*************************************************************************************** '****************************************************************************************'****************************************************************************************

 

End Sub

posted @ 2022-05-09 20:31  ihh2021  阅读(428)  评论(0)    收藏  举报