是否有更改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似乎只是readonly,GraphicsPath.PathData.Points也是如此。所以我想知道这是否可能。
也许使用更新的点集生成一个新的GraphicsPath对象?如何知道某个点是线条还是多边形的一部分?
如果有人有任何建议,那么我将不胜感激。
答案 0 :(得分: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);
}
似乎工作正常。谢谢你的帮助。