捕获一个div作为图像 [英] Capture a div as an image

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

问题描述

我有一些div标签包含由javascript呈现的图表。我想通过按下按钮以图像格式导出它们。我不知道是否有可能使用javascript捕获div标签作为图像!所以我要求提示和提示。提前感谢。

I have some div tags containing charts rendered by javascript. I want to export them in an image format by the press of a button. I don't know if it's possible to capture a div tag as an image using javascript ! so there i'm asking for tips and hints. Thanks in advance.

推荐答案

您可以使用canvas元素创建图像。
如果您的图表使用HTML元素呈现,您需要绘制HTML到画布上
然后,您可以在画布上使用toDataURL来获取B64编码的图像数据。

You can create an image using the canvas element. If your charts are rendered using HTML elements you need to draw that HTML onto the canvas. Then you can use toDataURL on the canvas to get the B64-encoded image data.

这篇关于捕获一个div作为图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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