openharmony 鸿蒙 js-apis-cameraPicker

2025-06-12 浏览 (1)

@ohos.multimedia.cameraPicker (Camera Picker)

The cameraPicker module provides APIs for an application to use the system camera to take photos or record videos, depending on the media type specified by the application. The application must call these APIs within a UIAbility. Otherwise, the camera picker cannot be started.

NOTE

The initial APIs of this module are supported since API version 11. Newly added APIs will be marked with a superscript to indicate their earliest API version.

Modules to Import

import { cameraPicker as picker } from '@kit.CameraKit';

cameraPicker.pick

pick(context: Context, mediaTypes: Array<PickerMediaType>, pickerProfile: PickerProfile): Promise<PickerResult>

Starts the camera picker and enters the corresponding mode based on the media type. This API uses a promise to return the result.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.Multimedia.Camera.Core

Parameters

NameTypeMandatoryDescription
contextContextYesApplication context.
mediaTypesArray<PickerMediaType>YesMedia type.
pickerProfilePickerProfileYesProfile of the camera picker.

Return value

TypeDescription
Promise<PickerResult>Promise used to return the result, which is defined in PickerResult.

Example

import { cameraPicker as picker } from '@kit.CameraKit';
import { camera } from '@kit.CameraKit';
import { BusinessError } from '@kit.BasicServicesKit';

async function demo(context: Context) {
  try {
    let pickerProfile: picker.PickerProfile = {
      cameraPosition: camera.CameraPosition.CAMERA_POSITION_BACK
    };
    let pickerResult: picker.PickerResult = await picker.pick(context,
      [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}`);
  }
}

PickerMediaType

Enumerates the media types displayed in the camera picker.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.Multimedia.Camera.Core

NameValueDescription
PHOTOphotoPhoto mode.
VIDEOvideoVideo mode.

PickerProfile

Defines the configuration information about the camera picker.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.Multimedia.Camera.Core

NameTypeMandatoryDescription
cameraPositioncamera.CameraPositionYesCamera position.
saveUristringNoURI for saving the configuration information. For details about the default value, see File URI.
videoDurationnumberNoMaximum video duration, in seconds.

PickerResult

Defines the processing result of the camera picker.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.Multimedia.Camera.Core

NameTypeMandatoryDescription
resultCodenumberYesResult code. The value 0 means that the processing is successful, and -1 means that the processing fails.
resultUristringYesURI of the result. If saveUri is empty, resultUri is a public media path. If saveUri is not empty and the application has the write permission on the URI, the value of resultUri is the same as that of saveUri. If saveUri is not empty and the application does not have the write permission on the URI, resultUri cannot be obtained.
mediaTypePickerMediaTypeYesMedia type.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Camera Kit

harmony 鸿蒙Camera_CaptureEndInfo

harmony 鸿蒙Camera_CaptureStartInfo

harmony 鸿蒙Camera_ConcurrentInfo

harmony 鸿蒙Camera_Device

harmony 鸿蒙Camera_FrameRateRange

harmony 鸿蒙Camera_FrameShutterEndInfo

harmony 鸿蒙Camera_FrameShutterInfo

harmony 鸿蒙Camera_Location

harmony 鸿蒙Camera_MetadataObject

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/mAjQbU