Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/112.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 使用CGPath绘制SVG输出_Ios_Svg_Drawing - Fatal编程技术网

Ios 使用CGPath绘制SVG输出

Ios 使用CGPath绘制SVG输出,ios,svg,drawing,Ios,Svg,Drawing,我用CGPath和CAShapeLayer制作了一个绘画(绘图屏幕),现在我的客户希望输出的图像可以缩放,我找到了SVG工具包,但我不知道如何使用这个库。我在图书馆的示例中也没有找到和示例!有人知道如何使用这个库将CGPath转换成SVG吗?或者可以给我一个关于CGPath的教程吗 提前谢谢 你可以先看看。它有一个将CGPathRef转换为SVG路径的d属性的例程。我写的 类方法的签名是+(NSString*)svgPathFromCGPath:(CGPathRef)aPath; [更新:在下面

我用CGPath和CAShapeLayer制作了一个绘画(绘图屏幕),现在我的客户希望输出的图像可以缩放,我找到了SVG工具包,但我不知道如何使用这个库。我在图书馆的示例中也没有找到和示例!有人知道如何使用这个库将CGPath转换成SVG吗?或者可以给我一个关于CGPath的教程吗


提前谢谢

你可以先看看。它有一个将CGPathRef转换为SVG路径的d属性的例程。我写的

类方法的签名是+(NSString*)svgPathFromCGPath:(CGPathRef)aPath; [更新:在下面添加了代码片段]

#import "SVGPathGenerator.h"

产出: M10.0 10.0Q20.0 0.0 30.0 40.0C20.0 40.0 40.0 30.0 100.0 90.0L50.0 100.0

注意,如果添加弧,输出将不会有紧密的对应关系,因为SVG中的弧和Quartz中的弧的描述完全不同

如果您想将其输出到一个简单的SVG文件,那么您可以执行以下操作:

 CGRect boundingBox = CGPathGetPathBoundingBox(pathToBuild);

NSString* svgAsString = [NSString stringWithFormat:@" <?xml version=\"1.0\" encoding=\"UTF-8\"?> \
                         <!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\"> \
                         <svg  xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" viewport-fill=\"none\" viewBox=\"%lf, %lf, %lf, %lf\" version=\"1.1\" height=\"%lf\" width=\"%lf\" > \
                         <path fill=\"none\" stroke=\"green\" d=\"%@\" /> \
                         </svg>",
                         boundingBox.origin.x, boundingBox.origin.y, boundingBox.size.width, boundingBox.size.height, boundingBox.size.height, boundingBox.size.width, aDAttribute
                         ];

NSData* utf8Data = [svgAsString dataUsingEncoding:NSUTF8StringEncoding];
[utf8Data writeToFile:pathToFile atomically:YES];
CGRect boundingBox=CGPathGetPathBoundingBox(pathToBuild);
NSString*SVGASTRING=[NSString stringWithFormat:@]\
\
\
\
",
boundingBox.origin.x,boundingBox.origin.y,boundingBox.size.width,boundingBox.size.height,boundingBox.size.height,boundingBox.size.width,AdaAttribute
];
NSData*utf8Data=[SvGaString数据使用编码:NSUTF8StringEncoding];
[utf8Data WriteFile:pathToFile原子性:是];

(我没有编译这段代码)。

您好,我非常感谢您的帮助,如果我没有要求太多,您能给我一个如何使用svgPathFromCGPath函数的示例吗?谢谢,祝你今天愉快!好的,附加了代码片段。您好,谢谢您的回答,但是我看到了这个函数,我的问题是在我进行了从CGPath到SVGPath的转换之后,生成SVG文件的例程是什么。我真的很感激你帮助我的努力!祝您有个美好的一天!“好的,我加了一个剪子,我扔在一起也可以这么做。”科内利乌斯这个回答说了怎么做。使用SVGgh中的svgPathFromCGPath实用程序将CGPath转换为字符串,然后将其插入SVG文件。
 CGRect boundingBox = CGPathGetPathBoundingBox(pathToBuild);

NSString* svgAsString = [NSString stringWithFormat:@" <?xml version=\"1.0\" encoding=\"UTF-8\"?> \
                         <!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\"> \
                         <svg  xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" viewport-fill=\"none\" viewBox=\"%lf, %lf, %lf, %lf\" version=\"1.1\" height=\"%lf\" width=\"%lf\" > \
                         <path fill=\"none\" stroke=\"green\" d=\"%@\" /> \
                         </svg>",
                         boundingBox.origin.x, boundingBox.origin.y, boundingBox.size.width, boundingBox.size.height, boundingBox.size.height, boundingBox.size.width, aDAttribute
                         ];

NSData* utf8Data = [svgAsString dataUsingEncoding:NSUTF8StringEncoding];
[utf8Data writeToFile:pathToFile atomically:YES];