• Direct2D (12) : 画刷之 ID2D1RadialGradientBrush



    uses Direct2D, D2D1;
    
    procedure TForm1.FormPaint(Sender: TObject);
    var
      cvs: TDirect2DCanvas;
      iBrush: ID2D1RadialGradientBrush;
      R: TRect;
      rRGBP: TD2D1RadialGradientBrushProperties; //结构包含:中心点、偏移点、横向半径、纵向半径
      arrGradientStop: array[0..1] of TD2D1GradientStop;
      iGradientStops: ID2D1GradientStopCollection;
    begin
      cvs := TDirect2DCanvas.Create(Canvas, ClientRect);
    
      R := ClientRect;
      InflateRect(R, -ClientWidth div 6, -ClientHeight div 6);
    
      rRGBP.center := D2D1PointF(ClientWidth / 2, ClientHeight / 2);
      rRGBP.gradientOriginOffset := D2D1PointF(0, 0);
      rRGBP.radiusX := (R.Right - R.Left) / 2;
      rRGBP.radiusY := (R.Bottom - R.Top) / 2;
    
      arrGradientStop[0].position := 0.0;
      arrGradientStop[0].color := D2D1ColorF(clYellow);
      arrGradientStop[1].position := 1.0;
      arrGradientStop[1].color := D2D1ColorF(clRed);
    
      cvs.RenderTarget.CreateGradientStopCollection(
        @arrGradientStop[0], Length(arrGradientStop), D2D1_GAMMA_2_2, D2D1_EXTEND_MODE_CLAMP, iGradientStops
      );
    
      cvs.RenderTarget.CreateRadialGradientBrush(rRGBP, nil, iGradientStops, iBrush);
      cvs.Brush.Handle := iBrush;
    
      cvs.Pen.Width := 0;
      cvs.BeginDraw;
      cvs.Ellipse(R);
      cvs.EndDraw;
      cvs.Free;
    end;
    
    procedure TForm1.FormResize(Sender: TObject);
    begin
      Repaint;
    end;
    


    效果图:



  • 相关阅读:
    扫描线算法
    评论备份(3)
    评论备份(2)
    二分法的注意事项
    sam模板
    Machine Learning(Andrew Ng)学习笔记
    洛谷P2221 [HAOI2012]高速公路
    洛谷P3233 [HNOI2014]世界树
    P2515 [HAOI2010]软件安装
    BZOJ4293: [PA2015]Siano
  • 原文地址:https://www.cnblogs.com/del/p/2003689.html
Copyright © 2020-2023  润新知