The following example creates a
GraphicsPath object
path, adds a sequence of two connected Bézier splines to path, closes the current figure (the only figure in this case), and then draws
path.
C++
VOID Example_AddBeziers(HDC hdc)
{
Graphics graphics(hdc);
GraphicsPath path;
PointF pts[] = {PointF(50.0f,50.0f),
PointF(60.0f,20.0f),
PointF(70.0f,100.0f),
PointF(80.0f,50.0f),
PointF(120.0f,40.0f),
PointF(150.0f,80.0f),
PointF(170.0f,30.0f)};
path.AddBeziers(pts, 7);
path.CloseFigure();
// Draw the path.
Pen pen(Color(255, 255, 0, 0));
graphics.DrawPath(&pen, &path);
}
PowerBASIC
SUB GDIP_AddPathBeziers (BYVAL hdc AS DWORD)
LOCAL hStatus AS LONG
LOCAL pGraphics AS DWORD
LOCAL pPath AS DWORD
LOCAL pPen AS DWORD
DIM pts(6) AS POINTF
hStatus = GdipCreateFromHDC(hdc, pGraphics)
hStatus = GdipCreatePath(%FillModeAlternate, pPath)
pts(0).x = 50 : pts(0).y = 50
pts(1).x = 60 : pts(1).y = 20
pts(2).x = 70 : pts(2).y = 100
pts(3).x = 80 : pts(3).y = 50
pts(4).x = 120 : pts(4).y = 40
pts(5).x = 150 : pts(5).y = 80
pts(6).x = 170 : pts(6).y = 30
hStatus = GdipAddPathBeziers(pPath, pts(0), 7)
hStatus = GdipClosePathFigure(pPath)
' // Draw the path.
hStatus = GdipCreatePen1(GDIP_ARGB(255, 255, 0, 0), 1, %UnitWorld, pPen)
hStatus = GdipDrawPath(pGraphics, pPen, pPath)
' // Cleanup
IF pPen THEN GdipDeletePen(pPen)
IF pPath THEN GdipDeletePath(pPath)
IF pGraphics THEN GdipDeleteGraphics(pGraphics)
END SUB
(http://www.jose.it-berater.org/captures/GdipAddPathBeziers.png)