Home > Web Front-end > JS Tutorial > js realizes saving the image generated by canvas or directly saving a picture

js realizes saving the image generated by canvas or directly saving a picture

小云云
Release: 2018-05-19 15:49:13
Original
3194 people have browsed it

This article mainly shares with you how to use js to save a picture generated by canvas or directly save a picture. I hope it can help you.

Save the canvas array

<span style="font-size: 14px;">function downLoadImage(canvas,name) {<br/>    var a = document.createElement("a");<br/>    a.href = canvas.toDataURL();<br/>    a.download = name;<br/>    a.click();}<br/></span>
Copy after login

canvas: the dom object passed into the canvas
name: the name of the saved image

Method to directly save the picture

<span style="font-size: 14px;">function downLoadImage(img,name) {<br/>    var a = document.createElement("a");<br/>    a.href = img.src;<br/>    a.download = name;<br/>    a.click();}<br/></span>
Copy after login

img: DOM object of the picture
name: The name when saving as a picture

The above is the detailed content of js realizes saving the image generated by canvas or directly saving a picture. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template