如果在定义了两端位置的图形路径中添加了一条线,是否可以读取这对点?
Point[] myArray =
{
new Point(30,30),
new Point(60,60),
};
GraphicsPath myPath2 = new GraphicsPath();
myPath2.AddLines(myArray2);
从 myPath2 中,是否有类似于 myPath2.Location
的东西可以给我点 (30,30) 和 (60,60)?
谢谢
最佳答案
是的,可以通过 GraphicsPath.PathPoints
但您需要了解 GraphicsPath.PathTypes
的第二个数组!
只有当所有点都添加为线坐标的简单点数组时,可能像这样:
List<Point> points = new List<Point>();
.. // add some points!
GraphicsPath gp = new GraphicsPath();
gp.AddLines(points.ToArray());
您能否轻松使用/修改积分。
如果您通过圆形 形状添加它们,例如..
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
是交替端点和控制点。
关于c# - 是否可以访问图形路径中的点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38816141/