GDI+ 学习记录(29): 区域 - Region

//创建并填充区域
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;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值