我希望获得使用TImage显示的图像的当前大小,该对象的Proportional属性设置为True,并与具有主窗体的Client对齐。因此,在调整表单大小时,我想获取该图像的当前大小,而不是画布大小,也不是该图像的实际大小。得到当前大小,我可以显示当前图像大小相对于实际图像大小的百分比。
提前致谢
最佳答案
您可以将Image1.Picture.Width或.Height与Image1.Width或.Height进行比较。
要知道是使用水平尺寸还是垂直尺寸按比例拉伸图像,您应该比较两者的比率:
if Image1.Width/Image1.Height > Image1.Picture.Width/Image1.Picture.Height then
Result:=Image1.Picture.Width/Image1.Width
else
Result:=Image1.Picture.Height/Image1.Height;
使用数学技巧将除法转换为乘法,可以避免将转换转换为浮点值,使用以下方法也可以更快地计算出浮点值:
if Image1.Width*Image1.Picture.Height >Image1.Picture.Width*Image1.Height then