收藏
回答

IOS 14.x 版本 canvas.toDataURL 返回 data:; ,其它平台正常。?

 function compressImage(file){
  let cvs = document.getElementById('compress-canvas');
  let newImage = new Image();
  let fileCache = file;
  newImage.src = file.content;
  newImage.onload = () => {
    if (newImage.complete) {
      cvs.width = newImage.naturalWidth;
      cvs.height = newImage.naturalHeight;
      cvs.getContext('2d').drawImage(newImage, 0, 0, newImage.naturalWidth, newImage.naturalHeight);
      const newImageData = cvs.toDataURL(mime_type, 0.5);
      // newImageData 居然为data:; 
    }
  };
}
      
回答关注问题邀请回答
收藏

1 个回答

  • ZLENGANG
    ZLENGANG
    2022-04-11
    naturalWidth和naturalHeight的原因,替换成widthheight就行了
    


    2022-04-11
    有用
    回复
登录 后发表内容