The following example creates a
GraphicsPath object and then adds a rectangle and an ellipse to the path. The code passes the address of that
GraphicsPath object to the
GdipCreatePathIter function to create an iterator that is associated with the path. The code calls the
GdipPathIterGetCount function to determine the number of data points in the path. The call to
GdipPathIterEnumerate retrieves two arrays from the path: one that holds the path's data points and one that holds the path's point types. After the data points have been retrieved, the code calls the
GdipFillEllipse function to draw each of the data points.
C++
VOID GetCountExample(HDC hdc)
{
Graphics graphics(hdc);
// Create a path that has a rectangle and an ellipse.
GraphicsPath path;
path.AddRectangle(Rect(20, 20, 60, 30));
path.AddEllipse(Rect(20, 70, 100, 50));
// Create an iterator, and associate it with the path.
GraphicsPathIterator iterator(&path);
// Get the number of data points in the path.
INT count = iterator.GetCount();
// Get the data points.
PointF* points = new PointF[count];
BYTE* types = new BYTE[count];
iterator.Enumerate(points, types, count);
// Draw the data points.
SolidBrush brush(Color(255, 255, 0, 0));
for(INT j = 0; j < count; ++j)
graphics.FillEllipse(
&brush,
points[j].X - 3.0f,
points[j].Y - 3.0f,
6.0f,
6.0f);
delete points;
delete types;
}
PowerBASIC
SUB GDIP_PathIterGetCount (BYVAL hdc AS DWORD)
LOCAL hStatus AS LONG
LOCAL pGraphics AS DWORD
LOCAL pPath AS DWORD
LOCAL pBrush AS DWORD
LOCAL pIterator AS DWORD
LOCAL c AS LONG
LOCAL count AS LONG
LOCAL i AS LONG
DIM pts(3) AS POINTF
DIM pPoints(0) AS POINTF
DIM pTypes(0) 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)
hStatus = GdipAddPathEllipse(pPath, 20, 70, 100, 50)
' // Create a GraphicsPathIterator object, and associate it with the path.
hStatus = GdipCreatePathIter(pIterator, pPath)
' // Get the number of data points in the path.
hStatus = GdipPathIterGetCount(pIterator, c)
' // Get the data points.
IF c THEN
REDIM pPoints (c - 1)
REDIM pTypes(c - 1)
hStatus = GdipPathIterEnumerate(pIterator, count, pPoints(0), pTypes(0), c)
IF count THEN
' // Draw the data points.
hStatus = GdipCreateSolidFill(GDIP_ARGB(255, 255, 0, 0), pBrush)
FOR i = 0 TO count - 1
hStatus = GdipFillEllipse(pGraphics, pBrush, pPoints(i).x - 3, pPoints(i).y - 3, 6, 6)
NEXT
END IF
END IF
' // Cleanup
IF pIterator THEN GdipDeletePathIter(pIterator)
IF pBrush THEN GdipDeleteBrush(pBrush)
IF pPath THEN GdipDeletePath(pPath)
IF pGraphics THEN GdipDeleteGraphics(pGraphics)
END SUB
(http://www.jose.it-berater.org/captures/GdipPathIterGetCount.png)