Export (0) Print
Expand All

GraphicsPathIterator.CopyData Method

Copies the PathPoints property and PathTypes property arrays of the associated GraphicsPath into the two specified arrays.

Namespace:  System.Drawing.Drawing2D
Assembly:  System.Drawing (in System.Drawing.dll)

public int CopyData(
	ref PointF[] points,
	ref byte[] types,
	int startIndex,
	int endIndex
)

Parameters

points
Type: System.Drawing.PointF[]

Upon return, contains an array of PointF structures that represents the points in the path.

types
Type: System.Byte[]

Upon return, contains an array of bytes that represents the types of points in the path.

startIndex
Type: System.Int32

Specifies the starting index of the arrays.

endIndex
Type: System.Int32

Specifies the ending index of the arrays.

Return Value

Type: System.Int32
The number of points copied.

Use the startIndex and endIndex parameters to copy a specified range of the path data.

The following example is designed for use with Windows Forms, and it requires PaintEventArgs e, an OnPaint event object. The code performs the following actions:

  • Creates a graphics path.

  • Populates it with several primitives and some markers.

  • Lists the path data on the left side of the screen.

  • Creates a GraphicsPathIterator and rewinds it.

  • Increments the path data index to the second marker.

  • Calls the CopyData method to copy the path data contained between the start and end indexes to the points and types arrays.

  • Lists this copied data on the right side of the screen.

public void CopyDataExample(PaintEventArgs e)
{

    // Create a graphics path.
    GraphicsPath myPath = new GraphicsPath();

    // Set up a points array.
    Point[] myPoints =
             {
                 new Point(20, 20),
                 new Point(120, 120),
                 new Point(20, 120),
                 new Point(20, 20)
             };

    // Create a rectangle.
    Rectangle myRect = new Rectangle(120, 120, 100, 100);

    // Add the points, rectangle, and an ellipse to the path.
    myPath.AddLines(myPoints);
    myPath.SetMarkers();
    myPath.AddRectangle(myRect);
    myPath.SetMarkers();
    myPath.AddEllipse(220, 220, 100, 100);

    // Get the total number of points for the path, and arrays of 
    // the  points and types. 
    int myPathPointCount = myPath.PointCount;
    PointF[] myPathPoints = myPath.PathPoints;
    byte[] myPathTypes = myPath.PathTypes;

    // Set up variables for listing the array of points on the left 
    // side of the screen. 
    int i;
    float j = 20;
    Font myFont = new Font("Arial", 8);
    SolidBrush myBrush = new SolidBrush(Color.Black);

    // List the set of points and types and types to the left side 
    // of the screen. 
    for(i=0; i<myPathPointCount; i++)
    {
        e.Graphics.DrawString(myPathPoints[i].X.ToString()+
            ", " + myPathPoints[i].Y.ToString() + ", " +
            myPathTypes[i].ToString(),
            myFont,
            myBrush,
            20,
            j);
        j+=20;
    }

    // Create a GraphicsPathIterator for myPath and rewind it.
    GraphicsPathIterator myPathIterator =
        new GraphicsPathIterator(myPath);
    myPathIterator.Rewind();

    // Set up the arrays to receive the copied data.
    PointF[] points = new PointF[myPathIterator.Count];
    byte[] types = new byte[myPathIterator.Count];
    int myStartIndex;
    int myEndIndex;

    // Increment the starting index to the second marker in the 
    // path.
    myPathIterator.NextMarker(out myStartIndex, out myEndIndex);
    myPathIterator.NextMarker(out myStartIndex, out myEndIndex);

    // Copy all the points and types from the starting index to the 
    // ending index to the points array and the types array 
    // respectively. 
    int numPointsCopied = myPathIterator.CopyData(
        ref points,
        ref types,
        myStartIndex,
        myEndIndex);

    // List the copied points to the right side of the screen.
    j = 20;
    int copiedStartIndex = 0;
    for(i=0; i<numPointsCopied; i++)
    {
        copiedStartIndex = myStartIndex + i;
        e.Graphics.DrawString(
            "Point: " + copiedStartIndex.ToString() +
            ", Value: " + points[i].ToString() +
            ", Type: " + types[i].ToString(),
            myFont,
            myBrush,
            200,
            j);
        j+=20;
    }
}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft