處理圖片流數據

處理二進制流圖片數據

  • 使用xml.responseType = "blob"; 請求返回blob數據流
  • 使用window.URL.createObjectURL(this.response);處理爲尋址數據
  • 在加載完成後卸載window.URL.revokeObjectURL(tar.src);節省內存
loadImg(item,ev){
            let url =URL.APIURL(`UniversalMarketing/Project/LoadImage?filename=110.png`);
            let tar = ev.target
            let me = tar.classList;
             if(!me.contains("show")){
                 let xml = new XMLHttpRequest();
                     xml.withCredentials = true;
                     xml.responseType = "blob";
                     xml.open("GET",url);
                     xml.addEventListener("readystatechange",function(d){
                         if(this.status==200&&this.response){
                             tar.src = window.URL.createObjectURL(this.response);
                             tar.classList.add("show");
                             
                         }
                     })
                        xml.send(null);
               
            }else{
                window.URL.revokeObjectURL(tar.src)
            }
            return;
            
        }
複製代碼
相關文章
相關標籤/搜索