【问题标题】:How to change the coordinate of a point that is inside a GraphicsPath?如何更改 GraphicsPath 内的点的坐标?
【发布时间】:2010-05-15 16:52:32
【问题描述】:

是否有办法改变 GraphicsPath 对象中某些点的坐标,而将其他点留在原处?

传入我的方法的 GraphicsPath 对象将包含多边形和线条的混合。我的方法看起来像:

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 似乎是只读的,GraphicsPath.PathData.Points 也是如此。所以我想知道这是否可能。

也许用一组更新的点生成一个新的 GraphicsPath 对象?如何知道一个点是直线还是多边形的一部分?

如果有人有任何建议,我将不胜感激。

【问题讨论】:

    标签: c# graphics


    【解决方案1】:

    感谢您的建议 Hans,这是我使用 GraphicsPath(PointF[], byte[]) 构造函数的建议的实现:

    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);
    }
    

    似乎工作正常。感谢您的帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-09
      • 2013-10-17
      • 2015-05-09
      • 1970-01-01
      • 2017-07-22
      • 1970-01-01
      • 2020-03-06
      • 2021-04-30
      相关资源
      最近更新 更多