gpt4 book ai didi

德尔福6 : TImage Width and Height properties report wrong values?

转载 作者:行者123 更新时间:2023-12-02 09:22:05 24 4
gpt4 key购买 nike

我在 TImage 组件的宽度和高度属性方面遇到了一个相当奇怪的问题。作为测试,我在 TImage 组件的中心(应该是)绘制一个红点,方法是取 TImage 的宽度和高度的中点,并在那里绘制该点,使其居中(centerPoint2D 是一个 TPoint):

// The center point is the center of the display area.
centerPoint2D.X := Trunc(Image1.Width / 2);
centerPoint2D.Y := Trunc(Image1.Height / 2);

Image1.Canvas.Brush.Color := clRed;
Image1.Canvas.Brush.Style := bsSolid;
Image1.Canvas.Ellipse(centerPoint2D.X - 5, centerPoint2D.Y - 5, centerPoint2D.X + 5, centerPoint2D.Y + 5);

红点并不出现在 TImage 的中心,而是出现在其下方和右侧的某个位置。此外,我打印到组件的任何文本都显得被拉伸(stretch)。就好像 TImage 比报告的尺寸大得多,比从视口(viewport)中看到的尺寸大得多,就好像可见的尺寸被剪裁了。

其他详细信息。 TImage 控件位于 TPanel 上,TPanel 位于 TFrame 上的 TGroupBox 上。然而,所有这些组件的 Align 属性都设置为 alClient。 TFrame 本身的 Align 属性设置为 alNone。但是,位于 Form 上的它的实例在设计时将其 Align 属性设置为 alClient。换句话说,TImage 组件不应该大于其在运行时可见的部分。此外,报告的尺寸确实与我眼中屏幕上显示的组件尺寸相符,但我没有“像素标尺”实用程序来客观地确认这一点。

最佳答案

TImage 控件通常用于显示图像文件(例如 *.bmp 文件)。因此,控件可以加载任何尺寸的图像,然后使用指定的属性(CenterStretchProportional)将其呈现在控件的 Canvas 上。 >)。考虑到这一点,表单上的 TImage 控件的宽度与 Canvas、关联位图的 Canvas 或其他任何东西的大小不同就不足为奇了.

如果您不加载图像,而是想要一个带有 Canvas 的控件来绘制,则应该使用TPaintBox。或者为什么不直接在 TForm 上绘图?

关于德尔福6 : TImage Width and Height properties report wrong values?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3897777/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com