IGPGraphicsPath.Flatten(); //把路徑中的曲線轉換為近似直線段(路徑中只有 BezIEr 線和直線).
IGPGraphicsPath.Outline(); //同 Flatten();
IGPGraphicsPath.Warp(); //四邊形或平行四邊形扭曲.
IGPGraphicsPath.Widen(); //把輪廓轉換為范圍.
IGPGraphicsPath.Transform(); //矩陣變換; 其實上面幾個方法都包含矩陣變換的參數.
Flatten 測試圖:
Flatten 測試代碼:
uses GdiPlus;
procedure TForm1.FormPaint(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(); //其參數 2 默認是 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 測試圖:
Warp 測試代碼:
uses GdiPlus;
const
{ 數組有三個元素時, 0: 左上; 1: 右上; 2: 左下; 3: 自動調整為平行四邊形 }
pts3: array[0..2] of TGPPointF = ((X:20; Y:20),(X:250; Y:0),(X:20; Y:120));
{ 數組有四個元素時, 0: 左上; 1: 右上; 2: 左下; 3: 右下 }
pts4: array[0..3] of TGPPointF = ((X:20; Y:20),(X:220; Y:10),(X:20; Y:120),(X:270; Y:190));
procedure TForm1.FormPaint(Sender: TObject);
var
Graphics: IGPGraphics;
Brush: IGPHatchBrush;
Path,PathClone: IGPGraphicsPath;
Rect: TGPRectF;
FontFamily: IGPFontFamily;
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 測試圖:
Widen 測試代碼:
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 測試圖:
Translate 測試代碼:
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;