前端imageBuffer设置图片src(后端到前端直传buffer)

本质为buffer转base64
let bytes = new Uint8Array(imageBuffer.data);
let data = "";
let len = bytes.byteLength;
for (let i = 0; i < len; i++) {
  data += String.fromCharCode(bytes[i]);
}
image.src = "data:image/png;base64," + window.btoa(data);

 

posted @ 2018-01-22 17:52  善未易明  阅读(4393)  评论(0编辑  收藏  举报