//创建并填充区域 var g:TGPGraphics; sb:TGPSolidBrush; region:TGPRegion;{定义区域} begin g:=TGPGraphics.Create(Canvas.Handle); g.Clear(aclWhite); sb:=TGPSolidBrush.Create(aclGold); region:=TGPRegion.Create(MakeRect(20,20,150,150));{建立区域} g.FillRegion(sb,region);{填充区域} region.Free; sb.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); g.Clear(aclWhite); sb:=TGPSolidBrush.Create(aclRed); path:=TGPGraphicsPath.Create(); path.AddPolygon(pgppoint(@pts),Length(pts)); region:=TGPRegion.Create(path);//根据路径建立区域 g.FillRegion(sb,region); region.Free; path.Free; sb.Free; g.Free; end;
//区域联合 var g:TGPGraphics; region:TGPRegion; sb:TGPSolidBrush; begin g:=TGPGraphics.Create(Canvas.Handle); g.Clear(aclWhite); sb:=TGPSolidBrush.Create(aclRed); region:=TGPRegion.Create(MakeRect(60,10,50,150));{建立区域} region.Union(MakeRect(10,60,160,50));{区域联合} g.FillRegion(sb,region);{填充} region.Free; sb.Free; g.Free; end;
//用区域剪切画板 var g:TGPGraphics; p:TGPPen; sb:TGPSolidBrush; region:TGPRegion; font:TGPFont; begin g:=TGPGraphics.Create(Canvas.Handle); p:=TGPPen.Create(aclRed); sb:=TGPSolidBrush.Create(aclYellowGreen); font:=TGPFont.Create('宋体',12); region:=TGPRegion.Create(MakeRect(60,0,50,150));{建立区域} region.Union(MakeRect(10,60,160,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; region.Free; font.Free; p.Free; g.Free; end;