按比例重新定位 FormResize 上的图像

发布于 2024-09-25 10:14:28 字数 426 浏览 4 评论 0原文

我有一个带有 TImages 的 Delphi 表单。实际上,它是一个带有“图标”(TImages)的“假”桌面。

当用户调整表单大小(例如缩放或最大化)时,表单上的图标应按比例对齐。

现在,我正在对图像做这样的事情:

ImageX.Left:=Round(ImageX.Left * (Width / OldWidth));
ImageX.Top:=Round(ImageX.Top * (Height / OldHeight));

现在这没问题,只要我开始缩小最大化的形式。

在这种情况下,最右边的图像将被表单的边框部分剪切(它们超出了表单的客户区)。

如果我重新定位这些图像以适合客户区域,那么图标的位置在缩放回最大尺寸时会变形。

有更好的算法/修复的想法吗?

谢谢!

I have a Delphi form with TImages on it. Actually, it's a "fake" desktop with "icons" (the TImages).

When the user resizes the form (scales it or maximizes it, for example) the icons on the form should align proportionally.

Right now, I'm doing something like this with the images:

ImageX.Left:=Round(ImageX.Left * (Width / OldWidth));
ImageX.Top:=Round(ImageX.Top * (Height / OldHeight));

Now this is OK, as long as I start to make the maximized form smaller.

In that case the rightmost images are cut in part by the form's border (they're off the form's client area).

If I reposition these images to fit the client area, then the position of the icons get distorted upon scaling back to maximum size.

Any ideas for a better algorithm/fix?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

再见回来 2024-10-02 10:14:28

首先,当您仅移动图像并且不缩放它们时,您无法获得正确缩放的桌面。您可以通过移动图像的中点而不是左上角来做得更好。它仍然不完美,但会更好。当然,现在图像将在所有四个边上被裁剪,不仅仅是底部和右侧,但至少它是对称的:-)

其次,你会得到累积的舍入误差,因为你不断地覆盖“原始”值(ImageX 的顶部和左侧坐标)。您最好将原始值存储在某种集合或数组中,并根据原始值而不是以前的值设置新位置。

像这样的东西:

ImageX.Left:=Round(ImageX_OriginalLeft * (Width / Original_Width));

First of all, you can't have a correctly scaled desktop when you only move the images, and don't scale them as well. You can do slightly better by moving the midpoints of your images, not their top left corner. It still won't be perfect, but it will work better. Of course, now the images will be cropped on all four sides, not just bottom and right, but at least it will be symmetrical :-)

Second, you will get accumulative rounding errors since you constantly override the "original" values (ImageX's top and left coordinate). You'd be better off having the original values stored in some sort of collection or array, and setting the new position based on the original value, rather than the previous value.

Something like this:

ImageX.Left:=Round(ImageX_OriginalLeft * (Width / Original_Width));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文