Direct2D (25) : 将画笔线条所占用的区域转换为路径 - ID2D1Geometry.Widen()



uses Direct2D, D2D1;



procedure TForm1.FormPaint(Sender: TObject);

var

  cvs: TDirect2DCanvas;

  iGeometry: ID2D1Geometry;

  iPathGeometry: ID2D1PathGeometry;

  iGeometrySink: ID2D1GeometrySink;

begin

  {建立一个几何对象 iGeometry}

  D2DFactory.CreateEllipseGeometry(

    D2D1Ellipse(D2D1PointF(ClientWidth/2, ClientHeight/2), ClientWidth/4, ClientHeight/4),

    ID2D1EllipseGeometry(iGeometry)

  );



  cvs := TDirect2DCanvas.Create(Canvas, ClientRect);

  cvs.BeginDraw;



  {绘制 iGeometry}

  cvs.Pen.Color := clYellow;

  cvs.Pen.Width := 25;

  cvs.DrawGeometry(iGeometry);



  {创建 iPathGeometry,并把 iGeometry 的线条所占用的区域转换成新的路径到 iPathGeometry}

  D2DFactory.CreatePathGeometry(iPathGeometry);

  iPathGeometry.Open(iGeometrySink);

  iGeometry.Widen(25, nil, TD2DMatrix3x2F.Identity, 0, iGeometrySink); //参数4是曲直容差,效果图中包含把它设为 9 的演示

  iGeometrySink.Close;



  {绘制 iPathGeometry}

  cvs.Pen.Color := clRed;

  cvs.Pen.Width := 1;

  cvs.DrawGeometry(iPathGeometry);



  cvs.EndDraw;

  cvs.Free;

end;



procedure TForm1.FormResize(Sender: TObject);

begin

  Repaint;

end;



效果图:

Direct2D (25) : 将画笔线条所占用的区域转换为路径 - ID2D1Geometry.Widen()

你可能感兴趣的:(ide)