//路徑漸變畫刷
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;
//設置路徑畫刷的中心點
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, 140, 70);
pb:= TGPPathGradIEntBrush.Create(path);
pb.SetCenterPoint(MakePoint(120, 40)); {設置中心點}
pb.SetCenterColor(MakeColor(255, 0, 0, 255));
num := 1;
pb.SetSurroundColors(@colors, num);
g.FillEllipse(pb, 0, 0, 140, 70);
path.Free;
pb.Free;
g.Free;
end;
//使用灰度校正
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.SetGamMacorrection(True); {使用灰度校正}
num := 1;
pb.SetSurroundColors(@colors, num);
g.FillEllipse(pb, 0, 0, 166, 88);
path.Free;
pb.Free;
g.Free;
end;
//多種顏色及位置
var
g : TGPGraphics;
pts: array[0..2] of TGPPoint;
pb: TGPPathGradIEntBrush;
const
colors: array[0..2] of TGPColor = (aclGreen, aclAqua, aclBlue);
pos: array[0..2] of Single = (0.0, 0.25, 1.0); {顏色位置需要 >0、<1, 是百分百}
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); {根據點數組指針建立路徑畫刷}
pb.SetInterpolationColors(@colors, @pos, 3); {設置顏色位置}
g.FillRectangle(pb, 0, 0, 200, 200);
pb.Free;
g.Free;
end;
//設置多種周邊顏色
var
g: TGPGraphics;
path: TGPGraphicsPath;
pb: TGPPathGradIEntBrush;
colors: array[0..9] of TGPColor;
num: Integer;
const
pts : array[0..9] of TGPPoint =
((x:75 ; y:0 ), (x:100; y:50 ),
(x:150; y:50 ), (x:112; y:75 ),
(x:150; y:150), (x:75 ; y:100),
(x:0 ; y:150), (x:37 ; y:75 ),
(x:0 ; y:50 ), (x:50 ; y:50 ));
begin
g := TGPGraphics.Create(Canvas.Handle);
path:= TGPGraphicsPath.Create;
path.AddLines(PGPPoint(@pts), 10);
pb:= TGPPathGradIEntBrush.Create(path);
pb.SetCenterColor(MakeColor(255, 255, 0, 0));
colors[0] := MakeColor(255, 0, 0, 0);
colors[1] := MakeColor(255, 0, 255, 0);
colors[2] := MakeColor(255, 0, 0, 255);
colors[3] := MakeColor(255, 255, 255, 255);
colors[4] := MakeColor(255, 0, 0, 0);
colors[5] := MakeColor(255, 0, 255, 0);
colors[6] := MakeColor(255, 0, 0, 255);
colors[7] := MakeColor(255, 255, 255, 255);
colors[8] := MakeColor(255, 0, 0, 0);
colors[9] := MakeColor(255, 0, 255, 0);
num := 10;
pb.SetSurroundColors(@colors, num); {設置多種周邊顏色}
g.FillPath(pb, path);
pb.SetGamMacorrection(True); {使用灰度校正}
g.TranslateTransform(200.0, 0.0);
g.FillPath(pb, path);
path.Free;
pb.Free;
g.Free;
end;
//描繪在不同的區域
var
g : TGPGraphics;
pb: TGPPathGradIEntBrush;
p: TGPPen;
colors: array[0..4] of TGPColor;
num: Integer;
const
pts: array[0..4] of TGPPointF =
((x: 0.0 ; y: 0.0),
(x: 160.0; y: 0.0),
(x: 160.0; y: 200.0),
(x: 80.0 ; y: 150.0),
(x: 0.0 ; y: 200.0));
begin
g := TGPGraphics.Create(Canvas.Handle);
pb:= TGPPathGradIEntBrush.Create(PGPPointF(@pts), 5);
colors[0] := MakeColor(255, 255, 0, 0);
colors[1] := MakeColor(255, 0, 255, 0);
colors[2] := MakeColor(255, 0, 255, 0);
colors[3] := MakeColor(255, 0, 0, 255);
colors[4] := MakeColor(255, 255, 0, 0);
num := 5;
pb.SetSurroundColors(@colors, num);
pb.SetCenterColor(MakeColor(255, 255, 255, 255));
g.FillRectangle(pb, MakeRect(0, 0, 180, 220));
p := TGPPen.Create(aclBlack);
g.DrawRectangle(p, MakeRect(0, 0, 180, 220));
p.Free;
pb.Free;
g.Free;
end;