//線性漸變畫刷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
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;
end;
線性漸變的方向參數:
Delphi 微軟 說明 LinearGradientModeBackwardDiagonal BackwardDiagonal 指定從右上到左下的漸變。 LinearGradientModeForwardDiagonal ForwardDiagonal 指定從左上到右下的漸變。 LinearGradientModeHorizontal Horizontal 指定從左到右的漸變。 LinearGradientModeVertical Vertical 指定從上到下的漸變。