您可以在图像上叠加一个 Paintbox 并使用这样的代码
unit Unit3;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TPointArray=array of TPoint;
TForm3 = class(TForm)
Image1: TImage;
PaintBox1: TPaintBox;
Button1: TButton;
procedure PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure PaintBox1Paint(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
FPointArray:TPointArray;
public
{ Public-Deklarationen }
end;
var
Form3: TForm3;
implementation
{$R *.dfm}
procedure TForm3.Button1Click(Sender: TObject);
begin
PaintBox1.Visible := false;
Image1.Canvas.Polygon(FPointArray);
end;
procedure TForm3.PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
SetLength(FPointArray,Length(FPointArray)+1);
FPointArray[High(FPointArray)].X := X;
FPointArray[High(FPointArray)].Y := Y;
Paintbox1.Invalidate;
end;
procedure TForm3.PaintBox1Paint(Sender: TObject);
var
i:Integer;
begin
PaintBox1.Canvas.Brush.Style := bsClear; //as suggested by TLama
PaintBox1.Canvas.Polygon(FPointArray);
for I := 0 to High(FPointArray) do
begin
PaintBox1.Canvas.TextOut(FPointArray[i].X-5,FPointArray[i].y-5,IntToStr(i));
end;
end;
end.