Welcome

首页 / 软件开发 / Delphi / Delphi GDI+学习记录(11): 路径渐变画刷 - PathGradientBrush

Delphi GDI+学习记录(11): 路径渐变画刷 - PathGradientBrush2012-03-23 cnblogs 万一//路径渐变画刷

var
g: TGPGraphics;
path: TGPGraphicsPath;
pb: TGPPathGradientBrush; {声明渐变画刷}
num: Integer;
const
colors: array[0..0] of TGPColor = (aclAqua);
begin
g := TGPGraphics.Create(Canvas.Handle);
path := TGPGraphicsPath.Create;
path.AddEllipse(0,0,166,88);
pb := TGPPathGradientBrush.Create(path); {建立渐变画刷}
pb.SetCenterColor(MakeColor(255,0,0,255)); {中心颜色}
num := 1;
pb.SetSurroundColors(@colors, num); {周围的颜色}
{第二个参数, 不能用常数代替; 它好像是第一个数组参数的索引+1}
g.FillEllipse(pb, 0, 0, 166, 88); {需要和定义的渐变效果的大小一样}
//g.FillPath(pb,path); {直接画路径效果也一样}
path.Free;
pb.Free;
g.Free;
end;

//可以通过点数组的指针创建路径画刷

var
g : TGPGraphics;
pts: array[0..2] of TGPPoint;
pb: TGPPathGradientBrush;
begin
g := TGPGraphics.Create(Canvas.Handle);
pts[0] := MakePoint(100, 0);
pts[1] := MakePoint(200, 200);
pts[2] := MakePoint(0, 200);
pb:= TGPPathGradientBrush.Create(PGPPoint(@pts), 3);
g.FillRectangle(pb, 0, 0, 200, 200);
{没有指定中心颜色和周边颜色, 将分别默认黑色和白色}
pb.Free;
g.Free;
end;