vue2\vue3\react\h5 实现图片下载到本地
vue2\vue3\react\h5 实现图片下载到本地
·
const image = new Image();
image.src = '你的图片地址';
image.setAttribute('crossOrigin', 'anonymous');
image.onload = () => {
const canvas = document.createElement('canvas');
canvas.width = image.width;
canvas.height = image.height;
const ctx = canvas.getContext('2d');
ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
const dataURL = canvas.toDataURL();
const a = document.createElement('a');
a.href = dataURL;
a.download = `haha.png`;
a.click();
};
更多推荐
已为社区贡献2条内容
所有评论(0)