HarmonyOS cameraPicker.PickerResult 设置 saveUri后拍照处理不成功

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

参考demo如下:

import picker from '@ohos.multimedia.cameraPicker'
import camera from '@ohos.multimedia.camera';
import common from '@ohos.app.ability.common';
import { BusinessError } from '@ohos.base';
import fileuri from '@ohos.file.fileuri';
import fs from '@ohos.file.fs';
let mContext = getContext(this) as common.Context;
class CameraPosition {
 cameraPosition : camera.CameraPosition
 saveUri :string
 constructor(cameraPosition : camera.CameraPosition,saveUri:string) {
  this.cameraPosition = cameraPosition
  this.saveUri = saveUri
 }
}
let pathDir = getContext().filesDir;
let filePath = pathDir + `/${new Date().getTime()}.jpg`
fs.createRandomAccessFileSync(filePath, fs.OpenMode.CREATE);
let uri = fileuri.getUriFromPath(filePath);
async function demo() {
 try {
  let pickerProfile = new CameraPosition(camera.CameraPosition.CAMERA_POSITION_BACK,uri)
  //前置摄像机传CAMERA_POSITION_FRONT,后置摄像机传CAMERA_POSITION_BACK,saveuri传想存到对应沙箱的uri
  let pickerResult: picker.PickerResult = await picker.pick(mContext, [picker.PickerMediaType.PHOTO, picker.PickerMediaType.VIDEO], pickerProfile);
  console.log("the pick pickerResult is:" + JSON.stringify(pickerResult));
 } catch (error) {
  let err = error as BusinessError;
  console.error(`the pick call failed. error code: ${err.code}`);
 }
}
@Entry
@Component struct Photopage{
 build(){
  Column(){
   Button('拉起后置摄像头').onClick(()=>{ demo() })
  }
 }
}
分享
微博
QQ
微信
回复
2天前
相关问题
HarmonyOS uris 使用不成功
442浏览 • 1回复 待解决
HarmonyOS 接口调用不成功
55浏览 • 1回复 待解决
鸿蒙手表后台持续定位不成功
130浏览 • 0回复 待解决
startAbility跳转不成功,错误码16000001
2084浏览 • 1回复 待解决
ohpm unpublish 对于带group的不成功
839浏览 • 1回复 待解决
HarmonyOS skills 功能使用不成功
380浏览 • 1回复 待解决
HarmonyOS ffmpeg静态库引用不成功
371浏览 • 1回复 待解决
HarmonyOS拍照saveUri的异常
407浏览 • 1回复 待解决
配置OHPM代理一直不成功
579浏览 • 1回复 待解决
数据库插入数据不成功怎么回事?
2475浏览 • 1回复 待解决
HarmonyOS拍照调用openSync方法报错
610浏览 • 1回复 待解决