JS加载二进制流图片
如果用的是axios,要设置responseType为"arraybuffer"
axios.get('http://localhost:8000/contour', {
params: {
source: source,
type: type,
},
responseType: "arraybuffer",
})
Chrome更新后不知处createObjectURL而是同srcObject做了替代
this.imageData = Image
try {
this.imageData.srcObject = response.data;
} catch (error) {
imageData.onload = function () {
window.URL.revokeObjectURL(imageData.src);
}
this.imageData.src = window.URL.createObjectURL(response.data);
}
如果需要生成url可以采取以下方法
let binaryData = [];
binaryData.push(response.data); //My blob
this.picUrl = URL.createObjectURL(new Blob(binaryData, {type: "image/png"}));