Пример #1
0
        public string GetAllToTogether(string[] paths)
        {
            PathGeometry result = new PathGeometry();
            foreach (var item in paths)
            {
                result.AddGeometry (  PathGeometry.Parse(item));

            }

            return result.ToString();
        }
        private void CreateAutoShape(object sender, RoutedEventArgs e)
        {
            PathGeometry sendingPath = new PathGeometry(); 
            PathFigure pathFigure = new PathFigure();
            pathFigure.StartPoint = new Point(47.7778, 48.6667);
            pathFigure.IsClosed = true;
            LineSegment lineSegment1 = new LineSegment();
            lineSegment1.Point = new Point(198, 48.6667);
            pathFigure.Segments.Add(lineSegment1);
            LineSegment lineSegment2 = new LineSegment();
            lineSegment2.Point = new Point(198, 102);
            pathFigure.Segments.Add(lineSegment2);
            BezierSegment bezierSegment1 = new BezierSegment();
            bezierSegment1.Point1 = new Point(174.889, 91.3334);
            bezierSegment1.Point2 = new Point(157.111, 79.7778);
            bezierSegment1.Point3 = new Point(110.889, 114.444);
            pathFigure.Segments.Add(bezierSegment1);
            BezierSegment bezierSegment2 = new BezierSegment();
            bezierSegment2.Point1 = new Point(64.667, 149.111);
            bezierSegment2.Point2 = new Point(58.4444, 130.444);
            bezierSegment2.Point3 = new Point(47.7778, 118.889);
            pathFigure.Segments.Add(bezierSegment2);
            sendingPath.Figures.Add(pathFigure);

            PathGeometry pathGeometry = new PathGeometry();
            if (sendingPath.FillRule != null)
                pathGeometry.FillRule = sendingPath.FillRule;
            else pathGeometry.FillRule = FillRule.Nonzero;
            pathGeometry.Figures = sendingPath.Figures;

            var newThumb = new SandRibbonInterop.AutoShape();
            var safePathGeometry = (Geometry)(new GeometryConverter().ConvertFromString(pathGeometry.ToString()));
            var safePathData = new PathGeometry();
            safePathData.AddGeometry(safePathGeometry);
            newThumb.PathData = safePathData;
            newThumb.Background = Brushes.LightGreen;
            newThumb.Foreground = Brushes.Green;
            newThumb.StrokeThickness = 5;
            newThumb.Height = 100;
            newThumb.Width = 100;
            
            Commands.AddAutoShape.Execute(newThumb);
        }
Пример #3
0
		/// <summary>
		///     Преобразует набор точек в путь
		/// </summary>
		/// <param name="points">Коллекция точек</param>
		/// <param name="pathKind">Тип пути - Линия(замкнутая/открытая), либо Эллипс</param>
		/// <returns></returns>
		public static string PointsToPath(PointCollection points, PathKind pathKind) {
			var enumerable = points.ToArray();
			if (!enumerable.Any()) {
				return string.Empty;
			}

			switch (pathKind) {
				case PathKind.Ellipse: {
						var radiusX = (enumerable[1].X - enumerable[0].X) / 2;
						var radiusY = (enumerable[2].Y - enumerable[1].Y) / 2;
						var center = new Point(enumerable[1].X - radiusX, enumerable[2].Y - radiusY);
						var geometry = new EllipseGeometry(center: center, radiusX: radiusX, radiusY: radiusY);
						return geometry.GetFlattenedPathGeometry().ToString(CultureInfo.InvariantCulture);
					}
				default: {
						var start = enumerable[0];
						var segments = new List<LineSegment>();
						for (var i = 1; i < enumerable.Length; i++) {
							segments.Add(new LineSegment(new Point(enumerable[i].X, enumerable[i].Y), true));
						}
						var figure = new PathFigure(start, segments, (pathKind == PathKind.ClosedLine));
						var geometry = new PathGeometry();
						geometry.Figures.Add(figure);
						return geometry.ToString(CultureInfo.InvariantCulture);
					}
			}
		}