Reputation: 144
If there is a line added to a Graphicspath with two ends location defined, is it possible to read this pair of points?
Point[] myArray =
{
new Point(30,30),
new Point(60,60),
};
GraphicsPath myPath2 = new GraphicsPath();
myPath2.AddLines(myArray2);
from myPath2, is there something similar to myPath2.Location
that can give me the points (30,30) and (60,60)?
Thanks
Upvotes: 3
Views: 2239
Reputation: 11
Somethimes, Matrix don't plot correct my points, so..., in small number of paths, this is helpfull, in this example you can: read, modify and compare, points and point types, rewrite your path or create a new.. etc ..
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);
Upvotes: 0
Reputation: 54453
Yes it is possible via GraphicsPath.PathPoints
but you will need to understand the 2nd array of GraphicsPath.PathTypes
!
Only if all the points are added as a simple point array of line coordinates, maybe like this:
List<Point> points = new List<Point>();
.. // add some points!
GraphicsPath gp = new GraphicsPath();
gp.AddLines(points.ToArray());
will you be able to use/modify the points without much hassle.
If you add them via rounded shapes, like..
gp.AddEllipse(ClientRectangle);
..you will need to understand the various types! The same is true when you add them as other curves gp.AddCurves(points.ToArray());
If you add them as gp.AddRectangle(ClientRectangle);
you will get the regular points but with a byte type that says
0 - Indicates that the point is the start of a figure.
So in your case you get at the 1st of your points like this:
Console.WriteLine(gp.PathPoints[1].ToString());
Btw: There is no such thing as a GraphicsPath.Location
; but you may find GraphicsPath.GetBounds()
useful..
Note that all rounded shapes (including arcs and ellipses!) in fact consist only of bezier points:
3 - Indicates that the point is an endpoint or control point of a cubic Bézier spline
which means that the PathPoints
are alternating endpoints and control points.
Upvotes: 5