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

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐