Home > Web Front-end > JS Tutorial > body text

How to save the image generated by canvas in js

亚连
Release: 2018-06-14 10:46:02
Original
3757 people have browsed it

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();
}
Copy after login

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();
}
Copy after login

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!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!