GdiPlus[18]: IGPPathGradientBrush 之 CenterColor、SurroundColors


最简单的 IGPPathGradientBrush 就是有一个中心颜色和一组周边颜色的渐变.

这里牵扯到 CenterColor、SurroundColors 属性和 SetSurroundColors 方法.

测试一效果图:

o_09121501.png

测试一代码:

//使用 SetSurroundColors 方法设置周边色组:
uses GdiPlus, GdiPlusHelpers;

procedure TForm1.FormPaint(Sender: TObject);
var
  Brush: IGPPathGradientBrush;
  Rect: TGPRect;
  Path: IGPGraphicsPath;
begin
  Rect.Initialize(10, 10, 200, 150);
  Path := TGPGraphicsPath.Create;
  Path.AddEllipse(Rect);

  Brush := TGPPathGradientBrush.Create(Path);
  Brush.CenterColor := $FF00FF00;
  Brush.SetSurroundColors([$FF000000]);

  Canvas.ToGPGraphics.FillEllipse(Brush, Rect);
end;

//使用 SurroundColors 属性设置周边色组:
uses GdiPlus, GdiPlusHelpers;

procedure TForm1.FormPaint(Sender: TObject);
var
  Brush: IGPPathGradientBrush;
  Rect: TGPRect;
  Path: IGPGraphicsPath;
  Colors: IGPColors;
begin
  Rect.Initialize(10, 10, 200, 150);
  Path := TGPGraphicsPath.Create;
  Path.AddEllipse(Rect);

  Brush := TGPPathGradientBrush.Create(Path);
  Brush.CenterColor := $FF00FF00;

  Colors := TGPArray<TGPColor>.Create(1);
  Colors[0] := $FF000000;
  Brush.SurroundColors := Colors;

  Canvas.ToGPGraphics.FillEllipse(Brush, Rect);
end;

测试二效果图:

o_09121502.png

测试二代码:

//使用 SetSurroundColors 方法设置周边色组:
uses GdiPlus, GdiPlusHelpers;

procedure TForm1.FormPaint(Sender: TObject);
var
  Brush: IGPPathGradientBrush;
  Rect: TGPRect;
  Path: IGPGraphicsPath;
begin
  Rect.Initialize(10, 10, 200, 150);
  Path := TGPGraphicsPath.Create;
  Path.AddRectangle(Rect);

  Brush := TGPPathGradientBrush.Create(Path);
  Brush.CenterColor := $FFFFFFFF;
  Brush.SetSurroundColors([$FFFF0000, $FF00FF00, $FF0000FF, $FFFFFF00]);

  Canvas.ToGPGraphics.FillRectangle(Brush, Rect);
end;

//使用 SurroundColors 属性设置周边色组:
uses GdiPlus, GdiPlusHelpers;

procedure TForm1.FormPaint(Sender: TObject);
var
  Brush: IGPPathGradientBrush;
  Rect: TGPRect;
  Path: IGPGraphicsPath;
  Colors: IGPColors;
begin
  Rect.Initialize(10, 10, 200, 150);
  Path := TGPGraphicsPath.Create;
  Path.AddRectangle(Rect);

  Brush := TGPPathGradientBrush.Create(Path);
  Brush.CenterColor := $FFFFFFFF;

  Colors := TGPArray<TGPColor>.Create(4);
  Colors[0] := $FFFF0000;
  Colors[1] := $FF00FF00;
  Colors[2] := $FF0000FF;
  Colors[3] := $FFFFFF00;
  Brush.SurroundColors := Colors;

  Canvas.ToGPGraphics.FillRectangle(Brush, Rect);
end;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值