如何在Delphi 2009中获取图像的当前视图大小 [英] How to get the current view size for an image in Delphi 2009

查看:70
本文介绍了如何在Delphi 2009中获取图像的当前视图大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望获得使用TImage显示的图像的当前大小,该对象的Proportional属性设置为True,并与具有主窗体的Client对齐。因此,在调整表单大小时,我想获取该图像的当前大小,而不是画布大小,也不获取该图像的实际大小。获取当前尺寸我可以显示当前图像尺寸相对于实际图像尺寸的百分比。
预先感谢

I wish to get the current size for an image being displayed with TImage, this object has the Proportional property set to True and is aligned to Client with main form. So, when resizing the form I wanna get the current size for that image, not canvas size neither real size for that image. Getting the current size I can show what's the percentage for current image size respect to real image size. Thanks in advance

推荐答案

您可以将Image1.Picture.Width或.Height与Image1.Width或.Height进行比较

You can compare Image1.Picture.Width or .Height with Image1.Width or .Height.

要知道图像是使用水平尺寸还是垂直尺寸按比例拉伸,您应该比较两者的比率:

To know if the image is streched proportional using the horizontal or vertical dimension, you should compare the ratio's of the two:

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;

使用数学技巧将除法转换为乘法,可以避免将转换转换为浮点值,也可以使用以下方法更快地计算:

using a mathematical trick to convert the divisions into multiplications, you can avoid the conversions into float values, which also calculate a bit faster by using:

if Image1.Width*Image1.Picture.Height >Image1.Picture.Width*Image1.Height then

这篇关于如何在Delphi 2009中获取图像的当前视图大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆