harmony 鸿蒙@ohos.multimedia.cameraPicker (Camera Picker)

  • 2025-06-12
  • 浏览 (4)

@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

Name Type Mandatory Description
context Context Yes Application context.
mediaTypes Array<PickerMediaType> Yes Media type.
pickerProfile PickerProfile Yes Profile of the camera picker.

Return value

Type Description
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

Name Value Description
PHOTO photo Photo mode.
VIDEO video Video 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

Name Type Mandatory Description
cameraPosition camera.CameraPosition Yes Camera position.
saveUri string No URI for saving the configuration information. For details about the default value, see File URI.
videoDuration number No Maximum 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

Name Type Mandatory Description
resultCode number Yes Result code. The value 0 means that the processing is successful, and -1 means that the processing fails.
resultUri string Yes URI 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.
mediaType PickerMediaType Yes Media 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

0  赞