//线性渐变画刷
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 指定从上到下的渐变。


posted on 2007-12-27 16:49  万一  阅读(4883)  评论(6编辑  收藏  举报