void ConvertToPathXaml(FileEntity file) { SVG svg = SVGReader.Read(file.FilePath); Drawing drawing = svg.GetDrawing(); DrawingGroup group = drawing as DrawingGroup; Action <DrawingGroup> drawingAction = null; this.tx_code.Text = null; drawingAction = l => { foreach (var item in l.Children) { if (item is GeometryDrawing) { GeometryDrawing gd = item as GeometryDrawing; string line = $"<Path Stroke=\"{gd.Pen?.Brush}\" Fill=\"{gd.Brush}\" Data=\"{gd.Geometry.ToString()}\"/>"; this.tx_code.Text += line.Replace($"Stroke =\"\"", "").Replace($"Fill =\"\"", "") + Environment.NewLine; } else if (item is DrawingGroup) { drawingAction(item as DrawingGroup); } } }; drawingAction(group); }
void ConvertToPathDrawing(FileEntity file) { SVG svg = SVGReader.Read(file.FilePath); Drawing drawing = svg.GetDrawing(); DrawingGroup group = drawing as DrawingGroup; Action <DrawingGroup> drawingAction = null; this.tx_code.Text = null; this.cv_pathdraw.Children.Clear(); this.cv_pathdraw.Width = svg.Width; this.cv_pathdraw.Height = svg.Height; drawingAction = l => { foreach (var item in l.Children) { if (item is GeometryDrawing) { GeometryDrawing gd = item as GeometryDrawing; System.Windows.Shapes.Path p = new System.Windows.Shapes.Path(); p.Data = gd.Geometry; p.Fill = gd.Brush; p.Stroke = gd.Pen?.Brush; this.tx_code.Text += gd.Geometry.ToString() + Environment.NewLine; this.cv_pathdraw.Children.Add(p); } else if (item is DrawingGroup) { drawingAction(item as DrawingGroup); } } }; drawingAction(group); }
void ConvertToImage(FileEntity file) { SVG svg = SVGReader.Read(file.FilePath); this.image_svg.Source = new DrawingImage(svg.GetDrawing()); }