程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> Delphi GDI+ 學習記錄(29): 區域 - Region

Delphi GDI+ 學習記錄(29): 區域 - Region

編輯:Delphi

//創建並填充區域

var
 g: TGPGraphics;
 sb: TGPSolidBrush;
 region: TGPRegion; {定義區域}
begin
 g := TGPGraphics.Create(Canvas.Handle);
 sb := TGPSolidBrush.Create(aclGold);
 region := TGPRegion.Create(MakeRect(50, 50, 150, 150)); {建立區域}
 g.FillRegion(sb, region); {填充區域}
 sb.Free;
 region.Free;
 g.Free;
end;

//根據路徑建立區域

var
 g: TGPGraphics;
 path: TGPGraphicsPath;
 region: TGPRegion;
 sb: TGPSolidBrush;
const
 pts: array[0..3] of TGPPoint =
  ((x:10 ; y:10 ),
   (x:150; y:10 ),
   (x:100; y:75 ),
   (x:100; y:150));
begin
 g := TGPGraphics.Create(Canvas.Handle);
 sb := TGPSolidBrush.Create(aclRed);
 path := TGPGraphicsPath.Create;
 path.AddPolygon(PGPPoint(@pts), Length(pts));
 region := TGPRegion.Create(path); {根據路徑建立區域}
 g.FillRegion(sb, region);
 g.Free;
 path.Free;
 region.Free;
 sb.Free;
end;

//區域聯合

var
 g : TGPGraphics;
 sb: TGPSolidBrush;
 region: TGPRegion;
begin
 g := TGPGraphics.Create(Canvas.Handle);
 sb := TGPSolidBrush.Create(aclYellowGreen);
 region := TGPRegion.Create(MakeRect(50, 0, 50, 150)); {建立區域}
 region.Union(MakeRect(0, 50, 150, 50)); {區域聯合}
 g.FillRegion(sb, region); {填充}
 sb.Free;
 region.Free;
 g.Free;
end;

//用區域剪切畫板

var
 g : TGPGraphics;
 sb: TGPSolidBrush;
 p: TGPPen;
 region: TGPRegion;
 font: TGPFont;
begin
 g := TGPGraphics.Create(Canvas.Handle);
 sb := TGPSolidBrush.Create(aclYellowGreen);
 p := TGPPen.Create(aclRed);
 font := TGPFont.Create('宋體',12);
 region := TGPRegion.Create(MakeRect(50, 0, 50, 150)); {建立區域}
 region.Union(MakeRect(0, 50, 150, 50)); {區域聯合}
 g.FillRegion(sb, region);
 g.SetClip(region); {用區域剪切畫板}
 g.DrawLine(p, 0, 0, 100, 100); {測試畫板剪切後的直線}
 sb.SetColor(aclBlack);
 g.DrawString('萬一萬一萬一', -1, font, MakePoint(20.0,20.0), sb); {測試文本}
 sb.Free;
 p.Free;
 region.Free;
 font.Free;
 g.Free;
end;

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