在开始画(OnMouseDown)之前将图片保存下来
在重画之前先恢复总个图片
再用 Pen.Mode:=pmCOPY 的方式画图
就是这么简单
简单示例:
var
AImg: TBitmap;
procedure Save(Image: TBitmap);
begin
if not Assigned(AImg) then
begin
AImg:=TBitmap.Create;
AImg.Width:=Image.Width;
AImg.Height:=Image.Height;
end;
AImg.Assign(Image);
end;
procedure Restore(Image: TBitmap);
begin
if not Assigned(AImg) then
Exit;
Image.Assign(AImg);
end;
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
Save(Image.Picture.Bitmap);
Drawing := True;
Image.Canvas.MoveTo(X, Y);
Origin := Point(X, Y);
MovePt := Origin;
StatusBar1.Panels[0].Text := Format('Origin: (%d, %d)', [X, Y]);
end;
procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if Drawing then
begin
Restore(Image.Picture.Bitmap);
DrawShape(Origin, Point(X, Y), pmCopy);
Drawing := False;
end;
end;
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if Drawing then
begin
//DrawShape(Origin, MovePt, pmNotXor);
Restore(Image.Picture.Bitmap);
MovePt := Point(X, Y);
DrawShape(Origin, MovePt, pmCopy);
end;
StatusBar1.Panels[1].Text := Format('Current: (%d, %d)', [X, Y]);
end;