RotateTransform, ScaleTransform and other transformations
RotateTransform {旋转}
ScaleTransform {缩放}
TranslateTransform {平移}
SetTransform {综合的矩阵变换}
ResetTransform {取消变换}This example effect chart:
Code files:Unit Unit1;
Interface
Uses
Windows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms,
Dialogs, Comctrls, Stdctrls, Extctrls;
Type
TForm1 = Class (Tform)
Trackbar1:ttrackbar;
Trackbar2:ttrackbar;
Procedure Formcreate (Sender:tobject);
Procedure Formpaint (Sender:tobject);
Procedure Trackbar1change (Sender:tobject);
Procedure Trackbar2change (Sender:tobject);
End
Var
Form1:tform1;
Implementation
{$R *.DFM}
Uses Gdipobj, GDIPAPI;
Procedure Tform1.formcreate (Sender:tobject);
Begin
Trackbar1.min: =-50;
Trackbar1.max: = 50;
Trackbar1.position: = 0;
Trackbar2.min: = 1;
Trackbar2.max: = 10;
Trackbar2.position: = 10;
End
Procedure Tform1.formpaint (Sender:tobject);
Const
COLORS:ARRAY[0..3] of Tgpcolor = (aclred, Aclyellow, Aclgreen, Aclblue);
Var
G:tgpgraphics;
P:tgppen;
Path:tgpgraphicspath;
Pb:tgppathgradientbrush;
Num:integer;
Begin
G: = Tgpgraphics.create (Canvas.handle);
P: = tgppen.create (aclred);
Path: = Tgpgraphicspath.create;
Path. AddRectangle (Makerect (50, 20, 120, 100));
PB: = tgppathgradientbrush.create (path);
Num: = Length (colors);
Pb. Setsurroundcolors (@colors, num);
Pb. Resettransform;
Pb. RotateTransform (trackbar1.position);
Pb. ScaleTransform (TRACKBAR2.POSITION/10, TRACKBAR2.POSITION/10);
G.fillpath (Pb, Path);
G.drawpath (P, path);
Pb. Free;
Path. Free;
P.free;
G.free;
End
Procedure Tform1.trackbar1change (Sender:tobject);
Begin
Repaint;
End
Procedure Tform1.trackbar2change (Sender:tobject);
Begin
Repaint;
End
End.