将 Raphael SVG 转换为图像(png 等)客户端 [英] Convert Raphael SVG to image (png etc) client side
问题描述
可能的重复:
将 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.然后我可以将画布的 ID 用于 canvas2image.它只适用于 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屋!