Capture a div as an image [duplicate]

烈酒焚心 提交于 2020-01-20 08:27:38

问题


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.


回答1:


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.




回答2:


This is not possible using only JavaScript.

JavaScript has no access on a PC to save files, nor can it convert the DOM to a image format.




回答3:


There was a dissussion here: html5: copy a canvas to image and back Also there is a project http://www.nihilogic.dk/labs/canvas2image/




回答4:


u might try phantomjs, http://phantomjs.org/, although I have'nt used it personally, but it is widely used for screen captures




回答5:


  1. JS can't access to displayed in case he can't parse HTML
  2. You can call some utility to make screenshot of area. But it's not safe to use, so it will work if you give access.
  3. This question was already asked here. Probably it has some good things you need


来源:https://stackoverflow.com/questions/13720815/capture-a-div-as-an-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!