Hi,
You could use the following method to find the shape points coordinates. You might also add some arguments to customize the result, e.g. to include additional points such as the middle points of line segments.
List<PointF> shapePoints = GetShapePoints(Shapes.Tape);
foreach (PointF p in shapePoints)
Debug.WriteLine(p.ToString());
List<PointF> GetShapePoints(Shape shape)
{
List<PointF> points = new List<PointF>();
foreach (ElementTemplate element in shape.Outline)
{
LineTemplate line = element as LineTemplate;
if (line != null)
{
AddPoint(points, line.Coordinates[0], line.Coordinates[1]);
AddPoint(points, line.Coordinates[2], line.Coordinates[3]);
}
BezierTemplate bezier = element as BezierTemplate;
if (bezier != null)
{
AddPoint(points, bezier.Coordinates[0], bezier.Coordinates[1]);
AddPoint(points, bezier.Coordinates[6], bezier.Coordinates[7]);
}
ArcTemplate arc = element as ArcTemplate;
if (arc != null)
{
if (arc.SweepAngle == 360)
{
AddRect(points, arc.Bounds);
}
else
{
GraphicsPath path = new GraphicsPath();
path.AddArc(arc.Bounds, arc.StartAngle, arc.SweepAngle);
AddPoint(points, path.PathPoints[0]);
AddPoint(points, path.PathPoints[path.PathPoints.Length - 1]);
path.Dispose();
}
}
RoundRectangleTemplate roundRect = element as RoundRectangleTemplate;
if (roundRect != null)
{
AddRect(points, roundRect.Bounds);
}
}
if (points[0] == points[points.Count - 1])
points.RemoveAt(points.Count - 1);
return points;
}
void AddRect(List<PointF> points, RectangleF r)
{
AddPoint(points, r.X + r.Width / 2, r.Top);
AddPoint(points, r.Right, r.Y + r.Height / 2);
AddPoint(points, r.X + r.Width / 2, r.Bottom);
AddPoint(points, r.Left, r.Y + r.Height / 2);
}
void AddPoint(List<PointF> points, float x, float y)
{
AddPoint(points, new PointF(x, y));
}
void AddPoint(List<PointF> points, PointF point)
{
if (points.Count == 0 || points[points.Count - 1] != point)
points.Add(point);
}
I hope that helps,
Stoyan