Gdiplus [37]: igpgraphicspath (4) path Transformation

Source: Internet
Author: User
Igpgraphicspath. flatten (); // convert the curve in the path to an approximate straight line segment (only the betiller line and straight line in the path ). igpgraphicspath. outline (); // same as flatten (); igpgraphicspath. warp (); // The quadrilateral or parallelogram is distorted. igpgraphicspath. widen (); // converts a contour to a range. igpgraphicspath. transform (); // matrix transformation; in fact, the above methods contain parameters of matrix transformation.
 

Flatten test diagram:


Flatten test code:
Uses gdiplus; Procedure kernel (Sender: tobject); var graphics: igpgraphics; pen: igppen; brush: igpbrush; Path, pathclone: igpgraphicspath; rect: tgprect; Pt: tgppoint; Matrix: igpmatrix; begin graphics: = tgpgraphics. create (canvas. handle); pen: = tgppen. create ($ ffff0000); brush: = tgpsolidbrush. create ($ 800000ff); Path: = tgpgraphicspath. create; rect. initialize (20, 20,200, 75); Path. addellipse (rect); pathclone: = path. clone; graphics. drawpath (pen, pathclone); for Pt IN pathclone. pathpointsi do graphics. fillrectangle (brush, PT. x-2, PT. y-2, 4, 4); graphics. translatetransform (0, rect. Y + rect. height); pathclone: = path. clone; pathclone. flatten (); // The default value of parameter 2 is 0.25 graphics. drawpath (pen, pathclone); for Pt IN pathclone. pathpointsi do graphics. fillrectangle (brush, PT. x-2, PT. y-2, 4, 4); graphics. translatetransform (0, rect. Y + rect. height); pathclone: = path. clone; pathclone. flatten (nil, 10); graphics. drawpath (pen, pathclone); for Pt IN pathclone. pathpointsi do graphics. fillrectangle (brush, PT. x-2, PT. y-2, 4, 4); graphics. translatetransform (0, rect. Y + rect. height); pathclone: = path. clone; pathclone. flatten (nil, 25); graphics. drawpath (pen, pathclone); for Pt IN pathclone. pathpointsi do graphics. fillrectangle (brush, PT. x-2, PT. y-2, 4, 4); graphics. translatetransform (0, rect. Y + rect. height); pathclone: = path. clone; pathclone. flatten (nil, 50); graphics. drawpath (pen, pathclone); for Pt IN pathclone. pathpointsi do graphics. fillrectangle (brush, PT. x-2, PT. y-2, 4, 4); graphics. translatetransform (0, rect. Y + rect. height); pathclone: = path. clone; matrix: = tgpmatrix. create; matrix. scale (1, 0.5); matrix. translate (0, 20); pathclone. flatten (matrix, 25); graphics. drawpath (pen, pathclone); for Pt IN pathclone. pathpointsi do graphics. fillrectangle (brush, PT. x-2, PT. y-2, 4, 4); graphics. translatetransform (0, rect. Y + rect. height); end;
 

Warp test diagram:


Warp test code:
Uses gdiplus; const {when the array has three elements, 0: upper left; 1: upper right; 2: lower left; 3: Automatically adjusted to parallelogram} pts3: array [0 .. 2] of tgppointf = (X: 20; Y: 20), (X: 250; Y: 0), (X: 20; Y: 120 )); {when the array has four elements, 0: Top left; 1: Top right; 2: Bottom left; 3: bottom right} pts4: array [0 .. 3] of tgppointf = (X: 20; Y: 20), (X: 220; Y: 10), (X: 20; Y: 120), (X: 270; Y: 190); procedure merge (Sender: tobject); var graphics: igpgraphics; brush: igphatchbrush; Path, pathclone: igpgraphicspath; rect: tgprectf; fontfamily: disabled; stringformat: igpstringformat; Pt: tgppointf; begin graphics: = tgpgraphics. create (canvas. handle); brush: = tgphatchbrush. create (hatchstyleshingle, $ ff808080, $ ff483d8b); rect. initialize (20, 20,250,120); fontfamily: = tgpfontfamily. create ('arial black'); stringformat: = tgpstringformat. create; stringformat. alignment: = stringalignmentcenter; stringformat. linealignment: = stringalignmentcenter; Path: = tgpgraphicspath. create; Path. addrectangle (rect); Path. addstring ('delphi ', fontfamily, [], 56, rect, stringformat); pathclone: = path. clone; graphics. fillpath (brush, pathclone); graphics. translatetransform (0, rect. y * 2 + rect. height); // pathclone: = path. clone; pathclone. warp (pts3, rect); graphics. fillpath (brush, pathclone); graphics. translatetransform (0, rect. y * 2 + rect. height); pathclone: = path. clone; pathclone. warp (pts4, rect); graphics. fillpath (brush, pathclone); graphics. translatetransform (0, rect. y * 2 + rect. height); end;
 

Widen test diagram:


Widen test code:
uses GdiPlus;procedure TForm1.FormPaint(Sender: TObject);var  Graphics: IGPGraphics;  Pen: IGPPen;  Brush: IGPHatchBrush;  Path, PathClone: IGPGraphicsPath;  Rect: TGPRect;begin  Graphics := TGPGraphics.Create(Canvas.Handle);  Pen := TGPPen.Create($AAFF0000, 20);  Brush := TGPHatchBrush.Create(HatchStyleShingle, $FFC0C0C0, $FF888888);  Path := TGPGraphicsPath.Create;  Rect.Initialize(20, 20, 200, 75);  Path.AddEllipse(Rect);  PathClone := Path.Clone;  Graphics.FillPath(Brush, PathClone);  Graphics.DrawPath(Pen, PathClone);  Graphics.TranslateTransform(0, Rect.Y*2 + Rect.Height);  PathClone := Path.Clone;  PathClone.Widen(Pen);  Graphics.FillPath(Brush, PathClone);  Pen.Width := 1;  Graphics.DrawPath(Pen, PathClone);  Graphics.TranslateTransform(0, Rect.Y + Rect.Height);end;
 

Translate test diagram:


Translate test code:
uses GdiPlus;procedure TForm1.FormPaint(Sender: TObject);var  Graphics: IGPGraphics;  Brush: IGPHatchBrush;  Path,PathClone: IGPGraphicsPath;  FontFamily: IGPFontFamily;  Pt: TGPPointF;  Matrix: IGPMatrix; begin  Graphics := TGPGraphics.Create(Canvas.Handle);  Brush := TGPHatchBrush.Create(HatchStyleZigZag, $FFC0C0C0, $FFFF0000);  FontFamily := TGPFontFamily.Create('Arial Black');  Pt.Initialize(0, 0);  Path := TGPGraphicsPath.Create;  Path.AddString('Delphi', FontFamily, [], 32, Pt, nil);  Graphics.FillPath(Brush, Path);  PathClone := Path.Clone;  Matrix := TGPMatrix.Create;  Matrix.Scale(2, 2);  Matrix.Rotate(-30);  Matrix.Translate(-35, 45);  PathClone.Transform(Matrix);  Graphics.FillPath(Brush, PathClone);    PathClone := Path.Clone;  Matrix.Reset;  Matrix.Scale(2.5, 6);  Matrix.Translate(0, 18);  PathClone.Transform(Matrix);  Graphics.FillPath(Brush, PathClone);end;
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.