tags:

views:

32

answers:

1

Is there anyway to change the coordinates of some of the points within a GraphicsPath object while leaving the other points where they are?

The GraphicsPath object that gets passed into my method will contain a mixture of polygons and lines. My method would want to look something like:

void UpdateGraphicsPath(GraphicsPath gPath, RectangleF regionToBeChanged, PointF delta)
{
    // Find the points in gPath that are inside regionToBeChanged
    // and move them by delta.
    // gPath.PathPoints[i].X += delta.X; // Compiles but doesn't work
}

GraphicsPath.PathPoints seems to be readonly, so does GraphicsPath.PathData.Points. So I am wondering if this is even possible.

Perhaps generating a new GraphicsPath object with an updated set of points? How can I know if a point is part of a line or a polygon?

If anyone has any suggestions then I would be grateful.

A: 

Thanks for your suggestions Hans, here is my implementation of your suggestion to use the GraphicsPath(PointF[], byte[]) constructor:

GraphicsPath UpdateGraphicsPath(GraphicsPath gP, RectangleF rF, PointF delta)
{
    // Find the points in gP that are inside rF and move them by delta.

    PointF[] updatePoints = gP.PathData.Points;
    byte[] updateTypes = gP.PathData.Types;
    for (int i = 0; i < gP.PointCount; i++)
    {
        if (rF.Contains(updatePoints[i]))
        {
            updatePoints[i].X += delta.X;
            updatePoints[i].Y += delta.Y;
        }
    }

    return new GraphicsPath(updatePoints, updateTypes);
}

Seems to be working fine. Thanks for the help.

Ben