//创建并填充区域
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;
GDI+ 学习记录(29): 区域 - Region
原创
©著作权归作者所有:来自51CTO博客作者JLee79的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
SpringBoot集成Ip2region实现IP白名单
SpringBoot集成Ip2region实现IP白名单 区域判断
IP 白名单 SpringBoot ip2region -
C++ GDI+ Region区域c++ GDI+
-
GDI+简介
GDI+简介
GDI+简介