我如何拉出“数据"?从一个SVG,改变它,然后把它放回正确的格式? [英] How do I pull out the ”data" from a SVG, alter it, then put it back with correct format?

查看:30
本文介绍了我如何拉出“数据"?从一个SVG,改变它,然后把它放回正确的格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谢谢你帮助我!我想使用代码更改路径(SVG)的整个数据,以便我可以将路径的位置移动到特定方向.例如,史蒂夫帮助我使用以下代码在所有 (x,y) 对中将 1 添加到 x 以将路径 (SVG) 移动到正确的方向:史蒂夫的代码(但第一个x (311) 没有改变.有一些错误)

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

得到输出后,我尝试将其放入数据中.我写了 a.SetValue(Path.DataProperty,replace)a.SetValue(Path.DataProperty,Geometry.Parse(replace)),但它们都不起作用.结果表明

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

未处理的错误:System.FormatException: 输入字符串的格式不正确.

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

如何将输出更改为路径数据的正确格式(SVG)?或者我应该更改我以前的代码?

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

谢谢!

推荐答案

WPF 中的路径使用简单的几何图形.这里有关解释了它的语法.如果您阅读并理解那篇文章,那么通过您自己的路径并按照您想要的方式修复它会很容易.

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.

主要命令:

移动命令 M startPoint - 或 - m startPoint

Move command M startPoint - or - m startPoint

行命令 L endPoint - 或 - l endPoint

Line command L endPoint - or - l endPoint

水平线命令 H x - 或 - h x

Horizontal line command H x - or - h x

竖线命令 V y - 或 - v y

Vertical line command V y - or - v y

三次贝塞尔曲线命令 C controlPoint1 controlPoint2 endPoint - 或 - c controlPoint1 controlPoint2 endPoint

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

二次贝塞尔曲线命令 Q controlPoint endPoint - 或 - q controlPoint endPoint

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

椭圆弧指令 A size rotationAngle isLargeArcFlag slimDirectionFlag endPoint- 或 - a size rotationAngle isLargeArcFlag slimDirectionFlag endPoint

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

这篇关于我如何拉出“数据"?从一个SVG,改变它,然后把它放回正确的格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆