{相關方法}
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();
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;