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

GdiPlus[31]: IGPPen: 自定義線帽

編輯:Delphi

自定義線帽可以通過兩個接口: IGPCustomLineCap、IGPAdjustableArrowCap.

  後者繼承與前者, 專用於修改箭頭線帽.

  IGPAdjustableArrowCap 測試效果圖:

GdiPlus[31]: IGPPen: 自定義線帽

  IGPAdjustableArrowCap 測試代碼:

uses GdiPlus; 
 
procedure TForm1.FormPaint(Sender: TObject); 
var 
 Graphics: IGPGraphics; 
 Pen: IGPPen; 
 Cap1,Cap2: IGPAdjustableArrowCap; 
begin 
 Graphics := TGPGraphics.Create(Handle); 
 Pen := TGPPen.Create($FFDC143C , 4 ); 
 
 Cap1 := TGPAdjustableArrowCap.Create(4, 4); 
 Cap2 := TGPAdjustableArrowCap.Create(4, 4, False); 
 Pen.CustomStartCap := Cap1; 
 Pen.CustomEndCap := Cap2; 
 Graphics.DrawLine(Pen, 30, 30, 250, 30); 
 
 Cap1 := TGPAdjustableArrowCap.Create(4, 8); 
 Cap2 := TGPAdjustableArrowCap.Create(4, 8, False); 
 Pen.CustomStartCap := Cap1; 
 Pen.CustomEndCap := Cap2; 
 Graphics.DrawLine(Pen, 30, 80, 250, 80); 
end; 

  IGPCustomLineCap 測試效果圖:

GdiPlus[31]: IGPPen: 自定義線帽

  IGPCustomLineCap 測試代碼:

uses GdiPlus; 
 
procedure TForm1.FormPaint(Sender: TObject); 
const 
 pts: array[0..3] of TGPPoint = ((X:-4; Y:0),(X:0; Y:-4),(X:4; Y:0),(X:0; Y:8)); 
var 
 Graphics: IGPGraphics; 
 Pen: IGPPen; 
 Path1,Path2: IGPGraphicsPath; 
 Cap1,Cap2: IGPCustomLineCap; 
 Pt1,Pt2: TGPPoint; 
begin 
 Graphics := TGPGraphics.Create(Handle); 
 
 Path1 := TGPGraphicsPath.Create; 
 Path1.AddEllipse(TGPRect.Create(-3, -3, 6, 6)); 
 
 Path2 := TGPGraphicsPath.Create; 
 Path2.AddPolygon(pts); 
 
 Pt1.Initialize(50, 30); 
 Pt2.Initialize(50, 150); 
 
 Pen := TGPPen.Create($FF8B0000, 3); 
 
 // 
 Cap1 := TGPCustomLineCap.Create(nil, Path1); 
 Cap2 := TGPCustomLineCap.Create(nil, Path2); 
 Pen.CustomStartCap := Cap1; 
 Pen.CustomEndCap := Cap2; 
 Graphics.DrawLine(Pen, Pt1, Pt2); 
 Graphics.TranslateTransform(Pt1.X, 0); 
 
 // 
 Cap1 := TGPCustomLineCap.Create(nil, Path1, LineCapFlat, 3); 
 Cap2 := TGPCustomLineCap.Create(nil, Path2, LineCapFlat, 4); 
 Pen.CustomStartCap := Cap1; 
 Pen.CustomEndCap := Cap2; 
 Graphics.DrawLine(Pen, Pt1, Pt2); 
 Graphics.TranslateTransform(Pt1.X, 0); 
 
 //注意: 使用填充路徑時, 對構建路徑的參數要求比較古怪... 
 Cap1 := TGPCustomLineCap.Create(Path1, nil); 
 Cap2 := TGPCustomLineCap.Create(Path2, nil); 
 Pen.CustomStartCap := Cap1; 
 Pen.CustomEndCap := Cap2; 
 Graphics.DrawLine(Pen, Pt1, Pt2); 
 Graphics.TranslateTransform(Pt1.X, 0); 
 
 // 
 Cap1 := TGPCustomLineCap.Create(Path1, nil); 
 Cap2 := TGPCustomLineCap.Create(Path2, nil); 
 Cap1.WidthScale := 0.75; 
 Cap2.WidthScale := 1.3; 
 Pen.CustomStartCap := Cap1; 
 Pen.CustomEndCap := Cap2; 
 Graphics.DrawLine(Pen, Pt1, Pt2); 
end; 


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