pixelMap 和 imageSource 的数据类型如何保存到相册?

pixelMap 和 imageSource 的数据类型如何保存到相册?目前官网的例子是保存的 photoAsset 类型的数据

咨询场景描述:

将截图后的 pixelMap 和 imageSource 的数据类型保存到相册

阅读 395
1 个回答

您好,可以先将pixelMap进行格式转换,在保存到相册,可以参考以下接口链接https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-image-0000001821001457

pixelmap使用imagePacker.packing的方法转成arraybuffer,在进行编码
imageSource.createPixelMap(decodingOptions).then((pixelMap: PixelMap) => {
  this.pixelMap = pixelMap
  this.pixelMap.getImageInfo().then((info: image.ImageInfo) => {
console.info('info.width = ’ + info.size.width)
}).catch((err: BusinessError) =>{
    console.error("Faild " + err);
  })
  imagePackerApi.packing(pixelMap, packOpts).then( (data : ArrayBuffer) => {
    …
  }).catch((error : BusinessError) => {
console.error('Failed to pack the image. And the error is: ’ + error);
})
  pixelMap.release();
})
保存到相册示例代码如下:[https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/photoaccesshelper-useralbum-guidelines-0000001774120638](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/photoaccesshelper-useralbum-guidelines-0000001774120638)
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进