Paths-Getpointcount, getpathpoints, Getlastpoint, getbounds
This example effect chart:
Code files:Unit Unit1;
Interface
Uses
Windows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms,
Dialogs, Stdctrls;
Type
TForm1 = Class (Tform)
Checkbox1:tcheckbox;
Checkbox2:tcheckbox;
Checkbox3:tcheckbox;
Procedure Formcreate (Sender:tobject);
Procedure Formpaint (Sender:tobject);
Procedure Checkbox1click (Sender:tobject);
Procedure Checkbox2click (Sender:tobject);
Procedure Checkbox3click (Sender:tobject);
End
Var
Form1:tform1;
Implementation
{$R *.DFM}
Uses Gdipobj, GDIPAPI;
Procedure Tform1.formcreate (Sender:tobject);
Begin
Checkbox1.caption: = ' Extract all points in the path ';
Checkbox2.caption: = ' Extract the last point in the path ';
Checkbox3.caption: = ' show the outer rectangle of the path ';
End
Procedure Tform1.formpaint (Sender:tobject);
Var
G:tgpgraphics;
Path:tgpgraphicspath;
P:tgppen;
B:tgpbrush;
PTS:ARRAY[0..6] of Tgppoint;
ptf:tgppointf;
Ppts:array of Tgppoint;
Rect:tgprect;
I:integer;
Begin
{The point to be prepared for the Bézier line to establish the path}
Pts[0]. X: = 22; Pts[0]. Y: = 44;
PTS[1]. X: = 11; PTS[1]. Y: = 111;
PTS[2]. X: = 33; PTS[2]. Y: = 222;
PTS[3]. X: = 60; PTS[3]. Y: = 88;
PTS[4]. X: = 80; PTS[4]. Y: = 222;
PTS[5]. X: = 170; PTS[5]. Y: = 111;
PTS[6]. X: = 200; PTS[6]. Y: = 11;
G: = Tgpgraphics.create (Canvas.handle);
{Create a path and add two Bézier lines to the path}
Path: = Tgpgraphicspath.create;
Path. AddBeziers (Pgppoint (@pts), Length (pts));
{Draw Path}
P: = tgppen.create (aclred);
G.drawpath (P, path);
{Virtual draw original data point}
P.setcolor (Aclgray);
For I: = 0 to Length (pts)-1 do
G.drawrectangle (P, Makerect (pts[i). X-2, Pts[i]. Y-2, 4, 4));
{Extract all points in the path}
B: = Tgpsolidbrush.create (Aclblue);
If Checkbox1.checked Then
Begin
SetLength (ppts, path.) Getpointcount);
Path. Getpathpoints (Pgppoint (ppts), Length (pts));
For I: = 0 to Length (ppts)-1 do
G.fillrectangle (b, Makerect (ppts[i). X-3, Ppts[i]. Y-3, 6, 6));
End
{You can specifically get the last point}
Tgpsolidbrush (b). SetColor (aclred);
If Checkbox2.checked Then
Begin
Path. Getlastpoint (PTF);
G.fillrectangle (b, Makerect (PTF). X-3, PTF. Y-3, 6, 6));
End
{External rectangle for path}
If Checkbox3.checked Then
Begin
Path. GetBounds (rect);
G.drawrectangle (P, rect);
End
B.free;
P.free;
Path. Free;
G.free;
End
Procedure Tform1.checkbox1click (Sender:tobject);
Begin
Repaint;
End
Procedure Tform1.checkbox2click (Sender:tobject);
Begin
Repaint;
End
Procedure Tform1.checkbox3click (Sender:tobject);
Begin
Repaint;
End
End.