1 function getimage(imageurl){ 2 var arr = imageurl.split('/'); 3 function binaryToArrayBuffer(data) { 4 var arr = new Uint8Array(data.length); 5 for(var i = 0, l = data.length; i < l; i++) { 6 arr[i] = data.charCodeAt(i); 7 } 10 return arr.buffer; 12 }; 13 //获取原始responseTest并转化为arrayBuffer格式 14 function getImageArrBuffer(url) { 15 var r = new XMLHttpRequest(); 16 r.open("GET", url, false); 17 r.overrideMimeType('text/plain; charset=x-user-defined'); 18 r.send(null); 19 var arrayBuffer = binaryToArrayBuffer(r.responseText); 20 arrayBuffer.name = arrayBuffer.fileName = url.substring(url.lastIndexOf('/') + 1); 21 arrayBuffer.fileType = "image/jpeg"; //"image/octet-stream"; 22 return arrayBuffer; 23 }; 24 var response = getImageArrBuffer(imageurl); 25 console.log(response);26 }
参考:https://www.cnblogs.com/fengmk2/archive/2011/05/08/2040621.html