//線性漸變畫刷var
//定義漸變的位置與顏色
g: TGPGraphics;
lb: TGPLinearGradIEntBrush;
rect: TGPRect;
begin
g := TGPGraphics.Create(Canvas.Handle);
rect := MakeRect(11,11,222,111);
lb := TGPLinearGradientBrush.Create(rect, aclBlue, aclGreen, LinearGradIEntModeHorizontal);
g.FillEllipse(lb, rect);
lb.Free;
g.Free;
end;var
//自定義漸變過渡效果
g : TGPGraphics;
p: TGPPen;
lb: TGPLinearGradIEntBrush;
p1,p2: TGPPoint;
c1,c2: TGPColor;
begin
g := TGPGraphics.Create(Canvas.Handle);
p1 := MakePoint(0, 0);
p2 := MakePoint(200, 100);
c1 := MakeColor(255, 0, 0, 255);
c2 := MakeColor(255, 0, 255, 0);
lb := TGPLinearGradIEntBrush.Create(p1, p2, c1, c2);
p:= TGPPen.Create(lb, 10);
g.DrawLine(p, 0, 0, 600, 300);
g.FillEllipse(lb, 10, 100, 200, 100);
lb.Free;
p.Free;
g.Free;
end;var
end;線性漸變的方向參數:
g : TGPGraphics;
lb: TGPLinearGradIEntBrush;
p1,p2: TGPPoint;
c1,c2: TGPColor;
const
Factors: array[0..2] of Single = (0.0, 0.5, 1.0); {顏色比例}
Positions: array[0..2] of Single = (0.0, 0.2, 1.0); {位置比例, 兩個數組元素須相同}
begin
g := TGPGraphics.Create(Canvas.Handle);
p1 := MakePoint(0, 10);
p2 := MakePoint(200, 10);
c1 := aclBlack;
c2 := aclRed;
lb := TGPLinearGradIEntBrush.Create(p1, p2, c1, c2);
lb.SetBlend(@Factors, @Positions, 3); {設置漸變因子}
g.FillEllipse(lb, 0, 30, 200, 100);
g.FillRectangle(lb, 0, 155, 500, 30);
lb.Free;
g.Free;