在HarmonyOS NEXT开发中pixelMap转成ArrayBuffer?下面2个方法的输入都是pixelMap,最后都输出ArrayBuffer,但是输出的arraybuffer好像不一样。想问一下这两个有什么不同?使用场景分别是什么?
const readBuffer = new ArrayBuffer(pixelBytesNumber);
pixelMap.readPixelsToBuffer(readBuffer).then(() => {
console.info('Succeeded in reading image pixel data.');
}).catch((error : BusinessError) => {
console.error('Failed to read image pixel data. And the error is: ' + error);
})
import {BusinessError} from '@ohos.base'
imagePackerApi.packing(imageSource, packOpts).then( (data : ArrayBuffer) => {
}).catch((error : BusinessError) => {
console.error('Failed to pack the image. And the error is: ' + error);
})
参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-refere...
1:在HarmonyOS上图片的数据是用PixelMap类存储,可以把ArrayBuffer转换为PixelMap,设置到image
2:提供图片处理效果,包括通过属性创建PixelMap、读取图像像素数据、读取区域内的图片数据等。ImagePacker图片打包器类,用于图片压缩和打包。在调用ImagePacker的方法前,需要先通过createImagePacker构建一个ImagePacker实例调用socket.sppWrite 给蓝牙打印机发送需要打印的图片数据可以使用readPixelsToBuffer