如何将图像转换为Buffer

2024-01-05

我想将图像 Mat 转换为缓冲区

console.log(image);

output:

Mat {
  step: 960,
  elemSize: 3,
  sizes: [ 160, 320 ],
  empty: 0,
  depth: 0,
  dims: 2,
  channels: 3,
  type: 16,
  cols: 320,
  rows: 160
}

我想把它转换成这样

Promise {
  <Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 00 00 01 00 01 00 00 ff db 00 43 00 08 06 06 07 06 05 08 07 07 07 09 09 08 0a 0c 14 0d 0c 0b 0b 0c 19 12 13 0f ... 14164 more bytes>
}

我尝试了各种方法但没有成功。

一些例子

var processImageBuffer = new ArrayBuffer(image);  // convert image to buffer array

var blob = new Blob(image);                       // convert buffer array to promise array

var processImageBuffer = blob.arrayBuffer();

var processImageBuffer = arrayBufferToBuffer(processImageBuffer);  // convert promise array to buffer

使用 NodeJ

const promise = fs.promises.readFile(path.join('path to image file'));

Promise.resolve(promise).then(function(buffer){
     console.log(buffer);
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何将图像转换为Buffer 的相关文章

随机推荐