Skip to content

Instantly share code, notes, and snippets.

@pixtur
Created January 3, 2021 12:23
Show Gist options
  • Save pixtur/529bccbf3bdf1e6026db8fa9235b587e to your computer and use it in GitHub Desktop.
Save pixtur/529bccbf3bdf1e6026db8fa9235b587e to your computer and use it in GitHub Desktop.
How to convert paths from svg into points using svg.net
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