将jQuery SVG转换为图像

Bak*_*yor 2 javascript jquery svg canvas

我正在使用jQuery SVG插件生成SVG对象.问题是如何在脚本中将其转换为图像.

我的脚本如下:

<html>
<head>        
<script type="text/javascript" src="jquery-latest.min.js"></script>                
<script type="text/javascript" src="jquery.svg.js"></script>
<script type="text/javascript">
$(function(){
  $("#draw").click(function(){
     $('#svg_container').svg();
     svg = $('#svg_container').svg('get');
     svg.clear(true);
     svg.circle(200, 220, 150, {fill: "red", stroke: "blue", strokeWidth: 5});
     alert(svg.toSVG()); //this prints svg source of the generated image, i.e. circle
  });
});
</script>
</head>
<body>
<div id="svg_container" style="position: absolute; left: 100px; top: 100px; width: 400px; height: 400px; border: thin solid #4297D7;"></div>
<button id="draw">Draw</button>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

我已经尝试了这个这个,但没有成功.

你能告诉我如何将这个svg转换成任何类型的图像吗?

提前致谢.

UPDATE

问题解决了,我已将解决方案作为答案发布,请在此处查看.

Dav*_*son 6

这种接缝很难做到.

我发现这个项目试图这样做:

http://www.svgopen.org/2010/papers/62-From_SVG_to_Canvas_and_Back/index.html

我还发现了一个试图为Canvas构建SVG渲染器的项目,但它还远未完成.

他们确实使用了一个解决方案来通过服务器并将SVG渲染到那里的PNG,这可能是目前唯一真正有用的解决方案.