zl程序教程

您现在的位置是:首页 >  前端

当前栏目

ajax获取图片二进制blob,arraybuffer

AJAX二进制 获取 图片 blob
2023-09-14 08:58:45 时间

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)
      }
    })