zoukankan      html  css  js  c++  java
  • Direct2D (4) : DrawGeometry() 与 FillGeometry()


    原始的 Direct2D 只提供了几种简单图形(直线、矩形、圆角矩形、椭圆)的绘制与填充,更多集合图形或路径的描绘要使用 DrawGeometry() 和 FillGeometry()。

    既然能绘制更复杂的图形,当然也能绘制基本图形,先试下使用 DrawGeometry()、FillGeometry() 实现矩形、圆角矩形和椭圆。

    方法的参数是 ID2D1Geometry 接口,ID2D1RectangleGeometry、ID2D1RoundedRectangleGeometry、ID2D1EllipseGeometry 都是它的子接口。
    ID2D1Factory 提供了实现这三个接口的方法,从 D2DFactory() 可获取 ID2D1Factory 接口。

    测试代码:

    uses Direct2D, D2D1;
    
    procedure TForm1.FormPaint(Sender: TObject);
    var
      cvs: TDirect2DCanvas;
      fPt: TD2DPoint2f;
      fLeft,fTop: Single;
      iEllipse: ID2D1EllipseGeometry;
      iRectangle: ID2D1RectangleGeometry;
      iRoundedRectangle: ID2D1RoundedRectangleGeometry;
      iFactory: ID2D1Factory;
    begin
      fPt := D2D1PointF(ClientWidth / 2, ClientHeight / 2);
      fLeft := ClientWidth / 4;
      fTop := ClientHeight / 4;
    
      iFactory := D2DFactory();
      iFactory.CreateRectangleGeometry(D2D1RectF(fLeft, fTop, fLeft*3, fTop*3), iRectangle);
      iFactory.CreateRoundedRectangleGeometry(D2D1RoundedRect(D2D1RectF(fLeft, fTop, fLeft*3, fTop*3), 32, 32), iRoundedRectangle);
      iFactory.CreateEllipseGeometry(D2D1Ellipse(fPt, fLeft, fTop), iEllipse);
    
      cvs := TDirect2DCanvas.Create(Canvas, ClientRect);
      cvs.BeginDraw;
      cvs.Pen.Color := clRed;
    
      cvs.Brush.Color := clBlack;
      cvs.FillGeometry(iRectangle);
      cvs.Brush.Color := clGreen;
      cvs.FillGeometry(iRoundedRectangle);
      cvs.Brush.Color := clBlue;
      cvs.FillGeometry(iEllipse);
    
      cvs.DrawGeometry(iRectangle);
      cvs.DrawGeometry(iRoundedRectangle);
      cvs.DrawGeometry(iEllipse);
    
      cvs.EndDraw;
      cvs.Free;
    end;
    
    procedure TForm1.FormResize(Sender: TObject);
    begin
      Repaint;
    end;
    

  • 相关阅读:
    常见业务指标
    1006 换个格式输出整数 (Python)
    1004 成绩排名 (Python)
    1003 我要通过! (Python)
    1008 数组元素循环右移问题 (Python)
    如何使用SSH秘钥链接Github
    在windows下如何正确安装curses模块
    面向数据结构C基础知识点(个人向)
    用Python实现链式调用
    python重点串讲
  • 原文地址:https://www.cnblogs.com/del/p/2001344.html
Copyright © 2011-2022 走看看