Halcon显示图片自适应窗口控件中心 缩放平移图像

本文介绍了一种图像在自适应窗口中显示的方法,确保图像以窗口中心为基准进行展示,并实现通过鼠标进行图像的缩放和平移功能。详细阐述了如何根据窗口大小调整图像显示区域,以及如何响应鼠标滚轮和拖动事件来改变图像的显示比例和位置。

图像自适应窗口控件显示,以窗口中心为基准

read_image (Image,'tooth_rim.png')

winWidth:=640
winHeight:=880
dev_resize_window_fit_size (0, 0, winWidth, winHeight, -1, -1)

get_image_size (Image, imgWidth, imgHeight)

ScaleWidth:=imgWidth/(winWidth*1.0)
ScaleHeight:=imgHeight/(winHeight*1.0)

if(ScaleWidth>=ScaleHeight)
    row1:= -(1.0) * ((winHeight * ScaleWidth) - imgHeight) / 2
    column1 := 0                    
    row2 := row1 + winHeight * ScaleWidth
    column2:= column1 + winWidth * ScaleWidth      
else
    row1:= 0
    column1 := -(1.0) * ((winWidth * ScaleHeight) - imgWidth) / 2                    
    row2 := row1 + winHeight * ScaleHeight
    column2:= column1 + winWidth * ScaleHeight
endif   
dev_clear_window ()
dev_set_part (row1, column1, row2, column2)
dev_display (Image)

                                                  &nb

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值