onImageArrival(receiver: image.ImageReceiver): void {
receiver.on('imageArrival', () => {
receiver.readNextImage((err: BusinessError, nextImage: image.Image) => {
if (err || nextImage === undefined) {
console.error('readNextImage failed');
return;
}
nextImage.getComponent(image.ComponentType.JPEG, async (err: BusinessError, imgComponent: image.Component) => {
if (err || imgComponent === undefined) {
console.error('getComponent failed');
}
if (imgComponent && imgComponent.byteBuffer as ArrayBuffer) {
let buffer = imgComponent.byteBuffer as ArrayBuffer
try {
let pixelMap: image.PixelMap =
await image.createImageSource(buffer).createPixelMap()
console.error(`result ${pixelMap.getDensity()}`);
} catch (e) {
console.error(JSON.stringify(e))
}
} else {
console.error('byteBuffer is null');
}
nextImage.release();
})
})
})
}
详细日志
05-27 16:46:22.152 12178-12424 C02B03/HeifFormatAgent com.examp...lication E [nodict]head type is not ftyp.
05-27 16:46:22.152 12178-12424 C02B05/ImageSource com.examp...lication E [nodict][ImageSource]check mismatched format :image/heif.
05-27 16:46:22.152 12178-12424 C02B05/ImageSource com.examp...lication E [nodict][ImageSource]check mismatched format :image/jpeg.
05-27 16:46:22.152 12178-12424 C02B05/ImageSource com.examp...lication E [nodict][ImageSource]check mismatched format :image/png.
05-27 16:46:22.152 12178-12424 C02B05/ImageSource com.examp...lication E [nodict][ImageSource]check mismatched format :image/svg+xml.
05-27 16:46:22.152 12178-12424 C02B05/ImageSource com.examp...lication E [nodict][ImageSource]check mismatched format :image/vnd.wap.wbmp.
05-27 16:46:22.152 12178-12424 C02B05/ImageSource com.examp...lication E [nodict][ImageSource]check mismatched format :image/webp.
05-27 16:46:22.155 12178-12424 C02B03/RawDecoder com.examp...lication E [nodict]DoDecodeHeader header decode fail, ret=[62980103]
05-27 16:46:22.155 12178-12424 C02B03/RawDecoder com.examp...lication E [nodict][GetImageSize]decode header error on get image size, ret:62980103.
05-27 16:46:22.155 12178-12424 C02B05/ImageSource com.examp...lication E [nodict][ImageSource]decode the image info fail.
05-27 16:46:22.155 12178-12424 C02B05/ImageSource com.examp...lication E [nodict][ImageSource]image info decode fail, ret:62980116.
05-27 16:46:22.155 12178-12424 C02B05/ImageSource com.examp...lication E [nodict][ImageSource]get valid image status fail on create pixel map, ret:62980116.
05-27 16:46:22.155 12178-12424 C02B05/ImageSourceNapi com.examp...lication E [nodict]Create PixelMap error
从代码日志中查看错误码:62980103,可能出现问题的地方是:解码过程中异常退出。图片格式不支持。未读取到图片。参考关于相机能读取到每一帧的demo