The path Warp method allows the path to be transformed within a range (the four-point range);
The first argument can be an array of 3 dots or 4 points, and if it is an array of 3, then the 4th point will automatically follow a parallelogram;
The second parameter is used to specify the number of points, in this case, the number of points is controlled by this parameter;
The third argument is a rectangle, which should be the outer rectangle of the path, and the subsequent arguments are optional;
The fourth parameter is also a matrix transformation, because by the special example, there is no attempt;
The fifth parameter is Twarpmode (warpmodeperspective, warpmodebilinear), which defaults to the former;
The sixth parameter can specify a flatten transform, as in the previous example, and there is no attempt at it.
This example effect chart:
Code files:Unit Unit1;
Interface
Uses
Windows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms,
Dialogs, Comctrls, Stdctrls;
Type
TForm1 = Class (Tform)
Checkbox1:tcheckbox;
Procedure Formcreate (Sender:tobject);
Procedure Formpaint (Sender:tobject);
Procedure Checkbox1click (Sender:tobject);
Procedure Formmousedown (Sender:tobject; Button:tmousebutton;
Shift:tshiftstate; X, Y:integer);
Procedure Formmouseup (Sender:tobject; Button:tmousebutton;
Shift:tshiftstate; X, Y:integer);
Procedure Formmousemove (Sender:tobject; Shift:tshiftstate; X, Y:integer);
End
Var
Form1:tform1;
Implementation
{$R *.DFM}
Uses Gdipobj, GDIPAPI;
Var
PTFS:ARRAY[0..3] of tgppointf;
Ptcount:integer = 4;
Pti:integer;
R:trect;
Flag:boolean;
Procedure Tform1.formcreate (Sender:tobject);
Begin
Checkbox1.caption: = ' control with only 3 points ';
R: = Rect (ClientWidth-20, ClientHeight-40);
Ptfs[0]: = Makepoint (r.left*1.0, r.top);
PTFS[1]: = Makepoint (r.right*1.0, r.top);
PTFS[2]: = Makepoint (r.left*1.0, R.bottom);
PTFS[3]: = Makepoint (r.right*1.0, R.bottom);
End
Procedure Tform1.formpaint (Sender:tobject);
Var
G:tgpgraphics;
P:tgppen;
B:tgpbrush;
Path:tgpgraphicspath;
fontfamily:tgpfontfamily;
Stringformat:tgpstringformat;
RECTF:TGPRECTF;
I:integer;
Begin
G: = Tgpgraphics.create (Canvas.handle);
P: = Tgppen.create (aclred, 1);
B: = Tgphatchbrush.create (Hatchstyleshingle, Acldarkcyan);
Path: = Tgpgraphicspath.create;
Path. AddEllipse (Makerect (R));
FontFamily: = Tgpfontfamily.create (' Arial black ');
StringFormat: = tgpstringformat.create;
Stringformat.setalignment (Stringalignmentcenter);
Stringformat.setlinealignment (Stringalignmentcenter);
Path. GetBounds (RECTF);
Path. AddString (' Delphi ',-1, fontFamily, Fontstyleregular, RECTF, StringFormat);
Path. Warp (pgppointf (@ptfs), Length (PTFs), RECTF);
G.fillpath (b, Path);
For I: = 0 to PtCount-1 do
G.drawrectangle (P, Makerect (ptfs[i). X-3, Ptfs[i]. Y-3, 6, 6));
Stringformat.free;
Fontfamily.free;
Path. Free;
B.free;
P.free;
G.free;
End
Procedure Tform1.checkbox1click (Sender:tobject);
Begin
Ptcount: = 4;
If checkbox1.checked then ptcount: = 3;
Repaint;
End
Procedure Tform1.formmousedown (Sender:tobject; Button:tmousebutton;
Shift:tshiftstate; X, Y:integer);
Var
I:integer;
Begin
For I: = 0 to 3 do
If PtInRect (Bounds Trunc (ptfs[i). X-3), Trunc (Ptfs[i]. Y-3), 6, 6), point (X, Y)) then
Begin
PTI: = i;
Flag: = True;
Exit;
End
End
Procedure Tform1.formmousemove (Sender:tobject; Shift:tshiftstate; X
Y:integer);
Begin
If Flag then
Begin
Ptfs[pti]. x: = x;
Ptfs[pti]. Y: = y;
Repaint;
End
End
Procedure Tform1.formmouseup (Sender:tobject; Button:tmousebutton;
Shift:tshiftstate; X, Y:integer);
Begin
Flag: = False;
End
End.