• 鸿蒙开发接口媒体:【@ohos.multimedia.camera (相机管理)】


     相机管理

    说明:
    开发前请熟悉鸿蒙开发指导文档gitee.com/li-shizhen-skin/harmony-os/blob/master/README.md点击或者复制转到。
    本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。

    导入模块

    import camera from '@ohos.multimedia.camera';

    camera.getCameraManager

    getCameraManager(context: Context, callback: AsyncCallback): void

    获取相机管理器实例,通过注册回调函数获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    contextContext应用上下文。
    callbackAsyncCallback<[CameraManager]>回调函数,用于获取相机管理器实例。

    示例:

    1. camera.getCameraManager(context, (err, cameraManager) => {
    2. if (err) {
    3. console.error('Failed to get the CameraManager instance ${err.message}');
    4. return;
    5. }
    6. console.log('Callback returned with the CameraManager instance');
    7. });

    camera.getCameraManager

    getCameraManager(context: Context): Promise

    获取相机管理器实例,通过Promise获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    contextContext应用上下文。

    返回值:

    类型说明
    Promise<[CameraManager]>使用Promise的方式获取一个相机管理器实例。

    示例:

    1. camera.getCameraManager(context).then((cameraManager) => {
    2. console.log('Promise returned with the CameraManager instance.');
    3. })

    CameraStatus

    枚举,相机状态。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    名称说明
    CAMERA_STATUS_APPEAR0相机存在。
    CAMERA_STATUS_DISAPPEAR1相机不存在。
    CAMERA_STATUS_AVAILABLE2相机就绪。
    CAMERA_STATUS_UNAVAILABLE3相机未就绪。

    CameraPosition

    枚举,相机方向。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    名称说明
    CAMERA_POSITION_UNSPECIFIED0未指定方向相机。
    CAMERA_POSITION_BACK1后置相机。
    CAMERA_POSITION_FRONT2前置相机。

    CameraType

    枚举,相机类型。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    名称说明
    CAMERA_TYPE_UNSPECIFIED0未指定相机类型。
    CAMERA_TYPE_WIDE_ANGLE1广角相机。
    CAMERA_TYPE_ULTRA_WIDE2超级广角相机。
    CAMERA_TYPE_TELEPHOTO3长焦相机。
    CAMERA_TYPE_TRUE_DEPTH4深度相机。

    ConnectionType

    枚举,相机连接类型。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    名称说明
    CAMERA_CONNECTION_BUILT_IN0内置相机。
    CAMERA_CONNECTION_USB_PLUGIN1外置USB相机。
    CAMERA_CONNECTION_REMOTE2分布式相机。

    Size

    用于表示相机预览、照片、视频支持的尺寸大小。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    名称类型可读可写说明
    heightstring图像的高度。
    widthnumber图像的宽度。

    CameraManager

    相机管理器类,使用前需要通过getCameraManager获取相机管理实例。

    getCameras

    getCameras(callback: AsyncCallback<Array>): void

    异步获取设备支持的相机列表,通过注册回调函数获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    callbackAsyncCallback>使用callback方式获取支持的相机列表。

    示例:

    1. cameraManager.getCameras((err, cameras) => {
    2. if (err) {
    3. console.error('Failed to get the cameras. ${err.message}');
    4. return;
    5. }
    6. console.log('Callback returned with an array of supported cameras: ' + cameras.length);
    7. })

    getCameras

    getCameras(): Promise>

    异步获取设备支持的相机列表,通过Promise获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    返回值:

    类型说明
    Promise>使用promise获取支持相机列表。

    示例:

    1. cameraManager.getCameras().then((cameraArray) => {
    2. console.log('Promise returned with an array of supported cameras: ' + cameraArray.length);
    3. })

    createCameraInput

    createCameraInput(cameraId: string, callback: AsyncCallback): void

    使用相机ID异步创建CameraInput实例,通过注册回调函数获取结果。

    需要权限:  ohos.permission.CAMERA

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    cameraIdstring指定相机ID。
    callbackAsyncCallback<[CameraInput]>回调函数,用于获取CameraInput实例。

    示例:

    1. cameraManager.createCameraInput(cameraId, (err, cameraInput) => {
    2. if (err) {
    3. console.error('Failed to create the CameraInput instance. ${err.message}');
    4. return;
    5. }
    6. console.log('Callback returned with the CameraInput instance.');
    7. })

    createCameraInput

    createCameraInput(cameraId: string): Promise

    使用相机ID异步创建CameraInput实例,通过Promise获取结果。

    需要权限:  ohos.permission.CAMERA

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    cameraIdstring指定相机ID。

    返回值:

    类型说明
    Promise<[CameraInput]>使用Promise的方式获取CameraInput的实例。

    示例:

    1. cameraManager.createCameraInput(cameraId).then((cameraInput) => {
    2. console.log('Promise returned with the CameraInput instance');
    3. })

    createCameraInput

    createCameraInput(position: CameraPosition, type: CameraType, callback: AsyncCallback): void

    使用相机位置和相机类型异步创建CameraInput实例,通过注册回调函数获取结果。

    需要权限:  ohos.permission.CAMERA

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    position[CameraPosition]相机位置。
    type[CameraType]相机类型。
    callbackAsyncCallback<[CameraInput]>回调函数,用于获取CameraInput实例。

    示例:

    1. cameraManager.createCameraInput(camera.CameraPosition.CAMERA_POSITION_BACK, camera.CameraType.CAMERA_TYPE_UNSPECIFIED, (err, cameraInput) => {
    2. if (err) {
    3. console.error('Failed to create the CameraInput instance. ${err.message}');
    4. return;
    5. }
    6. console.log('Callback returned with the CameraInput instance');
    7. })

    createCameraInput

    createCameraInput(position: CameraPosition, type: CameraType): Promise

    使用相机位置和相机类型异步创建CameraInput实例,通过Promise获取结果。

    需要权限:  ohos.permission.CAMERA

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    position[CameraPosition]相机位置。
    type[CameraType]相机类型。

    返回值:

    类型说明
    Promise<[CameraInput]>使用Promise的方式获取CameraInput的实例。

    示例:

    1. cameraManager.createCameraInput(camera.CameraPosition.CAMERA_POSITION_BACK, camera.CameraType.CAMERA_TYPE_UNSPECIFIED).then((cameraInput) => {
    2. console.log('Promise returned with the CameraInput instance.');
    3. })

    on('cameraStatus')

    on(type: 'cameraStatus', callback: AsyncCallback): void

    监听相机的状态变化,通过注册回调函数获取相机的状态变化。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    typestring监听事件,固定为'cameraStatus',即相机状态变化事件。
    callbackAsyncCallback<[CameraStatusInfo]>回调函数,用于获取相机状态变化信息。

    示例:

    1. cameraManager.on('cameraStatus', (err, cameraStatusInfo) => {
    2. if (err) {
    3. console.error('Failed to get cameraStatus callback. ${err.message}');
    4. return;
    5. }
    6. console.log('camera : ' + cameraStatusInfo.camera.cameraId);
    7. console.log('status: ' + cameraStatusInfo.status);
    8. })

    Camera

    调用[camera.getCameraManager]后,将返回Camera实例,包括相机ID、位置、类型、连接类型等相机相关的元数据。

    系统能力:  SystemCapability.Multimedia.Camera.Core。

    名称类型只读说明
    cameraIdstring相机ID。
    cameraPosition[CameraPosition]相机位置。
    cameraType[CameraType]相机类型。
    connectionType[ConnectionType]相机连接类型。

    示例:

    1. async function getCameraInfo("cameraId") {
    2. var cameraManager = await camera.getCameraManager();
    3. var cameras = await cameraManager.getCameras();
    4. var cameraObj = cameras[0];
    5. var cameraId = cameraObj.cameraId;
    6. var cameraPosition = cameraObj.cameraPosition;
    7. var cameraType = cameraObj.cameraType;
    8. var connectionType = cameraObj.connectionType;
    9. }

    CameraStatusInfo

    相机管理器回调返回的接口实例,表示相机状态信息。

    系统能力:  SystemCapability.Multimedia.Camera.Core。

    名称类型说明
    camera[Camera]相机信息。
    status[CameraStatus]相机状态。

    CameraInput

    相机输入类。在使用该类的方法前,需要先构建一个CameraInput实例。

    getCameraId

    getCameraId(callback: AsyncCallback): void

    异步获取该CameraInput实例的相机ID,通过注册回调函数获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    callbackAsyncCallback回调函数,用于获取相机ID。

    示例:

    1. cameraInput.getCameraId((err, cameraId) => {
    2. if (err) {
    3. console.error('Failed to get the camera ID. ${err.message}');
    4. return;
    5. }
    6. console.log('Callback returned with the camera ID: ' + cameraId);
    7. })

    getCameraId

    getCameraId(): Promise

    异步获取该CameraInput实例的相机ID,通过Promise获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    返回值:

    类型说明
    Promise使用Promise的方式获取相机ID。

    示例:

    1. cameraInput.getCameraId().then((cameraId) => {
    2. console.log('Promise returned with the camera ID:' + cameraId);
    3. })

    hasFlash

    hasFlash(callback: AsyncCallback): void

    判断设备是否支持闪光灯,通过注册回调函数获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    callbackAsyncCallback回调函数,返回true表示设备支持闪光灯。

    示例:

    1. cameraInput.hasFlash((err, status) => {
    2. if (err) {
    3. console.error('Failed to check whether the device has flash light. ${err.message}');
    4. return;
    5. }
    6. console.log('Callback returned with flash light support status: ' + status);
    7. })

    hasFlash

    hasFlash(): Promise

    判断设备是否支持闪光灯,通过Promise获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    返回值:

    类型说明
    Promise使用Promise的方式获取结果,返回true表示设备支持闪光灯。

    示例:

    1. cameraInput.hasFlash().then((status) => {
    2. console.log('Promise returned with the flash light support status:' + status);
    3. })

    isFlashModeSupported

    isFlashModeSupported(flashMode: FlashMode, callback: AsyncCallback): void

    判断设备是否支持指定闪光灯模式,通过注册回调函数获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    flashMode[FlashMode]指定闪光灯模式。
    callbackAsyncCallback回调函数,返回true表示支持该闪光灯模式。

    示例:

    1. cameraInput.isFlashModeSupported(camera.FlashMode.FLASH_MODE_AUTO, (err, status) => {
    2. if (err) {
    3. console.error('Failed to check whether the flash mode is supported. ${err.message}');
    4. return;
    5. }
    6. console.log('Callback returned with the flash mode support status: ' + status);
    7. })

    isFlashModeSupported

    isFlashModeSupported(flashMode: FlashMode): Promise

    判断设备是否支持指定闪光灯模式,通过Promise获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    flashMode[FlashMode]指定闪光灯模式。

    返回值:

    类型说明
    Promise使用Promise的方式获取结果,返回true表示设备支持该闪光灯模式。

    示例:

    1. cameraInput.isFlashModeSupported(camera.FlashMode.FLASH_MODE_AUTO).then((status) => {
    2. console.log('Promise returned with flash mode support status.' + status);
    3. })

    setFlashMode

    setFlashMode(flashMode: FlashMode, callback: AsyncCallback): void

    设置闪光灯模式,通过注册回调函数获取结果。

    进行设置之前,需要先检查:

    1. 设备是否支持闪光灯,可使用方法[hasFlash]。
    2. 设备是否支持指定的闪光灯模式,可使用方法[isFlashModeSupported]。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    flashMode[FlashMode]指定闪光灯模式。
    callbackAsyncCallback回调函数,用于获取结果。

    示例:

    1. cameraInput.setFlashMode(camera.FlashMode.FLASH_MODE_AUTO, (err) => {
    2. if (err) {
    3. console.error('Failed to set the flash mode ${err.message}');
    4. return;
    5. }
    6. console.log('Callback returned with the successful execution of setFlashMode.');
    7. })

    setFlashMode

    setFlashMode(flashMode: FlashMode): Promise

    设置闪光灯模式,通过Promise获取结果。

    进行设置之前,需要先检查:

    1. 设备是否支持闪光灯,可使用方法[hasFlash]。
    2. 设备是否支持指定的闪光灯模式。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    flashMode[FlashMode]指定闪光灯模式。

    返回值:

    类型说明
    Promise使用Promise的方式获取结果。

    示例:

    1. cameraInput.setFlashMode(camera.FlashMode.FLASH_MODE_AUTO).then(() => {
    2. console.log('Promise returned with the successful execution of setFlashMode.');
    3. })

    getFlashMode

    getFlashMode(callback: AsyncCallback): void

    获取当前设备的闪光灯模式,通过注册回调函数获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    callbackAsyncCallback<[FlashMode]>回调函数,用于获取当前设备的闪光灯模式。

    示例:

    1. cameraInput.getFlashMode((err, flashMode) => {
    2. if (err) {
    3. console.error('Failed to get the flash mode ${err.message}');
    4. return;
    5. }
    6. console.log('Callback returned with current flash mode: ' + flashMode);
    7. })

    getFlashMode

    getFlashMode(): Promise

    获取当前设备的闪光灯模式,通过Promise获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    返回值:

    类型说明
    Promise<[FlashMode]>使用Promise的方式获取当前的闪光灯模式。

    示例:

    1. cameraInput.getFlashMode().then((flashMode) => {
    2. console.log('Promise returned with current flash mode : ' + flashMode);
    3. })

    isFocusModeSupported

    isFocusModeSupported(afMode: FocusMode, callback: AsyncCallback): void

    判断设备是否支持指定的焦距模式,通过注册回调函数获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    afMode[FocusMode]指定的焦距模式。
    callbackAsyncCallback回调函数,返回true表示支持该焦距模式。

    示例:

    1. cameraInput.isFocusModeSupported(camera.FocusMode.FOCUS_MODE_AUTO, (err, status) => {
    2. if (err) {
    3. console.error('Failed to check whether the focus mode is supported. ${err.message}');
    4. return;
    5. }
    6. console.log('Callback returned with the focus mode support status: ' + status);
    7. })

    isFocusModeSupported

    isFocusModeSupported(afMode: FocusMode): Promise

    判断设备是否支持指定的焦距模式,通过Promise获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    afMode[FocusMode]指定的焦距模式。

    返回值:

    类型说明
    Promise使用Promise的方式获取结果,返回true表示设备支持该焦距模式。

    示例:

    1. cameraInput.isFocusModeSupported(camera.FocusMode.FOCUS_MODE_AUTO).then((status) => {
    2. console.log('Promise returned with focus mode support status.' + status);
    3. })

    setFocusMode

    setFocusMode(afMode: FocusMode, callback: AsyncCallback): void

    设置焦距模式,通过注册回调函数获取结果。

    进行设置之前,需要先检查设备是否支持指定的焦距模式。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    afMode[FocusMode]指定的焦距模式。
    callbackAsyncCallback回调函数,用于获取结果。

    示例:

    1. cameraInput.setFocusMode(camera.FocusMode.FOCUS_MODE_AUTO, (err) => {
    2. if (err) {
    3. console.error('Failed to set the focus mode ${err.message}');
    4. return;
    5. }
    6. console.log('Callback returned with the successful execution of setFocusMode.');
    7. })

    setFocusMode

    setFocusMode(afMode: FocusMode): Promise

    设置焦距模式,通过Promise获取结果。

    进行设置之前,需要先检查设备是否支持指定的焦距模式,可使用方法[isFocusModeSupported]。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    afMode[FocusMode]指定的焦距模式。

    返回值:

    类型说明
    Promise使用Promise的方式获取结果。

    示例:

    1. cameraInput.setFocusMode(camera.FocusMode.FOCUS_MODE_AUTO).then(() => {
    2. console.log('Promise returned with the successful execution of setFocusMode.');
    3. })

    getFocusMode

    getFocusMode(callback: AsyncCallback): void

    获取当前设备的焦距模式,通过注册回调函数获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    callbackAsyncCallback<[FocusMode]>回调函数,用于获取当前设备的焦距模式。

    示例:

    1. cameraInput.getFocusMode((err, afMode) => {
    2. if (err) {
    3. console.error('Failed to get the focus mode ${err.message}');
    4. return;
    5. }
    6. console.log('Callback returned with current focus mode: ' + afMode);
    7. })

    getFocusMode

    getFocusMode(): Promise

    获取当前设备的焦距模式,通过Promise获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    返回值:

    类型说明
    Promise使用Promise的方式获取当前的焦距模式。

    示例:

    1. cameraInput.getFocusMode().then((afMode) => {
    2. console.log('Promise returned with current focus mode : ' + afMode);
    3. })

    getZoomRatioRange

    getZoomRatioRange(callback: AsyncCallback>): void

    获取可变焦距比范围,通过注册回调函数获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    callbackAsyncCallback>回调函数,用于获取结果。

    示例:

    1. cameraInput.getZoomRatioRange((err, zoomRatioRange) => {
    2. if (err) {
    3. console.error('Failed to get the zoom ratio range. ${err.message}');
    4. return;
    5. }
    6. console.log('Callback returned with zoom ratio range: ' + zoomRatioRange.length);
    7. })

    getZoomRatioRange

    getZoomRatioRange(): Promise>

    获取可变焦距比范围,通过Promise获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    返回值:

    类型说明
    Promise>使用Promise的方式获取当前的可变焦距比范围。

    示例:

    1. cameraInput.getZoomRatioRange().then((zoomRatioRange) => {
    2. console.log('Promise returned with zoom ratio range: ' + zoomRatioRange.length);
    3. })

    setZoomRatio

    setZoomRatio(zoomRatio: number, callback: AsyncCallback): void

    设置可变焦距比,通过注册回调函数获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    zoomRationumber可变焦距比。
    callbackAsyncCallback回调函数,用于获取结果。

    示例:

    1. cameraInput.setZoomRatio(1, (err) => {
    2. if (err) {
    3. console.error('Failed to set the zoom ratio value ${err.message}');
    4. return;
    5. }
    6. console.log('Callback returned with the successful execution of setZoomRatio.');
    7. })

    setZoomRatio

    setZoomRatio(zoomRatio: number): Promise

    设置可变焦距比,通过Promise获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    zoomRationumber可变焦距比。

    返回值:

    类型说明
    Promise使用Promise的方式获取结果。

    示例:

    1. cameraInput.setZoomRatio(1).then(() => {
    2. console.log('Promise returned with the successful execution of setZoomRatio.');
    3. })

    getZoomRatio

    getZoomRatio(callback: AsyncCallback): void

    获取当前的可变焦距比,通过注册回调函数获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    callbackAsyncCallback回调函数,用于获取结果。

    示例:

    1. cameraInput.getZoomRatio((err, zoomRatio) => {
    2. if (err) {
    3. console.error('Failed to get the zoom ratio ${err.message}');
    4. return;
    5. }
    6. console.log('Callback returned with current zoom ratio: ' + zoomRatio);
    7. })

    getZoomRatio

    getZoomRatio(): Promise

    获取当前的可变焦距比,通过Promise获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    返回值:

    类型说明
    Promise使用Promise的方式获取结果。

    示例:

    1. cameraInput.getZoomRatio().then((zoomRatio) => {
    2. console.log('Promise returned with current zoom ratio : ' + zoomRatio);
    3. })

    release

    release(callback: AsyncCallback): void

    释放相机实例,通过注册回调函数获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    callbackAsyncCallback回调函数,用于获取结果。

    示例:

    1. cameraInput.release((err) => {
    2. if (err) {
    3. console.error('Failed to release the CameraInput instance ${err.message}');
    4. return;
    5. }
    6. console.log('Callback invoked to indicate that the CameraInput instance is released successfully.');
    7. });

    release

    release(): Promise

    释放相机实例,通过Promise获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    返回值:

    类型说明
    Promise使用Promise的方式获取结果。

    示例:

    1. cameraInput.release().then(() => {
    2. console.log('Promise returned to indicate that the CameraInput instance is released successfully.');
    3. })

    on('focusStateChange')

    on(type: 'focusStateChange', callback: AsyncCallback): void

    监听焦距的状态变化,通过注册回调函数获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    typestring监听事件,固定为'focusStateChange',即焦距状态变化事件。
    callbackAsyncCallback<[FocusState]>回调函数,用于获取焦距状态。

    示例:

    1. cameraInput.on('focusStateChange', (focusState) => {
    2. console.log('Focus state : ' + focusState);
    3. })

    on('error')

    on(type: 'error', callback: ErrorCallback): void

    监听CameraInput的错误事件,通过注册回调函数获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    typestring监听事件,固定为'error',即CameraInput错误事件。
    callbackErrorCallback<[CameraInputError]>回调函数,用于获取结果。

    示例:

    1. cameraInput.on('error', (cameraInputError) => {
    2. console.log('Camera input error code: ' + cameraInputError.code);
    3. })

    CameraInputErrorCode

    枚举,CameraInput的错误码。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    名称说明
    ERROR_UNKNOWN-1未知错误。

    CameraInputError

    CameraInput错误对象。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    名称类型说明
    code[CameraInputErrorCode]CameraInput中的错误码。

    FlashMode

    枚举,闪光灯模式。

    系统能力:  SystemCapability.Multimedia.Camera.Core。

    名称说明
    FLASH_MODE_CLOSE0闪光灯关闭。
    FLASH_MODE_OPEN1闪光灯开启。
    FLASH_MODE_AUTO2自动闪光灯。
    FLASH_MODE_ALWAYS_OPEN3闪光灯常亮。

    FocusMode

    枚举,焦距模式。

    系统能力:  SystemCapability.Multimedia.Camera.Core。

    名称说明
    FOCUS_MODE_MANUAL0手动变焦模式。
    FOCUS_MODE_CONTINUOUS_AUTO1连续自动变焦模式。
    FOCUS_MODE_AUTO2自动变焦模式。
    FOCUS_MODE_LOCKED3定焦模式。

    FocusState

    枚举,焦距状态。

    系统能力:  SystemCapability.Multimedia.Camera.Core。

    名称说明
    FOCUS_STATE_SCAN0扫描状态。
    FOCUS_STATE_FOCUSED1相机已对焦。
    FOCUS_STATE_UNFOCUSED2相机未对焦。

    camera.createCaptureSession

    createCaptureSession(context: Context, callback: AsyncCallback): void

    获取CaptureSession实例,通过注册回调函数获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    contextContext应用上下文。
    callbackAsyncCallback<[CaptureSession]>回调函数,用于获取CaptureSession实例。

    示例:

    1. camera.createCaptureSession((context), (err, captureSession) => {
    2. if (err) {
    3. console.error('Failed to create the CaptureSession instance. ${err.message}');
    4. return;
    5. }
    6. console.log('Callback returned with the CaptureSession instance.' + captureSession);
    7. });

    camera.createCaptureSession

    createCaptureSession(context: Context): Promise;

    获取CaptureSession实例,通过Promise获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    contextContext应用上下文。

    返回值:

    类型说明
    Promise<[CaptureSession]>使用Promise的方式获取CaptureSession实例。

    示例:

    1. camera.createCaptureSession(context).then((captureSession) => {
    2. console.log('Promise returned with the CaptureSession instance');
    3. })

    CaptureSession

    拍照会话类。

    beginConfig

    beginConfig(callback: AsyncCallback): void

    开始配置会话,通过注册回调函数获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    callbackAsyncCallback回调函数,用于获取结果。

    示例:

    1. captureSession.beginConfig((err) => {
    2. if (err) {
    3. console.error('Failed to start the configuration. ${err.message}');
    4. return;
    5. }
    6. console.log('Callback invoked to indicate the begin config success.');
    7. });

    beginConfig

    beginConfig(): Promise

    开始配置会话,通过Promise获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    返回值:

    类型说明
    Promise使用Promise的方式获取结果。

    示例:

    1. captureSession.beginConfig().then(() => {
    2. console.log('Promise returned to indicate the begin config success.');
    3. })

    commitConfig

    commitConfig(callback: AsyncCallback): void

    提交会话配置,通过注册回调函数获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    callbackAsyncCallback回调函数,用于获取结果。

    示例:

    1. captureSession.commitConfig((err) => {
    2. if (err) {
    3. console.error('Failed to commit the configuration. ${err.message}');
    4. return;
    5. }
    6. console.log('Callback invoked to indicate the commit config success.');
    7. });

    commitConfig

    commitConfig(): Promise

    提交会话配置,通过Promise获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    返回值:

    类型说明
    Promise使用Promise的方式获取结果。

    示例:

    1. captureSession.commitConfig().then(() => {
    2. console.log('Promise returned to indicate the commit config success.');
    3. })

    addInput

    addInput(cameraInput: CameraInput, callback: AsyncCallback): void

    在当前会话中,添加一个CameraInput实例,通过注册回调函数获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    cameraInput[CameraInput]需要添加的CameraInput实例。
    callbackAsyncCallback回调函数,用于获取结果。

    示例:

    1. captureSession.addInput(cameraInput, (err) => {
    2. if (err) {
    3. console.error('Failed to add the CameraInput instance. ${err.message}');
    4. return;
    5. }
    6. console.log('Callback invoked to indicate that the CameraInput instance is added.');
    7. });

    addInput

    addInput(cameraInput: CameraInput): Promise

    在当前会话中,添加一个CameraInput实例,通过Promise获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    cameraInput[CameraInput]需要添加的CameraInput实例。

    返回值:

    类型说明
    Promise使用Promise的方式获取结果。

    示例:

    1. captureSession.addInput(cameraInput).then(() => {
    2. console.log('Promise used to indicate that the CameraInput instance is added.');
    3. })

    addOutput

    addOutput(previewOutput: PreviewOutput, callback: AsyncCallback): void

    在当前会话中,添加一个PreviewOutput实例,通过注册回调函数获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    previewOutput[PreviewOutput]需要添加的PreviewOutput实例。
    callbackAsyncCallback回调函数,用于获取结果。

    示例:

    1. captureSession.addOutput(previewOutput, (err) => {
    2. if (err) {
    3. console.error('Failed to add the PreviewOutput instance ${err.message}');
    4. return;
    5. }
    6. console.log('Callback invoked to indicate that the PreviewOutput instance is added.');
    7. });

    addOutput

    addOutput(previewOutput: PreviewOutput): Promise

    在当前会话中,添加一个PreviewOutput实例,通过Promise获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    previewOutput[PreviewOutput]需要添加的PreviewOutput实例。

    返回值:

    类型说明
    Promise使用Promise的方式获取结果。

    示例:

    1. captureSession.addOutput(previewOutput).then(() => {
    2. console.log('Promise used to indicate that the PreviewOutput instance is added.');
    3. })

    addOutput

    addOutput(photoOutput: PhotoOutput, callback: AsyncCallback): void

    在当前会话中,添加一个PhotoOutput实例,通过注册回调函数获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    photoOutput[PhotoOutput]需要添加的PhotoOutput实例。
    callbackAsyncCallback回调函数,用于获取结果。

    示例:

    1. captureSession.addOutput(photoOutput, (err) => {
    2. if (err) {
    3. console.error('Failed to add the PhotoOutput instance ${err.message}');
    4. return;
    5. }
    6. console.log('Callback invoked to indicate that the PhotoOutput instance is added.');
    7. });

    addOutput

    addOutput(photoOutput: PhotoOutput): Promise

    在当前会话中,添加一个PhotoOutput实例,通过Promise获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    photoOutput[PhotoOutput]需要添加的PhotoOutput实例。

    返回值:

    类型说明
    Promise使用Promise的方式获取结果。

    示例:

    1. captureSession.addOutput(photoOutput).then(() => {
    2. console.log('Promise used to indicate that the PhotoOutput instance is added.');
    3. })

    addOutput

    addOutput(videoOutput: VideoOutput, callback: AsyncCallback): void

    在当前会话中,添加一个VideoOutput实例,通过注册回调函数获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    videoOutput[VideoOutput]需要添加的VideoOutput实例。
    callbackAsyncCallback回调函数,用于获取结果。

    示例:

    1. captureSession.addOutput(videoOutput, (err) => {
    2. if (err) {
    3. console.error('Failed to add the VideoOutput instance ${err.message}');
    4. return;
    5. }
    6. console.log('Callback invoked to indicate that the VideoOutput instance is added.');
    7. });

    addOutput

    addOutput(videoOutput: VideoOutput): Promise

    在当前会话中,添加一个VideoOutput实例,通过Promise获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    videoOutput[VideoOutput]需要添加的VideoOutput实例。

    返回值:

    类型说明
    Promise使用Promise的方式获取结果。

    示例:

    1. captureSession.addOutput(videoOutput).then(() => {
    2. console.log('Promise used to indicate that the VideoOutput instance is added.');
    3. })

    removeInput

    removeInput(cameraInput: CameraInput, callback: AsyncCallback): void

    在当前会话中,移除一个CameraInput实例,通过注册回调函数获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    cameraInput[CameraInput]需要移除的CameraInput实例。
    callbackAsyncCallback回调函数,用于获取结果。

    示例:

    1. captureSession.removeInput(cameraInput, (err) => {
    2. if (err) {
    3. console.error('Failed to remove the CameraInput instance. ${err.message}');
    4. return;
    5. }
    6. console.log('Callback invoked to indicate that the cameraInput instance is removed.');
    7. });

    removeInput

    removeInput(cameraInput: CameraInput): Promise

    在当前会话中,移除一个CameraInput实例,通过Promise获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    cameraInput[CameraInput]需要移除的CameraInput实例。

    返回值:

    类型说明
    Promise使用Promise的方式获取结果。

    示例:

    1. captureSession.removeInput(cameraInput).then(() => {
    2. console.log('Promise returned to indicate that the cameraInput instance is removed.');
    3. })

    removeOutput

    removeOutput(previewOutput: PreviewOutput, callback: AsyncCallback): void

    在当前会话中,移除一个PreviewOutput实例,通过注册回调函数获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    previewOutput[PreviewOutput]需要移除的PreviewOutput实例。
    callbackAsyncCallback回调函数,用于获取结果。

    示例:

    1. captureSession.removeOutput(previewOutput, (err) => {
    2. if (err) {
    3. console.error('Failed to remove the PreviewOutput instance. ${err.message}');
    4. return;
    5. }
    6. console.log('Callback invoked to indicate that the PreviewOutput instance is removed.');
    7. });

    removeOutput

    removeOutput(previewOutput: PreviewOutput): Promise

    在当前会话中,移除一个PreviewOutput实例,通过Promise获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    previewOutput[PreviewOutput]需要移除的PreviewOutput实例。

    返回值:

    类型说明
    Promise使用Promise的方式获取结果。

    示例:

    1. captureSession.removeOutput(previewOutput).then(() => {
    2. console.log('Promise returned to indicate that the PreviewOutput instance is removed.');
    3. })

    removeOutput

    removeOutput(photoOutput: PhotoOutput, callback: AsyncCallback): void

    在当前会话中,移除一个PhotoOutput实例,通过注册回调函数获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    photoOutput[PhotoOutput]需要移除的PhotoOutput实例。
    callbackAsyncCallback回调函数,用于获取结果。

    示例:

    1. captureSession.removeOutput(photoOutput, (err) => {
    2. if (err) {
    3. console.error('Failed to remove the PhotoOutput instance. ${err.message}');
    4. return;
    5. }
    6. console.log('Callback invoked to indicate that the PhotoOutput instance is removed.');
    7. });

    removeOutput

    removeOutput(photoOutput: PhotoOutput): Promise

    在当前会话中,移除一个PhotoOutput实例,通过Promise获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    photoOutput[PhotoOutput]需要移除的PhotoOutput实例。

    返回值:

    类型说明
    Promise使用Promise的方式获取结果。

    示例:

    1. captureSession.removeOutput(photoOutput).then(() => {
    2. console.log('Promise returned to indicate that the PhotoOutput instance is removed.');
    3. })

    removeOutput

    removeOutput(videoOutput: VideoOutput, callback: AsyncCallback): void

    在当前会话中,移除一个VideoOutput实例,通过注册回调函数获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    videoOutput[VideoOutput]需要移除的VideoOutput实例。
    callbackAsyncCallback回调函数,用于获取结果。

    示例:

    1. captureSession.removeOutput(videoOutput, (err) => {
    2. if (err) {
    3. console.error('Failed to remove the VideoOutput instance. ${err.message}');
    4. return;
    5. }
    6. console.log('Callback invoked to indicate that the VideoOutput instance is removed.');
    7. });

    removeOutput

    removeOutput(videoOutput: VideoOutput): Promise

    在当前会话中,移除一个VideoOutput实例,通过Promise获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    videoOutput[VideoOutput]需要移除的VideoOutput实例。

    返回值:

    类型说明
    Promise使用Promise的方式获取结果。

    示例:

    1. captureSession.removeOutput(videoOutput).then(() => {
    2. console.log('Promise returned to indicate that the VideoOutput instance is removed.');
    3. })

    start

    start(callback: AsyncCallback): void

    启动拍照会话,通过注册回调函数获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    callbackAsyncCallback回调函数,用于获取结果。

    示例:

    1. captureSession.start((err) => {
    2. if (err) {
    3. console.error('Failed to start the session ${err.message}');
    4. return;
    5. }
    6. console.log('Callback invoked to indicate the session start success.');
    7. });

    start

    start(): Promise

    启动拍照会话,通过Promise获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    返回值:

    类型说明
    Promise使用Promise的方式获取结果。

    示例:

    1. captureSession.start().then(() => {
    2. console.log('Promise returned to indicate the session start success.');
    3. })

    stop

    stop(callback: AsyncCallback): void

    停止拍照会话,通过注册回调函数获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    callbackAsyncCallback回调函数,用于获取结果。

    示例:

    1. captureSession.stop((err) => {
    2. if (err) {
    3. console.error('Failed to stop the session ${err.message}');
    4. return;
    5. }
    6. console.log('Callback invoked to indicate the session stop success.');
    7. });

    stop

    stop(): Promise

    停止拍照会话,通过Promise获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    返回值:

    类型说明
    Promise使用Promise的方式获取结果。

    示例:

    1. captureSession.stop().then(() => {
    2. console.log('Promise returned to indicate the session stop success.');
    3. })

    release

    release(callback: AsyncCallback): void

    释放CaptureSession实例,通过注册回调函数获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    callbackAsyncCallback回调函数,用于获取结果。

    示例:

    1. captureSession.release((err) => {
    2. if (err) {
    3. console.error('Failed to release the CaptureSession instance ${err.message}');
    4. return;
    5. }
    6. console.log('Callback invoked to indicate that the CaptureSession instance is released successfully.');
    7. });

    release

    release(): Promise

    释放CaptureSession实例,通过Promise获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    返回值:

    类型说明
    Promise使用Promise的方式获取结果。

    示例:

    1. captureSession.release().then(() => {
    2. console.log('Promise returned to indicate that the CaptureSession instance is released successfully.');
    3. })

    on('error')

    on(type: 'error', callback: ErrorCallback): void

    监听拍照会话的错误事件,通过注册回调函数获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    typestring监听事件,固定为'error',即拍照会话错误事件。
    callbackErrorCallback<[CaptureSessionError]>回调函数,用于获取错误信息。

    示例:

    1. captureSession.on('error', (captureSessionError) => {
    2. console.log('Capture session error code: ' + captureSessionError.code);
    3. })

    CaptureSessionErrorCode

    枚举,拍照会话的错误码。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    名称说明
    ERROR_UNKNOWN-1未知错误。

    CaptureSessionError

    拍照会话错误对象。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    名称类型说明
    code[CaptureSessionError]CaptureSession中的错误码。

    camera.createPreviewOutput

    createPreviewOutput(surfaceId: string, callback: AsyncCallback): void

    获取PreviewOutput实例,通过注册回调函数获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    surfaceIdstring从XComponent组件获取的Surface ID。
    callbackAsyncCallback<[PreviewOutput]>回调函数,用于获取PreviewOutput实例。

    示例:

    1. camera.createPreviewOutput(("surfaceId"), (err, previewOutput) => {
    2. if (err) {
    3. console.error('Failed to create the PreviewOutput instance. ${err.message}');
    4. return;
    5. }
    6. console.log('Callback returned with previewOutput instance');
    7. });

    camera.createPreviewOutput

    createPreviewOutput(surfaceId: string): Promise

    获取PreviewOutput实例,通过Promise获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    surfaceIdstring从XComponent组件获取的Surface ID。

    返回值:

    类型说明
    Promise<[PreviewOutput]>使用Promise的方式获取结果。

    示例:

    1. camera.createPreviewOutput("surfaceId").then((previewOutput) => {
    2. console.log('Promise returned with the PreviewOutput instance');
    3. })

    PreviewOutput

    预览输出类。

    release

    release(callback: AsyncCallback): void

    释放PreviewOutput实例,通过注册回调函数获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    callbackAsyncCallback回调函数,用于获取结果。

    示例:

    1. previewOutput.release((err) => {
    2. if (err) {
    3. console.error('Failed to release the PreviewOutput instance ${err.message}');
    4. return;
    5. }
    6. console.log('Callback invoked to indicate that the PreviewOutput instance is released successfully.');
    7. });

    release

    release(): Promise

    释放PreviewOutput实例,通过Promise获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    返回值:

    类型说明
    Promise使用Promise的方式获取结果。

    示例:

    1. previewOutput.release().then(() => {
    2. console.log('Promise returned to indicate that the PreviewOutput instance is released successfully.');
    3. })

    on('frameStart')

    on(type: 'frameStart', callback: AsyncCallback): void

    监听预览帧启动,通过注册回调函数获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    typestring监听事件,固定为'frameStart',即帧启动事件。
    callbackAsyncCallback回调函数,用于获取结果。

    示例:

    1. previewOutput.on('frameStart', () => {
    2. console.log('Preview frame started');
    3. })

    on('frameEnd')

    on(type: 'frameEnd', callback: AsyncCallback): void

    监听预览帧结束,通过注册回调函数获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    typestring监听事件,固定为'frameEnd',即帧结束事件。
    callbackAsyncCallback回调函数,用于获取结果。

    示例:

    1. previewOutput.on('frameEnd', () => {
    2. console.log('Preview frame ended');
    3. })

    on('error')

    on(type: 'error', callback: ErrorCallback): void

    监听预览输出的错误事件,通过注册回调函数获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    typestring监听事件,固定为'error',即预览输出错误事件。
    callbackErrorCallback<[PreviewOutputErrorCode]>回调函数,用于获取错误信息。

    示例:

    1. previewOutput.on('error', (previewOutputError) => {
    2. console.log('Preview output error code: ' + previewOutputError.code);
    3. })

    PreviewOutputErrorCode

    枚举,预览输出的错误码。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    名称说明
    ERROR_UNKNOWN-1未知错误。

    PreviewOutputError

    预览输出错误对象。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    名称类型说明
    code[PreviewOutputErrorCode]PreviewOutput中的错误码。

    camera.createPhotoOutput

    createPhotoOutput(surfaceId: string, callback: AsyncCallback): void

    获取PhotoOutput实例,通过注册回调函数获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    surfaceIdstring从[ImageReceiver]获取的Surface ID。
    callbackAsyncCallback<[PhotoOutput]>回调函数,用于获取PhotoOutput实例。

    示例:

    1. camera.createPhotoOutput(("surfaceId"), (err, photoOutput) => {
    2. if (err) {
    3. console.error('Failed to create the PhotoOutput instance. ${err.message}');
    4. return;
    5. }
    6. console.log('Callback returned with the PhotoOutput instance.');
    7. });

    camera.createPhotoOutput

    createPhotoOutput(surfaceId: string): Promise

    获取PhotoOutput实例,通过Promise获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    surfaceIdstring从[ImageReceiver]获取的Surface ID。

    返回值:

    类型说明
    Promise<[PhotoOutput]>使用Promise的方式获取PhotoOutput实例。

    示例:

    1. camera.createPhotoOutput("surfaceId").then((photoOutput) => {
    2. console.log('Promise returned with PhotoOutput instance');
    3. })

    ImageRotation

    枚举,图片旋转角度。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    名称说明
    ROTATION_00图片旋转0度。
    ROTATION_9090图片旋转90度。
    ROTATION_180180图片旋转180度。
    ROTATION_270270图片旋转270度。

    QualityLevel

    枚举,图片质量。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    名称说明
    QUALITY_LEVEL_HIGH0图片质量高。
    QUALITY_LEVEL_MEDIUM1图片质量中等。
    QUALITY_LEVEL_LOW2图片质量差。

    PhotoCaptureSetting

    拍摄照片的设置。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    名称类型必填说明
    quality[QualityLevel]图片质量。
    rotation[ImageRotation]图片旋转角度。

    PhotoOutput

    照片输出类。

    capture

    capture(callback: AsyncCallback): void

    拍照,通过注册回调函数获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    callbackAsyncCallback回调函数,用于获取结果。

    示例:

    1. photoOutput.capture((err) => {
    2. if (err) {
    3. console.error('Failed to capture the photo ${err.message}');
    4. return;
    5. }
    6. console.log('Callback invoked to indicate the photo capture request success.');
    7. });

    capture

    capture(setting: PhotoCaptureSetting, callback: AsyncCallback): void

    根据拍照设置拍照,通过注册回调函数获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    setting[PhotoCaptureSetting]拍照设置。
    callbackAsyncCallback回调函数,用于获取结果。

    示例:

    1. photoOutput.capture(settings, (err) => {
    2. if (err) {
    3. console.error('Failed to capture the photo ${err.message}');
    4. return;
    5. }
    6. console.log('Callback invoked to indicate the photo capture request success.');
    7. });

    capture

    capture(setting?: PhotoCaptureSetting): Promise

    根据拍照设置拍照,通过Promise获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    setting[PhotoCaptureSetting]拍照设置。

    返回值:

    类型说明
    Promise使用Promise的方式获取结果。

    示例:

    1. photoOutput.capture().then(() => {
    2. console.log('Promise returned to indicate that photo capture request success.');
    3. })

    release

    release(callback: AsyncCallback): void

    释放PhotoOutput实例,通过注册回调函数获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    callbackAsyncCallback回调函数,用于获取结果。

    示例:

    1. photoOutput.release((err) => {
    2. if (err) {
    3. console.error('Failed to release the PhotoOutput instance ${err.message}');
    4. return;
    5. }
    6. console.log('Callback invoked to indicate that the PhotoOutput instance is released successfully.');
    7. });

    release

    release(): Promise

    释放PhotoOutput实例,通过Promise获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    返回值:

    类型说明
    Promise使用Promise的方式获取结果。

    示例:

    1. photoOutput.release().then(() => {
    2. console.log('Promise returned to indicate that the PhotoOutput instance is released successfully.');
    3. })

    on('captureStart')

    on(type: 'captureStart', callback: AsyncCallback): void

    监听拍照启动,通过注册回调函数获取Capture ID。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    typestring监听事件,固定为'captureStart',即拍照启动事件。
    callbackAsyncCallback使用callback的方式获取Capture ID。

    示例:

    1. photoOutput.on('captureStart', (err, captureId) => {
    2. console.log('photo capture stated, captureId : ' + captureId);
    3. })

    on('frameShutter')

    on(type: 'frameShutter', callback: AsyncCallback): void

    监听快门,通过注册回调函数获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    typestring监听事件,固定为'frameShutter',即帧刷新事件。
    callbackAsyncCallback<[FrameShutterInfo]>回调函数,用于获取相关信息。

    示例:

    1. photoOutput.on('frameShutter', (frameShutterInfo) => {
    2. console.log('photo capture end, captureId : ' + frameShutterInfo.captureId);
    3. console.log('Timestamp for frame : ' + frameShutterInfo.timestamp);
    4. })

    on('captureEnd')

    on(type: 'captureEnd', callback: AsyncCallback): void

    监听拍照停止,通过注册回调函数获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    typestring监听事件,固定为'captureEnd',即拍照停止事件。
    callbackAsyncCallback<[CaptureEndInfo]>回调函数,用于获取相关信息。

    示例:

    1. photoOutput.on('captureEnd', (captureEndInfo) => {
    2. console.log('photo capture end, captureId : ' + captureEndInfo.captureId);
    3. console.log('frameCount : ' + captureEndInfo.frameCount);
    4. })

    on('error')

    on(type: 'error', callback: ErrorCallback): void

    监听拍照的错误事件,通过注册回调函数获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    typestring监听事件,固定为'error',即拍照错误事件。
    callbackErrorCallback<[PhotoOutputError]>回调函数,用于获取错误信息。

    示例:

    1. photoOutput.on('error', (photoOutputError) => {
    2. console.log('Photo output error code: ' + photoOutputError.code);
    3. })

    FrameShutterInfo

    快门事件信息。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    名称类型必填说明
    captureIdnumberCaptureId,本次拍摄动作的ID。
    timestampnumber时间戳。

    CaptureEndInfo

    拍照停止信息。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    名称类型必填说明
    captureIdnumberCaptureId,本次拍摄动作的ID。
    frameCountnumber帧计数。

    PhotoOutputErrorCode

    枚举,拍照输出的错误码。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    名称说明
    ERROR_UNKNOWN-1未知错误。

    PhotoOutputError

    拍照输出错误对象。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    名称类型说明
    code[PhotoOutputError]PhotoOutput中的错误码。

    camera.createVideoOutput

    createVideoOutput(surfaceId: string, callback: AsyncCallback): void

    获取VideoOutput实例,通过注册回调函数获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    surfaceIdstring从VideoRecorder获取的Surface ID。
    callbackAsyncCallback<[VideoOutput]>回调函数,用于获取VideoOutput实例。

    示例:

    1. camera.createVideoOutput(("surfaceId"), (err, videoOutput) => {
    2. if (err) {
    3. console.error('Failed to create the VideoOutput instance. ${err.message}');
    4. return;
    5. }
    6. console.log('Callback returned with the VideoOutput instance');
    7. });

    camera.createVideoOutput

    createVideoOutput(surfaceId: string): Promise

    获取VideoOutput实例,通过Promise获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    surfaceIdstring从VideoRecorder获取的Surface ID。

    返回值:

    类型说明
    Promise<[VideoOutput]>使用Promise的方式获取VideoOutput实例。

    示例:

    1. camera.createVideoOutput("surfaceId"
    2. ).then((videoOutput) => {
    3. console.log('Promise returned with the VideoOutput instance');
    4. })

    VideoOutput

    视频输出类。

    start

    start(callback: AsyncCallback): void

    开始拍摄视频,通过注册回调函数获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    callbackAsyncCallback回调函数,用于获取结果。

    示例:

    1. videoOutput.start((err) => {
    2. if (err) {
    3. console.error('Failed to start the video output ${err.message}');
    4. return;
    5. }
    6. console.log('Callback invoked to indicate the video output start success.');
    7. });

    start

    start(): Promise

    开始拍摄视频,通过Promise获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    返回值:

    类型说明
    Promise使用Promise的方式获取结果。

    示例:

    1. videoOutput.start().then(() => {
    2. console.log('Promise returned to indicate that start method execution success.');
    3. })

    stop

    stop(callback: AsyncCallback): void

    停止拍摄视频,通过注册回调函数获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    callbackAsyncCallback回调函数,用于获取结果。

    示例:

    1. videoOutput.stop((err) => {
    2. if (err) {
    3. console.error('Failed to stop the video output ${err.message}');
    4. return;
    5. }
    6. console.log('Callback invoked to indicate the video output stop success.');
    7. });

    stop

    stop(): Promise

    停止拍摄视频,通过Promise获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    返回值:

    类型说明
    Promise使用Promise的方式获取结果。

    示例:

    1. videoOutput.start().then(() => {
    2. console.log('Promise returned to indicate that stop method execution success.');
    3. })

    release

    release(callback: AsyncCallback): void

    释放VideoOutput实例,通过注册回调函数获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    callbackAsyncCallback回调函数,用于获取结果。

    示例:

    1. videoOutput.release((err) => {
    2. if (err) {
    3. console.error('Failed to release the VideoOutput instance ${err.message}');
    4. return;
    5. }
    6. console.log('Callback invoked to indicate that the VideoOutput instance is released successfully.');
    7. });

    release

    release(): Promise

    释放VideoOutput实例,通过Promise获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    返回值:

    类型说明
    Promise使用Promise的方式获取结果。

    示例:

    1. videoOutput.release().then(() => {
    2. console.log('Promise returned to indicate that the VideoOutput instance is released successfully.');
    3. })

    on('frameStart')

    on(type: 'frameStart', callback: AsyncCallback): void

    监听视频帧开启,通过注册回调函数获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    typestring监听事件,固定为'frameStart',即视频帧开启事件。
    callbackAsyncCallback回调函数,用于获取结果。

    示例:

    1. videoOutput.on('frameStart', () => {
    2. console.log('Video frame started');
    3. })

    on('frameEnd')

    on(type: 'frameEnd', callback: AsyncCallback): void

    监听视频帧结束,通过注册回调函数获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    typestring监听事件,固定为'frameEnd',即视频帧结束事件。
    callbackAsyncCallback回调函数,用于获取结果。

    示例:

    1. videoOutput.on('frameEnd', () => {
    2. console.log('Video frame ended');
    3. })

    on('error')

    on(type: 'error', callback: ErrorCallback): void

    监听视频输出的错误事件,通过注册回调函数获取结果。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    参数:

    名称类型必填说明
    typestring监听事件,固定为'error',即视频输出错误事件。
    callbackCallback<[VideoOutputError]>回调函数,用于获取错误信息。

    示例:

    1. videoOutput.on('error', (VideoOutputError) => {
    2. console.log('Video output error code: ' + VideoOutputError.code);
    3. })

    VideoOutputErrorCode

    枚举,视频输出的错误码。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    名称 HarmonyOS与OpenHarmony鸿蒙文档籽料:mau123789是v直接拿说明
    ERROR_UNKNOWN-1未知错误。

    搜狗高速浏览器截图20240326151450.png

    VideoOutputError

    视频输出错误对象。

    系统能力:  SystemCapability.Multimedia.Camera.Core

    名称类型说明
    code[PhotoOutputError]VideoOutput中的错误码。

    2024年,已有许多程序员把未来投向了鸿蒙开发,想必也在网上寻找过【鸿蒙学习资料】,然而搜索到的资料都是七零八碎比较杂乱,对于新入门的人来说增加了时间成本;为了避免大家在学习过程中浪费过多时间。对此录制了一套鸿蒙基础进阶视频(HarmonyOS NEXT开发入门&实战教学视频(200集+)发放给大家。↓↓↓点击即可

    《鸿蒙 (HarmonyOS NEXT)开发入门&实战教学视频》

    鸿蒙ArkTS语言》

    鸿蒙ArkUI声明式》

    《鸿蒙开发环境搭建》

    另外还根据鸿蒙官方发布的文档结合华为内部人员分享,经过反复修改整理得出的一整套鸿蒙(HarmonyOS NEXT)学习手册(共计2000页+)想要鸿蒙进阶文档的开发者有福了!

    内容包含了:(ArkTS、ArkUI、Stage模型、多端部署、分布式应用开发、音频、视频、WebGL、OpenHarmony多媒体技术、Napi组件、OpenHarmony内核、鸿蒙南向开发、鸿蒙项目实战)等技术知识点。帮助大家在学习鸿蒙路上少走弯路!点击即可↓↓↓

    《鸿蒙 (HarmonyOS NEXT)开发基础与实战手册》

  • 相关阅读:
    TPO69 01|Why Snakes Have Forked Tongues|阅读真题精读|10:40-11:40+15:30-16:57
    Spring 官方建议的在 Spring Boot 应用中如何做单元测试
    突破“三个九”!离子阱量子计算再创新高
    git 配置公钥
    【应用统计学】随机变量的概率分布,数学期望和方差及协方差
    ELK学习总结
    4G通信电子标签
    理解MySQL的日志 Redo、Undo
    R 语言 Hitters 数据分析
    【JAVA项目实战】【图书管理系统】书籍管理功能【Servlet】+【JSP】+【MySql】+【Ajax】
  • 原文地址:https://blog.csdn.net/2301_76813281/article/details/139335612