专注于互联网--专注于架构

最新标签
网站地图
文章索引
Rss订阅

首页 »PHP教程 » GdiPlus[38]: IGPGraphicsPath ( 5) 路径标记 »正文

GdiPlus[38]: IGPGraphicsPath ( 5) 路径标记

来源: 发布时间:星期四, 2009年12月24日 浏览:0次 评论:0
IGPGraphicsPath.SetMarker  //建立个标记  
IGPGraphicsPath.ClearMarkers //取消全部标记  


  在路径中每建立个图形都可以同时做个 Marker,

  真正使用这些个标记时, 主要通过 IGPGraphicsPathIterator NextMarker 思路方法.

  下面是建立并遍历 Marker 演示代码, 暂未使用 IGPGraphicsPathIterator.

uses GdiPlus; 
 
procedure TForm1.FormCreate(Sender: TObject); 
var 
 Pt1,Pt2: TGPPo; 
 Rect: TGPRect; 
 Path: IGPGraphicsPath; 
 i: Integer; 
 str: ; 
begin 
 Pt1.Initialize(20, 20); 
 Pt2.Initialize(150, 150); 
 Rect.InitializeFromLTRB(Pt1.X, Pt1.Y, Pt2.X , Pt2.Y); 
 Path := TGPGraphicsPath.Create; 
 
 { 路径有 4个图形(或叫子路径构成), 并在每个图形后做了 marker; 第个前不需要也作不上. } 
 Path.AddRectangle(Rect); 
 Path.SetMarker; 
 
 Path.AddEllipse(Rect); 
 Path.SetMarker; 
 
 Path.AddLine(Pt1.X, Pt1.Y, Pt2.X, Pt2.Y); 
 Path.SetMarker; 
 
 Path.AddLine(Pt1.X, Pt2.Y, Pt2.X, Pt1.Y); 
 Path.SetMarker; 
 
 { 检索看看都是哪个点上有 Marker, 它类型标识是 $20 } 
 str := ''; 
 for i := 0 to Path.PoCount - 1 do 
   Path.PathTypes[i] and $20 = $20 then 
   str := str + IntToStr(i+1) + ' '; 
 ShowMessage(TrimRight(str)); // 4 17 19 21 
 
 { 执行 ClearMarkers, 重新检索看看 } 
 Path.ClearMarkers; 
 str := ''; 
 for i := 0 to Path.PoCount - 1 do 
   Path.PathTypes[i] and $20 = $20 then 
   str := str + IntToStr(i+1) + ' '; 
 ShowMessage(TrimRight(str)); // 当然不会再有了 
end; 


  使用 IGPGraphicsPathIterator 检索 Marker 例子:

uses GdiPlus; 
 
var 
 Path: IGPGraphicsPath; 
 PathIterator: IGPGraphicsPathIterator; 
 
procedure TForm1.FormCreate(Sender: TObject); 
var 
 Pt1,Pt2: TGPPo; 
 Rect: TGPRect; 
begin 
 Pt1.Initialize(20, 20); 
 Pt2.Initialize(150, 150); 
 Rect.InitializeFromLTRB(Pt1.X, Pt1.Y, Pt2.X , Pt2.Y); 
 Path := TGPGraphicsPath.Create; 
 
 //建立 4个图形并添加两个标记 
 Path.AddRectangle(Rect); 
 Path.SetMarker; 
 
 Path.AddEllipse(Rect); 
 
 Path.AddLine(Pt1.X, Pt1.Y, Pt2.X, Pt2.Y); 
 Path.SetMarker; 
 
 Path.AddLine(Pt1.X, Pt2.Y, Pt2.X, Pt1.Y); 
 
 //建立 PathIterator 
 PathIterator := TGPGraphicsPathIterator.Create(Path); 
end; 
 
procedure TForm1.Button1Click(Sender: TObject); 
var 
 m1,m2: Integer; 
 i: Integer; 
begin 
 i := 0; 
 PathIterator.Rewind; 
 while PathIterator.NextMarker(m1, m2) > 0 do 
 begin 
  Inc(i); 
  ShowMessageFmt('第 %d - %d 个标记范围: %d - %d', [i-1, i, m1, m2]); 
 end; 
{ 
 第 0 - 1 个标记范围: 0 - 3 
 第 1 - 2 个标记范围: 4 - 18 
 第 2 - 3 个标记范围: 19 - 20 
} //就添加了两个标记如何会检索出 3个范围呢? 两个点把路径分成了 3段! 
end; 
 
//IGPGraphicsPathIterator.NextMarker 第 2种使用方法 
procedure TForm1.Button2Click(Sender: TObject); 
var 
 i,r: Integer; 
begin 
 i := 0; 
 PathIterator.Rewind; 
 while True do 
 begin 
  r := PathIterator.NextMarker(Path); 
   r = 0 then Break; 
  Inc(i); 
  ShowMessageFmt('第 %d - %d 个标记间共有 %d 个点', [i-1, i, r]); 
 end; 
{ 
 第 0 - 1 个标记间共有 4 个点 
 第 1 - 2 个标记间共有 15 个点 
 第 2 - 3 个标记间共有 2 个点 
} 
end; 


标签:
0

相关文章

读者评论

发表评论

  • 昵称:
  • 内容: