如何去掉tcanvas上一张图片的结果

how to remove the results of the previous image on tcanvas

就是这个代码

procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
SpeedButton1.Tag := SpeedButton1.Tag + 1;
if SpeedButton1.Tag = 4 then
SpeedButton1.Tag := 0;
//------------------------------------------------------------------------------
with Image1.Canvas do
begin
Brush.Style := BSSolid;
Pen.Color := [=10=]00FF;
Pen.Style := PSSolid;
Pen.Width := 5;
//------------------------------------------------------------------------------
case SpeedButton1.Tag of
0 :
Ellipse(Image1.Width - 45, 4, Image1.Width - 35, 14);
1 :
Ellipse(Image1.Width - 45, 32, Image1.Width - 35, 42);
2 :
Ellipse(Image1.Width - 115, 4, Image1.Width - 125, 14);
3 :
Ellipse(Image1.Width - 115, 32, Image1.Width - 125, 42);
end;
SpeedButton1.Caption := 'Pos : '+IntToStr(SpeedButton1.Tag);
end;
Image1.Invalidate;
{ Image1.Canvas.Refresh;
Image1.Repaint;
Image1.Refresh;
}
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
DoubleBuffered := true;
//------------------------------------------------------------------------------
with Image1.Canvas do
begin
Brush.Style := BSClear;
Pen.Color := [=10=]0000;
Pen.Style := PSSolid;
//------------------------------------------------------------------------------
Pen.Width := 5;
MoveTo(Image1.Width - 2, 6);
LineTo(Image1.Width - 2, 40);
//------------------------------------------------------------------------------
Pen.Width := 2;
MoveTo(Image1.Width - 80, 6);
LineTo(Image1.Width - 80, 40);
MoveTo(Image1.Width - 160, 6);
LineTo(Image1.Width - 160, 40);
MoveTo(Image1.Width - 240, 6);
LineTo(Image1.Width - 240, 40);
MoveTo(Image1.Width - 320, 6);
LineTo(Image1.Width - 320, 40);
//------------------------------------------------------------------------------
Pen.Width := 1;
MoveTo(0, 8);
LineTo(Image1.Width, 8);
MoveTo(0, 38);
LineTo(Image1.Width, 38);
//------------------------------------------------------------------------------
Brush.Style := BSSolid;
Pen.Color := [=10=]00FF;
Pen.Style := PSSolid;
//------------------------------------------------------------------------------
Pen.Width := 5;
Ellipse(Image1.Width - 45, 4, Image1.Width - 35, 14);
end;
Image1.Invalidate;
end;

使用 FillRect 使用当前画笔填充矩形区域。填充区域包括矩形的顶部和左侧,但不包括底部和右侧边缘。

begin
  Image1.Canvas.Brush.Style := bsSolid;
  Image1.Canvas.Brush.Color := clWtite;
  Image1.Canvas.FillRect(Image1.Canvas.ClipRect);
end;

TImage 控件包含一个简单的位图。它不包含图层。这意味着您不能删除和弦并保留弦线。弦线已经画完了,需要重新画。

由于您需要重新绘制字符串,在我看来,重新绘制整个 canvas 最简单。我会说 TImage 是这个任务的错误控制。它适用于静态图像。

对于这样的动态图像,TPaintBox 是更好的选择。您提供一个 OnPaint 事件处理程序。您还必须记住需要绘制的状态。此状态将包含和弦及其指法的详细信息。当您需要重新绘制时,更新此状态并调用 Invalidate 油漆盒。这将强制执行一个绘制周期,该周期将调用您的 OnPaint 处理程序。