js 怎么实现image的二进制流
2个回答
展开全部
var convertImgDataToBlob = function (base64Data) {
var format = "image/jpeg";
var base64 = base64Data;
var code = window.atob(base64.split(",")[1]);
var aBuffer = new window.ArrayBuffer(code.length);
var uBuffer = new window.Uint8Array(aBuffer);
for(var i = 0; i < code.length; i++){
uBuffer[i] = code.charCodeAt(i) & 0xff ;
}
console.info([aBuffer]);
console.info(uBuffer);
console.info(uBuffer.buffer);
console.info(uBuffer.buffer==aBuffer); //true
var blob=null;
try{
blob = new Blob([uBuffer], {type : format});
}
catch(e){
window.BlobBuilder = window.BlobBuilder ||
window.WebKitBlobBuilder ||
window.MozBlobBuilder ||
window.MSBlobBuilder;
if(e.name == 'TypeError' && window.BlobBuilder){
var bb = new window.BlobBuilder();
bb.append(uBuffer.buffer);
blob = bb.getBlob("image/jpeg");
}
else if(e.name == "InvalidStateError"){
blob = new Blob([aBuffer], {type : format});
}
else{
}
}
alert(blob.size);
return blob;
};
2017-11-06
展开全部
canvas或者buffer
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询