通过路径下载图片
let src =
"http://tiebapic.baidu.com/forum/w%3D580/sign=547bdfe1143b5bb5bed720f606d2d523/5205e7cd7b899e5173fce45e55a7d933c9950d0d.jpg";
var canvas = document.createElement("canvas");
var img = document.createElement("img");
img.onload = function (e) {
canvas.width = img.width;
canvas.height = img.height;
var context = canvas.getContext("2d");
context.drawImage(img, 0, 0, img.width, img.height);
// window.navigator.msSaveBlob(canvas.msToBlob(),'image.jpg');
// saveAs(imageDataUrl, '附件');
canvas.getContext("2d").drawImage(img, 0, 0, img.width, img.height);
canvas.toBlob((blob) => {
let link = document.createElement("a");
link.href = window.URL.createObjectURL(blob);
link.download = "aaa";
link.click();
}, "image/jpeg");
// context.toBlob(function(blob) {
// console.log('blob :', blob);
// let link = document.createElement('a');
// link.href = window.URL.createObjectURL(blob);
// link.download = 'aaa';
// }, "image/jpeg");
};
img.setAttribute("crossOrigin", "Anonymous");
img.src = src;