转换SVG图像编程 [英] convert svg to image programatically

查看:172
本文介绍了转换SVG图像编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试我的SVG转换为图像
I一直在寻找到一些工具,仍然不能让这个hapen:(



1。 SVG渲染引擎
,但有它的麻烦IM,因为它没有文件



这是我的代码:使用

 (的FileStream FILESTREAM = File.OpenRead (@C:\sample.svg))
{
的MemoryStream MemoryStream的=新的MemoryStream();
memoryStream.SetLength(fileStream.Length);
fileStream.Read (memoryStream.GetBuffer(),0,(INT)fileStream.Length);
SvgDocument svgDocument = SvgDocument.Open(MemoryStream的);
字符串的ImagePath =local.jpg;
svgDocument。画出()保存(的ImagePath);
}

或本

  VAR sampleDoc = SvgDocument.Open(@C:\sample.svg); 
sampleDoc.Draw()保存(@C:\sample.png);



既不作品!



我得到的错误:

 对象引用未设置到对象的实例。 

说明:当前Web请求的执行过程中发生未处理的异常。请检查堆栈跟踪有关该错误它起源于代码的更多信息和。

异常详细信息:System.NullReferenceException:对象不设置到对象的实例。

源错误:


线363:SvgDocument svgDocument = SvgDocument.Open(MemoryStream的);
线364:字符串的ImagePath =local.jpg;
线365:svgDocument.Draw()保存(的ImagePath);
线366:}
线367:



这个问题似乎是svgDocument是空!



结果



2。 Inkscape的



我的代码:

 字符串svgFileName = HttpContext.Current.Server.MapPath(sample.svg); 
串PngRelativeDirectory = HttpContext.Current.Server.MapPath(〜/);
串pngName =svgpieresult.png;
串pngFileName = HttpContext.Current.Server.MapPath(pngName);


//忽略承担sample.svg是在web app目录
//使用(StreamWriter的作家=新的StreamWriter(svgFileName,FALSE))
// {
// writer.Write(svgXml);
//}


串inkscapeArgs =的String.Format(@ - F{0}-e,{1},,svgFileName,pngFileName);

过程Inkscape中=的Process.Start (
新的ProcessStartInfo(C:\\Program Files\\inkscape\\inkscape.exe,inkscapeArgs));

inkscape.WaitForExit(3000);
//Context.RewritePath(pngName);
context.Response.Redirect(PngRelativeDirectory + pngName);

但没有发生!!我想我失去了一些东西保存图像,而不是RewritePath()



结果
<强>如果u有一个更好的解决方案,我PLZ关于如何使用它的一个例子张贴,感谢



这是我的SVG:



 < XML版本=1.0独立=YES><!DOCTYPE SVG PUBLIC -  // W3C // DTD SVG 1.1 // ENhttp://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\"> 

< SVG宽度=598pxHEIGHT =346px的xmlns =htt​​p://www.w3.org/2000/svg的xmlns:XLink的=HTTP://www.w3 .ORG / 1999 / XLink的版本=1.1>

将; DEFS>&下;的LinearGradient X1 =0Y1 =0×2 =1Y2 =0.9999999999999998ID =主题94ae0a-6b7e07>&下;停止偏移=0%停止色=#94ae0a停不透明度=1>< /停止><停止偏移=100%停止色=#6b7e07停不透明度=1 >< /停止>< /的LinearGradient><的LinearGradient X1 =0Y1 =0X2 =1Y2 =0.9999999999999998ID =主题115fa6-0c4578><停止偏移量=0%停止色=#115fa6停不透明度=1>< /停止><停止偏移=100%停止色=#0c4578停不透明度= 1>&下; /停止及GT;&下; /的LinearGradient>&下;的LinearGradient X1 =0Y1 =0×2 =1Y2 =0.9999999999999998ID =主题a61120-780c17>&下;停止偏移=0%停止色=#a61120停不透明度=1>< /停止><停止偏移=100%停止色=#780c17停不透明度= 1>&下; /停止及GT;&下; /的LinearGradient>&下;的LinearGradient X1 =0Y1 =0×2 =1Y2 =0.9999999999999998ID =主题ff8809-d56e00>&下;停止偏移=0%停止色=#ff8809停不透明度=1>< /停止><停止偏移=100%停止色=#d56e00停不透明度=1>&下; /停止及GT;&下; /的LinearGradient>&下;的LinearGradient X1 =0Y1 =0×2 =1Y2 =0.9999999999999998ID =主题ffd13e-ffc50b> <停止偏移=0%停止色=#ffd13e停不透明度=1>< /停止><停止偏移=100%停止色=#ffc50b停停透明度=1>&下; /停止及GT;&下; /的LinearGradient>&下;的LinearGradient X1 =0Y1 =0×2 =1Y2 =0.9999999999999998ID =主题a61187-780c61> ;<停止偏移=0%停止色=#a61187停不透明度=1>< /停止><停止偏移=100%停止色=#780c61停-opacity =1>&下; /停止及GT;&下; /的LinearGradient>&下;的LinearGradient X1 =0Y1 =0×2 =1Y2 =0.9999999999999998ID =主题24ad9a-1b8374 ><停止偏移=0%停止色=#24ad9a停不透明度=1>< /停止><停止偏移=100%停止色=#1b8374停不透明度=1>< /停止>< /的LinearGradient><的LinearGradient X1 =0Y1 =0X2 =1Y2 =0.9999999999999998ID =主题7c7474-625b5b ><停止偏移=0%停止色=#7c7474停不透明度=1>< /停止><停止偏移=100%停止色=#625b5b 停不透明度=1>< /停止>< /的LinearGradient><的LinearGradient X1 =0Y1 =0X2 =1Y2 =0.9999999999999998ID =主题a66111- 78460c><停止偏移=0%停止色=#a66111停不透明度=1>< /停止><停止偏移=100%停止色=# 78460c停不透明度=1>< /停止>< /的LinearGradient>< / DEFS>< RECT WIDTH =100%HEIGHT =100%补=#FFF填充不透明度=0行程=无/><路径D =M 230 173L 272.3305450559981 68.22822443395302A 113 113 001 343 173L 343 113 173A 113 0 0 1 272.3305450559981 277.771775566047L 272.3305450559981 277.771775566047L 230 173Z补=无行程=RGB(200,200,200),笔划宽度=6中风不透明度=1变换=矩阵(1,0,0,1,1,2)/>< ;路径D =M 230 173L 272.3305450559981 68.22822443395302A 113 113 001 343 173L 343 113 173A 113 0 0 1 272.3305450559981 277.771775566047L 272.3305450559981 277.771775566047L 230 173Z补=无行程=RGB(150,150,150) 笔画宽度=4中风不透明度=1变换=矩阵(1,0,0,1,0,1)/><路径D =M 230 173L 272.3305450559981 68.22822443395302A 113 113 0 0 1 343 173L 343 113 173A 113 0 0 1 272.3305450559981 277.771775566047L 272.3305450559981 277.771775566047L 230 173Z补=无行程=RGB(100,100,100)中风宽度=2中风不透明度= 1变换=矩阵(1,0,0,1,0,1)/><路径D =M 230 173L 210.37775592363687 61.7167239096205A 113 113 0 0 1 241.81171634924485 60.619025823385115L 241.81171634924485 60.619025823385115A 113 113 0 0 1 272.3305450559981 68.22822443395302L 272.3305450559981 68.22822443395302L 230 173Z补=无行程=RGB(200,200,200),笔划宽度=6中风不透明度=1变换=矩阵(1,0, 0,1,1,2)/><路径D =M 230 173L 210.37775592363687 61.7167239096205A 113 113 0 0 1 241.81171634924485 60.619025823385115L 241.81171634924485 60.619025823385115A 113 113 0 0 1 272.3305450559981 68.22822443395302L 272.3305450559981 68.22822443395302L 230 173Z补=无行程=RGB(150,150,150)中风宽度=4中风不透明度=1变换=矩阵(1,0,0,1,0,1)/> ;<路径D =M 230 173L 210.37775592363687 61.7167239096205A 113 113 0 0 1 241.81171634924485 60.619025823385115L 241.81171634924485 60.619025823385115A 113 113 0 0 1 272.3305450559981 68.22822443395302L 272.3305450559981 68.22822443395302L 230 173Z补=无行程=RGB(100, 100,100)中风宽度=2中风不透明度=1变换=矩阵(1,0,0,1,0,1)/><路径D =M 230 173L 120.3565829308124 200.33717420276244A 113 113 0 0 1 135.23022582216709 111.4557890433019L 135.23022582216709 111.4557890433019A 113 113 0 0 1 210.37775592363687 61.7167239096205L 210.37775592363687 61.7167239096205L 230 173Z补=无行程=RGB(200,200,200),笔划宽度=6 中风不透明度=1变换=矩阵(1,0,0,1,1,2)/><路径D =M 230 173L 120.3565829308124 200.33717420276244A 113 113 0 0 1 135.23022582216709 111.4557890433019L 135.23022582216709 111.4557890433019A 113 113 0 0 1 210.37775592363687 61.7167239096205L 210.37775592363687 61.7167239096205L 230 173Z补=无行程=RGB(150,150,150)中风宽度=4中风不透明度=1改造=矩阵(1,0,0,1,0,1)/><路径D =M 230 173L 120.3565829308124 200.33717420276244A 113 113 0 0 1 135.23022582216709 111.4557890433019L 135.23022582216709 111.4557890433019A 113 113 0 0 1 210.37775592363687 61.7167239096205L 210.37775592363687 61.7167239096205L 230 173Z补=无行程=RGB(100,100,100)中风宽度=2中风不透明度=1变换=矩阵(1,0,0,1,0 1)/><路径D =M 230 173L 151.5036041381333 254.28539743826758A 113 113 0 0 1 132.13912937235844 229.5L 132.13912937235844 229.5A 113 113 0 0 1 120.3565829308124 200.33717420276244L 120.3565829308124 200.33717420276244L 230 173Z补=无行程=RGB(200,200,200)笔划宽度=6中风不透明度=1变换=矩阵(1,0,0,1,1,2)/>&下;路径D =M 230 173L 151.5036041381333 254.28539743826758A 113 113 0 0 1 132.13912937235844 229.5L 132.13912937235844 229.5A 113 113 0 0 1 120.3565829308124 200.33717420276244L 120.3565829308124 200.33717420276244L 230 173Z补=无行程=RGB(150,150,150)笔画宽度=4中风不透明度=1变换=矩阵(1,0,0,1,0,1)/><路径D =M 230 173L 151.5036041381333 254.28539743826758A 113 113 0 0 1 132.13912937235844 229.5L 132.13912937235844 229.5A 113 113 0 0 1 120.3565829308124 200.33717420276244L 120.3565829308124 200.33717420276244L 230 173Z补=无行程=RGB(100,100,100)中风宽度=2中风不透明度= 1变换=矩阵(1,0,0,1,0,1)/><路径D =M 230 173L 208.43858352245047 283.92387172958604A 113 113 0 0 1 177.8224067044411 273.23222414913903L 177.8224067044411 273.23222414913903A 113 113 0 0 1 151.5036041381333 254.28539743826758L 151.5036041381333 254.28539743826758L 230 173Z补=无行程=RGB(200,200,200),笔划宽度=6中风不透明度=1变换=矩阵(1,0 ,0,1,1,2)/><路径D =M 230 173L 208.43858352245047 283.92387172958604A 113 113 0 0 1 177.8224067044411 273.23222414913903L 177.8224067044411 273.23222414913903A 113 113 0 0 1 151.5036041381333 254.28539743826758L 151.5036041381333 254.28539743826758L 230 173Z填写=无行程=RGB(150,150,150)中风宽度=4中风不透明度=1变换=矩阵(1,0,0,1,0,1)/ ><路径D =M 230 173L 208.43858352245047 283.92387172958604A 113 113 0 0 1 177.8224067044411 273.23222414913903L 177.8224067044411 273.23222414913903A 113 113 0 0 1 151.5036041381333 254.28539743826758L 151.5036041381333 254.28539743826758L 230 173Z补=无行程=RGB(100 ,100,100)中风宽度=2中风不透明度=1变换=矩阵(1,0,0,1,0,1)/><路径D =M 230 173L 270.495578​​29861897 278.4945881941838A 113 113 0 0 1 239.84859893048534 285.57000088436723L 239.84859893048534 285.57000088436723A 113 113 0 0 1 208.43858352245047 283.92387172958604L 208.43858352245047 283.92387172958604L 230 173Z补=无行程=RGB(200,200,200),笔划宽度= 6中风不透明度=1变换=矩阵(1,0,0,1,1,2)/><路径D =M 230 173L 270.495578​​29861897 278.4945881941838A 113 113 0 0 1 239.84859893048534 285.57000088436723L 239.84859893048534 285.57000088436723A 113 113 0 0 1 208.43858352245047 283.92387172958604L 208.43858352245047 283.92387172958604L 230 173Z补=无行程=RGB(150,150,150)中风宽度=4中风不透明度=1变换= 矩阵(1,0,0,1,0,1)/><路径D =M 230 173L 270.495578​​29861897 278.4945881941838A 113 113 0 0 1 239.84859893048534 285.57000088436723L 239.84859893048534 285.57000088436723A 113 113 0 0 1 208.43858352245047 283.92387172958604L 208.43858352245047 283.92387172958604L 230 173Z补=无行程=RGB(100,100,100)中风宽度=2中风不透明度=1变换=矩阵(1,0,0,1, 0,1)/><路径D =M 230 173L 272.3305450559981 68.22822443395302A 113 113 001 343 173L 343 113 173A 113 0 0 1 272.3305450559981 277.771775566047L 272.3305450559981 277.771775566047L 230 173Z补=URL(#theme -94ae0a-6b7e07)笔画宽度=0像素改造=矩阵(1,0,0,1,0,0)/><路径D =M 230 173L 210.37775592363687 61.7167239096205A 113 113 0 0 1 241.81171634924485 60.619025823385115L 241.81171634924485 60.619025823385115A 113 113 0 0 1 272.3305450559981 68.22822443395302L 272.3305450559981 68.22822443395302L 230 173Z补=URL(#主题115fa6-0c4578)笔画宽度=0像素改造=矩阵(1,0, 0,1,0,0)/><路径D =M 230 173L 120.3565829308124 200.33717420276244A 113 113 0 0 1 135.23022582216709 111.4557890433019L 135.23022582216709 111.4557890433019A 113 113 0 0 1 210.37775592363687 61.7167239096205L 210.37775592363687 61.7167239096205L 230 173Z补=URL(#主题a61120-780c17)笔画宽度=0像素改造=矩阵(1,0,0,1,0,0)/><路径D =M 230 173L 151.5036041381333 254.28539743826758A 113 113 0 0 1 132.13912937235844 229.5L 132.13912937235844 229.5A 113 113 0 0 1 120.3565829308124 200.33717420276244L 120.3565829308124 200.33717420276244L 230 173Z补=URL(#主题ff8809-d56e00)笔画宽度=0像素改造=矩阵(1,0,0,1,0,0)/><路径D =M 230 173L 208.43858352245047 283.92387172958604A 113 113 0 0 1 177.8224067044411 273.23222414913903L 177.8224067044411 273.23222414913903A 113 113 0 0 1 151.5036041381333 254.28539743826758L 151.5036041381333 254.28539743826758L 230 173Z补=URL(#主题ffd13e-ffc50b)笔画宽度=0像素改造=矩阵(1,0,0,1,0,0)/><路径D =M 230 173L 270.495578​​29861897 278.4945881941838A 113 113 0 0 1 239.84859893048534 285.57000088436723L 239.84859893048534 285.57000088436723A 113 113 0 0 1 208.43858352245047 283.92387172958604L 208.43858352245047 283.92387172958604L 230 173Z补=URL(#主题a61187-780c61)笔画宽度= 0像素改造=矩阵(1,0,0,1,0,0)/><文字X =286.5Y =173FONT-SIZE =18FONT-FAMILY =宋体文本锚=中补=#333333变换=矩阵(1,0,0,1,0,0)>< TSPAN X =286.5DY =4.5> 1月 - LT ; / TSPAN>< /文本><文字X =235.1665388416979Y =116.73671822229682FONT-SIZE =18FONT-FAMILY =宋体文本锚=中补=#CCCCCC改造=矩阵(0.0914,-0.9958,0.9958,0.0914,97.4145,340.2432)>< TSPAN X =235.1665388416979DY =4.5>二月和LT; / TSPAN>< /文本><文字X = 182.2358551905599Y =142.81993256099588FONT-SIZE =18FONT-FAMILY =宋体文本锚=中补=#CCCCCC改造=矩阵(0.8454,0.5342,-0.5342,0.8454,104.4655 ,-75.2608)>< TSPAN X =182.2358551905599DY =4.5> 3月< / TSPAN>< /文本><文字X =181.4045806349622Y =201.8224776300739FONT-SIZE = 18FONT-FAMILY =宋体文本锚=中补=#333333变换=矩阵(0.8601,-0.5101,0.5101,0.8601,-77.5769,120.7761)>< TSPAN X = 181.4045806349622DY =4.5> 4月< / TSPAN>< /文本><文字X =204.31408267270237Y =223.32378812306592FONT-SIZE =18FONT-FAMILY =宋体文本锚= 中补=#333333变换=矩阵(0.4546,-0.8​​907,0.8907,0.4546,-8​​7.4823,303.7766)>< TSPAN X =204.31408267270237DY =4.5>&五月LT; / TSPAN> ;< /文本><文字X =235.16653884169793Y =229.26328177770318FONT-SIZE =18FONT-FAMILY =宋体文本锚=中补=#CCCCCC改造=矩阵(0.0914,0.9958,-0.9958,0.0914,441.9649,-25.8825)>< TSPAN X =235.16653884169793DY =4.5> 6月< / TSPAN>< /文本>< RECT X =459.5 Y =85.5WIDTH =78HEIGHT =173补=#FFF行程=#000笔画宽度=1变换=矩阵(1,0,0,1,0, 0)/><文字X =485Y =102FONT-SIZE =12FONT-FAMILY =黑体,无衬线补=#000变换=矩阵(1, 0,0,1,0,0),>< TSPAN X =485DY =3> 1< / TSPAN>< /文本>< RECT X =0Y =0 WIDTH =12高度=12补=URL(#主题94ae0a-6b7e07)改造=矩阵(1,0,0,1,465,96)/><文字X =485 Y =129FONT-SIZE =12FONT-FAMILY =黑体,无衬线补=#000变换=矩阵(1,0,0,1,0,0)> < TSPAN X =485DY =3>二月和LT; / TSPAN>< /文本>< RECT X =0Y =0WIDTH =12高度=12补= URL(#主题115fa6-0c4578)改造=矩阵(1,0,0,1,465,123)/><文字X =485Y =156FONT-SIZE =12字体 - 家庭=黑体,无衬线补=#000变换=矩阵(1,0,0,1,0,0)>< TSPAN X =485DY =3>三月< / TSPAN>< /文本>< RECT X =0Y =0WIDTH =12高度=12补=URL(#主题a61120-780c17)改造=矩阵(1,0,0,1,465,150)/><文字X =485Y =183FONT-SIZE =12FONT-FAMILY =黑体,无衬线补=#000变换=矩阵(1,0,0,1,0,0)>< TSPAN X =485DY =3> 4月< / TSPAN>< /文本>< RECT X = 0Y =0WIDTH =12高度=12补=URL(#主题ff8809-d56e00)改造=矩阵(1,0,0,1,465,177)/><文字X =485Y =210FONT-SIZE =12FONT-FAMILY =黑体,无衬线补=#000变换=矩阵(1,0,0,1,0, 0)>< TSPAN X =485DY =3>五月< / TSPAN>< /文本>< RECT X =0Y =0WIDTH =12高度= 12补=URL(#主题ffd13e-ffc50b)改造=矩阵(1,0,0,1,465,204)/><文字X =485Y =237FONT-SIZE = 12FONT-FAMILY =黑体,无衬线补=#000变换=矩阵(1,0,0,1,0,0)>< TSPAN X =485DY = 3> 6月< / TSPAN>< /文本>< RECT X =0Y =0WIDTH =12高度=12补=URL(#主题a61187-780c61) 改造=矩阵(1,0,0,1,465,231)/>< RECT X =0Y = - 9WIDTH =63HEIGHT =21补=#F00填补─不透明=0变换=矩阵(1,0,0,1,465,96)/>< RECT X =0Y = - 9WIDTH =68HEIGHT =21补= #F00填充不透明度=0变换=矩阵(1,0,0,1,465,123)/>< RECT X =0Y = - 9WIDTH =53HEIGHT = 21补=#F00填充不透明度=0变换=矩阵(1,0,0,1,465,150)/>< RECT X =0Y = - 9WIDTH =44 HEIGHT =21补=#F00填充不透明度=0变换=矩阵(1,0,0,1,465,177)/>< RECT X =0Y = - 9 WIDTH =41高度=21补=#F00填充不透明度=0变换=矩阵(1,0,0,1,465,204)/>< RECT X =0Y = -9WIDTH =47高度=21补=#F00填充不透明度=0变换=矩阵(1,0,0,1,465,231)/>

< / SVG>


解决方案

我做了几个修改你在这里的代码:
我想Inkscape的是跟你的路径有问题,你会使用



PngRelativeDirectory +\+ pngFileName



PngRelativeDirectory在它已经有一个\这样的路径来了我们为c:\\sample.png



此外,我改变了Context.RewritePath到的Response.Redirect - 我得到在浏览器中浏览器呈现饼图

 字符串svgFileName =的HttpContext .Current.Server.MapPath(sample.svg); 
串PngRelativeDirectory =C:\\;
串pngName =svgpieresult.png;
串pngFileName = HttpContext.Current.Server.MapPath(pngName);


/ *忽略假设使用sample.svg是在web app目录
(StreamWriter的作家=新的StreamWriter(svgFileName,FALSE))
{
writer.Write(svgXml);
}
* /

串inkscapeArgs =的String.Format(@ - F{0}-e,{1},,svgFileName, pngFileName);

过程Inkscape中=的Process.Start(
新的ProcessStartInfo(C:\\Program Files\\inkscape\\inkscape.exe,inkscapeArgs));

inkscape.WaitForExit(3000);
//Context.RewritePath(pngName);
this.Response.Redirect(pngName);


im trying to convert my svg to an image i ve been looking into several tools and still cant make this hapen :(

1. SVG rendering engine but im having trouble with it since it has no documentation

this is my code:

 using (FileStream fileStream = File.OpenRead(@"C:\sample.svg"))
        {
            MemoryStream memoryStream = new MemoryStream();
            memoryStream.SetLength(fileStream.Length);
            fileStream.Read(memoryStream.GetBuffer(), 0, (int)fileStream.Length);
            SvgDocument svgDocument = SvgDocument.Open(memoryStream);
            string imagePath = "local.jpg";
            svgDocument.Draw().Save(imagePath);
        }

or this:

        var sampleDoc = SvgDocument.Open(@"C:\sample.svg");
        sampleDoc.Draw().Save(@"C:\sample.png");

neither works !

i get the error :

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error: 


Line 363:                SvgDocument svgDocument = SvgDocument.Open(memoryStream);
Line 364:                string imagePath = "local.jpg";
Line 365:                svgDocument.Draw().Save(imagePath);
Line 366:            }
Line 367:  

The problem seems that svgDocument is null !


2. Inkscape

my code:

 string svgFileName = HttpContext.Current.Server.MapPath("sample.svg");
        string PngRelativeDirectory = HttpContext.Current.Server.MapPath("~/");
        string pngName = "svgpieresult.png";
        string pngFileName = HttpContext.Current.Server.MapPath("pngName);


        // ignored assume sample.svg is in the web app directory
        //using (StreamWriter writer = new StreamWriter(svgFileName, false))
        //{
        //    writer.Write(svgXml);
        //}


        string inkscapeArgs = string.Format(@"-f ""{0}"" -e ""{1}""", svgFileName, pngFileName);

        Process inkscape = Process.Start(
          new ProcessStartInfo("C:\\Program Files\\inkscape\\inkscape.exe", inkscapeArgs));

        inkscape.WaitForExit(3000);
        //Context.RewritePath(pngName);
        context.Response.Redirect(PngRelativeDirectory + pngName); 

but nothing happen!! i think im missing something to save the image instead of RewritePath()


if u have a better solution for me plz post it with an example on how to use it,thanks

this is my svg:

<?xml version="1.0" standalone="yes"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">

<svg width="598px" height="346px" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1">

<defs><linearGradient x1="0" y1="0" x2="1" y2="0.9999999999999998" id="theme-94ae0a-6b7e07"><stop offset="0%" stop-color="#94ae0a" stop-opacity="1"></stop><stop offset="100%" stop-color="#6b7e07" stop-opacity="1"></stop></linearGradient><linearGradient x1="0" y1="0" x2="1" y2="0.9999999999999998" id="theme-115fa6-0c4578"><stop offset="0%" stop-color="#115fa6" stop-opacity="1"></stop><stop offset="100%" stop-color="#0c4578" stop-opacity="1"></stop></linearGradient><linearGradient x1="0" y1="0" x2="1" y2="0.9999999999999998" id="theme-a61120-780c17"><stop offset="0%" stop-color="#a61120" stop-opacity="1"></stop><stop offset="100%" stop-color="#780c17" stop-opacity="1"></stop></linearGradient><linearGradient x1="0" y1="0" x2="1" y2="0.9999999999999998" id="theme-ff8809-d56e00"><stop offset="0%" stop-color="#ff8809" stop-opacity="1"></stop><stop offset="100%" stop-color="#d56e00" stop-opacity="1"></stop></linearGradient><linearGradient x1="0" y1="0" x2="1" y2="0.9999999999999998" id="theme-ffd13e-ffc50b"><stop offset="0%" stop-color="#ffd13e" stop-opacity="1"></stop><stop offset="100%" stop-color="#ffc50b" stop-opacity="1"></stop></linearGradient><linearGradient x1="0" y1="0" x2="1" y2="0.9999999999999998" id="theme-a61187-780c61"><stop offset="0%" stop-color="#a61187" stop-opacity="1"></stop><stop offset="100%" stop-color="#780c61" stop-opacity="1"></stop></linearGradient><linearGradient x1="0" y1="0" x2="1" y2="0.9999999999999998" id="theme-24ad9a-1b8374"><stop offset="0%" stop-color="#24ad9a" stop-opacity="1"></stop><stop offset="100%" stop-color="#1b8374" stop-opacity="1"></stop></linearGradient><linearGradient x1="0" y1="0" x2="1" y2="0.9999999999999998" id="theme-7c7474-625b5b"><stop offset="0%" stop-color="#7c7474" stop-opacity="1"></stop><stop offset="100%" stop-color="#625b5b" stop-opacity="1"></stop></linearGradient><linearGradient x1="0" y1="0" x2="1" y2="0.9999999999999998" id="theme-a66111-78460c"><stop offset="0%" stop-color="#a66111" stop-opacity="1"></stop><stop offset="100%" stop-color="#78460c" stop-opacity="1"></stop></linearGradient></defs><rect width="100%" height="100%" fill="#fff" fill-opacity="0" stroke="none" /><path d="M 230 173L 272.3305450559981 68.22822443395302A 113 113 0 0 1 343 173L 343 173A 113 113 0 0 1 272.3305450559981 277.771775566047L 272.3305450559981 277.771775566047L 230 173Z" fill="none" stroke="rgb(200, 200, 200)" stroke-width="6" stroke-opacity="1" transform="matrix(1,0,0,1,1,2)" /><path d="M 230 173L 272.3305450559981 68.22822443395302A 113 113 0 0 1 343 173L 343 173A 113 113 0 0 1 272.3305450559981 277.771775566047L 272.3305450559981 277.771775566047L 230 173Z" fill="none" stroke="rgb(150, 150, 150)" stroke-width="4" stroke-opacity="1" transform="matrix(1,0,0,1,0,1)" /><path d="M 230 173L 272.3305450559981 68.22822443395302A 113 113 0 0 1 343 173L 343 173A 113 113 0 0 1 272.3305450559981 277.771775566047L 272.3305450559981 277.771775566047L 230 173Z" fill="none" stroke="rgb(100, 100, 100)" stroke-width="2" stroke-opacity="1" transform="matrix(1,0,0,1,0,1)" /><path d="M 230 173L 210.37775592363687 61.7167239096205A 113 113 0 0 1 241.81171634924485 60.619025823385115L 241.81171634924485 60.619025823385115A 113 113 0 0 1 272.3305450559981 68.22822443395302L 272.3305450559981 68.22822443395302L 230 173Z" fill="none" stroke="rgb(200, 200, 200)" stroke-width="6" stroke-opacity="1" transform="matrix(1,0,0,1,1,2)" /><path d="M 230 173L 210.37775592363687 61.7167239096205A 113 113 0 0 1 241.81171634924485 60.619025823385115L 241.81171634924485 60.619025823385115A 113 113 0 0 1 272.3305450559981 68.22822443395302L 272.3305450559981 68.22822443395302L 230 173Z" fill="none" stroke="rgb(150, 150, 150)" stroke-width="4" stroke-opacity="1" transform="matrix(1,0,0,1,0,1)" /><path d="M 230 173L 210.37775592363687 61.7167239096205A 113 113 0 0 1 241.81171634924485 60.619025823385115L 241.81171634924485 60.619025823385115A 113 113 0 0 1 272.3305450559981 68.22822443395302L 272.3305450559981 68.22822443395302L 230 173Z" fill="none" stroke="rgb(100, 100, 100)" stroke-width="2" stroke-opacity="1" transform="matrix(1,0,0,1,0,1)" /><path d="M 230 173L 120.3565829308124 200.33717420276244A 113 113 0 0 1 135.23022582216709 111.4557890433019L 135.23022582216709 111.4557890433019A 113 113 0 0 1 210.37775592363687 61.7167239096205L 210.37775592363687 61.7167239096205L 230 173Z" fill="none" stroke="rgb(200, 200, 200)" stroke-width="6" stroke-opacity="1" transform="matrix(1,0,0,1,1,2)" /><path d="M 230 173L 120.3565829308124 200.33717420276244A 113 113 0 0 1 135.23022582216709 111.4557890433019L 135.23022582216709 111.4557890433019A 113 113 0 0 1 210.37775592363687 61.7167239096205L 210.37775592363687 61.7167239096205L 230 173Z" fill="none" stroke="rgb(150, 150, 150)" stroke-width="4" stroke-opacity="1" transform="matrix(1,0,0,1,0,1)" /><path d="M 230 173L 120.3565829308124 200.33717420276244A 113 113 0 0 1 135.23022582216709 111.4557890433019L 135.23022582216709 111.4557890433019A 113 113 0 0 1 210.37775592363687 61.7167239096205L 210.37775592363687 61.7167239096205L 230 173Z" fill="none" stroke="rgb(100, 100, 100)" stroke-width="2" stroke-opacity="1" transform="matrix(1,0,0,1,0,1)" /><path d="M 230 173L 151.5036041381333 254.28539743826758A 113 113 0 0 1 132.13912937235844 229.5L 132.13912937235844 229.5A 113 113 0 0 1 120.3565829308124 200.33717420276244L 120.3565829308124 200.33717420276244L 230 173Z" fill="none" stroke="rgb(200, 200, 200)" stroke-width="6" stroke-opacity="1" transform="matrix(1,0,0,1,1,2)" /><path d="M 230 173L 151.5036041381333 254.28539743826758A 113 113 0 0 1 132.13912937235844 229.5L 132.13912937235844 229.5A 113 113 0 0 1 120.3565829308124 200.33717420276244L 120.3565829308124 200.33717420276244L 230 173Z" fill="none" stroke="rgb(150, 150, 150)" stroke-width="4" stroke-opacity="1" transform="matrix(1,0,0,1,0,1)" /><path d="M 230 173L 151.5036041381333 254.28539743826758A 113 113 0 0 1 132.13912937235844 229.5L 132.13912937235844 229.5A 113 113 0 0 1 120.3565829308124 200.33717420276244L 120.3565829308124 200.33717420276244L 230 173Z" fill="none" stroke="rgb(100, 100, 100)" stroke-width="2" stroke-opacity="1" transform="matrix(1,0,0,1,0,1)" /><path d="M 230 173L 208.43858352245047 283.92387172958604A 113 113 0 0 1 177.8224067044411 273.23222414913903L 177.8224067044411 273.23222414913903A 113 113 0 0 1 151.5036041381333 254.28539743826758L 151.5036041381333 254.28539743826758L 230 173Z" fill="none" stroke="rgb(200, 200, 200)" stroke-width="6" stroke-opacity="1" transform="matrix(1,0,0,1,1,2)" /><path d="M 230 173L 208.43858352245047 283.92387172958604A 113 113 0 0 1 177.8224067044411 273.23222414913903L 177.8224067044411 273.23222414913903A 113 113 0 0 1 151.5036041381333 254.28539743826758L 151.5036041381333 254.28539743826758L 230 173Z" fill="none" stroke="rgb(150, 150, 150)" stroke-width="4" stroke-opacity="1" transform="matrix(1,0,0,1,0,1)" /><path d="M 230 173L 208.43858352245047 283.92387172958604A 113 113 0 0 1 177.8224067044411 273.23222414913903L 177.8224067044411 273.23222414913903A 113 113 0 0 1 151.5036041381333 254.28539743826758L 151.5036041381333 254.28539743826758L 230 173Z" fill="none" stroke="rgb(100, 100, 100)" stroke-width="2" stroke-opacity="1" transform="matrix(1,0,0,1,0,1)" /><path d="M 230 173L 270.49557829861897 278.4945881941838A 113 113 0 0 1 239.84859893048534 285.57000088436723L 239.84859893048534 285.57000088436723A 113 113 0 0 1 208.43858352245047 283.92387172958604L 208.43858352245047 283.92387172958604L 230 173Z" fill="none" stroke="rgb(200, 200, 200)" stroke-width="6" stroke-opacity="1" transform="matrix(1,0,0,1,1,2)" /><path d="M 230 173L 270.49557829861897 278.4945881941838A 113 113 0 0 1 239.84859893048534 285.57000088436723L 239.84859893048534 285.57000088436723A 113 113 0 0 1 208.43858352245047 283.92387172958604L 208.43858352245047 283.92387172958604L 230 173Z" fill="none" stroke="rgb(150, 150, 150)" stroke-width="4" stroke-opacity="1" transform="matrix(1,0,0,1,0,1)" /><path d="M 230 173L 270.49557829861897 278.4945881941838A 113 113 0 0 1 239.84859893048534 285.57000088436723L 239.84859893048534 285.57000088436723A 113 113 0 0 1 208.43858352245047 283.92387172958604L 208.43858352245047 283.92387172958604L 230 173Z" fill="none" stroke="rgb(100, 100, 100)" stroke-width="2" stroke-opacity="1" transform="matrix(1,0,0,1,0,1)" /><path d="M 230 173L 272.3305450559981 68.22822443395302A 113 113 0 0 1 343 173L 343 173A 113 113 0 0 1 272.3305450559981 277.771775566047L 272.3305450559981 277.771775566047L 230 173Z" fill="url(#theme-94ae0a-6b7e07)" stroke-width="0px" transform="matrix(1,0,0,1,0,0)" /><path d="M 230 173L 210.37775592363687 61.7167239096205A 113 113 0 0 1 241.81171634924485 60.619025823385115L 241.81171634924485 60.619025823385115A 113 113 0 0 1 272.3305450559981 68.22822443395302L 272.3305450559981 68.22822443395302L 230 173Z" fill="url(#theme-115fa6-0c4578)" stroke-width="0px" transform="matrix(1,0,0,1,0,0)" /><path d="M 230 173L 120.3565829308124 200.33717420276244A 113 113 0 0 1 135.23022582216709 111.4557890433019L 135.23022582216709 111.4557890433019A 113 113 0 0 1 210.37775592363687 61.7167239096205L 210.37775592363687 61.7167239096205L 230 173Z" fill="url(#theme-a61120-780c17)" stroke-width="0px" transform="matrix(1,0,0,1,0,0)" /><path d="M 230 173L 151.5036041381333 254.28539743826758A 113 113 0 0 1 132.13912937235844 229.5L 132.13912937235844 229.5A 113 113 0 0 1 120.3565829308124 200.33717420276244L 120.3565829308124 200.33717420276244L 230 173Z" fill="url(#theme-ff8809-d56e00)" stroke-width="0px" transform="matrix(1,0,0,1,0,0)" /><path d="M 230 173L 208.43858352245047 283.92387172958604A 113 113 0 0 1 177.8224067044411 273.23222414913903L 177.8224067044411 273.23222414913903A 113 113 0 0 1 151.5036041381333 254.28539743826758L 151.5036041381333 254.28539743826758L 230 173Z" fill="url(#theme-ffd13e-ffc50b)" stroke-width="0px" transform="matrix(1,0,0,1,0,0)" /><path d="M 230 173L 270.49557829861897 278.4945881941838A 113 113 0 0 1 239.84859893048534 285.57000088436723L 239.84859893048534 285.57000088436723A 113 113 0 0 1 208.43858352245047 283.92387172958604L 208.43858352245047 283.92387172958604L 230 173Z" fill="url(#theme-a61187-780c61)" stroke-width="0px" transform="matrix(1,0,0,1,0,0)" /><text x="286.5" y="173" font-size="18" font-family="Arial" text-anchor="middle" fill="#333333" transform="matrix(1,0,0,1,0,0)" ><tspan x="286.5" dy="4.5">January</tspan></text><text x="235.1665388416979" y="116.73671822229682" font-size="18" font-family="Arial" text-anchor="middle" fill="#cccccc" transform="matrix(0.0914,-0.9958,0.9958,0.0914,97.4145,340.2432)" ><tspan x="235.1665388416979" dy="4.5">February</tspan></text><text x="182.2358551905599" y="142.81993256099588" font-size="18" font-family="Arial" text-anchor="middle" fill="#cccccc" transform="matrix(0.8454,0.5342,-0.5342,0.8454,104.4655,-75.2608)" ><tspan x="182.2358551905599" dy="4.5">March</tspan></text><text x="181.4045806349622" y="201.8224776300739" font-size="18" font-family="Arial" text-anchor="middle" fill="#333333" transform="matrix(0.8601,-0.5101,0.5101,0.8601,-77.5769,120.7761)" ><tspan x="181.4045806349622" dy="4.5">April</tspan></text><text x="204.31408267270237" y="223.32378812306592" font-size="18" font-family="Arial" text-anchor="middle" fill="#333333" transform="matrix(0.4546,-0.8907,0.8907,0.4546,-87.4823,303.7766)" ><tspan x="204.31408267270237" dy="4.5">May</tspan></text><text x="235.16653884169793" y="229.26328177770318" font-size="18" font-family="Arial" text-anchor="middle" fill="#cccccc" transform="matrix(0.0914,0.9958,-0.9958,0.0914,441.9649,-25.8825)" ><tspan x="235.16653884169793" dy="4.5">June</tspan></text><rect x="459.5" y="85.5" width="78" height="173" fill="#FFF" stroke="#000" stroke-width="1" transform="matrix(1,0,0,1,0,0)" /><text x="485" y="102" font-size="12" font-family="Helvetica, sans-serif" fill="#000" transform="matrix(1,0,0,1,0,0)" ><tspan x="485" dy="3">January</tspan></text><rect x="0" y="0" width="12" height="12" fill="url(#theme-94ae0a-6b7e07)" transform="matrix(1,0,0,1,465,96)" /><text x="485" y="129" font-size="12" font-family="Helvetica, sans-serif" fill="#000" transform="matrix(1,0,0,1,0,0)" ><tspan x="485" dy="3">February</tspan></text><rect x="0" y="0" width="12" height="12" fill="url(#theme-115fa6-0c4578)" transform="matrix(1,0,0,1,465,123)" /><text x="485" y="156" font-size="12" font-family="Helvetica, sans-serif" fill="#000" transform="matrix(1,0,0,1,0,0)" ><tspan x="485" dy="3">March</tspan></text><rect x="0" y="0" width="12" height="12" fill="url(#theme-a61120-780c17)" transform="matrix(1,0,0,1,465,150)" /><text x="485" y="183" font-size="12" font-family="Helvetica, sans-serif" fill="#000" transform="matrix(1,0,0,1,0,0)" ><tspan x="485" dy="3">April</tspan></text><rect x="0" y="0" width="12" height="12" fill="url(#theme-ff8809-d56e00)" transform="matrix(1,0,0,1,465,177)" /><text x="485" y="210" font-size="12" font-family="Helvetica, sans-serif" fill="#000" transform="matrix(1,0,0,1,0,0)" ><tspan x="485" dy="3">May</tspan></text><rect x="0" y="0" width="12" height="12" fill="url(#theme-ffd13e-ffc50b)" transform="matrix(1,0,0,1,465,204)" /><text x="485" y="237" font-size="12" font-family="Helvetica, sans-serif" fill="#000" transform="matrix(1,0,0,1,0,0)" ><tspan x="485" dy="3">June</tspan></text><rect x="0" y="0" width="12" height="12" fill="url(#theme-a61187-780c61)" transform="matrix(1,0,0,1,465,231)" /><rect x="0" y="-9" width="63" height="21" fill="#f00" fill-opacity="0" transform="matrix(1,0,0,1,465,96)" /><rect x="0" y="-9" width="68" height="21" fill="#f00" fill-opacity="0" transform="matrix(1,0,0,1,465,123)" /><rect x="0" y="-9" width="53" height="21" fill="#f00" fill-opacity="0" transform="matrix(1,0,0,1,465,150)" /><rect x="0" y="-9" width="44" height="21" fill="#f00" fill-opacity="0" transform="matrix(1,0,0,1,465,177)" /><rect x="0" y="-9" width="41" height="21" fill="#f00" fill-opacity="0" transform="matrix(1,0,0,1,465,204)" /><rect x="0" y="-9" width="47" height="21" fill="#f00" fill-opacity="0" transform="matrix(1,0,0,1,465,231)" />

</svg>

解决方案

I made a couple of changes to you code here: I think InkScape was having a problem with you paths, you'd used

PngRelativeDirectory + "\" + pngFileName

PngRelativeDirectory already had a "\" in it so the path was coming our as c:\\sample.png

Also i changed the Context.RewritePath to Response.Redirect - I get the pie chart rendered in the browser the browser.

string svgFileName = HttpContext.Current.Server.MapPath("sample.svg");
string PngRelativeDirectory = "C:\\";
string pngName = "svgpieresult.png";
string pngFileName = HttpContext.Current.Server.MapPath(pngName);


/* ignored assume sample.svg is in the web app directory
using (StreamWriter writer = new StreamWriter(svgFileName, false))
{
    writer.Write(svgXml);
}
 */

string inkscapeArgs = string.Format(@"-f ""{0}"" -e ""{1}""", svgFileName, pngFileName);

Process inkscape = Process.Start(
  new ProcessStartInfo( "C:\\Program Files\\inkscape\\inkscape.exe", inkscapeArgs));

inkscape.WaitForExit(3000);
//Context.RewritePath(pngName);
this.Response.Redirect(pngName);

这篇关于转换SVG图像编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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