• Welcome to Jose's Read Only Forum 2023.
 

GDI+: GdipPathIterEnumerate

Started by José Roca, June 22, 2008, 04:25:20 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca



The following example creates a GraphicsPath object and adds three lines to the path. The code creates a GraphicsPathIterator object and calls the GdipPathIterEnumerate function to retrieve the path's data points and point types. Then the code displays the count returned by the GdipPathIterEnumerate function.

C++


#define BUFFER_SIZE 30
TCHAR numPointsEnum[BUFFER_SIZE];

// Add some lines to a path.
Point pts[] = {Point(20, 20),
                Point(100, 20),
                Point(100, 50),
                Point(20, 50)};
GraphicsPath path;
path.AddLines(pts, 4);

// Create a GraphicsPathIterator object, and associate it with the path.
GraphicsPathIterator pathIterator(&path);

// Create destination arrays, and copy the path data to them.
UINT c = pathIterator.GetCount();
PointF* pEnumPoints = new PointF[c];
BYTE* pTypes = new BYTE[c];
INT count = pathIterator.Enumerate(pEnumPoints, pTypes, c);

// Confirm that the points were enumerated.
StringCchPrintf(
   numPointsEnum, BUFFER_SIZE, TEXT("%d points were enumerated."), count);

MessageBox(hWnd, numPointsEnum, TEXT("Enumerate"), NULL);

delete[] pEnumPoints;
delete[] pTypes;


PowerBASIC


SUB GDIP_GdipPathIterEnumerate (BYVAL hdc AS DWORD)

   LOCAL hStatus AS LONG
   LOCAL pGraphics AS DWORD
   LOCAL pPath AS DWORD
   LOCAL pIterator AS DWORD
   LOCAL c AS LONG
   LOCAL count AS LONG
   DIM   pts(3) AS POINTF
   DIM   pPoints(0) AS POINTF
   DIM   pTypes(0) AS BYTE

   hStatus = GdipCreateFromHDC(hdc, pGraphics)

   ' // Create a path.
   hStatus = GdipCreatePath(%FillModeAlternate, pPath)

   ' // Add some lines to a path.
   pts(0).x = 20  : pts(0).y = 20
   pts(1).x = 100 : pts(1).y = 20
   pts(2).x = 100 : pts(2).y = 50
   pts(3).x = 20  : pts(3).y = 50

   hStatus = GdipAddPathLine2(pPath, pts(0), 4)

   ' // Create a GraphicsPathIterator object, and associate it with the path.
   hStatus = GdipCreatePathIter(pIterator, pPath)

   ' // Create destination arrays, and copy the path data to them.
   hStatus = GdipPathIterGetCount(pIterator, c)
   IF c THEN
      REDIM pPoints(c - 1)
      REDIM pTypes(c - 1)
      hStatus = GdipPathIterEnumerate(pIterator, count, pPoints(0), pTypes(0), c)
      ' // Confirm that the points were enumerated.
      MSGBOX "count =" & STR$(count)
   END IF

   ' // Cleanup
   IF pIterator THEN GdipDeletePathIter(pIterator)
   IF pPath THEN GdipDeletePath(pPath)
   IF pGraphics THEN GdipDeleteGraphics(pGraphics)

END SUB