Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
531 views
in Technique[技术] by (71.8m points)

c# - How do I pull out the ”data" from a SVG, alter it, then put it back with correct format?

Thank you for helping me! I would like to change the whole data of a path (SVG) using code, so that I can move the position of the path to a specific direction. For example, steve helps me with the following code to add 1 to x in all (x,y) pair to move the path (SVG) to theright direction : Steve's code (but the first x (311) doesn't change. There is some bug)

var data = @"M311.97458,250.39993L213.97533,248.39996 222.37435,216.7998C222.37435,216.7998 ......589.5753,173.99994,593.1753,179.9999......334.3039,253.21373 311.97458,250.39993 z"; '           
var replaced = Regex.Replace(data, "((?=[^, ])\d+\.\d+),", (match) => (double.Parse(match.Groups[1].Value) + 1).ToString()+",")
// output: M311.97458,251.39993L214.97533,249.39996 223.37435,217.7998C223.37435,217.7998 ......590.5753,174.99994,594.1753,180.9999......335.3039,254.21373 312.97458,251.39993 z

After I get the output, I tried to put it into data. I wrote a.SetValue(Path.DataProperty,replace) and a.SetValue(Path.DataProperty,Geometry.Parse(replace)), but they both don't work. The result shows that

Unprocessed error: System.FormatException: the format of input string is not correct.

How can I alter the output into a correct format for the data of a path(SVG) ? Or should I change my previous code?

Thank you!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Paths in WPF use simple geometry. Here everything about the syntax of that is explained. If you read and understand that article it will be much easy to go through your own Path and fix it the way you want.

Main commands:

Move command M startPoint - or - m startPoint

Line command L endPoint - or - l endPoint

Horizontal line command H x - or - h x

Vertical line command V y - or - v y

Cubic bezier curve command C controlPoint1 controlPoint2 endPoint - or - c controlPoint1 controlPoint2 endPoint

Quadratic Bezier Curve Command Q controlPoint endPoint - or - q controlPoint endPoint

Elliptical Arc Command A size rotationAngle isLargeArcFlag sweepDirectionFlag endPoint - or - a size rotationAngle isLargeArcFlag sweepDirectionFlag endPoint


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...