HarmonyOS 拍照picker控件好像传saveUrl好像无法正常存储

let pathUrl = ''
try {
  let pickerProfile: picker.PickerProfile = {
    cameraPosition: camera.CameraPosition.CAMERA_POSITION_BACK,
    saveUri: "/data/storage/el2/base/haps/phone/cache/compressUploadImg/1722246248971pictures.jpg"
  };
  let pickerResult: picker.PickerResult = await picker.pick(getContext(),
    [picker.PickerMediaType.PHOTO], pickerProfile);
  if (pickerResult.resultCode == 0) {
    pathUrl = pickerResult.resultUri;
  }
} catch (e) {
  console.error($r("app.string.take_photo_err") + JSON.stringify(e));
}
return pathUrl;
HarmonyOS
2天前
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
shlp

参考下面示例,了解路径参数的格式:

import {cameraPicker as picker,camera} from '@kit.CameraKit'
import common from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import {fileIo as fs ,fileUri} from '@kit.CoreFileKit'
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 avplayer错误码好像不对
41浏览 • 1回复 待解决
HarmonyOS picker组件如何隐藏拍照按钮
44浏览 • 1回复 待解决
好像不自带)
5374浏览 • 1回复 待解决
HarmonyOS 拍照无法确认返回
39浏览 • 1回复 待解决
HarmonyOS 地图无法正常加载
45浏览 • 1回复 待解决
我试了试好像不能展示?
126浏览 • 1回复 待解决
HarmonyOS WebView无法正常渲染
87浏览 • 1回复 待解决
HarmonyOS url 无法+号
114浏览 • 1回复 待解决
HarmonyOS APP无法打开相机拍照
466浏览 • 1回复 待解决
地图组件无法正常展示
520浏览 • 1回复 待解决
HarmonyOS preferences无法持久化存储
54浏览 • 1回复 待解决