如何在Delphi中在调整大小的TImage的整个区域上绘图?

发布于 2024-08-07 20:01:16 字数 1137 浏览 4 评论 0原文

我已将在 Delphi 2009 中的 TImage.Canvas 上绘图的问题缩小到以下可重现的情况:

给定:一个表单,一个 TImageTLabel< /code> 和 TButtonTImage 锚定到所有四个边缘,以便调整表单大小将调整 TImage 的大小。我想要做的是在调整大小后绘制可用的 Image1 的最大区域。因此,在我的测试用例中,我的 Button 的 OnClick 处理程序中有以下代码:


procedure TForm1.Button1Click(Sender: TObject);
begin
  Label1.Caption:= IntToStr (Image1.Width)+' x '+IntToStr(Image1.Height);
  Image1.Canvas.Pen.Color:= 0;
  Image1.Canvas.Rectangle(0,0,Image1.Width, Image1.Height);
end;
You'll see that if the form is resized, Image1.Width and .Height change as expected, however the rectangle that is drawn if the resized form is larger than the original one, will be incomplete, only drawing on the same area that was there previously.

如何使用整个调整大小的区域?

对于它的价值,在我最初的问题中,我使用了 Image1.Stretch,它允许我使用更多调整大小时的区域,但会导致我的绘图变形(不希望)。如果我还使用 Image1.Proportional,那就更好了,但我仍然无法使用完整的可用区域。 Image1.AutoSize 似乎也没有做任何对我有用的事情。

任何帮助表示赞赏。

I've narrowed a problem I have drawing on TImage.Canvas in Delphi 2009 down to the following reproducible case:

Given: a form, a TImage, TLabel and TButton on it. The TImage is anchored to all four edges so that resizing the form will resize the TImage. What I want to be able to do is draw on the maximal area of Image1 available to me after resizing. So in my test case I have the following code in my the Button's OnClick handler:


procedure TForm1.Button1Click(Sender: TObject);
begin
  Label1.Caption:= IntToStr (Image1.Width)+' x '+IntToStr(Image1.Height);
  Image1.Canvas.Pen.Color:= 0;
  Image1.Canvas.Rectangle(0,0,Image1.Width, Image1.Height);
end;


You'll see that if the form is resized, Image1.Width and .Height change as expected, however the rectangle that is drawn if the resized form is larger than the original one, will be incomplete, only drawing on the same area that was there previously.

How do I get it do use the entire resized area?

For what it's worth, in my original problem I had played with Image1.Stretch, which allows me to use more of the area upon resizing but will result in my drawings being distorted (not desired). If I also use Image1.Proportional, then it's better but I still can't use the full area available. Image1.AutoSize doesn't seem to be doing anything useful to me either.

Any help appreciated.

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

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

发布评论

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

评论(2

饮惑 2024-08-14 20:01:16

将 OnResize 事件添加到表单中:

procedure TForm1.FormResize(Sender: TObject);
begin
  Image1.Picture.Bitmap.Width := Image1.Width;
  Image1.Picture.Bitmap.Height := Image1.Height;
end;

此外,如果您使用组件进行绘图,而不是显示文件等中的图像,请考虑使用 TPaintBox 而不是 TImage。

Add an OnResize-event to your form:

procedure TForm1.FormResize(Sender: TObject);
begin
  Image1.Picture.Bitmap.Width := Image1.Width;
  Image1.Picture.Bitmap.Height := Image1.Height;
end;

Also, if you are using the component to draw on, rather than displaying images from file etc, consider using the TPaintBox rather than TImage.

萌︼了一个春 2024-08-14 20:01:16

也许您还必须调整 Image1.Picture.Width/Height 或 Image1.Picture.Bitmap.Width/Height。

Maybe you have to also adjust Image1.Picture.Width/Height or Image1.Picture.Bitmap.Width/Height.

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