ajax获取图片二进制blob,arraybuffer

blob

ajanuw.request('get', 'http://127.0.0.1:5500/ajax4/4.jpg', {
      resType: 'blob'
    }).then(res => {
      let url = URL.createObjectURL(res.data);
      let img = document.createElement('img')
      img.src = url;
      document.body.append(img);
      img.onload = function () {
        URL.revokeObjectURL(this.url)
      }
    })

arraybuffer

    ajanuw.request('get', 'http://127.0.0.1:5500/ajax4/4.jpg', {
      resType: 'arraybuffer'
    }).then(res => {
      let buffer = res.data; // 只有int8
      l(buffer)
      let url = URL.createObjectURL(new Blob([buffer]), {
        type: 'image/jpg'
      });
      let img = document.createElement('img')
      img.src = url;
      document.body.append(img);
      img.onload = function () {
        URL.revokeObjectURL(this.url)
      }
    })
posted @ 2018-07-01 12:50  Ajanuw  阅读(1105)  评论(0编辑  收藏  举报