簡體   English   中英

將圖像更改為 Blob 在 IE11 中不起作用

[英]Change image into Blob is not working in IE11

使用以下代碼將圖像更改為 blob。

changeImageIntoBlob = getImageResponse => {
 var urlCreator = window.URL || window.webkitURL;
 var binaryData = [];
 binaryData.push(getImageResponse);
 var image = urlCreator.createObjectURL(
   new Blob(binaryData, { type: "jpeg/png" })
 );

 this.setState({
   image
 });
};

在上面的代碼中 getImageResponse 參數應該是這樣的

Blob {size: 144425, type: "image/jpeg"}

它在 chrome、firefox 和 EDGE 中工作正常,但這個現在在 IE11 中工作,在 IE 中發生的錯誤是InvalidStateError並且還在下圖中添加了錯誤以供您參考。

IE11面臨的錯誤

幫我弄清楚。

您可以嘗試使用此 function。 我不確定您的getImageResponse的格式是什么。 如果它是一個 dataURI,像這樣

data:image/jpeg;base64,R0lGODlhEAAQAMQAAORHHOV....

然后你可以試試這個

dataURItoBlob(dataURI) {
      var byteString = atob(dataURI.split(",")[1]);
      var ab = new ArrayBuffer(byteString.length);
      var ia = new Uint8Array(ab);
      for (var i = 0; i < byteString.length; i++) {
        ia[i] = byteString.charCodeAt(i);
      }
      return new Blob([ab], { type: "image/jpeg" }); // change the type here into the type you want
    },

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM