The following example defines a polygon and fills it.
C++
VOID Example_DrawCurve5(HDC hdc)
{
Graphics graphics(hdc);
// Define a Pen object and an array of PointF objects.
Pen greenPen(Color::Green, 3);
PointF point1(100.0f, 100.0f);
PointF point2(200.0f, 50.0f);
PointF point3(400.0f, 10.0f);
PointF point4(500.0f, 100.0f);
PointF curvePoints[4] = {
point1,
point2,
point3,
point4};
PointF* pcurvePoints = curvePoints;
// Specify offset, number of segments to draw, and tension.
int offset = 1;
int segments = 2;
REAL tension = 1.0f;
// Draw the curve.
graphics.DrawCurve(&greenPen, curvePoints, 4, offset, segments, tension);
//Draw the points in the curve.
SolidBrush redBrush(Color::Red);
graphics.FillEllipse(&redBrush, Rect(95, 95, 10, 10));
graphics.FillEllipse(&redBrush, Rect(195, 45, 10, 10));
graphics.FillEllipse(&redBrush, Rect(395, 5, 10, 10));
graphics.FillEllipse(&redBrush, Rect(495, 95, 10, 10));
}
PowerBASIC
SUB GDIP_DrawCurve (BYVAL hdc AS DWORD)
LOCAL hStatus AS LONG
LOCAL pGraphics AS DWORD
LOCAL pGreenPen AS DWORD
LOCAL pRedBrush AS DWORD
LOCAL offset AS LONG
LOCAL segments AS LONG
LOCAL tension AS SINGLE
LOCAL point1 AS POINTF
LOCAL point2 AS POINTF
LOCAL point3 AS POINTF
LOCAL point4 AS POINTF
DIM curvePoints(3) AS POINTF
hStatus = GdipCreateFromHDC(hdc, pGraphics)
' // Create a green Pen
hStatus = GdipCreatePen1(GDIP_ARGB(255, 0, 255, 0), 1.0!, %UnitWorld, pGreenPen)
point1.x = 100.0 : point1.y = 100.0
point2.x = 200.0 : point2.y = 50.0
point3.x = 400.0 : point3.y = 10.0
point4.x = 500.0 : point4.y = 100.0
curvePoints(0) = point1
curvePoints(1) = point2
curvePoints(2) = point3
curvePoints(3) = point4
' // Specify offset, number of segments to draw, and tension.
offset = 1
segments = 2
tension = 1.0!
' // Draw the curve
hStatus = GdipDrawCurve3(pGraphics, pGreenPen, curvePoints(0), 4, offset, segments, tension)
' // Create the brush
hStatus = GdipCreateSolidFill(GDIP_ARGB(255, 255, 0, 0), pRedBrush)
' //Draw the points in the curve
hStatus = GdipFillEllipse(pGraphics, pRedBrush, 95, 95, 10, 10)
hStatus = GdipFillEllipse(pGraphics, pRedBrush, 195, 45, 10, 10)
hStatus = GdipFillEllipse(pGraphics, pRedBrush, 395, 5, 10, 10)
hStatus = GdipFillEllipse(pGraphics, pRedBrush, 495, 95, 10, 10)
' // Cleanup
IF pRedBrush THEN GdipDeleteBrush(pRedBrush)
IF pGreenPen THEN GdipDeletePen(pGreenPen)
IF pGraphics THEN GdipDeleteGraphics(pGraphics)
END SUB
(http://www.jose.it-berater.org/captures/GdipDrawCurve.png)
The following example draws an antialised cardinal spline.
SUB GDIP_DrawCurve (BYVAL hdc AS DWORD)
LOCAL hStatus AS LONG
LOCAL pGraphics AS DWORD
LOCAL pPen AS DWORD
DIM curvePoints(4) AS POINTL
hStatus = GdipCreateFromHDC(hdc, pGraphics)
' // Array of Point structures
curvePoints(0).x = 0 : curvePoints(0).y = 100
curvePoints(1).x = 50 : curvePoints(1).y = 80
curvePoints(2).x = 100 : curvePoints(2).y = 20
curvePoints(3).x = 150 : curvePoints(3).y = 80
curvePoints(4).x = 200 : curvePoints(4).y = 100
' // Create a Pen
hStatus = GdipCreatePen1(GDIP_ARGB(255, 0, 0, 255), 4, %UnitPixel, pPen)
' Gamma correction is nice, though slower...
hStatus = GdipSetCompositingQuality(pGraphics, %CompositingQualityGammaCorrected)
' Draw the curve with anti-aliasing
hStatus = GdipSetSmoothingMode(pGraphics, %SmoothingModeAntiAlias)
hStatus = GdipDrawCurveI(pGraphics, pPen, curvePoints(0), 5)
' // Cleanup
IF pPen THEN GdipDeletePen(pPen)
IF pGraphics THEN GdipDeleteGraphics(pGraphics)
END SUB
(http://www.jose.it-berater.org/captures/GdipDrawCurveAntialised.png)