如何在Delphi中在调整大小的TImage的整个区域上绘图?
我已将在 Delphi 2009 中的 TImage.Canvas
上绘图的问题缩小到以下可重现的情况:
给定:一个表单,一个 TImage
,TLabel< /code> 和
TButton
。 TImage
锚定到所有四个边缘,以便调整表单大小将调整 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将 OnResize 事件添加到表单中:
此外,如果您使用组件进行绘图,而不是显示文件等中的图像,请考虑使用 TPaintBox 而不是 TImage。
Add an OnResize-event to your form:
Also, if you are using the component to draw on, rather than displaying images from file etc, consider using the TPaintBox rather than TImage.
也许您还必须调整 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.