zoukankan      html  css  js  c++  java
  • Direct2D (5) : 绘制自定义图形


    下面是通过自定义函数绘制菱形的测试代码。

    uses Direct2D, D2D1;
    
    {自定义的绘制菱形的函数}
    function GetDiamondPath(ptLeft, ptTop: TD2DPoint2f): ID2D1PathGeometry; //返回路径接口
    var
      sink: ID2D1GeometrySink; //给路径添加图形的接口
      ptRight,ptBottom: TD2DPoint2f;
    begin
      {算出另外两个点}
      ptRight := D2D1PointF((ptTop.x-ptLeft.x)*2+ptLeft.x, ptLeft.y);
      ptBottom := D2D1PointF(ptTop.x, (ptLeft.y-ptTop.y)*2+ptTop.y);
    
      {构建 ID2D1PathGeometry}
      D2DFactory.CreatePathGeometry(Result);
      {建立并启用 ID2D1GeometrySink}
      Result.Open(sink);
      {开始添加图形,}
      sink.BeginFigure(ptLeft, D2D1_FIGURE_BEGIN_FILLED); //选项 D2D1_FIGURE_BEGIN_FILLED 标识图形可以填充
      sink.AddLine(ptTop);
      sink.AddLine(ptRight);
      sink.AddLine(ptBottom);
      {结束图形并关闭 ID2D1GeometrySink}
      sink.EndFigure(D2D1_FIGURE_END_CLOSED); //选项 D2D1_FIGURE_END_CLOSED 标识图形自动封闭
      sink.Close;
    end;
    
    {绘制}
    procedure TForm1.FormPaint(Sender: TObject);
    var
      path: ID2D1PathGeometry;
    begin
      path := GetDiamondPath(D2D1PointF(ClientWidth/5, ClientHeight/2), D2D1PointF(ClientWidth/2, ClientHeight/5));
      with TDirect2DCanvas.Create(Canvas, ClientRect) do
      begin
        Pen.Color := clRed;
        Brush.Color := clYellow;
        BeginDraw;
        FillGeometry(path);
        DrawGeometry(path);
        EndDraw;
        Free;
      end;
    end;
    
    procedure TForm1.FormResize(Sender: TObject);
    begin
      Repaint;
    end;
    


    效果图:



  • 相关阅读:
    matlab colormap
    张量的基本概念
    河南省测绘资质单位大全
    Meanshift算法
    图形图像的绘制 GandyDraw
    leetcode
    Java 实现装饰(Decorator)模式
    Python
    Asp.Net+Easyui实现重大CRUD
    Scriptcase演示程序,现在,他们使用SC多么简单的开发系统
  • 原文地址:https://www.cnblogs.com/del/p/2001499.html
Copyright © 2011-2022 走看看