Created
January 3, 2021 12:23
-
-
Save pixtur/529bccbf3bdf1e6026db8fa9235b587e to your computer and use it in GitHub Desktop.
How to convert paths from svg into points using svg.net
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using System.Drawing.Drawing2D; | |
using System.IO; | |
using Svg; | |
using T3.Core.Operator; | |
public class SvgToPoints : Instance<SvgToPoints> | |
{ | |
private static void SampleSvg(string filepath) | |
{ | |
if (!File.Exists(filepath)) | |
return; | |
var svgDoc = SvgDocument.Open<SvgDocument>(filepath, null); | |
var newPath = new GraphicsPath(); | |
SampleNodes(svgDoc.Descendants(), newPath); | |
newPath.Flatten(); | |
for (var index = 0; index < newPath.PathPoints.Length; index++) | |
{ | |
var point = newPath.PathPoints[index]; | |
//Log.Debug($"{point.X} {point.Y}"); | |
} | |
} | |
private static void SampleNodes(IEnumerable<SvgElement> nodes, GraphicsPath path) | |
{ | |
foreach (var node in nodes) | |
{ | |
if (!(node is SvgPath svgPath)) | |
continue; | |
foreach (var s in svgPath.PathData) | |
{ | |
s.AddToPath(path); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment