将Raphael SVG转换为图像(png等)客户端 [英] Convert Raphael SVG to image (png etc) client side

查看:411
本文介绍了将Raphael SVG转换为图像(png等)客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

在浏览器中将SVG转换为图像(JPEG,PNG等)

我有一个小项目,用户使用Raphael构建图表,然后将组合图表导出到图像中以保存。

I have a small project where users construct a diagram using Raphael and then export the composed diagram to an image to save.

问题是它必须脱机运行。 http://www.nihilogic.dk/labs/canvas2image/ 将无法正常运行需要画布,而不是Raphael生成的SVG。

Problem is it has to run offline. http://www.nihilogic.dk/labs/canvas2image/ will not work as it requires a canvas, not the Raphael generated SVG.

有没有办法(javascript)可以从SVG导出图像?

Is there a way (javascript) that I can export an image from the SVG?

推荐答案

是的,这个重复的问题是一个很大的帮助。 canvg结合canvas2image将我排除在外。

Yes, that duplicate question was a big help. canvg combined with canvas2image sorted me out.

所以我用Raphael创建了SVG。然后在按钮上单击,将保存SVG的div的内部HTML保存在变量中,然后在canvg中使用它,隐藏SVG div。然后我可以使用canvas2image的画布ID。这对PNG来说真的很有效。

So I created the SVG using Raphael. Then on a button click, saved the inner HTML of the div holding the SVG in a variable, then used that in canvg, hiding the SVG div. I could then use the ID of the canvas for canvas2image. It only really worked well for PNG.

这篇关于将Raphael SVG转换为图像(png等)客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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