## 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;``````

### 涂孟超

2013/10/08
0
0
WPF 使用 Direct2D1 画图 绘制基本图形

lindexi_gd
04/19
0
0
Direct2D教程（十二）图层

2017/10/26
0
0

weixin_41101173
04/22
0
0
Windows桌面应用程序(1-2-4-7th) DPI和设备无关的像素

qq_37422196
01/12
0
0

SQL与NoSQL数据库入门基础知识详解

14分钟前
3
0
Jenkinsfile

node { wrap([\$class: 'BuildUser']) { def user = env.BUILD_USER_ID println user }}def InPutCheckBranch(){ timeout(time:10, unit:'SECONDS') { I......

whhbb
20分钟前
0
0

24分钟前
0
0

RancherLabs
26分钟前
0
0

kisshua

10
0