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

GdiPlus[30]: IGPPen: 線帽

編輯:Delphi

StartCap 和 EndCap 屬性分別用來讀寫兩段的線帽, 測試圖:

GdiPlus[30]: IGPPen: 線帽

  StartCap 和 EndCap 測試代碼:

uses GdiPlus; 
 
procedure TForm1.FormPaint(Sender: TObject); 
const 
 CapArr: array[0 ..8 ] of Byte = (0 , 1, 2, 3, $10, $11, $12, $13, $14); 
var 
 Graphics: IGPGraphics; 
 Pen: IGPPen; 
 Pt1,Pt2: TGPPoint; 
 i: Integer; 
begin 
 Pt1.Initialize(20, 20); 
 Pt2.Initialize(200, 20); 
 Graphics := TGPGraphics.Create(Handle); 
 Pen := TGPPen.Create($FF2E8B57, 11); 
 
 for i := 0 to Length(CapArr) - 1 do 
 begin 
  Pen.StartCap := TGPLineCap(CapArr[i]); 
  Pen.EndCap := Pen.StartCap; 
  Graphics.DrawLine(Pen, Pt1, Pt2); 
  Graphics.TranslateTransform(0, Pt1.Y * 1.5); 
 end; 
end; 

  DashCap 屬性用來讀寫虛線線帽, 這在實線中沒有效果; 測試圖:

GdiPlus[30]: IGPPen: 線帽

  DashCap 測試代碼:

uses GdiPlus; 
 
procedure TForm1.FormPaint(Sender: TObject); 
var 
 Graphics: IGPGraphics; 
 Pen: IGPPen; 
 Pt1,Pt2: TGPPoint; 
begin 
 Pt1.Initialize(20, 20); 
 Pt2.Initialize(240, 20); 
 Graphics := TGPGraphics.Create(Handle); 
 Pen := TGPPen.Create($FF4169E1, 11); 
 Pen.DashStyle := DashStyleDashDot; 
 
 Pen.DashCap := DashCapFlat; 
 Graphics.DrawLine(Pen, Pt1, Pt2); 
 Graphics.TranslateTransform(0, Pt1.Y * 1.5); 
 
 Pen.DashCap := DashCapRound; 
 Graphics.DrawLine(Pen, Pt1, Pt2); 
 Graphics.TranslateTransform(0, Pt1.Y * 1.5); 
 
 Pen.DashCap := DashCapTriangle; 
 Graphics.DrawLine(Pen, Pt1, Pt2); 
end; 

  可通過 SetLineCap 方法一起設定 StartCap、EndCap、DashCap, 測試圖:

GdiPlus[30]: IGPPen: 線帽

  SetLineCap 測試代碼:

uses GdiPlus; 
 
procedure TForm1.FormPaint(Sender: TObject); 
var 
 Graphics: IGPGraphics; 
 Pen: IGPPen; 
begin 
 Graphics := TGPGraphics.Create(Handle); 
 Pen := TGPPen.Create($FFC71585, 11); 
 Pen.DashStyle := DashStyleDashDot; 
 
 Pen.SetLineCap(LineCapRoundAnchor, LineCapArrowAnchor, DashCapTriangle); 
 
 Graphics.DrawLine(Pen, 20, 30, 300, 30); 
end; 


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