• Welcome to Jose's Read Only Forum 2023.
 

GDI+: GdipDrawClosedCurve

Started by José Roca, June 23, 2008, 07:06:37 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca



The following example draws a closed cardinal spline.

C++


VOID Example_DrawClosedCurve3(HDC hdc)
{
   Graphics graphics(hdc);

   // Define a Pen object and an array of PointF objects.
   Pen greenPen(Color(255, 0, 0, 255), 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 point5(600.0f, 200.0f);
   PointF point6(700.0f, 400.0f);
   PointF point7(500.0f, 500.0f);

   PointF curvePoints[7] = {
      point1,
      point2,
      point3,
      point4,
      point5,
      point6,
      point7};

   // Draw the closed curve.
   graphics.DrawClosedCurve(&greenPen, curvePoints, 7);

   // Draw the points in the curve.
   SolidBrush redBrush(Color(255, 255, 0, 0));
   graphics.FillEllipse(&redBrush, Rect(95, 95, 10, 10));
   graphics.FillEllipse(&redBrush, Rect(495, 95, 10, 10));
   graphics.FillEllipse(&redBrush, Rect(495, 495, 10, 10));
   graphics.FillEllipse(&redBrush, Rect(195, 45, 10, 10));
   graphics.FillEllipse(&redBrush, Rect(395, 5, 10, 10));
   graphics.FillEllipse(&redBrush, Rect(595, 195, 10, 10));
   graphics.FillEllipse(&redBrush, Rect(695, 395, 10, 10));
}


PowerBASIC


SUB GDIP_DrawClosedCurve (BYVAL hdc AS DWORD)

   LOCAL hStatus AS LONG
   LOCAL pGraphics AS DWORD
   LOCAL pGreenPen AS DWORD
   LOCAL pRedBrush AS DWORD
   LOCAL point1 AS POINTF
   LOCAL point2 AS POINTF
   LOCAL point3 AS POINTF
   LOCAL point4 AS POINTF
   LOCAL point5 AS POINTF
   LOCAL point6 AS POINTF
   LOCAL point7 AS POINTF
   DIM   curvePoints(6) 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
   point5.x = 600.0 : point5.y = 200.0
   point6.x = 700.0 : point6.y = 400.0
   point7.x = 500.0 : point7.y = 500.0

   curvePoints(0) = point1
   curvePoints(1) = point2
   curvePoints(2) = point3
   curvePoints(3) = point4
   curvePoints(4) = point5
   curvePoints(5) = point6
   curvePoints(6) = point7

   ' // Draw the closed curve
   hStatus = GdipDrawClosedCurve(pGraphics, pGreenPen, curvePoints(0), 7)

  ' // 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, 495, 95, 10, 10)
   hStatus = GdipFillEllipse(pGraphics, pRedBrush, 495, 495, 10, 10)
   hStatus = GdipFillEllipse(pGraphics, pRedBrush, 195, 45, 10, 10)
   hStatus = GdipFillEllipse(pGraphics, pRedBrush, 395, 5, 10, 10)
   hStatus = GdipFillEllipse(pGraphics, pRedBrush, 595, 195, 10, 10)
   hStatus = GdipFillEllipse(pGraphics, pRedBrush, 695, 395, 10, 10)

   ' // Cleanup
   IF pRedBrush THEN GdipDeleteBrush(pRedBrush)
   IF pGreenPen THEN GdipDeletePen(pGreenPen)
   IF pGraphics THEN GdipDeleteGraphics(pGraphics)

END SUB