Download canvas image on the fly

2019-02-27 10:10发布

问题:

I have <div id="qrcode"></div>

Then jquery.qrcode.js plugin creates over a` element with the QR Code.

So, i would like to put a <button> element in the page for downloading that "image" (it's a canvas element) created on the fly.

Is it possible to do that?

回答1:

jquery canvas image download

The saving of the image can be done using HTML5 blobs.

http://www.html5rocks.com/en/tutorials/file/filesystem/#toc-file-writing

You can get Blob out of the like done in this code:

https://github.com/miohtama/Krusovice/blob/master/src/tools/resizer.js