The original direct2d only provides the drawing and filling of several simple images (straight lines, rectangles, rounded corners, rectangles). For more set images or paths, use drawgeometry () and fillgeometry ().
Now that you can draw more complex images, you can also draw basic images. First, use drawgeometry () and fillgeometry () to create a rectangle, a rounded rectangle, and an ellipse.
The id2d1geometry interface, id2d1rectanglegeometry, id2d1roundedrectanglegeometry, and id2d1ellipsegeometry are all its sub-interfaces.
Id2d1factory provides methods to implement these three interfaces. You can obtain the id2d1factory interface from d2dfactory.
TestCode:
Uses direct2d, d2d1; procedure invoke (Sender: tobject); var CVS: tdirect2dcanvas; FPT: td2dpoint2f; fleft, ftop: single; iellipse: inline; irectangle: inline; iroundedrectangle; ifacloud: id2d1factory; begin FPT: = d2d1pointf (clientwidth/2, clientheight/2); fleft: = clientwidth/4; ftop: = clientheight/4; ifacloud: = d2dfactory (); ifacloud. createrectanglegeometry (d2d1rectf (fleft, ftop, fleft * 3, ftop * 3), irectangle); ifacloud. createroundedrectanglegeometry (d2d1roundedrect (d2d1rectf (fleft, ftop, fleft * 3, ftop * 3), 32, 32), iroundedrectangle); ifacloud. createellipsegeometry (d2d1ellipse (FPT, fleft, ftop), iellipse); CVS: = tdirect2dcanvas. create (canvas, clientrect); CVs. begindraw; CVs. pen. color: = clred; CVs. brush. color: = clblack; CVs. fillgeometry (irectangle); CVs. brush. color: = clgreen; CVs. fillgeometry (iroundedrectangle); CVs. brush. color: = clblue; CVs. fillgeometry (iellipse); CVs. drawgeometry (irectangle); CVs. drawgeometry (iroundedrectangle); CVs. drawgeometry (iellipse); CVs. enddraw; CVs. free; end; Procedure tform1.formresize (Sender: tobject); begin repaint; end;