• Welcome to Jose's Read Only Forum 2023.
 

GDI+: GdipPathIterCopyData

Started by José Roca, June 22, 2008, 04:32:59 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 graphics patyh iterator and calls the GdipPathIterCopyData function to retrieve the path's points and point types. Then the code displays the count returned by the GdipPathIterCopyData function.

C++


#define BUFFER_SIZE 30
TCHAR numPointsCopied[BUFFER_SIZE];

// Create the points for three lines in a path.
Point pts[] = { Point(20, 20),
                Point(100, 20),
                Point(100, 50),
                Point(20, 50) };
GraphicsPath path;
path.AddLines(pts, 4); // Add the lines to the path.

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

// Create destination arrays, and copy the path data to them.
PointF* pCopiedPoints = new PointF[4];
BYTE* pTypes = new BYTE[4];
INT count = pathIterator.CopyData(pCopiedPoints, pTypes, 0, 3);

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

MessageBox(hWnd, numPointsCopied, TEXT("CopyData"), NULL);

delete[] pCopiedPoints;
delete[] pTypes;


PowerBASIC


SUB GDIP_PathIterCopyData (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(3) AS POINTF
   DIM   pTypes(3) AS BYTE

   hStatus = GdipCreateFromHDC(hdc, pGraphics)

   ' // Create a path that has a rectangle and an ellipse.
   hStatus = GdipCreatePath(%FillModeAlternate, pPath)

   hStatus = GdipAddPathRectangle(pPath, 20, 20, 60, 30)

   ' // 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)
   OutputDebugString("pIterator =" & STR$(pIterator))

   ' // Copy the path data to the destination arrays.
   hStatus = GdipPathIterCopyData(pIterator, count, pPoints(0), pTypes(0), 0, 3)
   OutPutDebugString("hStatus =" & STR$(hStatus))
   
   ' // Confirm that the points copied.
   OutPutDebugString("count =" & STR$(count))

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

END SUB