是否可以访问图形路径中的点?
Is it possible to access the points in a Graphicspath?
如果在定义了两端位置的图形路径中添加了一条线,是否可以读取这对点?
Point[] myArray =
{
new Point(30,30),
new Point(60,60),
};
GraphicsPath myPath2 = new GraphicsPath();
myPath2.AddLines(myArray2);
from myPath2,有没有类似myPath2.Location
的东西可以给我点数(30,30)和(60,60)?
谢谢
是的,可以通过 GraphicsPath.PathPoints
but you will need to understand the 2nd array of GraphicsPath.PathTypes
!
只有当所有点都添加为线坐标的简单点数组时,可能像这样:
List<Point> points = new List<Point>();
.. // add some points!
GraphicsPath gp = new GraphicsPath();
gp.AddLines(points.ToArray());
你能use/modify 轻松获得分数吗?
如果您通过 圆形 形状添加它们,例如..
gp.AddEllipse(ClientRectangle);
..你需要了解各种类型!将它们添加为其他曲线时也是如此 gp.AddCurves(points.ToArray());
如果将它们添加为 gp.AddRectangle(ClientRectangle);
,您将获得常规积分,但字节类型为
0 - Indicates that the point is the start of a figure.
所以在你的情况下,你得到的第一点是这样的:
Console.WriteLine(gp.PathPoints[1].ToString());
顺便说一句:没有 GraphicsPath.Location
这样的东西;但您可能会发现 GraphicsPath.GetBounds()
有用..
请注意,所有圆形(包括圆弧和椭圆!)实际上仅由贝塞尔点组成:
3 - Indicates that the point is an endpoint or control point of a
cubic Bézier spline
这意味着 PathPoints
是 交替的 端点和控制点。
有时候,Matrix 没有绘制正确的点,所以...,在少量路径中,这很有帮助,在这个例子中你可以:阅读,修改和比较,点和点类型,重写你的路径或创建一个新的..等..
PointF[] changedPoints = Refpath.PathData.Points;
byte[] pointTypes = Refpath.PathData.Types;
List<PointF> OriginalPoints = new List<PointF>();
PointF currentPoint = new Point();
int MyCoffe = 0;
Refpath.PathPoints
.ToList()
.ForEach(
i =>
{
currentPoint = new PointF
{
X = i.X,
Y = i.Y
};
OriginalPoints.Add(currentPoint);
if (pointTypes[MyCoffe]==3)
{
// it's a curve, see the "TaW" explantion, do something, like add text caption, etc...
changedPoints[MyCoffe].X -= 100;
changedPoints[MyCoffe].Y -= 100;
// etc...
}
changedPoints[MyCoffe].X += 100; // if you want to change value
changedPoints[MyCoffe].Y += 100;
MyCoffe ++;
}
);
GraphicsPath newPath = new GraphicsPath(changedPoints, pointTypes);
如果在定义了两端位置的图形路径中添加了一条线,是否可以读取这对点?
Point[] myArray =
{
new Point(30,30),
new Point(60,60),
};
GraphicsPath myPath2 = new GraphicsPath();
myPath2.AddLines(myArray2);
from myPath2,有没有类似myPath2.Location
的东西可以给我点数(30,30)和(60,60)?
谢谢
是的,可以通过 GraphicsPath.PathPoints
but you will need to understand the 2nd array of GraphicsPath.PathTypes
!
只有当所有点都添加为线坐标的简单点数组时,可能像这样:
List<Point> points = new List<Point>();
.. // add some points!
GraphicsPath gp = new GraphicsPath();
gp.AddLines(points.ToArray());
你能use/modify 轻松获得分数吗?
如果您通过 圆形 形状添加它们,例如..
gp.AddEllipse(ClientRectangle);
..你需要了解各种类型!将它们添加为其他曲线时也是如此 gp.AddCurves(points.ToArray());
如果将它们添加为 gp.AddRectangle(ClientRectangle);
,您将获得常规积分,但字节类型为
0 - Indicates that the point is the start of a figure.
所以在你的情况下,你得到的第一点是这样的:
Console.WriteLine(gp.PathPoints[1].ToString());
顺便说一句:没有 GraphicsPath.Location
这样的东西;但您可能会发现 GraphicsPath.GetBounds()
有用..
请注意,所有圆形(包括圆弧和椭圆!)实际上仅由贝塞尔点组成:
3 - Indicates that the point is an endpoint or control point of a cubic Bézier spline
这意味着 PathPoints
是 交替的 端点和控制点。
有时候,Matrix 没有绘制正确的点,所以...,在少量路径中,这很有帮助,在这个例子中你可以:阅读,修改和比较,点和点类型,重写你的路径或创建一个新的..等..
PointF[] changedPoints = Refpath.PathData.Points;
byte[] pointTypes = Refpath.PathData.Types;
List<PointF> OriginalPoints = new List<PointF>();
PointF currentPoint = new Point();
int MyCoffe = 0;
Refpath.PathPoints
.ToList()
.ForEach(
i =>
{
currentPoint = new PointF
{
X = i.X,
Y = i.Y
};
OriginalPoints.Add(currentPoint);
if (pointTypes[MyCoffe]==3)
{
// it's a curve, see the "TaW" explantion, do something, like add text caption, etc...
changedPoints[MyCoffe].X -= 100;
changedPoints[MyCoffe].Y -= 100;
// etc...
}
changedPoints[MyCoffe].X += 100; // if you want to change value
changedPoints[MyCoffe].Y += 100;
MyCoffe ++;
}
);
GraphicsPath newPath = new GraphicsPath(changedPoints, pointTypes);