试图画一个timage

时间:2020-04-19 05:14:15

标签: delphi timage

我已经编写了一个简单的程序(使用Delphi XE7);它具有一个TImage和一个TPaintBox(部分位于Timage之上)。在FormPaint过程中,我调用“ BringToFront”,然后绘制一个(填充的)矩形。矩形显示在图像的 下。

procedure TForm1.FormPaint(Sender: TObject);
begin
 with paintbox1 do
   begin
     BringToFront;
     canvas.Rectangle(0,0,width-1,height-1);
   end;
end;

这是程序窗口的图像:

enter image description here

我希望矩形在图像上 。 我究竟做错了什么? :)

1 个答案:

答案 0 :(得分:3)

您没有正确使用PaintBox。 PaintBox有其自己的绘图事件。您应该使用TPaintBox.OnPaint而不是TForm.OnPaint,结果将如您所写。

您也可以直接在图片上绘制。在这种情况下,使用事件TForm.OnPaint

您还可以在图片更改后(例如,加载后)直接在图片上绘制。如果使用了TBitmap图形,它将起作用。

procedure TForm1.button1click(Sender: TObject);
begin
  image1.LoadFromFile('c:\temp\1.bmp')
  image1.canvas.Rectangle(0,0,100,100);
end;
相关问题