unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls; type TForm1 = class(TForm) TrackBar1: TTrackBar; Button1: TButton; procedure FormCreate(Sender: TObject); procedure FormMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure FormPaint(Sender: TObject); procedure TrackBar1Change(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} uses GDIPOBJ,GDIPAPI; var i:Integer = 0; PtArr:array of TGPPoint; tension:Single; procedure TForm1.Button1Click(Sender: TObject); begin i:=0; SetLength(PtArr,i); Repaint; Text:=IntToStr(i); end; procedure TForm1.FormCreate(Sender: TObject); begin Button1.Caption:='擦除'; TrackBar1.ShowSelRange:=False; TrackBar1.Min:=-25; TrackBar1.Max:=35; TrackBar1.Position:=5; end; procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin Inc(i); SetLength(PtArr,i); PtArr[i-1]:=MakePoint(x,y); Text:=IntToStr(i); Repaint; end; procedure TForm1.FormPaint(Sender: TObject); var g:TGPGraphics; p:TGPPen; i:Integer; begin g:=TGPGraphics.Create(Canvas.Handle); g.Clear(aclWhite); p:=TGPPen.Create(aclRed,2); {最后一个参数是可选的, 默认值是 0.5, 为 0 时曲线会转为直线段} g.DrawClosedCurve(p,PGPPoint(PtArr),Length(PtArr),tension); p.SetWidth(1); p.SetColor(aclBlack); for i := 0 to Length(PtArr) - 1 do begin g.DrawEllipse(p,ptarr[i].X-2,ptarr[i].Y-2,4,4); end; p.Free; g.Free; end; procedure TForm1.TrackBar1Change(Sender: TObject); begin tension:=TrackBar1.Position / 10; Repaint; end; end.