How can I save div as image at client side where div contains one or more than one HTML5 canvas elements?

我是研究僧i 提交于 2019-12-18 07:14:30

问题


Div 'canvasesdiv' element contains three HTML5 canvases.

<div style="position: relative; width: 400px; height: 300px;" id="canvasesdiv">
    <canvas width="400" height="300px" style="z-index: 1; position: absolute; left: 0px; top: 0px;" id="layer1" />
    <canvas width="400" height="300px" style="z-index: 2; position: absolute; left: 0px; top: 0px;" id="layer2"/>
    <canvas width="400" height="300px" style="z-index: 3; position: absolute; left: 0px; top: 0px;" id="layer3"/>
</div>

How can I save an image combining all canvases present inside the div 'canvasesdiv' at client side using JavaScript?


回答1:


This is very similar to a previous question that I answered: save-many-canvas-element-as-image

In summary: draw all of the canvases to one of them and then get the image via toDataURL()




回答2:


I think you have to use Ajax query for some serverside operations. A canvas can be exported in png using Apache Batik with exec('java -jar...')

The rest is algorithmic.



来源:https://stackoverflow.com/questions/3880330/how-can-i-save-div-as-image-at-client-side-where-div-contains-one-or-more-than-o

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