HarmonyOS 如何设置拍照后不存图库?

调用系统相机拍摄照片后,存储在我们自定义的路径,但是图库中还存在照片原图,如何设置拍照后不存图库?

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

参考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 IndexPage{
  build(){
    Column(){
      Button('拉起后置摄像头').onClick(()=>{
        demo()
      })
    }
  }
}

照片不存相册可参照:

const context2 = getContext(this);
const imageSourceApi: image.ImageSource = image.createImageSource(this.combinePath);
let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 };
const filePath: string = context2.filesDir + "/image_source.jpg";
let file2 = fs.openSync(filePath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE);
const imagePackerApi: image.ImagePacker = image.createImagePacker();
imagePackerApi.packToFile(imageSourceApi, file2.fd, packOpts, (err: BusinessError) => {
  if (err) {
    console.error(`Failed to pack the image to file.code ${err.code},message is ${err.message}`);
  } else {
    console.info('Succeeded in packing the image to file.');
  }
})
分享
微博
QQ
微信
回复
2天前
相关问题
HarmonyOS 录像图库里找不到视频
53浏览 • 1回复 待解决
如何获取拍照的图片地址
1994浏览 • 1回复 待解决
HarmonyOS拍照调用openSync方法报错
645浏览 • 1回复 待解决
HarmonyOS 拍照的图片加水印
35浏览 • 1回复 待解决
HarmonyOS 拍照的图片转base64
10浏览 • 1回复 待解决
HarmonyOS 自定义相机拍照数据展示
818浏览 • 1回复 待解决
js相机组件拍照自动保存吗
4198浏览 • 1回复 待解决
关于如何使用相机拍照模块拍照问题
1787浏览 • 0回复 待解决
HarmonyOS web如何拉起图库选择器
48浏览 • 1回复 待解决