程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> GdiPlus[34]: IGPGraphicsPath (一)

GdiPlus[34]: IGPGraphicsPath (一)

編輯:Delphi

 路徑是一組圖形命令, 它能容納所有基本圖形和文本、子路徑:

IGPGraphicsPath.AddLine(); 
IGPGraphicsPath.AddLines(); 
IGPGraphicsPath.AddArc(); 
IGPGraphicsPath.AddBezIEr(); 
IGPGraphicsPath.AddBezIErs(); 
IGPGraphicsPath.AddCurve(); 
IGPGraphicsPath.AddClosedCurve(); 
IGPGraphicsPath.AddRectangle(); 
IGPGraphicsPath.AddRectangles(); 
IGPGraphicsPath.AddEllipse(); 
IGPGraphicsPath.AddPIE(); 
IGPGraphicsPath.AddPolygon(); 
IGPGraphicsPath.AddPath(); 
IGPGraphicsPath.AddString(); 
 
{ 本頁示例相關命令 }  
IGPGraphics.DrawPath      // 繪制路徑  
IGPGraphics.FillPath      // 填充路徑 
IGPGraphicsPath.FillMode    // 路徑填充模式 
 
IGPGraphicsPath.StartFigure   // 開始一個新的圖形, 並不關閉之前的圖形 
IGPGraphicsPath.CloseFigure   // 關閉當前圖形, 並開始新圖形 
IGPGraphicsPath.CloseAllFigures // 關閉之前所有開放圖形, 並開始新圖形 
IGPGraphicsPath.Reset      // 重置路徑 

  FillPath、DrawPath 測試圖:

GdiPlus[34]: IGPGraphicsPath (一)

  FillPath、DrawPath 測試代碼:

uses GdiPlus; 
 
procedure TForm1.FormPaint(Sender: TObject); 
var 
 Graphics: IGPGraphics; 
 Path: IGPGraphicsPath; 
 Pen: IGPPen; 
 Brush: IGPBrush; 
begin 
 Path := TGPGraphicsPath.Create; 
 Path.AddRectangle(TGPRect.Create(20, 20, 96, 60)); 
 Path.AddEllipse(TGPRect.Create(92, 20, 120, 60)); 
 
 Graphics := TGPGraphics.Create(Handle); 
 Pen := TGPPen.Create($FFFF0000, 2); 
 Brush := TGPSolidBrush.Create($FFFFD700); 
 
 Graphics.DrawPath(Pen, Path); 
 Graphics.TranslateTransform(0, 80); 
 
 Graphics.FillPath(Brush, Path); 
 Graphics.TranslateTransform(0, 80); 
 
 Graphics.FillPath(Brush, Path); 
 Graphics.DrawPath(Pen, Path); 
 Graphics.TranslateTransform(0, 80); 
 
 //填充模式有兩種, 默認的是 FillModeAlternate; 可以在建立路徑時指定填充模式 
 Path.FillMode := FillModeWinding; 
 Graphics.FillPath(Brush, Path); 
 Graphics.DrawPath(Pen, Path); 
 Graphics.TranslateTransform(0, 80); 
end; 

StartFigure、CloseFigure、CloseAllFigures、Reset 測試圖:

GdiPlus[34]: IGPGraphicsPath (一)

  StartFigure、CloseFigure、CloseAllFigures、Reset 測試代碼:

uses GdiPlus; 
 
procedure TForm1.FormPaint(Sender: TObject); 
const 
 Pts1: array[0..2] of TGPPoint = ((X:0;  Y:30), (X:30; Y:0), (X:60; Y:30)); 
 Pts2: array[0..2] of TGPPoint = ((X:80; Y:30), (X:110; Y:0), (X:140; Y:30)); 
 Pts3: array[0..2] of TGPPoint = ((X:160; Y:30), (X:190; Y:0), (X:220; Y:30)); 
var 
 Graphics: IGPGraphics; 
 Path: IGPGraphicsPath; 
 Pen: IGPPen; 
 Brush: IGPBrush; 
begin 
 Graphics := TGPGraphics.Create(Handle); 
 Pen := TGPPen.Create($FFFF0000, 2); 
 Brush := TGPSolidBrush.Create($FFD0D0D0); 
 Path := TGPGraphicsPath.Create; 
 
 // 
 Path.AddLines(Pts1); 
 Path.AddLines(Pts2); 
 Path.AddLines(Pts3); 
 Graphics.FillPath(Brush, Path); 
 Graphics.DrawPath(Pen, Path); 
 Graphics.TranslateTransform(0, 50); 
 
 // 
 Path.Reset; 
 Path.StartFigure; 
  Path.AddLines(Pts1); 
 Path.StartFigure; 
  Path.AddLines(Pts2); 
 Path.StartFigure; 
  Path.AddLines(Pts3); 
 
 Graphics.FillPath(Brush, Path); 
 Graphics.DrawPath(Pen, Path); 
 Graphics.TranslateTransform(0, 50); 
 
 // 
 Path.Reset; 
 Path.StartFigure; 
  Path.AddLines(Pts1); 
 Path.StartFigure; 
  Path.AddLines(Pts2); 
 Path.StartFigure; 
  Path.AddLines(Pts3); 
 Path.CloseFigure; 
 Graphics.FillPath(Brush, Path); 
 Graphics.DrawPath(Pen, Path); 
 Graphics.TranslateTransform(0, 50); 
 
 // 
 Path.Reset; 
 Path.StartFigure; 
  Path.AddLines(Pts1); 
 Path.StartFigure; 
  Path.AddLines(Pts2); 
 Path.StartFigure; 
  Path.AddLines(Pts3); 
 Path.CloseAllFigures; 
 Graphics.FillPath(Brush, Path); 
 Graphics.DrawPath(Pen, Path); 
 Graphics.TranslateTransform(0, 50); 
 
 // 
 Path.Reset; 
 Path.StartFigure; 
  Path.AddLines(Pts1); 
  Path.AddLines(Pts2); 
  Path.AddLines(Pts3); 
 Path.CloseFigure; 
 Graphics.FillPath(Brush, Path); 
 Graphics.DrawPath(Pen, Path); 
end; 



  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved