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;
    

  • 相关阅读:
    Java控制台五子棋编码学习
    Java Web基础
    JavaScript Unit Test with Mocha
    Cross-browser Testing Tool
    GRIDVIEW 控件
    C# .net ACCESS 网页增删改查 --留言板
    在一般处理文件中访问Session需要添加IRequiresSessionState(转载)
    win7 IIS7 发布网站 出现 "处理程序“PageHandlerFactory-Integrated”在其模块列表中有一个错误"
    http://www.cnblogs.com/hanshuhe/archive/2012/08/30/vss.html
    win 7 配置 IIS
  • 原文地址:https://www.cnblogs.com/del/p/2001344.html
Copyright © 2011-2022 走看看