HTuple width, height;
HOperatorSet.GetImageSize(ho_Image, out width, out height);
#region 设置自适应
double ratioWidth = (1.0) * width / hWindowControl1.Width;
double ratioHeight = (1.0) * height / hWindowControl1.Height;
HTuple row1, column1, row2, column2;
if (ratioWidth >= ratioHeight)
{
row1 = -(1.0) * ((hWindowControl1.Height * ratioWidth) - height) / 2;
column1 = 0;
row2 = row1 + hWindowControl1.Height * ratioWidth;
column2 = column1 + hWindowControl1.Width * ratioWidth;
}
else
{
row1 = 0;
column1 = -(1.0) * ((hWindowControl1.Width * ratioHeight) - width) / 2;
row2 = row1 + hWindowControl1.Height * ratioHeight;
column2 = column1 + hWindowControl1.Width * ratioHeight;
}
#endregion
HOperatorSet.SetPart(hv_WindowHandle, row1, column1, row2, column2);
DisplayObject(ho_Image);
Halcon - 图像随 HWindowControl 控件缩放的同时,保持图像的长宽比例不变
最新推荐文章于 2024-03-12 22:51:30 发布