HarmonyOS Image组件显示PixelMap类型数据问题

相机拍照回调获取buffer(ArrayBuffer) 通过 image.createImageSource(buffer)获取imageSource信息 最后通过imageSource.createPixelMap获取到该照片的pixelMap 项目内通过

router.pushUrl({
  url:"pages/savePhoto",
  params:{
    photoHeight:px2vp(this.hValue),
    photoWidth:px2vp(this.wValue),
    pixelMapInfo:pixeMap,
    // uri:uri
  }
})

将该pixeMap信息作为参数传递 savephoto界面

Image(this.imgInfo)
       .size({width:this.photoWidth,height:this.photoHeight})
      .margin({top:5}) 

为什么不显示内容

HarmonyOS
2024-12-27 15:42:03
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
aquaa

经测试相机输出 buffer 无法转为正常 pixelmap 格式,建议将照片写入沙箱文件,通过使用路由传递沙箱文件路径,使用 image 组件加载图像

关键点:

1、写入文件

let file1 = fs.openSync(context.cacheDir + "/test11.jpg", fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE);
fs.writeSync(file1.fd, buffer);

2、文件地址转为 image 加载的 uri 路径

this.uri = fileUri.getUriFromPath(getContext(this).cacheDir + "/test11.jpg");

3、image 加载

Image(this.uri)
.height(640)
.width(480)
分享
微博
QQ
微信
回复
2024-12-27 19:22:32
相关问题
HarmonyOS image.PixelMap保存到 相册问题
442浏览 • 1回复 待解决
HarmonyOS image组件拖拽问题
635浏览 • 1回复 待解决
HarmonyOS Image组件网络图片不显示
876浏览 • 1回复 待解决
HarmonyOS Image组件无法显示网络图片
1683浏览 • 1回复 待解决
HarmonyOS image.PixelMap的拉伸变形
389浏览 • 1回复 待解决
HarmonyOS image组件图片加载性能数据
854浏览 • 1回复 待解决