其他分享
首页 > 其他分享> > Direct2D (3) : 使用浮点参数绘制基本图形

Direct2D (3) : 使用浮点参数绘制基本图形

作者:互联网

Direct2D (3) : 使用浮点参数绘制基本图形


{相关方法}
TDirect2DCanvas.DrawEllipse();
TDirect2DCanvas.DrawLine();
TDirect2DCanvas.DrawRectangle();
TDirect2DCanvas.DrawRoundedRectangle();
TDirect2DCanvas.FillEllipse();
TDirect2DCanvas.FillRectangle();
TDirect2DCanvas.FillRoundedRectangle();

{相关结构}
TD2DPoint2f      (或 D2D_POINT_2F)	//浮点点结构;		构建函数 D2D1PointF(); 可从 TPoint 隐式转换到 TD2DPoint2f
TD2D1Ellipse     (或 D2D1_ELLIPSE)	//浮点椭圆结构;		构建函数 D2D1Ellipse(); 
TD2D1RectF       (或 D2D1_RECT_F)	//浮点矩形结构;		构建函数 D2D1RectF();  可从 TRect 隐式转换到 TD2D1RectF
TD2D1RoundedRect (或 D2D1_ROUNDED_RECT)	//浮点圆角矩形结构;	构建函数 D2D1RoundedRect();


测试代码:

uses Direct2D, D2D1;

procedure TForm1.FormPaint(Sender: TObject);
var
  cvs: TDirect2DCanvas;
  fPt: TD2DPoint2f;
  fLeft,fTop: Single;
begin
  fPt := D2D1PointF(ClientWidth / 2, ClientHeight / 2);
  fLeft := ClientWidth / 4;
  fTop := ClientHeight / 4;

  cvs := TDirect2DCanvas.Create(Canvas, ClientRect);
  cvs.BeginDraw;
  cvs.Pen.Color := clRed;
  cvs.Pen.Width := 2;

  cvs.Brush.Color := clBlack;
  cvs.FillRectangle(D2D1RectF(fLeft, fTop, fLeft*3, fTop*3));
  cvs.Brush.Color := clGreen;
  cvs.FillRoundedRectangle(D2D1RoundedRect(D2D1RectF(fLeft, fTop, fLeft*3, fTop*3), 32, 32));
  cvs.Brush.Color := clBlue;
  cvs.FillEllipse(D2D1Ellipse(fPt, fLeft, fTop));

  cvs.DrawRectangle(D2D1RectF(fLeft, fTop, fLeft*3, fTop*3));
  cvs.DrawRoundedRectangle(D2D1RoundedRect(D2D1RectF(fLeft, fTop, fLeft*3, fTop*3), 32, 32));
  cvs.DrawEllipse(D2D1Ellipse(fPt, fLeft, fTop));
  cvs.DrawLine(D2D1PointF(fLeft, fTop), D2D1PointF(fLeft*3, fTop*3));

  cvs.EndDraw;
  cvs.Free;
end;

procedure TForm1.FormResize(Sender: TObject);
begin
  Repaint;
end;

posted on 2011-03-31 14:01  万一  阅读(2336)  评论(1)  编辑  收藏

标签:fLeft,fTop,D2D1RectF,TDirect2DCanvas,cvs,浮点,Direct2D,绘制
来源: https://blog.51cto.com/u_14617575/2745422