Home >Web Front-end >JS Tutorial >How to save the image generated by canvas in js
Below I will share with you a js method to generate a picture from canvas and save it, or directly save a picture. It has a good reference value and I hope it will be helpful to everyone.
Save the canvas array
function downLoadImage(canvas,name) { var a = document.createElement("a"); a.href = canvas.toDataURL(); a.download = name; a.click(); }
canvas: The dom object passed into the canvas
name: The name of the saved picture
How to save the picture directly
function downLoadImage(img,name) { var a = document.createElement("a"); a.href = img.src; a.download = name; a.click(); }
img :DOM object of the picture
name:The name when saving as a picture
The above is what I compiled for everyone , I hope it will be helpful to everyone in the future.
Related articles:
Using JS to calculate the problem of buying 100 chickens
Implementing DOM attribute binding in Angular4
How to implement JSON tree using Vue2.x
Tutorial on the installation and use of CLI in Angular4
The above is the detailed content of How to save the image generated by canvas in js. For more information, please follow other related articles on the PHP Chinese website!