HarmonyOS 拍下照片传输到不同页面无法显示

scanCamera_page页面拉起相机拍完照后,跳转到imageHandle_demopage这个图片处理页面,router带过去的参数urlParams在处理页面无法显示,项目在真机上运行时,拍完照后出现闪退,也没有跳转到imageHandle_demopage页面。

HarmonyOS
1天前
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
aquaa

应该是没有权限导致的,参考以下,申请权限。

aboutToAppear(): void {
  let permissions: Array<Permissions> = [
  'ohos.permission.CAMERA',
  'ohos.permission.WRITE_MEDIA',
  'ohos.permission.READ_MEDIA',
  'ohos.permission.MEDIA_LOCATION',
  ];
  let atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager();
  // requestPermissionsFromUser会判断权限的授权状态来决定是否唤起弹窗
  atManager.requestPermissionsFromUser(this.context, permissions).then((data: PermissionRequestResult) => {
  let grantStatus: Array<number> = data.authResults;
  let length: number = grantStatus.length;
  for (let i = 0; i < length; i++) {
  if (grantStatus[i] != 0) {
  // 用户拒绝授权,提示用户必须授权才能访问当前页面的功能,并引导用户到系统设置中打开相应的权限
  return;
}
}
console.info(`${TAG} Success to request permissions from user. authResults is ${grantStatus}.`);
}).catch((err: BusinessError) => {
  console.error(`${TAG} Failed to request permissions from user. Code is ${err.code}, message is ${err.message}`);
})
}

图片无法显示的问题,可以查看获取的pixelMap是否有值,报错和根据uris获取pixelMap参考以下:

photoSelectOptions.MIMEType = photoAccessHelper.PhotoViewMIMETypes.IMAGE_TYPE; // 过滤选择媒体文件类型为VIDEO
photoSelectOptions.maxSelectNumber = 1; // 选择媒体文件的最大数目
photoSelectOptions.isSearchSupported = true
photoSelectOptions.isEditSupported = true
let uris: Array<string> = [];
const photoViewPicker = new photoAccessHelper.PhotoViewPicker();
photoViewPicker.select(photoSelectOptions).then((photoSelectResult: photoAccessHelper.PhotoSelectResult) => {
  uris = photoSelectResult.photoUris;
  let file = fs.openSync(uris[0], fs.OpenMode.READ_ONLY);
  console.info('file fd:' + file.fd);
  const imageSource: image.ImageSource = image.createImageSource(file.fd);
  let decodingOptions: image.DecodingOptions = {
    editable: true,
    desiredPixelFormat: 3,
  }
  this.pixelMap = await imageSource.createPixelMap(decodingOptions);
}).catch((err: BusinessError) => {
  console.error(`Invoke photoViewPicker.select failed, code is ${err.code}, message is ${err.message}`);
})

按照以上代码,创建photoViewPicker使用:

const photoViewPicker = new photoAccessHelper.PhotoViewPicker();
分享
微博
QQ
微信
回复
1天前
相关问题
HarmonyOS webview加载页面无法显示
721浏览 • 1回复 待解决
HarmonyOS 列表多选页面无法刷新
34浏览 • 1回复 待解决
HarmonyOS hap跳hsp页面无法跳转
46浏览 • 1回复 待解决
HarmonyOS scroll嵌套list页面无法滑动
44浏览 • 1回复 待解决
HarmonyOS Har静态包内部页面无法跳转
537浏览 • 1回复 待解决
ForEach数组数据无法传输
5293浏览 • 1回复 待解决
鸿蒙webview 上面无法放其它组件。
5820浏览 • 3回复 待解决