javascript 将 Raphael SVG 转换为图像(png 等)客户端
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4086703/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Convert Raphael SVG to image (png etc) client side
提问by mitch
Possible Duplicate:
Convert SVG to image (JPEG, PNG, etc.) in the browser
I have a small project where users construct a diagram using Raphael and then export the composed diagram to an image to save.
我有一个小项目,用户使用 Raphael 构建图表,然后将组合图导出到图像进行保存。
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.
问题是它必须离线运行。http://www.nihilogic.dk/labs/canvas2image/将无法工作,因为它需要画布,而不是 Raphael 生成的 SVG。
Is there a way (javascript) that I can export an image from the SVG?
有没有办法(javascript)可以从 SVG 导出图像?
回答by mitch
Yes, that duplicate question was a big help. canvg combined with canvas2image sorted me out.
是的,那个重复的问题很有帮助。canvg 与 canvas2image 相结合,让我找到了答案。
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。然后单击按钮,将保存 SVG 的 div 的内部 HTML 保存在一个变量中,然后在 canvg 中使用它,隐藏 SVG div。然后我可以将画布的 ID 用于 canvas2image。它只适用于 PNG。

