Direct2D (3) : 使用浮点参数绘制基本图形
Direct2D (3) : 使用浮点参数绘制基本图形
涂孟超 发表于3年前
Direct2D (3) : 使用浮点参数绘制基本图形
  • 发表于 3年前
  • 阅读 3
  • 收藏 0
  • 点赞 0
  • 评论 0

{相关方法}
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;

共有 人打赏支持
粉丝 13
博文 2004
码字总数 14107
×
涂孟超
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: