1e41f4b71Sopenharmony_ci# @ohos.multimedia.camera (Camera Management) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciThe camera module provides a set of camera service APIs for you to easily develop a camera application. The application can access and operate the camera hardware to implement basic operations, such as preview, taking photos, and recording videos. It can also perform more operations, for example, controlling the flash and exposure time, and focusing or adjusting the focus. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **NOTE** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci## Modules to Import 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci```ts 12e41f4b71Sopenharmony_ciimport { camera } from '@kit.CameraKit'; 13e41f4b71Sopenharmony_ci``` 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci## camera.getCameraManager 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_cigetCameraManager(context: Context): CameraManager 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ciObtains a **CameraManager** instance. This API returns the result synchronously. 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ci**Parameters** 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 26e41f4b71Sopenharmony_ci| -------- | ----------------------------------------------- | ---- | ---------------------------- | 27e41f4b71Sopenharmony_ci| context | [Context](../apis-ability-kit/js-apis-inner-application-baseContext.md) | Yes | Application context. | 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ci**Return value** 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_ci| Type | Description | 32e41f4b71Sopenharmony_ci| ----------------------------------------------- | ---------------------------- | 33e41f4b71Sopenharmony_ci| [CameraManager](#cameramanager) | **CameraManager** instance obtained. | 34e41f4b71Sopenharmony_ci 35e41f4b71Sopenharmony_ci**Error codes** 36e41f4b71Sopenharmony_ci 37e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 38e41f4b71Sopenharmony_ci 39e41f4b71Sopenharmony_ci| ID | Error Message | 40e41f4b71Sopenharmony_ci| --------------- | --------------- | 41e41f4b71Sopenharmony_ci| 7400101 | Parameter missing or parameter type incorrect. | 42e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 43e41f4b71Sopenharmony_ci 44e41f4b71Sopenharmony_ci**Example** 45e41f4b71Sopenharmony_ci 46e41f4b71Sopenharmony_ci```ts 47e41f4b71Sopenharmony_ciimport { common } from '@kit.AbilityKit'; 48e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 49e41f4b71Sopenharmony_ci 50e41f4b71Sopenharmony_cifunction getCameraManager(context: common.BaseContext): camera.CameraManager | undefined { 51e41f4b71Sopenharmony_ci let cameraManager: camera.CameraManager | undefined = undefined; 52e41f4b71Sopenharmony_ci try { 53e41f4b71Sopenharmony_ci cameraManager = camera.getCameraManager(context); 54e41f4b71Sopenharmony_ci } catch (error) { 55e41f4b71Sopenharmony_ci let err = error as BusinessError; 56e41f4b71Sopenharmony_ci console.error(`The getCameraManager call failed. error code: ${err.code}`); 57e41f4b71Sopenharmony_ci } 58e41f4b71Sopenharmony_ci return cameraManager; 59e41f4b71Sopenharmony_ci} 60e41f4b71Sopenharmony_ci``` 61e41f4b71Sopenharmony_ci 62e41f4b71Sopenharmony_ci## CameraDevice 63e41f4b71Sopenharmony_ci 64e41f4b71Sopenharmony_ciDefines the camera device information. 65e41f4b71Sopenharmony_ci 66e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 67e41f4b71Sopenharmony_ci 68e41f4b71Sopenharmony_ci| Name | Type | Read-only| Optional| Description | 69e41f4b71Sopenharmony_ci| -------------- | --------------------------------- | ---- | ---- |---------- | 70e41f4b71Sopenharmony_ci| cameraId | string | Yes | No | Camera ID.| 71e41f4b71Sopenharmony_ci| cameraPosition | [CameraPosition](#cameraposition) | Yes | No | Camera position. | 72e41f4b71Sopenharmony_ci| cameraType | [CameraType](#cameratype) | Yes | No | Camera type. | 73e41f4b71Sopenharmony_ci| connectionType | [ConnectionType](#connectiontype) | Yes | No | Camera connection type.| 74e41f4b71Sopenharmony_ci| cameraOrientation<sup>12+</sup> | number | Yes | No | Installation angle of the lens, which does not change as the screen rotates. The value ranges from 0° to 360°.| 75e41f4b71Sopenharmony_ci 76e41f4b71Sopenharmony_ci## CameraPosition 77e41f4b71Sopenharmony_ci 78e41f4b71Sopenharmony_ciEnumerates the camera positions. 79e41f4b71Sopenharmony_ci 80e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 81e41f4b71Sopenharmony_ci 82e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 83e41f4b71Sopenharmony_ci 84e41f4b71Sopenharmony_ci| Name | Value | Description | 85e41f4b71Sopenharmony_ci| --------------------------- | ---- |-----------------------------------------------------------------| 86e41f4b71Sopenharmony_ci| CAMERA_POSITION_UNSPECIFIED | 0 | Unspecified position. | 87e41f4b71Sopenharmony_ci| CAMERA_POSITION_BACK | 1 | Rear camera. | 88e41f4b71Sopenharmony_ci| CAMERA_POSITION_FRONT | 2 | Front camera. | 89e41f4b71Sopenharmony_ci| CAMERA_POSITION_FOLD_INNER<sup>(deprecated)</sup> | 3 | Folded camera.<br>This API is supported since API version 11 and deprecated since API version 12.| 90e41f4b71Sopenharmony_ci 91e41f4b71Sopenharmony_ci## CameraType 92e41f4b71Sopenharmony_ci 93e41f4b71Sopenharmony_ciEnumerates the camera types. 94e41f4b71Sopenharmony_ci 95e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 96e41f4b71Sopenharmony_ci 97e41f4b71Sopenharmony_ci| Name | Value | Description | 98e41f4b71Sopenharmony_ci| ----------------------- | ---- | -------------- | 99e41f4b71Sopenharmony_ci| CAMERA_TYPE_DEFAULT | 0 | Unspecified camera type. | 100e41f4b71Sopenharmony_ci| CAMERA_TYPE_WIDE_ANGLE | 1 | Wide camera. | 101e41f4b71Sopenharmony_ci| CAMERA_TYPE_ULTRA_WIDE | 2 | Ultra wide camera. | 102e41f4b71Sopenharmony_ci| CAMERA_TYPE_TELEPHOTO | 3 | Telephoto camera. | 103e41f4b71Sopenharmony_ci| CAMERA_TYPE_TRUE_DEPTH | 4 | Camera with depth of field information.| 104e41f4b71Sopenharmony_ci 105e41f4b71Sopenharmony_ci## ConnectionType 106e41f4b71Sopenharmony_ci 107e41f4b71Sopenharmony_ciEnumerates the camera connection types. 108e41f4b71Sopenharmony_ci 109e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 110e41f4b71Sopenharmony_ci 111e41f4b71Sopenharmony_ci| Name | Value | Description | 112e41f4b71Sopenharmony_ci| ---------------------------- | ---- | ------------- | 113e41f4b71Sopenharmony_ci| CAMERA_CONNECTION_BUILT_IN | 0 | Built-in camera. | 114e41f4b71Sopenharmony_ci| CAMERA_CONNECTION_USB_PLUGIN | 1 | Camera connected using USB.| 115e41f4b71Sopenharmony_ci| CAMERA_CONNECTION_REMOTE | 2 | Remote camera.| 116e41f4b71Sopenharmony_ci 117e41f4b71Sopenharmony_ci## CameraStatus 118e41f4b71Sopenharmony_ci 119e41f4b71Sopenharmony_ciEnumerates the camera statuses. 120e41f4b71Sopenharmony_ci 121e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 122e41f4b71Sopenharmony_ci 123e41f4b71Sopenharmony_ci| Name | Value | Description | 124e41f4b71Sopenharmony_ci| ------------------------- | ---- | ------------ | 125e41f4b71Sopenharmony_ci| CAMERA_STATUS_APPEAR | 0 | A camera appears. | 126e41f4b71Sopenharmony_ci| CAMERA_STATUS_DISAPPEAR | 1 | The camera disappears. | 127e41f4b71Sopenharmony_ci| CAMERA_STATUS_AVAILABLE | 2 | The camera is available. | 128e41f4b71Sopenharmony_ci| CAMERA_STATUS_UNAVAILABLE | 3 | The camera is unavailable. | 129e41f4b71Sopenharmony_ci 130e41f4b71Sopenharmony_ci## FoldStatus<sup>12+</sup> 131e41f4b71Sopenharmony_ci 132e41f4b71Sopenharmony_ciEnumerates the folding statuses available for a fordable device. 133e41f4b71Sopenharmony_ci 134e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 135e41f4b71Sopenharmony_ci 136e41f4b71Sopenharmony_ci| Name | Value | Description | 137e41f4b71Sopenharmony_ci| ------------------------- | ---- | ------------ | 138e41f4b71Sopenharmony_ci| NON_FOLDABLE | 0 | The device is not foldable. | 139e41f4b71Sopenharmony_ci| EXPANDED | 1 | The device is fully unfolded.| 140e41f4b71Sopenharmony_ci| FOLDED | 2 | The device is folded. | 141e41f4b71Sopenharmony_ci 142e41f4b71Sopenharmony_ci## CameraStatusInfo 143e41f4b71Sopenharmony_ci 144e41f4b71Sopenharmony_ciDefines the camera status information. 145e41f4b71Sopenharmony_ci 146e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 147e41f4b71Sopenharmony_ci 148e41f4b71Sopenharmony_ci| Name | Type | Read-only | Optional | Description | 149e41f4b71Sopenharmony_ci| ------ | ----------------------------- | --------- |------------ | ---------- | 150e41f4b71Sopenharmony_ci| camera | [CameraDevice](#cameradevice) | No | No | Camera device.| 151e41f4b71Sopenharmony_ci| status | [CameraStatus](#camerastatus) | No | No | Camera status.| 152e41f4b71Sopenharmony_ci 153e41f4b71Sopenharmony_ci## FoldStatusInfo<sup>12+</sup> 154e41f4b71Sopenharmony_ci 155e41f4b71Sopenharmony_ciDescribes the folding status information about a foldable device. 156e41f4b71Sopenharmony_ci 157e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 158e41f4b71Sopenharmony_ci 159e41f4b71Sopenharmony_ci| Name | Type | Read-only | Optional | Description | 160e41f4b71Sopenharmony_ci| ------ | ----------------------------- | --------- |------------ | ---------- | 161e41f4b71Sopenharmony_ci| supportedCameras | [Array<CameraDevice\>](#cameradevice) | No | No | List of cameras supported in the current folding status.| 162e41f4b71Sopenharmony_ci| foldStatus | [FoldStatus](#foldstatus12) | No | No | Folding status.| 163e41f4b71Sopenharmony_ci 164e41f4b71Sopenharmony_ci## Profile 165e41f4b71Sopenharmony_ci 166e41f4b71Sopenharmony_ciDefines the camera profile. 167e41f4b71Sopenharmony_ci 168e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 169e41f4b71Sopenharmony_ci 170e41f4b71Sopenharmony_ci| Name | Type | Read-only| Optional| Description | 171e41f4b71Sopenharmony_ci| -------- | ----------------------------- |---- | ---- | ------------- | 172e41f4b71Sopenharmony_ci| format | [CameraFormat](#cameraformat) | Yes | No | Output format. | 173e41f4b71Sopenharmony_ci| size | [Size](#size) | Yes | No | Resolution.<br>The width and height of the camera resolution is set, not the actual width and height of an output image. | 174e41f4b71Sopenharmony_ci 175e41f4b71Sopenharmony_ci## FrameRateRange 176e41f4b71Sopenharmony_ci 177e41f4b71Sopenharmony_ciDefines the frame rate range. 178e41f4b71Sopenharmony_ci 179e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 180e41f4b71Sopenharmony_ci 181e41f4b71Sopenharmony_ci| Name | Type | Read-only| Optional| Description | 182e41f4b71Sopenharmony_ci| -------- | ----------------------------- |----- |---| -------------- | 183e41f4b71Sopenharmony_ci| min | number | Yes | No| Minimum frame rate. | 184e41f4b71Sopenharmony_ci| max | number | Yes | No| Maximum frame rate. | 185e41f4b71Sopenharmony_ci 186e41f4b71Sopenharmony_ci## VideoProfile 187e41f4b71Sopenharmony_ci 188e41f4b71Sopenharmony_ciDefines the video configuration information. It inherits from [Profile](#profile). 189e41f4b71Sopenharmony_ci 190e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 191e41f4b71Sopenharmony_ci 192e41f4b71Sopenharmony_ci| Name | Type | Read-only| Optional| Description | 193e41f4b71Sopenharmony_ci| ------------------------- | ----------------------------------------- | --- | ---- |----------- | 194e41f4b71Sopenharmony_ci| frameRateRange | [FrameRateRange](#frameraterange) | Yes | No | Frame rate range, in units of frames per second (FPS).| 195e41f4b71Sopenharmony_ci 196e41f4b71Sopenharmony_ci## CameraOutputCapability 197e41f4b71Sopenharmony_ci 198e41f4b71Sopenharmony_ciDefines the camera output capability. 199e41f4b71Sopenharmony_ci 200e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 201e41f4b71Sopenharmony_ci 202e41f4b71Sopenharmony_ci| Name | Type | Read-only| Optional| Description | 203e41f4b71Sopenharmony_ci| ----------------------------- | --------------------------------------------------- | ---- | ---- |-------------------| 204e41f4b71Sopenharmony_ci| previewProfiles | Array\<[Profile](#profile)\> | Yes | No| Supported preview profiles. | 205e41f4b71Sopenharmony_ci| photoProfiles | Array\<[Profile](#profile)\> | Yes | No| Supported photo profiles. | 206e41f4b71Sopenharmony_ci| videoProfiles | Array\<[VideoProfile](#videoprofile)\> | Yes | No| Supported video profiles. | 207e41f4b71Sopenharmony_ci| supportedMetadataObjectTypes | Array\<[MetadataObjectType](#metadataobjecttype)\> | Yes | No| Supported metadata object types.| 208e41f4b71Sopenharmony_ci 209e41f4b71Sopenharmony_ci## SceneMode<sup>11+</sup> 210e41f4b71Sopenharmony_ci 211e41f4b71Sopenharmony_ciEnumerates the camera scene modes. 212e41f4b71Sopenharmony_ci 213e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 214e41f4b71Sopenharmony_ci 215e41f4b71Sopenharmony_ci| Name | Value | Description | 216e41f4b71Sopenharmony_ci|----------------------------|---------|---------------------------------------------| 217e41f4b71Sopenharmony_ci| NORMAL_PHOTO | 1 | Normal photo mode. For details, see [PhotoSession](#photosession11). | 218e41f4b71Sopenharmony_ci| NORMAL_VIDEO | 2 | Normal record mode. For details, see [VideoSession](#videosession11). | 219e41f4b71Sopenharmony_ci| SECURE_PHOTO<sup>12+</sup> | 12 | Secure mode. For details, see [SecureSession](#securesession12).| 220e41f4b71Sopenharmony_ci 221e41f4b71Sopenharmony_ci## CameraErrorCode 222e41f4b71Sopenharmony_ci 223e41f4b71Sopenharmony_ciEnumerates the camera error codes, 224e41f4b71Sopenharmony_ci 225e41f4b71Sopenharmony_ciwhich are returned when an API call is incorrect or the **on()** API is used to listen for the error status. 226e41f4b71Sopenharmony_ci 227e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 228e41f4b71Sopenharmony_ci 229e41f4b71Sopenharmony_ci| Name | Value | Description | 230e41f4b71Sopenharmony_ci| ------------------------- | ---- | ------------ | 231e41f4b71Sopenharmony_ci| INVALID_ARGUMENT | 7400101 | A parameter is missing or the parameter type is incorrect. | 232e41f4b71Sopenharmony_ci| OPERATION_NOT_ALLOWED | 7400102 | The operation is not allowed. | 233e41f4b71Sopenharmony_ci| SESSION_NOT_CONFIG | 7400103 | The session is not configured. | 234e41f4b71Sopenharmony_ci| SESSION_NOT_RUNNING | 7400104 | The session is not running. | 235e41f4b71Sopenharmony_ci| SESSION_CONFIG_LOCKED | 7400105 | The session configuration is locked. | 236e41f4b71Sopenharmony_ci| DEVICE_SETTING_LOCKED | 7400106 | The device setting is locked. | 237e41f4b71Sopenharmony_ci| CONFLICT_CAMERA | 7400107 | The device is already started. | 238e41f4b71Sopenharmony_ci| DEVICE_DISABLED | 7400108 | The camera is disabled for security reasons. | 239e41f4b71Sopenharmony_ci| DEVICE_PREEMPTED | 7400109 | The camera is preempted. | 240e41f4b71Sopenharmony_ci| UNRESOLVED_CONFLICTS_WITH_CURRENT_CONFIGURATIONS<sup>12+</sup> | 7400110 | The configuration conflicts with the current configuration. | 241e41f4b71Sopenharmony_ci| SERVICE_FATAL_ERROR | 7400201 | An error occurs in the camera service. | 242e41f4b71Sopenharmony_ci 243e41f4b71Sopenharmony_ci## CameraManager 244e41f4b71Sopenharmony_ci 245e41f4b71Sopenharmony_ciImplements camera management. Before calling any API in **CameraManager**, you must use [getCameraManager](#cameragetcameramanager) to obtain a **CameraManager** instance. 246e41f4b71Sopenharmony_ci 247e41f4b71Sopenharmony_ci### getSupportedCameras 248e41f4b71Sopenharmony_ci 249e41f4b71Sopenharmony_cigetSupportedCameras(): Array\<CameraDevice\> 250e41f4b71Sopenharmony_ci 251e41f4b71Sopenharmony_ciObtains the supported camera devices. This API returns the result synchronously. 252e41f4b71Sopenharmony_ci 253e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 254e41f4b71Sopenharmony_ci 255e41f4b71Sopenharmony_ci**Return value** 256e41f4b71Sopenharmony_ci 257e41f4b71Sopenharmony_ci| Type | Description | 258e41f4b71Sopenharmony_ci| ----------------------------------------------- | ---------------------------- | 259e41f4b71Sopenharmony_ci| Array\<[CameraDevice](#cameradevice)> | Array of camera devices supported. | 260e41f4b71Sopenharmony_ci 261e41f4b71Sopenharmony_ci**Example** 262e41f4b71Sopenharmony_ci 263e41f4b71Sopenharmony_ci```ts 264e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 265e41f4b71Sopenharmony_ci 266e41f4b71Sopenharmony_cifunction getSupportedCameras(cameraManager: camera.CameraManager): Array<camera.CameraDevice> { 267e41f4b71Sopenharmony_ci let cameras: Array<camera.CameraDevice> = []; 268e41f4b71Sopenharmony_ci try { 269e41f4b71Sopenharmony_ci cameras = cameraManager.getSupportedCameras(); 270e41f4b71Sopenharmony_ci } catch (error) { 271e41f4b71Sopenharmony_ci let err = error as BusinessError; 272e41f4b71Sopenharmony_ci console.error(`The getSupportedCameras call failed. error code: ${err.code}`); 273e41f4b71Sopenharmony_ci } 274e41f4b71Sopenharmony_ci return cameras; 275e41f4b71Sopenharmony_ci} 276e41f4b71Sopenharmony_ci``` 277e41f4b71Sopenharmony_ci 278e41f4b71Sopenharmony_ci### getSupportedSceneModes<sup>11+</sup> 279e41f4b71Sopenharmony_ci 280e41f4b71Sopenharmony_cigetSupportedSceneModes(camera: CameraDevice): Array\<SceneMode\> 281e41f4b71Sopenharmony_ci 282e41f4b71Sopenharmony_ciObtains the scene modes supported by a camera device. This API returns the result synchronously. 283e41f4b71Sopenharmony_ci 284e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 285e41f4b71Sopenharmony_ci 286e41f4b71Sopenharmony_ci**Parameters** 287e41f4b71Sopenharmony_ci 288e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 289e41f4b71Sopenharmony_ci| ------------ |--------------------------------------------------------------- | -- | -------------------------- | 290e41f4b71Sopenharmony_ci| camera | [CameraDevice](#cameradevice) | Yes| **CameraDevice** instance, which is obtained through [getSupportedCameras](#getsupportedcameras). | 291e41f4b71Sopenharmony_ci 292e41f4b71Sopenharmony_ci**Return value** 293e41f4b71Sopenharmony_ci 294e41f4b71Sopenharmony_ci| Type | Description | 295e41f4b71Sopenharmony_ci| ----------------------------------------------- | ---------------------------- | 296e41f4b71Sopenharmony_ci| Array\<[SceneMode](#scenemode11)> | Array of scene modes supported. | 297e41f4b71Sopenharmony_ci 298e41f4b71Sopenharmony_ci**Example** 299e41f4b71Sopenharmony_ci 300e41f4b71Sopenharmony_ci```ts 301e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 302e41f4b71Sopenharmony_ci 303e41f4b71Sopenharmony_cifunction getSupportedSceneModes(cameraManager: camera.CameraManager, camera: camera.CameraDevice): Array<camera.SceneMode> { 304e41f4b71Sopenharmony_ci let modes: Array<camera.SceneMode> = []; 305e41f4b71Sopenharmony_ci try { 306e41f4b71Sopenharmony_ci modes = cameraManager.getSupportedSceneModes(camera); 307e41f4b71Sopenharmony_ci } catch (error) { 308e41f4b71Sopenharmony_ci let err = error as BusinessError; 309e41f4b71Sopenharmony_ci console.error(`The getSupportedSceneModes call failed. error code: ${err.code}`); 310e41f4b71Sopenharmony_ci } 311e41f4b71Sopenharmony_ci return modes; 312e41f4b71Sopenharmony_ci} 313e41f4b71Sopenharmony_ci``` 314e41f4b71Sopenharmony_ci 315e41f4b71Sopenharmony_ci### getSupportedOutputCapability<sup>(deprecated)</sup> 316e41f4b71Sopenharmony_ci 317e41f4b71Sopenharmony_cigetSupportedOutputCapability(camera: CameraDevice): CameraOutputCapability 318e41f4b71Sopenharmony_ci 319e41f4b71Sopenharmony_ciObtains the output capability supported by a camera device. This API returns the result synchronously. 320e41f4b71Sopenharmony_ci 321e41f4b71Sopenharmony_ci> **NOTE** 322e41f4b71Sopenharmony_ci> 323e41f4b71Sopenharmony_ci> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [getSupportedOutputCapability](#getsupportedoutputcapability11) instead. 324e41f4b71Sopenharmony_ci 325e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 326e41f4b71Sopenharmony_ci 327e41f4b71Sopenharmony_ci**Parameters** 328e41f4b71Sopenharmony_ci 329e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 330e41f4b71Sopenharmony_ci| ------------ |--------------------------------------------------------------- | -- | -------------------------- | 331e41f4b71Sopenharmony_ci| camera | [CameraDevice](#cameradevice) | Yes| **CameraDevice** instance, which is obtained through [getSupportedCameras](#getsupportedcameras). | 332e41f4b71Sopenharmony_ci 333e41f4b71Sopenharmony_ci**Return value** 334e41f4b71Sopenharmony_ci 335e41f4b71Sopenharmony_ci| Type | Description | 336e41f4b71Sopenharmony_ci| ----------------------------------------------- | ---------------------------- | 337e41f4b71Sopenharmony_ci| [CameraOutputCapability](#cameraoutputcapability) | Camera output capability obtained. | 338e41f4b71Sopenharmony_ci 339e41f4b71Sopenharmony_ci**Example** 340e41f4b71Sopenharmony_ci 341e41f4b71Sopenharmony_ci```ts 342e41f4b71Sopenharmony_cifunction getSupportedOutputCapability(camera: camera.CameraDevice, cameraManager: camera.CameraManager): camera.CameraOutputCapability { 343e41f4b71Sopenharmony_ci let cameraOutputCapability: camera.CameraOutputCapability = cameraManager.getSupportedOutputCapability(camera); 344e41f4b71Sopenharmony_ci return cameraOutputCapability; 345e41f4b71Sopenharmony_ci} 346e41f4b71Sopenharmony_ci``` 347e41f4b71Sopenharmony_ci 348e41f4b71Sopenharmony_ci### getSupportedOutputCapability<sup>11+</sup> 349e41f4b71Sopenharmony_ci 350e41f4b71Sopenharmony_cigetSupportedOutputCapability(camera: CameraDevice, mode: SceneMode): CameraOutputCapability 351e41f4b71Sopenharmony_ci 352e41f4b71Sopenharmony_ciObtains the output capability supported by a camera device in a given scene mode. This API returns the result synchronously. 353e41f4b71Sopenharmony_ci 354e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 355e41f4b71Sopenharmony_ci 356e41f4b71Sopenharmony_ci**Parameters** 357e41f4b71Sopenharmony_ci 358e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 359e41f4b71Sopenharmony_ci| ------------ |--------------------------------------------------------------- | -- | -------------------------- | 360e41f4b71Sopenharmony_ci| camera | [CameraDevice](#cameradevice) | Yes| **CameraDevice** instance, which is obtained through [getSupportedCameras](#getsupportedcameras). | 361e41f4b71Sopenharmony_ci| mode | [SceneMode](#scenemode11) | Yes| Scene mode, which is obtained through [getSupportedSceneModes](#getsupportedscenemodes11). | 362e41f4b71Sopenharmony_ci 363e41f4b71Sopenharmony_ci**Return value** 364e41f4b71Sopenharmony_ci 365e41f4b71Sopenharmony_ci| Type | Description | 366e41f4b71Sopenharmony_ci| ----------------------------------------------- | ---------------------------- | 367e41f4b71Sopenharmony_ci| [CameraOutputCapability](#cameraoutputcapability) | Camera output capability obtained. | 368e41f4b71Sopenharmony_ci 369e41f4b71Sopenharmony_ci**Example** 370e41f4b71Sopenharmony_ci 371e41f4b71Sopenharmony_ci```ts 372e41f4b71Sopenharmony_cifunction getSupportedOutputCapability(camera: camera.CameraDevice, cameraManager: camera.CameraManager, sceneMode: camera.SceneMode): camera.CameraOutputCapability { 373e41f4b71Sopenharmony_ci let cameraOutputCapability: camera.CameraOutputCapability = cameraManager.getSupportedOutputCapability(camera, sceneMode); 374e41f4b71Sopenharmony_ci return cameraOutputCapability; 375e41f4b71Sopenharmony_ci} 376e41f4b71Sopenharmony_ci``` 377e41f4b71Sopenharmony_ci 378e41f4b71Sopenharmony_ci### isCameraMuted 379e41f4b71Sopenharmony_ci 380e41f4b71Sopenharmony_ciisCameraMuted(): boolean 381e41f4b71Sopenharmony_ci 382e41f4b71Sopenharmony_ciChecks whether the camera device is muted. 383e41f4b71Sopenharmony_ci 384e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 385e41f4b71Sopenharmony_ci 386e41f4b71Sopenharmony_ci**Return value** 387e41f4b71Sopenharmony_ci 388e41f4b71Sopenharmony_ci| Type | Description | 389e41f4b71Sopenharmony_ci| ---------- | -------------------------------------------- | 390e41f4b71Sopenharmony_ci| boolean | **true**: The camera device is muted.<br>**false**: The camera device is not muted.| 391e41f4b71Sopenharmony_ci 392e41f4b71Sopenharmony_ci**Example** 393e41f4b71Sopenharmony_ci 394e41f4b71Sopenharmony_ci```ts 395e41f4b71Sopenharmony_cifunction isCameraMuted(cameraManager: camera.CameraManager): boolean { 396e41f4b71Sopenharmony_ci let isMuted: boolean = cameraManager.isCameraMuted(); 397e41f4b71Sopenharmony_ci return isMuted; 398e41f4b71Sopenharmony_ci} 399e41f4b71Sopenharmony_ci``` 400e41f4b71Sopenharmony_ci 401e41f4b71Sopenharmony_ci### createCameraInput 402e41f4b71Sopenharmony_ci 403e41f4b71Sopenharmony_cicreateCameraInput(camera: CameraDevice): CameraInput 404e41f4b71Sopenharmony_ci 405e41f4b71Sopenharmony_ciCreates a **CameraInput** instance with the specified **CameraDevice** instance. This API returns the result synchronously. 406e41f4b71Sopenharmony_ci 407e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.CAMERA 408e41f4b71Sopenharmony_ci 409e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 410e41f4b71Sopenharmony_ci 411e41f4b71Sopenharmony_ci**Parameters** 412e41f4b71Sopenharmony_ci 413e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 414e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | ---- |--------------------------------------------------| 415e41f4b71Sopenharmony_ci| camera | [CameraDevice](#cameradevice) | Yes | **CameraDevice** instance, which is obtained through [getSupportedCameras](#getsupportedcameras).| 416e41f4b71Sopenharmony_ci 417e41f4b71Sopenharmony_ci**Return value** 418e41f4b71Sopenharmony_ci 419e41f4b71Sopenharmony_ci| Type | Description | 420e41f4b71Sopenharmony_ci| ---------- | ----------------------------- | 421e41f4b71Sopenharmony_ci| [CameraInput](#camerainput) | **CameraInput** instance created. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 422e41f4b71Sopenharmony_ci 423e41f4b71Sopenharmony_ci**Error codes** 424e41f4b71Sopenharmony_ci 425e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 426e41f4b71Sopenharmony_ci 427e41f4b71Sopenharmony_ci| ID | Error Message | 428e41f4b71Sopenharmony_ci| --------------- | --------------- | 429e41f4b71Sopenharmony_ci| 7400101 | Parameter missing or parameter type incorrect. | 430e41f4b71Sopenharmony_ci| 7400102 | Operation not allowed. | 431e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 432e41f4b71Sopenharmony_ci 433e41f4b71Sopenharmony_ci**Example** 434e41f4b71Sopenharmony_ci 435e41f4b71Sopenharmony_ci```ts 436e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 437e41f4b71Sopenharmony_ci 438e41f4b71Sopenharmony_cifunction createCameraInput(camera: camera.CameraDevice, cameraManager: camera.CameraManager): camera.CameraInput | undefined { 439e41f4b71Sopenharmony_ci let cameraInput: camera.CameraInput | undefined = undefined; 440e41f4b71Sopenharmony_ci try { 441e41f4b71Sopenharmony_ci cameraInput = cameraManager.createCameraInput(camera); 442e41f4b71Sopenharmony_ci } catch (error) { 443e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 444e41f4b71Sopenharmony_ci let err = error as BusinessError; 445e41f4b71Sopenharmony_ci console.error(`The createCameraInput call failed. error code: ${err.code}`); 446e41f4b71Sopenharmony_ci } 447e41f4b71Sopenharmony_ci return cameraInput; 448e41f4b71Sopenharmony_ci} 449e41f4b71Sopenharmony_ci``` 450e41f4b71Sopenharmony_ci 451e41f4b71Sopenharmony_ci### createCameraInput 452e41f4b71Sopenharmony_ci 453e41f4b71Sopenharmony_cicreateCameraInput(position: CameraPosition, type: CameraType): CameraInput 454e41f4b71Sopenharmony_ci 455e41f4b71Sopenharmony_ciCreates a **CameraInput** instance with the specified camera position and type. This API returns the result synchronously. 456e41f4b71Sopenharmony_ci 457e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.CAMERA 458e41f4b71Sopenharmony_ci 459e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 460e41f4b71Sopenharmony_ci 461e41f4b71Sopenharmony_ci**Parameters** 462e41f4b71Sopenharmony_ci 463e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 464e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | ---- | --------------------------------- | 465e41f4b71Sopenharmony_ci| position | [CameraPosition](#cameraposition) | Yes | Camera position. You can call [getSupportedCameras](#getsupportedcameras) to obtain a **CameraDevice** instance, which contains the camera position information. | 466e41f4b71Sopenharmony_ci| type | [CameraType](#cameratype) | Yes | Camera type. You can call [getSupportedCameras](#getsupportedcameras) to obtain a **CameraDevice** instance, which contains the camera type information.| 467e41f4b71Sopenharmony_ci 468e41f4b71Sopenharmony_ci**Return value** 469e41f4b71Sopenharmony_ci 470e41f4b71Sopenharmony_ci| Type | Description | 471e41f4b71Sopenharmony_ci| ---------- | ----------------------------- | 472e41f4b71Sopenharmony_ci| [CameraInput](#camerainput) | **CameraInput** instance created. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 473e41f4b71Sopenharmony_ci 474e41f4b71Sopenharmony_ci**Error codes** 475e41f4b71Sopenharmony_ci 476e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 477e41f4b71Sopenharmony_ci 478e41f4b71Sopenharmony_ci| ID | Error Message | 479e41f4b71Sopenharmony_ci| --------------- | --------------- | 480e41f4b71Sopenharmony_ci| 7400101 | Parameter missing or parameter type incorrect. | 481e41f4b71Sopenharmony_ci| 7400102 | Operation not allowed. | 482e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 483e41f4b71Sopenharmony_ci 484e41f4b71Sopenharmony_ci**Example** 485e41f4b71Sopenharmony_ci 486e41f4b71Sopenharmony_ci```ts 487e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 488e41f4b71Sopenharmony_ci 489e41f4b71Sopenharmony_cifunction createCameraInput(camera: camera.CameraDevice, cameraManager: camera.CameraManager): camera.CameraInput | undefined { 490e41f4b71Sopenharmony_ci let position: camera.CameraPosition = camera.cameraPosition; 491e41f4b71Sopenharmony_ci let type: camera.CameraType = camera.cameraType; 492e41f4b71Sopenharmony_ci let cameraInput: camera.CameraInput | undefined = undefined; 493e41f4b71Sopenharmony_ci try { 494e41f4b71Sopenharmony_ci cameraInput = cameraManager.createCameraInput(position, type); 495e41f4b71Sopenharmony_ci } catch (error) { 496e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 497e41f4b71Sopenharmony_ci let err = error as BusinessError; 498e41f4b71Sopenharmony_ci console.error(`The createCameraInput call failed. error code: ${err.code}`); 499e41f4b71Sopenharmony_ci } 500e41f4b71Sopenharmony_ci return cameraInput; 501e41f4b71Sopenharmony_ci} 502e41f4b71Sopenharmony_ci``` 503e41f4b71Sopenharmony_ci 504e41f4b71Sopenharmony_ci### createPreviewOutput 505e41f4b71Sopenharmony_ci 506e41f4b71Sopenharmony_cicreatePreviewOutput(profile: Profile, surfaceId: string): PreviewOutput 507e41f4b71Sopenharmony_ci 508e41f4b71Sopenharmony_ciCreates a **PreviewOutput** instance. This API returns the result synchronously. 509e41f4b71Sopenharmony_ci 510e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 511e41f4b71Sopenharmony_ci 512e41f4b71Sopenharmony_ci**Parameters** 513e41f4b71Sopenharmony_ci 514e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 515e41f4b71Sopenharmony_ci| -------- | ----------------------------------------------- | ---- | ------------------------------- | 516e41f4b71Sopenharmony_ci| profile | [Profile](#profile) | Yes | Supported preview profile, which is obtained through [getSupportedOutputCapability](#getsupportedoutputcapability11).| 517e41f4b71Sopenharmony_ci| surfaceId| string | Yes | Surface ID, which is obtained from [XComponent](../apis-arkui/arkui-ts/ts-basic-components-xcomponent.md) or [ImageReceiver](../apis-image-kit/js-apis-image.md#imagereceiver9).| 518e41f4b71Sopenharmony_ci 519e41f4b71Sopenharmony_ci**Return value** 520e41f4b71Sopenharmony_ci 521e41f4b71Sopenharmony_ci| Type | Description | 522e41f4b71Sopenharmony_ci| ---------- | ----------------------------- | 523e41f4b71Sopenharmony_ci| [PreviewOutput](#previewoutput) | **PreviewOutput** instance created. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 524e41f4b71Sopenharmony_ci 525e41f4b71Sopenharmony_ci**Error codes** 526e41f4b71Sopenharmony_ci 527e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 528e41f4b71Sopenharmony_ci 529e41f4b71Sopenharmony_ci| ID | Error Message | 530e41f4b71Sopenharmony_ci| --------------- | --------------- | 531e41f4b71Sopenharmony_ci| 7400101 | Parameter missing or parameter type incorrect. | 532e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 533e41f4b71Sopenharmony_ci 534e41f4b71Sopenharmony_ci**Example** 535e41f4b71Sopenharmony_ci 536e41f4b71Sopenharmony_ci```ts 537e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 538e41f4b71Sopenharmony_ci 539e41f4b71Sopenharmony_cifunction createPreviewOutput(cameraOutputCapability: camera.CameraOutputCapability, cameraManager: camera.CameraManager, surfaceId: string): camera.PreviewOutput | undefined { 540e41f4b71Sopenharmony_ci let profile: camera.Profile = cameraOutputCapability.previewProfiles[0]; 541e41f4b71Sopenharmony_ci let previewOutput: camera.PreviewOutput | undefined = undefined; 542e41f4b71Sopenharmony_ci try { 543e41f4b71Sopenharmony_ci previewOutput = cameraManager.createPreviewOutput(profile, surfaceId); 544e41f4b71Sopenharmony_ci } catch (error) { 545e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 546e41f4b71Sopenharmony_ci let err = error as BusinessError; 547e41f4b71Sopenharmony_ci console.error(`The createPreviewOutput call failed. error code: ${err.code}`); 548e41f4b71Sopenharmony_ci } 549e41f4b71Sopenharmony_ci return previewOutput; 550e41f4b71Sopenharmony_ci} 551e41f4b71Sopenharmony_ci``` 552e41f4b71Sopenharmony_ci 553e41f4b71Sopenharmony_ci### createPreviewOutput<sup>12+</sup> 554e41f4b71Sopenharmony_ci 555e41f4b71Sopenharmony_cicreatePreviewOutput(surfaceId: string): PreviewOutput 556e41f4b71Sopenharmony_ci 557e41f4b71Sopenharmony_ciCreates a **PreviewOutput** instance without configuration. This API returns the result synchronously. It must be used together with [Preconfig](#preconfig12). 558e41f4b71Sopenharmony_ci 559e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 560e41f4b71Sopenharmony_ci 561e41f4b71Sopenharmony_ci**Parameters** 562e41f4b71Sopenharmony_ci 563e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 564e41f4b71Sopenharmony_ci| -------- | ----------------------------------------------- | ---- | ------------------------------- | 565e41f4b71Sopenharmony_ci| surfaceId| string | Yes | Surface ID, which is obtained from [XComponent](../apis-arkui/arkui-ts/ts-basic-components-xcomponent.md) or [ImageReceiver](../apis-image-kit/js-apis-image.md#imagereceiver9).| 566e41f4b71Sopenharmony_ci 567e41f4b71Sopenharmony_ci**Return value** 568e41f4b71Sopenharmony_ci 569e41f4b71Sopenharmony_ci| Type | Description | 570e41f4b71Sopenharmony_ci| ---------- | ----------------------------- | 571e41f4b71Sopenharmony_ci| [PreviewOutput](#previewoutput) | **PreviewOutput** instance created. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 572e41f4b71Sopenharmony_ci 573e41f4b71Sopenharmony_ci**Error codes** 574e41f4b71Sopenharmony_ci 575e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 576e41f4b71Sopenharmony_ci 577e41f4b71Sopenharmony_ci| ID | Error Message | 578e41f4b71Sopenharmony_ci|---------|------------------------------------------------| 579e41f4b71Sopenharmony_ci| 7400101 | Parameter missing or parameter type incorrect. | 580e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 581e41f4b71Sopenharmony_ci 582e41f4b71Sopenharmony_ci**Example** 583e41f4b71Sopenharmony_ci 584e41f4b71Sopenharmony_ci```ts 585e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 586e41f4b71Sopenharmony_ci 587e41f4b71Sopenharmony_cifunction createPreviewOutput(cameraManager: camera.CameraManager, surfaceId: string): camera.PreviewOutput | undefined { 588e41f4b71Sopenharmony_ci let previewOutput: camera.PreviewOutput | undefined = undefined; 589e41f4b71Sopenharmony_ci try { 590e41f4b71Sopenharmony_ci previewOutput = cameraManager.createPreviewOutput(surfaceId); 591e41f4b71Sopenharmony_ci } catch (error) { 592e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 593e41f4b71Sopenharmony_ci let err = error as BusinessError; 594e41f4b71Sopenharmony_ci console.error(`The createPreviewOutput call failed. error code: ${err.code}`); 595e41f4b71Sopenharmony_ci } 596e41f4b71Sopenharmony_ci return previewOutput; 597e41f4b71Sopenharmony_ci} 598e41f4b71Sopenharmony_ci``` 599e41f4b71Sopenharmony_ci 600e41f4b71Sopenharmony_ci### createPhotoOutput<sup>(deprecated)</sup> 601e41f4b71Sopenharmony_ci 602e41f4b71Sopenharmony_cicreatePhotoOutput(profile: Profile, surfaceId: string): PhotoOutput 603e41f4b71Sopenharmony_ci 604e41f4b71Sopenharmony_ciCreates a **PhotoOutput** instance. This API returns the result synchronously. 605e41f4b71Sopenharmony_ci 606e41f4b71Sopenharmony_ci> **NOTE** 607e41f4b71Sopenharmony_ci> 608e41f4b71Sopenharmony_ci> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [createPhotoOutput](#createphotooutput11) instead. 609e41f4b71Sopenharmony_ci 610e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 611e41f4b71Sopenharmony_ci 612e41f4b71Sopenharmony_ci**Parameters** 613e41f4b71Sopenharmony_ci 614e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 615e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | ---- | ----------------------------------- | 616e41f4b71Sopenharmony_ci| profile | [Profile](#profile) | Yes | Supported photo profile, which is obtained through [getSupportedOutputCapability](#getsupportedoutputcapability11).| 617e41f4b71Sopenharmony_ci| surfaceId| string | Yes | Surface ID, which is obtained from [ImageReceiver](../apis-image-kit/js-apis-image.md#imagereceiver9).| 618e41f4b71Sopenharmony_ci 619e41f4b71Sopenharmony_ci**Return value** 620e41f4b71Sopenharmony_ci 621e41f4b71Sopenharmony_ci| Type | Description | 622e41f4b71Sopenharmony_ci| ---------- | ----------------------------- | 623e41f4b71Sopenharmony_ci| [PhotoOutput](#photooutput) | **PhotoOutput** instance created. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 624e41f4b71Sopenharmony_ci 625e41f4b71Sopenharmony_ci**Error codes** 626e41f4b71Sopenharmony_ci 627e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 628e41f4b71Sopenharmony_ci 629e41f4b71Sopenharmony_ci| ID | Error Message | 630e41f4b71Sopenharmony_ci| --------------- | --------------- | 631e41f4b71Sopenharmony_ci| 7400101 | Parameter missing or parameter type incorrect. | 632e41f4b71Sopenharmony_ci 633e41f4b71Sopenharmony_ci```ts 634e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 635e41f4b71Sopenharmony_ci 636e41f4b71Sopenharmony_cifunction createPhotoOutput(cameraOutputCapability: camera.CameraOutputCapability, cameraManager: camera.CameraManager, surfaceId: string): camera.PhotoOutput | undefined { 637e41f4b71Sopenharmony_ci let profile: camera.Profile = cameraOutputCapability.photoProfiles[0]; 638e41f4b71Sopenharmony_ci let photoOutput: camera.PhotoOutput | undefined = undefined; 639e41f4b71Sopenharmony_ci try { 640e41f4b71Sopenharmony_ci photoOutput = cameraManager.createPhotoOutput(profile, surfaceId); 641e41f4b71Sopenharmony_ci } catch (error) { 642e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 643e41f4b71Sopenharmony_ci let err = error as BusinessError; 644e41f4b71Sopenharmony_ci console.error(`The createPhotoOutput call failed. error code: ${err.code}`); 645e41f4b71Sopenharmony_ci } 646e41f4b71Sopenharmony_ci return photoOutput; 647e41f4b71Sopenharmony_ci} 648e41f4b71Sopenharmony_ci``` 649e41f4b71Sopenharmony_ci 650e41f4b71Sopenharmony_ci### createPhotoOutput<sup>11+</sup> 651e41f4b71Sopenharmony_ci 652e41f4b71Sopenharmony_cicreatePhotoOutput(profile?: Profile): PhotoOutput 653e41f4b71Sopenharmony_ci 654e41f4b71Sopenharmony_ciCreates a **PhotoOutput** instance. This API returns the result synchronously. 655e41f4b71Sopenharmony_ci 656e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 657e41f4b71Sopenharmony_ci 658e41f4b71Sopenharmony_ci**Parameters** 659e41f4b71Sopenharmony_ci 660e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 661e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- |----| ----------------------------------- | 662e41f4b71Sopenharmony_ci| profile | [Profile](#profile) | No | Supported photo profile, which is obtained through [getSupportedOutputCapability](#getsupportedoutputcapability11).<br>In API version 11, this parameter is mandatory. Since API version 12, it will overwrite the preconfigured parameters passed in through **preconfig**.| 663e41f4b71Sopenharmony_ci 664e41f4b71Sopenharmony_ci**Return value** 665e41f4b71Sopenharmony_ci 666e41f4b71Sopenharmony_ci| Type | Description | 667e41f4b71Sopenharmony_ci| ---------- | ----------------------------- | 668e41f4b71Sopenharmony_ci| [PhotoOutput](#photooutput) | **PhotoOutput** instance created. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 669e41f4b71Sopenharmony_ci 670e41f4b71Sopenharmony_ci**Error codes** 671e41f4b71Sopenharmony_ci 672e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 673e41f4b71Sopenharmony_ci 674e41f4b71Sopenharmony_ci| ID | Error Message | 675e41f4b71Sopenharmony_ci|----------|------------------------------------------------| 676e41f4b71Sopenharmony_ci| 7400101 | Parameter missing or parameter type incorrect. | 677e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 678e41f4b71Sopenharmony_ci 679e41f4b71Sopenharmony_ci**Example** 680e41f4b71Sopenharmony_ci 681e41f4b71Sopenharmony_ci```ts 682e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 683e41f4b71Sopenharmony_ci 684e41f4b71Sopenharmony_cifunction createPhotoOutput(cameraOutputCapability: camera.CameraOutputCapability, cameraManager: camera.CameraManager): camera.PhotoOutput | undefined { 685e41f4b71Sopenharmony_ci let profile: camera.Profile = cameraOutputCapability.photoProfiles[0]; 686e41f4b71Sopenharmony_ci let photoOutput: camera.PhotoOutput | undefined = undefined; 687e41f4b71Sopenharmony_ci try { 688e41f4b71Sopenharmony_ci photoOutput = cameraManager.createPhotoOutput(profile); 689e41f4b71Sopenharmony_ci } catch (error) { 690e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 691e41f4b71Sopenharmony_ci let err = error as BusinessError; 692e41f4b71Sopenharmony_ci console.error(`The createPhotoOutput call failed. error code: ${err.code}`); 693e41f4b71Sopenharmony_ci } 694e41f4b71Sopenharmony_ci return photoOutput; 695e41f4b71Sopenharmony_ci} 696e41f4b71Sopenharmony_ci``` 697e41f4b71Sopenharmony_ci 698e41f4b71Sopenharmony_ci### createVideoOutput 699e41f4b71Sopenharmony_ci 700e41f4b71Sopenharmony_cicreateVideoOutput(profile: VideoProfile, surfaceId: string): VideoOutput 701e41f4b71Sopenharmony_ci 702e41f4b71Sopenharmony_ciCreates a **VideoOutput** instance. This API returns the result synchronously. 703e41f4b71Sopenharmony_ci 704e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 705e41f4b71Sopenharmony_ci 706e41f4b71Sopenharmony_ci**Parameters** 707e41f4b71Sopenharmony_ci 708e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 709e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | ---- | ------------------------------ | 710e41f4b71Sopenharmony_ci| profile | [VideoProfile](#videoprofile) | Yes | Supported video profile, which is obtained through [getSupportedOutputCapability](#getsupportedoutputcapability11).| 711e41f4b71Sopenharmony_ci| surfaceId| string | Yes | Surface ID, which is obtained from [AVRecorder](../apis-media-kit/js-apis-media.md#avrecorder9).| 712e41f4b71Sopenharmony_ci 713e41f4b71Sopenharmony_ci**Return value** 714e41f4b71Sopenharmony_ci 715e41f4b71Sopenharmony_ci| Type | Description | 716e41f4b71Sopenharmony_ci| ---------- | ----------------------------- | 717e41f4b71Sopenharmony_ci| [VideoOutput](#videooutput) | **VideoOutput** instance created. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 718e41f4b71Sopenharmony_ci 719e41f4b71Sopenharmony_ci**Error codes** 720e41f4b71Sopenharmony_ci 721e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 722e41f4b71Sopenharmony_ci 723e41f4b71Sopenharmony_ci| ID | Error Message | 724e41f4b71Sopenharmony_ci| --------------- | --------------- | 725e41f4b71Sopenharmony_ci| 7400101 | Parameter missing or parameter type incorrect. | 726e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 727e41f4b71Sopenharmony_ci 728e41f4b71Sopenharmony_ci**Example** 729e41f4b71Sopenharmony_ci 730e41f4b71Sopenharmony_ci```ts 731e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 732e41f4b71Sopenharmony_ci 733e41f4b71Sopenharmony_cifunction createVideoOutput(cameraOutputCapability: camera.CameraOutputCapability, cameraManager: camera.CameraManager, surfaceId: string): camera.VideoOutput | undefined { 734e41f4b71Sopenharmony_ci let profile: camera.VideoProfile = cameraOutputCapability.videoProfiles[0]; 735e41f4b71Sopenharmony_ci let videoOutput: camera.VideoOutput | undefined = undefined; 736e41f4b71Sopenharmony_ci try { 737e41f4b71Sopenharmony_ci videoOutput = cameraManager.createVideoOutput(profile, surfaceId); 738e41f4b71Sopenharmony_ci } catch (error) { 739e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 740e41f4b71Sopenharmony_ci let err = error as BusinessError; 741e41f4b71Sopenharmony_ci console.error(`The createVideoOutput call failed. error code: ${err.code}`); 742e41f4b71Sopenharmony_ci } 743e41f4b71Sopenharmony_ci return videoOutput; 744e41f4b71Sopenharmony_ci} 745e41f4b71Sopenharmony_ci``` 746e41f4b71Sopenharmony_ci 747e41f4b71Sopenharmony_ci### createVideoOutput<sup>12+</sup> 748e41f4b71Sopenharmony_ci 749e41f4b71Sopenharmony_cicreateVideoOutput(surfaceId: string): VideoOutput 750e41f4b71Sopenharmony_ci 751e41f4b71Sopenharmony_ciCreates a **VideoOutput** instance without configuration. This API returns the result synchronously. It must be used together with [Preconfig](#preconfig12). 752e41f4b71Sopenharmony_ci 753e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 754e41f4b71Sopenharmony_ci 755e41f4b71Sopenharmony_ci**Parameters** 756e41f4b71Sopenharmony_ci 757e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 758e41f4b71Sopenharmony_ci|-----------|--------|-------|----------------------------------------------------------------------------| 759e41f4b71Sopenharmony_ci| surfaceId | string | Yes | Surface ID, which is obtained from [AVRecorder](../apis-media-kit/js-apis-media.md#avrecorder9).| 760e41f4b71Sopenharmony_ci 761e41f4b71Sopenharmony_ci**Return value** 762e41f4b71Sopenharmony_ci 763e41f4b71Sopenharmony_ci| Type | Description | 764e41f4b71Sopenharmony_ci| ---------- | ----------------------------- | 765e41f4b71Sopenharmony_ci| [VideoOutput](#videooutput) | **VideoOutput** instance created. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 766e41f4b71Sopenharmony_ci 767e41f4b71Sopenharmony_ci**Error codes** 768e41f4b71Sopenharmony_ci 769e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 770e41f4b71Sopenharmony_ci 771e41f4b71Sopenharmony_ci| ID | Error Message | 772e41f4b71Sopenharmony_ci|----------|------------------------------------------------| 773e41f4b71Sopenharmony_ci| 7400101 | Parameter missing or parameter type incorrect. | 774e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 775e41f4b71Sopenharmony_ci 776e41f4b71Sopenharmony_ci**Example** 777e41f4b71Sopenharmony_ci 778e41f4b71Sopenharmony_ci```ts 779e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 780e41f4b71Sopenharmony_ci 781e41f4b71Sopenharmony_cifunction createVideoOutput(cameraManager: camera.CameraManager, surfaceId: string): camera.VideoOutput | undefined { 782e41f4b71Sopenharmony_ci let videoOutput: camera.VideoOutput | undefined = undefined; 783e41f4b71Sopenharmony_ci try { 784e41f4b71Sopenharmony_ci videoOutput = cameraManager.createVideoOutput(surfaceId); 785e41f4b71Sopenharmony_ci } catch (error) { 786e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 787e41f4b71Sopenharmony_ci let err = error as BusinessError; 788e41f4b71Sopenharmony_ci console.error(`The createVideoOutput call failed. error code: ${err.code}`); 789e41f4b71Sopenharmony_ci } 790e41f4b71Sopenharmony_ci return videoOutput; 791e41f4b71Sopenharmony_ci} 792e41f4b71Sopenharmony_ci``` 793e41f4b71Sopenharmony_ci 794e41f4b71Sopenharmony_ci### createMetadataOutput 795e41f4b71Sopenharmony_ci 796e41f4b71Sopenharmony_cicreateMetadataOutput(metadataObjectTypes: Array\<MetadataObjectType\>): MetadataOutput 797e41f4b71Sopenharmony_ci 798e41f4b71Sopenharmony_ciCreates a **MetadataOutput** instance. This API returns the result synchronously. 799e41f4b71Sopenharmony_ci 800e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 801e41f4b71Sopenharmony_ci 802e41f4b71Sopenharmony_ci**Parameters** 803e41f4b71Sopenharmony_ci 804e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 805e41f4b71Sopenharmony_ci| -------------------- | -------------------------------------------------- | --- | ---------------------------- | 806e41f4b71Sopenharmony_ci| metadataObjectTypes | Array\<[MetadataObjectType](#metadataobjecttype)\> | Yes | Metadata object types, which are obtained through [getSupportedOutputCapability](#getsupportedoutputcapability11).| 807e41f4b71Sopenharmony_ci 808e41f4b71Sopenharmony_ci**Return value** 809e41f4b71Sopenharmony_ci 810e41f4b71Sopenharmony_ci| Type | Description | 811e41f4b71Sopenharmony_ci| ---------- | ----------------------------- | 812e41f4b71Sopenharmony_ci| [MetadataOutput](#metadataoutput) | **MetadataOutput** instance created. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 813e41f4b71Sopenharmony_ci 814e41f4b71Sopenharmony_ci**Error codes** 815e41f4b71Sopenharmony_ci 816e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 817e41f4b71Sopenharmony_ci 818e41f4b71Sopenharmony_ci| ID | Error Message | 819e41f4b71Sopenharmony_ci| --------------- | --------------- | 820e41f4b71Sopenharmony_ci| 7400101 | Parameter missing or parameter type incorrect. | 821e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 822e41f4b71Sopenharmony_ci 823e41f4b71Sopenharmony_ci**Example** 824e41f4b71Sopenharmony_ci 825e41f4b71Sopenharmony_ci```ts 826e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 827e41f4b71Sopenharmony_ci 828e41f4b71Sopenharmony_cifunction createMetadataOutput(cameraManager: camera.CameraManager, cameraOutputCapability: camera.CameraOutputCapability): void { 829e41f4b71Sopenharmony_ci let metadataObjectTypes: Array<camera.MetadataObjectType> = cameraOutputCapability.supportedMetadataObjectTypes; 830e41f4b71Sopenharmony_ci let metadataOutput: camera.MetadataOutput | undefined = undefined; 831e41f4b71Sopenharmony_ci try { 832e41f4b71Sopenharmony_ci metadataOutput = cameraManager.createMetadataOutput(metadataObjectTypes); 833e41f4b71Sopenharmony_ci } catch (error) { 834e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 835e41f4b71Sopenharmony_ci let err = error as BusinessError; 836e41f4b71Sopenharmony_ci console.error(`createMetadataOutput error. error code: ${err.code}`); 837e41f4b71Sopenharmony_ci } 838e41f4b71Sopenharmony_ci} 839e41f4b71Sopenharmony_ci``` 840e41f4b71Sopenharmony_ci 841e41f4b71Sopenharmony_ci### createCaptureSession<sup>(deprecated)</sup> 842e41f4b71Sopenharmony_ci 843e41f4b71Sopenharmony_cicreateCaptureSession(): CaptureSession 844e41f4b71Sopenharmony_ci 845e41f4b71Sopenharmony_ciCreates a **CaptureSession** instance. This API returns the result synchronously. 846e41f4b71Sopenharmony_ci 847e41f4b71Sopenharmony_ci> **NOTE** 848e41f4b71Sopenharmony_ci> 849e41f4b71Sopenharmony_ci> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [createSession](#createsession11) instead. 850e41f4b71Sopenharmony_ci 851e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 852e41f4b71Sopenharmony_ci 853e41f4b71Sopenharmony_ci**Return value** 854e41f4b71Sopenharmony_ci 855e41f4b71Sopenharmony_ci| Type | Description | 856e41f4b71Sopenharmony_ci| ---------- | ----------------------------- | 857e41f4b71Sopenharmony_ci| [CaptureSession](#capturesessiondeprecated) | **CaptureSession** instance created. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 858e41f4b71Sopenharmony_ci 859e41f4b71Sopenharmony_ci**Error codes** 860e41f4b71Sopenharmony_ci 861e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 862e41f4b71Sopenharmony_ci 863e41f4b71Sopenharmony_ci| ID | Error Message | 864e41f4b71Sopenharmony_ci| --------------- | --------------- | 865e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 866e41f4b71Sopenharmony_ci 867e41f4b71Sopenharmony_ci**Example** 868e41f4b71Sopenharmony_ci 869e41f4b71Sopenharmony_ci```ts 870e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 871e41f4b71Sopenharmony_ci 872e41f4b71Sopenharmony_cifunction createCaptureSession(cameraManager: camera.CameraManager): camera.CaptureSession | undefined { 873e41f4b71Sopenharmony_ci let captureSession: camera.CaptureSession | undefined = undefined; 874e41f4b71Sopenharmony_ci try { 875e41f4b71Sopenharmony_ci captureSession = cameraManager.createCaptureSession(); 876e41f4b71Sopenharmony_ci } catch (error) { 877e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 878e41f4b71Sopenharmony_ci let err = error as BusinessError; 879e41f4b71Sopenharmony_ci console.error(`createCaptureSession error. error code: ${err.code}`); 880e41f4b71Sopenharmony_ci } 881e41f4b71Sopenharmony_ci return captureSession; 882e41f4b71Sopenharmony_ci} 883e41f4b71Sopenharmony_ci``` 884e41f4b71Sopenharmony_ci 885e41f4b71Sopenharmony_ci### createSession<sup>11+</sup> 886e41f4b71Sopenharmony_ci 887e41f4b71Sopenharmony_cicreateSession\<T extends Session\>(mode: SceneMode): T 888e41f4b71Sopenharmony_ci 889e41f4b71Sopenharmony_ciCreates a **Session** instance with a given scene mode. This API returns the result synchronously. 890e41f4b71Sopenharmony_ci 891e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 892e41f4b71Sopenharmony_ci 893e41f4b71Sopenharmony_ci**Parameters** 894e41f4b71Sopenharmony_ci 895e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 896e41f4b71Sopenharmony_ci| -------- | -----------------| ---- | --------- | 897e41f4b71Sopenharmony_ci| mode | SceneMode | Yes | Scene mode.| 898e41f4b71Sopenharmony_ci 899e41f4b71Sopenharmony_ci**Return value** 900e41f4b71Sopenharmony_ci 901e41f4b71Sopenharmony_ci| Type | Description | 902e41f4b71Sopenharmony_ci| ---------- | ----------------------------- | 903e41f4b71Sopenharmony_ci| [T extends Session](#session11) | **Session** instance created. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 904e41f4b71Sopenharmony_ci 905e41f4b71Sopenharmony_ci**Error codes** 906e41f4b71Sopenharmony_ci 907e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 908e41f4b71Sopenharmony_ci 909e41f4b71Sopenharmony_ci| ID | Error Message | 910e41f4b71Sopenharmony_ci| --------------- | --------------- | 911e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 912e41f4b71Sopenharmony_ci 913e41f4b71Sopenharmony_ci**Example** 914e41f4b71Sopenharmony_ci 915e41f4b71Sopenharmony_ci```ts 916e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 917e41f4b71Sopenharmony_ci 918e41f4b71Sopenharmony_cifunction createSession(cameraManager: camera.CameraManager, mode: camera.SceneMode): camera.Session | undefined { 919e41f4b71Sopenharmony_ci let photoSession: camera.PhotoSession | undefined = undefined; 920e41f4b71Sopenharmony_ci try { 921e41f4b71Sopenharmony_ci photoSession = cameraManager.createSession(mode) as camera.PhotoSession; 922e41f4b71Sopenharmony_ci } catch (error) { 923e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 924e41f4b71Sopenharmony_ci let err = error as BusinessError; 925e41f4b71Sopenharmony_ci console.error(`createCaptureSession error. error code: ${err.code}`); 926e41f4b71Sopenharmony_ci } 927e41f4b71Sopenharmony_ci return photoSession; 928e41f4b71Sopenharmony_ci} 929e41f4b71Sopenharmony_ci``` 930e41f4b71Sopenharmony_ci 931e41f4b71Sopenharmony_ci### on('cameraStatus') 932e41f4b71Sopenharmony_ci 933e41f4b71Sopenharmony_cion(type: 'cameraStatus', callback: AsyncCallback\<CameraStatusInfo\>): void 934e41f4b71Sopenharmony_ci 935e41f4b71Sopenharmony_ciSubscribes to camera status events. This API uses an asynchronous callback to return the result. 936e41f4b71Sopenharmony_ci 937e41f4b71Sopenharmony_ci> **NOTE** 938e41f4b71Sopenharmony_ci> 939e41f4b71Sopenharmony_ci> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**. 940e41f4b71Sopenharmony_ci 941e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 942e41f4b71Sopenharmony_ci 943e41f4b71Sopenharmony_ci**Parameters** 944e41f4b71Sopenharmony_ci 945e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 946e41f4b71Sopenharmony_ci| -------- | -----------------| ---- | --------- | 947e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'cameraStatus'**. The event can be listened for when a **CameraManager** instance is obtained. This event is triggered and the corresponding information is returned only when the camera device is enabled or disabled.| 948e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[CameraStatusInfo](#camerastatusinfo)\> | Yes | Callback used to return the camera status change.| | 949e41f4b71Sopenharmony_ci 950e41f4b71Sopenharmony_ci**Example** 951e41f4b71Sopenharmony_ci 952e41f4b71Sopenharmony_ci```ts 953e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 954e41f4b71Sopenharmony_ci 955e41f4b71Sopenharmony_cifunction callback(err: BusinessError, cameraStatusInfo: camera.CameraStatusInfo): void { 956e41f4b71Sopenharmony_ci if (err !== undefined && err.code !== 0) { 957e41f4b71Sopenharmony_ci console.error('cameraStatus with errorCode = ' + err.code); 958e41f4b71Sopenharmony_ci return; 959e41f4b71Sopenharmony_ci } 960e41f4b71Sopenharmony_ci console.info(`camera : ${cameraStatusInfo.camera.cameraId}`); 961e41f4b71Sopenharmony_ci console.info(`status: ${cameraStatusInfo.status}`); 962e41f4b71Sopenharmony_ci} 963e41f4b71Sopenharmony_ci 964e41f4b71Sopenharmony_cifunction registerCameraStatus(cameraManager: camera.CameraManager): void { 965e41f4b71Sopenharmony_ci cameraManager.on('cameraStatus', callback); 966e41f4b71Sopenharmony_ci} 967e41f4b71Sopenharmony_ci``` 968e41f4b71Sopenharmony_ci 969e41f4b71Sopenharmony_ci### off('cameraStatus') 970e41f4b71Sopenharmony_ci 971e41f4b71Sopenharmony_cioff(type: 'cameraStatus', callback?: AsyncCallback\<CameraStatusInfo\>): void 972e41f4b71Sopenharmony_ci 973e41f4b71Sopenharmony_ciUnsubscribes from camera status events. This API uses an asynchronous callback to return the result. 974e41f4b71Sopenharmony_ci 975e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 976e41f4b71Sopenharmony_ci 977e41f4b71Sopenharmony_ci**Parameters** 978e41f4b71Sopenharmony_ci 979e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 980e41f4b71Sopenharmony_ci| -------- | -----------------| ---- | --------- | 981e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'cameraStatus'**. The event can be listened for when a **CameraManager** instance is obtained.| 982e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[CameraStatusInfo](#camerastatusinfo)\> | No | Callback used to return the result. If this parameter is specified, the subscription to the specified event with the specified callback is canceled. (The callback object cannot be an anonymous function.) Otherwise, the subscriptions to the specified event with all the callbacks are canceled.| 983e41f4b71Sopenharmony_ci 984e41f4b71Sopenharmony_ci**Example** 985e41f4b71Sopenharmony_ci 986e41f4b71Sopenharmony_ci```ts 987e41f4b71Sopenharmony_cifunction unregisterCameraStatus(cameraManager: camera.CameraManager): void { 988e41f4b71Sopenharmony_ci cameraManager.off('cameraStatus'); 989e41f4b71Sopenharmony_ci} 990e41f4b71Sopenharmony_ci``` 991e41f4b71Sopenharmony_ci 992e41f4b71Sopenharmony_ci### on('foldStatusChange')<sup>12+</sup> 993e41f4b71Sopenharmony_ci 994e41f4b71Sopenharmony_cion(type: 'foldStatusChange', callback: AsyncCallback\<FoldStatusInfo\>): void 995e41f4b71Sopenharmony_ci 996e41f4b71Sopenharmony_ciSubscribes to folding status change events of the foldable device. This API uses an asynchronous callback to return the result. 997e41f4b71Sopenharmony_ci 998e41f4b71Sopenharmony_ci> **NOTE** 999e41f4b71Sopenharmony_ci> 1000e41f4b71Sopenharmony_ci> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**. 1001e41f4b71Sopenharmony_ci 1002e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 1003e41f4b71Sopenharmony_ci 1004e41f4b71Sopenharmony_ci**Parameters** 1005e41f4b71Sopenharmony_ci 1006e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 1007e41f4b71Sopenharmony_ci| -------- | -----------------| ---- | --------- | 1008e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'foldStatusChange'**. The event is triggered when the folding status of the foldable device changes.| 1009e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[FoldStatusInfo](#foldstatusinfo12)\> | Yes | Callback used to return the folding status information about the foldable device.| 1010e41f4b71Sopenharmony_ci 1011e41f4b71Sopenharmony_ci**Example** 1012e41f4b71Sopenharmony_ci 1013e41f4b71Sopenharmony_ci```ts 1014e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1015e41f4b71Sopenharmony_ci 1016e41f4b71Sopenharmony_cifunction callback(err: BusinessError, foldStatusInfo: camera.FoldStatusInfo): void { 1017e41f4b71Sopenharmony_ci if (err !== undefined && err.code !== 0) { 1018e41f4b71Sopenharmony_ci console.error('foldStatusChange with errorCode = ' + err.code); 1019e41f4b71Sopenharmony_ci return; 1020e41f4b71Sopenharmony_ci } 1021e41f4b71Sopenharmony_ci console.info(`camera length: ${foldStatusInfo.supportedCameras.length}`); 1022e41f4b71Sopenharmony_ci console.info(`foldStatus: ${foldStatusInfo.foldStatus}`); 1023e41f4b71Sopenharmony_ci} 1024e41f4b71Sopenharmony_ci 1025e41f4b71Sopenharmony_cifunction registerFoldStatusChange(cameraManager: camera.CameraManager): void { 1026e41f4b71Sopenharmony_ci cameraManager.on('foldStatusChange', callback); 1027e41f4b71Sopenharmony_ci} 1028e41f4b71Sopenharmony_ci``` 1029e41f4b71Sopenharmony_ci 1030e41f4b71Sopenharmony_ci### off('foldStatusChange')<sup>12+</sup> 1031e41f4b71Sopenharmony_ci 1032e41f4b71Sopenharmony_cioff(type: 'foldStatusChange', callback?: AsyncCallback\<FoldStatusInfo\>): void 1033e41f4b71Sopenharmony_ci 1034e41f4b71Sopenharmony_ciUnsubscribes from folding status change events of the foldable device. 1035e41f4b71Sopenharmony_ci 1036e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 1037e41f4b71Sopenharmony_ci 1038e41f4b71Sopenharmony_ci**Parameters** 1039e41f4b71Sopenharmony_ci 1040e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 1041e41f4b71Sopenharmony_ci| -------- | -----------------| ---- | --------- | 1042e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'foldStatusChange'**. The event is triggered when the folding status of the foldable device changes.| 1043e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[FoldStatusInfo](#foldstatusinfo12)\> | No | Callback used to return the folding status information about the foldable device. If this parameter is specified, the subscription to the specified event with the specified callback is canceled. (The callback object cannot be an anonymous function.) Otherwise, the subscriptions to the specified event with all the callbacks are canceled.| 1044e41f4b71Sopenharmony_ci 1045e41f4b71Sopenharmony_ci**Example** 1046e41f4b71Sopenharmony_ci 1047e41f4b71Sopenharmony_ci```ts 1048e41f4b71Sopenharmony_cifunction unregisterFoldStatusChange(cameraManager: camera.CameraManager): void { 1049e41f4b71Sopenharmony_ci cameraManager.off('foldStatusChange'); 1050e41f4b71Sopenharmony_ci} 1051e41f4b71Sopenharmony_ci``` 1052e41f4b71Sopenharmony_ci 1053e41f4b71Sopenharmony_ci### isTorchSupported<sup>11+</sup> 1054e41f4b71Sopenharmony_ci 1055e41f4b71Sopenharmony_ciisTorchSupported(): boolean 1056e41f4b71Sopenharmony_ci 1057e41f4b71Sopenharmony_ciChecks whether the camera device supports the flashlight. 1058e41f4b71Sopenharmony_ci 1059e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 1060e41f4b71Sopenharmony_ci 1061e41f4b71Sopenharmony_ci**Return value** 1062e41f4b71Sopenharmony_ci 1063e41f4b71Sopenharmony_ci| Type | Description | 1064e41f4b71Sopenharmony_ci| ---------- | ----------------------------- | 1065e41f4b71Sopenharmony_ci| boolean | **true**: The camera device supports the flashlight.<br>**false**: The camera device does not support the flashlight.| 1066e41f4b71Sopenharmony_ci 1067e41f4b71Sopenharmony_ci**Example** 1068e41f4b71Sopenharmony_ci 1069e41f4b71Sopenharmony_ci```ts 1070e41f4b71Sopenharmony_cifunction isTorchSupported(cameraManager: camera.CameraManager): boolean { 1071e41f4b71Sopenharmony_ci let isSupported = cameraManager.isTorchSupported(); 1072e41f4b71Sopenharmony_ci return isSupported; 1073e41f4b71Sopenharmony_ci} 1074e41f4b71Sopenharmony_ci``` 1075e41f4b71Sopenharmony_ci 1076e41f4b71Sopenharmony_ci### isTorchModeSupported<sup>11+</sup> 1077e41f4b71Sopenharmony_ci 1078e41f4b71Sopenharmony_ciisTorchModeSupported(mode: TorchMode): boolean 1079e41f4b71Sopenharmony_ci 1080e41f4b71Sopenharmony_ciChecks whether a flashlight mode is supported. 1081e41f4b71Sopenharmony_ci 1082e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 1083e41f4b71Sopenharmony_ci 1084e41f4b71Sopenharmony_ci**Parameters** 1085e41f4b71Sopenharmony_ci 1086e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 1087e41f4b71Sopenharmony_ci| -------- | --------------- | ---- | --------- | 1088e41f4b71Sopenharmony_ci| mode | [TorchMode](#torchmode11) | Yes| Flashlight mode.| 1089e41f4b71Sopenharmony_ci 1090e41f4b71Sopenharmony_ci**Return value** 1091e41f4b71Sopenharmony_ci 1092e41f4b71Sopenharmony_ci| Type | Description | 1093e41f4b71Sopenharmony_ci| ---------- | ----------------------------- | 1094e41f4b71Sopenharmony_ci| boolean | **true**: The flashlight mode is supported.<br>**false**: The flashlight mode is not supported.| 1095e41f4b71Sopenharmony_ci 1096e41f4b71Sopenharmony_ci**Example** 1097e41f4b71Sopenharmony_ci 1098e41f4b71Sopenharmony_ci```ts 1099e41f4b71Sopenharmony_cifunction isTorchModeSupported(cameraManager: camera.CameraManager, torchMode: camera.TorchMode): boolean { 1100e41f4b71Sopenharmony_ci let isSupported = cameraManager.isTorchModeSupported(torchMode); 1101e41f4b71Sopenharmony_ci return isSupported; 1102e41f4b71Sopenharmony_ci} 1103e41f4b71Sopenharmony_ci``` 1104e41f4b71Sopenharmony_ci 1105e41f4b71Sopenharmony_ci### getTorchMode<sup>11+</sup> 1106e41f4b71Sopenharmony_ci 1107e41f4b71Sopenharmony_cigetTorchMode(): TorchMode 1108e41f4b71Sopenharmony_ci 1109e41f4b71Sopenharmony_ciObtains the flashlight mode of this camera device. 1110e41f4b71Sopenharmony_ci 1111e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 1112e41f4b71Sopenharmony_ci 1113e41f4b71Sopenharmony_ci**Return value** 1114e41f4b71Sopenharmony_ci 1115e41f4b71Sopenharmony_ci| Type | Description | 1116e41f4b71Sopenharmony_ci| ---------- | ----------------------------- | 1117e41f4b71Sopenharmony_ci| [TorchMode](#torchmode11) | Flashlight mode.| 1118e41f4b71Sopenharmony_ci 1119e41f4b71Sopenharmony_ci**Example** 1120e41f4b71Sopenharmony_ci 1121e41f4b71Sopenharmony_ci```ts 1122e41f4b71Sopenharmony_cifunction getTorchMode(cameraManager: camera.CameraManager): camera.TorchMode | undefined { 1123e41f4b71Sopenharmony_ci let torchMode: camera.TorchMode | undefined = undefined; 1124e41f4b71Sopenharmony_ci torchMode = cameraManager.getTorchMode(); 1125e41f4b71Sopenharmony_ci return torchMode; 1126e41f4b71Sopenharmony_ci} 1127e41f4b71Sopenharmony_ci``` 1128e41f4b71Sopenharmony_ci 1129e41f4b71Sopenharmony_ci### setTorchMode<sup>11+</sup> 1130e41f4b71Sopenharmony_ci 1131e41f4b71Sopenharmony_cisetTorchMode(mode: TorchMode): void 1132e41f4b71Sopenharmony_ci 1133e41f4b71Sopenharmony_ciSets the flashlight mode. 1134e41f4b71Sopenharmony_ci 1135e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 1136e41f4b71Sopenharmony_ci 1137e41f4b71Sopenharmony_ci**Parameters** 1138e41f4b71Sopenharmony_ci 1139e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 1140e41f4b71Sopenharmony_ci| -------- | --------------- | ---- | --------- | 1141e41f4b71Sopenharmony_ci| mode | [TorchMode](#torchmode11) | Yes| Flashlight mode.| 1142e41f4b71Sopenharmony_ci 1143e41f4b71Sopenharmony_ci**Error codes** 1144e41f4b71Sopenharmony_ci 1145e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 1146e41f4b71Sopenharmony_ci 1147e41f4b71Sopenharmony_ci| ID | Error Message | 1148e41f4b71Sopenharmony_ci| --------------- | --------------- | 1149e41f4b71Sopenharmony_ci| 7400101 | Parameter missing or parameter type incorrect. | 1150e41f4b71Sopenharmony_ci| 7400102 | Operation not allowed. | 1151e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 1152e41f4b71Sopenharmony_ci 1153e41f4b71Sopenharmony_ci**Example** 1154e41f4b71Sopenharmony_ci 1155e41f4b71Sopenharmony_ci```ts 1156e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1157e41f4b71Sopenharmony_ci 1158e41f4b71Sopenharmony_cifunction setTorchMode(cameraManager: camera.CameraManager, torchMode: camera.TorchMode): void { 1159e41f4b71Sopenharmony_ci try { 1160e41f4b71Sopenharmony_ci cameraManager.setTorchMode(torchMode); 1161e41f4b71Sopenharmony_ci } catch (error) { 1162e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 1163e41f4b71Sopenharmony_ci let err = error as BusinessError; 1164e41f4b71Sopenharmony_ci console.error(`The setTorchMode call failed. error code: ${err.code}`); 1165e41f4b71Sopenharmony_ci } 1166e41f4b71Sopenharmony_ci} 1167e41f4b71Sopenharmony_ci``` 1168e41f4b71Sopenharmony_ci 1169e41f4b71Sopenharmony_ci### on('torchStatusChange')<sup>11+</sup> 1170e41f4b71Sopenharmony_ci 1171e41f4b71Sopenharmony_cion(type: 'torchStatusChange', callback: AsyncCallback\<TorchStatusInfo\>): void 1172e41f4b71Sopenharmony_ci 1173e41f4b71Sopenharmony_ciSubscribes to flashlight status change events. This API uses an asynchronous callback to return the result. 1174e41f4b71Sopenharmony_ci 1175e41f4b71Sopenharmony_ci> **NOTE** 1176e41f4b71Sopenharmony_ci> 1177e41f4b71Sopenharmony_ci> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**. 1178e41f4b71Sopenharmony_ci 1179e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 1180e41f4b71Sopenharmony_ci 1181e41f4b71Sopenharmony_ci**Parameters** 1182e41f4b71Sopenharmony_ci 1183e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 1184e41f4b71Sopenharmony_ci| -------- | --------------- | ---- | --------- | 1185e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'torchStatusChange'**. The event can be listened for when a **CameraManager** instance is obtained. Currently, this event is triggered only in the following scenarios: The flashlight is turned on or turned off, or becomes unavailable or available.| 1186e41f4b71Sopenharmony_ci| callback | AsyncCallback\<TorchStatusInfo> | Yes | Callback used to return the flashlight status. | 1187e41f4b71Sopenharmony_ci 1188e41f4b71Sopenharmony_ci**Example** 1189e41f4b71Sopenharmony_ci 1190e41f4b71Sopenharmony_ci```ts 1191e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1192e41f4b71Sopenharmony_ci 1193e41f4b71Sopenharmony_cifunction callback(err: BusinessError, torchStatusInfo: camera.TorchStatusInfo): void { 1194e41f4b71Sopenharmony_ci if (err !== undefined && err.code !== 0) { 1195e41f4b71Sopenharmony_ci console.error(`Callback Error, errorCode: ${err.code}`); 1196e41f4b71Sopenharmony_ci return; 1197e41f4b71Sopenharmony_ci } 1198e41f4b71Sopenharmony_ci console.info(`onTorchStatusChange, isTorchAvailable: ${torchStatusInfo.isTorchAvailable}, isTorchActive: ${torchStatusInfo.isTorchActive}, level: ${torchStatusInfo.torchLevel}`); 1199e41f4b71Sopenharmony_ci} 1200e41f4b71Sopenharmony_ci 1201e41f4b71Sopenharmony_cifunction registerTorchStatusChange(cameraManager: camera.CameraManager): void { 1202e41f4b71Sopenharmony_ci cameraManager.on('torchStatusChange', callback); 1203e41f4b71Sopenharmony_ci} 1204e41f4b71Sopenharmony_ci``` 1205e41f4b71Sopenharmony_ci 1206e41f4b71Sopenharmony_ci### off('torchStatusChange')<sup>11+</sup> 1207e41f4b71Sopenharmony_ci 1208e41f4b71Sopenharmony_cioff(type: 'torchStatusChange', callback?: AsyncCallback\<TorchStatusInfo\>): void 1209e41f4b71Sopenharmony_ci 1210e41f4b71Sopenharmony_ciUnsubscribes from flashlight status change events. This API uses an asynchronous callback to return the result. 1211e41f4b71Sopenharmony_ci 1212e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 1213e41f4b71Sopenharmony_ci 1214e41f4b71Sopenharmony_ci**Parameters** 1215e41f4b71Sopenharmony_ci 1216e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 1217e41f4b71Sopenharmony_ci| -------- | --------------- | ---- | --------- | 1218e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'torchStatusChange'**. The event can be listened for when a **CameraManager** instance is obtained.| 1219e41f4b71Sopenharmony_ci| callback | AsyncCallback\<TorchStatusInfo> | No | Callback used to return the result. If this parameter is specified, the subscription to the specified event with the specified callback is canceled. (The callback object cannot be an anonymous function.) Otherwise, the subscriptions to the specified event with all the callbacks are canceled.| 1220e41f4b71Sopenharmony_ci 1221e41f4b71Sopenharmony_ci**Example** 1222e41f4b71Sopenharmony_ci 1223e41f4b71Sopenharmony_ci```ts 1224e41f4b71Sopenharmony_cifunction unregisterTorchStatusChange(cameraManager: camera.CameraManager): void { 1225e41f4b71Sopenharmony_ci cameraManager.off('torchStatusChange'); 1226e41f4b71Sopenharmony_ci} 1227e41f4b71Sopenharmony_ci``` 1228e41f4b71Sopenharmony_ci 1229e41f4b71Sopenharmony_ci## TorchMode<sup>11+</sup> 1230e41f4b71Sopenharmony_ci 1231e41f4b71Sopenharmony_ciEnumerates the flashlight modes. 1232e41f4b71Sopenharmony_ci 1233e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 1234e41f4b71Sopenharmony_ci 1235e41f4b71Sopenharmony_ci| Name | Value | Description | 1236e41f4b71Sopenharmony_ci| ---------------------------- | ---- | ------------- | 1237e41f4b71Sopenharmony_ci| OFF | 0 | The flashlight is off. | 1238e41f4b71Sopenharmony_ci| ON | 1 | The flashlight is on.| 1239e41f4b71Sopenharmony_ci| AUTO | 2 | The flashlight mode is auto.| 1240e41f4b71Sopenharmony_ci 1241e41f4b71Sopenharmony_ci## TorchStatusInfo<sup>11+</sup> 1242e41f4b71Sopenharmony_ci 1243e41f4b71Sopenharmony_ciDefines the flashlight status information. 1244e41f4b71Sopenharmony_ci 1245e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 1246e41f4b71Sopenharmony_ci 1247e41f4b71Sopenharmony_ci| Name | Type | Read-only| Optional| Description | 1248e41f4b71Sopenharmony_ci| ---------------- | ---------- | ---- | ---- | ----------- | 1249e41f4b71Sopenharmony_ci| isTorchAvailable | boolean | Yes | No | Whether the flashlight is available.| 1250e41f4b71Sopenharmony_ci| isTorchActive | boolean | Yes | No | Whether the flashlight is activated. | 1251e41f4b71Sopenharmony_ci| torchLevel | number | Yes | No | Flashlight level. The value range is [0, 1]. A larger value indicates a greater luminance. | 1252e41f4b71Sopenharmony_ci 1253e41f4b71Sopenharmony_ci## Size 1254e41f4b71Sopenharmony_ci 1255e41f4b71Sopenharmony_ciDefines the output capability. 1256e41f4b71Sopenharmony_ci 1257e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 1258e41f4b71Sopenharmony_ci 1259e41f4b71Sopenharmony_ci| Name | Type | Read-only| Optional | Description | 1260e41f4b71Sopenharmony_ci| ------ | ------ | ---- |-----| ------------ | 1261e41f4b71Sopenharmony_ci| height | number | No | No | Image height, in pixels.| 1262e41f4b71Sopenharmony_ci| width | number | No | No | Image width, in pixels.| 1263e41f4b71Sopenharmony_ci 1264e41f4b71Sopenharmony_ci## Point 1265e41f4b71Sopenharmony_ci 1266e41f4b71Sopenharmony_ciDefines the point coordinates, which are used for focus and exposure configuration. 1267e41f4b71Sopenharmony_ci 1268e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 1269e41f4b71Sopenharmony_ci 1270e41f4b71Sopenharmony_ci| Name | Type | Read-only | Optional | Description | 1271e41f4b71Sopenharmony_ci| ------ | ------ | ------ | ------ | ------------ | 1272e41f4b71Sopenharmony_ci| x | number | No | No | X coordinate of a point. | 1273e41f4b71Sopenharmony_ci| y | number | No | No | Y coordinate of a point. | 1274e41f4b71Sopenharmony_ci 1275e41f4b71Sopenharmony_ci## CameraFormat 1276e41f4b71Sopenharmony_ci 1277e41f4b71Sopenharmony_ciEnumerates the camera output formats. 1278e41f4b71Sopenharmony_ci 1279e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 1280e41f4b71Sopenharmony_ci 1281e41f4b71Sopenharmony_ci| Name | Value | Description | 1282e41f4b71Sopenharmony_ci| ----------------------- | --------- | ------------ | 1283e41f4b71Sopenharmony_ci| CAMERA_FORMAT_RGBA_8888 | 3 | RGBA_888 image. | 1284e41f4b71Sopenharmony_ci| CAMERA_FORMAT_YUV_420_SP| 1003 | YUV_420_SP image. | 1285e41f4b71Sopenharmony_ci| CAMERA_FORMAT_JPEG | 2000 | JPEG image. | 1286e41f4b71Sopenharmony_ci| CAMERA_FORMAT_YCBCR_P010<sup>11+</sup> | 2001 | YCBCR_P010 image. | 1287e41f4b71Sopenharmony_ci| CAMERA_FORMAT_YCRCB_P010<sup>11+</sup> | 2002 | YCRCB_P010 image. | 1288e41f4b71Sopenharmony_ci 1289e41f4b71Sopenharmony_ci## CameraInput 1290e41f4b71Sopenharmony_ci 1291e41f4b71Sopenharmony_ciDefines the camera input object. 1292e41f4b71Sopenharmony_ci 1293e41f4b71Sopenharmony_ciProvides camera device information used in [Session](#session11). 1294e41f4b71Sopenharmony_ci 1295e41f4b71Sopenharmony_ci### open 1296e41f4b71Sopenharmony_ci 1297e41f4b71Sopenharmony_ciopen(callback: AsyncCallback\<void\>): void 1298e41f4b71Sopenharmony_ci 1299e41f4b71Sopenharmony_ciOpens this camera device. This API uses an asynchronous callback to return the result. 1300e41f4b71Sopenharmony_ci 1301e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 1302e41f4b71Sopenharmony_ci 1303e41f4b71Sopenharmony_ci**Parameters** 1304e41f4b71Sopenharmony_ci 1305e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 1306e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ------------------- | 1307e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 1308e41f4b71Sopenharmony_ci 1309e41f4b71Sopenharmony_ci**Error codes** 1310e41f4b71Sopenharmony_ci 1311e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 1312e41f4b71Sopenharmony_ci 1313e41f4b71Sopenharmony_ci| ID | Error Message | 1314e41f4b71Sopenharmony_ci| --------------- | --------------- | 1315e41f4b71Sopenharmony_ci| 7400107 | Can not use camera cause of conflict. | 1316e41f4b71Sopenharmony_ci| 7400108 | Camera disabled cause of security reason. | 1317e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 1318e41f4b71Sopenharmony_ci 1319e41f4b71Sopenharmony_ci**Example** 1320e41f4b71Sopenharmony_ci 1321e41f4b71Sopenharmony_ci```ts 1322e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1323e41f4b71Sopenharmony_ci 1324e41f4b71Sopenharmony_cifunction openCameraInput(cameraInput: camera.CameraInput): void { 1325e41f4b71Sopenharmony_ci cameraInput.open((err: BusinessError) => { 1326e41f4b71Sopenharmony_ci if (err) { 1327e41f4b71Sopenharmony_ci console.error(`Failed to open the camera, error code: ${err.code}.`); 1328e41f4b71Sopenharmony_ci return; 1329e41f4b71Sopenharmony_ci } 1330e41f4b71Sopenharmony_ci console.info('Callback returned with camera opened.'); 1331e41f4b71Sopenharmony_ci }); 1332e41f4b71Sopenharmony_ci} 1333e41f4b71Sopenharmony_ci``` 1334e41f4b71Sopenharmony_ci 1335e41f4b71Sopenharmony_ci### open 1336e41f4b71Sopenharmony_ci 1337e41f4b71Sopenharmony_ciopen(): Promise\<void\> 1338e41f4b71Sopenharmony_ci 1339e41f4b71Sopenharmony_ciOpens this camera device. This API uses a promise to return the result. 1340e41f4b71Sopenharmony_ci 1341e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 1342e41f4b71Sopenharmony_ci 1343e41f4b71Sopenharmony_ci**Return value** 1344e41f4b71Sopenharmony_ci 1345e41f4b71Sopenharmony_ci| Type | Description | 1346e41f4b71Sopenharmony_ci| -------------- | ----------------------- | 1347e41f4b71Sopenharmony_ci| Promise\<void\> | Promise that returns no value.| 1348e41f4b71Sopenharmony_ci 1349e41f4b71Sopenharmony_ci**Error codes** 1350e41f4b71Sopenharmony_ci 1351e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 1352e41f4b71Sopenharmony_ci 1353e41f4b71Sopenharmony_ci| ID | Error Message | 1354e41f4b71Sopenharmony_ci| --------------- | --------------- | 1355e41f4b71Sopenharmony_ci| 7400107 | Can not use camera cause of conflict. | 1356e41f4b71Sopenharmony_ci| 7400108 | Camera disabled cause of security reason. | 1357e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 1358e41f4b71Sopenharmony_ci 1359e41f4b71Sopenharmony_ci**Example** 1360e41f4b71Sopenharmony_ci 1361e41f4b71Sopenharmony_ci```ts 1362e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1363e41f4b71Sopenharmony_ci 1364e41f4b71Sopenharmony_cifunction openCameraInput(cameraInput: camera.CameraInput): void { 1365e41f4b71Sopenharmony_ci cameraInput.open().then(() => { 1366e41f4b71Sopenharmony_ci console.info('Promise returned with camera opened.'); 1367e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 1368e41f4b71Sopenharmony_ci console.error(`Failed to open the camera, error code: ${error.code}.`); 1369e41f4b71Sopenharmony_ci }); 1370e41f4b71Sopenharmony_ci} 1371e41f4b71Sopenharmony_ci``` 1372e41f4b71Sopenharmony_ci 1373e41f4b71Sopenharmony_ci### open<sup>12+</sup> 1374e41f4b71Sopenharmony_ci 1375e41f4b71Sopenharmony_ciopen(isSecureEnabled: boolean): Promise\<bigint\> 1376e41f4b71Sopenharmony_ci 1377e41f4b71Sopenharmony_ciOpens this camera device and obtains the handle to the camera in secure mode. 1378e41f4b71Sopenharmony_ci 1379e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 1380e41f4b71Sopenharmony_ci 1381e41f4b71Sopenharmony_ci**Parameters** 1382e41f4b71Sopenharmony_ci 1383e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 1384e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- |-------------------------------------------------------------------------| 1385e41f4b71Sopenharmony_ci| isSecureEnabled | boolean | Yes | Whether the camera can be enabled in secure mode. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 1386e41f4b71Sopenharmony_ci 1387e41f4b71Sopenharmony_ci**Return value** 1388e41f4b71Sopenharmony_ci 1389e41f4b71Sopenharmony_ci| Type | Description | 1390e41f4b71Sopenharmony_ci| -------------- | ----------------------- | 1391e41f4b71Sopenharmony_ci| Promise\<bigint\> | Promise used to return the handle to the camera.| 1392e41f4b71Sopenharmony_ci 1393e41f4b71Sopenharmony_ci**Error codes** 1394e41f4b71Sopenharmony_ci 1395e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 1396e41f4b71Sopenharmony_ci 1397e41f4b71Sopenharmony_ci| ID | Error Message | 1398e41f4b71Sopenharmony_ci| --------------- | --------------- | 1399e41f4b71Sopenharmony_ci| 7400107 | Can not use camera cause of conflict. | 1400e41f4b71Sopenharmony_ci| 7400108 | Camera disabled cause of security reason. | 1401e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 1402e41f4b71Sopenharmony_ci 1403e41f4b71Sopenharmony_ci**Example** 1404e41f4b71Sopenharmony_ci 1405e41f4b71Sopenharmony_ci```ts 1406e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1407e41f4b71Sopenharmony_ci 1408e41f4b71Sopenharmony_cifunction openCameraInput(cameraInput: camera.CameraInput): void { 1409e41f4b71Sopenharmony_ci cameraInput.open(true).then(() => { 1410e41f4b71Sopenharmony_ci console.info('Promise returned with camera opened.'); 1411e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 1412e41f4b71Sopenharmony_ci console.error(`Failed to open the camera, error code: ${error.code}.`); 1413e41f4b71Sopenharmony_ci }); 1414e41f4b71Sopenharmony_ci} 1415e41f4b71Sopenharmony_ci``` 1416e41f4b71Sopenharmony_ci 1417e41f4b71Sopenharmony_ci### close 1418e41f4b71Sopenharmony_ci 1419e41f4b71Sopenharmony_ciclose(callback: AsyncCallback\<void\>\): void 1420e41f4b71Sopenharmony_ci 1421e41f4b71Sopenharmony_ciCloses this camera device. This API uses an asynchronous callback to return the result. 1422e41f4b71Sopenharmony_ci 1423e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 1424e41f4b71Sopenharmony_ci 1425e41f4b71Sopenharmony_ci**Parameters** 1426e41f4b71Sopenharmony_ci 1427e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 1428e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | -------------------- | 1429e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 1430e41f4b71Sopenharmony_ci 1431e41f4b71Sopenharmony_ci**Error codes** 1432e41f4b71Sopenharmony_ci 1433e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 1434e41f4b71Sopenharmony_ci 1435e41f4b71Sopenharmony_ci| ID | Error Message | 1436e41f4b71Sopenharmony_ci| --------------- | --------------- | 1437e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 1438e41f4b71Sopenharmony_ci 1439e41f4b71Sopenharmony_ci**Example** 1440e41f4b71Sopenharmony_ci 1441e41f4b71Sopenharmony_ci```ts 1442e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1443e41f4b71Sopenharmony_ci 1444e41f4b71Sopenharmony_cifunction closeCameraInput(cameraInput: camera.CameraInput): void { 1445e41f4b71Sopenharmony_ci cameraInput.close((err: BusinessError) => { 1446e41f4b71Sopenharmony_ci if (err) { 1447e41f4b71Sopenharmony_ci console.error(`Failed to close the cameras, error code: ${err.code}.`); 1448e41f4b71Sopenharmony_ci return; 1449e41f4b71Sopenharmony_ci } 1450e41f4b71Sopenharmony_ci console.info('Callback returned with camera closed.'); 1451e41f4b71Sopenharmony_ci }); 1452e41f4b71Sopenharmony_ci} 1453e41f4b71Sopenharmony_ci``` 1454e41f4b71Sopenharmony_ci 1455e41f4b71Sopenharmony_ci### close 1456e41f4b71Sopenharmony_ci 1457e41f4b71Sopenharmony_ciclose(): Promise\<void\> 1458e41f4b71Sopenharmony_ci 1459e41f4b71Sopenharmony_ciCloses this camera device. This API uses a promise to return the result. 1460e41f4b71Sopenharmony_ci 1461e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 1462e41f4b71Sopenharmony_ci 1463e41f4b71Sopenharmony_ci**Return value** 1464e41f4b71Sopenharmony_ci 1465e41f4b71Sopenharmony_ci| Type | Description | 1466e41f4b71Sopenharmony_ci| -------------- | ----------------------- | 1467e41f4b71Sopenharmony_ci| Promise\<void\> | Promise that returns no value.| 1468e41f4b71Sopenharmony_ci 1469e41f4b71Sopenharmony_ci**Error codes** 1470e41f4b71Sopenharmony_ci 1471e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 1472e41f4b71Sopenharmony_ci 1473e41f4b71Sopenharmony_ci| ID | Error Message | 1474e41f4b71Sopenharmony_ci| --------------- | --------------- | 1475e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 1476e41f4b71Sopenharmony_ci 1477e41f4b71Sopenharmony_ci**Example** 1478e41f4b71Sopenharmony_ci 1479e41f4b71Sopenharmony_ci```ts 1480e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1481e41f4b71Sopenharmony_ci 1482e41f4b71Sopenharmony_cifunction closeCameraInput(cameraInput: camera.CameraInput): void { 1483e41f4b71Sopenharmony_ci cameraInput.close().then(() => { 1484e41f4b71Sopenharmony_ci console.info('Promise returned with camera closed.'); 1485e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 1486e41f4b71Sopenharmony_ci console.error(`Failed to close the cameras, error code: ${error.code}.`); 1487e41f4b71Sopenharmony_ci }); 1488e41f4b71Sopenharmony_ci} 1489e41f4b71Sopenharmony_ci``` 1490e41f4b71Sopenharmony_ci 1491e41f4b71Sopenharmony_ci### on('error') 1492e41f4b71Sopenharmony_ci 1493e41f4b71Sopenharmony_cion(type: 'error', camera: CameraDevice, callback: ErrorCallback): void 1494e41f4b71Sopenharmony_ci 1495e41f4b71Sopenharmony_ciSubscribes to **CameraInput** error events. This API uses an asynchronous callback to return the result. 1496e41f4b71Sopenharmony_ci 1497e41f4b71Sopenharmony_ci> **NOTE** 1498e41f4b71Sopenharmony_ci> 1499e41f4b71Sopenharmony_ci> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**. 1500e41f4b71Sopenharmony_ci 1501e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 1502e41f4b71Sopenharmony_ci 1503e41f4b71Sopenharmony_ci**Parameters** 1504e41f4b71Sopenharmony_ci 1505e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 1506e41f4b71Sopenharmony_ci| -------- | -------------------------------- | --- | ------------------------------------------- | 1507e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a **CameraInput** instance is created. This event is triggered and the result is returned when an error occurs on the camera device. For example, if the camera device is unavailable or a conflict occurs, the error information is returned.| 1508e41f4b71Sopenharmony_ci| camera | [CameraDevice](#cameradevice) | Yes | Camera device.| 1509e41f4b71Sopenharmony_ci| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | Yes | Callback used to return an error code defined in [CameraErrorCode](#cameraerrorcode). | 1510e41f4b71Sopenharmony_ci 1511e41f4b71Sopenharmony_ci**Example** 1512e41f4b71Sopenharmony_ci 1513e41f4b71Sopenharmony_ci```ts 1514e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1515e41f4b71Sopenharmony_ci 1516e41f4b71Sopenharmony_cifunction callback(err: BusinessError): void { 1517e41f4b71Sopenharmony_ci console.error(`Camera input error code: ${err.code}`); 1518e41f4b71Sopenharmony_ci} 1519e41f4b71Sopenharmony_ci 1520e41f4b71Sopenharmony_cifunction registerCameraInputError(cameraInput: camera.CameraInput, camera: camera.CameraDevice): void { 1521e41f4b71Sopenharmony_ci cameraInput.on('error', camera, callback); 1522e41f4b71Sopenharmony_ci} 1523e41f4b71Sopenharmony_ci``` 1524e41f4b71Sopenharmony_ci 1525e41f4b71Sopenharmony_ci### off('error') 1526e41f4b71Sopenharmony_ci 1527e41f4b71Sopenharmony_cioff(type: 'error', camera: CameraDevice, callback?: ErrorCallback): void 1528e41f4b71Sopenharmony_ci 1529e41f4b71Sopenharmony_ciUnsubscribes from **CameraInput** error events. 1530e41f4b71Sopenharmony_ci 1531e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 1532e41f4b71Sopenharmony_ci 1533e41f4b71Sopenharmony_ci**Parameters** 1534e41f4b71Sopenharmony_ci 1535e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 1536e41f4b71Sopenharmony_ci| -------- | -------------------------------- | --- | ------------------------------------------- | 1537e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a **CameraInput** instance is created. This event is triggered and the result is returned when an error occurs on the camera device. For example, if the camera device is unavailable or a conflict occurs, the error information is returned.| 1538e41f4b71Sopenharmony_ci| camera | [CameraDevice](#cameradevice) | Yes | Camera device.| 1539e41f4b71Sopenharmony_ci| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | No | Callback used to return the result. If this parameter is specified, the subscription to the specified event with the specified callback is canceled. (The callback object cannot be an anonymous function.) Otherwise, the subscriptions to the specified event with all the callbacks are canceled.| 1540e41f4b71Sopenharmony_ci 1541e41f4b71Sopenharmony_ci**Example** 1542e41f4b71Sopenharmony_ci 1543e41f4b71Sopenharmony_ci```ts 1544e41f4b71Sopenharmony_cifunction unregisterCameraInputError(cameraInput: camera.CameraInput, camera: camera.CameraDevice): void { 1545e41f4b71Sopenharmony_ci cameraInput.off('error', camera); 1546e41f4b71Sopenharmony_ci} 1547e41f4b71Sopenharmony_ci``` 1548e41f4b71Sopenharmony_ci 1549e41f4b71Sopenharmony_ci## CameraOutput 1550e41f4b71Sopenharmony_ci 1551e41f4b71Sopenharmony_ciImplements output information used in [Session](#session11). It is the base class of **output**. 1552e41f4b71Sopenharmony_ci 1553e41f4b71Sopenharmony_ci### release 1554e41f4b71Sopenharmony_ci 1555e41f4b71Sopenharmony_cirelease(callback: AsyncCallback\<void\>): void 1556e41f4b71Sopenharmony_ci 1557e41f4b71Sopenharmony_ciReleases output resources. This API uses an asynchronous callback to return the result. 1558e41f4b71Sopenharmony_ci 1559e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 1560e41f4b71Sopenharmony_ci 1561e41f4b71Sopenharmony_ci**Parameters** 1562e41f4b71Sopenharmony_ci 1563e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 1564e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ------------------- | 1565e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 1566e41f4b71Sopenharmony_ci 1567e41f4b71Sopenharmony_ci**Error codes** 1568e41f4b71Sopenharmony_ci 1569e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 1570e41f4b71Sopenharmony_ci 1571e41f4b71Sopenharmony_ci| ID | Error Message | 1572e41f4b71Sopenharmony_ci| --------------- | --------------- | 1573e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 1574e41f4b71Sopenharmony_ci 1575e41f4b71Sopenharmony_ci**Example** 1576e41f4b71Sopenharmony_ci 1577e41f4b71Sopenharmony_ci```ts 1578e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1579e41f4b71Sopenharmony_ci 1580e41f4b71Sopenharmony_cifunction releasePreviewOutput(previewOutput: camera.PreviewOutput): void { 1581e41f4b71Sopenharmony_ci previewOutput.release((err: BusinessError) => { 1582e41f4b71Sopenharmony_ci if (err) { 1583e41f4b71Sopenharmony_ci console.error(`Failed to release the Preview output instance ${err.code}`); 1584e41f4b71Sopenharmony_ci return; 1585e41f4b71Sopenharmony_ci } 1586e41f4b71Sopenharmony_ci console.info('Callback invoked to indicate that the preview output instance is released successfully.'); 1587e41f4b71Sopenharmony_ci }); 1588e41f4b71Sopenharmony_ci} 1589e41f4b71Sopenharmony_ci 1590e41f4b71Sopenharmony_cifunction releaseVideoOutput(videoOutput: camera.VideoOutput): void { 1591e41f4b71Sopenharmony_ci videoOutput.release((err: BusinessError) => { 1592e41f4b71Sopenharmony_ci if (err) { 1593e41f4b71Sopenharmony_ci console.error(`Failed to release the video output instance ${err.code}`); 1594e41f4b71Sopenharmony_ci return; 1595e41f4b71Sopenharmony_ci } 1596e41f4b71Sopenharmony_ci console.info('Callback invoked to indicate that the video output instance is released successfully.'); 1597e41f4b71Sopenharmony_ci }); 1598e41f4b71Sopenharmony_ci} 1599e41f4b71Sopenharmony_ci``` 1600e41f4b71Sopenharmony_ci 1601e41f4b71Sopenharmony_ci### release 1602e41f4b71Sopenharmony_ci 1603e41f4b71Sopenharmony_cirelease(): Promise\<void\> 1604e41f4b71Sopenharmony_ci 1605e41f4b71Sopenharmony_ciReleases output resources. This API uses a promise to return the result. 1606e41f4b71Sopenharmony_ci 1607e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 1608e41f4b71Sopenharmony_ci 1609e41f4b71Sopenharmony_ci**Return value** 1610e41f4b71Sopenharmony_ci 1611e41f4b71Sopenharmony_ci| Type | Description | 1612e41f4b71Sopenharmony_ci| -------------- | ----------------------- | 1613e41f4b71Sopenharmony_ci| Promise\<void\> | Promise that returns no value.| 1614e41f4b71Sopenharmony_ci 1615e41f4b71Sopenharmony_ci**Error codes** 1616e41f4b71Sopenharmony_ci 1617e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 1618e41f4b71Sopenharmony_ci 1619e41f4b71Sopenharmony_ci| ID | Error Message | 1620e41f4b71Sopenharmony_ci| --------------- | --------------- | 1621e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 1622e41f4b71Sopenharmony_ci 1623e41f4b71Sopenharmony_ci**Example** 1624e41f4b71Sopenharmony_ci 1625e41f4b71Sopenharmony_ci```ts 1626e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1627e41f4b71Sopenharmony_ci 1628e41f4b71Sopenharmony_cifunction releasePreviewOutput(previewOutput: camera.PreviewOutput): void { 1629e41f4b71Sopenharmony_ci previewOutput.release().then(() => { 1630e41f4b71Sopenharmony_ci console.info('Promise returned to indicate that the preview output instance is released successfully.'); 1631e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 1632e41f4b71Sopenharmony_ci console.error(`Failed to preview output release, error code: ${error.code}`); 1633e41f4b71Sopenharmony_ci }); 1634e41f4b71Sopenharmony_ci} 1635e41f4b71Sopenharmony_ci 1636e41f4b71Sopenharmony_cifunction releaseVideoOutput(videoOutput: camera.VideoOutput): void { 1637e41f4b71Sopenharmony_ci videoOutput.release().then(() => { 1638e41f4b71Sopenharmony_ci console.info('Promise returned to indicate that the video output instance is released successfully.'); 1639e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 1640e41f4b71Sopenharmony_ci console.error(`Failed to video output release, error code: ${error.code}`); 1641e41f4b71Sopenharmony_ci }); 1642e41f4b71Sopenharmony_ci} 1643e41f4b71Sopenharmony_ci``` 1644e41f4b71Sopenharmony_ci 1645e41f4b71Sopenharmony_ci## PreviewOutput 1646e41f4b71Sopenharmony_ci 1647e41f4b71Sopenharmony_ciImplements preview output. It inherits from [CameraOutput](#cameraoutput). 1648e41f4b71Sopenharmony_ci 1649e41f4b71Sopenharmony_ci### start<sup>(deprecated)</sup> 1650e41f4b71Sopenharmony_ci 1651e41f4b71Sopenharmony_cistart(callback: AsyncCallback\<void\>): void 1652e41f4b71Sopenharmony_ci 1653e41f4b71Sopenharmony_ciStarts to output preview streams. This API uses an asynchronous callback to return the result. 1654e41f4b71Sopenharmony_ci 1655e41f4b71Sopenharmony_ci> **NOTE** 1656e41f4b71Sopenharmony_ci> 1657e41f4b71Sopenharmony_ci> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Session.start](#start11) instead. 1658e41f4b71Sopenharmony_ci 1659e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 1660e41f4b71Sopenharmony_ci 1661e41f4b71Sopenharmony_ci**Parameters** 1662e41f4b71Sopenharmony_ci 1663e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 1664e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | -------------------- | 1665e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 1666e41f4b71Sopenharmony_ci 1667e41f4b71Sopenharmony_ci**Error codes** 1668e41f4b71Sopenharmony_ci 1669e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 1670e41f4b71Sopenharmony_ci 1671e41f4b71Sopenharmony_ci| ID | Error Message | 1672e41f4b71Sopenharmony_ci| --------------- | --------------- | 1673e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 1674e41f4b71Sopenharmony_ci 1675e41f4b71Sopenharmony_ci**Example** 1676e41f4b71Sopenharmony_ci 1677e41f4b71Sopenharmony_ci```ts 1678e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1679e41f4b71Sopenharmony_ci 1680e41f4b71Sopenharmony_cifunction startPreviewOutput(previewOutput: camera.PreviewOutput): void { 1681e41f4b71Sopenharmony_ci previewOutput.start((err: BusinessError) => { 1682e41f4b71Sopenharmony_ci if (err) { 1683e41f4b71Sopenharmony_ci console.error(`Failed to start the preview output, error code: ${err.code}.`); 1684e41f4b71Sopenharmony_ci return; 1685e41f4b71Sopenharmony_ci } 1686e41f4b71Sopenharmony_ci console.info('Callback returned with preview output started.'); 1687e41f4b71Sopenharmony_ci }); 1688e41f4b71Sopenharmony_ci} 1689e41f4b71Sopenharmony_ci``` 1690e41f4b71Sopenharmony_ci 1691e41f4b71Sopenharmony_ci### start<sup>(deprecated)</sup> 1692e41f4b71Sopenharmony_ci 1693e41f4b71Sopenharmony_cistart(): Promise\<void\> 1694e41f4b71Sopenharmony_ci 1695e41f4b71Sopenharmony_ciStarts to output preview streams. This API uses a promise to return the result. 1696e41f4b71Sopenharmony_ci 1697e41f4b71Sopenharmony_ci> **NOTE** 1698e41f4b71Sopenharmony_ci> 1699e41f4b71Sopenharmony_ci> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Session.start](#start11-1) instead. 1700e41f4b71Sopenharmony_ci 1701e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 1702e41f4b71Sopenharmony_ci 1703e41f4b71Sopenharmony_ci**Return value** 1704e41f4b71Sopenharmony_ci 1705e41f4b71Sopenharmony_ci| Type | Description | 1706e41f4b71Sopenharmony_ci| -------------- |-------------------| 1707e41f4b71Sopenharmony_ci| Promise\<void\> | Promise that returns no value. | 1708e41f4b71Sopenharmony_ci 1709e41f4b71Sopenharmony_ci**Error codes** 1710e41f4b71Sopenharmony_ci 1711e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 1712e41f4b71Sopenharmony_ci 1713e41f4b71Sopenharmony_ci| ID | Error Message | 1714e41f4b71Sopenharmony_ci| --------------- | --------------- | 1715e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 1716e41f4b71Sopenharmony_ci 1717e41f4b71Sopenharmony_ci**Example** 1718e41f4b71Sopenharmony_ci 1719e41f4b71Sopenharmony_ci```ts 1720e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1721e41f4b71Sopenharmony_ci 1722e41f4b71Sopenharmony_cifunction startPreviewOutput(previewOutput: camera.PreviewOutput): void { 1723e41f4b71Sopenharmony_ci previewOutput.start().then(() => { 1724e41f4b71Sopenharmony_ci console.info('Promise returned with preview output started.'); 1725e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 1726e41f4b71Sopenharmony_ci console.error(`Failed to preview output start, error code: ${error.code}.`); 1727e41f4b71Sopenharmony_ci }); 1728e41f4b71Sopenharmony_ci} 1729e41f4b71Sopenharmony_ci``` 1730e41f4b71Sopenharmony_ci 1731e41f4b71Sopenharmony_ci### stop<sup>(deprecated)</sup> 1732e41f4b71Sopenharmony_ci 1733e41f4b71Sopenharmony_cistop(callback: AsyncCallback\<void\>): void 1734e41f4b71Sopenharmony_ci 1735e41f4b71Sopenharmony_ciStops outputting preview streams. This API uses an asynchronous callback to return the result. 1736e41f4b71Sopenharmony_ci 1737e41f4b71Sopenharmony_ci> **NOTE** 1738e41f4b71Sopenharmony_ci> 1739e41f4b71Sopenharmony_ci> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Session.stop](#stop11) instead. 1740e41f4b71Sopenharmony_ci 1741e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 1742e41f4b71Sopenharmony_ci 1743e41f4b71Sopenharmony_ci**Parameters** 1744e41f4b71Sopenharmony_ci 1745e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 1746e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | -------------------- | 1747e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| 1748e41f4b71Sopenharmony_ci 1749e41f4b71Sopenharmony_ci**Example** 1750e41f4b71Sopenharmony_ci 1751e41f4b71Sopenharmony_ci```ts 1752e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1753e41f4b71Sopenharmony_ci 1754e41f4b71Sopenharmony_cifunction stopPreviewOutput(previewOutput: camera.PreviewOutput): void { 1755e41f4b71Sopenharmony_ci previewOutput.stop((err: BusinessError) => { 1756e41f4b71Sopenharmony_ci if (err) { 1757e41f4b71Sopenharmony_ci console.error(`Failed to stop the preview output, error code: ${err.code}.`); 1758e41f4b71Sopenharmony_ci return; 1759e41f4b71Sopenharmony_ci } 1760e41f4b71Sopenharmony_ci console.info('Returned with preview output stopped.'); 1761e41f4b71Sopenharmony_ci }) 1762e41f4b71Sopenharmony_ci} 1763e41f4b71Sopenharmony_ci``` 1764e41f4b71Sopenharmony_ci 1765e41f4b71Sopenharmony_ci### stop<sup>(deprecated)</sup> 1766e41f4b71Sopenharmony_ci 1767e41f4b71Sopenharmony_cistop(): Promise\<void\> 1768e41f4b71Sopenharmony_ci 1769e41f4b71Sopenharmony_ciStops outputting preview streams. This API uses a promise to return the result. 1770e41f4b71Sopenharmony_ci 1771e41f4b71Sopenharmony_ci> **NOTE** 1772e41f4b71Sopenharmony_ci> 1773e41f4b71Sopenharmony_ci> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Session.stop](#stop11-1) instead. 1774e41f4b71Sopenharmony_ci 1775e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 1776e41f4b71Sopenharmony_ci 1777e41f4b71Sopenharmony_ci**Return value** 1778e41f4b71Sopenharmony_ci 1779e41f4b71Sopenharmony_ci| Type | Description | 1780e41f4b71Sopenharmony_ci| -------------- | ------------------------ | 1781e41f4b71Sopenharmony_ci| Promise\<void\> | Promise that returns no value.| 1782e41f4b71Sopenharmony_ci 1783e41f4b71Sopenharmony_ci**Example** 1784e41f4b71Sopenharmony_ci 1785e41f4b71Sopenharmony_ci```ts 1786e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1787e41f4b71Sopenharmony_ci 1788e41f4b71Sopenharmony_cifunction stopPreviewOutput(previewOutput: camera.PreviewOutput): void { 1789e41f4b71Sopenharmony_ci previewOutput.stop().then(() => { 1790e41f4b71Sopenharmony_ci console.info('Callback returned with preview output stopped.'); 1791e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 1792e41f4b71Sopenharmony_ci console.error(`Failed to preview output stop, error code: ${error.code}.`); 1793e41f4b71Sopenharmony_ci }); 1794e41f4b71Sopenharmony_ci} 1795e41f4b71Sopenharmony_ci``` 1796e41f4b71Sopenharmony_ci 1797e41f4b71Sopenharmony_ci### on('frameStart') 1798e41f4b71Sopenharmony_ci 1799e41f4b71Sopenharmony_cion(type: 'frameStart', callback: AsyncCallback\<void\>): void 1800e41f4b71Sopenharmony_ci 1801e41f4b71Sopenharmony_ciSubscribes to preview frame start events. This API uses an asynchronous callback to return the result. 1802e41f4b71Sopenharmony_ci 1803e41f4b71Sopenharmony_ci> **NOTE** 1804e41f4b71Sopenharmony_ci> 1805e41f4b71Sopenharmony_ci> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**. 1806e41f4b71Sopenharmony_ci 1807e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 1808e41f4b71Sopenharmony_ci 1809e41f4b71Sopenharmony_ci**Parameters** 1810e41f4b71Sopenharmony_ci 1811e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 1812e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | --------------------------------------- | 1813e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'frameStart'**. The event can be listened for when a **previewOutput** instance is created. This event is triggered and returned when the bottom layer starts exposure for the first time.| 1814e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. The preview starts as long as this event is returned. | 1815e41f4b71Sopenharmony_ci 1816e41f4b71Sopenharmony_ci**Example** 1817e41f4b71Sopenharmony_ci 1818e41f4b71Sopenharmony_ci```ts 1819e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1820e41f4b71Sopenharmony_ci 1821e41f4b71Sopenharmony_cifunction callback(err: BusinessError): void { 1822e41f4b71Sopenharmony_ci if (err !== undefined && err.code !== 0) { 1823e41f4b71Sopenharmony_ci console.error(`Callback Error, errorCode: ${err.code}`); 1824e41f4b71Sopenharmony_ci return; 1825e41f4b71Sopenharmony_ci } 1826e41f4b71Sopenharmony_ci console.info('Preview frame started'); 1827e41f4b71Sopenharmony_ci} 1828e41f4b71Sopenharmony_ci 1829e41f4b71Sopenharmony_cifunction registerPreviewOutputFrameStart(previewOutput: camera.PreviewOutput): void { 1830e41f4b71Sopenharmony_ci previewOutput.on('frameStart', callback); 1831e41f4b71Sopenharmony_ci} 1832e41f4b71Sopenharmony_ci``` 1833e41f4b71Sopenharmony_ci 1834e41f4b71Sopenharmony_ci### off('frameStart') 1835e41f4b71Sopenharmony_ci 1836e41f4b71Sopenharmony_cioff(type: 'frameStart', callback?: AsyncCallback\<void\>): void 1837e41f4b71Sopenharmony_ci 1838e41f4b71Sopenharmony_ciUnsubscribes from preview frame start events. 1839e41f4b71Sopenharmony_ci 1840e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 1841e41f4b71Sopenharmony_ci 1842e41f4b71Sopenharmony_ci**Parameters** 1843e41f4b71Sopenharmony_ci 1844e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 1845e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | --------------------------------------- | 1846e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'frameStart'**. The event can be listened for when a **previewOutput** instance is created.| 1847e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void\> | No | Callback used to return the result. If this parameter is specified, the subscription to the specified event with the specified callback is canceled. (The callback object cannot be an anonymous function.) Otherwise, the subscriptions to the specified event with all the callbacks are canceled.| 1848e41f4b71Sopenharmony_ci 1849e41f4b71Sopenharmony_ci**Example** 1850e41f4b71Sopenharmony_ci 1851e41f4b71Sopenharmony_ci```ts 1852e41f4b71Sopenharmony_cifunction unregisterPreviewOutputFrameStart(previewOutput: camera.PreviewOutput): void { 1853e41f4b71Sopenharmony_ci previewOutput.off('frameStart'); 1854e41f4b71Sopenharmony_ci} 1855e41f4b71Sopenharmony_ci``` 1856e41f4b71Sopenharmony_ci 1857e41f4b71Sopenharmony_ci### on('frameEnd') 1858e41f4b71Sopenharmony_ci 1859e41f4b71Sopenharmony_cion(type: 'frameEnd', callback: AsyncCallback\<void\>): void 1860e41f4b71Sopenharmony_ci 1861e41f4b71Sopenharmony_ciSubscribes to preview frame end events. This API uses an asynchronous callback to return the result. 1862e41f4b71Sopenharmony_ci 1863e41f4b71Sopenharmony_ci> **NOTE** 1864e41f4b71Sopenharmony_ci> 1865e41f4b71Sopenharmony_ci> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**. 1866e41f4b71Sopenharmony_ci 1867e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 1868e41f4b71Sopenharmony_ci 1869e41f4b71Sopenharmony_ci**Parameters** 1870e41f4b71Sopenharmony_ci 1871e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 1872e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ------------------------------------- | 1873e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'frameEnd'**. The event can be listened for when a **previewOutput** instance is created. This event is triggered and returned when the last frame of preview ends.| 1874e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. The preview ends as long as this event is returned. | 1875e41f4b71Sopenharmony_ci 1876e41f4b71Sopenharmony_ci**Example** 1877e41f4b71Sopenharmony_ci 1878e41f4b71Sopenharmony_ci```ts 1879e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1880e41f4b71Sopenharmony_ci 1881e41f4b71Sopenharmony_cifunction callback(err: BusinessError): void { 1882e41f4b71Sopenharmony_ci if (err !== undefined && err.code !== 0) { 1883e41f4b71Sopenharmony_ci console.error(`Callback Error, errorCode: ${err.code}`); 1884e41f4b71Sopenharmony_ci return; 1885e41f4b71Sopenharmony_ci } 1886e41f4b71Sopenharmony_ci console.info('Preview frame ended'); 1887e41f4b71Sopenharmony_ci} 1888e41f4b71Sopenharmony_ci 1889e41f4b71Sopenharmony_cifunction registerPreviewOutputFrameEnd(previewOutput: camera.PreviewOutput): void { 1890e41f4b71Sopenharmony_ci previewOutput.on('frameEnd', callback); 1891e41f4b71Sopenharmony_ci} 1892e41f4b71Sopenharmony_ci``` 1893e41f4b71Sopenharmony_ci 1894e41f4b71Sopenharmony_ci### off('frameEnd') 1895e41f4b71Sopenharmony_ci 1896e41f4b71Sopenharmony_cioff(type: 'frameEnd', callback?: AsyncCallback\<void\>): void 1897e41f4b71Sopenharmony_ci 1898e41f4b71Sopenharmony_ciUnsubscribes from preview frame end events. 1899e41f4b71Sopenharmony_ci 1900e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 1901e41f4b71Sopenharmony_ci 1902e41f4b71Sopenharmony_ci**Parameters** 1903e41f4b71Sopenharmony_ci 1904e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 1905e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ------------------------------------- | 1906e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'frameEnd'**. The event can be listened for when a **previewOutput** instance is created.| 1907e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void\> | No | Callback used to return the result. If this parameter is specified, the subscription to the specified event with the specified callback is canceled. (The callback object cannot be an anonymous function.) Otherwise, the subscriptions to the specified event with all the callbacks are canceled.| 1908e41f4b71Sopenharmony_ci 1909e41f4b71Sopenharmony_ci**Example** 1910e41f4b71Sopenharmony_ci 1911e41f4b71Sopenharmony_ci```ts 1912e41f4b71Sopenharmony_cifunction unregisterPreviewOutputFrameEnd(previewOutput: camera.PreviewOutput): void { 1913e41f4b71Sopenharmony_ci previewOutput.off('frameEnd'); 1914e41f4b71Sopenharmony_ci} 1915e41f4b71Sopenharmony_ci``` 1916e41f4b71Sopenharmony_ci 1917e41f4b71Sopenharmony_ci### on('error') 1918e41f4b71Sopenharmony_ci 1919e41f4b71Sopenharmony_cion(type: 'error', callback: ErrorCallback): void 1920e41f4b71Sopenharmony_ci 1921e41f4b71Sopenharmony_ciSubscribes to **PreviewOutput** error events. This API uses an asynchronous callback to return the result. 1922e41f4b71Sopenharmony_ci 1923e41f4b71Sopenharmony_ci> **NOTE** 1924e41f4b71Sopenharmony_ci> 1925e41f4b71Sopenharmony_ci> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**. 1926e41f4b71Sopenharmony_ci 1927e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 1928e41f4b71Sopenharmony_ci 1929e41f4b71Sopenharmony_ci**Parameters** 1930e41f4b71Sopenharmony_ci 1931e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 1932e41f4b71Sopenharmony_ci| -------- | --------------| ---- | ------------------------ | 1933e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a **previewOutput** instance is created. This event is triggered and the corresponding error message is returned when an error occurs during the use of a preview-related API such as [Session.start](#start11-1) or [CameraOutput.release](#release-1).| 1934e41f4b71Sopenharmony_ci| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | Yes | Callback used to return an error code defined in [CameraErrorCode](#cameraerrorcode). | 1935e41f4b71Sopenharmony_ci 1936e41f4b71Sopenharmony_ci**Example** 1937e41f4b71Sopenharmony_ci 1938e41f4b71Sopenharmony_ci```ts 1939e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1940e41f4b71Sopenharmony_ci 1941e41f4b71Sopenharmony_cifunction callback(previewOutputError: BusinessError): void { 1942e41f4b71Sopenharmony_ci console.error(`Preview output error code: ${previewOutputError.code}`); 1943e41f4b71Sopenharmony_ci} 1944e41f4b71Sopenharmony_ci 1945e41f4b71Sopenharmony_cifunction registerPreviewOutputError(previewOutput: camera.PreviewOutput): void { 1946e41f4b71Sopenharmony_ci previewOutput.on('error', callback) 1947e41f4b71Sopenharmony_ci} 1948e41f4b71Sopenharmony_ci``` 1949e41f4b71Sopenharmony_ci 1950e41f4b71Sopenharmony_ci### off('error') 1951e41f4b71Sopenharmony_ci 1952e41f4b71Sopenharmony_cioff(type: 'error', callback?: ErrorCallback): void 1953e41f4b71Sopenharmony_ci 1954e41f4b71Sopenharmony_ciUnsubscribes from **PreviewOutput** error events. 1955e41f4b71Sopenharmony_ci 1956e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 1957e41f4b71Sopenharmony_ci 1958e41f4b71Sopenharmony_ci**Parameters** 1959e41f4b71Sopenharmony_ci 1960e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 1961e41f4b71Sopenharmony_ci| -------- | --------------| ---- | ------------------------ | 1962e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a **previewOutput** instance is created.| 1963e41f4b71Sopenharmony_ci| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | No | Callback used to return the result. If this parameter is specified, the subscription to the specified event with the specified callback is canceled. (The callback object cannot be an anonymous function.) Otherwise, the subscriptions to the specified event with all the callbacks are canceled.| 1964e41f4b71Sopenharmony_ci 1965e41f4b71Sopenharmony_ci**Example** 1966e41f4b71Sopenharmony_ci 1967e41f4b71Sopenharmony_ci```ts 1968e41f4b71Sopenharmony_cifunction unregisterPreviewOutputError(previewOutput: camera.PreviewOutput): void { 1969e41f4b71Sopenharmony_ci previewOutput.off('error'); 1970e41f4b71Sopenharmony_ci} 1971e41f4b71Sopenharmony_ci``` 1972e41f4b71Sopenharmony_ci 1973e41f4b71Sopenharmony_ci### getSupportedFrameRates<sup>12+</sup> 1974e41f4b71Sopenharmony_ci 1975e41f4b71Sopenharmony_ci getSupportedFrameRates(): Array\<FrameRateRange\> 1976e41f4b71Sopenharmony_ci 1977e41f4b71Sopenharmony_ciObtains the supported frame rates. 1978e41f4b71Sopenharmony_ci 1979e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 1980e41f4b71Sopenharmony_ci 1981e41f4b71Sopenharmony_ci**Return value** 1982e41f4b71Sopenharmony_ci| Type | Description | 1983e41f4b71Sopenharmony_ci| ------------- | ------------ | 1984e41f4b71Sopenharmony_ci| Array<[FrameRateRange](#frameraterange)> | Array of supported frame rates.| 1985e41f4b71Sopenharmony_ci 1986e41f4b71Sopenharmony_ci**Example** 1987e41f4b71Sopenharmony_ci 1988e41f4b71Sopenharmony_ci```ts 1989e41f4b71Sopenharmony_cifunction getSupportedFrameRates(previewOutput: camera.PreviewOutput): Array<camera.FrameRateRange> { 1990e41f4b71Sopenharmony_ci let supportedFrameRatesArray: Array<camera.FrameRateRange> = previewOutput.getSupportedFrameRates(); 1991e41f4b71Sopenharmony_ci return supportedFrameRatesArray; 1992e41f4b71Sopenharmony_ci} 1993e41f4b71Sopenharmony_ci``` 1994e41f4b71Sopenharmony_ci 1995e41f4b71Sopenharmony_ci### setFrameRate<sup>12+</sup> 1996e41f4b71Sopenharmony_ci 1997e41f4b71Sopenharmony_cisetFrameRate(minFps: number, maxFps: number): void 1998e41f4b71Sopenharmony_ci 1999e41f4b71Sopenharmony_ciSets a frame rate range for preview streams. The range must be within the supported frame rate range, which can be obtained by calling [getSupportedFrameRates](#getsupportedframerates12). 2000e41f4b71Sopenharmony_ci 2001e41f4b71Sopenharmony_ci> **NOTE** 2002e41f4b71Sopenharmony_ci> 2003e41f4b71Sopenharmony_ci> This API is valid only in [VideoSession](#videosession11) mode. 2004e41f4b71Sopenharmony_ci 2005e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 2006e41f4b71Sopenharmony_ci 2007e41f4b71Sopenharmony_ci**Parameters** 2008e41f4b71Sopenharmony_ci 2009e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 2010e41f4b71Sopenharmony_ci| -------- | --------------| ---- | ------------------------ | 2011e41f4b71Sopenharmony_ci| minFps | number | Yes | Minimum frame rate.| 2012e41f4b71Sopenharmony_ci| maxFps | number | Yes | Maximum frame rate.| 2013e41f4b71Sopenharmony_ci 2014e41f4b71Sopenharmony_ci**Error codes** 2015e41f4b71Sopenharmony_ci 2016e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 2017e41f4b71Sopenharmony_ci 2018e41f4b71Sopenharmony_ci| ID | Error Message | 2019e41f4b71Sopenharmony_ci| --------------- | --------------- | 2020e41f4b71Sopenharmony_ci| 7400101 | Parameter missing or parameter type incorrect. | 2021e41f4b71Sopenharmony_ci| 7400110 | Unresolved conflicts with current configurations. | 2022e41f4b71Sopenharmony_ci 2023e41f4b71Sopenharmony_ci**Example** 2024e41f4b71Sopenharmony_ci 2025e41f4b71Sopenharmony_ci```ts 2026e41f4b71Sopenharmony_cifunction setFrameRateRange(previewOutput: camera.PreviewOutput, frameRateRange: Array<number>): void { 2027e41f4b71Sopenharmony_ci previewOutput.setFrameRate(frameRateRange[0], frameRateRange[1]); 2028e41f4b71Sopenharmony_ci} 2029e41f4b71Sopenharmony_ci``` 2030e41f4b71Sopenharmony_ci 2031e41f4b71Sopenharmony_ci### getActiveFrameRate<sup>12+</sup> 2032e41f4b71Sopenharmony_ci 2033e41f4b71Sopenharmony_cigetActiveFrameRate(): FrameRateRange 2034e41f4b71Sopenharmony_ci 2035e41f4b71Sopenharmony_ciObtains the configured frame rate range. 2036e41f4b71Sopenharmony_ci 2037e41f4b71Sopenharmony_ciThis API is valid only after [setFrameRate](#setframerate12) is called to set a frame rate range for preview streams. 2038e41f4b71Sopenharmony_ci 2039e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 2040e41f4b71Sopenharmony_ci 2041e41f4b71Sopenharmony_ci**Return value** 2042e41f4b71Sopenharmony_ci 2043e41f4b71Sopenharmony_ci| Type | Description | 2044e41f4b71Sopenharmony_ci| ------------- | ------------ | 2045e41f4b71Sopenharmony_ci| [FrameRateRange](#frameraterange) | Frame rate range.| 2046e41f4b71Sopenharmony_ci 2047e41f4b71Sopenharmony_ci**Example** 2048e41f4b71Sopenharmony_ci 2049e41f4b71Sopenharmony_ci```ts 2050e41f4b71Sopenharmony_cifunction getActiveFrameRate(previewOutput: camera.PreviewOutput): camera.FrameRateRange { 2051e41f4b71Sopenharmony_ci let activeFrameRate: camera.FrameRateRange = previewOutput.getActiveFrameRate(); 2052e41f4b71Sopenharmony_ci return activeFrameRate; 2053e41f4b71Sopenharmony_ci} 2054e41f4b71Sopenharmony_ci``` 2055e41f4b71Sopenharmony_ci 2056e41f4b71Sopenharmony_ci### getActiveProfile<sup>12+</sup> 2057e41f4b71Sopenharmony_ci 2058e41f4b71Sopenharmony_cigetActiveProfile(): Profile 2059e41f4b71Sopenharmony_ci 2060e41f4b71Sopenharmony_ciObtains the profile that takes effect currently. 2061e41f4b71Sopenharmony_ci 2062e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 2063e41f4b71Sopenharmony_ci 2064e41f4b71Sopenharmony_ci**Return value** 2065e41f4b71Sopenharmony_ci 2066e41f4b71Sopenharmony_ci| Type | Description | 2067e41f4b71Sopenharmony_ci| ------------- |-----------| 2068e41f4b71Sopenharmony_ci| [Profile](#profile) | Profile obtained.| 2069e41f4b71Sopenharmony_ci 2070e41f4b71Sopenharmony_ci**Error codes** 2071e41f4b71Sopenharmony_ci 2072e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 2073e41f4b71Sopenharmony_ci 2074e41f4b71Sopenharmony_ci| ID | Error Message | 2075e41f4b71Sopenharmony_ci|---------|------------------------------| 2076e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 2077e41f4b71Sopenharmony_ci 2078e41f4b71Sopenharmony_ci**Example** 2079e41f4b71Sopenharmony_ci 2080e41f4b71Sopenharmony_ci```ts 2081e41f4b71Sopenharmony_cifunction testGetActiveProfile(previewOutput: camera.PreviewOutput): camera.Profile | undefined { 2082e41f4b71Sopenharmony_ci let activeProfile: camera.Profile | undefined = undefined; 2083e41f4b71Sopenharmony_ci try { 2084e41f4b71Sopenharmony_ci activeProfile = previewOutput.getActiveProfile(); 2085e41f4b71Sopenharmony_ci } catch (error) { 2086e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 2087e41f4b71Sopenharmony_ci let err = error as BusinessError; 2088e41f4b71Sopenharmony_ci console.error(`The previewOutput.getActiveProfile call failed. error code: ${err.code}`); 2089e41f4b71Sopenharmony_ci } 2090e41f4b71Sopenharmony_ci return activeProfile; 2091e41f4b71Sopenharmony_ci} 2092e41f4b71Sopenharmony_ci``` 2093e41f4b71Sopenharmony_ci 2094e41f4b71Sopenharmony_ci### getPreviewRotation<sup>12+</sup> 2095e41f4b71Sopenharmony_ci 2096e41f4b71Sopenharmony_cigetPreviewRotation(imageRotation: ImageRotation): ImageRotation 2097e41f4b71Sopenharmony_ci 2098e41f4b71Sopenharmony_ciObtains the preview rotation degree. 2099e41f4b71Sopenharmony_ci 2100e41f4b71Sopenharmony_ci- Device' natural orientation: The default orientation of the device (phone) is in portrait mode, with the charging port facing downward. 2101e41f4b71Sopenharmony_ci- Camera lens angle: equivalent to the angle at which the camera is rotated clockwise to match the device's natural direction. The rear camera sensor of a phone is installed in portrait mode. Therefore, it needs to be rotated by 90 degrees clockwise to match the device's natural direction. 2102e41f4b71Sopenharmony_ci- Screen orientation: The upper left corner of the image displayed on the screen is the first pixel, which is the coordinate origin. In the case of lock screen, the direction is the same as the device's natural orientation. 2103e41f4b71Sopenharmony_ci 2104e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 2105e41f4b71Sopenharmony_ci 2106e41f4b71Sopenharmony_ci**Parameters** 2107e41f4b71Sopenharmony_ci 2108e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 2109e41f4b71Sopenharmony_ci| -------- | --------------| ---- | ------------------------ | 2110e41f4b71Sopenharmony_ci| imageRotation | [ImageRotation](#imagerotation) | Yes | Screen display compensation angle (the angle required for rotating the image counterclockwise from the device's natural orientation to the screen orientation during image display).| 2111e41f4b71Sopenharmony_ci 2112e41f4b71Sopenharmony_ci**Return value** 2113e41f4b71Sopenharmony_ci 2114e41f4b71Sopenharmony_ci| Type | Description | 2115e41f4b71Sopenharmony_ci| ------------- |-----------| 2116e41f4b71Sopenharmony_ci| [ImageRotation](#imagerotation) | Preview rotation degree.| 2117e41f4b71Sopenharmony_ci 2118e41f4b71Sopenharmony_ci**Error codes** 2119e41f4b71Sopenharmony_ci 2120e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 2121e41f4b71Sopenharmony_ci 2122e41f4b71Sopenharmony_ci| ID | Error Message | 2123e41f4b71Sopenharmony_ci|---------|------------------------------| 2124e41f4b71Sopenharmony_ci| 7400101 | Parameter missing or parameter type incorrect. | 2125e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 2126e41f4b71Sopenharmony_ci 2127e41f4b71Sopenharmony_ci**Example** 2128e41f4b71Sopenharmony_ci 2129e41f4b71Sopenharmony_ci```ts 2130e41f4b71Sopenharmony_cifunction testGetPreviewRotation(previewOutput: camera.PreviewOutput, imageRotation : camera.ImageRotation): camera.ImageRotation { 2131e41f4b71Sopenharmony_ci let previewRotation: camera.ImageRotation; 2132e41f4b71Sopenharmony_ci try { 2133e41f4b71Sopenharmony_ci previewRotation = previewOutput.getPreviewRotation(imageRotation); 2134e41f4b71Sopenharmony_ci console.log(`Preview rotation is: ${previewRotation}`); 2135e41f4b71Sopenharmony_ci } catch (error) { 2136e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 2137e41f4b71Sopenharmony_ci let err = error as BusinessError; 2138e41f4b71Sopenharmony_ci console.error(`The previewOutput.getPreviewRotation call failed. error code: ${err.code}`); 2139e41f4b71Sopenharmony_ci } 2140e41f4b71Sopenharmony_ci return; 2141e41f4b71Sopenharmony_ci} 2142e41f4b71Sopenharmony_ci``` 2143e41f4b71Sopenharmony_ci### setPreviewRotation<sup>12+</sup> 2144e41f4b71Sopenharmony_cisetPreviewRotation(previewRotation: Imagerotation, isDisplayLocked?: boolean): void 2145e41f4b71Sopenharmony_ci 2146e41f4b71Sopenharmony_ciSets the preview rotation degree. 2147e41f4b71Sopenharmony_ci 2148e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 2149e41f4b71Sopenharmony_ci 2150e41f4b71Sopenharmony_ci**Parameters** 2151e41f4b71Sopenharmony_ci 2152e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 2153e41f4b71Sopenharmony_ci| -------- | --------------| ---- | ------------------------ | 2154e41f4b71Sopenharmony_ci| previewRotation | [ImageRotation](#imagerotation) | Yes | Preview rotation angle.| 2155e41f4b71Sopenharmony_ci| isDisplayLocked | boolean | No | Whether the display is locked.| 2156e41f4b71Sopenharmony_ci 2157e41f4b71Sopenharmony_ci**Error codes** 2158e41f4b71Sopenharmony_ci 2159e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 2160e41f4b71Sopenharmony_ci 2161e41f4b71Sopenharmony_ci| ID | Error Message | 2162e41f4b71Sopenharmony_ci|---------|------------------------------| 2163e41f4b71Sopenharmony_ci| 7400101 | Parameter missing or parameter type incorrect. | 2164e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 2165e41f4b71Sopenharmony_ci 2166e41f4b71Sopenharmony_ci**Example** 2167e41f4b71Sopenharmony_ci 2168e41f4b71Sopenharmony_ci```ts 2169e41f4b71Sopenharmony_cifunction testSetPreviewRotation(previewOutput: camera.PreviewOutput, previewRotation : camera.ImageRotation, isDisplayLocked: boolean): void { 2170e41f4b71Sopenharmony_ci let previewRotation: camera.ImageRotation; 2171e41f4b71Sopenharmony_ci try { 2172e41f4b71Sopenharmony_ci previewOutput.setPreviewRotation(previewRotation, isDisplayLocked); 2173e41f4b71Sopenharmony_ci } catch (error) { 2174e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 2175e41f4b71Sopenharmony_ci let err = error as BusinessError; 2176e41f4b71Sopenharmony_ci console.error(`The previewOutput.setPreviewRotation call failed. error code: ${err.code}`); 2177e41f4b71Sopenharmony_ci } 2178e41f4b71Sopenharmony_ci return; 2179e41f4b71Sopenharmony_ci} 2180e41f4b71Sopenharmony_ci``` 2181e41f4b71Sopenharmony_ci## ImageRotation 2182e41f4b71Sopenharmony_ci 2183e41f4b71Sopenharmony_ciEnumerates the image rotation angles. 2184e41f4b71Sopenharmony_ci 2185e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 2186e41f4b71Sopenharmony_ci 2187e41f4b71Sopenharmony_ci| Name | Value | Description | 2188e41f4b71Sopenharmony_ci| ------------ | ---- | ------------- | 2189e41f4b71Sopenharmony_ci| ROTATION_0 | 0 | The image rotates 0 degrees. | 2190e41f4b71Sopenharmony_ci| ROTATION_90 | 90 | The image rotates 90 degrees. | 2191e41f4b71Sopenharmony_ci| ROTATION_180 | 180 | The image rotates 180 degrees.| 2192e41f4b71Sopenharmony_ci| ROTATION_270 | 270 | The image rotates 270 degrees.| 2193e41f4b71Sopenharmony_ci 2194e41f4b71Sopenharmony_ci## Location 2195e41f4b71Sopenharmony_ci 2196e41f4b71Sopenharmony_ciDefines the geolocation information. 2197e41f4b71Sopenharmony_ci 2198e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 2199e41f4b71Sopenharmony_ci 2200e41f4b71Sopenharmony_ci| Name | Type | Read-only| Optional |Description | 2201e41f4b71Sopenharmony_ci| ------------ | ------ | ---- |-----|------------ | 2202e41f4b71Sopenharmony_ci| latitude | number | No | No |Latitude, in degrees. | 2203e41f4b71Sopenharmony_ci| longitude | number | No | No |Longitude, in degrees. | 2204e41f4b71Sopenharmony_ci| altitude | number | No | No |Altitude, in meters. | 2205e41f4b71Sopenharmony_ci 2206e41f4b71Sopenharmony_ci## QualityLevel 2207e41f4b71Sopenharmony_ci 2208e41f4b71Sopenharmony_ciEnumerates the image quality levels. 2209e41f4b71Sopenharmony_ci 2210e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 2211e41f4b71Sopenharmony_ci 2212e41f4b71Sopenharmony_ci| Name | Value | Description | 2213e41f4b71Sopenharmony_ci| -------------------- | ---- | ------------ | 2214e41f4b71Sopenharmony_ci| QUALITY_LEVEL_HIGH | 0 | High image quality. | 2215e41f4b71Sopenharmony_ci| QUALITY_LEVEL_MEDIUM | 1 | Medium image quality.| 2216e41f4b71Sopenharmony_ci| QUALITY_LEVEL_LOW | 2 | Low image quality. | 2217e41f4b71Sopenharmony_ci 2218e41f4b71Sopenharmony_ci 2219e41f4b71Sopenharmony_ci## PhotoCaptureSetting 2220e41f4b71Sopenharmony_ci 2221e41f4b71Sopenharmony_ciDefines the settings for taking an image. 2222e41f4b71Sopenharmony_ci 2223e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 2224e41f4b71Sopenharmony_ci 2225e41f4b71Sopenharmony_ci| Name | Type | Read-only| Optional| Description | 2226e41f4b71Sopenharmony_ci| -------- | ------------------------------- | ---- | ---- |----------------------------------------------------------------------| 2227e41f4b71Sopenharmony_ci| quality | [QualityLevel](#qualitylevel) | No | Yes | Image quality (low by default). | 2228e41f4b71Sopenharmony_ci| rotation | [ImageRotation](#imagerotation) | No | Yes | Rotation angle of the image. The default value is **0**, indicating clockwise rotation. | 2229e41f4b71Sopenharmony_ci| location | [Location](#location) | No | Yes | Geolocation information of the image (depending on the device hardware information by default). | 2230e41f4b71Sopenharmony_ci| mirror | boolean | No | Yes | Whether mirror photography is enabled (disabled by default). Before using this enumerated value, call [isMirrorSupported](#ismirrorsupported) to check whether mirror photography is supported.| 2231e41f4b71Sopenharmony_ci 2232e41f4b71Sopenharmony_ci## Photo<sup>11+</sup> 2233e41f4b71Sopenharmony_ci 2234e41f4b71Sopenharmony_ciDefines a higher-resolution image object. 2235e41f4b71Sopenharmony_ci 2236e41f4b71Sopenharmony_ci### Attributes 2237e41f4b71Sopenharmony_ci 2238e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 2239e41f4b71Sopenharmony_ci 2240e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 2241e41f4b71Sopenharmony_ci| ------ | ----------------------------- | -------------- | ---------- | 2242e41f4b71Sopenharmony_ci| main<sup>11+</sup> | [image.Image](../apis-image-kit/js-apis-image.md#image9) | Yes | Higher-resolution image.| 2243e41f4b71Sopenharmony_ci 2244e41f4b71Sopenharmony_ci### release<sup>11+</sup> 2245e41f4b71Sopenharmony_ci 2246e41f4b71Sopenharmony_cirelease(): Promise\<void\> 2247e41f4b71Sopenharmony_ci 2248e41f4b71Sopenharmony_ciReleases output resources. This API uses a promise to return the result. 2249e41f4b71Sopenharmony_ci 2250e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 2251e41f4b71Sopenharmony_ci 2252e41f4b71Sopenharmony_ci**Return value** 2253e41f4b71Sopenharmony_ci 2254e41f4b71Sopenharmony_ci| Type | Description | 2255e41f4b71Sopenharmony_ci| -------------- | ----------------------- | 2256e41f4b71Sopenharmony_ci| Promise\<void\> | Promise that returns no value.| 2257e41f4b71Sopenharmony_ci 2258e41f4b71Sopenharmony_ci**Example** 2259e41f4b71Sopenharmony_ci 2260e41f4b71Sopenharmony_ci```ts 2261e41f4b71Sopenharmony_ciasync function releasePhoto(photo: camera.Photo): Promise<void> { 2262e41f4b71Sopenharmony_ci await photo.release(); 2263e41f4b71Sopenharmony_ci} 2264e41f4b71Sopenharmony_ci``` 2265e41f4b71Sopenharmony_ci 2266e41f4b71Sopenharmony_ci## PhotoOutput 2267e41f4b71Sopenharmony_ci 2268e41f4b71Sopenharmony_ciImplements output information used in a photo session. It inherits from [CameraOutput](#cameraoutput). 2269e41f4b71Sopenharmony_ci 2270e41f4b71Sopenharmony_ci### capture 2271e41f4b71Sopenharmony_ci 2272e41f4b71Sopenharmony_cicapture(callback: AsyncCallback\<void\>): void 2273e41f4b71Sopenharmony_ci 2274e41f4b71Sopenharmony_ciCaptures a photo with the default photo capture parameters. This API uses an asynchronous callback to return the result. 2275e41f4b71Sopenharmony_ci 2276e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 2277e41f4b71Sopenharmony_ci 2278e41f4b71Sopenharmony_ci**Parameters** 2279e41f4b71Sopenharmony_ci 2280e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 2281e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ------------------- | 2282e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 2283e41f4b71Sopenharmony_ci 2284e41f4b71Sopenharmony_ci**Error codes** 2285e41f4b71Sopenharmony_ci 2286e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 2287e41f4b71Sopenharmony_ci 2288e41f4b71Sopenharmony_ci| ID | Error Message | 2289e41f4b71Sopenharmony_ci| --------------- | --------------- | 2290e41f4b71Sopenharmony_ci| 7400104 | Session not running. | 2291e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 2292e41f4b71Sopenharmony_ci 2293e41f4b71Sopenharmony_ci**Example** 2294e41f4b71Sopenharmony_ci 2295e41f4b71Sopenharmony_ci```ts 2296e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 2297e41f4b71Sopenharmony_ci 2298e41f4b71Sopenharmony_cifunction capture(photoOutput: camera.PhotoOutput): void { 2299e41f4b71Sopenharmony_ci photoOutput.capture((err: BusinessError) => { 2300e41f4b71Sopenharmony_ci if (err) { 2301e41f4b71Sopenharmony_ci console.error(`Failed to capture the photo, error code: ${err.code}.`); 2302e41f4b71Sopenharmony_ci return; 2303e41f4b71Sopenharmony_ci } 2304e41f4b71Sopenharmony_ci console.info('Callback invoked to indicate the photo capture request success.'); 2305e41f4b71Sopenharmony_ci }); 2306e41f4b71Sopenharmony_ci} 2307e41f4b71Sopenharmony_ci``` 2308e41f4b71Sopenharmony_ci 2309e41f4b71Sopenharmony_ci### capture 2310e41f4b71Sopenharmony_ci 2311e41f4b71Sopenharmony_cicapture(): Promise\<void\> 2312e41f4b71Sopenharmony_ci 2313e41f4b71Sopenharmony_ciCaptures a photo with the default photo capture parameters. This API uses a promise to return the result. 2314e41f4b71Sopenharmony_ci 2315e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 2316e41f4b71Sopenharmony_ci 2317e41f4b71Sopenharmony_ci**Return value** 2318e41f4b71Sopenharmony_ci 2319e41f4b71Sopenharmony_ci| Type | Description | 2320e41f4b71Sopenharmony_ci| -------------- | ------------------------ | 2321e41f4b71Sopenharmony_ci| Promise\<void\> | Promise that returns no value.| 2322e41f4b71Sopenharmony_ci 2323e41f4b71Sopenharmony_ci**Error codes** 2324e41f4b71Sopenharmony_ci 2325e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 2326e41f4b71Sopenharmony_ci 2327e41f4b71Sopenharmony_ci| ID | Error Message | 2328e41f4b71Sopenharmony_ci| --------------- | --------------- | 2329e41f4b71Sopenharmony_ci| 7400104 | Session not running. | 2330e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 2331e41f4b71Sopenharmony_ci 2332e41f4b71Sopenharmony_ci**Example** 2333e41f4b71Sopenharmony_ci 2334e41f4b71Sopenharmony_ci```ts 2335e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 2336e41f4b71Sopenharmony_ci 2337e41f4b71Sopenharmony_cifunction capture(photoOutput: camera.PhotoOutput): void { 2338e41f4b71Sopenharmony_ci photoOutput.capture().then(() => { 2339e41f4b71Sopenharmony_ci console.info('Promise returned to indicate that photo capture request success.'); 2340e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 2341e41f4b71Sopenharmony_ci console.error(`Failed to photo output capture, error code: ${error.code}.`); 2342e41f4b71Sopenharmony_ci }); 2343e41f4b71Sopenharmony_ci} 2344e41f4b71Sopenharmony_ci``` 2345e41f4b71Sopenharmony_ci 2346e41f4b71Sopenharmony_ci### capture 2347e41f4b71Sopenharmony_ci 2348e41f4b71Sopenharmony_cicapture(setting: PhotoCaptureSetting, callback: AsyncCallback\<void\>): void 2349e41f4b71Sopenharmony_ci 2350e41f4b71Sopenharmony_ciCaptures a photo with the specified photo capture parameters. This API uses an asynchronous callback to return the result. 2351e41f4b71Sopenharmony_ci 2352e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 2353e41f4b71Sopenharmony_ci 2354e41f4b71Sopenharmony_ci**Parameters** 2355e41f4b71Sopenharmony_ci 2356e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 2357e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | ---- | -------------------- | 2358e41f4b71Sopenharmony_ci| setting | [PhotoCaptureSetting](#photocapturesetting) | Yes | Photo capture settings. | 2359e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned. | 2360e41f4b71Sopenharmony_ci 2361e41f4b71Sopenharmony_ci**Error codes** 2362e41f4b71Sopenharmony_ci 2363e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 2364e41f4b71Sopenharmony_ci 2365e41f4b71Sopenharmony_ci| ID | Error Message | 2366e41f4b71Sopenharmony_ci| --------------- | --------------- | 2367e41f4b71Sopenharmony_ci| 7400101 | Parameter missing or parameter type incorrect. | 2368e41f4b71Sopenharmony_ci| 7400104 | Session not running. | 2369e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 2370e41f4b71Sopenharmony_ci 2371e41f4b71Sopenharmony_ci**Example** 2372e41f4b71Sopenharmony_ci 2373e41f4b71Sopenharmony_ci```ts 2374e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 2375e41f4b71Sopenharmony_ci 2376e41f4b71Sopenharmony_cifunction capture(photoOutput: camera.PhotoOutput): void { 2377e41f4b71Sopenharmony_ci let captureLocation: camera.Location = { 2378e41f4b71Sopenharmony_ci latitude: 0, 2379e41f4b71Sopenharmony_ci longitude: 0, 2380e41f4b71Sopenharmony_ci altitude: 0 2381e41f4b71Sopenharmony_ci } 2382e41f4b71Sopenharmony_ci let settings: camera.PhotoCaptureSetting = { 2383e41f4b71Sopenharmony_ci quality: camera.QualityLevel.QUALITY_LEVEL_LOW, 2384e41f4b71Sopenharmony_ci rotation: camera.ImageRotation.ROTATION_0, 2385e41f4b71Sopenharmony_ci location: captureLocation, 2386e41f4b71Sopenharmony_ci mirror: false 2387e41f4b71Sopenharmony_ci } 2388e41f4b71Sopenharmony_ci photoOutput.capture(settings, (err: BusinessError) => { 2389e41f4b71Sopenharmony_ci if (err) { 2390e41f4b71Sopenharmony_ci console.error(`Failed to capture the photo, error code: ${err.code}.`); 2391e41f4b71Sopenharmony_ci return; 2392e41f4b71Sopenharmony_ci } 2393e41f4b71Sopenharmony_ci console.info('Callback invoked to indicate the photo capture request success.'); 2394e41f4b71Sopenharmony_ci }); 2395e41f4b71Sopenharmony_ci} 2396e41f4b71Sopenharmony_ci``` 2397e41f4b71Sopenharmony_ci 2398e41f4b71Sopenharmony_ci### capture 2399e41f4b71Sopenharmony_ci 2400e41f4b71Sopenharmony_cicapture(setting: PhotoCaptureSetting): Promise\<void\> 2401e41f4b71Sopenharmony_ci 2402e41f4b71Sopenharmony_ciCaptures a photo with the specified photo capture parameters. This API uses a promise to return the result. 2403e41f4b71Sopenharmony_ci 2404e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 2405e41f4b71Sopenharmony_ci 2406e41f4b71Sopenharmony_ci**Parameters** 2407e41f4b71Sopenharmony_ci 2408e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 2409e41f4b71Sopenharmony_ci| ------- | ------------------------------------------- | ---- | -------- | 2410e41f4b71Sopenharmony_ci| setting | [PhotoCaptureSetting](#photocapturesetting) | Yes | Photo capture parameters. The input of **undefined** is processed as if no parameters were passed.| 2411e41f4b71Sopenharmony_ci 2412e41f4b71Sopenharmony_ci**Return value** 2413e41f4b71Sopenharmony_ci 2414e41f4b71Sopenharmony_ci| Type | Description | 2415e41f4b71Sopenharmony_ci| -------------- | ------------------------ | 2416e41f4b71Sopenharmony_ci| Promise\<void\> | Promise that returns no value.| 2417e41f4b71Sopenharmony_ci 2418e41f4b71Sopenharmony_ci**Error codes** 2419e41f4b71Sopenharmony_ci 2420e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 2421e41f4b71Sopenharmony_ci 2422e41f4b71Sopenharmony_ci| ID | Error Message | 2423e41f4b71Sopenharmony_ci| --------------- | --------------- | 2424e41f4b71Sopenharmony_ci| 7400101 | Parameter missing or parameter type incorrect. | 2425e41f4b71Sopenharmony_ci| 7400104 | Session not running. | 2426e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 2427e41f4b71Sopenharmony_ci 2428e41f4b71Sopenharmony_ci**Example** 2429e41f4b71Sopenharmony_ci 2430e41f4b71Sopenharmony_ci```ts 2431e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 2432e41f4b71Sopenharmony_ci 2433e41f4b71Sopenharmony_cifunction capture(photoOutput: camera.PhotoOutput): void { 2434e41f4b71Sopenharmony_ci let captureLocation: camera.Location = { 2435e41f4b71Sopenharmony_ci latitude: 0, 2436e41f4b71Sopenharmony_ci longitude: 0, 2437e41f4b71Sopenharmony_ci altitude: 0 2438e41f4b71Sopenharmony_ci } 2439e41f4b71Sopenharmony_ci let settings: camera.PhotoCaptureSetting = { 2440e41f4b71Sopenharmony_ci quality: camera.QualityLevel.QUALITY_LEVEL_LOW, 2441e41f4b71Sopenharmony_ci rotation: camera.ImageRotation.ROTATION_0, 2442e41f4b71Sopenharmony_ci location: captureLocation, 2443e41f4b71Sopenharmony_ci mirror: false 2444e41f4b71Sopenharmony_ci } 2445e41f4b71Sopenharmony_ci photoOutput.capture(settings).then(() => { 2446e41f4b71Sopenharmony_ci console.info('Promise returned to indicate that photo capture request success.'); 2447e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 2448e41f4b71Sopenharmony_ci console.error(`Failed to photo output capture, error code: ${error.code}.`); 2449e41f4b71Sopenharmony_ci }); 2450e41f4b71Sopenharmony_ci} 2451e41f4b71Sopenharmony_ci``` 2452e41f4b71Sopenharmony_ci 2453e41f4b71Sopenharmony_ci### on('photoAvailable')<sup>11+</sup> 2454e41f4b71Sopenharmony_ci 2455e41f4b71Sopenharmony_cion(type: 'photoAvailable', callback: AsyncCallback\<Photo\>): void 2456e41f4b71Sopenharmony_ci 2457e41f4b71Sopenharmony_ciSubscribes to events indicating available high-resolution images. This API uses an asynchronous callback to return the result. 2458e41f4b71Sopenharmony_ci 2459e41f4b71Sopenharmony_ci> **NOTE** 2460e41f4b71Sopenharmony_ci> 2461e41f4b71Sopenharmony_ci> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**. 2462e41f4b71Sopenharmony_ci 2463e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 2464e41f4b71Sopenharmony_ci 2465e41f4b71Sopenharmony_ci**Parameters** 2466e41f4b71Sopenharmony_ci 2467e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 2468e41f4b71Sopenharmony_ci| -------- | ---------- | --- | ------------------------------------ | 2469e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'photoAvailable'**. The event can be listened for when a **photoOutput** instance is created.| 2470e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[Photo](#photo11)\> | Yes | Callback used to return the high-resolution image.| 2471e41f4b71Sopenharmony_ci 2472e41f4b71Sopenharmony_ci**Example** 2473e41f4b71Sopenharmony_ci 2474e41f4b71Sopenharmony_ci```ts 2475e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 2476e41f4b71Sopenharmony_ciimport { image } from '@kit.ImageKit'; 2477e41f4b71Sopenharmony_ci 2478e41f4b71Sopenharmony_cifunction callback(err: BusinessError, photo: camera.Photo): void { 2479e41f4b71Sopenharmony_ci if (err !== undefined && err.code !== 0) { 2480e41f4b71Sopenharmony_ci console.error(`Callback Error, errorCode: ${err.code}`); 2481e41f4b71Sopenharmony_ci return; 2482e41f4b71Sopenharmony_ci } 2483e41f4b71Sopenharmony_ci let mainImage: image.Image = photo.main; 2484e41f4b71Sopenharmony_ci} 2485e41f4b71Sopenharmony_ci 2486e41f4b71Sopenharmony_cifunction registerPhotoOutputPhotoAvailable(photoOutput: camera.PhotoOutput): void { 2487e41f4b71Sopenharmony_ci photoOutput.on('photoAvailable', callback); 2488e41f4b71Sopenharmony_ci} 2489e41f4b71Sopenharmony_ci``` 2490e41f4b71Sopenharmony_ci 2491e41f4b71Sopenharmony_ci### off('photoAvailable')<sup>11+</sup> 2492e41f4b71Sopenharmony_ci 2493e41f4b71Sopenharmony_cioff(type: 'photoAvailable', callback?: AsyncCallback\<Photo\>): void 2494e41f4b71Sopenharmony_ci 2495e41f4b71Sopenharmony_ciUnsubscribes from events indicating available high-resolution images. 2496e41f4b71Sopenharmony_ci 2497e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 2498e41f4b71Sopenharmony_ci 2499e41f4b71Sopenharmony_ci**Parameters** 2500e41f4b71Sopenharmony_ci 2501e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 2502e41f4b71Sopenharmony_ci| -------- | ---------------------- | ---- | ------------------------------------------ | 2503e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'photoAvailable'**. The event can be listened for when a **photoOutput** instance is created.| 2504e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[Photo](#photo11)\> | No | Callback used to return the result. If this parameter is specified, the subscription to the specified event with the specified callback is canceled. (The callback object cannot be an anonymous function.) Otherwise, the subscriptions to the specified event with all the callbacks are canceled.| 2505e41f4b71Sopenharmony_ci 2506e41f4b71Sopenharmony_ci**Example** 2507e41f4b71Sopenharmony_ci 2508e41f4b71Sopenharmony_ci```ts 2509e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 2510e41f4b71Sopenharmony_ciimport { image } from '@kit.ImageKit'; 2511e41f4b71Sopenharmony_ci 2512e41f4b71Sopenharmony_cifunction callback(err: BusinessError, photo: camera.Photo): void { 2513e41f4b71Sopenharmony_ci if (err !== undefined && err.code !== 0) { 2514e41f4b71Sopenharmony_ci console.error(`Callback Error, errorCode: ${err.code}`); 2515e41f4b71Sopenharmony_ci return; 2516e41f4b71Sopenharmony_ci } 2517e41f4b71Sopenharmony_ci let mainImage: image.Image = photo.main; 2518e41f4b71Sopenharmony_ci} 2519e41f4b71Sopenharmony_ci 2520e41f4b71Sopenharmony_cifunction unRegisterPhotoOutputPhotoAvailable(photoOutput: camera.PhotoOutput): void { 2521e41f4b71Sopenharmony_ci photoOutput.off('photoAvailable', callback); 2522e41f4b71Sopenharmony_ci} 2523e41f4b71Sopenharmony_ci``` 2524e41f4b71Sopenharmony_ci 2525e41f4b71Sopenharmony_ci### on('captureStartWithInfo')<sup>11+</sup> 2526e41f4b71Sopenharmony_ci 2527e41f4b71Sopenharmony_cion(type: 'captureStartWithInfo', callback: AsyncCallback\<CaptureStartInfo\>): void 2528e41f4b71Sopenharmony_ci 2529e41f4b71Sopenharmony_ciSubscribes to capture start events. This API uses an asynchronous callback to return the result. 2530e41f4b71Sopenharmony_ci 2531e41f4b71Sopenharmony_ci> **NOTE** 2532e41f4b71Sopenharmony_ci> 2533e41f4b71Sopenharmony_ci> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**. 2534e41f4b71Sopenharmony_ci 2535e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 2536e41f4b71Sopenharmony_ci 2537e41f4b71Sopenharmony_ci**Parameters** 2538e41f4b71Sopenharmony_ci 2539e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 2540e41f4b71Sopenharmony_ci| -------- | ---------- | --- | ------------------------------------ | 2541e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'captureStartWithInfo'**. The event can be listened for when a **photoOutput** instance is created.| 2542e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[CaptureStartInfo](#capturestartinfo11)\> | Yes | Callback used to return the capture ID.| 2543e41f4b71Sopenharmony_ci 2544e41f4b71Sopenharmony_ci**Example** 2545e41f4b71Sopenharmony_ci 2546e41f4b71Sopenharmony_ci```ts 2547e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 2548e41f4b71Sopenharmony_ci 2549e41f4b71Sopenharmony_cifunction callback(err: BusinessError, captureStartInfo: camera.CaptureStartInfo): void { 2550e41f4b71Sopenharmony_ci if (err !== undefined && err.code !== 0) { 2551e41f4b71Sopenharmony_ci console.error(`Callback Error, errorCode: ${err.code}`); 2552e41f4b71Sopenharmony_ci return; 2553e41f4b71Sopenharmony_ci } 2554e41f4b71Sopenharmony_ci console.info(`photo capture started, captureStartInfo : ${captureStartInfo}`); 2555e41f4b71Sopenharmony_ci} 2556e41f4b71Sopenharmony_ci 2557e41f4b71Sopenharmony_cifunction registerCaptureStartWithInfo(photoOutput: camera.PhotoOutput): void { 2558e41f4b71Sopenharmony_ci photoOutput.on('captureStartWithInfo', callback); 2559e41f4b71Sopenharmony_ci} 2560e41f4b71Sopenharmony_ci``` 2561e41f4b71Sopenharmony_ci 2562e41f4b71Sopenharmony_ci### off('captureStartWithInfo')<sup>11+</sup> 2563e41f4b71Sopenharmony_ci 2564e41f4b71Sopenharmony_cioff(type: 'captureStartWithInfo', callback?: AsyncCallback\<CaptureStartInfo\>): void 2565e41f4b71Sopenharmony_ci 2566e41f4b71Sopenharmony_ciUnsubscribes from capture start events. 2567e41f4b71Sopenharmony_ci 2568e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 2569e41f4b71Sopenharmony_ci 2570e41f4b71Sopenharmony_ci**Parameters** 2571e41f4b71Sopenharmony_ci 2572e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 2573e41f4b71Sopenharmony_ci| -------- | ---------------------- | ---- | ------------------------------------------ | 2574e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'captureStartWithInfo'**. The event can be listened for when a **photoOutput** instance is created.| 2575e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[CaptureStartInfo](#capturestartinfo11)\> | No | Callback used to return the result. If this parameter is specified, the subscription to the specified event with the specified callback is canceled. (The callback object cannot be an anonymous function.) Otherwise, the subscriptions to the specified event with all the callbacks are canceled.| 2576e41f4b71Sopenharmony_ci 2577e41f4b71Sopenharmony_ci**Example** 2578e41f4b71Sopenharmony_ci 2579e41f4b71Sopenharmony_ci```ts 2580e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 2581e41f4b71Sopenharmony_ci 2582e41f4b71Sopenharmony_cifunction unRegisterCaptureStartWithInfo(photoOutput: camera.PhotoOutput): void { 2583e41f4b71Sopenharmony_ci photoOutput.off('captureStartWithInfo'); 2584e41f4b71Sopenharmony_ci} 2585e41f4b71Sopenharmony_ci``` 2586e41f4b71Sopenharmony_ci 2587e41f4b71Sopenharmony_ci### isMovingPhotoSupported<sup>12+</sup> 2588e41f4b71Sopenharmony_ci 2589e41f4b71Sopenharmony_ciisMovingPhotoSupported(): boolean 2590e41f4b71Sopenharmony_ci 2591e41f4b71Sopenharmony_ciChecks whether taking moving photos is supported. 2592e41f4b71Sopenharmony_ci 2593e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 2594e41f4b71Sopenharmony_ci 2595e41f4b71Sopenharmony_ci**Return value** 2596e41f4b71Sopenharmony_ci 2597e41f4b71Sopenharmony_ci| Type | Description | 2598e41f4b71Sopenharmony_ci| -------------- | ----------------------- | 2599e41f4b71Sopenharmony_ci| boolean | **true**: Taking moving photos is supported.<br>**false**: Taking moving photos is not supported.| 2600e41f4b71Sopenharmony_ci 2601e41f4b71Sopenharmony_ci**Error codes** 2602e41f4b71Sopenharmony_ci 2603e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 2604e41f4b71Sopenharmony_ci 2605e41f4b71Sopenharmony_ci| ID | Error Message | 2606e41f4b71Sopenharmony_ci| -------------- | --------------- | 2607e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 2608e41f4b71Sopenharmony_ci 2609e41f4b71Sopenharmony_ci**Example** 2610e41f4b71Sopenharmony_ci 2611e41f4b71Sopenharmony_ci```ts 2612e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 2613e41f4b71Sopenharmony_ci 2614e41f4b71Sopenharmony_cifunction isMovingPhotoSupported(photoOutput: camera.PhotoOutput): boolean { 2615e41f4b71Sopenharmony_ci let isSupported: boolean = false; 2616e41f4b71Sopenharmony_ci try { 2617e41f4b71Sopenharmony_ci isSupported = photoOutput.isMovingPhotoSupported(); 2618e41f4b71Sopenharmony_ci } catch (error) { 2619e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 2620e41f4b71Sopenharmony_ci let err = error as BusinessError; 2621e41f4b71Sopenharmony_ci console.error(`The isMovingPhotoSupported call failed. error code: ${err.code}`); 2622e41f4b71Sopenharmony_ci } 2623e41f4b71Sopenharmony_ci return isSupported; 2624e41f4b71Sopenharmony_ci} 2625e41f4b71Sopenharmony_ci``` 2626e41f4b71Sopenharmony_ci 2627e41f4b71Sopenharmony_ci### enableMovingPhoto<sup>12+</sup> 2628e41f4b71Sopenharmony_ci 2629e41f4b71Sopenharmony_cienableMovingPhoto(enabled: boolean): void 2630e41f4b71Sopenharmony_ci 2631e41f4b71Sopenharmony_ciEnables or disables the feature of taking moving photos. 2632e41f4b71Sopenharmony_ci 2633e41f4b71Sopenharmony_ci**Required permissions:** ohos.permission.MICROPHONE 2634e41f4b71Sopenharmony_ci 2635e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 2636e41f4b71Sopenharmony_ci 2637e41f4b71Sopenharmony_ci**Parameters** 2638e41f4b71Sopenharmony_ci 2639e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 2640e41f4b71Sopenharmony_ci| -------- | ---------------------- | ---- | ------------------------------------------ | 2641e41f4b71Sopenharmony_ci| enabled | boolean | Yes | Whether to enable the feature of taking moving photos. The value **true** means to enable the feature, and **false** means the opposite. | 2642e41f4b71Sopenharmony_ci 2643e41f4b71Sopenharmony_ci**Error codes** 2644e41f4b71Sopenharmony_ci 2645e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 2646e41f4b71Sopenharmony_ci 2647e41f4b71Sopenharmony_ci| ID | Error Message | 2648e41f4b71Sopenharmony_ci| -------- |------------------------------------------------| 2649e41f4b71Sopenharmony_ci| 201 | permission denied. | 2650e41f4b71Sopenharmony_ci| 7400101 | Parameter missing or parameter type incorrect. | 2651e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 2652e41f4b71Sopenharmony_ci 2653e41f4b71Sopenharmony_ci**Example** 2654e41f4b71Sopenharmony_ci 2655e41f4b71Sopenharmony_ci```ts 2656e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 2657e41f4b71Sopenharmony_ci 2658e41f4b71Sopenharmony_cifunction enableMovingPhoto(photoOutput: camera.PhotoOutput): void { 2659e41f4b71Sopenharmony_ci try { 2660e41f4b71Sopenharmony_ci photoOutput.enableMovingPhoto(true); 2661e41f4b71Sopenharmony_ci } catch (error) { 2662e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 2663e41f4b71Sopenharmony_ci let err = error as BusinessError; 2664e41f4b71Sopenharmony_ci console.error(`The enableMovingPhoto call failed. error code: ${err.code}`); 2665e41f4b71Sopenharmony_ci } 2666e41f4b71Sopenharmony_ci} 2667e41f4b71Sopenharmony_ci``` 2668e41f4b71Sopenharmony_ci 2669e41f4b71Sopenharmony_ci### on('photoAssetAvailable')<sup>12+</sup> 2670e41f4b71Sopenharmony_ci 2671e41f4b71Sopenharmony_cion(type: 'photoAssetAvailable', callback: AsyncCallback\<photoAccessHelper.PhotoAsset\>): void 2672e41f4b71Sopenharmony_ci 2673e41f4b71Sopenharmony_ciSubscribes to photo asset available events. This API uses an asynchronous callback to return the result. 2674e41f4b71Sopenharmony_ci 2675e41f4b71Sopenharmony_ci> **NOTE** 2676e41f4b71Sopenharmony_ci> 2677e41f4b71Sopenharmony_ci> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**. 2678e41f4b71Sopenharmony_ci 2679e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 2680e41f4b71Sopenharmony_ci 2681e41f4b71Sopenharmony_ci**Parameters** 2682e41f4b71Sopenharmony_ci 2683e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 2684e41f4b71Sopenharmony_ci| -------- | ---------- | --- | ------------------------------------ | 2685e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'photoAssetAvailable'**. The event can be listened for when a **photoOutput** instance is created.| 2686e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[photoAccessHelper.PhotoAsset](../apis-media-library-kit/js-apis-photoAccessHelper.md#photoasset)\> | Yes | Callback used to return the photo asset.| 2687e41f4b71Sopenharmony_ci 2688e41f4b71Sopenharmony_ci**Example** 2689e41f4b71Sopenharmony_ci 2690e41f4b71Sopenharmony_ci```ts 2691e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 2692e41f4b71Sopenharmony_ciimport { photoAccessHelper } from '@kit.MediaLibraryKit'; 2693e41f4b71Sopenharmony_ci 2694e41f4b71Sopenharmony_cifunction photoAssetAvailableCallback(err: BusinessError, photoAsset: photoAccessHelper.PhotoAsset): void { 2695e41f4b71Sopenharmony_ci if (err) { 2696e41f4b71Sopenharmony_ci console.info(`photoAssetAvailable error: ${JSON.stringify(err)}.`); 2697e41f4b71Sopenharmony_ci return; 2698e41f4b71Sopenharmony_ci } 2699e41f4b71Sopenharmony_ci console.info('photoOutPutCallBack photoAssetAvailable'); 2700e41f4b71Sopenharmony_ci // You can use photoAsset to obtain image information. 2701e41f4b71Sopenharmony_ci} 2702e41f4b71Sopenharmony_ci 2703e41f4b71Sopenharmony_cifunction onPhotoOutputPhotoAssetAvailable(photoOutput: camera.PhotoOutput): void { 2704e41f4b71Sopenharmony_ci photoOutput.on('photoAssetAvailable', photoAssetAvailableCallback); 2705e41f4b71Sopenharmony_ci} 2706e41f4b71Sopenharmony_ci``` 2707e41f4b71Sopenharmony_ci 2708e41f4b71Sopenharmony_ci### off('photoAssetAvailable')<sup>12+</sup> 2709e41f4b71Sopenharmony_ci 2710e41f4b71Sopenharmony_cioff(type: 'photoAssetAvailable', callback?: AsyncCallback\<photoAccessHelper.PhotoAsset\>): void 2711e41f4b71Sopenharmony_ci 2712e41f4b71Sopenharmony_ciUnsubscribes from photo asset available events. 2713e41f4b71Sopenharmony_ci 2714e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 2715e41f4b71Sopenharmony_ci 2716e41f4b71Sopenharmony_ci**Parameters** 2717e41f4b71Sopenharmony_ci 2718e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 2719e41f4b71Sopenharmony_ci| -------- | ---------- |-----|----------------------------------------------------------------------------| 2720e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'photoAssetAvailable'**. The event can be listened for when a **photoOutput** instance is created. | 2721e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[photoAccessHelper.PhotoAsset](../apis-media-library-kit/js-apis-photoAccessHelper.md#photoasset)\> | No | Callback used for unsubscription. If this parameter is specified, the subscription to the specified event with the specified callback is canceled. (The callback object cannot be an anonymous function.) Otherwise, the subscriptions to the specified event with all the callbacks are canceled.| 2722e41f4b71Sopenharmony_ci 2723e41f4b71Sopenharmony_ci**Example** 2724e41f4b71Sopenharmony_ci 2725e41f4b71Sopenharmony_ci```ts 2726e41f4b71Sopenharmony_cifunction offPhotoOutputPhotoAssetAvailable(photoOutput: camera.PhotoOutput): void { 2727e41f4b71Sopenharmony_ci photoOutput.off('photoAssetAvailable'); 2728e41f4b71Sopenharmony_ci} 2729e41f4b71Sopenharmony_ci``` 2730e41f4b71Sopenharmony_ci 2731e41f4b71Sopenharmony_ci### isMirrorSupported 2732e41f4b71Sopenharmony_ci 2733e41f4b71Sopenharmony_ciisMirrorSupported(): boolean 2734e41f4b71Sopenharmony_ci 2735e41f4b71Sopenharmony_ciChecks whether mirror photography is supported. 2736e41f4b71Sopenharmony_ci 2737e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 2738e41f4b71Sopenharmony_ci 2739e41f4b71Sopenharmony_ci**Return value** 2740e41f4b71Sopenharmony_ci 2741e41f4b71Sopenharmony_ci| Type | Description | 2742e41f4b71Sopenharmony_ci| -------------- | ----------------------- | 2743e41f4b71Sopenharmony_ci| boolean | **true**: Mirror photography is supported.<br>**false**: Mirror photography is not supported.| 2744e41f4b71Sopenharmony_ci 2745e41f4b71Sopenharmony_ci**Example** 2746e41f4b71Sopenharmony_ci 2747e41f4b71Sopenharmony_ci```ts 2748e41f4b71Sopenharmony_cifunction isMirrorSupported(photoOutput: camera.PhotoOutput): boolean { 2749e41f4b71Sopenharmony_ci let isSupported: boolean = photoOutput.isMirrorSupported(); 2750e41f4b71Sopenharmony_ci return isSupported; 2751e41f4b71Sopenharmony_ci} 2752e41f4b71Sopenharmony_ci``` 2753e41f4b71Sopenharmony_ci 2754e41f4b71Sopenharmony_ci### on('captureStart')<sup>(deprecated)</sup> 2755e41f4b71Sopenharmony_ci 2756e41f4b71Sopenharmony_cion(type: 'captureStart', callback: AsyncCallback\<number\>): void 2757e41f4b71Sopenharmony_ci 2758e41f4b71Sopenharmony_ciSubscribes to capture start events. This API uses an asynchronous callback to return the result. 2759e41f4b71Sopenharmony_ci 2760e41f4b71Sopenharmony_ci> **NOTE** 2761e41f4b71Sopenharmony_ci> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [on('captureStartWithInfo')](#oncapturestartwithinfo11) instead. 2762e41f4b71Sopenharmony_ci> 2763e41f4b71Sopenharmony_ci> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**. 2764e41f4b71Sopenharmony_ci 2765e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 2766e41f4b71Sopenharmony_ci 2767e41f4b71Sopenharmony_ci**Parameters** 2768e41f4b71Sopenharmony_ci 2769e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 2770e41f4b71Sopenharmony_ci| -------- | ---------------------- | ---- | ------------------------------------------ | 2771e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'captureStart'**. The event can be listened for when a **photoOutput** instance is created. This event is triggered and returned when the bottom layer starts exposure each time a photo is taken.| 2772e41f4b71Sopenharmony_ci| callback | AsyncCallback\<number\> | Yes | Callback used to return the capture ID. | 2773e41f4b71Sopenharmony_ci 2774e41f4b71Sopenharmony_ci**Example** 2775e41f4b71Sopenharmony_ci 2776e41f4b71Sopenharmony_ci```ts 2777e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 2778e41f4b71Sopenharmony_ci 2779e41f4b71Sopenharmony_cifunction callback(err: BusinessError, captureId: number): void { 2780e41f4b71Sopenharmony_ci if (err !== undefined && err.code !== 0) { 2781e41f4b71Sopenharmony_ci console.error(`Callback Error, errorCode: ${err.code}`); 2782e41f4b71Sopenharmony_ci return; 2783e41f4b71Sopenharmony_ci } 2784e41f4b71Sopenharmony_ci console.info(`photo capture started, captureId : ${captureId}`); 2785e41f4b71Sopenharmony_ci} 2786e41f4b71Sopenharmony_ci 2787e41f4b71Sopenharmony_cifunction registerPhotoOutputCaptureStart(photoOutput: camera.PhotoOutput): void { 2788e41f4b71Sopenharmony_ci photoOutput.on('captureStart', callback); 2789e41f4b71Sopenharmony_ci} 2790e41f4b71Sopenharmony_ci``` 2791e41f4b71Sopenharmony_ci 2792e41f4b71Sopenharmony_ci### off('captureStart')<sup>(deprecated)</sup> 2793e41f4b71Sopenharmony_ci 2794e41f4b71Sopenharmony_cioff(type: 'captureStart', callback?: AsyncCallback\<number\>): void 2795e41f4b71Sopenharmony_ci 2796e41f4b71Sopenharmony_ciUnsubscribes from capture start events. 2797e41f4b71Sopenharmony_ci 2798e41f4b71Sopenharmony_ci> **NOTE** 2799e41f4b71Sopenharmony_ci> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [off('captureStartWithInfo')](#offcapturestartwithinfo11) instead. 2800e41f4b71Sopenharmony_ci> 2801e41f4b71Sopenharmony_ci> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**. 2802e41f4b71Sopenharmony_ci 2803e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 2804e41f4b71Sopenharmony_ci 2805e41f4b71Sopenharmony_ci**Parameters** 2806e41f4b71Sopenharmony_ci 2807e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 2808e41f4b71Sopenharmony_ci| -------- | ---------------------- | ---- | ------------------------------------------ | 2809e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'captureStart'**. The event can be listened for when a **photoOutput** instance is created.| 2810e41f4b71Sopenharmony_ci| callback | AsyncCallback\<number\> | No | Callback used to return the result. If this parameter is specified, the subscription to the specified event with the specified callback is canceled. (The callback object cannot be an anonymous function.) Otherwise, the subscriptions to the specified event with all the callbacks are canceled.| 2811e41f4b71Sopenharmony_ci 2812e41f4b71Sopenharmony_ci**Example** 2813e41f4b71Sopenharmony_ci 2814e41f4b71Sopenharmony_ci```ts 2815e41f4b71Sopenharmony_cifunction unregisterPhotoOutputCaptureStart(photoOutput: camera.PhotoOutput): void { 2816e41f4b71Sopenharmony_ci photoOutput.off('captureStart'); 2817e41f4b71Sopenharmony_ci} 2818e41f4b71Sopenharmony_ci``` 2819e41f4b71Sopenharmony_ci 2820e41f4b71Sopenharmony_ci### on('frameShutter') 2821e41f4b71Sopenharmony_ci 2822e41f4b71Sopenharmony_cion(type: 'frameShutter', callback: AsyncCallback\<FrameShutterInfo\>): void 2823e41f4b71Sopenharmony_ci 2824e41f4b71Sopenharmony_ciSubscribes to frame shutter events. This API uses an asynchronous callback to return the result. 2825e41f4b71Sopenharmony_ci 2826e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 2827e41f4b71Sopenharmony_ci 2828e41f4b71Sopenharmony_ci**Parameters** 2829e41f4b71Sopenharmony_ci 2830e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 2831e41f4b71Sopenharmony_ci| -------- | ---------- | --- | ------------------------------------ | 2832e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'frameShutter'**. The event can be listened for when a **photoOutput** instance is created.| 2833e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[FrameShutterInfo](#frameshutterinfo)\> | Yes | Callback used to return the result. A new photographing request can be delivered as long as this event is returned. | 2834e41f4b71Sopenharmony_ci 2835e41f4b71Sopenharmony_ci**Example** 2836e41f4b71Sopenharmony_ci 2837e41f4b71Sopenharmony_ci```ts 2838e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 2839e41f4b71Sopenharmony_ci 2840e41f4b71Sopenharmony_cifunction callback(err: BusinessError, frameShutterInfo: camera.FrameShutterInfo): void { 2841e41f4b71Sopenharmony_ci if (err !== undefined && err.code !== 0) { 2842e41f4b71Sopenharmony_ci console.error(`Callback Error, errorCode: ${err.code}`); 2843e41f4b71Sopenharmony_ci return; 2844e41f4b71Sopenharmony_ci } 2845e41f4b71Sopenharmony_ci console.info(`CaptureId for frame : ${frameShutterInfo.captureId}`); 2846e41f4b71Sopenharmony_ci console.info(`Timestamp for frame : ${frameShutterInfo.timestamp}`); 2847e41f4b71Sopenharmony_ci} 2848e41f4b71Sopenharmony_ci 2849e41f4b71Sopenharmony_cifunction registerPhotoOutputFrameShutter(photoOutput: camera.PhotoOutput): void { 2850e41f4b71Sopenharmony_ci photoOutput.on('frameShutter', callback); 2851e41f4b71Sopenharmony_ci} 2852e41f4b71Sopenharmony_ci``` 2853e41f4b71Sopenharmony_ci 2854e41f4b71Sopenharmony_ci### off('frameShutter') 2855e41f4b71Sopenharmony_ci 2856e41f4b71Sopenharmony_cioff(type: 'frameShutter', callback?: AsyncCallback\<FrameShutterInfo\>): void 2857e41f4b71Sopenharmony_ci 2858e41f4b71Sopenharmony_ciUnsubscribes from frame shutter events. 2859e41f4b71Sopenharmony_ci 2860e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 2861e41f4b71Sopenharmony_ci 2862e41f4b71Sopenharmony_ci**Parameters** 2863e41f4b71Sopenharmony_ci 2864e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 2865e41f4b71Sopenharmony_ci| -------- | ---------- | --- | ------------------------------------ | 2866e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'frameShutter'**. The event can be listened for when a **photoOutput** instance is created.| 2867e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[FrameShutterInfo](#frameshutterinfo)\> | No | Callback used to return the result. If this parameter is specified, the subscription to the specified event with the specified callback is canceled. (The callback object cannot be an anonymous function.) Otherwise, the subscriptions to the specified event with all the callbacks are canceled.| 2868e41f4b71Sopenharmony_ci 2869e41f4b71Sopenharmony_ci**Example** 2870e41f4b71Sopenharmony_ci 2871e41f4b71Sopenharmony_ci```ts 2872e41f4b71Sopenharmony_cifunction unregisterPhotoOutputFrameShutter(photoOutput: camera.PhotoOutput): void { 2873e41f4b71Sopenharmony_ci photoOutput.off('frameShutter'); 2874e41f4b71Sopenharmony_ci} 2875e41f4b71Sopenharmony_ci``` 2876e41f4b71Sopenharmony_ci 2877e41f4b71Sopenharmony_ci### on('captureEnd') 2878e41f4b71Sopenharmony_ci 2879e41f4b71Sopenharmony_cion(type: 'captureEnd', callback: AsyncCallback\<CaptureEndInfo\>): void 2880e41f4b71Sopenharmony_ci 2881e41f4b71Sopenharmony_ciSubscribes to capture end events. This API uses an asynchronous callback to return the result. 2882e41f4b71Sopenharmony_ci 2883e41f4b71Sopenharmony_ci> **NOTE** 2884e41f4b71Sopenharmony_ci> 2885e41f4b71Sopenharmony_ci> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**. 2886e41f4b71Sopenharmony_ci 2887e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 2888e41f4b71Sopenharmony_ci 2889e41f4b71Sopenharmony_ci**Parameters** 2890e41f4b71Sopenharmony_ci 2891e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 2892e41f4b71Sopenharmony_ci| -------- | --------------- | ---- | ---------------------------------------- | 2893e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'captureEnd'**. The event can be listened for when a **photoOutput** instance is created. This event is triggered and the corresponding information is returned when the photographing is complete.| 2894e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[CaptureEndInfo](#captureendinfo)\> | Yes | Callback used to return the result. | 2895e41f4b71Sopenharmony_ci 2896e41f4b71Sopenharmony_ci**Example** 2897e41f4b71Sopenharmony_ci 2898e41f4b71Sopenharmony_ci```ts 2899e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 2900e41f4b71Sopenharmony_ci 2901e41f4b71Sopenharmony_cifunction callback(err: BusinessError, captureEndInfo: camera.CaptureEndInfo): void { 2902e41f4b71Sopenharmony_ci if (err !== undefined && err.code !== 0) { 2903e41f4b71Sopenharmony_ci console.error(`Callback Error, errorCode: ${err.code}`); 2904e41f4b71Sopenharmony_ci return; 2905e41f4b71Sopenharmony_ci } 2906e41f4b71Sopenharmony_ci console.info(`photo capture end, captureId : ${captureEndInfo.captureId}`); 2907e41f4b71Sopenharmony_ci console.info(`frameCount : ${captureEndInfo.frameCount}`); 2908e41f4b71Sopenharmony_ci} 2909e41f4b71Sopenharmony_ci 2910e41f4b71Sopenharmony_cifunction registerPhotoOutputCaptureEnd(photoOutput: camera.PhotoOutput): void { 2911e41f4b71Sopenharmony_ci photoOutput.on('captureEnd', callback); 2912e41f4b71Sopenharmony_ci} 2913e41f4b71Sopenharmony_ci``` 2914e41f4b71Sopenharmony_ci 2915e41f4b71Sopenharmony_ci### off('captureEnd') 2916e41f4b71Sopenharmony_ci 2917e41f4b71Sopenharmony_cioff(type: 'captureEnd', callback?: AsyncCallback\<CaptureEndInfo\>): void 2918e41f4b71Sopenharmony_ci 2919e41f4b71Sopenharmony_ciUnsubscribes from capture end events. 2920e41f4b71Sopenharmony_ci 2921e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 2922e41f4b71Sopenharmony_ci 2923e41f4b71Sopenharmony_ci**Parameters** 2924e41f4b71Sopenharmony_ci 2925e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 2926e41f4b71Sopenharmony_ci| -------- | --------------- | ---- | ---------------------------------------- | 2927e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'captureEnd'**. The event can be listened for when a **photoOutput** instance is created.| 2928e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[CaptureEndInfo](#captureendinfo)\> | No | Callback used to return the result. If this parameter is specified, the subscription to the specified event with the specified callback is canceled. (The callback object cannot be an anonymous function.) Otherwise, the subscriptions to the specified event with all the callbacks are canceled.| 2929e41f4b71Sopenharmony_ci 2930e41f4b71Sopenharmony_ci**Example** 2931e41f4b71Sopenharmony_ci 2932e41f4b71Sopenharmony_ci```ts 2933e41f4b71Sopenharmony_cifunction unregisterPhotoOutputCaptureEnd(photoOutput: camera.PhotoOutput): void { 2934e41f4b71Sopenharmony_ci photoOutput.off('captureEnd'); 2935e41f4b71Sopenharmony_ci} 2936e41f4b71Sopenharmony_ci``` 2937e41f4b71Sopenharmony_ci 2938e41f4b71Sopenharmony_ci### on('frameShutterEnd')<sup>12+</sup> 2939e41f4b71Sopenharmony_ci 2940e41f4b71Sopenharmony_cion(type: 'frameShutterEnd', callback: AsyncCallback\<FrameShutterEndInfo\>): void 2941e41f4b71Sopenharmony_ci 2942e41f4b71Sopenharmony_ciSubscribes to frame shutter end events. This API uses an asynchronous callback to return the result. 2943e41f4b71Sopenharmony_ci 2944e41f4b71Sopenharmony_ci> **NOTE** 2945e41f4b71Sopenharmony_ci> 2946e41f4b71Sopenharmony_ci> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**. 2947e41f4b71Sopenharmony_ci 2948e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 2949e41f4b71Sopenharmony_ci 2950e41f4b71Sopenharmony_ci**Parameters** 2951e41f4b71Sopenharmony_ci 2952e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 2953e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 2954e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'frameShutterEnd'**. The event can be listened for when a **photoOutput** instance is created.| 2955e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[FrameShutterEndInfo](#frameshutterendinfo12)\> | Yes | Callback used to return the result. It is invoked when the frame shutter ends. | 2956e41f4b71Sopenharmony_ci 2957e41f4b71Sopenharmony_ci**Example** 2958e41f4b71Sopenharmony_ci 2959e41f4b71Sopenharmony_ci```ts 2960e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 2961e41f4b71Sopenharmony_ci 2962e41f4b71Sopenharmony_cifunction callback(err: BusinessError, frameShutterEndInfo: camera.FrameShutterEndInfo): void { 2963e41f4b71Sopenharmony_ci if (err !== undefined && err.code !== 0) { 2964e41f4b71Sopenharmony_ci console.error(`Callback Error, errorCode: ${err.code}`); 2965e41f4b71Sopenharmony_ci return; 2966e41f4b71Sopenharmony_ci } 2967e41f4b71Sopenharmony_ci console.info(`CaptureId for frame : ${frameShutterEndInfo.captureId}`); 2968e41f4b71Sopenharmony_ci} 2969e41f4b71Sopenharmony_ci 2970e41f4b71Sopenharmony_cifunction registerPhotoOutputFrameShutterEnd(photoOutput: camera.PhotoOutput): void { 2971e41f4b71Sopenharmony_ci photoOutput.on('frameShutterEnd', callback); 2972e41f4b71Sopenharmony_ci} 2973e41f4b71Sopenharmony_ci``` 2974e41f4b71Sopenharmony_ci 2975e41f4b71Sopenharmony_ci### off('frameShutterEnd')<sup>12+</sup> 2976e41f4b71Sopenharmony_ci 2977e41f4b71Sopenharmony_cioff(type: 'frameShutterEnd', callback?: AsyncCallback\<FrameShutterEndInfo\>): void 2978e41f4b71Sopenharmony_ci 2979e41f4b71Sopenharmony_ciUnsubscribes from frame shutter end events. 2980e41f4b71Sopenharmony_ci 2981e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 2982e41f4b71Sopenharmony_ci 2983e41f4b71Sopenharmony_ci**Parameters** 2984e41f4b71Sopenharmony_ci 2985e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 2986e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 2987e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'frameShutterEnd'**. The event can be listened for when a **photoOutput** instance is created.| 2988e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[FrameShutterEndInfo](#frameshutterendinfo12)\> | No | Callback used to return the result. If this parameter is specified, the subscription to the specified event with the specified callback is canceled. (The callback object cannot be an anonymous function.) Otherwise, the subscriptions to the specified event with all the callbacks are canceled.| 2989e41f4b71Sopenharmony_ci 2990e41f4b71Sopenharmony_ci**Example** 2991e41f4b71Sopenharmony_ci 2992e41f4b71Sopenharmony_ci```ts 2993e41f4b71Sopenharmony_cifunction unregisterPhotoOutputFrameShutterEnd(photoOutput: camera.PhotoOutput): void { 2994e41f4b71Sopenharmony_ci photoOutput.off('frameShutterEnd'); 2995e41f4b71Sopenharmony_ci} 2996e41f4b71Sopenharmony_ci``` 2997e41f4b71Sopenharmony_ci 2998e41f4b71Sopenharmony_ci### on('captureReady')<sup>12+</sup> 2999e41f4b71Sopenharmony_ci 3000e41f4b71Sopenharmony_cion(type: 'captureReady', callback: AsyncCallback\<void\>): void 3001e41f4b71Sopenharmony_ci 3002e41f4b71Sopenharmony_ciSubscribes to capture ready events. This API uses an asynchronous callback to return the result. 3003e41f4b71Sopenharmony_ci 3004e41f4b71Sopenharmony_ci> **NOTE** 3005e41f4b71Sopenharmony_ci> 3006e41f4b71Sopenharmony_ci> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**. 3007e41f4b71Sopenharmony_ci 3008e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 3009e41f4b71Sopenharmony_ci 3010e41f4b71Sopenharmony_ci**Parameters** 3011e41f4b71Sopenharmony_ci 3012e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 3013e41f4b71Sopenharmony_ci| -------- | --------------------- | ---- | ------------------------------------------------------------ | 3014e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'captureReady'**. The event can be listened for when a **photoOutput** instance is created. The event is triggered and the corresponding information is returned when it is ready to take the next photo.| 3015e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. | 3016e41f4b71Sopenharmony_ci 3017e41f4b71Sopenharmony_ci**Example** 3018e41f4b71Sopenharmony_ci 3019e41f4b71Sopenharmony_ci```ts 3020e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 3021e41f4b71Sopenharmony_ci 3022e41f4b71Sopenharmony_cifunction callback(err: BusinessError): void { 3023e41f4b71Sopenharmony_ci if (err !== undefined && err.code !== 0) { 3024e41f4b71Sopenharmony_ci console.error(`Callback Error, errorCode: ${err.code}`); 3025e41f4b71Sopenharmony_ci return; 3026e41f4b71Sopenharmony_ci } 3027e41f4b71Sopenharmony_ci console.info(`photo capture ready`); 3028e41f4b71Sopenharmony_ci} 3029e41f4b71Sopenharmony_ci 3030e41f4b71Sopenharmony_cifunction registerPhotoOutputCaptureReady(photoOutput: camera.PhotoOutput): void { 3031e41f4b71Sopenharmony_ci photoOutput.on('captureReady', callback); 3032e41f4b71Sopenharmony_ci} 3033e41f4b71Sopenharmony_ci``` 3034e41f4b71Sopenharmony_ci 3035e41f4b71Sopenharmony_ci### off('captureReady')<sup>12+</sup> 3036e41f4b71Sopenharmony_ci 3037e41f4b71Sopenharmony_cioff(type: 'captureReady', callback?: AsyncCallback\<void\>): void 3038e41f4b71Sopenharmony_ci 3039e41f4b71Sopenharmony_ciUnsubscribes from capture ready events. 3040e41f4b71Sopenharmony_ci 3041e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 3042e41f4b71Sopenharmony_ci 3043e41f4b71Sopenharmony_ci**Parameters** 3044e41f4b71Sopenharmony_ci 3045e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 3046e41f4b71Sopenharmony_ci| -------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------ | 3047e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'captureReady'**. The event can be listened for when a **photoOutput** instance is created.| 3048e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[CaptureReadyInfo](#captureendinfo)\> | No | Callback used to return the result. If this parameter is specified, the subscription to the specified event with the specified callback is canceled. (The callback object cannot be an anonymous function.) Otherwise, the subscriptions to the specified event with all the callbacks are canceled.| 3049e41f4b71Sopenharmony_ci 3050e41f4b71Sopenharmony_ci**Example** 3051e41f4b71Sopenharmony_ci 3052e41f4b71Sopenharmony_ci```ts 3053e41f4b71Sopenharmony_cifunction unregisterPhotoOutputCaptureReady(photoOutput: camera.PhotoOutput): void { 3054e41f4b71Sopenharmony_ci photoOutput.off('captureReady'); 3055e41f4b71Sopenharmony_ci} 3056e41f4b71Sopenharmony_ci``` 3057e41f4b71Sopenharmony_ci 3058e41f4b71Sopenharmony_ci### on('estimatedCaptureDuration')<sup>12+</sup> 3059e41f4b71Sopenharmony_ci 3060e41f4b71Sopenharmony_cion(type: 'estimatedCaptureDuration', callback: AsyncCallback\<number\>): void 3061e41f4b71Sopenharmony_ci 3062e41f4b71Sopenharmony_ciSubscribes to estimated capture duration events. This API uses an asynchronous callback to return the result. 3063e41f4b71Sopenharmony_ci 3064e41f4b71Sopenharmony_ci> **NOTE** 3065e41f4b71Sopenharmony_ci> 3066e41f4b71Sopenharmony_ci> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**. 3067e41f4b71Sopenharmony_ci 3068e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 3069e41f4b71Sopenharmony_ci 3070e41f4b71Sopenharmony_ci**Parameters** 3071e41f4b71Sopenharmony_ci 3072e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 3073e41f4b71Sopenharmony_ci| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 3074e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'estimatedCaptureDuration'**. The event can be listened for when a **photoOutput** instance is created. This event is triggered and the corresponding information is returned when the photographing is complete.| 3075e41f4b71Sopenharmony_ci| callback | AsyncCallback\<number> | Yes | Callback used to return the estimated duration when the sensor captures frames at the bottom layer in a single capture. If **–1** is reported, there is no estimated duration. | 3076e41f4b71Sopenharmony_ci 3077e41f4b71Sopenharmony_ci**Example** 3078e41f4b71Sopenharmony_ci 3079e41f4b71Sopenharmony_ci```ts 3080e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 3081e41f4b71Sopenharmony_ci 3082e41f4b71Sopenharmony_cifunction callback(err: BusinessError, duration: number): void { 3083e41f4b71Sopenharmony_ci if (err !== undefined && err.code !== 0) { 3084e41f4b71Sopenharmony_ci console.error(`Callback Error, errorCode: ${err.code}`); 3085e41f4b71Sopenharmony_ci return; 3086e41f4b71Sopenharmony_ci } 3087e41f4b71Sopenharmony_ci console.info(`photo estimated capture duration : ${duration}`); 3088e41f4b71Sopenharmony_ci} 3089e41f4b71Sopenharmony_ci 3090e41f4b71Sopenharmony_cifunction registerPhotoOutputEstimatedCaptureDuration(photoOutput: camera.PhotoOutput): void { 3091e41f4b71Sopenharmony_ci photoOutput.on('estimatedCaptureDuration', callback); 3092e41f4b71Sopenharmony_ci} 3093e41f4b71Sopenharmony_ci``` 3094e41f4b71Sopenharmony_ci 3095e41f4b71Sopenharmony_ci### off('estimatedCaptureDuration')<sup>12+</sup> 3096e41f4b71Sopenharmony_ci 3097e41f4b71Sopenharmony_cioff(type: 'estimatedCaptureDuration', callback?: AsyncCallback\<number\>): void 3098e41f4b71Sopenharmony_ci 3099e41f4b71Sopenharmony_ciUnsubscribes from estimated capture duration events. 3100e41f4b71Sopenharmony_ci 3101e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 3102e41f4b71Sopenharmony_ci 3103e41f4b71Sopenharmony_ci**Parameters** 3104e41f4b71Sopenharmony_ci 3105e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 3106e41f4b71Sopenharmony_ci| -------- | ----------------------- | ---- | ------------------------------------------------------------ | 3107e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'estimatedCaptureDuration'**. The event can be listened for when a **photoOutput** instance is created.| 3108e41f4b71Sopenharmony_ci| callback | AsyncCallback\<number\> | No | Callback used to return the result. If this parameter is specified, the subscription to the specified event with the specified callback is canceled. (The callback object cannot be an anonymous function.) Otherwise, the subscriptions to the specified event with all the callbacks are canceled.| 3109e41f4b71Sopenharmony_ci 3110e41f4b71Sopenharmony_ci**Example** 3111e41f4b71Sopenharmony_ci 3112e41f4b71Sopenharmony_ci```ts 3113e41f4b71Sopenharmony_cifunction unregisterPhotoOutputEstimatedCaptureDuration(photoOutput: camera.PhotoOutput): void { 3114e41f4b71Sopenharmony_ci photoOutput.off('estimatedCaptureDuration'); 3115e41f4b71Sopenharmony_ci} 3116e41f4b71Sopenharmony_ci``` 3117e41f4b71Sopenharmony_ci 3118e41f4b71Sopenharmony_ci### on('error') 3119e41f4b71Sopenharmony_ci 3120e41f4b71Sopenharmony_cion(type: 'error', callback: ErrorCallback): void 3121e41f4b71Sopenharmony_ci 3122e41f4b71Sopenharmony_ciSubscribes to **PhotoOutput** error events. This API uses an asynchronous callback to return the result. 3123e41f4b71Sopenharmony_ci 3124e41f4b71Sopenharmony_ci> **NOTE** 3125e41f4b71Sopenharmony_ci> 3126e41f4b71Sopenharmony_ci> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**. 3127e41f4b71Sopenharmony_ci 3128e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 3129e41f4b71Sopenharmony_ci 3130e41f4b71Sopenharmony_ci**Parameters** 3131e41f4b71Sopenharmony_ci 3132e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 3133e41f4b71Sopenharmony_ci| -------- | ------------- | ---- | ----------------------------------- | 3134e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a **photoOutput** instance is created. This event is triggered and the corresponding error message is returned when an error occurs during the calling of a photo-related API.| 3135e41f4b71Sopenharmony_ci| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | Yes | Callback used to return an error code defined in [CameraErrorCode](#cameraerrorcode). | 3136e41f4b71Sopenharmony_ci 3137e41f4b71Sopenharmony_ci**Example** 3138e41f4b71Sopenharmony_ci 3139e41f4b71Sopenharmony_ci```ts 3140e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 3141e41f4b71Sopenharmony_ci 3142e41f4b71Sopenharmony_cifunction callback(err: BusinessError): void { 3143e41f4b71Sopenharmony_ci console.error(`Photo output error code: ${err.code}`); 3144e41f4b71Sopenharmony_ci} 3145e41f4b71Sopenharmony_ci 3146e41f4b71Sopenharmony_cifunction registerPhotoOutputError(photoOutput: camera.PhotoOutput): void { 3147e41f4b71Sopenharmony_ci photoOutput.on('error', callback); 3148e41f4b71Sopenharmony_ci} 3149e41f4b71Sopenharmony_ci``` 3150e41f4b71Sopenharmony_ci 3151e41f4b71Sopenharmony_ci### off('error') 3152e41f4b71Sopenharmony_ci 3153e41f4b71Sopenharmony_cioff(type: 'error', callback?: ErrorCallback): void 3154e41f4b71Sopenharmony_ci 3155e41f4b71Sopenharmony_ciUnsubscribes from **PhotoOutput** error events. 3156e41f4b71Sopenharmony_ci 3157e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 3158e41f4b71Sopenharmony_ci 3159e41f4b71Sopenharmony_ci**Parameters** 3160e41f4b71Sopenharmony_ci 3161e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 3162e41f4b71Sopenharmony_ci| -------- | ------------- | ---- | ----------------------------------- | 3163e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a **photoOutput** instance is created.| 3164e41f4b71Sopenharmony_ci| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | No | Callback used to return the result. If this parameter is specified, the subscription to the specified event with the specified callback is canceled. (The callback object cannot be an anonymous function.) Otherwise, the subscriptions to the specified event with all the callbacks are canceled.| 3165e41f4b71Sopenharmony_ci 3166e41f4b71Sopenharmony_ci**Example** 3167e41f4b71Sopenharmony_ci 3168e41f4b71Sopenharmony_ci```ts 3169e41f4b71Sopenharmony_cifunction unregisterPhotoOutputError(photoOutput: camera.PhotoOutput): void { 3170e41f4b71Sopenharmony_ci photoOutput.off('error'); 3171e41f4b71Sopenharmony_ci} 3172e41f4b71Sopenharmony_ci``` 3173e41f4b71Sopenharmony_ci 3174e41f4b71Sopenharmony_ci### getActiveProfile<sup>12+</sup> 3175e41f4b71Sopenharmony_ci 3176e41f4b71Sopenharmony_cigetActiveProfile(): Profile 3177e41f4b71Sopenharmony_ci 3178e41f4b71Sopenharmony_ciObtains the profile that takes effect currently. 3179e41f4b71Sopenharmony_ci 3180e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 3181e41f4b71Sopenharmony_ci 3182e41f4b71Sopenharmony_ci**Return value** 3183e41f4b71Sopenharmony_ci 3184e41f4b71Sopenharmony_ci| Type | Description | 3185e41f4b71Sopenharmony_ci| ------------- |-----------| 3186e41f4b71Sopenharmony_ci| [Profile](#profile) | Profile obtained.| 3187e41f4b71Sopenharmony_ci 3188e41f4b71Sopenharmony_ci**Error codes** 3189e41f4b71Sopenharmony_ci 3190e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 3191e41f4b71Sopenharmony_ci 3192e41f4b71Sopenharmony_ci| ID | Error Message | 3193e41f4b71Sopenharmony_ci|---------|------------------------------| 3194e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 3195e41f4b71Sopenharmony_ci 3196e41f4b71Sopenharmony_ci**Example** 3197e41f4b71Sopenharmony_ci 3198e41f4b71Sopenharmony_ci```ts 3199e41f4b71Sopenharmony_cifunction testGetActiveProfile(photoOutput: camera.PhotoOutput): camera.Profile | undefined { 3200e41f4b71Sopenharmony_ci let activeProfile: camera.Profile | undefined = undefined; 3201e41f4b71Sopenharmony_ci try { 3202e41f4b71Sopenharmony_ci activeProfile = photoOutput.getActiveProfile(); 3203e41f4b71Sopenharmony_ci } catch (error) { 3204e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 3205e41f4b71Sopenharmony_ci let err = error as BusinessError; 3206e41f4b71Sopenharmony_ci console.error(`The photoOutput.getActiveProfile call failed. error code: ${err.code}`); 3207e41f4b71Sopenharmony_ci } 3208e41f4b71Sopenharmony_ci return activeProfile; 3209e41f4b71Sopenharmony_ci} 3210e41f4b71Sopenharmony_ci``` 3211e41f4b71Sopenharmony_ci### getPhotoRotation<sup>12+</sup> 3212e41f4b71Sopenharmony_ci 3213e41f4b71Sopenharmony_cigetPhotoRotation(imageRotation: ImageRotation): ImageRotation 3214e41f4b71Sopenharmony_ci 3215e41f4b71Sopenharmony_ciObtains the photo rotation degree. 3216e41f4b71Sopenharmony_ci 3217e41f4b71Sopenharmony_ci- Device' natural orientation: The default orientation of the device (phone) is in portrait mode, with the charging port facing downward. 3218e41f4b71Sopenharmony_ci- Camera lens angle: equivalent to the angle at which the camera is rotated clockwise to match the device's natural direction. The rear camera sensor of a phone is installed in portrait mode. Therefore, it needs to be rotated by 90 degrees clockwise to match the device's natural direction. 3219e41f4b71Sopenharmony_ci- Screen orientation: The upper left corner of the image displayed on the screen is the first pixel, which is the coordinate origin. In the case of lock screen, the direction is the same as the device's natural orientation. 3220e41f4b71Sopenharmony_ci 3221e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 3222e41f4b71Sopenharmony_ci 3223e41f4b71Sopenharmony_ci**Parameters** 3224e41f4b71Sopenharmony_ci 3225e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 3226e41f4b71Sopenharmony_ci| -------- | --------------| ---- | ------------------------ | 3227e41f4b71Sopenharmony_ci| imageRotation | [ImageRotation](#imagerotation) | Yes | Screen display compensation angle (the angle required for rotating the image counterclockwise from the device's natural orientation to the screen orientation during image display).| 3228e41f4b71Sopenharmony_ci 3229e41f4b71Sopenharmony_ci**Return value** 3230e41f4b71Sopenharmony_ci 3231e41f4b71Sopenharmony_ci| Type | Description | 3232e41f4b71Sopenharmony_ci| ------------- |-----------| 3233e41f4b71Sopenharmony_ci| [ImageRotation](#imagerotation) | Photo rotation degree.| 3234e41f4b71Sopenharmony_ci 3235e41f4b71Sopenharmony_ci**Error codes** 3236e41f4b71Sopenharmony_ci 3237e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 3238e41f4b71Sopenharmony_ci 3239e41f4b71Sopenharmony_ci| ID | Error Message | 3240e41f4b71Sopenharmony_ci|---------|------------------------------| 3241e41f4b71Sopenharmony_ci| 7400101 | Parameter missing or parameter type incorrect. | 3242e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 3243e41f4b71Sopenharmony_ci 3244e41f4b71Sopenharmony_ci**Example** 3245e41f4b71Sopenharmony_ci 3246e41f4b71Sopenharmony_ci```ts 3247e41f4b71Sopenharmony_cifunction testGetPhotoRotation(photoOutput: camera.PreviewOutput, imageRotation : camera.ImageRotation): camera.ImageRotation { 3248e41f4b71Sopenharmony_ci let photoRotation: camera.ImageRotation; 3249e41f4b71Sopenharmony_ci try { 3250e41f4b71Sopenharmony_ci photoRotation = photoOutput.getPhotoRotation(imageRotation); 3251e41f4b71Sopenharmony_ci console.log(`Photo rotation is: ${photoRotation}`); 3252e41f4b71Sopenharmony_ci } catch (error) { 3253e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 3254e41f4b71Sopenharmony_ci let err = error as BusinessError; 3255e41f4b71Sopenharmony_ci console.error(`The photoOutput.getPhotoRotation call failed. error code: ${err.code}`); 3256e41f4b71Sopenharmony_ci } 3257e41f4b71Sopenharmony_ci return; 3258e41f4b71Sopenharmony_ci} 3259e41f4b71Sopenharmony_ci``` 3260e41f4b71Sopenharmony_ci 3261e41f4b71Sopenharmony_ci## FrameShutterInfo 3262e41f4b71Sopenharmony_ci 3263e41f4b71Sopenharmony_ciDefines the frame shutter information. 3264e41f4b71Sopenharmony_ci 3265e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 3266e41f4b71Sopenharmony_ci 3267e41f4b71Sopenharmony_ci| Name | Type | Read-only| Optional| Description | 3268e41f4b71Sopenharmony_ci| --------- | ------ | ---- | ---- | ---------- | 3269e41f4b71Sopenharmony_ci| captureId | number | No | No | ID of this capture action. | 3270e41f4b71Sopenharmony_ci| timestamp | number | No | No | Timestamp when the frame shutter event is triggered.| 3271e41f4b71Sopenharmony_ci 3272e41f4b71Sopenharmony_ci## FrameShutterEndInfo<sup>12+</sup> 3273e41f4b71Sopenharmony_ci 3274e41f4b71Sopenharmony_ciDescribes the frame shutter end information during capture. 3275e41f4b71Sopenharmony_ci 3276e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 3277e41f4b71Sopenharmony_ci 3278e41f4b71Sopenharmony_ci| Name | Type | Read-only| Optional| Description | 3279e41f4b71Sopenharmony_ci| --------- | ------ | ---- | ---- | ---------- | 3280e41f4b71Sopenharmony_ci| captureId | number | No | No | ID of this capture action.| 3281e41f4b71Sopenharmony_ci 3282e41f4b71Sopenharmony_ci## CaptureStartInfo<sup>11+</sup> 3283e41f4b71Sopenharmony_ci 3284e41f4b71Sopenharmony_ciDefines the capture start information. 3285e41f4b71Sopenharmony_ci 3286e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 3287e41f4b71Sopenharmony_ci 3288e41f4b71Sopenharmony_ci| Name | Type | Read-only| Optional| Description | 3289e41f4b71Sopenharmony_ci| ---------- | ------ | ---- | ---- | --------- | 3290e41f4b71Sopenharmony_ci| captureId | number | No | No | ID of this capture action.| 3291e41f4b71Sopenharmony_ci| time | number | No | No | Estimated duration when the sensor captures frames at the bottom layer in a single capture. If **–1** is reported, there is no estimated duration. | 3292e41f4b71Sopenharmony_ci 3293e41f4b71Sopenharmony_ci## CaptureEndInfo 3294e41f4b71Sopenharmony_ci 3295e41f4b71Sopenharmony_ciDefines the capture end information. 3296e41f4b71Sopenharmony_ci 3297e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 3298e41f4b71Sopenharmony_ci 3299e41f4b71Sopenharmony_ci| Name | Type | Read-only| Optional| Description | 3300e41f4b71Sopenharmony_ci| ---------- | ------ | ---- | ---- | ---------| 3301e41f4b71Sopenharmony_ci| captureId | number | No | No | ID of this capture action.| 3302e41f4b71Sopenharmony_ci| frameCount | number | No | No | Number of frames captured. | 3303e41f4b71Sopenharmony_ci 3304e41f4b71Sopenharmony_ci## VideoOutput 3305e41f4b71Sopenharmony_ci 3306e41f4b71Sopenharmony_ciImplements output information used in a video session. It inherits from [CameraOutput](#cameraoutput). 3307e41f4b71Sopenharmony_ci 3308e41f4b71Sopenharmony_ci### start 3309e41f4b71Sopenharmony_ci 3310e41f4b71Sopenharmony_cistart(callback: AsyncCallback\<void\>): void 3311e41f4b71Sopenharmony_ci 3312e41f4b71Sopenharmony_ciStarts video recording. This API uses an asynchronous callback to return the result. 3313e41f4b71Sopenharmony_ci 3314e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 3315e41f4b71Sopenharmony_ci 3316e41f4b71Sopenharmony_ci**Parameters** 3317e41f4b71Sopenharmony_ci 3318e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 3319e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | -------------------- | 3320e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 3321e41f4b71Sopenharmony_ci 3322e41f4b71Sopenharmony_ci**Error codes** 3323e41f4b71Sopenharmony_ci 3324e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 3325e41f4b71Sopenharmony_ci 3326e41f4b71Sopenharmony_ci| ID | Error Message | 3327e41f4b71Sopenharmony_ci| --------------- | --------------- | 3328e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 3329e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 3330e41f4b71Sopenharmony_ci 3331e41f4b71Sopenharmony_ci**Example** 3332e41f4b71Sopenharmony_ci 3333e41f4b71Sopenharmony_ci```ts 3334e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 3335e41f4b71Sopenharmony_ci 3336e41f4b71Sopenharmony_cifunction startVideoOutput(videoOutput: camera.VideoOutput): void { 3337e41f4b71Sopenharmony_ci videoOutput.start((err: BusinessError) => { 3338e41f4b71Sopenharmony_ci if (err) { 3339e41f4b71Sopenharmony_ci console.error(`Failed to start the video output, error code: ${err.code}.`); 3340e41f4b71Sopenharmony_ci return; 3341e41f4b71Sopenharmony_ci } 3342e41f4b71Sopenharmony_ci console.info('Callback invoked to indicate the video output start success.'); 3343e41f4b71Sopenharmony_ci }); 3344e41f4b71Sopenharmony_ci} 3345e41f4b71Sopenharmony_ci``` 3346e41f4b71Sopenharmony_ci 3347e41f4b71Sopenharmony_ci### start 3348e41f4b71Sopenharmony_ci 3349e41f4b71Sopenharmony_cistart(): Promise\<void\> 3350e41f4b71Sopenharmony_ci 3351e41f4b71Sopenharmony_ciStarts video recording. This API uses a promise to return the result. 3352e41f4b71Sopenharmony_ci 3353e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 3354e41f4b71Sopenharmony_ci 3355e41f4b71Sopenharmony_ci**Return value** 3356e41f4b71Sopenharmony_ci 3357e41f4b71Sopenharmony_ci| Type | Description | 3358e41f4b71Sopenharmony_ci| -------------- | ----------------------- | 3359e41f4b71Sopenharmony_ci| Promise\<void\> | Promise that returns no value.| 3360e41f4b71Sopenharmony_ci 3361e41f4b71Sopenharmony_ci**Error codes** 3362e41f4b71Sopenharmony_ci 3363e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 3364e41f4b71Sopenharmony_ci 3365e41f4b71Sopenharmony_ci| ID | Error Message | 3366e41f4b71Sopenharmony_ci| --------------- | --------------- | 3367e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 3368e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 3369e41f4b71Sopenharmony_ci 3370e41f4b71Sopenharmony_ci**Example** 3371e41f4b71Sopenharmony_ci 3372e41f4b71Sopenharmony_ci```ts 3373e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 3374e41f4b71Sopenharmony_ci 3375e41f4b71Sopenharmony_cifunction startVideoOutput(videoOutput: camera.VideoOutput): void { 3376e41f4b71Sopenharmony_ci videoOutput.start().then(() => { 3377e41f4b71Sopenharmony_ci console.info('Promise returned to indicate that start method execution success.'); 3378e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 3379e41f4b71Sopenharmony_ci console.error(`Failed to video output start, error code: ${error.code}.`); 3380e41f4b71Sopenharmony_ci }); 3381e41f4b71Sopenharmony_ci} 3382e41f4b71Sopenharmony_ci``` 3383e41f4b71Sopenharmony_ci 3384e41f4b71Sopenharmony_ci### stop 3385e41f4b71Sopenharmony_ci 3386e41f4b71Sopenharmony_cistop(callback: AsyncCallback\<void\>): void 3387e41f4b71Sopenharmony_ci 3388e41f4b71Sopenharmony_ciStops video recording. This API uses an asynchronous callback to return the result. 3389e41f4b71Sopenharmony_ci 3390e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 3391e41f4b71Sopenharmony_ci 3392e41f4b71Sopenharmony_ci**Parameters** 3393e41f4b71Sopenharmony_ci 3394e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 3395e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ------------------------ | 3396e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| 3397e41f4b71Sopenharmony_ci 3398e41f4b71Sopenharmony_ci**Example** 3399e41f4b71Sopenharmony_ci 3400e41f4b71Sopenharmony_ci```ts 3401e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 3402e41f4b71Sopenharmony_ci 3403e41f4b71Sopenharmony_cifunction stopVideoOutput(videoOutput: camera.VideoOutput): void { 3404e41f4b71Sopenharmony_ci videoOutput.stop((err: BusinessError) => { 3405e41f4b71Sopenharmony_ci if (err) { 3406e41f4b71Sopenharmony_ci console.error(`Failed to stop the video output, error code: ${err.code}.`); 3407e41f4b71Sopenharmony_ci return; 3408e41f4b71Sopenharmony_ci } 3409e41f4b71Sopenharmony_ci console.info('Callback invoked to indicate the video output stop success.'); 3410e41f4b71Sopenharmony_ci }); 3411e41f4b71Sopenharmony_ci} 3412e41f4b71Sopenharmony_ci``` 3413e41f4b71Sopenharmony_ci 3414e41f4b71Sopenharmony_ci### stop 3415e41f4b71Sopenharmony_ci 3416e41f4b71Sopenharmony_cistop(): Promise\<void\> 3417e41f4b71Sopenharmony_ci 3418e41f4b71Sopenharmony_ciStops video recording. This API uses a promise to return the result. 3419e41f4b71Sopenharmony_ci 3420e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 3421e41f4b71Sopenharmony_ci 3422e41f4b71Sopenharmony_ci**Return value** 3423e41f4b71Sopenharmony_ci 3424e41f4b71Sopenharmony_ci| Type | Description | 3425e41f4b71Sopenharmony_ci| -------------- | ----------------------- | 3426e41f4b71Sopenharmony_ci| Promise\<void\> | Promise that returns no value.| 3427e41f4b71Sopenharmony_ci 3428e41f4b71Sopenharmony_ci**Example** 3429e41f4b71Sopenharmony_ci 3430e41f4b71Sopenharmony_ci```ts 3431e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 3432e41f4b71Sopenharmony_ci 3433e41f4b71Sopenharmony_cifunction stopVideoOutput(videoOutput: camera.VideoOutput): void { 3434e41f4b71Sopenharmony_ci videoOutput.stop().then(() => { 3435e41f4b71Sopenharmony_ci console.info('Promise returned to indicate that stop method execution success.'); 3436e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 3437e41f4b71Sopenharmony_ci console.error(`Failed to video output stop, error code: ${error.code}.`); 3438e41f4b71Sopenharmony_ci }); 3439e41f4b71Sopenharmony_ci} 3440e41f4b71Sopenharmony_ci``` 3441e41f4b71Sopenharmony_ci 3442e41f4b71Sopenharmony_ci### on('frameStart') 3443e41f4b71Sopenharmony_ci 3444e41f4b71Sopenharmony_cion(type: 'frameStart', callback: AsyncCallback\<void\>): void 3445e41f4b71Sopenharmony_ci 3446e41f4b71Sopenharmony_ciSubscribes to video recording start events. This API uses an asynchronous callback to return the result. 3447e41f4b71Sopenharmony_ci 3448e41f4b71Sopenharmony_ci> **NOTE** 3449e41f4b71Sopenharmony_ci> 3450e41f4b71Sopenharmony_ci> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**. 3451e41f4b71Sopenharmony_ci 3452e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 3453e41f4b71Sopenharmony_ci 3454e41f4b71Sopenharmony_ci**Parameters** 3455e41f4b71Sopenharmony_ci 3456e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 3457e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ----------------------------------------- | 3458e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'frameStart'**. The event can be listened for when a **videoOutput** instance is created. The event is triggered and the corresponding information is returned when the bottom layer starts exposure for the first time.| 3459e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. The recording starts as long as this event is returned. | 3460e41f4b71Sopenharmony_ci 3461e41f4b71Sopenharmony_ci**Example** 3462e41f4b71Sopenharmony_ci 3463e41f4b71Sopenharmony_ci```ts 3464e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 3465e41f4b71Sopenharmony_ci 3466e41f4b71Sopenharmony_cifunction callback(err: BusinessError): void { 3467e41f4b71Sopenharmony_ci if (err !== undefined && err.code !== 0) { 3468e41f4b71Sopenharmony_ci console.error(`Callback Error, errorCode: ${err.code}`); 3469e41f4b71Sopenharmony_ci return; 3470e41f4b71Sopenharmony_ci } 3471e41f4b71Sopenharmony_ci console.info('Video frame started'); 3472e41f4b71Sopenharmony_ci} 3473e41f4b71Sopenharmony_ci 3474e41f4b71Sopenharmony_cifunction registerVideoOutputFrameStart(videoOutput: camera.VideoOutput): void { 3475e41f4b71Sopenharmony_ci videoOutput.on('frameStart', callback); 3476e41f4b71Sopenharmony_ci} 3477e41f4b71Sopenharmony_ci``` 3478e41f4b71Sopenharmony_ci 3479e41f4b71Sopenharmony_ci### off('frameStart') 3480e41f4b71Sopenharmony_ci 3481e41f4b71Sopenharmony_cioff(type: 'frameStart', callback?: AsyncCallback\<void\>): void 3482e41f4b71Sopenharmony_ci 3483e41f4b71Sopenharmony_ciUnsubscribes from video recording start events. 3484e41f4b71Sopenharmony_ci 3485e41f4b71Sopenharmony_ci> **NOTE** 3486e41f4b71Sopenharmony_ci> 3487e41f4b71Sopenharmony_ci> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**. 3488e41f4b71Sopenharmony_ci 3489e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 3490e41f4b71Sopenharmony_ci 3491e41f4b71Sopenharmony_ci**Parameters** 3492e41f4b71Sopenharmony_ci 3493e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 3494e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ----------------------------------------- | 3495e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'frameStart'**. The event can be listened for when a **videoOutput** instance is created.| 3496e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void\> | No | Callback used to return the result. If this parameter is specified, the subscription to the specified event with the specified callback is canceled. (The callback object cannot be an anonymous function.) Otherwise, the subscriptions to the specified event with all the callbacks are canceled.| 3497e41f4b71Sopenharmony_ci 3498e41f4b71Sopenharmony_ci**Example** 3499e41f4b71Sopenharmony_ci 3500e41f4b71Sopenharmony_ci```ts 3501e41f4b71Sopenharmony_cifunction unregisterVideoOutputFrameStart(videoOutput: camera.VideoOutput): void { 3502e41f4b71Sopenharmony_ci videoOutput.off('frameStart'); 3503e41f4b71Sopenharmony_ci} 3504e41f4b71Sopenharmony_ci 3505e41f4b71Sopenharmony_ci``` 3506e41f4b71Sopenharmony_ci 3507e41f4b71Sopenharmony_ci### on('frameEnd') 3508e41f4b71Sopenharmony_ci 3509e41f4b71Sopenharmony_cion(type: 'frameEnd', callback: AsyncCallback\<void\>): void 3510e41f4b71Sopenharmony_ci 3511e41f4b71Sopenharmony_ciSubscribes to video recording stop events. This API uses an asynchronous callback to return the result. 3512e41f4b71Sopenharmony_ci 3513e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 3514e41f4b71Sopenharmony_ci 3515e41f4b71Sopenharmony_ci**Parameters** 3516e41f4b71Sopenharmony_ci 3517e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 3518e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ------------------------------------------ | 3519e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'frameEnd'**. The event can be listened for when a **videoOutput** instance is created. This event is triggered and returned when the last frame of recording is complete.| 3520e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. The recording ends as long as this event is returned. | 3521e41f4b71Sopenharmony_ci 3522e41f4b71Sopenharmony_ci**Example** 3523e41f4b71Sopenharmony_ci 3524e41f4b71Sopenharmony_ci```ts 3525e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 3526e41f4b71Sopenharmony_ci 3527e41f4b71Sopenharmony_cifunction callback(err: BusinessError): void { 3528e41f4b71Sopenharmony_ci if (err !== undefined && err.code !== 0) { 3529e41f4b71Sopenharmony_ci console.error(`Callback Error, errorCode: ${err.code}`); 3530e41f4b71Sopenharmony_ci return; 3531e41f4b71Sopenharmony_ci } 3532e41f4b71Sopenharmony_ci console.info('Video frame ended'); 3533e41f4b71Sopenharmony_ci} 3534e41f4b71Sopenharmony_ci 3535e41f4b71Sopenharmony_cifunction registerVideoOutputFrameEnd(videoOutput: camera.VideoOutput): void { 3536e41f4b71Sopenharmony_ci videoOutput.on('frameEnd', callback); 3537e41f4b71Sopenharmony_ci} 3538e41f4b71Sopenharmony_ci``` 3539e41f4b71Sopenharmony_ci 3540e41f4b71Sopenharmony_ci### off('frameEnd') 3541e41f4b71Sopenharmony_ci 3542e41f4b71Sopenharmony_cioff(type: 'frameEnd', callback?: AsyncCallback\<void\>): void 3543e41f4b71Sopenharmony_ci 3544e41f4b71Sopenharmony_ciUnsubscribes from video recording stop events. 3545e41f4b71Sopenharmony_ci 3546e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 3547e41f4b71Sopenharmony_ci 3548e41f4b71Sopenharmony_ci**Parameters** 3549e41f4b71Sopenharmony_ci 3550e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 3551e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ------------------------------------------ | 3552e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'frameEnd'**. The event can be listened for when a **videoOutput** instance is created.| 3553e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void\> | No | Callback used to return the result. If this parameter is specified, the subscription to the specified event with the specified callback is canceled. (The callback object cannot be an anonymous function.) Otherwise, the subscriptions to the specified event with all the callbacks are canceled.| 3554e41f4b71Sopenharmony_ci 3555e41f4b71Sopenharmony_ci**Example** 3556e41f4b71Sopenharmony_ci 3557e41f4b71Sopenharmony_ci```ts 3558e41f4b71Sopenharmony_cifunction unregisterVideoOutputFrameEnd(videoOutput: camera.VideoOutput): void { 3559e41f4b71Sopenharmony_ci videoOutput.off('frameEnd'); 3560e41f4b71Sopenharmony_ci} 3561e41f4b71Sopenharmony_ci``` 3562e41f4b71Sopenharmony_ci 3563e41f4b71Sopenharmony_ci### on('error') 3564e41f4b71Sopenharmony_ci 3565e41f4b71Sopenharmony_cion(type: 'error', callback: ErrorCallback): void 3566e41f4b71Sopenharmony_ci 3567e41f4b71Sopenharmony_ciSubscribes to **VideoOutput** error events. This API uses an asynchronous callback to return the result. 3568e41f4b71Sopenharmony_ci 3569e41f4b71Sopenharmony_ci> **NOTE** 3570e41f4b71Sopenharmony_ci> 3571e41f4b71Sopenharmony_ci> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**. 3572e41f4b71Sopenharmony_ci 3573e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 3574e41f4b71Sopenharmony_ci 3575e41f4b71Sopenharmony_ci**Parameters** 3576e41f4b71Sopenharmony_ci 3577e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 3578e41f4b71Sopenharmony_ci| -------- | ----------- | ---- | -------------------------------------- | 3579e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a **videoOutput** instance is created. This event is triggered and the corresponding error message is returned when an error occurs during the use of a recording-related API such as [start](#start-1) or [CameraOutput.release](#release-1).| 3580e41f4b71Sopenharmony_ci| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | Yes | Callback used to return an error code defined in [CameraErrorCode](#cameraerrorcode). | 3581e41f4b71Sopenharmony_ci 3582e41f4b71Sopenharmony_ci**Example** 3583e41f4b71Sopenharmony_ci 3584e41f4b71Sopenharmony_ci```ts 3585e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 3586e41f4b71Sopenharmony_ci 3587e41f4b71Sopenharmony_cifunction callback(err: BusinessError): void { 3588e41f4b71Sopenharmony_ci console.error(`Video output error code: ${err.code}`); 3589e41f4b71Sopenharmony_ci} 3590e41f4b71Sopenharmony_ci 3591e41f4b71Sopenharmony_cifunction registerVideoOutputError(videoOutput: camera.VideoOutput): void { 3592e41f4b71Sopenharmony_ci videoOutput.on('error', callback); 3593e41f4b71Sopenharmony_ci} 3594e41f4b71Sopenharmony_ci``` 3595e41f4b71Sopenharmony_ci 3596e41f4b71Sopenharmony_ci### off('error') 3597e41f4b71Sopenharmony_ci 3598e41f4b71Sopenharmony_cioff(type: 'error', callback?: ErrorCallback): void 3599e41f4b71Sopenharmony_ci 3600e41f4b71Sopenharmony_ciUnsubscribes from **VideoOutput** error events. 3601e41f4b71Sopenharmony_ci 3602e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 3603e41f4b71Sopenharmony_ci 3604e41f4b71Sopenharmony_ci**Parameters** 3605e41f4b71Sopenharmony_ci 3606e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 3607e41f4b71Sopenharmony_ci| -------- | ------------- | ---- | ----------------------------------- | 3608e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a **photoOutput** instance is created.| 3609e41f4b71Sopenharmony_ci| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | No | Callback used to return the result. If this parameter is specified, the subscription to the specified event with the specified callback is canceled. (The callback object cannot be an anonymous function.) Otherwise, the subscriptions to the specified event with all the callbacks are canceled.| 3610e41f4b71Sopenharmony_ci 3611e41f4b71Sopenharmony_ci**Example** 3612e41f4b71Sopenharmony_ci 3613e41f4b71Sopenharmony_ci```ts 3614e41f4b71Sopenharmony_cifunction unregisterVideoOutputError(videoOutput: camera.VideoOutput): void { 3615e41f4b71Sopenharmony_ci videoOutput.off('error'); 3616e41f4b71Sopenharmony_ci} 3617e41f4b71Sopenharmony_ci``` 3618e41f4b71Sopenharmony_ci 3619e41f4b71Sopenharmony_ci### getSupportedFrameRates<sup>12+</sup> 3620e41f4b71Sopenharmony_ci 3621e41f4b71Sopenharmony_cigetSupportedFrameRates(): Array\<FrameRateRange\> 3622e41f4b71Sopenharmony_ci 3623e41f4b71Sopenharmony_ciObtains the supported frame rates. 3624e41f4b71Sopenharmony_ci 3625e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 3626e41f4b71Sopenharmony_ci 3627e41f4b71Sopenharmony_ci**Return value** 3628e41f4b71Sopenharmony_ci 3629e41f4b71Sopenharmony_ci| Type | Description | 3630e41f4b71Sopenharmony_ci| ------------- | ------------ | 3631e41f4b71Sopenharmony_ci| Array<[FrameRateRange](#frameraterange)> | Array of supported frame rates.| 3632e41f4b71Sopenharmony_ci 3633e41f4b71Sopenharmony_ci**Example** 3634e41f4b71Sopenharmony_ci 3635e41f4b71Sopenharmony_ci```ts 3636e41f4b71Sopenharmony_cifunction getSupportedFrameRates(videoOutput: camera.VideoOutput): Array<camera.FrameRateRange> { 3637e41f4b71Sopenharmony_ci let supportedFrameRatesArray: Array<camera.FrameRateRange> = videoOutput.getSupportedFrameRates(); 3638e41f4b71Sopenharmony_ci return supportedFrameRatesArray; 3639e41f4b71Sopenharmony_ci} 3640e41f4b71Sopenharmony_ci``` 3641e41f4b71Sopenharmony_ci 3642e41f4b71Sopenharmony_ci### setFrameRate<sup>12+</sup> 3643e41f4b71Sopenharmony_ci 3644e41f4b71Sopenharmony_cisetFrameRate(minFps: number, maxFps: number): void 3645e41f4b71Sopenharmony_ci 3646e41f4b71Sopenharmony_ciSets a frame rate range for preview streams. The range must be within the supported frame rate range, which can be obtained by calling [getSupportedFrameRates](#getsupportedframerates12-1). 3647e41f4b71Sopenharmony_ci 3648e41f4b71Sopenharmony_ci> **NOTE** 3649e41f4b71Sopenharmony_ci> 3650e41f4b71Sopenharmony_ci> This API is valid only in [VideoSession](#videosession11) mode. 3651e41f4b71Sopenharmony_ci 3652e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 3653e41f4b71Sopenharmony_ci 3654e41f4b71Sopenharmony_ci**Parameters** 3655e41f4b71Sopenharmony_ci 3656e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 3657e41f4b71Sopenharmony_ci| -------- | --------------| ---- | ------------------------ | 3658e41f4b71Sopenharmony_ci| minFps | number | Yes | Minimum frame rate.| 3659e41f4b71Sopenharmony_ci| maxFps | number | Yes | Maximum frame rate.| 3660e41f4b71Sopenharmony_ci 3661e41f4b71Sopenharmony_ci**Error codes** 3662e41f4b71Sopenharmony_ci 3663e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 3664e41f4b71Sopenharmony_ci 3665e41f4b71Sopenharmony_ci| ID | Error Message | 3666e41f4b71Sopenharmony_ci| --------------- | --------------- | 3667e41f4b71Sopenharmony_ci| 7400101 | Parameter missing or parameter type incorrect. | 3668e41f4b71Sopenharmony_ci| 7400110 | Unresolved conflicts with current configurations. | 3669e41f4b71Sopenharmony_ci 3670e41f4b71Sopenharmony_ci**Example** 3671e41f4b71Sopenharmony_ci 3672e41f4b71Sopenharmony_ci```ts 3673e41f4b71Sopenharmony_cifunction setFrameRateRange(videoOutput: camera.VideoOutput, frameRateRange: Array<number>): void { 3674e41f4b71Sopenharmony_ci videoOutput.setFrameRate(frameRateRange[0], frameRateRange[1]); 3675e41f4b71Sopenharmony_ci} 3676e41f4b71Sopenharmony_ci``` 3677e41f4b71Sopenharmony_ci 3678e41f4b71Sopenharmony_ci### getActiveFrameRate<sup>12+</sup> 3679e41f4b71Sopenharmony_ci 3680e41f4b71Sopenharmony_cigetActiveFrameRate(): FrameRateRange 3681e41f4b71Sopenharmony_ci 3682e41f4b71Sopenharmony_ciObtains the configured frame rate range. 3683e41f4b71Sopenharmony_ci 3684e41f4b71Sopenharmony_ciThis API is valid only after [setFrameRate](#setframerate12-1) is called to set a frame rate range for preview streams. 3685e41f4b71Sopenharmony_ci 3686e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 3687e41f4b71Sopenharmony_ci 3688e41f4b71Sopenharmony_ci**Return value** 3689e41f4b71Sopenharmony_ci 3690e41f4b71Sopenharmony_ci| Type | Description | 3691e41f4b71Sopenharmony_ci| ------------- | ------------ | 3692e41f4b71Sopenharmony_ci| [FrameRateRange](#frameraterange) | Frame rate range.| 3693e41f4b71Sopenharmony_ci 3694e41f4b71Sopenharmony_ci**Example** 3695e41f4b71Sopenharmony_ci 3696e41f4b71Sopenharmony_ci```ts 3697e41f4b71Sopenharmony_cifunction getActiveFrameRate(videoOutput: camera.VideoOutput): camera.FrameRateRange { 3698e41f4b71Sopenharmony_ci let activeFrameRate: camera.FrameRateRange = videoOutput.getActiveFrameRate(); 3699e41f4b71Sopenharmony_ci return activeFrameRate; 3700e41f4b71Sopenharmony_ci} 3701e41f4b71Sopenharmony_ci``` 3702e41f4b71Sopenharmony_ci 3703e41f4b71Sopenharmony_ci### getActiveProfile<sup>12+</sup> 3704e41f4b71Sopenharmony_ci 3705e41f4b71Sopenharmony_cigetActiveProfile(): VideoProfile 3706e41f4b71Sopenharmony_ci 3707e41f4b71Sopenharmony_ciObtains the profile that takes effect currently. 3708e41f4b71Sopenharmony_ci 3709e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 3710e41f4b71Sopenharmony_ci 3711e41f4b71Sopenharmony_ci**Return value** 3712e41f4b71Sopenharmony_ci 3713e41f4b71Sopenharmony_ci| Type | Description | 3714e41f4b71Sopenharmony_ci| ------------- |-----------| 3715e41f4b71Sopenharmony_ci| [VideoProfile](#videoprofile) | Profile obtained.| 3716e41f4b71Sopenharmony_ci 3717e41f4b71Sopenharmony_ci**Error codes** 3718e41f4b71Sopenharmony_ci 3719e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 3720e41f4b71Sopenharmony_ci 3721e41f4b71Sopenharmony_ci| ID | Error Message | 3722e41f4b71Sopenharmony_ci|---------|------------------------------| 3723e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 3724e41f4b71Sopenharmony_ci 3725e41f4b71Sopenharmony_ci**Example** 3726e41f4b71Sopenharmony_ci 3727e41f4b71Sopenharmony_ci```ts 3728e41f4b71Sopenharmony_cifunction testGetActiveProfile(videoOutput: camera.VideoOutput): camera.Profile | undefined { 3729e41f4b71Sopenharmony_ci let activeProfile: camera.VideoProfile | undefined = undefined; 3730e41f4b71Sopenharmony_ci try { 3731e41f4b71Sopenharmony_ci activeProfile = videoOutput.getActiveProfile(); 3732e41f4b71Sopenharmony_ci } catch (error) { 3733e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 3734e41f4b71Sopenharmony_ci let err = error as BusinessError; 3735e41f4b71Sopenharmony_ci console.error(`The videoOutput.getActiveProfile call failed. error code: ${err.code}`); 3736e41f4b71Sopenharmony_ci } 3737e41f4b71Sopenharmony_ci return activeProfile; 3738e41f4b71Sopenharmony_ci} 3739e41f4b71Sopenharmony_ci``` 3740e41f4b71Sopenharmony_ci 3741e41f4b71Sopenharmony_ci### getVideoRotation<sup>12+</sup> 3742e41f4b71Sopenharmony_ci 3743e41f4b71Sopenharmony_cigetVideoRotation(imageRotation: ImageRotation): ImageRotation 3744e41f4b71Sopenharmony_ci 3745e41f4b71Sopenharmony_ciObtains the video rotation degree. 3746e41f4b71Sopenharmony_ci 3747e41f4b71Sopenharmony_ci- Device' natural orientation: The default orientation of the device (phone) is in portrait mode, with the charging port facing downward. 3748e41f4b71Sopenharmony_ci- Camera lens angle: equivalent to the angle at which the camera is rotated clockwise to match the device's natural direction. The rear camera sensor of a phone is installed in portrait mode. Therefore, it needs to be rotated by 90 degrees clockwise to match the device's natural direction. 3749e41f4b71Sopenharmony_ci- Screen orientation: The upper left corner of the image displayed on the screen is the first pixel, which is the coordinate origin. In the case of lock screen, the direction is the same as the device's natural orientation. 3750e41f4b71Sopenharmony_ci 3751e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 3752e41f4b71Sopenharmony_ci 3753e41f4b71Sopenharmony_ci**Parameters** 3754e41f4b71Sopenharmony_ci 3755e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 3756e41f4b71Sopenharmony_ci| -------- | --------------| ---- | ------------------------ | 3757e41f4b71Sopenharmony_ci| imageRotation | [ImageRotation](#imagerotation) | Yes | Screen display compensation angle (the angle required for rotating the image counterclockwise from the device's natural orientation to the screen orientation during image display).| 3758e41f4b71Sopenharmony_ci 3759e41f4b71Sopenharmony_ci**Return value** 3760e41f4b71Sopenharmony_ci 3761e41f4b71Sopenharmony_ci| Type | Description | 3762e41f4b71Sopenharmony_ci| ------------- |-----------| 3763e41f4b71Sopenharmony_ci| [ImageRotation](#imagerotation) | Video rotation degree.| 3764e41f4b71Sopenharmony_ci 3765e41f4b71Sopenharmony_ci**Error codes** 3766e41f4b71Sopenharmony_ci 3767e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 3768e41f4b71Sopenharmony_ci 3769e41f4b71Sopenharmony_ci| ID | Error Message | 3770e41f4b71Sopenharmony_ci|---------|------------------------------| 3771e41f4b71Sopenharmony_ci| 7400101 | Parameter missing or parameter type incorrect. | 3772e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 3773e41f4b71Sopenharmony_ci 3774e41f4b71Sopenharmony_ci**Example** 3775e41f4b71Sopenharmony_ci 3776e41f4b71Sopenharmony_ci```ts 3777e41f4b71Sopenharmony_cifunction testGetVideoRotation(videoOutput: camera.PreviewOutput, imageRotation : camera.ImageRotation): camera.ImageRotation { 3778e41f4b71Sopenharmony_ci let videoRotation: camera.ImageRotation; 3779e41f4b71Sopenharmony_ci try { 3780e41f4b71Sopenharmony_ci videoRotation = videoOutput.getVideoRotation(imageRotation); 3781e41f4b71Sopenharmony_ci console.log(`Video rotation is: ${videoRotation}`); 3782e41f4b71Sopenharmony_ci } catch (error) { 3783e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 3784e41f4b71Sopenharmony_ci let err = error as BusinessError; 3785e41f4b71Sopenharmony_ci console.error(`The videoOutput.getVideoRotation call failed. error code: ${err.code}`); 3786e41f4b71Sopenharmony_ci } 3787e41f4b71Sopenharmony_ci return; 3788e41f4b71Sopenharmony_ci} 3789e41f4b71Sopenharmony_ci``` 3790e41f4b71Sopenharmony_ci 3791e41f4b71Sopenharmony_ci## MetadataOutput 3792e41f4b71Sopenharmony_ci 3793e41f4b71Sopenharmony_ciImplements metadata streams. It inherits from [CameraOutput](#cameraoutput). 3794e41f4b71Sopenharmony_ci 3795e41f4b71Sopenharmony_ci### start 3796e41f4b71Sopenharmony_ci 3797e41f4b71Sopenharmony_cistart(callback: AsyncCallback\<void\>): void 3798e41f4b71Sopenharmony_ci 3799e41f4b71Sopenharmony_ciStarts to output metadata. This API uses an asynchronous callback to return the result. 3800e41f4b71Sopenharmony_ci 3801e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 3802e41f4b71Sopenharmony_ci 3803e41f4b71Sopenharmony_ci**Parameters** 3804e41f4b71Sopenharmony_ci 3805e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 3806e41f4b71Sopenharmony_ci| -------- | -------------------------- | ---- | ------------------- | 3807e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 3808e41f4b71Sopenharmony_ci 3809e41f4b71Sopenharmony_ci**Error codes** 3810e41f4b71Sopenharmony_ci 3811e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 3812e41f4b71Sopenharmony_ci 3813e41f4b71Sopenharmony_ci| ID | Error Message | 3814e41f4b71Sopenharmony_ci| --------------- | --------------- | 3815e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 3816e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 3817e41f4b71Sopenharmony_ci 3818e41f4b71Sopenharmony_ci**Example** 3819e41f4b71Sopenharmony_ci 3820e41f4b71Sopenharmony_ci```ts 3821e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 3822e41f4b71Sopenharmony_ci 3823e41f4b71Sopenharmony_cifunction startMetadataOutput(metadataOutput: camera.MetadataOutput): void { 3824e41f4b71Sopenharmony_ci metadataOutput.start((err: BusinessError) => { 3825e41f4b71Sopenharmony_ci if (err) { 3826e41f4b71Sopenharmony_ci console.error(`Failed to start metadata output, error code: ${err.code}.`); 3827e41f4b71Sopenharmony_ci return; 3828e41f4b71Sopenharmony_ci } 3829e41f4b71Sopenharmony_ci console.info('Callback returned with metadata output started.'); 3830e41f4b71Sopenharmony_ci }); 3831e41f4b71Sopenharmony_ci} 3832e41f4b71Sopenharmony_ci``` 3833e41f4b71Sopenharmony_ci 3834e41f4b71Sopenharmony_ci### start 3835e41f4b71Sopenharmony_ci 3836e41f4b71Sopenharmony_cistart(): Promise\<void\> 3837e41f4b71Sopenharmony_ci 3838e41f4b71Sopenharmony_ciStarts to output metadata. This API uses a promise to return the result. 3839e41f4b71Sopenharmony_ci 3840e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 3841e41f4b71Sopenharmony_ci 3842e41f4b71Sopenharmony_ci**Return value** 3843e41f4b71Sopenharmony_ci 3844e41f4b71Sopenharmony_ci| Type | Description | 3845e41f4b71Sopenharmony_ci| ---------------------- | ------------------------ | 3846e41f4b71Sopenharmony_ci| Promise\<void\> | Promise that returns no value.| 3847e41f4b71Sopenharmony_ci 3848e41f4b71Sopenharmony_ci**Error codes** 3849e41f4b71Sopenharmony_ci 3850e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 3851e41f4b71Sopenharmony_ci 3852e41f4b71Sopenharmony_ci| ID | Error Message | 3853e41f4b71Sopenharmony_ci| --------------- | --------------- | 3854e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 3855e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 3856e41f4b71Sopenharmony_ci 3857e41f4b71Sopenharmony_ci**Example** 3858e41f4b71Sopenharmony_ci 3859e41f4b71Sopenharmony_ci```ts 3860e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 3861e41f4b71Sopenharmony_ci 3862e41f4b71Sopenharmony_cifunction startMetadataOutput(metadataOutput: camera.MetadataOutput): void { 3863e41f4b71Sopenharmony_ci metadataOutput.start().then(() => { 3864e41f4b71Sopenharmony_ci console.info('Callback returned with metadata output started.'); 3865e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 3866e41f4b71Sopenharmony_ci console.error(`Failed to metadata output stop, error code: ${error.code}`); 3867e41f4b71Sopenharmony_ci }); 3868e41f4b71Sopenharmony_ci} 3869e41f4b71Sopenharmony_ci``` 3870e41f4b71Sopenharmony_ci 3871e41f4b71Sopenharmony_ci### stop 3872e41f4b71Sopenharmony_ci 3873e41f4b71Sopenharmony_cistop(callback: AsyncCallback\<void\>): void 3874e41f4b71Sopenharmony_ci 3875e41f4b71Sopenharmony_ciStops outputting metadata. This API uses an asynchronous callback to return the result. 3876e41f4b71Sopenharmony_ci 3877e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 3878e41f4b71Sopenharmony_ci 3879e41f4b71Sopenharmony_ci**Parameters** 3880e41f4b71Sopenharmony_ci 3881e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 3882e41f4b71Sopenharmony_ci| -------- | -------------------------- | ---- | ------------------- | 3883e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| 3884e41f4b71Sopenharmony_ci 3885e41f4b71Sopenharmony_ci**Example** 3886e41f4b71Sopenharmony_ci 3887e41f4b71Sopenharmony_ci```ts 3888e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 3889e41f4b71Sopenharmony_ci 3890e41f4b71Sopenharmony_cifunction stopMetadataOutput(metadataOutput: camera.MetadataOutput): void { 3891e41f4b71Sopenharmony_ci metadataOutput.stop((err: BusinessError) => { 3892e41f4b71Sopenharmony_ci if (err) { 3893e41f4b71Sopenharmony_ci console.error(`Failed to stop the metadata output, error code: ${err.code}.`); 3894e41f4b71Sopenharmony_ci return; 3895e41f4b71Sopenharmony_ci } 3896e41f4b71Sopenharmony_ci console.info('Callback returned with metadata output stopped.'); 3897e41f4b71Sopenharmony_ci }) 3898e41f4b71Sopenharmony_ci} 3899e41f4b71Sopenharmony_ci``` 3900e41f4b71Sopenharmony_ci 3901e41f4b71Sopenharmony_ci### stop 3902e41f4b71Sopenharmony_ci 3903e41f4b71Sopenharmony_cistop(): Promise\<void\> 3904e41f4b71Sopenharmony_ci 3905e41f4b71Sopenharmony_ciStops outputting metadata. This API uses a promise to return the result. 3906e41f4b71Sopenharmony_ci 3907e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 3908e41f4b71Sopenharmony_ci 3909e41f4b71Sopenharmony_ci**Return value** 3910e41f4b71Sopenharmony_ci 3911e41f4b71Sopenharmony_ci| Type | Description | 3912e41f4b71Sopenharmony_ci| ---------------------- | --------------------------- | 3913e41f4b71Sopenharmony_ci| Promise\<void\> | Promise that returns no value.| 3914e41f4b71Sopenharmony_ci 3915e41f4b71Sopenharmony_ci**Example** 3916e41f4b71Sopenharmony_ci 3917e41f4b71Sopenharmony_ci```ts 3918e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 3919e41f4b71Sopenharmony_ci 3920e41f4b71Sopenharmony_cifunction stopMetadataOutput(metadataOutput: camera.MetadataOutput): void { 3921e41f4b71Sopenharmony_ci metadataOutput.stop().then(() => { 3922e41f4b71Sopenharmony_ci console.info('Callback returned with metadata output stopped.'); 3923e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 3924e41f4b71Sopenharmony_ci console.error(`Failed to metadata output stop, error code: ${error.code}`); 3925e41f4b71Sopenharmony_ci }); 3926e41f4b71Sopenharmony_ci} 3927e41f4b71Sopenharmony_ci``` 3928e41f4b71Sopenharmony_ci 3929e41f4b71Sopenharmony_ci### on('metadataObjectsAvailable') 3930e41f4b71Sopenharmony_ci 3931e41f4b71Sopenharmony_cion(type: 'metadataObjectsAvailable', callback: AsyncCallback\<Array\<MetadataObject\>\>): void 3932e41f4b71Sopenharmony_ci 3933e41f4b71Sopenharmony_ciSubscribes to events indicating available metadata objects. This API uses an asynchronous callback to return the result. 3934e41f4b71Sopenharmony_ci 3935e41f4b71Sopenharmony_ci> **NOTE** 3936e41f4b71Sopenharmony_ci> 3937e41f4b71Sopenharmony_ci> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**. 3938e41f4b71Sopenharmony_ci 3939e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 3940e41f4b71Sopenharmony_ci 3941e41f4b71Sopenharmony_ci**Parameters** 3942e41f4b71Sopenharmony_ci 3943e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 3944e41f4b71Sopenharmony_ci| -------- | -------------- | ---- | ------------------------------------ | 3945e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'metadataObjectsAvailable'**. The event can be listened for when a **metadataOutput** instance is created. This event is triggered and the corresponding metadata is returned when valid metadata is detected.| 3946e41f4b71Sopenharmony_ci| callback | AsyncCallback\<Array\<[MetadataObject](#metadataobject)\>\> | Yes | Callback used to return the metadata.| 3947e41f4b71Sopenharmony_ci 3948e41f4b71Sopenharmony_ci**Example** 3949e41f4b71Sopenharmony_ci 3950e41f4b71Sopenharmony_ci```ts 3951e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 3952e41f4b71Sopenharmony_ci 3953e41f4b71Sopenharmony_cifunction callback(err: BusinessError, metadataObjectArr: Array<camera.MetadataObject>): void { 3954e41f4b71Sopenharmony_ci if (err !== undefined && err.code !== 0) { 3955e41f4b71Sopenharmony_ci console.error(`Callback Error, errorCode: ${err.code}`); 3956e41f4b71Sopenharmony_ci return; 3957e41f4b71Sopenharmony_ci } 3958e41f4b71Sopenharmony_ci console.info('metadata output metadataObjectsAvailable'); 3959e41f4b71Sopenharmony_ci} 3960e41f4b71Sopenharmony_ci 3961e41f4b71Sopenharmony_cifunction registerMetadataObjectsAvailable(metadataOutput: camera.MetadataOutput): void { 3962e41f4b71Sopenharmony_ci metadataOutput.on('metadataObjectsAvailable', callback); 3963e41f4b71Sopenharmony_ci} 3964e41f4b71Sopenharmony_ci``` 3965e41f4b71Sopenharmony_ci 3966e41f4b71Sopenharmony_ci### off('metadataObjectsAvailable') 3967e41f4b71Sopenharmony_ci 3968e41f4b71Sopenharmony_cioff(type: 'metadataObjectsAvailable', callback?: AsyncCallback\<Array\<MetadataObject\>\>): void 3969e41f4b71Sopenharmony_ci 3970e41f4b71Sopenharmony_ciUnsubscribes from events indicating available metadata objects. 3971e41f4b71Sopenharmony_ci 3972e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 3973e41f4b71Sopenharmony_ci 3974e41f4b71Sopenharmony_ci**Parameters** 3975e41f4b71Sopenharmony_ci 3976e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 3977e41f4b71Sopenharmony_ci| -------- | -------------- | ---- | ------------------------------------ | 3978e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'metadataObjectsAvailable'**. The event can be listened for when a **metadataOutput** instance is created.| 3979e41f4b71Sopenharmony_ci| callback | AsyncCallback\<Array\<[MetadataObject](#metadataobject)\>\> | No | Callback used to return the result. If this parameter is specified, the subscription to the specified event with the specified callback is canceled. (The callback object cannot be an anonymous function.) Otherwise, the subscriptions to the specified event with all the callbacks are canceled.| 3980e41f4b71Sopenharmony_ci 3981e41f4b71Sopenharmony_ci**Example** 3982e41f4b71Sopenharmony_ci 3983e41f4b71Sopenharmony_ci```ts 3984e41f4b71Sopenharmony_cifunction unregisterMetadataObjectsAvailable(metadataOutput: camera.MetadataOutput): void { 3985e41f4b71Sopenharmony_ci metadataOutput.off('metadataObjectsAvailable'); 3986e41f4b71Sopenharmony_ci} 3987e41f4b71Sopenharmony_ci``` 3988e41f4b71Sopenharmony_ci 3989e41f4b71Sopenharmony_ci### on('error') 3990e41f4b71Sopenharmony_ci 3991e41f4b71Sopenharmony_cion(type: 'error', callback: ErrorCallback): void 3992e41f4b71Sopenharmony_ci 3993e41f4b71Sopenharmony_ciSubscribes to metadata error events. This API uses an asynchronous callback to return the result. 3994e41f4b71Sopenharmony_ci 3995e41f4b71Sopenharmony_ci> **NOTE** 3996e41f4b71Sopenharmony_ci> 3997e41f4b71Sopenharmony_ci> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**. 3998e41f4b71Sopenharmony_ci 3999e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 4000e41f4b71Sopenharmony_ci 4001e41f4b71Sopenharmony_ci**Parameters** 4002e41f4b71Sopenharmony_ci 4003e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 4004e41f4b71Sopenharmony_ci| -------- | ------------- | ---- | --------------------------------------- | 4005e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a **metadataOutput** instance is created. This event is triggered and the corresponding error message is returned when an error occurs during the use of a metadata-related API such as [start](#start-3) or [CameraOutput.release](#release-1).| 4006e41f4b71Sopenharmony_ci| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | Yes | Callback used to return an error code defined in [CameraErrorCode](#cameraerrorcode). | 4007e41f4b71Sopenharmony_ci 4008e41f4b71Sopenharmony_ci**Example** 4009e41f4b71Sopenharmony_ci 4010e41f4b71Sopenharmony_ci```ts 4011e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 4012e41f4b71Sopenharmony_ci 4013e41f4b71Sopenharmony_cifunction callback(metadataOutputError: BusinessError): void { 4014e41f4b71Sopenharmony_ci console.error(`Metadata output error code: ${metadataOutputError.code}`); 4015e41f4b71Sopenharmony_ci} 4016e41f4b71Sopenharmony_ci 4017e41f4b71Sopenharmony_cifunction registerMetadataOutputError(metadataOutput: camera.MetadataOutput): void { 4018e41f4b71Sopenharmony_ci metadataOutput.on('error', callback); 4019e41f4b71Sopenharmony_ci} 4020e41f4b71Sopenharmony_ci``` 4021e41f4b71Sopenharmony_ci 4022e41f4b71Sopenharmony_ci### off('error') 4023e41f4b71Sopenharmony_ci 4024e41f4b71Sopenharmony_cioff(type: 'error', callback?: ErrorCallback): void 4025e41f4b71Sopenharmony_ci 4026e41f4b71Sopenharmony_ciUnsubscribes from metadata error events. 4027e41f4b71Sopenharmony_ci 4028e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 4029e41f4b71Sopenharmony_ci 4030e41f4b71Sopenharmony_ci**Parameters** 4031e41f4b71Sopenharmony_ci 4032e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 4033e41f4b71Sopenharmony_ci| -------- | ------------- | ---- | --------------------------------------- | 4034e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a **metadataOutput** instance is created.| 4035e41f4b71Sopenharmony_ci| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | No | Callback used to return the result. If this parameter is specified, the subscription to the specified event with the specified callback is canceled. (The callback object cannot be an anonymous function.) Otherwise, the subscriptions to the specified event with all the callbacks are canceled.| 4036e41f4b71Sopenharmony_ci 4037e41f4b71Sopenharmony_ci**Example** 4038e41f4b71Sopenharmony_ci 4039e41f4b71Sopenharmony_ci```ts 4040e41f4b71Sopenharmony_cifunction unregisterMetadataOutputError(metadataOutput: camera.MetadataOutput): void { 4041e41f4b71Sopenharmony_ci metadataOutput.off('error'); 4042e41f4b71Sopenharmony_ci} 4043e41f4b71Sopenharmony_ci``` 4044e41f4b71Sopenharmony_ci 4045e41f4b71Sopenharmony_ci## MetadataObjectType 4046e41f4b71Sopenharmony_ci 4047e41f4b71Sopenharmony_ciEnumerates the metadata object types. 4048e41f4b71Sopenharmony_ci 4049e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 4050e41f4b71Sopenharmony_ci 4051e41f4b71Sopenharmony_ci| Name | Value | Description | 4052e41f4b71Sopenharmony_ci| ------------------------- | ---- | ----------------- | 4053e41f4b71Sopenharmony_ci| FACE_DETECTION | 0 | Metadata object used for face detection.<br> The detection point must be in the coordinate system (0-1), where the upper left corner is (0, 0) and the lower right corner is (1, 1).<br> The coordinate system is based on the horizontal device direction with the device's charging port on the right.<br>If the layout of a preview screen of an application is based on the vertical direction with the charging port on the lower side,<br>the layout width and height are (w, h) and the return point is (x, y), then the coordinate point after conversion is (1-y, x).| 4054e41f4b71Sopenharmony_ci 4055e41f4b71Sopenharmony_ci## Rect 4056e41f4b71Sopenharmony_ci 4057e41f4b71Sopenharmony_ciDefines a rectangle. 4058e41f4b71Sopenharmony_ci 4059e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 4060e41f4b71Sopenharmony_ci 4061e41f4b71Sopenharmony_ci| Name | Type | Read-only | Optional | Description | 4062e41f4b71Sopenharmony_ci| -------- | ------ | ------ |-----| --------------------- | 4063e41f4b71Sopenharmony_ci| topLeftX | number | No | No | X-axis coordinate of the upper left corner of the rectangle. | 4064e41f4b71Sopenharmony_ci| topLeftY | number | No | No | Y-axis coordinate of the upper left corner of the rectangle. | 4065e41f4b71Sopenharmony_ci| width | number | No | No | Width of the rectangle, which is a relative value. The value range is [0, 1]. | 4066e41f4b71Sopenharmony_ci| height | number | No | No | Height of the rectangle, which is a relative value. The value range is [0, 1]. | 4067e41f4b71Sopenharmony_ci 4068e41f4b71Sopenharmony_ci## MetadataObject 4069e41f4b71Sopenharmony_ci 4070e41f4b71Sopenharmony_ciImplements camera metadata, which is the data source of [CameraInput](#camerainput). The metadata is obtained through metadataOutput.on('metadataObjectsAvailable'). 4071e41f4b71Sopenharmony_ci 4072e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 4073e41f4b71Sopenharmony_ci 4074e41f4b71Sopenharmony_ci| Name | Type | Read-only| Optional|Description | 4075e41f4b71Sopenharmony_ci| ----------- | ------------------------------------------- | ---- | ---- | ----------------- | 4076e41f4b71Sopenharmony_ci| type | [MetadataObjectType](#metadataobjecttype) | Yes | No | Metadata object type. | 4077e41f4b71Sopenharmony_ci| timestamp | number | Yes | No | Current timestamp, in milliseconds.| 4078e41f4b71Sopenharmony_ci| boundingBox | [Rect](#rect) | Yes | No | Metadata rectangle. | 4079e41f4b71Sopenharmony_ci 4080e41f4b71Sopenharmony_ci## FlashMode 4081e41f4b71Sopenharmony_ci 4082e41f4b71Sopenharmony_ciEnumerates the flash modes. 4083e41f4b71Sopenharmony_ci 4084e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 4085e41f4b71Sopenharmony_ci 4086e41f4b71Sopenharmony_ci| Name | Value | Description | 4087e41f4b71Sopenharmony_ci| ---------------------- | ---- | ---------- | 4088e41f4b71Sopenharmony_ci| FLASH_MODE_CLOSE | 0 | The flash is off.| 4089e41f4b71Sopenharmony_ci| FLASH_MODE_OPEN | 1 | The flash is on.| 4090e41f4b71Sopenharmony_ci| FLASH_MODE_AUTO | 2 | The flash mode is auto, indicating that the flash fires automatically depending on the photo capture conditions.| 4091e41f4b71Sopenharmony_ci| FLASH_MODE_ALWAYS_OPEN | 3 | The flash is steady on.| 4092e41f4b71Sopenharmony_ci 4093e41f4b71Sopenharmony_ci## ExposureMode 4094e41f4b71Sopenharmony_ci 4095e41f4b71Sopenharmony_ciEnumerates the exposure modes. 4096e41f4b71Sopenharmony_ci 4097e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 4098e41f4b71Sopenharmony_ci 4099e41f4b71Sopenharmony_ci| Name | Value | Description | 4100e41f4b71Sopenharmony_ci| ----------------------------- | ---- | ----------- | 4101e41f4b71Sopenharmony_ci| EXPOSURE_MODE_LOCKED | 0 | Exposure locked. The metering point cannot be set.| 4102e41f4b71Sopenharmony_ci| EXPOSURE_MODE_AUTO | 1 | Auto exposure. The metering point can be set by calling [AutoExposure.setMeteringPoint](#setmeteringpoint11).| 4103e41f4b71Sopenharmony_ci| EXPOSURE_MODE_CONTINUOUS_AUTO | 2 | Continuous auto exposure. The metering point cannot be set.| 4104e41f4b71Sopenharmony_ci 4105e41f4b71Sopenharmony_ci## FocusMode 4106e41f4b71Sopenharmony_ci 4107e41f4b71Sopenharmony_ciEnumerates the focus modes. 4108e41f4b71Sopenharmony_ci 4109e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 4110e41f4b71Sopenharmony_ci 4111e41f4b71Sopenharmony_ci| Name | Value | Description | 4112e41f4b71Sopenharmony_ci| -------------------------- | ---- | ------------ | 4113e41f4b71Sopenharmony_ci| FOCUS_MODE_MANUAL | 0 | Manual focus. The focal length of the camera can be manually set to change the focus position. However, the focal point cannot be set. | 4114e41f4b71Sopenharmony_ci| FOCUS_MODE_CONTINUOUS_AUTO | 1 | Continuous auto focus. The focal point cannot be set.| 4115e41f4b71Sopenharmony_ci| FOCUS_MODE_AUTO | 2 | Auto focus. The focal point can be set by calling [Focus.setFocusPoint](#setfocuspoint11), and auto focus is performed once based on the focal point. | 4116e41f4b71Sopenharmony_ci| FOCUS_MODE_LOCKED | 3 | Focus locked. The focal point cannot be set. | 4117e41f4b71Sopenharmony_ci 4118e41f4b71Sopenharmony_ci## FocusState 4119e41f4b71Sopenharmony_ci 4120e41f4b71Sopenharmony_ciEnumerates the focus states. 4121e41f4b71Sopenharmony_ci 4122e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 4123e41f4b71Sopenharmony_ci 4124e41f4b71Sopenharmony_ci| Name | Value | Description | 4125e41f4b71Sopenharmony_ci| --------------------- | ---- | --------- | 4126e41f4b71Sopenharmony_ci| FOCUS_STATE_SCAN | 0 | Focusing. | 4127e41f4b71Sopenharmony_ci| FOCUS_STATE_FOCUSED | 1 | Focused. | 4128e41f4b71Sopenharmony_ci| FOCUS_STATE_UNFOCUSED | 2 | Unfocused.| 4129e41f4b71Sopenharmony_ci 4130e41f4b71Sopenharmony_ci## VideoStabilizationMode 4131e41f4b71Sopenharmony_ci 4132e41f4b71Sopenharmony_ciEnumerates the video stabilization modes. 4133e41f4b71Sopenharmony_ci 4134e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 4135e41f4b71Sopenharmony_ci 4136e41f4b71Sopenharmony_ci| Name | Value | Description | 4137e41f4b71Sopenharmony_ci| --------- | ---- | ------------ | 4138e41f4b71Sopenharmony_ci| OFF | 0 | Video stabilization is disabled. | 4139e41f4b71Sopenharmony_ci| LOW | 1 | The basic video stabilization algorithm is used. | 4140e41f4b71Sopenharmony_ci| MIDDLE | 2 | A video stabilization algorithm with a stabilization effect better than that of the **LOW** type is used. | 4141e41f4b71Sopenharmony_ci| HIGH | 3 | A video stabilization algorithm with a stabilization effect better than that of the **MIDDLE** type is used. | 4142e41f4b71Sopenharmony_ci| AUTO | 4 | Automatic video stabilization is used. | 4143e41f4b71Sopenharmony_ci 4144e41f4b71Sopenharmony_ci## Session<sup>11+</sup> 4145e41f4b71Sopenharmony_ci 4146e41f4b71Sopenharmony_ciImplements a session, which saves all [CameraInput](#camerainput) and [CameraOutput](#cameraoutput) instances required to run the camera and requests the camera to take a photo or record a video. 4147e41f4b71Sopenharmony_ci 4148e41f4b71Sopenharmony_ci### beginConfig<sup>11+</sup> 4149e41f4b71Sopenharmony_ci 4150e41f4b71Sopenharmony_cibeginConfig(): void 4151e41f4b71Sopenharmony_ci 4152e41f4b71Sopenharmony_ciStarts configuration for the session. 4153e41f4b71Sopenharmony_ci 4154e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 4155e41f4b71Sopenharmony_ci 4156e41f4b71Sopenharmony_ci**Error codes** 4157e41f4b71Sopenharmony_ci 4158e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 4159e41f4b71Sopenharmony_ci 4160e41f4b71Sopenharmony_ci| ID | Error Message | 4161e41f4b71Sopenharmony_ci| --------------- | --------------- | 4162e41f4b71Sopenharmony_ci| 7400105 | Session config locked. | 4163e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 4164e41f4b71Sopenharmony_ci 4165e41f4b71Sopenharmony_ci**Example** 4166e41f4b71Sopenharmony_ci 4167e41f4b71Sopenharmony_ci```ts 4168e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 4169e41f4b71Sopenharmony_ci 4170e41f4b71Sopenharmony_cifunction beginConfig(session: camera.Session): void { 4171e41f4b71Sopenharmony_ci try { 4172e41f4b71Sopenharmony_ci session.beginConfig(); 4173e41f4b71Sopenharmony_ci } catch (error) { 4174e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 4175e41f4b71Sopenharmony_ci let err = error as BusinessError; 4176e41f4b71Sopenharmony_ci console.error(`The beginConfig call failed. error code: ${err.code}`); 4177e41f4b71Sopenharmony_ci } 4178e41f4b71Sopenharmony_ci} 4179e41f4b71Sopenharmony_ci``` 4180e41f4b71Sopenharmony_ci 4181e41f4b71Sopenharmony_ci### commitConfig<sup>11+</sup> 4182e41f4b71Sopenharmony_ci 4183e41f4b71Sopenharmony_cicommitConfig(callback: AsyncCallback\<void\>): void 4184e41f4b71Sopenharmony_ci 4185e41f4b71Sopenharmony_ciCommits the configuration for this session. This API uses an asynchronous callback to return the result. 4186e41f4b71Sopenharmony_ci 4187e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 4188e41f4b71Sopenharmony_ci 4189e41f4b71Sopenharmony_ci**Parameters** 4190e41f4b71Sopenharmony_ci 4191e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 4192e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | -------------------- | 4193e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 4194e41f4b71Sopenharmony_ci 4195e41f4b71Sopenharmony_ci**Error codes** 4196e41f4b71Sopenharmony_ci 4197e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 4198e41f4b71Sopenharmony_ci 4199e41f4b71Sopenharmony_ci| ID | Error Message | 4200e41f4b71Sopenharmony_ci| --------------- | --------------- | 4201e41f4b71Sopenharmony_ci| 7400102 | Operation not allowed. | 4202e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 4203e41f4b71Sopenharmony_ci 4204e41f4b71Sopenharmony_ci**Example** 4205e41f4b71Sopenharmony_ci 4206e41f4b71Sopenharmony_ci```ts 4207e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 4208e41f4b71Sopenharmony_ci 4209e41f4b71Sopenharmony_cifunction commitConfig(session: camera.Session): void { 4210e41f4b71Sopenharmony_ci session.commitConfig((err: BusinessError) => { 4211e41f4b71Sopenharmony_ci if (err) { 4212e41f4b71Sopenharmony_ci console.error(`The commitConfig call failed. error code: ${err.code}`); 4213e41f4b71Sopenharmony_ci return; 4214e41f4b71Sopenharmony_ci } 4215e41f4b71Sopenharmony_ci console.info('Callback invoked to indicate the commit config success.'); 4216e41f4b71Sopenharmony_ci }); 4217e41f4b71Sopenharmony_ci} 4218e41f4b71Sopenharmony_ci``` 4219e41f4b71Sopenharmony_ci 4220e41f4b71Sopenharmony_ci### commitConfig<sup>11+</sup> 4221e41f4b71Sopenharmony_ci 4222e41f4b71Sopenharmony_cicommitConfig(): Promise\<void\> 4223e41f4b71Sopenharmony_ci 4224e41f4b71Sopenharmony_ciCommits the configuration for this session. This API uses a promise to return the result. 4225e41f4b71Sopenharmony_ci 4226e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 4227e41f4b71Sopenharmony_ci 4228e41f4b71Sopenharmony_ci**Return value** 4229e41f4b71Sopenharmony_ci 4230e41f4b71Sopenharmony_ci| Type | Description | 4231e41f4b71Sopenharmony_ci| -------------- | ------------------------ | 4232e41f4b71Sopenharmony_ci| Promise\<void\> | Promise that returns no value.| 4233e41f4b71Sopenharmony_ci 4234e41f4b71Sopenharmony_ci**Error codes** 4235e41f4b71Sopenharmony_ci 4236e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 4237e41f4b71Sopenharmony_ci 4238e41f4b71Sopenharmony_ci| ID | Error Message | 4239e41f4b71Sopenharmony_ci| --------------- | --------------- | 4240e41f4b71Sopenharmony_ci| 7400102 | Operation not allowed. | 4241e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 4242e41f4b71Sopenharmony_ci 4243e41f4b71Sopenharmony_ci**Example** 4244e41f4b71Sopenharmony_ci 4245e41f4b71Sopenharmony_ci```ts 4246e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 4247e41f4b71Sopenharmony_ci 4248e41f4b71Sopenharmony_cifunction commitConfig(session: camera.Session): void { 4249e41f4b71Sopenharmony_ci session.commitConfig().then(() => { 4250e41f4b71Sopenharmony_ci console.info('Promise returned to indicate the commit config success.'); 4251e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 4252e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 4253e41f4b71Sopenharmony_ci console.error(`The commitConfig call failed. error code: ${error.code}`); 4254e41f4b71Sopenharmony_ci }); 4255e41f4b71Sopenharmony_ci} 4256e41f4b71Sopenharmony_ci``` 4257e41f4b71Sopenharmony_ci 4258e41f4b71Sopenharmony_ci### canAddInput<sup>11+</sup> 4259e41f4b71Sopenharmony_ci 4260e41f4b71Sopenharmony_cicanAddInput(cameraInput: CameraInput): boolean 4261e41f4b71Sopenharmony_ci 4262e41f4b71Sopenharmony_ciDetermines whether a **CameraInput** instance can be added to this session. This API must be called after [beginConfig](#beginconfig11) and before [commitConfig](#commitconfig11-1). 4263e41f4b71Sopenharmony_ci 4264e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 4265e41f4b71Sopenharmony_ci 4266e41f4b71Sopenharmony_ci**Parameters** 4267e41f4b71Sopenharmony_ci 4268e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 4269e41f4b71Sopenharmony_ci| ----------- | --------------------------- | ---- | ------------------------ | 4270e41f4b71Sopenharmony_ci| cameraInput | [CameraInput](#camerainput) | Yes | **CameraInput** instance to add.| 4271e41f4b71Sopenharmony_ci 4272e41f4b71Sopenharmony_ci**Return value** 4273e41f4b71Sopenharmony_ci 4274e41f4b71Sopenharmony_ci| Type | Description | 4275e41f4b71Sopenharmony_ci| -------------- | ------------------------ | 4276e41f4b71Sopenharmony_ci| boolean | **true**: The **CameraInput** instance can be added.<br>**false**: The **CameraInput** instance cannot be added.| 4277e41f4b71Sopenharmony_ci 4278e41f4b71Sopenharmony_ci**Example** 4279e41f4b71Sopenharmony_ci 4280e41f4b71Sopenharmony_ci```ts 4281e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 4282e41f4b71Sopenharmony_ci 4283e41f4b71Sopenharmony_cifunction canAddInput(session: camera.Session, cameraInput: camera.CameraInput): void { 4284e41f4b71Sopenharmony_ci let canAdd: boolean = session.canAddInput(cameraInput); 4285e41f4b71Sopenharmony_ci console.info(`The input canAddInput: ${canAdd}`); 4286e41f4b71Sopenharmony_ci} 4287e41f4b71Sopenharmony_ci``` 4288e41f4b71Sopenharmony_ci 4289e41f4b71Sopenharmony_ci### addInput<sup>11+</sup> 4290e41f4b71Sopenharmony_ci 4291e41f4b71Sopenharmony_ciaddInput(cameraInput: CameraInput): void 4292e41f4b71Sopenharmony_ci 4293e41f4b71Sopenharmony_ciAdds a [CameraInput](#camerainput) instance to this session. 4294e41f4b71Sopenharmony_ci 4295e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 4296e41f4b71Sopenharmony_ci 4297e41f4b71Sopenharmony_ci**Parameters** 4298e41f4b71Sopenharmony_ci 4299e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 4300e41f4b71Sopenharmony_ci| ----------- | --------------------------- | ---- | ------------------------ | 4301e41f4b71Sopenharmony_ci| cameraInput | [CameraInput](#camerainput) | Yes | **CameraInput** instance to add.| 4302e41f4b71Sopenharmony_ci 4303e41f4b71Sopenharmony_ci**Error codes** 4304e41f4b71Sopenharmony_ci 4305e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 4306e41f4b71Sopenharmony_ci 4307e41f4b71Sopenharmony_ci| ID | Error Message | 4308e41f4b71Sopenharmony_ci| --------------- | --------------- | 4309e41f4b71Sopenharmony_ci| 7400101 | Parameter missing or parameter type incorrect. | 4310e41f4b71Sopenharmony_ci| 7400102 | Operation not allowed. | 4311e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 4312e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 4313e41f4b71Sopenharmony_ci 4314e41f4b71Sopenharmony_ci**Example** 4315e41f4b71Sopenharmony_ci 4316e41f4b71Sopenharmony_ci```ts 4317e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 4318e41f4b71Sopenharmony_ci 4319e41f4b71Sopenharmony_cifunction addInput(session: camera.Session, cameraInput: camera.CameraInput): void { 4320e41f4b71Sopenharmony_ci try { 4321e41f4b71Sopenharmony_ci session.addInput(cameraInput); 4322e41f4b71Sopenharmony_ci } catch (error) { 4323e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 4324e41f4b71Sopenharmony_ci let err = error as BusinessError; 4325e41f4b71Sopenharmony_ci console.error(`The addInput call failed. error code: ${err.code}`); 4326e41f4b71Sopenharmony_ci } 4327e41f4b71Sopenharmony_ci} 4328e41f4b71Sopenharmony_ci``` 4329e41f4b71Sopenharmony_ci 4330e41f4b71Sopenharmony_ci### removeInput<sup>11+</sup> 4331e41f4b71Sopenharmony_ci 4332e41f4b71Sopenharmony_ciremoveInput(cameraInput: CameraInput): void 4333e41f4b71Sopenharmony_ci 4334e41f4b71Sopenharmony_ciRemoves a [CameraInput](#camerainput) instance from this session. This API must be called after [beginConfig](#beginconfig11) and before [commitConfig](#commitconfig11-1). 4335e41f4b71Sopenharmony_ci 4336e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 4337e41f4b71Sopenharmony_ci 4338e41f4b71Sopenharmony_ci**Parameters** 4339e41f4b71Sopenharmony_ci 4340e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 4341e41f4b71Sopenharmony_ci| ----------- | --------------------------- | ---- | ------------------------ | 4342e41f4b71Sopenharmony_ci| cameraInput | [CameraInput](#camerainput) | Yes | **CameraInput** instance to remove.| 4343e41f4b71Sopenharmony_ci 4344e41f4b71Sopenharmony_ci**Error codes** 4345e41f4b71Sopenharmony_ci 4346e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 4347e41f4b71Sopenharmony_ci 4348e41f4b71Sopenharmony_ci| ID | Error Message | 4349e41f4b71Sopenharmony_ci| --------------- | --------------- | 4350e41f4b71Sopenharmony_ci| 7400101 | Parameter missing or parameter type incorrect. | 4351e41f4b71Sopenharmony_ci| 7400102 | Operation not allowed. | 4352e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 4353e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 4354e41f4b71Sopenharmony_ci 4355e41f4b71Sopenharmony_ci**Example** 4356e41f4b71Sopenharmony_ci 4357e41f4b71Sopenharmony_ci```ts 4358e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 4359e41f4b71Sopenharmony_ci 4360e41f4b71Sopenharmony_cifunction removeInput(session: camera.Session, cameraInput: camera.CameraInput): void { 4361e41f4b71Sopenharmony_ci try { 4362e41f4b71Sopenharmony_ci session.removeInput(cameraInput); 4363e41f4b71Sopenharmony_ci } catch (error) { 4364e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 4365e41f4b71Sopenharmony_ci let err = error as BusinessError; 4366e41f4b71Sopenharmony_ci console.error(`The removeInput call failed. error code: ${err.code}`); 4367e41f4b71Sopenharmony_ci } 4368e41f4b71Sopenharmony_ci} 4369e41f4b71Sopenharmony_ci``` 4370e41f4b71Sopenharmony_ci 4371e41f4b71Sopenharmony_ci### canAddOutput<sup>11+</sup> 4372e41f4b71Sopenharmony_ci 4373e41f4b71Sopenharmony_cicanAddOutput(cameraOutput: CameraOutput): boolean 4374e41f4b71Sopenharmony_ci 4375e41f4b71Sopenharmony_ciDetermines whether a **CameraOutput** instance can be added to this session. This API must be called after [addInput](#addinput11) and before [commitConfig](#commitconfig11-1). 4376e41f4b71Sopenharmony_ci 4377e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 4378e41f4b71Sopenharmony_ci 4379e41f4b71Sopenharmony_ci**Parameters** 4380e41f4b71Sopenharmony_ci 4381e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 4382e41f4b71Sopenharmony_ci| ----------- | --------------------------- | ---- | ------------------------ | 4383e41f4b71Sopenharmony_ci| cameraOutput | [CameraOutput](#cameraoutput) | Yes | **CameraOutput** instance to add.| 4384e41f4b71Sopenharmony_ci 4385e41f4b71Sopenharmony_ci**Return value** 4386e41f4b71Sopenharmony_ci 4387e41f4b71Sopenharmony_ci| Type | Description | 4388e41f4b71Sopenharmony_ci| -------------- | ------------------------ | 4389e41f4b71Sopenharmony_ci| boolean | **true**: The **CameraOutput** instance can be added.<br>**false**: The **CameraOutput** instance cannot be added.| 4390e41f4b71Sopenharmony_ci 4391e41f4b71Sopenharmony_ci**Example** 4392e41f4b71Sopenharmony_ci 4393e41f4b71Sopenharmony_ci```ts 4394e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 4395e41f4b71Sopenharmony_ci 4396e41f4b71Sopenharmony_cifunction canAddOutput(session: camera.Session, cameraOutput: camera.CameraOutput): void { 4397e41f4b71Sopenharmony_ci let canAdd: boolean = session.canAddOutput(cameraOutput); 4398e41f4b71Sopenharmony_ci console.info(`This addOutput can add: ${canAdd}`); 4399e41f4b71Sopenharmony_ci} 4400e41f4b71Sopenharmony_ci``` 4401e41f4b71Sopenharmony_ci 4402e41f4b71Sopenharmony_ci### addOutput<sup>11+</sup> 4403e41f4b71Sopenharmony_ci 4404e41f4b71Sopenharmony_ciaddOutput(cameraOutput: CameraOutput): void 4405e41f4b71Sopenharmony_ci 4406e41f4b71Sopenharmony_ciAdds a [CameraOutput](#cameraoutput) instance to this session. 4407e41f4b71Sopenharmony_ci 4408e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 4409e41f4b71Sopenharmony_ci 4410e41f4b71Sopenharmony_ci**Parameters** 4411e41f4b71Sopenharmony_ci 4412e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 4413e41f4b71Sopenharmony_ci| ------------- | ------------------------------- | ---- | ------------------------ | 4414e41f4b71Sopenharmony_ci| cameraOutput | [CameraOutput](#cameraoutput) | Yes | **CameraOutput** instance to add.| 4415e41f4b71Sopenharmony_ci 4416e41f4b71Sopenharmony_ci**Error codes** 4417e41f4b71Sopenharmony_ci 4418e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 4419e41f4b71Sopenharmony_ci 4420e41f4b71Sopenharmony_ci| ID | Error Message | 4421e41f4b71Sopenharmony_ci| --------------- | --------------- | 4422e41f4b71Sopenharmony_ci| 7400101 | Parameter missing or parameter type incorrect. | 4423e41f4b71Sopenharmony_ci| 7400102 | Operation not allowed. | 4424e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 4425e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 4426e41f4b71Sopenharmony_ci 4427e41f4b71Sopenharmony_ci**Example** 4428e41f4b71Sopenharmony_ci 4429e41f4b71Sopenharmony_ci```ts 4430e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 4431e41f4b71Sopenharmony_ci 4432e41f4b71Sopenharmony_cifunction addOutput(session: camera.Session, cameraOutput: camera.CameraOutput): void { 4433e41f4b71Sopenharmony_ci try { 4434e41f4b71Sopenharmony_ci session.addOutput(cameraOutput); 4435e41f4b71Sopenharmony_ci } catch (error) { 4436e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 4437e41f4b71Sopenharmony_ci let err = error as BusinessError; 4438e41f4b71Sopenharmony_ci console.error(`The addOutput call failed. error code: ${err.code}`); 4439e41f4b71Sopenharmony_ci } 4440e41f4b71Sopenharmony_ci} 4441e41f4b71Sopenharmony_ci``` 4442e41f4b71Sopenharmony_ci 4443e41f4b71Sopenharmony_ci### removeOutput<sup>11+</sup> 4444e41f4b71Sopenharmony_ci 4445e41f4b71Sopenharmony_ciremoveOutput(cameraOutput: CameraOutput): void 4446e41f4b71Sopenharmony_ci 4447e41f4b71Sopenharmony_ciRemoves a [CameraOutput](#cameraoutput) instance from this session. 4448e41f4b71Sopenharmony_ci 4449e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 4450e41f4b71Sopenharmony_ci 4451e41f4b71Sopenharmony_ci**Parameters** 4452e41f4b71Sopenharmony_ci 4453e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 4454e41f4b71Sopenharmony_ci| ------------- | ------------------------------- | ---- | ------------------------ | 4455e41f4b71Sopenharmony_ci| cameraOutput | [CameraOutput](#cameraoutput) | Yes | **CameraOutput** instance to remove.| 4456e41f4b71Sopenharmony_ci 4457e41f4b71Sopenharmony_ci**Error codes** 4458e41f4b71Sopenharmony_ci 4459e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 4460e41f4b71Sopenharmony_ci 4461e41f4b71Sopenharmony_ci| ID | Error Message | 4462e41f4b71Sopenharmony_ci| --------------- | --------------- | 4463e41f4b71Sopenharmony_ci| 7400101 | Parameter missing or parameter type incorrect. | 4464e41f4b71Sopenharmony_ci| 7400102 | Operation not allowed. | 4465e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 4466e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 4467e41f4b71Sopenharmony_ci 4468e41f4b71Sopenharmony_ci**Example** 4469e41f4b71Sopenharmony_ci 4470e41f4b71Sopenharmony_ci```ts 4471e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 4472e41f4b71Sopenharmony_ci 4473e41f4b71Sopenharmony_cifunction removeOutput(session: camera.Session, previewOutput: camera.PreviewOutput): void { 4474e41f4b71Sopenharmony_ci try { 4475e41f4b71Sopenharmony_ci session.removeOutput(previewOutput); 4476e41f4b71Sopenharmony_ci } catch (error) { 4477e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 4478e41f4b71Sopenharmony_ci let err = error as BusinessError; 4479e41f4b71Sopenharmony_ci console.error(`The removeOutput call failed. error code: ${err.code}`); 4480e41f4b71Sopenharmony_ci } 4481e41f4b71Sopenharmony_ci} 4482e41f4b71Sopenharmony_ci``` 4483e41f4b71Sopenharmony_ci 4484e41f4b71Sopenharmony_ci### start<sup>11+</sup> 4485e41f4b71Sopenharmony_ci 4486e41f4b71Sopenharmony_cistart(callback: AsyncCallback\<void\>): void 4487e41f4b71Sopenharmony_ci 4488e41f4b71Sopenharmony_ciStarts this session. This API uses an asynchronous callback to return the result. 4489e41f4b71Sopenharmony_ci 4490e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 4491e41f4b71Sopenharmony_ci 4492e41f4b71Sopenharmony_ci**Parameters** 4493e41f4b71Sopenharmony_ci 4494e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 4495e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | -------------------- | 4496e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 4497e41f4b71Sopenharmony_ci 4498e41f4b71Sopenharmony_ci**Error codes** 4499e41f4b71Sopenharmony_ci 4500e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 4501e41f4b71Sopenharmony_ci 4502e41f4b71Sopenharmony_ci| ID | Error Message | 4503e41f4b71Sopenharmony_ci| --------------- | --------------- | 4504e41f4b71Sopenharmony_ci| 7400102 | Operation not allowed. | 4505e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 4506e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 4507e41f4b71Sopenharmony_ci 4508e41f4b71Sopenharmony_ci**Example** 4509e41f4b71Sopenharmony_ci 4510e41f4b71Sopenharmony_ci```ts 4511e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 4512e41f4b71Sopenharmony_ci 4513e41f4b71Sopenharmony_cifunction startCaptureSession(session: camera.Session): void { 4514e41f4b71Sopenharmony_ci session.start((err: BusinessError) => { 4515e41f4b71Sopenharmony_ci if (err) { 4516e41f4b71Sopenharmony_ci console.error(`Failed to start the session, error code: ${err.code}.`); 4517e41f4b71Sopenharmony_ci return; 4518e41f4b71Sopenharmony_ci } 4519e41f4b71Sopenharmony_ci console.info('Callback invoked to indicate the session start success.'); 4520e41f4b71Sopenharmony_ci }); 4521e41f4b71Sopenharmony_ci} 4522e41f4b71Sopenharmony_ci``` 4523e41f4b71Sopenharmony_ci 4524e41f4b71Sopenharmony_ci### start<sup>11+</sup> 4525e41f4b71Sopenharmony_ci 4526e41f4b71Sopenharmony_cistart(): Promise\<void\> 4527e41f4b71Sopenharmony_ci 4528e41f4b71Sopenharmony_ciStarts this session. This API uses a promise to return the result. 4529e41f4b71Sopenharmony_ci 4530e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 4531e41f4b71Sopenharmony_ci 4532e41f4b71Sopenharmony_ci**Return value** 4533e41f4b71Sopenharmony_ci 4534e41f4b71Sopenharmony_ci| Type | Description | 4535e41f4b71Sopenharmony_ci| -------------- | ------------------------ | 4536e41f4b71Sopenharmony_ci| Promise\<void\> | Promise that returns no value.| 4537e41f4b71Sopenharmony_ci 4538e41f4b71Sopenharmony_ci**Error codes** 4539e41f4b71Sopenharmony_ci 4540e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 4541e41f4b71Sopenharmony_ci 4542e41f4b71Sopenharmony_ci| ID | Error Message | 4543e41f4b71Sopenharmony_ci| --------------- | --------------- | 4544e41f4b71Sopenharmony_ci| 7400102 | Operation not allowed. | 4545e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 4546e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 4547e41f4b71Sopenharmony_ci 4548e41f4b71Sopenharmony_ci**Example** 4549e41f4b71Sopenharmony_ci 4550e41f4b71Sopenharmony_ci```ts 4551e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 4552e41f4b71Sopenharmony_ci 4553e41f4b71Sopenharmony_cifunction startCaptureSession(session: camera.Session): void { 4554e41f4b71Sopenharmony_ci session.start().then(() => { 4555e41f4b71Sopenharmony_ci console.info('Promise returned to indicate the session start success.'); 4556e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 4557e41f4b71Sopenharmony_ci console.error(`Failed to start the session, error code: ${error.code}.`); 4558e41f4b71Sopenharmony_ci }); 4559e41f4b71Sopenharmony_ci} 4560e41f4b71Sopenharmony_ci``` 4561e41f4b71Sopenharmony_ci 4562e41f4b71Sopenharmony_ci### stop<sup>11+</sup> 4563e41f4b71Sopenharmony_ci 4564e41f4b71Sopenharmony_cistop(callback: AsyncCallback\<void\>): void 4565e41f4b71Sopenharmony_ci 4566e41f4b71Sopenharmony_ciStops this session. This API uses an asynchronous callback to return the result. 4567e41f4b71Sopenharmony_ci 4568e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 4569e41f4b71Sopenharmony_ci 4570e41f4b71Sopenharmony_ci**Parameters** 4571e41f4b71Sopenharmony_ci 4572e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 4573e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ------------------- | 4574e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 4575e41f4b71Sopenharmony_ci 4576e41f4b71Sopenharmony_ci**Error codes** 4577e41f4b71Sopenharmony_ci 4578e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 4579e41f4b71Sopenharmony_ci 4580e41f4b71Sopenharmony_ci| ID | Error Message | 4581e41f4b71Sopenharmony_ci| --------------- | --------------- | 4582e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 4583e41f4b71Sopenharmony_ci 4584e41f4b71Sopenharmony_ci**Example** 4585e41f4b71Sopenharmony_ci 4586e41f4b71Sopenharmony_ci```ts 4587e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 4588e41f4b71Sopenharmony_ci 4589e41f4b71Sopenharmony_cifunction stopCaptureSession(session: camera.Session): void { 4590e41f4b71Sopenharmony_ci session.stop((err: BusinessError) => { 4591e41f4b71Sopenharmony_ci if (err) { 4592e41f4b71Sopenharmony_ci console.error(`Failed to stop the session, error code: ${err.code}.`); 4593e41f4b71Sopenharmony_ci return; 4594e41f4b71Sopenharmony_ci } 4595e41f4b71Sopenharmony_ci console.info('Callback invoked to indicate the session stop success.'); 4596e41f4b71Sopenharmony_ci }); 4597e41f4b71Sopenharmony_ci} 4598e41f4b71Sopenharmony_ci``` 4599e41f4b71Sopenharmony_ci 4600e41f4b71Sopenharmony_ci### stop<sup>11+</sup> 4601e41f4b71Sopenharmony_ci 4602e41f4b71Sopenharmony_cistop(): Promise\<void\> 4603e41f4b71Sopenharmony_ci 4604e41f4b71Sopenharmony_ciStops this session. This API uses a promise to return the result. 4605e41f4b71Sopenharmony_ci 4606e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 4607e41f4b71Sopenharmony_ci 4608e41f4b71Sopenharmony_ci**Return value** 4609e41f4b71Sopenharmony_ci 4610e41f4b71Sopenharmony_ci| Type | Description | 4611e41f4b71Sopenharmony_ci| -------------- |-------------------| 4612e41f4b71Sopenharmony_ci| Promise\<void\> | Promise that returns no value. | 4613e41f4b71Sopenharmony_ci 4614e41f4b71Sopenharmony_ci**Error codes** 4615e41f4b71Sopenharmony_ci 4616e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 4617e41f4b71Sopenharmony_ci 4618e41f4b71Sopenharmony_ci| ID | Error Message | 4619e41f4b71Sopenharmony_ci| --------------- | --------------- | 4620e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 4621e41f4b71Sopenharmony_ci 4622e41f4b71Sopenharmony_ci**Example** 4623e41f4b71Sopenharmony_ci 4624e41f4b71Sopenharmony_ci```ts 4625e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 4626e41f4b71Sopenharmony_ci 4627e41f4b71Sopenharmony_cifunction stopCaptureSession(session: camera.Session): void { 4628e41f4b71Sopenharmony_ci session.stop().then(() => { 4629e41f4b71Sopenharmony_ci console.info('Promise returned to indicate the session stop success.'); 4630e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 4631e41f4b71Sopenharmony_ci console.error(`Failed to stop the session, error code: ${error.code}.`); 4632e41f4b71Sopenharmony_ci }); 4633e41f4b71Sopenharmony_ci} 4634e41f4b71Sopenharmony_ci``` 4635e41f4b71Sopenharmony_ci 4636e41f4b71Sopenharmony_ci### release<sup>11+</sup> 4637e41f4b71Sopenharmony_ci 4638e41f4b71Sopenharmony_cirelease(callback: AsyncCallback\<void\>): void 4639e41f4b71Sopenharmony_ci 4640e41f4b71Sopenharmony_ciReleases this session. This API uses an asynchronous callback to return the result. 4641e41f4b71Sopenharmony_ci 4642e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 4643e41f4b71Sopenharmony_ci 4644e41f4b71Sopenharmony_ci**Parameters** 4645e41f4b71Sopenharmony_ci 4646e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 4647e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | -------------------- | 4648e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 4649e41f4b71Sopenharmony_ci 4650e41f4b71Sopenharmony_ci**Error codes** 4651e41f4b71Sopenharmony_ci 4652e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 4653e41f4b71Sopenharmony_ci 4654e41f4b71Sopenharmony_ci| ID | Error Message | 4655e41f4b71Sopenharmony_ci| --------------- | --------------- | 4656e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 4657e41f4b71Sopenharmony_ci 4658e41f4b71Sopenharmony_ci**Example** 4659e41f4b71Sopenharmony_ci 4660e41f4b71Sopenharmony_ci```ts 4661e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 4662e41f4b71Sopenharmony_ci 4663e41f4b71Sopenharmony_cifunction releaseCaptureSession(session: camera.Session): void { 4664e41f4b71Sopenharmony_ci session.release((err: BusinessError) => { 4665e41f4b71Sopenharmony_ci if (err) { 4666e41f4b71Sopenharmony_ci console.error(`Failed to release the session instance, error code: ${err.code}.`); 4667e41f4b71Sopenharmony_ci return; 4668e41f4b71Sopenharmony_ci } 4669e41f4b71Sopenharmony_ci console.info('Callback invoked to indicate that the session instance is released successfully.'); 4670e41f4b71Sopenharmony_ci }); 4671e41f4b71Sopenharmony_ci} 4672e41f4b71Sopenharmony_ci``` 4673e41f4b71Sopenharmony_ci 4674e41f4b71Sopenharmony_ci### release<sup>11+</sup> 4675e41f4b71Sopenharmony_ci 4676e41f4b71Sopenharmony_cirelease(): Promise\<void\> 4677e41f4b71Sopenharmony_ci 4678e41f4b71Sopenharmony_ciReleases this session. This API uses a promise to return the result. 4679e41f4b71Sopenharmony_ci 4680e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 4681e41f4b71Sopenharmony_ci 4682e41f4b71Sopenharmony_ci**Return value** 4683e41f4b71Sopenharmony_ci 4684e41f4b71Sopenharmony_ci| Type | Description | 4685e41f4b71Sopenharmony_ci| -------------- | ------------------------ | 4686e41f4b71Sopenharmony_ci| Promise\<void\> | Promise that returns no value.| 4687e41f4b71Sopenharmony_ci 4688e41f4b71Sopenharmony_ci**Error codes** 4689e41f4b71Sopenharmony_ci 4690e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 4691e41f4b71Sopenharmony_ci 4692e41f4b71Sopenharmony_ci| ID | Error Message | 4693e41f4b71Sopenharmony_ci| --------------- | --------------- | 4694e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 4695e41f4b71Sopenharmony_ci 4696e41f4b71Sopenharmony_ci**Example** 4697e41f4b71Sopenharmony_ci 4698e41f4b71Sopenharmony_ci```ts 4699e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 4700e41f4b71Sopenharmony_ci 4701e41f4b71Sopenharmony_cifunction releaseCaptureSession(session: camera.Session): void { 4702e41f4b71Sopenharmony_ci session.release().then(() => { 4703e41f4b71Sopenharmony_ci console.info('Promise returned to indicate that the session instance is released successfully.'); 4704e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 4705e41f4b71Sopenharmony_ci console.error(`Failed to release the session instance, error code: ${error.code}.`); 4706e41f4b71Sopenharmony_ci }); 4707e41f4b71Sopenharmony_ci} 4708e41f4b71Sopenharmony_ci``` 4709e41f4b71Sopenharmony_ci 4710e41f4b71Sopenharmony_ci## Flash<sup>11+</sup> 4711e41f4b71Sopenharmony_ci 4712e41f4b71Sopenharmony_ciFlash extends [FlashQuery](#flashquery12) 4713e41f4b71Sopenharmony_ci 4714e41f4b71Sopenharmony_ciProvides APIs related to the flash. 4715e41f4b71Sopenharmony_ci 4716e41f4b71Sopenharmony_ci### setFlashMode<sup>11+</sup> 4717e41f4b71Sopenharmony_ci 4718e41f4b71Sopenharmony_cisetFlashMode(flashMode: FlashMode): void 4719e41f4b71Sopenharmony_ci 4720e41f4b71Sopenharmony_ciSets a flash mode. 4721e41f4b71Sopenharmony_ci 4722e41f4b71Sopenharmony_ciBefore the setting, do the following checks: 4723e41f4b71Sopenharmony_ci 4724e41f4b71Sopenharmony_ci1. Use [hasFlash](#hasflash11) to check whether the camera device has flash. 4725e41f4b71Sopenharmony_ci2. Use [isFlashModeSupported](#isflashmodesupported11) to check whether the camera device supports the flash mode. 4726e41f4b71Sopenharmony_ci 4727e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 4728e41f4b71Sopenharmony_ci 4729e41f4b71Sopenharmony_ci**Parameters** 4730e41f4b71Sopenharmony_ci 4731e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 4732e41f4b71Sopenharmony_ci| --------- | ----------------------- | ---- | --------------------- | 4733e41f4b71Sopenharmony_ci| flashMode | [FlashMode](#flashmode) | Yes | Flash mode. | 4734e41f4b71Sopenharmony_ci 4735e41f4b71Sopenharmony_ci**Error codes** 4736e41f4b71Sopenharmony_ci 4737e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 4738e41f4b71Sopenharmony_ci 4739e41f4b71Sopenharmony_ci| ID | Error Message | 4740e41f4b71Sopenharmony_ci| --------------- | --------------- | 4741e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 4742e41f4b71Sopenharmony_ci 4743e41f4b71Sopenharmony_ci**Example** 4744e41f4b71Sopenharmony_ci 4745e41f4b71Sopenharmony_ci```ts 4746e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 4747e41f4b71Sopenharmony_ci 4748e41f4b71Sopenharmony_cifunction setFlashMode(photoSession: camera.PhotoSession): void { 4749e41f4b71Sopenharmony_ci try { 4750e41f4b71Sopenharmony_ci photoSession.setFlashMode(camera.FlashMode.FLASH_MODE_AUTO); 4751e41f4b71Sopenharmony_ci } catch (error) { 4752e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 4753e41f4b71Sopenharmony_ci let err = error as BusinessError; 4754e41f4b71Sopenharmony_ci console.error(`The setFlashMode call failed. error code: ${err.code}`); 4755e41f4b71Sopenharmony_ci } 4756e41f4b71Sopenharmony_ci} 4757e41f4b71Sopenharmony_ci``` 4758e41f4b71Sopenharmony_ci 4759e41f4b71Sopenharmony_ci### getFlashMode<sup>11+</sup> 4760e41f4b71Sopenharmony_ci 4761e41f4b71Sopenharmony_cigetFlashMode(): FlashMode 4762e41f4b71Sopenharmony_ci 4763e41f4b71Sopenharmony_ciObtains the flash mode in use. 4764e41f4b71Sopenharmony_ci 4765e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 4766e41f4b71Sopenharmony_ci 4767e41f4b71Sopenharmony_ci**Return value** 4768e41f4b71Sopenharmony_ci 4769e41f4b71Sopenharmony_ci| Type | Description | 4770e41f4b71Sopenharmony_ci| ---------- | ----------------------------- | 4771e41f4b71Sopenharmony_ci| [FlashMode](#flashmode) | Flash mode obtained. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 4772e41f4b71Sopenharmony_ci 4773e41f4b71Sopenharmony_ci**Error codes** 4774e41f4b71Sopenharmony_ci 4775e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 4776e41f4b71Sopenharmony_ci 4777e41f4b71Sopenharmony_ci| ID | Error Message | 4778e41f4b71Sopenharmony_ci| --------------- | --------------- | 4779e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 4780e41f4b71Sopenharmony_ci 4781e41f4b71Sopenharmony_ci**Example** 4782e41f4b71Sopenharmony_ci 4783e41f4b71Sopenharmony_ci```ts 4784e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 4785e41f4b71Sopenharmony_ci 4786e41f4b71Sopenharmony_cifunction getFlashMode(photoSession: camera.PhotoSession): camera.FlashMode | undefined { 4787e41f4b71Sopenharmony_ci let flashMode: camera.FlashMode | undefined = undefined; 4788e41f4b71Sopenharmony_ci try { 4789e41f4b71Sopenharmony_ci flashMode = photoSession.getFlashMode(); 4790e41f4b71Sopenharmony_ci } catch (error) { 4791e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 4792e41f4b71Sopenharmony_ci let err = error as BusinessError; 4793e41f4b71Sopenharmony_ci console.error(`The getFlashMode call failed.error code: ${err.code}`); 4794e41f4b71Sopenharmony_ci } 4795e41f4b71Sopenharmony_ci return flashMode; 4796e41f4b71Sopenharmony_ci} 4797e41f4b71Sopenharmony_ci``` 4798e41f4b71Sopenharmony_ci 4799e41f4b71Sopenharmony_ci## FlashQuery<sup>12+</sup> 4800e41f4b71Sopenharmony_ci 4801e41f4b71Sopenharmony_ciProvides APIs to query the flash status and mode of a camera device. 4802e41f4b71Sopenharmony_ci 4803e41f4b71Sopenharmony_ci### hasFlash<sup>11+</sup> 4804e41f4b71Sopenharmony_ci 4805e41f4b71Sopenharmony_cihasFlash(): boolean 4806e41f4b71Sopenharmony_ci 4807e41f4b71Sopenharmony_ciChecks whether the camera device has flash. This API uses an asynchronous callback to return the result. 4808e41f4b71Sopenharmony_ci 4809e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 4810e41f4b71Sopenharmony_ci 4811e41f4b71Sopenharmony_ci**Return value** 4812e41f4b71Sopenharmony_ci 4813e41f4b71Sopenharmony_ci| Type | Description | 4814e41f4b71Sopenharmony_ci| ---------- | ----------------------------- | 4815e41f4b71Sopenharmony_ci| boolean | **true**: The camera device has flash.<br>**false**: The camera device does not have flash. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 4816e41f4b71Sopenharmony_ci 4817e41f4b71Sopenharmony_ci**Error codes** 4818e41f4b71Sopenharmony_ci 4819e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 4820e41f4b71Sopenharmony_ci 4821e41f4b71Sopenharmony_ci| ID | Error Message | 4822e41f4b71Sopenharmony_ci| --------------- | --------------- | 4823e41f4b71Sopenharmony_ci| 7400103 | Session not config, only throw in session usage. | 4824e41f4b71Sopenharmony_ci 4825e41f4b71Sopenharmony_ci**Example** 4826e41f4b71Sopenharmony_ci 4827e41f4b71Sopenharmony_ci```ts 4828e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 4829e41f4b71Sopenharmony_ci 4830e41f4b71Sopenharmony_cifunction hasFlash(photoSession: camera.PhotoSession): boolean { 4831e41f4b71Sopenharmony_ci let status: boolean = false; 4832e41f4b71Sopenharmony_ci try { 4833e41f4b71Sopenharmony_ci status = photoSession.hasFlash(); 4834e41f4b71Sopenharmony_ci } catch (error) { 4835e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 4836e41f4b71Sopenharmony_ci let err = error as BusinessError; 4837e41f4b71Sopenharmony_ci console.error(`The hasFlash call failed. error code: ${err.code}`); 4838e41f4b71Sopenharmony_ci } 4839e41f4b71Sopenharmony_ci return status; 4840e41f4b71Sopenharmony_ci} 4841e41f4b71Sopenharmony_ci``` 4842e41f4b71Sopenharmony_ci 4843e41f4b71Sopenharmony_ci### isFlashModeSupported<sup>11+</sup> 4844e41f4b71Sopenharmony_ci 4845e41f4b71Sopenharmony_ciisFlashModeSupported(flashMode: FlashMode): boolean 4846e41f4b71Sopenharmony_ci 4847e41f4b71Sopenharmony_ciChecks whether a flash mode is supported. 4848e41f4b71Sopenharmony_ci 4849e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 4850e41f4b71Sopenharmony_ci 4851e41f4b71Sopenharmony_ci**Parameters** 4852e41f4b71Sopenharmony_ci 4853e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 4854e41f4b71Sopenharmony_ci| --------- | ----------------------- | ---- | --------------------------------- | 4855e41f4b71Sopenharmony_ci| flashMode | [FlashMode](#flashmode) | Yes | Flash mode. | 4856e41f4b71Sopenharmony_ci 4857e41f4b71Sopenharmony_ci**Return value** 4858e41f4b71Sopenharmony_ci 4859e41f4b71Sopenharmony_ci| Type | Description | 4860e41f4b71Sopenharmony_ci| ---------- | ----------------------------- | 4861e41f4b71Sopenharmony_ci| boolean | **true**: The flash mode is supported.<br>**false**: The flash mode is not supported. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 4862e41f4b71Sopenharmony_ci 4863e41f4b71Sopenharmony_ci**Error codes** 4864e41f4b71Sopenharmony_ci 4865e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 4866e41f4b71Sopenharmony_ci 4867e41f4b71Sopenharmony_ci| ID | Error Message | 4868e41f4b71Sopenharmony_ci| --------------- | --------------- | 4869e41f4b71Sopenharmony_ci| 7400103 | Session not config, only throw in session usage. | 4870e41f4b71Sopenharmony_ci 4871e41f4b71Sopenharmony_ci**Example** 4872e41f4b71Sopenharmony_ci 4873e41f4b71Sopenharmony_ci```ts 4874e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 4875e41f4b71Sopenharmony_ci 4876e41f4b71Sopenharmony_cifunction isFlashModeSupported(photoSession: camera.PhotoSession): boolean { 4877e41f4b71Sopenharmony_ci let status: boolean = false; 4878e41f4b71Sopenharmony_ci try { 4879e41f4b71Sopenharmony_ci status = photoSession.isFlashModeSupported(camera.FlashMode.FLASH_MODE_AUTO); 4880e41f4b71Sopenharmony_ci } catch (error) { 4881e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 4882e41f4b71Sopenharmony_ci let err = error as BusinessError; 4883e41f4b71Sopenharmony_ci console.error(`The isFlashModeSupported call failed. error code: ${err.code}`); 4884e41f4b71Sopenharmony_ci } 4885e41f4b71Sopenharmony_ci return status; 4886e41f4b71Sopenharmony_ci} 4887e41f4b71Sopenharmony_ci``` 4888e41f4b71Sopenharmony_ci 4889e41f4b71Sopenharmony_ci## AutoExposure<sup>11+</sup> 4890e41f4b71Sopenharmony_ci 4891e41f4b71Sopenharmony_ciAutoExposure extends [AutoExposureQuery](#autoexposurequery12) 4892e41f4b71Sopenharmony_ci 4893e41f4b71Sopenharmony_ciProvides APIs related to auto exposure. 4894e41f4b71Sopenharmony_ci 4895e41f4b71Sopenharmony_ci### getExposureMode<sup>11+</sup> 4896e41f4b71Sopenharmony_ci 4897e41f4b71Sopenharmony_cigetExposureMode(): ExposureMode 4898e41f4b71Sopenharmony_ci 4899e41f4b71Sopenharmony_ciObtains the exposure mode in use. 4900e41f4b71Sopenharmony_ci 4901e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 4902e41f4b71Sopenharmony_ci 4903e41f4b71Sopenharmony_ci**Return value** 4904e41f4b71Sopenharmony_ci 4905e41f4b71Sopenharmony_ci| Type | Description | 4906e41f4b71Sopenharmony_ci| ---------- | ----------------------------- | 4907e41f4b71Sopenharmony_ci| [ExposureMode](#exposuremode) | Exposure mode obtained. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 4908e41f4b71Sopenharmony_ci 4909e41f4b71Sopenharmony_ci**Error codes** 4910e41f4b71Sopenharmony_ci 4911e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 4912e41f4b71Sopenharmony_ci 4913e41f4b71Sopenharmony_ci| ID | Error Message | 4914e41f4b71Sopenharmony_ci| --------------- | --------------- | 4915e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 4916e41f4b71Sopenharmony_ci 4917e41f4b71Sopenharmony_ci**Example** 4918e41f4b71Sopenharmony_ci 4919e41f4b71Sopenharmony_ci```ts 4920e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 4921e41f4b71Sopenharmony_ci 4922e41f4b71Sopenharmony_cifunction getExposureMode(photoSession: camera.PhotoSession): camera.ExposureMode | undefined { 4923e41f4b71Sopenharmony_ci let exposureMode: camera.ExposureMode | undefined = undefined; 4924e41f4b71Sopenharmony_ci try { 4925e41f4b71Sopenharmony_ci exposureMode = photoSession.getExposureMode(); 4926e41f4b71Sopenharmony_ci } catch (error) { 4927e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 4928e41f4b71Sopenharmony_ci let err = error as BusinessError; 4929e41f4b71Sopenharmony_ci console.error(`The getExposureMode call failed. error code: ${err.code}`); 4930e41f4b71Sopenharmony_ci } 4931e41f4b71Sopenharmony_ci return exposureMode; 4932e41f4b71Sopenharmony_ci} 4933e41f4b71Sopenharmony_ci``` 4934e41f4b71Sopenharmony_ci 4935e41f4b71Sopenharmony_ci### setExposureMode<sup>11+</sup> 4936e41f4b71Sopenharmony_ci 4937e41f4b71Sopenharmony_cisetExposureMode(aeMode: ExposureMode): void 4938e41f4b71Sopenharmony_ci 4939e41f4b71Sopenharmony_ciSets an exposure mode. Before the setting, call [isExposureModeSupported](#isexposuremodesupported11) to check whether the target exposure mode is supported. 4940e41f4b71Sopenharmony_ci 4941e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 4942e41f4b71Sopenharmony_ci 4943e41f4b71Sopenharmony_ci**Parameters** 4944e41f4b71Sopenharmony_ci 4945e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 4946e41f4b71Sopenharmony_ci| -------- | -------------------------------| ---- | ----------------------- | 4947e41f4b71Sopenharmony_ci| aeMode | [ExposureMode](#exposuremode) | Yes | Exposure mode. | 4948e41f4b71Sopenharmony_ci 4949e41f4b71Sopenharmony_ci**Error codes** 4950e41f4b71Sopenharmony_ci 4951e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 4952e41f4b71Sopenharmony_ci 4953e41f4b71Sopenharmony_ci| ID | Error Message | 4954e41f4b71Sopenharmony_ci| --------------- | --------------- | 4955e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 4956e41f4b71Sopenharmony_ci 4957e41f4b71Sopenharmony_ci**Example** 4958e41f4b71Sopenharmony_ci 4959e41f4b71Sopenharmony_ci```ts 4960e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 4961e41f4b71Sopenharmony_ci 4962e41f4b71Sopenharmony_cifunction setExposureMode(photoSession: camera.PhotoSession): void { 4963e41f4b71Sopenharmony_ci try { 4964e41f4b71Sopenharmony_ci photoSession.setExposureMode(camera.ExposureMode.EXPOSURE_MODE_LOCKED); 4965e41f4b71Sopenharmony_ci } catch (error) { 4966e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 4967e41f4b71Sopenharmony_ci let err = error as BusinessError; 4968e41f4b71Sopenharmony_ci console.error(`The setExposureMode call failed. error code: ${err.code}`); 4969e41f4b71Sopenharmony_ci } 4970e41f4b71Sopenharmony_ci} 4971e41f4b71Sopenharmony_ci``` 4972e41f4b71Sopenharmony_ci 4973e41f4b71Sopenharmony_ci### getMeteringPoint<sup>11+</sup> 4974e41f4b71Sopenharmony_ci 4975e41f4b71Sopenharmony_cigetMeteringPoint(): Point 4976e41f4b71Sopenharmony_ci 4977e41f4b71Sopenharmony_ciObtains the metering point of the camera device. 4978e41f4b71Sopenharmony_ci 4979e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 4980e41f4b71Sopenharmony_ci 4981e41f4b71Sopenharmony_ci**Return value** 4982e41f4b71Sopenharmony_ci 4983e41f4b71Sopenharmony_ci| Type | Description | 4984e41f4b71Sopenharmony_ci| ---------- | ----------------------------- | 4985e41f4b71Sopenharmony_ci| [Point](#point) | Metering point obtained. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 4986e41f4b71Sopenharmony_ci 4987e41f4b71Sopenharmony_ci**Error codes** 4988e41f4b71Sopenharmony_ci 4989e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 4990e41f4b71Sopenharmony_ci 4991e41f4b71Sopenharmony_ci| ID | Error Message | 4992e41f4b71Sopenharmony_ci| --------------- | --------------- | 4993e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 4994e41f4b71Sopenharmony_ci 4995e41f4b71Sopenharmony_ci**Example** 4996e41f4b71Sopenharmony_ci 4997e41f4b71Sopenharmony_ci```ts 4998e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 4999e41f4b71Sopenharmony_ci 5000e41f4b71Sopenharmony_cifunction getMeteringPoint(photoSession: camera.PhotoSession): camera.Point | undefined { 5001e41f4b71Sopenharmony_ci let exposurePoint: camera.Point | undefined = undefined; 5002e41f4b71Sopenharmony_ci try { 5003e41f4b71Sopenharmony_ci exposurePoint = photoSession.getMeteringPoint(); 5004e41f4b71Sopenharmony_ci } catch (error) { 5005e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 5006e41f4b71Sopenharmony_ci let err = error as BusinessError; 5007e41f4b71Sopenharmony_ci console.error(`The getMeteringPoint call failed. error code: ${err.code}`); 5008e41f4b71Sopenharmony_ci } 5009e41f4b71Sopenharmony_ci return exposurePoint; 5010e41f4b71Sopenharmony_ci} 5011e41f4b71Sopenharmony_ci``` 5012e41f4b71Sopenharmony_ci 5013e41f4b71Sopenharmony_ci### setMeteringPoint<sup>11+</sup> 5014e41f4b71Sopenharmony_ci 5015e41f4b71Sopenharmony_cisetMeteringPoint(point: Point): void 5016e41f4b71Sopenharmony_ci 5017e41f4b71Sopenharmony_ciSets the metering point, which is the center point of the metering rectangle. 5018e41f4b71Sopenharmony_ci 5019e41f4b71Sopenharmony_ciThe metering point must be in the coordinate system (0-1), where the upper left corner is {0, 0} and the lower right corner is {1, 1}. 5020e41f4b71Sopenharmony_ci 5021e41f4b71Sopenharmony_ciThe coordinate system is based on the horizontal device direction with the device's charging port on the right. If the layout of the preview screen of an application is based on the vertical direction with the charging port on the lower side, the layout width and height are {w, h}, and the touch point is {x, y}, then the coordinate point after conversion is {y/h, 1-x/w}. 5022e41f4b71Sopenharmony_ci 5023e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 5024e41f4b71Sopenharmony_ci 5025e41f4b71Sopenharmony_ci**Parameters** 5026e41f4b71Sopenharmony_ci 5027e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 5028e41f4b71Sopenharmony_ci| ------------- | -------------------------------| ---- | ------------------- | 5029e41f4b71Sopenharmony_ci| point | [Point](#point) | Yes | Metering point. The value range of x and y must be within [0, 1]. If a value less than 0 is passed, the value **0** is used. If a value greater than **1** is passed, the value **1** is used. | 5030e41f4b71Sopenharmony_ci 5031e41f4b71Sopenharmony_ci**Error codes** 5032e41f4b71Sopenharmony_ci 5033e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 5034e41f4b71Sopenharmony_ci 5035e41f4b71Sopenharmony_ci| ID | Error Message | 5036e41f4b71Sopenharmony_ci| --------------- | --------------- | 5037e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 5038e41f4b71Sopenharmony_ci 5039e41f4b71Sopenharmony_ci**Example** 5040e41f4b71Sopenharmony_ci 5041e41f4b71Sopenharmony_ci```ts 5042e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 5043e41f4b71Sopenharmony_ci 5044e41f4b71Sopenharmony_cifunction setMeteringPoint(photoSession: camera.PhotoSession): void { 5045e41f4b71Sopenharmony_ci const point: camera.Point = {x: 1, y: 1}; 5046e41f4b71Sopenharmony_ci try { 5047e41f4b71Sopenharmony_ci photoSession.setMeteringPoint(point); 5048e41f4b71Sopenharmony_ci } catch (error) { 5049e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 5050e41f4b71Sopenharmony_ci let err = error as BusinessError; 5051e41f4b71Sopenharmony_ci console.error(`The setMeteringPoint call failed. error code: ${err.code}`); 5052e41f4b71Sopenharmony_ci } 5053e41f4b71Sopenharmony_ci} 5054e41f4b71Sopenharmony_ci``` 5055e41f4b71Sopenharmony_ci 5056e41f4b71Sopenharmony_ci### setExposureBias<sup>11+</sup> 5057e41f4b71Sopenharmony_ci 5058e41f4b71Sopenharmony_cisetExposureBias(exposureBias: number): void 5059e41f4b71Sopenharmony_ci 5060e41f4b71Sopenharmony_ciSets an exposure compensation value (EV). 5061e41f4b71Sopenharmony_ci 5062e41f4b71Sopenharmony_ciBefore the setting, you are advised to use [getExposureBiasRange](#getexposurebiasrange11) to obtain the supported values. 5063e41f4b71Sopenharmony_ci 5064e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 5065e41f4b71Sopenharmony_ci 5066e41f4b71Sopenharmony_ci**Parameters** 5067e41f4b71Sopenharmony_ci 5068e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 5069e41f4b71Sopenharmony_ci| -------- | -------------------------------| ---- |-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| 5070e41f4b71Sopenharmony_ci| exposureBias | number | Yes | EV. The supported EV range can be obtained by calling [getExposureBiasRange](#getexposurebiasrange11). If the value passed is not within the supported range, the nearest critical point is used.<br>There is a step for EV. For example, if the step is 0.5 and this parameter is set to 1.2, the EV that takes effect is 1.0.<br>If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 5071e41f4b71Sopenharmony_ci 5072e41f4b71Sopenharmony_ci**Error codes** 5073e41f4b71Sopenharmony_ci 5074e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 5075e41f4b71Sopenharmony_ci 5076e41f4b71Sopenharmony_ci| ID | Error Message | 5077e41f4b71Sopenharmony_ci| --------------- | --------------- | 5078e41f4b71Sopenharmony_ci| 7400102 | Operation not allowed. | 5079e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 5080e41f4b71Sopenharmony_ci 5081e41f4b71Sopenharmony_ci**Example** 5082e41f4b71Sopenharmony_ci 5083e41f4b71Sopenharmony_ci```ts 5084e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 5085e41f4b71Sopenharmony_ci 5086e41f4b71Sopenharmony_cifunction setExposureBias(photoSession: camera.PhotoSession, biasRangeArray: Array<number>): void { 5087e41f4b71Sopenharmony_ci if (biasRangeArray && biasRangeArray.length > 0) { 5088e41f4b71Sopenharmony_ci let exposureBias = biasRangeArray[0]; 5089e41f4b71Sopenharmony_ci try { 5090e41f4b71Sopenharmony_ci photoSession.setExposureBias(exposureBias); 5091e41f4b71Sopenharmony_ci } catch (error) { 5092e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 5093e41f4b71Sopenharmony_ci let err = error as BusinessError; 5094e41f4b71Sopenharmony_ci console.error(`The setExposureBias call failed. error code: ${err.code}`); 5095e41f4b71Sopenharmony_ci } 5096e41f4b71Sopenharmony_ci } 5097e41f4b71Sopenharmony_ci} 5098e41f4b71Sopenharmony_ci``` 5099e41f4b71Sopenharmony_ci 5100e41f4b71Sopenharmony_ci### getExposureValue<sup>11+</sup> 5101e41f4b71Sopenharmony_ci 5102e41f4b71Sopenharmony_cigetExposureValue(): number 5103e41f4b71Sopenharmony_ci 5104e41f4b71Sopenharmony_ciObtains the exposure value in use. 5105e41f4b71Sopenharmony_ci 5106e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 5107e41f4b71Sopenharmony_ci 5108e41f4b71Sopenharmony_ci**Return value** 5109e41f4b71Sopenharmony_ci 5110e41f4b71Sopenharmony_ci| Type | Description | 5111e41f4b71Sopenharmony_ci| ---------- | ----------------------------- | 5112e41f4b71Sopenharmony_ci| number | Exposure value obtained. There is a step for EV. For example, if the step is 0.5 and this parameter is set to 1.2, the EV that takes effect is 1.0.<br>If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 5113e41f4b71Sopenharmony_ci 5114e41f4b71Sopenharmony_ci**Error codes** 5115e41f4b71Sopenharmony_ci 5116e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 5117e41f4b71Sopenharmony_ci 5118e41f4b71Sopenharmony_ci| ID | Error Message | 5119e41f4b71Sopenharmony_ci| --------------- | --------------- | 5120e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 5121e41f4b71Sopenharmony_ci 5122e41f4b71Sopenharmony_ci**Example** 5123e41f4b71Sopenharmony_ci 5124e41f4b71Sopenharmony_ci```ts 5125e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 5126e41f4b71Sopenharmony_ci 5127e41f4b71Sopenharmony_cifunction getExposureValue(photoSession: camera.PhotoSession): number { 5128e41f4b71Sopenharmony_ci const invalidValue: number = -1; 5129e41f4b71Sopenharmony_ci let exposureValue: number = invalidValue; 5130e41f4b71Sopenharmony_ci try { 5131e41f4b71Sopenharmony_ci exposureValue = photoSession.getExposureValue(); 5132e41f4b71Sopenharmony_ci } catch (error) { 5133e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 5134e41f4b71Sopenharmony_ci let err = error as BusinessError; 5135e41f4b71Sopenharmony_ci console.error(`The getExposureValue call failed. error code: ${err.code}`); 5136e41f4b71Sopenharmony_ci } 5137e41f4b71Sopenharmony_ci return exposureValue; 5138e41f4b71Sopenharmony_ci} 5139e41f4b71Sopenharmony_ci``` 5140e41f4b71Sopenharmony_ci 5141e41f4b71Sopenharmony_ci## AutoExposureQuery<sup>12+</sup> 5142e41f4b71Sopenharmony_ci 5143e41f4b71Sopenharmony_ciProvides APIs to query the automatic exposure feature of a camera device. 5144e41f4b71Sopenharmony_ci 5145e41f4b71Sopenharmony_ci### isExposureModeSupported<sup>11+</sup> 5146e41f4b71Sopenharmony_ci 5147e41f4b71Sopenharmony_ciisExposureModeSupported(aeMode: ExposureMode): boolean 5148e41f4b71Sopenharmony_ci 5149e41f4b71Sopenharmony_ciChecks whether an exposure mode is supported. 5150e41f4b71Sopenharmony_ci 5151e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 5152e41f4b71Sopenharmony_ci 5153e41f4b71Sopenharmony_ci**Parameters** 5154e41f4b71Sopenharmony_ci 5155e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 5156e41f4b71Sopenharmony_ci| -------- | -------------------------------| ---- | ----------------------------- | 5157e41f4b71Sopenharmony_ci| aeMode | [ExposureMode](#exposuremode) | Yes | Exposure mode. | 5158e41f4b71Sopenharmony_ci 5159e41f4b71Sopenharmony_ci**Return value** 5160e41f4b71Sopenharmony_ci 5161e41f4b71Sopenharmony_ci| Type | Description | 5162e41f4b71Sopenharmony_ci| ---------- | ----------------------------- | 5163e41f4b71Sopenharmony_ci| boolean | **true**: The exposure mode is supported.<br>**false**: The exposure mode is not supported. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 5164e41f4b71Sopenharmony_ci 5165e41f4b71Sopenharmony_ci**Error codes** 5166e41f4b71Sopenharmony_ci 5167e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 5168e41f4b71Sopenharmony_ci 5169e41f4b71Sopenharmony_ci| ID | Error Message | 5170e41f4b71Sopenharmony_ci| --------------- | --------------- | 5171e41f4b71Sopenharmony_ci| 7400103 | Session not config, only throw in session usage. | 5172e41f4b71Sopenharmony_ci 5173e41f4b71Sopenharmony_ci**Example** 5174e41f4b71Sopenharmony_ci 5175e41f4b71Sopenharmony_ci```ts 5176e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 5177e41f4b71Sopenharmony_ci 5178e41f4b71Sopenharmony_cifunction isExposureModeSupported(photoSession: camera.PhotoSession): boolean { 5179e41f4b71Sopenharmony_ci let isSupported: boolean = false; 5180e41f4b71Sopenharmony_ci try { 5181e41f4b71Sopenharmony_ci isSupported = photoSession.isExposureModeSupported(camera.ExposureMode.EXPOSURE_MODE_LOCKED); 5182e41f4b71Sopenharmony_ci } catch (error) { 5183e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 5184e41f4b71Sopenharmony_ci let err = error as BusinessError; 5185e41f4b71Sopenharmony_ci console.error(`The isExposureModeSupported call failed. error code: ${err.code}`); 5186e41f4b71Sopenharmony_ci } 5187e41f4b71Sopenharmony_ci return isSupported; 5188e41f4b71Sopenharmony_ci} 5189e41f4b71Sopenharmony_ci``` 5190e41f4b71Sopenharmony_ci 5191e41f4b71Sopenharmony_ci### getExposureBiasRange<sup>11+</sup> 5192e41f4b71Sopenharmony_ci 5193e41f4b71Sopenharmony_cigetExposureBiasRange(): Array\<number\> 5194e41f4b71Sopenharmony_ci 5195e41f4b71Sopenharmony_ciObtains the exposure compensation values of the camera device. 5196e41f4b71Sopenharmony_ci 5197e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 5198e41f4b71Sopenharmony_ci 5199e41f4b71Sopenharmony_ci**Return value** 5200e41f4b71Sopenharmony_ci 5201e41f4b71Sopenharmony_ci| Type | Description | 5202e41f4b71Sopenharmony_ci| ---------- | ----------------------------- | 5203e41f4b71Sopenharmony_ci| Array\<number\> | Array of compensation values. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 5204e41f4b71Sopenharmony_ci 5205e41f4b71Sopenharmony_ci**Error codes** 5206e41f4b71Sopenharmony_ci 5207e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 5208e41f4b71Sopenharmony_ci 5209e41f4b71Sopenharmony_ci| ID | Error Message | 5210e41f4b71Sopenharmony_ci| --------------- | --------------- | 5211e41f4b71Sopenharmony_ci| 7400103 | Session not config, only throw in session usage. | 5212e41f4b71Sopenharmony_ci 5213e41f4b71Sopenharmony_ci**Example** 5214e41f4b71Sopenharmony_ci 5215e41f4b71Sopenharmony_ci```ts 5216e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 5217e41f4b71Sopenharmony_ci 5218e41f4b71Sopenharmony_cifunction getExposureBiasRange(photoSession: camera.PhotoSession): Array<number> { 5219e41f4b71Sopenharmony_ci let biasRangeArray: Array<number> = []; 5220e41f4b71Sopenharmony_ci try { 5221e41f4b71Sopenharmony_ci biasRangeArray = photoSession.getExposureBiasRange(); 5222e41f4b71Sopenharmony_ci } catch (error) { 5223e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 5224e41f4b71Sopenharmony_ci let err = error as BusinessError; 5225e41f4b71Sopenharmony_ci console.error(`The getExposureBiasRange call failed. error code: ${err.code}`); 5226e41f4b71Sopenharmony_ci } 5227e41f4b71Sopenharmony_ci return biasRangeArray; 5228e41f4b71Sopenharmony_ci} 5229e41f4b71Sopenharmony_ci``` 5230e41f4b71Sopenharmony_ci 5231e41f4b71Sopenharmony_ci## Focus<sup>11+</sup> 5232e41f4b71Sopenharmony_ci 5233e41f4b71Sopenharmony_ciFocus extends [FocusQuery](#focusquery12) 5234e41f4b71Sopenharmony_ci 5235e41f4b71Sopenharmony_ciProvides APIs related to focus operations. 5236e41f4b71Sopenharmony_ci 5237e41f4b71Sopenharmony_ci### setFocusMode<sup>11+</sup> 5238e41f4b71Sopenharmony_ci 5239e41f4b71Sopenharmony_cisetFocusMode(afMode: FocusMode): void 5240e41f4b71Sopenharmony_ci 5241e41f4b71Sopenharmony_ciSets a focus mode. 5242e41f4b71Sopenharmony_ci 5243e41f4b71Sopenharmony_ciBefore the setting, call [isFocusModeSupported](#isfocusmodesupported11) to check whether the focus mode is supported. 5244e41f4b71Sopenharmony_ci 5245e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 5246e41f4b71Sopenharmony_ci 5247e41f4b71Sopenharmony_ci**Parameters** 5248e41f4b71Sopenharmony_ci 5249e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 5250e41f4b71Sopenharmony_ci| -------- | ----------------------- | ---- | ------------------- | 5251e41f4b71Sopenharmony_ci| afMode | [FocusMode](#focusmode) | Yes | Focus mode. | 5252e41f4b71Sopenharmony_ci 5253e41f4b71Sopenharmony_ci**Error codes** 5254e41f4b71Sopenharmony_ci 5255e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 5256e41f4b71Sopenharmony_ci 5257e41f4b71Sopenharmony_ci| ID | Error Message | 5258e41f4b71Sopenharmony_ci| --------------- | --------------- | 5259e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 5260e41f4b71Sopenharmony_ci 5261e41f4b71Sopenharmony_ci**Example** 5262e41f4b71Sopenharmony_ci 5263e41f4b71Sopenharmony_ci```ts 5264e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 5265e41f4b71Sopenharmony_ci 5266e41f4b71Sopenharmony_cifunction setFocusMode(photoSession: camera.PhotoSession): void { 5267e41f4b71Sopenharmony_ci try { 5268e41f4b71Sopenharmony_ci photoSession.setFocusMode(camera.FocusMode.FOCUS_MODE_AUTO); 5269e41f4b71Sopenharmony_ci } catch (error) { 5270e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 5271e41f4b71Sopenharmony_ci let err = error as BusinessError; 5272e41f4b71Sopenharmony_ci console.error(`The setFocusMode call failed. error code: ${err.code}`); 5273e41f4b71Sopenharmony_ci } 5274e41f4b71Sopenharmony_ci} 5275e41f4b71Sopenharmony_ci``` 5276e41f4b71Sopenharmony_ci 5277e41f4b71Sopenharmony_ci### getFocusMode<sup>11+</sup> 5278e41f4b71Sopenharmony_ci 5279e41f4b71Sopenharmony_cigetFocusMode(): FocusMode 5280e41f4b71Sopenharmony_ci 5281e41f4b71Sopenharmony_ciObtains the focus mode in use. 5282e41f4b71Sopenharmony_ci 5283e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 5284e41f4b71Sopenharmony_ci 5285e41f4b71Sopenharmony_ci**Return value** 5286e41f4b71Sopenharmony_ci 5287e41f4b71Sopenharmony_ci| Type | Description | 5288e41f4b71Sopenharmony_ci| ---------- | ----------------------------- | 5289e41f4b71Sopenharmony_ci| [FocusMode](#focusmode) | Focus mode obtained. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 5290e41f4b71Sopenharmony_ci 5291e41f4b71Sopenharmony_ci**Error codes** 5292e41f4b71Sopenharmony_ci 5293e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 5294e41f4b71Sopenharmony_ci 5295e41f4b71Sopenharmony_ci| ID | Error Message | 5296e41f4b71Sopenharmony_ci| --------------- | --------------- | 5297e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 5298e41f4b71Sopenharmony_ci 5299e41f4b71Sopenharmony_ci**Example** 5300e41f4b71Sopenharmony_ci 5301e41f4b71Sopenharmony_ci```ts 5302e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 5303e41f4b71Sopenharmony_ci 5304e41f4b71Sopenharmony_cifunction getFocusMode(photoSession: camera.PhotoSession): camera.FocusMode | undefined { 5305e41f4b71Sopenharmony_ci let afMode: camera.FocusMode | undefined = undefined; 5306e41f4b71Sopenharmony_ci try { 5307e41f4b71Sopenharmony_ci afMode = photoSession.getFocusMode(); 5308e41f4b71Sopenharmony_ci } catch (error) { 5309e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 5310e41f4b71Sopenharmony_ci let err = error as BusinessError; 5311e41f4b71Sopenharmony_ci console.error(`The getFocusMode call failed. error code: ${err.code}`); 5312e41f4b71Sopenharmony_ci } 5313e41f4b71Sopenharmony_ci return afMode; 5314e41f4b71Sopenharmony_ci} 5315e41f4b71Sopenharmony_ci``` 5316e41f4b71Sopenharmony_ci 5317e41f4b71Sopenharmony_ci### setFocusPoint<sup>11+</sup> 5318e41f4b71Sopenharmony_ci 5319e41f4b71Sopenharmony_cisetFocusPoint(point: Point): void 5320e41f4b71Sopenharmony_ci 5321e41f4b71Sopenharmony_ciSets the focal point. The focal point must be in the coordinate system (0-1), where the upper left corner is {0, 0} and the lower right corner is {1, 1}. 5322e41f4b71Sopenharmony_ci 5323e41f4b71Sopenharmony_ciThe coordinate system is based on the horizontal device direction with the device's charging port on the right. If the layout of the preview screen of an application is based on the vertical direction with the charging port on the lower side, the layout width and height are {w, h}, and the touch point is {x, y}, then the coordinate point after conversion is {y/h, 1-x/w}. 5324e41f4b71Sopenharmony_ci 5325e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 5326e41f4b71Sopenharmony_ci 5327e41f4b71Sopenharmony_ci**Parameters** 5328e41f4b71Sopenharmony_ci 5329e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 5330e41f4b71Sopenharmony_ci| -------- | ----------------------- | ---- | ------------------- | 5331e41f4b71Sopenharmony_ci| point | [Point](#point) | Yes | Focal point. The value range of x and y must be within [0, 1]. If a value less than 0 is passed, the value **0** is used. If a value greater than **1** is passed, the value **1** is used. | 5332e41f4b71Sopenharmony_ci 5333e41f4b71Sopenharmony_ci**Error codes** 5334e41f4b71Sopenharmony_ci 5335e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 5336e41f4b71Sopenharmony_ci 5337e41f4b71Sopenharmony_ci| ID | Error Message | 5338e41f4b71Sopenharmony_ci| --------------- | --------------- | 5339e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 5340e41f4b71Sopenharmony_ci 5341e41f4b71Sopenharmony_ci**Example** 5342e41f4b71Sopenharmony_ci 5343e41f4b71Sopenharmony_ci```ts 5344e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 5345e41f4b71Sopenharmony_ci 5346e41f4b71Sopenharmony_cifunction setFocusPoint(photoSession: camera.PhotoSession): void { 5347e41f4b71Sopenharmony_ci const focusPoint: camera.Point = {x: 1, y: 1}; 5348e41f4b71Sopenharmony_ci try { 5349e41f4b71Sopenharmony_ci photoSession.setFocusPoint(focusPoint); 5350e41f4b71Sopenharmony_ci } catch (error) { 5351e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 5352e41f4b71Sopenharmony_ci let err = error as BusinessError; 5353e41f4b71Sopenharmony_ci console.error(`The setFocusPoint call failed. error code: ${err.code}`); 5354e41f4b71Sopenharmony_ci } 5355e41f4b71Sopenharmony_ci} 5356e41f4b71Sopenharmony_ci``` 5357e41f4b71Sopenharmony_ci 5358e41f4b71Sopenharmony_ci### getFocusPoint<sup>11+</sup> 5359e41f4b71Sopenharmony_ci 5360e41f4b71Sopenharmony_cigetFocusPoint(): Point 5361e41f4b71Sopenharmony_ci 5362e41f4b71Sopenharmony_ciObtains the focal point of the camera device. 5363e41f4b71Sopenharmony_ci 5364e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 5365e41f4b71Sopenharmony_ci 5366e41f4b71Sopenharmony_ci**Return value** 5367e41f4b71Sopenharmony_ci 5368e41f4b71Sopenharmony_ci| Type | Description | 5369e41f4b71Sopenharmony_ci| ---------- | ----------------------------- | 5370e41f4b71Sopenharmony_ci| [Point](#point) | Focal point obtained. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 5371e41f4b71Sopenharmony_ci 5372e41f4b71Sopenharmony_ci**Error codes** 5373e41f4b71Sopenharmony_ci 5374e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 5375e41f4b71Sopenharmony_ci 5376e41f4b71Sopenharmony_ci| ID | Error Message | 5377e41f4b71Sopenharmony_ci| --------------- | --------------- | 5378e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 5379e41f4b71Sopenharmony_ci 5380e41f4b71Sopenharmony_ci**Example** 5381e41f4b71Sopenharmony_ci 5382e41f4b71Sopenharmony_ci```ts 5383e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 5384e41f4b71Sopenharmony_ci 5385e41f4b71Sopenharmony_cifunction getFocusPoint(photoSession: camera.PhotoSession): camera.Point | undefined { 5386e41f4b71Sopenharmony_ci let point: camera.Point | undefined = undefined; 5387e41f4b71Sopenharmony_ci try { 5388e41f4b71Sopenharmony_ci point = photoSession.getFocusPoint(); 5389e41f4b71Sopenharmony_ci } catch (error) { 5390e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 5391e41f4b71Sopenharmony_ci let err = error as BusinessError; 5392e41f4b71Sopenharmony_ci console.error(`The getFocusPoint call failed. error code: ${err.code}`); 5393e41f4b71Sopenharmony_ci } 5394e41f4b71Sopenharmony_ci return point; 5395e41f4b71Sopenharmony_ci} 5396e41f4b71Sopenharmony_ci``` 5397e41f4b71Sopenharmony_ci 5398e41f4b71Sopenharmony_ci### getFocalLength<sup>11+</sup> 5399e41f4b71Sopenharmony_ci 5400e41f4b71Sopenharmony_cigetFocalLength(): number 5401e41f4b71Sopenharmony_ci 5402e41f4b71Sopenharmony_ciObtains the focal length of the camera device. 5403e41f4b71Sopenharmony_ci 5404e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 5405e41f4b71Sopenharmony_ci 5406e41f4b71Sopenharmony_ci**Return value** 5407e41f4b71Sopenharmony_ci 5408e41f4b71Sopenharmony_ci| Type | Description | 5409e41f4b71Sopenharmony_ci| ---------- | ----------------------------- | 5410e41f4b71Sopenharmony_ci| number | Focal length, in mm. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 5411e41f4b71Sopenharmony_ci 5412e41f4b71Sopenharmony_ci**Error codes** 5413e41f4b71Sopenharmony_ci 5414e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 5415e41f4b71Sopenharmony_ci 5416e41f4b71Sopenharmony_ci| ID | Error Message | 5417e41f4b71Sopenharmony_ci| --------------- | --------------- | 5418e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 5419e41f4b71Sopenharmony_ci 5420e41f4b71Sopenharmony_ci**Example** 5421e41f4b71Sopenharmony_ci 5422e41f4b71Sopenharmony_ci```ts 5423e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 5424e41f4b71Sopenharmony_ci 5425e41f4b71Sopenharmony_cifunction getFocalLength(photoSession: camera.PhotoSession): number { 5426e41f4b71Sopenharmony_ci const invalidValue: number = -1; 5427e41f4b71Sopenharmony_ci let focalLength: number = invalidValue; 5428e41f4b71Sopenharmony_ci try { 5429e41f4b71Sopenharmony_ci focalLength = photoSession.getFocalLength(); 5430e41f4b71Sopenharmony_ci } catch (error) { 5431e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 5432e41f4b71Sopenharmony_ci let err = error as BusinessError; 5433e41f4b71Sopenharmony_ci console.error(`The getFocalLength call failed. error code: ${err.code}`); 5434e41f4b71Sopenharmony_ci } 5435e41f4b71Sopenharmony_ci return focalLength; 5436e41f4b71Sopenharmony_ci} 5437e41f4b71Sopenharmony_ci``` 5438e41f4b71Sopenharmony_ci 5439e41f4b71Sopenharmony_ci## FocusQuery<sup>12+</sup> 5440e41f4b71Sopenharmony_ci 5441e41f4b71Sopenharmony_ciProvides APIs to check whether a focus mode is supported. 5442e41f4b71Sopenharmony_ci 5443e41f4b71Sopenharmony_ci### isFocusModeSupported<sup>11+</sup> 5444e41f4b71Sopenharmony_ci 5445e41f4b71Sopenharmony_ciisFocusModeSupported(afMode: FocusMode): boolean 5446e41f4b71Sopenharmony_ci 5447e41f4b71Sopenharmony_ciChecks whether a focus mode is supported. 5448e41f4b71Sopenharmony_ci 5449e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 5450e41f4b71Sopenharmony_ci 5451e41f4b71Sopenharmony_ci**Parameters** 5452e41f4b71Sopenharmony_ci 5453e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 5454e41f4b71Sopenharmony_ci| -------- | ----------------------- | ---- | -------------------------------- | 5455e41f4b71Sopenharmony_ci| afMode | [FocusMode](#focusmode) | Yes | Focus mode. | 5456e41f4b71Sopenharmony_ci 5457e41f4b71Sopenharmony_ci**Return value** 5458e41f4b71Sopenharmony_ci 5459e41f4b71Sopenharmony_ci| Type | Description | 5460e41f4b71Sopenharmony_ci| ---------- | ----------------------------- | 5461e41f4b71Sopenharmony_ci| boolean | **true**: The focus mode is supported.<br>**false**: The focus mode is not supported. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 5462e41f4b71Sopenharmony_ci 5463e41f4b71Sopenharmony_ci**Error codes** 5464e41f4b71Sopenharmony_ci 5465e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 5466e41f4b71Sopenharmony_ci 5467e41f4b71Sopenharmony_ci| ID | Error Message | 5468e41f4b71Sopenharmony_ci| --------------- | --------------- | 5469e41f4b71Sopenharmony_ci| 7400103 | Session not config, only throw in session usage. | 5470e41f4b71Sopenharmony_ci 5471e41f4b71Sopenharmony_ci**Example** 5472e41f4b71Sopenharmony_ci 5473e41f4b71Sopenharmony_ci```ts 5474e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 5475e41f4b71Sopenharmony_ci 5476e41f4b71Sopenharmony_cifunction isFocusModeSupported(photoSession: camera.PhotoSession): boolean { 5477e41f4b71Sopenharmony_ci let status: boolean = false; 5478e41f4b71Sopenharmony_ci try { 5479e41f4b71Sopenharmony_ci status = photoSession.isFocusModeSupported(camera.FocusMode.FOCUS_MODE_AUTO); 5480e41f4b71Sopenharmony_ci } catch (error) { 5481e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 5482e41f4b71Sopenharmony_ci let err = error as BusinessError; 5483e41f4b71Sopenharmony_ci console.error(`The isFocusModeSupported call failed. error code: ${err.code}`); 5484e41f4b71Sopenharmony_ci } 5485e41f4b71Sopenharmony_ci return status; 5486e41f4b71Sopenharmony_ci} 5487e41f4b71Sopenharmony_ci``` 5488e41f4b71Sopenharmony_ci 5489e41f4b71Sopenharmony_ci## SmoothZoomMode<sup>11+</sup> 5490e41f4b71Sopenharmony_ci 5491e41f4b71Sopenharmony_ciEnumerates the smooth zoom modes. 5492e41f4b71Sopenharmony_ci 5493e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 5494e41f4b71Sopenharmony_ci 5495e41f4b71Sopenharmony_ci| Name | Value | Description | 5496e41f4b71Sopenharmony_ci| ------------ | ---- | -------------- | 5497e41f4b71Sopenharmony_ci| NORMAL | 0 | Bessel curve mode. | 5498e41f4b71Sopenharmony_ci 5499e41f4b71Sopenharmony_ci## SmoothZoomInfo<sup>11+</sup> 5500e41f4b71Sopenharmony_ci 5501e41f4b71Sopenharmony_ciDefines the smooth zoom information. 5502e41f4b71Sopenharmony_ci 5503e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 5504e41f4b71Sopenharmony_ci 5505e41f4b71Sopenharmony_ci| Name | Type | Read-only | Optional | Description | 5506e41f4b71Sopenharmony_ci| -------- | ---------- | -------- | -------- | ---------- | 5507e41f4b71Sopenharmony_ci| duration | number | No | No | Total duration of smooth zoom, in ms.| 5508e41f4b71Sopenharmony_ci 5509e41f4b71Sopenharmony_ci## Zoom<sup>11+</sup> 5510e41f4b71Sopenharmony_ci 5511e41f4b71Sopenharmony_ciZoom extends [ZoomQuery](#zoomquery12) 5512e41f4b71Sopenharmony_ci 5513e41f4b71Sopenharmony_ciProvides APIs related to zoom operations. 5514e41f4b71Sopenharmony_ci 5515e41f4b71Sopenharmony_ci### setZoomRatio<sup>11+</sup> 5516e41f4b71Sopenharmony_ci 5517e41f4b71Sopenharmony_cisetZoomRatio(zoomRatio: number): void 5518e41f4b71Sopenharmony_ci 5519e41f4b71Sopenharmony_ciSets a zoom ratio, with a maximum precision of two decimal places. 5520e41f4b71Sopenharmony_ci 5521e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 5522e41f4b71Sopenharmony_ci 5523e41f4b71Sopenharmony_ci**Parameters** 5524e41f4b71Sopenharmony_ci 5525e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 5526e41f4b71Sopenharmony_ci| --------- | -------------------- | ---- |--------------------------------------------------------------------------------------| 5527e41f4b71Sopenharmony_ci| zoomRatio | number | Yes | Zoom ratio. The supported zoom ratio range can be obtained by calling [getZoomRatioRange](#getzoomratiorange11). If the value passed in is not within the supported range, the value within the precision range is retained.| 5528e41f4b71Sopenharmony_ci 5529e41f4b71Sopenharmony_ci**Error codes** 5530e41f4b71Sopenharmony_ci 5531e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 5532e41f4b71Sopenharmony_ci 5533e41f4b71Sopenharmony_ci| ID | Error Message | 5534e41f4b71Sopenharmony_ci| --------------- | --------------- | 5535e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 5536e41f4b71Sopenharmony_ci 5537e41f4b71Sopenharmony_ci**Example** 5538e41f4b71Sopenharmony_ci 5539e41f4b71Sopenharmony_ci```ts 5540e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 5541e41f4b71Sopenharmony_ci 5542e41f4b71Sopenharmony_cifunction setZoomRatio(photoSession: camera.PhotoSession, zoomRatioRange: Array<number>): void { 5543e41f4b71Sopenharmony_ci if (zoomRatioRange === undefined || zoomRatioRange.length <= 0) { 5544e41f4b71Sopenharmony_ci return; 5545e41f4b71Sopenharmony_ci } 5546e41f4b71Sopenharmony_ci let zoomRatio = zoomRatioRange[0]; 5547e41f4b71Sopenharmony_ci try { 5548e41f4b71Sopenharmony_ci photoSession.setZoomRatio(zoomRatio); 5549e41f4b71Sopenharmony_ci } catch (error) { 5550e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 5551e41f4b71Sopenharmony_ci let err = error as BusinessError; 5552e41f4b71Sopenharmony_ci console.error(`The setZoomRatio call failed. error code: ${err.code}`); 5553e41f4b71Sopenharmony_ci } 5554e41f4b71Sopenharmony_ci} 5555e41f4b71Sopenharmony_ci``` 5556e41f4b71Sopenharmony_ci 5557e41f4b71Sopenharmony_ci### getZoomRatio<sup>11+</sup> 5558e41f4b71Sopenharmony_ci 5559e41f4b71Sopenharmony_cigetZoomRatio(): number 5560e41f4b71Sopenharmony_ci 5561e41f4b71Sopenharmony_ciObtains the zoom ratio in use. 5562e41f4b71Sopenharmony_ci 5563e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 5564e41f4b71Sopenharmony_ci 5565e41f4b71Sopenharmony_ci**Return value** 5566e41f4b71Sopenharmony_ci 5567e41f4b71Sopenharmony_ci| Type | Description | 5568e41f4b71Sopenharmony_ci| ---------- | ----------------------------- | 5569e41f4b71Sopenharmony_ci| number | Zoom ratio obtained. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 5570e41f4b71Sopenharmony_ci 5571e41f4b71Sopenharmony_ci**Error codes** 5572e41f4b71Sopenharmony_ci 5573e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 5574e41f4b71Sopenharmony_ci 5575e41f4b71Sopenharmony_ci| ID | Error Message | 5576e41f4b71Sopenharmony_ci| --------------- | --------------- | 5577e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 5578e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 5579e41f4b71Sopenharmony_ci 5580e41f4b71Sopenharmony_ci**Example** 5581e41f4b71Sopenharmony_ci 5582e41f4b71Sopenharmony_ci```ts 5583e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 5584e41f4b71Sopenharmony_ci 5585e41f4b71Sopenharmony_cifunction getZoomRatio(photoSession: camera.PhotoSession): number { 5586e41f4b71Sopenharmony_ci const invalidValue: number = -1; 5587e41f4b71Sopenharmony_ci let zoomRatio: number = invalidValue; 5588e41f4b71Sopenharmony_ci try { 5589e41f4b71Sopenharmony_ci zoomRatio = photoSession.getZoomRatio(); 5590e41f4b71Sopenharmony_ci } catch (error) { 5591e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 5592e41f4b71Sopenharmony_ci let err = error as BusinessError; 5593e41f4b71Sopenharmony_ci console.error(`The getZoomRatio call failed. error code: ${err.code}`); 5594e41f4b71Sopenharmony_ci } 5595e41f4b71Sopenharmony_ci return zoomRatio; 5596e41f4b71Sopenharmony_ci} 5597e41f4b71Sopenharmony_ci``` 5598e41f4b71Sopenharmony_ci 5599e41f4b71Sopenharmony_ci### setSmoothZoom<sup>11+</sup> 5600e41f4b71Sopenharmony_ci 5601e41f4b71Sopenharmony_cisetSmoothZoom(targetRatio: number, mode?: SmoothZoomMode): void 5602e41f4b71Sopenharmony_ci 5603e41f4b71Sopenharmony_ciSets smooth zoom. 5604e41f4b71Sopenharmony_ci 5605e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 5606e41f4b71Sopenharmony_ci 5607e41f4b71Sopenharmony_ci**Parameters** 5608e41f4b71Sopenharmony_ci 5609e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 5610e41f4b71Sopenharmony_ci| ------------ | -------------- | ---- | ----------------- | 5611e41f4b71Sopenharmony_ci| targetRatio | number | Yes | Target zoom ratio. | 5612e41f4b71Sopenharmony_ci| mode | [SmoothZoomMode](#smoothzoommode11) | No | Smooth zoom mode. | 5613e41f4b71Sopenharmony_ci 5614e41f4b71Sopenharmony_ci**Error codes** 5615e41f4b71Sopenharmony_ci 5616e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 5617e41f4b71Sopenharmony_ci 5618e41f4b71Sopenharmony_ci| ID | Error Message | 5619e41f4b71Sopenharmony_ci| --------------- | --------------- | 5620e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 5621e41f4b71Sopenharmony_ci 5622e41f4b71Sopenharmony_ci**Example** 5623e41f4b71Sopenharmony_ci 5624e41f4b71Sopenharmony_ci```ts 5625e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 5626e41f4b71Sopenharmony_ci 5627e41f4b71Sopenharmony_cifunction setSmoothZoom(sessionExtendsZoom: camera.Zoom, targetZoomRatio: number, mode: camera.SmoothZoomMode): void { 5628e41f4b71Sopenharmony_ci try { 5629e41f4b71Sopenharmony_ci sessionExtendsZoom.setSmoothZoom(targetZoomRatio, mode); 5630e41f4b71Sopenharmony_ci } catch (error) { 5631e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 5632e41f4b71Sopenharmony_ci let err = error as BusinessError; 5633e41f4b71Sopenharmony_ci console.error(`The setSmoothZoom call failed. error code: ${err.code}`); 5634e41f4b71Sopenharmony_ci } 5635e41f4b71Sopenharmony_ci} 5636e41f4b71Sopenharmony_ci``` 5637e41f4b71Sopenharmony_ci 5638e41f4b71Sopenharmony_ci## ZoomQuery<sup>12+</sup> 5639e41f4b71Sopenharmony_ci 5640e41f4b71Sopenharmony_ciProvides APIs to query the zoom feature of a device camera, including the API to obtain the supported zoom ratio range. 5641e41f4b71Sopenharmony_ci 5642e41f4b71Sopenharmony_ci### getZoomRatioRange<sup>11+</sup> 5643e41f4b71Sopenharmony_ci 5644e41f4b71Sopenharmony_cigetZoomRatioRange(): Array\<number\> 5645e41f4b71Sopenharmony_ci 5646e41f4b71Sopenharmony_ciObtains the supported zoom ratio range. 5647e41f4b71Sopenharmony_ci 5648e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 5649e41f4b71Sopenharmony_ci 5650e41f4b71Sopenharmony_ci**Return value** 5651e41f4b71Sopenharmony_ci 5652e41f4b71Sopenharmony_ci| Type | Description | 5653e41f4b71Sopenharmony_ci| ---------- | ----------------------------- | 5654e41f4b71Sopenharmony_ci| Array\<number\> | Array containing the minimum and maximum zoom ratios. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 5655e41f4b71Sopenharmony_ci 5656e41f4b71Sopenharmony_ci**Error codes** 5657e41f4b71Sopenharmony_ci 5658e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 5659e41f4b71Sopenharmony_ci 5660e41f4b71Sopenharmony_ci| ID | Error Message | 5661e41f4b71Sopenharmony_ci| --------------- | --------------- | 5662e41f4b71Sopenharmony_ci| 7400103 | Session not config, only throw in session usage. | 5663e41f4b71Sopenharmony_ci 5664e41f4b71Sopenharmony_ci**Example** 5665e41f4b71Sopenharmony_ci 5666e41f4b71Sopenharmony_ci```ts 5667e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 5668e41f4b71Sopenharmony_ci 5669e41f4b71Sopenharmony_cifunction getZoomRatioRange(photoSession: camera.PhotoSession): Array<number> { 5670e41f4b71Sopenharmony_ci let zoomRatioRange: Array<number> = []; 5671e41f4b71Sopenharmony_ci try { 5672e41f4b71Sopenharmony_ci zoomRatioRange = photoSession.getZoomRatioRange(); 5673e41f4b71Sopenharmony_ci } catch (error) { 5674e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 5675e41f4b71Sopenharmony_ci let err = error as BusinessError; 5676e41f4b71Sopenharmony_ci console.error(`The getZoomRatioRange call failed. error code: ${err.code}`); 5677e41f4b71Sopenharmony_ci } 5678e41f4b71Sopenharmony_ci return zoomRatioRange; 5679e41f4b71Sopenharmony_ci} 5680e41f4b71Sopenharmony_ci``` 5681e41f4b71Sopenharmony_ci 5682e41f4b71Sopenharmony_ci## Stabilization<sup>11+</sup> 5683e41f4b71Sopenharmony_ci 5684e41f4b71Sopenharmony_ciStabilization extends [StabilizationQuery](#stabilizationquery12) 5685e41f4b71Sopenharmony_ci 5686e41f4b71Sopenharmony_ciProvides APIs to set video stabilization. 5687e41f4b71Sopenharmony_ci 5688e41f4b71Sopenharmony_ci > **NOTE** 5689e41f4b71Sopenharmony_ci > 5690e41f4b71Sopenharmony_ci > You can set video stabilization only when a [VideoOutput](#videooutput) stream exists in the session. 5691e41f4b71Sopenharmony_ci > The enumerated value **HIGH** of [VideoStabilizationMode](#videostabilizationmode) takes effect only when the resolution of [Profile](#profile) is 1920 x 1080. 5692e41f4b71Sopenharmony_ci 5693e41f4b71Sopenharmony_ci### getActiveVideoStabilizationMode<sup>11+</sup> 5694e41f4b71Sopenharmony_ci 5695e41f4b71Sopenharmony_cigetActiveVideoStabilizationMode(): VideoStabilizationMode 5696e41f4b71Sopenharmony_ci 5697e41f4b71Sopenharmony_ciObtains the video stabilization mode in use. 5698e41f4b71Sopenharmony_ci 5699e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 5700e41f4b71Sopenharmony_ci 5701e41f4b71Sopenharmony_ci**Return value** 5702e41f4b71Sopenharmony_ci 5703e41f4b71Sopenharmony_ci| Type | Description | 5704e41f4b71Sopenharmony_ci| ---------- |-------------| 5705e41f4b71Sopenharmony_ci| [VideoStabilizationMode](#videostabilizationmode) | Video stabilization mode obtained.| 5706e41f4b71Sopenharmony_ci 5707e41f4b71Sopenharmony_ci**Error codes** 5708e41f4b71Sopenharmony_ci 5709e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 5710e41f4b71Sopenharmony_ci 5711e41f4b71Sopenharmony_ci| ID | Error Message | 5712e41f4b71Sopenharmony_ci| --------------- | --------------- | 5713e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 5714e41f4b71Sopenharmony_ci 5715e41f4b71Sopenharmony_ci**Example** 5716e41f4b71Sopenharmony_ci 5717e41f4b71Sopenharmony_ci```ts 5718e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 5719e41f4b71Sopenharmony_ci 5720e41f4b71Sopenharmony_cifunction getActiveVideoStabilizationMode(videoSession: camera.VideoSession): camera.VideoStabilizationMode | undefined { 5721e41f4b71Sopenharmony_ci let vsMode: camera.VideoStabilizationMode | undefined = undefined; 5722e41f4b71Sopenharmony_ci try { 5723e41f4b71Sopenharmony_ci vsMode = videoSession.getActiveVideoStabilizationMode(); 5724e41f4b71Sopenharmony_ci } catch (error) { 5725e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 5726e41f4b71Sopenharmony_ci let err = error as BusinessError; 5727e41f4b71Sopenharmony_ci console.error(`The getActiveVideoStabilizationMode call failed. error code: ${err.code}`); 5728e41f4b71Sopenharmony_ci } 5729e41f4b71Sopenharmony_ci return vsMode; 5730e41f4b71Sopenharmony_ci} 5731e41f4b71Sopenharmony_ci``` 5732e41f4b71Sopenharmony_ci 5733e41f4b71Sopenharmony_ci### setVideoStabilizationMode<sup>11+</sup> 5734e41f4b71Sopenharmony_ci 5735e41f4b71Sopenharmony_cisetVideoStabilizationMode(mode: VideoStabilizationMode): void 5736e41f4b71Sopenharmony_ci 5737e41f4b71Sopenharmony_ciSets a video stabilization mode. Before the setting, call [isVideoStabilizationModeSupported](#isvideostabilizationmodesupported11) to check whether the target video stabilization mode is supported. 5738e41f4b71Sopenharmony_ci 5739e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 5740e41f4b71Sopenharmony_ci 5741e41f4b71Sopenharmony_ci**Parameters** 5742e41f4b71Sopenharmony_ci 5743e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 5744e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------- | ---- | --------------------- | 5745e41f4b71Sopenharmony_ci| mode | [VideoStabilizationMode](#videostabilizationmode) | Yes | Video stabilization mode. | 5746e41f4b71Sopenharmony_ci 5747e41f4b71Sopenharmony_ci**Error codes** 5748e41f4b71Sopenharmony_ci 5749e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 5750e41f4b71Sopenharmony_ci 5751e41f4b71Sopenharmony_ci| ID | Error Message | 5752e41f4b71Sopenharmony_ci| --------------- | --------------- | 5753e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 5754e41f4b71Sopenharmony_ci 5755e41f4b71Sopenharmony_ci**Example** 5756e41f4b71Sopenharmony_ci 5757e41f4b71Sopenharmony_ci```ts 5758e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 5759e41f4b71Sopenharmony_ci 5760e41f4b71Sopenharmony_cifunction setVideoStabilizationMode(videoSession: camera.VideoSession): void { 5761e41f4b71Sopenharmony_ci try { 5762e41f4b71Sopenharmony_ci videoSession.setVideoStabilizationMode(camera.VideoStabilizationMode.OFF); 5763e41f4b71Sopenharmony_ci } catch (error) { 5764e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 5765e41f4b71Sopenharmony_ci let err = error as BusinessError; 5766e41f4b71Sopenharmony_ci console.error(`The setVideoStabilizationMode call failed. error code: ${err.code}`); 5767e41f4b71Sopenharmony_ci } 5768e41f4b71Sopenharmony_ci} 5769e41f4b71Sopenharmony_ci``` 5770e41f4b71Sopenharmony_ci 5771e41f4b71Sopenharmony_ci## StabilizationQuery<sup>12+</sup> 5772e41f4b71Sopenharmony_ci 5773e41f4b71Sopenharmony_ciProvides APIs to check the support for video stabilization. 5774e41f4b71Sopenharmony_ci 5775e41f4b71Sopenharmony_ci### isVideoStabilizationModeSupported<sup>11+</sup> 5776e41f4b71Sopenharmony_ci 5777e41f4b71Sopenharmony_ciisVideoStabilizationModeSupported(vsMode: VideoStabilizationMode): boolean 5778e41f4b71Sopenharmony_ci 5779e41f4b71Sopenharmony_ciChecks whether a video stabilization mode is supported. 5780e41f4b71Sopenharmony_ci 5781e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 5782e41f4b71Sopenharmony_ci 5783e41f4b71Sopenharmony_ci**Parameters** 5784e41f4b71Sopenharmony_ci 5785e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 5786e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------- | ---- | ------------------------------ | 5787e41f4b71Sopenharmony_ci| vsMode | [VideoStabilizationMode](#videostabilizationmode) | Yes | Video stabilization mode. | 5788e41f4b71Sopenharmony_ci 5789e41f4b71Sopenharmony_ci**Return value** 5790e41f4b71Sopenharmony_ci 5791e41f4b71Sopenharmony_ci| Type | Description | 5792e41f4b71Sopenharmony_ci| ---------- | ----------------------------- | 5793e41f4b71Sopenharmony_ci| boolean | **true**: The video stabilization mode is supported.<br>**false**: The video stabilization mode is not supported. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 5794e41f4b71Sopenharmony_ci 5795e41f4b71Sopenharmony_ci**Error codes** 5796e41f4b71Sopenharmony_ci 5797e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 5798e41f4b71Sopenharmony_ci 5799e41f4b71Sopenharmony_ci| ID | Error Message | 5800e41f4b71Sopenharmony_ci| --------------- | --------------- | 5801e41f4b71Sopenharmony_ci| 7400103 | Session not config, only throw in session usage. | 5802e41f4b71Sopenharmony_ci 5803e41f4b71Sopenharmony_ci**Example** 5804e41f4b71Sopenharmony_ci 5805e41f4b71Sopenharmony_ci```ts 5806e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 5807e41f4b71Sopenharmony_ci 5808e41f4b71Sopenharmony_cifunction isVideoStabilizationModeSupported(videoSession: camera.VideoSession): boolean { 5809e41f4b71Sopenharmony_ci let isSupported: boolean = false; 5810e41f4b71Sopenharmony_ci try { 5811e41f4b71Sopenharmony_ci isSupported = videoSession.isVideoStabilizationModeSupported(camera.VideoStabilizationMode.OFF); 5812e41f4b71Sopenharmony_ci } catch (error) { 5813e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 5814e41f4b71Sopenharmony_ci let err = error as BusinessError; 5815e41f4b71Sopenharmony_ci console.error(`The isVideoStabilizationModeSupported call failed. error code: ${err.code}`); 5816e41f4b71Sopenharmony_ci } 5817e41f4b71Sopenharmony_ci return isSupported; 5818e41f4b71Sopenharmony_ci} 5819e41f4b71Sopenharmony_ci``` 5820e41f4b71Sopenharmony_ci 5821e41f4b71Sopenharmony_ci## CaptureSession<sup>(deprecated)</sup> 5822e41f4b71Sopenharmony_ci 5823e41f4b71Sopenharmony_ciImplements a capture session, which saves all [CameraInput](#camerainput) and [CameraOutput](#cameraoutput) instances required to run the camera and requests the camera to complete shooting or video recording. 5824e41f4b71Sopenharmony_ci 5825e41f4b71Sopenharmony_ci> **NOTE** 5826e41f4b71Sopenharmony_ci> 5827e41f4b71Sopenharmony_ci>This API is supported since API version 10 and deprecated since API version 11. You are advised to use [PhotoSession](#photosession11) and [VideoSession](#videosession11) instead. 5828e41f4b71Sopenharmony_ci 5829e41f4b71Sopenharmony_ci### beginConfig<sup>(deprecated)</sup> 5830e41f4b71Sopenharmony_ci 5831e41f4b71Sopenharmony_cibeginConfig(): void 5832e41f4b71Sopenharmony_ci 5833e41f4b71Sopenharmony_ciStarts configuration for the session. 5834e41f4b71Sopenharmony_ci 5835e41f4b71Sopenharmony_ci> **NOTE** 5836e41f4b71Sopenharmony_ci> 5837e41f4b71Sopenharmony_ci>This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Session.beginConfig](#beginconfig11) instead. 5838e41f4b71Sopenharmony_ci 5839e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 5840e41f4b71Sopenharmony_ci 5841e41f4b71Sopenharmony_ci**Error codes** 5842e41f4b71Sopenharmony_ci 5843e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 5844e41f4b71Sopenharmony_ci 5845e41f4b71Sopenharmony_ci| ID | Error Message | 5846e41f4b71Sopenharmony_ci| --------------- | --------------- | 5847e41f4b71Sopenharmony_ci| 7400105 | Session config locked. | 5848e41f4b71Sopenharmony_ci 5849e41f4b71Sopenharmony_ci**Example** 5850e41f4b71Sopenharmony_ci 5851e41f4b71Sopenharmony_ci```ts 5852e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 5853e41f4b71Sopenharmony_ci 5854e41f4b71Sopenharmony_cifunction beginConfig(captureSession: camera.CaptureSession): void { 5855e41f4b71Sopenharmony_ci try { 5856e41f4b71Sopenharmony_ci captureSession.beginConfig(); 5857e41f4b71Sopenharmony_ci } catch (error) { 5858e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 5859e41f4b71Sopenharmony_ci let err = error as BusinessError; 5860e41f4b71Sopenharmony_ci console.error(`The beginConfig call failed. error code: ${err.code}`); 5861e41f4b71Sopenharmony_ci } 5862e41f4b71Sopenharmony_ci} 5863e41f4b71Sopenharmony_ci``` 5864e41f4b71Sopenharmony_ci 5865e41f4b71Sopenharmony_ci### commitConfig<sup>(deprecated)</sup> 5866e41f4b71Sopenharmony_ci 5867e41f4b71Sopenharmony_cicommitConfig(callback: AsyncCallback\<void\>): void 5868e41f4b71Sopenharmony_ci 5869e41f4b71Sopenharmony_ciCommits the configuration for this session. This API uses an asynchronous callback to return the result. 5870e41f4b71Sopenharmony_ci 5871e41f4b71Sopenharmony_ci> **NOTE** 5872e41f4b71Sopenharmony_ci> 5873e41f4b71Sopenharmony_ci>This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Session.commitConfig](#commitconfig11) instead. 5874e41f4b71Sopenharmony_ci 5875e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 5876e41f4b71Sopenharmony_ci 5877e41f4b71Sopenharmony_ci**Parameters** 5878e41f4b71Sopenharmony_ci 5879e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 5880e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | -------------------- | 5881e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 5882e41f4b71Sopenharmony_ci 5883e41f4b71Sopenharmony_ci**Error codes** 5884e41f4b71Sopenharmony_ci 5885e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 5886e41f4b71Sopenharmony_ci 5887e41f4b71Sopenharmony_ci| ID | Error Message | 5888e41f4b71Sopenharmony_ci| --------------- | --------------- | 5889e41f4b71Sopenharmony_ci| 7400102 | Operation not allowed. | 5890e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 5891e41f4b71Sopenharmony_ci 5892e41f4b71Sopenharmony_ci**Example** 5893e41f4b71Sopenharmony_ci 5894e41f4b71Sopenharmony_ci```ts 5895e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 5896e41f4b71Sopenharmony_ci 5897e41f4b71Sopenharmony_cifunction commitConfig(captureSession: camera.CaptureSession): void { 5898e41f4b71Sopenharmony_ci captureSession.commitConfig((err: BusinessError) => { 5899e41f4b71Sopenharmony_ci if (err) { 5900e41f4b71Sopenharmony_ci console.error(`The commitConfig call failed. error code: ${err.code}`); 5901e41f4b71Sopenharmony_ci return; 5902e41f4b71Sopenharmony_ci } 5903e41f4b71Sopenharmony_ci console.info('Callback invoked to indicate the commit config success.'); 5904e41f4b71Sopenharmony_ci }); 5905e41f4b71Sopenharmony_ci} 5906e41f4b71Sopenharmony_ci``` 5907e41f4b71Sopenharmony_ci 5908e41f4b71Sopenharmony_ci### commitConfig<sup>(deprecated)</sup> 5909e41f4b71Sopenharmony_ci 5910e41f4b71Sopenharmony_cicommitConfig(): Promise\<void\> 5911e41f4b71Sopenharmony_ci 5912e41f4b71Sopenharmony_ciCommits the configuration for this session. This API uses a promise to return the result. 5913e41f4b71Sopenharmony_ci 5914e41f4b71Sopenharmony_ci> **NOTE** 5915e41f4b71Sopenharmony_ci> 5916e41f4b71Sopenharmony_ci>This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Session.commitConfig](#commitconfig11-1) instead. 5917e41f4b71Sopenharmony_ci 5918e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 5919e41f4b71Sopenharmony_ci 5920e41f4b71Sopenharmony_ci**Return value** 5921e41f4b71Sopenharmony_ci 5922e41f4b71Sopenharmony_ci| Type | Description | 5923e41f4b71Sopenharmony_ci| -------------- |-------------------| 5924e41f4b71Sopenharmony_ci| Promise\<void\> | Promise that returns no value.| 5925e41f4b71Sopenharmony_ci 5926e41f4b71Sopenharmony_ci**Error codes** 5927e41f4b71Sopenharmony_ci 5928e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 5929e41f4b71Sopenharmony_ci 5930e41f4b71Sopenharmony_ci| ID | Error Message | 5931e41f4b71Sopenharmony_ci| --------------- | --------------- | 5932e41f4b71Sopenharmony_ci| 7400102 | Operation not allowed. | 5933e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 5934e41f4b71Sopenharmony_ci 5935e41f4b71Sopenharmony_ci**Example** 5936e41f4b71Sopenharmony_ci 5937e41f4b71Sopenharmony_ci```ts 5938e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 5939e41f4b71Sopenharmony_ci 5940e41f4b71Sopenharmony_cifunction commitConfig(captureSession: camera.CaptureSession): void { 5941e41f4b71Sopenharmony_ci captureSession.commitConfig().then(() => { 5942e41f4b71Sopenharmony_ci console.info('Promise returned to indicate the commit config success.'); 5943e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 5944e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 5945e41f4b71Sopenharmony_ci console.error(`The commitConfig call failed. error code: ${error.code}`); 5946e41f4b71Sopenharmony_ci }); 5947e41f4b71Sopenharmony_ci} 5948e41f4b71Sopenharmony_ci``` 5949e41f4b71Sopenharmony_ci 5950e41f4b71Sopenharmony_ci### addInput<sup>(deprecated)</sup> 5951e41f4b71Sopenharmony_ci 5952e41f4b71Sopenharmony_ciaddInput(cameraInput: CameraInput): void 5953e41f4b71Sopenharmony_ci 5954e41f4b71Sopenharmony_ciAdds a [CameraInput](#camerainput) instance to this session. 5955e41f4b71Sopenharmony_ci 5956e41f4b71Sopenharmony_ci> **NOTE** 5957e41f4b71Sopenharmony_ci> 5958e41f4b71Sopenharmony_ci>This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Session.addInput](#addinput11) instead. 5959e41f4b71Sopenharmony_ci 5960e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 5961e41f4b71Sopenharmony_ci 5962e41f4b71Sopenharmony_ci**Parameters** 5963e41f4b71Sopenharmony_ci 5964e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 5965e41f4b71Sopenharmony_ci| ----------- | --------------------------- | ---- | ------------------------ | 5966e41f4b71Sopenharmony_ci| cameraInput | [CameraInput](#camerainput) | Yes | **CameraInput** instance to add.| 5967e41f4b71Sopenharmony_ci 5968e41f4b71Sopenharmony_ci**Error codes** 5969e41f4b71Sopenharmony_ci 5970e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 5971e41f4b71Sopenharmony_ci 5972e41f4b71Sopenharmony_ci| ID | Error Message | 5973e41f4b71Sopenharmony_ci|---------|-----------------------------------------------| 5974e41f4b71Sopenharmony_ci| 7400101 | Parameter missing or parameter type incorrect. | 5975e41f4b71Sopenharmony_ci| 7400102 | Operation not allowed. | 5976e41f4b71Sopenharmony_ci 5977e41f4b71Sopenharmony_ci**Example** 5978e41f4b71Sopenharmony_ci 5979e41f4b71Sopenharmony_ci```ts 5980e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 5981e41f4b71Sopenharmony_ci 5982e41f4b71Sopenharmony_cifunction addInput(captureSession: camera.CaptureSession, cameraInput: camera.CameraInput): void { 5983e41f4b71Sopenharmony_ci try { 5984e41f4b71Sopenharmony_ci captureSession.addInput(cameraInput); 5985e41f4b71Sopenharmony_ci } catch (error) { 5986e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 5987e41f4b71Sopenharmony_ci let err = error as BusinessError; 5988e41f4b71Sopenharmony_ci console.error(`The addInput call failed. error code: ${err.code}`); 5989e41f4b71Sopenharmony_ci } 5990e41f4b71Sopenharmony_ci} 5991e41f4b71Sopenharmony_ci``` 5992e41f4b71Sopenharmony_ci 5993e41f4b71Sopenharmony_ci### removeInput<sup>(deprecated)</sup> 5994e41f4b71Sopenharmony_ci 5995e41f4b71Sopenharmony_ciremoveInput(cameraInput: CameraInput): void 5996e41f4b71Sopenharmony_ci 5997e41f4b71Sopenharmony_ciRemoves a [CameraInput](#camerainput) instance from this session. 5998e41f4b71Sopenharmony_ci 5999e41f4b71Sopenharmony_ci> **NOTE** 6000e41f4b71Sopenharmony_ci> 6001e41f4b71Sopenharmony_ci>This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Session.removeInput](#removeinput11) instead. 6002e41f4b71Sopenharmony_ci 6003e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 6004e41f4b71Sopenharmony_ci 6005e41f4b71Sopenharmony_ci**Parameters** 6006e41f4b71Sopenharmony_ci 6007e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 6008e41f4b71Sopenharmony_ci| ----------- | --------------------------- | ---- | ------------------------ | 6009e41f4b71Sopenharmony_ci| cameraInput | [CameraInput](#camerainput) | Yes | **CameraInput** instance to remove.| 6010e41f4b71Sopenharmony_ci 6011e41f4b71Sopenharmony_ci**Error codes** 6012e41f4b71Sopenharmony_ci 6013e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 6014e41f4b71Sopenharmony_ci 6015e41f4b71Sopenharmony_ci| ID | Error Message | 6016e41f4b71Sopenharmony_ci| --------------- | --------------- | 6017e41f4b71Sopenharmony_ci| 7400101 | Parameter missing or parameter type incorrect. | 6018e41f4b71Sopenharmony_ci| 7400102 | Operation not allowed. | 6019e41f4b71Sopenharmony_ci 6020e41f4b71Sopenharmony_ci**Example** 6021e41f4b71Sopenharmony_ci 6022e41f4b71Sopenharmony_ci```ts 6023e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 6024e41f4b71Sopenharmony_ci 6025e41f4b71Sopenharmony_cifunction removeInput(captureSession: camera.CaptureSession, cameraInput: camera.CameraInput): void { 6026e41f4b71Sopenharmony_ci try { 6027e41f4b71Sopenharmony_ci captureSession.removeInput(cameraInput); 6028e41f4b71Sopenharmony_ci } catch (error) { 6029e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 6030e41f4b71Sopenharmony_ci let err = error as BusinessError; 6031e41f4b71Sopenharmony_ci console.error(`The removeInput call failed. error code: ${err.code}`); 6032e41f4b71Sopenharmony_ci } 6033e41f4b71Sopenharmony_ci} 6034e41f4b71Sopenharmony_ci``` 6035e41f4b71Sopenharmony_ci 6036e41f4b71Sopenharmony_ci### addOutput<sup>(deprecated)</sup> 6037e41f4b71Sopenharmony_ci 6038e41f4b71Sopenharmony_ciaddOutput(cameraOutput: CameraOutput): void 6039e41f4b71Sopenharmony_ci 6040e41f4b71Sopenharmony_ciAdds a [CameraOutput](#cameraoutput) instance to this session. 6041e41f4b71Sopenharmony_ci 6042e41f4b71Sopenharmony_ci> **NOTE** 6043e41f4b71Sopenharmony_ci> 6044e41f4b71Sopenharmony_ci>This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Session.addOutput](#addoutput11) instead. 6045e41f4b71Sopenharmony_ci 6046e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 6047e41f4b71Sopenharmony_ci 6048e41f4b71Sopenharmony_ci**Parameters** 6049e41f4b71Sopenharmony_ci 6050e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 6051e41f4b71Sopenharmony_ci| ------------- | ------------------------------- | ---- | ------------------------ | 6052e41f4b71Sopenharmony_ci| cameraOutput | [CameraOutput](#cameraoutput) | Yes | **CameraOutput** instance to add.| 6053e41f4b71Sopenharmony_ci 6054e41f4b71Sopenharmony_ci**Error codes** 6055e41f4b71Sopenharmony_ci 6056e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 6057e41f4b71Sopenharmony_ci 6058e41f4b71Sopenharmony_ci| ID | Error Message | 6059e41f4b71Sopenharmony_ci| --------------- | --------------- | 6060e41f4b71Sopenharmony_ci| 7400101 | Parameter missing or parameter type incorrect. | 6061e41f4b71Sopenharmony_ci| 7400102 | Operation not allowed. | 6062e41f4b71Sopenharmony_ci 6063e41f4b71Sopenharmony_ci**Example** 6064e41f4b71Sopenharmony_ci 6065e41f4b71Sopenharmony_ci```ts 6066e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 6067e41f4b71Sopenharmony_ci 6068e41f4b71Sopenharmony_cifunction addOutput(captureSession: camera.CaptureSession, cameraOutput: camera.CameraOutput): void { 6069e41f4b71Sopenharmony_ci try { 6070e41f4b71Sopenharmony_ci captureSession.addOutput(cameraOutput); 6071e41f4b71Sopenharmony_ci } catch (error) { 6072e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 6073e41f4b71Sopenharmony_ci let err = error as BusinessError; 6074e41f4b71Sopenharmony_ci console.error(`The addOutput call failed. error code: ${err.code}`); 6075e41f4b71Sopenharmony_ci } 6076e41f4b71Sopenharmony_ci} 6077e41f4b71Sopenharmony_ci``` 6078e41f4b71Sopenharmony_ci 6079e41f4b71Sopenharmony_ci### removeOutput<sup>(deprecated)</sup> 6080e41f4b71Sopenharmony_ci 6081e41f4b71Sopenharmony_ciremoveOutput(cameraOutput: CameraOutput): void 6082e41f4b71Sopenharmony_ci 6083e41f4b71Sopenharmony_ciRemoves a [CameraOutput](#cameraoutput) instance from this session. 6084e41f4b71Sopenharmony_ci 6085e41f4b71Sopenharmony_ci> **NOTE** 6086e41f4b71Sopenharmony_ci> 6087e41f4b71Sopenharmony_ci>This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Session.removeOutput](#removeoutput11) instead. 6088e41f4b71Sopenharmony_ci 6089e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 6090e41f4b71Sopenharmony_ci 6091e41f4b71Sopenharmony_ci**Parameters** 6092e41f4b71Sopenharmony_ci 6093e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 6094e41f4b71Sopenharmony_ci| ------------- | ------------------------------- | ---- | ------------------------ | 6095e41f4b71Sopenharmony_ci| cameraOutput | [CameraOutput](#cameraoutput) | Yes | **CameraOutput** instance to remove.| 6096e41f4b71Sopenharmony_ci 6097e41f4b71Sopenharmony_ci**Error codes** 6098e41f4b71Sopenharmony_ci 6099e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 6100e41f4b71Sopenharmony_ci 6101e41f4b71Sopenharmony_ci| ID | Error Message | 6102e41f4b71Sopenharmony_ci| --------------- | --------------- | 6103e41f4b71Sopenharmony_ci| 7400101 | Parameter missing or parameter type incorrect. | 6104e41f4b71Sopenharmony_ci| 7400102 | Operation not allowed. | 6105e41f4b71Sopenharmony_ci 6106e41f4b71Sopenharmony_ci**Example** 6107e41f4b71Sopenharmony_ci 6108e41f4b71Sopenharmony_ci```ts 6109e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 6110e41f4b71Sopenharmony_ci 6111e41f4b71Sopenharmony_cifunction removeOutput(captureSession: camera.CaptureSession, previewOutput: camera.PreviewOutput): void { 6112e41f4b71Sopenharmony_ci try { 6113e41f4b71Sopenharmony_ci captureSession.removeOutput(previewOutput); 6114e41f4b71Sopenharmony_ci } catch (error) { 6115e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 6116e41f4b71Sopenharmony_ci let err = error as BusinessError; 6117e41f4b71Sopenharmony_ci console.error(`The removeOutput call failed. error code: ${err.code}`); 6118e41f4b71Sopenharmony_ci } 6119e41f4b71Sopenharmony_ci} 6120e41f4b71Sopenharmony_ci``` 6121e41f4b71Sopenharmony_ci 6122e41f4b71Sopenharmony_ci### start<sup>(deprecated)</sup> 6123e41f4b71Sopenharmony_ci 6124e41f4b71Sopenharmony_cistart(callback: AsyncCallback\<void\>): void 6125e41f4b71Sopenharmony_ci 6126e41f4b71Sopenharmony_ciStarts this session. This API uses an asynchronous callback to return the result. 6127e41f4b71Sopenharmony_ci 6128e41f4b71Sopenharmony_ci> **NOTE** 6129e41f4b71Sopenharmony_ci> 6130e41f4b71Sopenharmony_ci>This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Session.start](#start11) instead. 6131e41f4b71Sopenharmony_ci 6132e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 6133e41f4b71Sopenharmony_ci 6134e41f4b71Sopenharmony_ci**Parameters** 6135e41f4b71Sopenharmony_ci 6136e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 6137e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | -------------------- | 6138e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 6139e41f4b71Sopenharmony_ci 6140e41f4b71Sopenharmony_ci**Error codes** 6141e41f4b71Sopenharmony_ci 6142e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 6143e41f4b71Sopenharmony_ci 6144e41f4b71Sopenharmony_ci| ID | Error Message | 6145e41f4b71Sopenharmony_ci| --------------- | --------------- | 6146e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 6147e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 6148e41f4b71Sopenharmony_ci 6149e41f4b71Sopenharmony_ci**Example** 6150e41f4b71Sopenharmony_ci 6151e41f4b71Sopenharmony_ci```ts 6152e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 6153e41f4b71Sopenharmony_ci 6154e41f4b71Sopenharmony_cifunction startCaptureSession(captureSession: camera.CaptureSession): void { 6155e41f4b71Sopenharmony_ci captureSession.start((err: BusinessError) => { 6156e41f4b71Sopenharmony_ci if (err) { 6157e41f4b71Sopenharmony_ci console.error(`Failed to start the session, error code: ${err.code}.`); 6158e41f4b71Sopenharmony_ci return; 6159e41f4b71Sopenharmony_ci } 6160e41f4b71Sopenharmony_ci console.info('Callback invoked to indicate the session start success.'); 6161e41f4b71Sopenharmony_ci }); 6162e41f4b71Sopenharmony_ci} 6163e41f4b71Sopenharmony_ci``` 6164e41f4b71Sopenharmony_ci 6165e41f4b71Sopenharmony_ci### start<sup>(deprecated)</sup> 6166e41f4b71Sopenharmony_ci 6167e41f4b71Sopenharmony_cistart(): Promise\<void\> 6168e41f4b71Sopenharmony_ci 6169e41f4b71Sopenharmony_ciStarts this session. This API uses a promise to return the result. 6170e41f4b71Sopenharmony_ci 6171e41f4b71Sopenharmony_ci> **NOTE** 6172e41f4b71Sopenharmony_ci> 6173e41f4b71Sopenharmony_ci>This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Session.start](#start11-1) instead. 6174e41f4b71Sopenharmony_ci 6175e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 6176e41f4b71Sopenharmony_ci 6177e41f4b71Sopenharmony_ci**Return value** 6178e41f4b71Sopenharmony_ci 6179e41f4b71Sopenharmony_ci| Type | Description | 6180e41f4b71Sopenharmony_ci| -------------- | ------------------------ | 6181e41f4b71Sopenharmony_ci| Promise\<void\> | Promise that returns no value.| 6182e41f4b71Sopenharmony_ci 6183e41f4b71Sopenharmony_ci**Error codes** 6184e41f4b71Sopenharmony_ci 6185e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 6186e41f4b71Sopenharmony_ci 6187e41f4b71Sopenharmony_ci| ID | Error Message | 6188e41f4b71Sopenharmony_ci| --------------- | --------------- | 6189e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 6190e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 6191e41f4b71Sopenharmony_ci 6192e41f4b71Sopenharmony_ci**Example** 6193e41f4b71Sopenharmony_ci 6194e41f4b71Sopenharmony_ci```ts 6195e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 6196e41f4b71Sopenharmony_ci 6197e41f4b71Sopenharmony_cifunction startCaptureSession(captureSession: camera.CaptureSession): void { 6198e41f4b71Sopenharmony_ci captureSession.start().then(() => { 6199e41f4b71Sopenharmony_ci console.info('Promise returned to indicate the session start success.'); 6200e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 6201e41f4b71Sopenharmony_ci console.error(`Failed to start the session, error code: ${err.code}.`); 6202e41f4b71Sopenharmony_ci }); 6203e41f4b71Sopenharmony_ci} 6204e41f4b71Sopenharmony_ci``` 6205e41f4b71Sopenharmony_ci 6206e41f4b71Sopenharmony_ci### stop<sup>(deprecated)</sup> 6207e41f4b71Sopenharmony_ci 6208e41f4b71Sopenharmony_cistop(callback: AsyncCallback\<void\>): void 6209e41f4b71Sopenharmony_ci 6210e41f4b71Sopenharmony_ciStops this session. This API uses an asynchronous callback to return the result. 6211e41f4b71Sopenharmony_ci 6212e41f4b71Sopenharmony_ci> **NOTE** 6213e41f4b71Sopenharmony_ci> 6214e41f4b71Sopenharmony_ci>This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Session.stop](#stop11) instead. 6215e41f4b71Sopenharmony_ci 6216e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 6217e41f4b71Sopenharmony_ci 6218e41f4b71Sopenharmony_ci**Parameters** 6219e41f4b71Sopenharmony_ci 6220e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 6221e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ------------------- | 6222e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 6223e41f4b71Sopenharmony_ci 6224e41f4b71Sopenharmony_ci**Error codes** 6225e41f4b71Sopenharmony_ci 6226e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 6227e41f4b71Sopenharmony_ci 6228e41f4b71Sopenharmony_ci| ID | Error Message | 6229e41f4b71Sopenharmony_ci| --------------- | --------------- | 6230e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 6231e41f4b71Sopenharmony_ci 6232e41f4b71Sopenharmony_ci**Example** 6233e41f4b71Sopenharmony_ci 6234e41f4b71Sopenharmony_ci```ts 6235e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 6236e41f4b71Sopenharmony_ci 6237e41f4b71Sopenharmony_cifunction stopCaptureSession(captureSession: camera.CaptureSession): void { 6238e41f4b71Sopenharmony_ci captureSession.stop((err: BusinessError) => { 6239e41f4b71Sopenharmony_ci if (err) { 6240e41f4b71Sopenharmony_ci console.error(`Failed to stop the session, error code: ${err.code}.`); 6241e41f4b71Sopenharmony_ci return; 6242e41f4b71Sopenharmony_ci } 6243e41f4b71Sopenharmony_ci console.info('Callback invoked to indicate the session stop success.'); 6244e41f4b71Sopenharmony_ci }); 6245e41f4b71Sopenharmony_ci} 6246e41f4b71Sopenharmony_ci``` 6247e41f4b71Sopenharmony_ci 6248e41f4b71Sopenharmony_ci### stop<sup>(deprecated)</sup> 6249e41f4b71Sopenharmony_ci 6250e41f4b71Sopenharmony_cistop(): Promise\<void\> 6251e41f4b71Sopenharmony_ci 6252e41f4b71Sopenharmony_ciStops this session. This API uses a promise to return the result. 6253e41f4b71Sopenharmony_ci 6254e41f4b71Sopenharmony_ci> **NOTE** 6255e41f4b71Sopenharmony_ci> 6256e41f4b71Sopenharmony_ci>This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Session.stop](#stop11-1) instead. 6257e41f4b71Sopenharmony_ci 6258e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 6259e41f4b71Sopenharmony_ci 6260e41f4b71Sopenharmony_ci**Return value** 6261e41f4b71Sopenharmony_ci 6262e41f4b71Sopenharmony_ci| Type | Description | 6263e41f4b71Sopenharmony_ci| -------------- | ----------------------- | 6264e41f4b71Sopenharmony_ci| Promise\<void\> | Promise that returns no value.| 6265e41f4b71Sopenharmony_ci 6266e41f4b71Sopenharmony_ci**Error codes** 6267e41f4b71Sopenharmony_ci 6268e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 6269e41f4b71Sopenharmony_ci 6270e41f4b71Sopenharmony_ci| ID | Error Message | 6271e41f4b71Sopenharmony_ci| --------------- | --------------- | 6272e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 6273e41f4b71Sopenharmony_ci 6274e41f4b71Sopenharmony_ci**Example** 6275e41f4b71Sopenharmony_ci 6276e41f4b71Sopenharmony_ci```ts 6277e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 6278e41f4b71Sopenharmony_ci 6279e41f4b71Sopenharmony_cifunction stopCaptureSession(captureSession: camera.CaptureSession): void { 6280e41f4b71Sopenharmony_ci captureSession.stop().then(() => { 6281e41f4b71Sopenharmony_ci console.info('Promise returned to indicate the session stop success.'); 6282e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 6283e41f4b71Sopenharmony_ci console.error(`Failed to stop the session, error code: ${err.code}.`); 6284e41f4b71Sopenharmony_ci }); 6285e41f4b71Sopenharmony_ci} 6286e41f4b71Sopenharmony_ci``` 6287e41f4b71Sopenharmony_ci 6288e41f4b71Sopenharmony_ci### release<sup>(deprecated)</sup> 6289e41f4b71Sopenharmony_ci 6290e41f4b71Sopenharmony_cirelease(callback: AsyncCallback\<void\>): void 6291e41f4b71Sopenharmony_ci 6292e41f4b71Sopenharmony_ciReleases this session. This API uses an asynchronous callback to return the result. 6293e41f4b71Sopenharmony_ci 6294e41f4b71Sopenharmony_ci> **NOTE** 6295e41f4b71Sopenharmony_ci> 6296e41f4b71Sopenharmony_ci>This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Session.release](#release11-1) instead. 6297e41f4b71Sopenharmony_ci 6298e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 6299e41f4b71Sopenharmony_ci 6300e41f4b71Sopenharmony_ci**Parameters** 6301e41f4b71Sopenharmony_ci 6302e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 6303e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | -------------------- | 6304e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 6305e41f4b71Sopenharmony_ci 6306e41f4b71Sopenharmony_ci**Error codes** 6307e41f4b71Sopenharmony_ci 6308e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 6309e41f4b71Sopenharmony_ci 6310e41f4b71Sopenharmony_ci| ID | Error Message | 6311e41f4b71Sopenharmony_ci| --------------- | --------------- | 6312e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 6313e41f4b71Sopenharmony_ci 6314e41f4b71Sopenharmony_ci**Example** 6315e41f4b71Sopenharmony_ci 6316e41f4b71Sopenharmony_ci```ts 6317e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 6318e41f4b71Sopenharmony_ci 6319e41f4b71Sopenharmony_cifunction releaseCaptureSession(captureSession: camera.CaptureSession): void { 6320e41f4b71Sopenharmony_ci captureSession.release((err: BusinessError) => { 6321e41f4b71Sopenharmony_ci if (err) { 6322e41f4b71Sopenharmony_ci console.error(`Failed to release the CaptureSession instance, error code: ${err.code}.`); 6323e41f4b71Sopenharmony_ci return; 6324e41f4b71Sopenharmony_ci } 6325e41f4b71Sopenharmony_ci console.info('Callback invoked to indicate that the CaptureSession instance is released successfully.'); 6326e41f4b71Sopenharmony_ci }); 6327e41f4b71Sopenharmony_ci} 6328e41f4b71Sopenharmony_ci``` 6329e41f4b71Sopenharmony_ci 6330e41f4b71Sopenharmony_ci### release<sup>(deprecated)</sup> 6331e41f4b71Sopenharmony_ci 6332e41f4b71Sopenharmony_cirelease(): Promise\<void\> 6333e41f4b71Sopenharmony_ci 6334e41f4b71Sopenharmony_ciReleases this session. This API uses a promise to return the result. 6335e41f4b71Sopenharmony_ci 6336e41f4b71Sopenharmony_ci> **NOTE** 6337e41f4b71Sopenharmony_ci> 6338e41f4b71Sopenharmony_ci>This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Session.release](#release11-2) instead. 6339e41f4b71Sopenharmony_ci 6340e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 6341e41f4b71Sopenharmony_ci 6342e41f4b71Sopenharmony_ci**Return value** 6343e41f4b71Sopenharmony_ci 6344e41f4b71Sopenharmony_ci| Type | Description | 6345e41f4b71Sopenharmony_ci| -------------- | ------------------------ | 6346e41f4b71Sopenharmony_ci| Promise\<void\> | Promise that returns no value.| 6347e41f4b71Sopenharmony_ci 6348e41f4b71Sopenharmony_ci**Error codes** 6349e41f4b71Sopenharmony_ci 6350e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 6351e41f4b71Sopenharmony_ci 6352e41f4b71Sopenharmony_ci| ID | Error Message | 6353e41f4b71Sopenharmony_ci| --------------- | --------------- | 6354e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 6355e41f4b71Sopenharmony_ci 6356e41f4b71Sopenharmony_ci**Example** 6357e41f4b71Sopenharmony_ci 6358e41f4b71Sopenharmony_ci```ts 6359e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 6360e41f4b71Sopenharmony_ci 6361e41f4b71Sopenharmony_cifunction releaseCaptureSession(captureSession: camera.CaptureSession): void { 6362e41f4b71Sopenharmony_ci captureSession.release().then(() => { 6363e41f4b71Sopenharmony_ci console.info('Promise returned to indicate that the CaptureSession instance is released successfully.'); 6364e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 6365e41f4b71Sopenharmony_ci console.error(`Failed to release the CaptureSession instance, error code: ${err.code}.`); 6366e41f4b71Sopenharmony_ci }); 6367e41f4b71Sopenharmony_ci} 6368e41f4b71Sopenharmony_ci``` 6369e41f4b71Sopenharmony_ci 6370e41f4b71Sopenharmony_ci### hasFlash<sup>(deprecated)</sup> 6371e41f4b71Sopenharmony_ci 6372e41f4b71Sopenharmony_cihasFlash(): boolean 6373e41f4b71Sopenharmony_ci 6374e41f4b71Sopenharmony_ciChecks whether the camera device has flash. 6375e41f4b71Sopenharmony_ci 6376e41f4b71Sopenharmony_ci> **NOTE** 6377e41f4b71Sopenharmony_ci> 6378e41f4b71Sopenharmony_ci>This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Flash.hasFlash](#hasflash11) instead. 6379e41f4b71Sopenharmony_ci 6380e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 6381e41f4b71Sopenharmony_ci 6382e41f4b71Sopenharmony_ci**Return value** 6383e41f4b71Sopenharmony_ci 6384e41f4b71Sopenharmony_ci| Type | Description | 6385e41f4b71Sopenharmony_ci| ---------- | ----------------------------- | 6386e41f4b71Sopenharmony_ci| boolean | **true**: The camera device has flash.<br>**false**: The camera device does not have flash. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 6387e41f4b71Sopenharmony_ci 6388e41f4b71Sopenharmony_ci**Error codes** 6389e41f4b71Sopenharmony_ci 6390e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 6391e41f4b71Sopenharmony_ci 6392e41f4b71Sopenharmony_ci| ID | Error Message | 6393e41f4b71Sopenharmony_ci| --------------- | --------------- | 6394e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 6395e41f4b71Sopenharmony_ci 6396e41f4b71Sopenharmony_ci**Example** 6397e41f4b71Sopenharmony_ci 6398e41f4b71Sopenharmony_ci```ts 6399e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 6400e41f4b71Sopenharmony_ci 6401e41f4b71Sopenharmony_cifunction hasFlash(captureSession: camera.CaptureSession): boolean { 6402e41f4b71Sopenharmony_ci let status: boolean = false; 6403e41f4b71Sopenharmony_ci try { 6404e41f4b71Sopenharmony_ci status = captureSession.hasFlash(); 6405e41f4b71Sopenharmony_ci } catch (error) { 6406e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 6407e41f4b71Sopenharmony_ci let err = error as BusinessError; 6408e41f4b71Sopenharmony_ci console.error(`The hasFlash call failed. error code: ${err.code}`); 6409e41f4b71Sopenharmony_ci } 6410e41f4b71Sopenharmony_ci return status; 6411e41f4b71Sopenharmony_ci} 6412e41f4b71Sopenharmony_ci``` 6413e41f4b71Sopenharmony_ci 6414e41f4b71Sopenharmony_ci### isFlashModeSupported<sup>(deprecated)</sup> 6415e41f4b71Sopenharmony_ci 6416e41f4b71Sopenharmony_ciisFlashModeSupported(flashMode: FlashMode): boolean 6417e41f4b71Sopenharmony_ci 6418e41f4b71Sopenharmony_ciChecks whether a flash mode is supported. 6419e41f4b71Sopenharmony_ci 6420e41f4b71Sopenharmony_ci> **NOTE** 6421e41f4b71Sopenharmony_ci> 6422e41f4b71Sopenharmony_ci>This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Flash.isFlashModeSupported](#isflashmodesupported11) instead. 6423e41f4b71Sopenharmony_ci 6424e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 6425e41f4b71Sopenharmony_ci 6426e41f4b71Sopenharmony_ci**Parameters** 6427e41f4b71Sopenharmony_ci 6428e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 6429e41f4b71Sopenharmony_ci| --------- | ----------------------- | ---- | --------------------------------- | 6430e41f4b71Sopenharmony_ci| flashMode | [FlashMode](#flashmode) | Yes | Flash mode. | 6431e41f4b71Sopenharmony_ci 6432e41f4b71Sopenharmony_ci**Return value** 6433e41f4b71Sopenharmony_ci 6434e41f4b71Sopenharmony_ci| Type | Description | 6435e41f4b71Sopenharmony_ci| ---------- | ----------------------------- | 6436e41f4b71Sopenharmony_ci| boolean | **true**: The flash mode is supported.<br>**false**: The flash mode is not supported. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 6437e41f4b71Sopenharmony_ci 6438e41f4b71Sopenharmony_ci**Error codes** 6439e41f4b71Sopenharmony_ci 6440e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 6441e41f4b71Sopenharmony_ci 6442e41f4b71Sopenharmony_ci| ID | Error Message | 6443e41f4b71Sopenharmony_ci| --------------- | --------------- | 6444e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 6445e41f4b71Sopenharmony_ci 6446e41f4b71Sopenharmony_ci**Example** 6447e41f4b71Sopenharmony_ci 6448e41f4b71Sopenharmony_ci```ts 6449e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 6450e41f4b71Sopenharmony_ci 6451e41f4b71Sopenharmony_cifunction isFlashModeSupported(captureSession: camera.CaptureSession): boolean { 6452e41f4b71Sopenharmony_ci let status: boolean = false; 6453e41f4b71Sopenharmony_ci try { 6454e41f4b71Sopenharmony_ci status = captureSession.isFlashModeSupported(camera.FlashMode.FLASH_MODE_AUTO); 6455e41f4b71Sopenharmony_ci } catch (error) { 6456e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 6457e41f4b71Sopenharmony_ci let err = error as BusinessError; 6458e41f4b71Sopenharmony_ci console.error(`The isFlashModeSupported call failed. error code: ${err.code}`); 6459e41f4b71Sopenharmony_ci } 6460e41f4b71Sopenharmony_ci return status; 6461e41f4b71Sopenharmony_ci} 6462e41f4b71Sopenharmony_ci``` 6463e41f4b71Sopenharmony_ci 6464e41f4b71Sopenharmony_ci### setFlashMode<sup>(deprecated)</sup> 6465e41f4b71Sopenharmony_ci 6466e41f4b71Sopenharmony_cisetFlashMode(flashMode: FlashMode): void 6467e41f4b71Sopenharmony_ci 6468e41f4b71Sopenharmony_ciSets a flash mode. 6469e41f4b71Sopenharmony_ci 6470e41f4b71Sopenharmony_ciBefore the setting, do the following checks: 6471e41f4b71Sopenharmony_ci 6472e41f4b71Sopenharmony_ci1. Use [hasFlash](#hasflashdeprecated) to check whether the camera device has flash. 6473e41f4b71Sopenharmony_ci2. Use [isFlashModeSupported](#isflashmodesupporteddeprecated) to check whether the camera device supports the flash mode. 6474e41f4b71Sopenharmony_ci 6475e41f4b71Sopenharmony_ci> **NOTE** 6476e41f4b71Sopenharmony_ci> 6477e41f4b71Sopenharmony_ci>This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Flash.setFlashMode](#setflashmode11) instead. 6478e41f4b71Sopenharmony_ci 6479e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 6480e41f4b71Sopenharmony_ci 6481e41f4b71Sopenharmony_ci**Parameters** 6482e41f4b71Sopenharmony_ci 6483e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 6484e41f4b71Sopenharmony_ci| --------- | ----------------------- | ---- | -------------------- | 6485e41f4b71Sopenharmony_ci| flashMode | [FlashMode](#flashmode) | Yes | Flash mode. | 6486e41f4b71Sopenharmony_ci 6487e41f4b71Sopenharmony_ci**Error codes** 6488e41f4b71Sopenharmony_ci 6489e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 6490e41f4b71Sopenharmony_ci 6491e41f4b71Sopenharmony_ci| ID | Error Message | 6492e41f4b71Sopenharmony_ci| --------------- | --------------- | 6493e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 6494e41f4b71Sopenharmony_ci 6495e41f4b71Sopenharmony_ci**Example** 6496e41f4b71Sopenharmony_ci 6497e41f4b71Sopenharmony_ci```ts 6498e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 6499e41f4b71Sopenharmony_ci 6500e41f4b71Sopenharmony_cifunction setFlashMode(captureSession: camera.CaptureSession): void { 6501e41f4b71Sopenharmony_ci try { 6502e41f4b71Sopenharmony_ci captureSession.setFlashMode(camera.FlashMode.FLASH_MODE_AUTO); 6503e41f4b71Sopenharmony_ci } catch (error) { 6504e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 6505e41f4b71Sopenharmony_ci let err = error as BusinessError; 6506e41f4b71Sopenharmony_ci console.error(`The setFlashMode call failed. error code: ${err.code}`); 6507e41f4b71Sopenharmony_ci } 6508e41f4b71Sopenharmony_ci} 6509e41f4b71Sopenharmony_ci``` 6510e41f4b71Sopenharmony_ci 6511e41f4b71Sopenharmony_ci### getFlashMode<sup>(deprecated)</sup> 6512e41f4b71Sopenharmony_ci 6513e41f4b71Sopenharmony_cigetFlashMode(): FlashMode 6514e41f4b71Sopenharmony_ci 6515e41f4b71Sopenharmony_ciObtains the flash mode in use. 6516e41f4b71Sopenharmony_ci 6517e41f4b71Sopenharmony_ci> **NOTE** 6518e41f4b71Sopenharmony_ci> 6519e41f4b71Sopenharmony_ci>This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Flash.getFlashMode](#getflashmode11) instead. 6520e41f4b71Sopenharmony_ci 6521e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 6522e41f4b71Sopenharmony_ci 6523e41f4b71Sopenharmony_ci**Return value** 6524e41f4b71Sopenharmony_ci 6525e41f4b71Sopenharmony_ci| Type | Description | 6526e41f4b71Sopenharmony_ci| ---------- | ----------------------------- | 6527e41f4b71Sopenharmony_ci| [FlashMode](#flashmode) | Flash mode obtained. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 6528e41f4b71Sopenharmony_ci 6529e41f4b71Sopenharmony_ci**Error codes** 6530e41f4b71Sopenharmony_ci 6531e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 6532e41f4b71Sopenharmony_ci 6533e41f4b71Sopenharmony_ci| ID | Error Message | 6534e41f4b71Sopenharmony_ci| --------------- | --------------- | 6535e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 6536e41f4b71Sopenharmony_ci 6537e41f4b71Sopenharmony_ci**Example** 6538e41f4b71Sopenharmony_ci 6539e41f4b71Sopenharmony_ci```ts 6540e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 6541e41f4b71Sopenharmony_ci 6542e41f4b71Sopenharmony_cifunction getFlashMode(captureSession: camera.CaptureSession): camera.FlashMode | undefined { 6543e41f4b71Sopenharmony_ci let flashMode: camera.FlashMode | undefined = undefined; 6544e41f4b71Sopenharmony_ci try { 6545e41f4b71Sopenharmony_ci flashMode = captureSession.getFlashMode(); 6546e41f4b71Sopenharmony_ci } catch (error) { 6547e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 6548e41f4b71Sopenharmony_ci let err = error as BusinessError; 6549e41f4b71Sopenharmony_ci console.error(`The getFlashMode call failed.error code: ${err.code}`); 6550e41f4b71Sopenharmony_ci } 6551e41f4b71Sopenharmony_ci return flashMode; 6552e41f4b71Sopenharmony_ci} 6553e41f4b71Sopenharmony_ci``` 6554e41f4b71Sopenharmony_ci 6555e41f4b71Sopenharmony_ci### isExposureModeSupported<sup>(deprecated)</sup> 6556e41f4b71Sopenharmony_ci 6557e41f4b71Sopenharmony_ciisExposureModeSupported(aeMode: ExposureMode): boolean 6558e41f4b71Sopenharmony_ci 6559e41f4b71Sopenharmony_ciChecks whether an exposure mode is supported. 6560e41f4b71Sopenharmony_ci 6561e41f4b71Sopenharmony_ci> **NOTE** 6562e41f4b71Sopenharmony_ci> 6563e41f4b71Sopenharmony_ci>This API is supported since API version 10 and deprecated since API version 11. You are advised to use [AutoExposure.isExposureModeSupported](#isexposuremodesupported11) instead. 6564e41f4b71Sopenharmony_ci 6565e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 6566e41f4b71Sopenharmony_ci 6567e41f4b71Sopenharmony_ci**Parameters** 6568e41f4b71Sopenharmony_ci 6569e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 6570e41f4b71Sopenharmony_ci| -------- | -------------------------------| ---- | ----------------------------- | 6571e41f4b71Sopenharmony_ci| aeMode | [ExposureMode](#exposuremode) | Yes | Exposure mode. | 6572e41f4b71Sopenharmony_ci 6573e41f4b71Sopenharmony_ci**Return value** 6574e41f4b71Sopenharmony_ci 6575e41f4b71Sopenharmony_ci| Type | Description | 6576e41f4b71Sopenharmony_ci| ---------- | ----------------------------- | 6577e41f4b71Sopenharmony_ci| boolean | **true**: The exposure mode is supported.<br>**false**: The exposure mode is not supported. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 6578e41f4b71Sopenharmony_ci 6579e41f4b71Sopenharmony_ci**Error codes** 6580e41f4b71Sopenharmony_ci 6581e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 6582e41f4b71Sopenharmony_ci 6583e41f4b71Sopenharmony_ci| ID | Error Message | 6584e41f4b71Sopenharmony_ci| --------------- | --------------- | 6585e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 6586e41f4b71Sopenharmony_ci 6587e41f4b71Sopenharmony_ci**Example** 6588e41f4b71Sopenharmony_ci 6589e41f4b71Sopenharmony_ci```ts 6590e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 6591e41f4b71Sopenharmony_ci 6592e41f4b71Sopenharmony_cifunction isExposureModeSupported(captureSession: camera.CaptureSession): boolean { 6593e41f4b71Sopenharmony_ci let isSupported: boolean = false; 6594e41f4b71Sopenharmony_ci try { 6595e41f4b71Sopenharmony_ci isSupported = captureSession.isExposureModeSupported(camera.ExposureMode.EXPOSURE_MODE_LOCKED); 6596e41f4b71Sopenharmony_ci } catch (error) { 6597e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 6598e41f4b71Sopenharmony_ci let err = error as BusinessError; 6599e41f4b71Sopenharmony_ci console.error(`The isExposureModeSupported call failed. error code: ${err.code}`); 6600e41f4b71Sopenharmony_ci } 6601e41f4b71Sopenharmony_ci return isSupported; 6602e41f4b71Sopenharmony_ci} 6603e41f4b71Sopenharmony_ci``` 6604e41f4b71Sopenharmony_ci 6605e41f4b71Sopenharmony_ci### getExposureMode<sup>(deprecated)</sup> 6606e41f4b71Sopenharmony_ci 6607e41f4b71Sopenharmony_cigetExposureMode(): ExposureMode 6608e41f4b71Sopenharmony_ci 6609e41f4b71Sopenharmony_ciObtains the exposure mode in use. 6610e41f4b71Sopenharmony_ci 6611e41f4b71Sopenharmony_ci> **NOTE** 6612e41f4b71Sopenharmony_ci> 6613e41f4b71Sopenharmony_ci>This API is supported since API version 10 and deprecated since API version 11. You are advised to use [AutoExposure.getExposureMode](#getexposuremode11) instead. 6614e41f4b71Sopenharmony_ci 6615e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 6616e41f4b71Sopenharmony_ci 6617e41f4b71Sopenharmony_ci**Return value** 6618e41f4b71Sopenharmony_ci 6619e41f4b71Sopenharmony_ci| Type | Description | 6620e41f4b71Sopenharmony_ci| ---------- | ----------------------------- | 6621e41f4b71Sopenharmony_ci| [ExposureMode](#exposuremode) | Exposure mode obtained. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 6622e41f4b71Sopenharmony_ci 6623e41f4b71Sopenharmony_ci**Error codes** 6624e41f4b71Sopenharmony_ci 6625e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 6626e41f4b71Sopenharmony_ci 6627e41f4b71Sopenharmony_ci| ID | Error Message | 6628e41f4b71Sopenharmony_ci| --------------- | --------------- | 6629e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 6630e41f4b71Sopenharmony_ci 6631e41f4b71Sopenharmony_ci**Example** 6632e41f4b71Sopenharmony_ci 6633e41f4b71Sopenharmony_ci```ts 6634e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 6635e41f4b71Sopenharmony_ci 6636e41f4b71Sopenharmony_cifunction getExposureMode(captureSession: camera.CaptureSession): camera.ExposureMode | undefined { 6637e41f4b71Sopenharmony_ci let exposureMode: camera.ExposureMode | undefined = undefined; 6638e41f4b71Sopenharmony_ci try { 6639e41f4b71Sopenharmony_ci exposureMode = captureSession.getExposureMode(); 6640e41f4b71Sopenharmony_ci } catch (error) { 6641e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 6642e41f4b71Sopenharmony_ci let err = error as BusinessError; 6643e41f4b71Sopenharmony_ci console.error(`The getExposureMode call failed. error code: ${err.code}`); 6644e41f4b71Sopenharmony_ci } 6645e41f4b71Sopenharmony_ci return exposureMode; 6646e41f4b71Sopenharmony_ci} 6647e41f4b71Sopenharmony_ci``` 6648e41f4b71Sopenharmony_ci 6649e41f4b71Sopenharmony_ci### setExposureMode<sup>(deprecated)</sup> 6650e41f4b71Sopenharmony_ci 6651e41f4b71Sopenharmony_cisetExposureMode(aeMode: ExposureMode): void 6652e41f4b71Sopenharmony_ci 6653e41f4b71Sopenharmony_ciSets an exposure mode. Before the setting, call [isExposureModeSupported](#isexposuremodesupporteddeprecated) to check whether the target exposure mode is supported. 6654e41f4b71Sopenharmony_ci 6655e41f4b71Sopenharmony_ci> **NOTE** 6656e41f4b71Sopenharmony_ci> 6657e41f4b71Sopenharmony_ci>This API is supported since API version 10 and deprecated since API version 11. You are advised to use [AutoExposure.setExposureMode](#setexposuremode11) instead. 6658e41f4b71Sopenharmony_ci 6659e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 6660e41f4b71Sopenharmony_ci 6661e41f4b71Sopenharmony_ci**Parameters** 6662e41f4b71Sopenharmony_ci 6663e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 6664e41f4b71Sopenharmony_ci| -------- | -------------------------------| ---- | ----------------------- | 6665e41f4b71Sopenharmony_ci| aeMode | [ExposureMode](#exposuremode) | Yes | Exposure mode. | 6666e41f4b71Sopenharmony_ci 6667e41f4b71Sopenharmony_ci**Error codes** 6668e41f4b71Sopenharmony_ci 6669e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 6670e41f4b71Sopenharmony_ci 6671e41f4b71Sopenharmony_ci| ID | Error Message | 6672e41f4b71Sopenharmony_ci| --------------- | --------------- | 6673e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 6674e41f4b71Sopenharmony_ci 6675e41f4b71Sopenharmony_ci**Example** 6676e41f4b71Sopenharmony_ci 6677e41f4b71Sopenharmony_ci```ts 6678e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 6679e41f4b71Sopenharmony_ci 6680e41f4b71Sopenharmony_cifunction setExposureMode(captureSession: camera.CaptureSession): void { 6681e41f4b71Sopenharmony_ci try { 6682e41f4b71Sopenharmony_ci captureSession.setExposureMode(camera.ExposureMode.EXPOSURE_MODE_LOCKED); 6683e41f4b71Sopenharmony_ci } catch (error) { 6684e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 6685e41f4b71Sopenharmony_ci let err = error as BusinessError; 6686e41f4b71Sopenharmony_ci console.error(`The setExposureMode call failed. error code: ${err.code}`); 6687e41f4b71Sopenharmony_ci } 6688e41f4b71Sopenharmony_ci} 6689e41f4b71Sopenharmony_ci``` 6690e41f4b71Sopenharmony_ci 6691e41f4b71Sopenharmony_ci### getMeteringPoint<sup>(deprecated)</sup> 6692e41f4b71Sopenharmony_ci 6693e41f4b71Sopenharmony_cigetMeteringPoint(): Point 6694e41f4b71Sopenharmony_ci 6695e41f4b71Sopenharmony_ciObtains the metering point of the camera device. 6696e41f4b71Sopenharmony_ci 6697e41f4b71Sopenharmony_ci> **NOTE** 6698e41f4b71Sopenharmony_ci> 6699e41f4b71Sopenharmony_ci>This API is supported since API version 10 and deprecated since API version 11. You are advised to use [AutoExposure.getMeteringPoint](#getmeteringpoint11) instead. 6700e41f4b71Sopenharmony_ci 6701e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 6702e41f4b71Sopenharmony_ci 6703e41f4b71Sopenharmony_ci**Return value** 6704e41f4b71Sopenharmony_ci 6705e41f4b71Sopenharmony_ci| Type | Description | 6706e41f4b71Sopenharmony_ci| ---------- | ----------------------------- | 6707e41f4b71Sopenharmony_ci| [Point](#point) | Metering point obtained. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 6708e41f4b71Sopenharmony_ci 6709e41f4b71Sopenharmony_ci**Error codes** 6710e41f4b71Sopenharmony_ci 6711e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 6712e41f4b71Sopenharmony_ci 6713e41f4b71Sopenharmony_ci| ID | Error Message | 6714e41f4b71Sopenharmony_ci| --------------- | --------------- | 6715e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 6716e41f4b71Sopenharmony_ci 6717e41f4b71Sopenharmony_ci**Example** 6718e41f4b71Sopenharmony_ci 6719e41f4b71Sopenharmony_ci```ts 6720e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 6721e41f4b71Sopenharmony_ci 6722e41f4b71Sopenharmony_cifunction getMeteringPoint(captureSession: camera.CaptureSession): camera.Point | undefined { 6723e41f4b71Sopenharmony_ci let exposurePoint: camera.Point | undefined = undefined; 6724e41f4b71Sopenharmony_ci try { 6725e41f4b71Sopenharmony_ci exposurePoint = captureSession.getMeteringPoint(); 6726e41f4b71Sopenharmony_ci } catch (error) { 6727e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 6728e41f4b71Sopenharmony_ci let err = error as BusinessError; 6729e41f4b71Sopenharmony_ci console.error(`The getMeteringPoint call failed. error code: ${err.code}`); 6730e41f4b71Sopenharmony_ci } 6731e41f4b71Sopenharmony_ci return exposurePoint; 6732e41f4b71Sopenharmony_ci} 6733e41f4b71Sopenharmony_ci``` 6734e41f4b71Sopenharmony_ci 6735e41f4b71Sopenharmony_ci### setMeteringPoint<sup>(deprecated)</sup> 6736e41f4b71Sopenharmony_ci 6737e41f4b71Sopenharmony_cisetMeteringPoint(point: Point): void 6738e41f4b71Sopenharmony_ci 6739e41f4b71Sopenharmony_ciSets the metering point, which is the center point of the metering rectangle. 6740e41f4b71Sopenharmony_ci 6741e41f4b71Sopenharmony_ciThe metering point must be in the coordinate system (0-1), where the upper left corner is {0, 0} and the lower right corner is {1, 1}. 6742e41f4b71Sopenharmony_ci 6743e41f4b71Sopenharmony_ciThe coordinate system is based on the horizontal device direction with the device's charging port on the right. If the layout of the preview screen of an application is based on the vertical direction with the charging port on the lower side, the layout width and height are {w, h}, and the touch point is {x, y}, then the coordinate point after conversion is {y/h, 1-x/w}. 6744e41f4b71Sopenharmony_ci 6745e41f4b71Sopenharmony_ci> **NOTE** 6746e41f4b71Sopenharmony_ci> 6747e41f4b71Sopenharmony_ci>This API is supported since API version 10 and deprecated since API version 11. You are advised to use [AutoExposure.setMeteringPoint](#setmeteringpoint11) instead. 6748e41f4b71Sopenharmony_ci 6749e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 6750e41f4b71Sopenharmony_ci 6751e41f4b71Sopenharmony_ci**Parameters** 6752e41f4b71Sopenharmony_ci 6753e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 6754e41f4b71Sopenharmony_ci| ------------- | -------------------------------| ---- | ------------------- | 6755e41f4b71Sopenharmony_ci| point | [Point](#point) | Yes | Metering point. The value range of x and y must be within [0,1]. If a value less than 0 is passed, the value **0** is used. If a value greater than **1** is passed, the value **1** is used. | 6756e41f4b71Sopenharmony_ci 6757e41f4b71Sopenharmony_ci**Error codes** 6758e41f4b71Sopenharmony_ci 6759e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 6760e41f4b71Sopenharmony_ci 6761e41f4b71Sopenharmony_ci| ID | Error Message | 6762e41f4b71Sopenharmony_ci| --------------- | --------------- | 6763e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 6764e41f4b71Sopenharmony_ci 6765e41f4b71Sopenharmony_ci**Example** 6766e41f4b71Sopenharmony_ci 6767e41f4b71Sopenharmony_ci```ts 6768e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 6769e41f4b71Sopenharmony_ci 6770e41f4b71Sopenharmony_cifunction setMeteringPoint(captureSession: camera.CaptureSession): void { 6771e41f4b71Sopenharmony_ci const point: camera.Point = {x: 1, y: 1}; 6772e41f4b71Sopenharmony_ci try { 6773e41f4b71Sopenharmony_ci captureSession.setMeteringPoint(point); 6774e41f4b71Sopenharmony_ci } catch (error) { 6775e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 6776e41f4b71Sopenharmony_ci let err = error as BusinessError; 6777e41f4b71Sopenharmony_ci console.error(`The setMeteringPoint call failed. error code: ${err.code}`); 6778e41f4b71Sopenharmony_ci } 6779e41f4b71Sopenharmony_ci} 6780e41f4b71Sopenharmony_ci``` 6781e41f4b71Sopenharmony_ci 6782e41f4b71Sopenharmony_ci### getExposureBiasRange<sup>(deprecated)</sup> 6783e41f4b71Sopenharmony_ci 6784e41f4b71Sopenharmony_cigetExposureBiasRange(): Array\<number\> 6785e41f4b71Sopenharmony_ci 6786e41f4b71Sopenharmony_ciObtains the exposure compensation values of the camera device. 6787e41f4b71Sopenharmony_ci 6788e41f4b71Sopenharmony_ci> **NOTE** 6789e41f4b71Sopenharmony_ci> 6790e41f4b71Sopenharmony_ci>This API is supported since API version 10 and deprecated since API version 11. You are advised to use [AutoExposure.getExposureBiasRange](#getexposurebiasrange11) instead. 6791e41f4b71Sopenharmony_ci 6792e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 6793e41f4b71Sopenharmony_ci 6794e41f4b71Sopenharmony_ci**Return value** 6795e41f4b71Sopenharmony_ci 6796e41f4b71Sopenharmony_ci| Type | Description | 6797e41f4b71Sopenharmony_ci| ---------- | ----------------------------- | 6798e41f4b71Sopenharmony_ci| Array\<number\> | Array of compensation values. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 6799e41f4b71Sopenharmony_ci 6800e41f4b71Sopenharmony_ci**Error codes** 6801e41f4b71Sopenharmony_ci 6802e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 6803e41f4b71Sopenharmony_ci 6804e41f4b71Sopenharmony_ci| ID | Error Message | 6805e41f4b71Sopenharmony_ci| --------------- | --------------- | 6806e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 6807e41f4b71Sopenharmony_ci 6808e41f4b71Sopenharmony_ci**Example** 6809e41f4b71Sopenharmony_ci 6810e41f4b71Sopenharmony_ci```ts 6811e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 6812e41f4b71Sopenharmony_ci 6813e41f4b71Sopenharmony_cifunction getExposureBiasRange(captureSession: camera.CaptureSession): Array<number> { 6814e41f4b71Sopenharmony_ci let biasRangeArray: Array<number> = []; 6815e41f4b71Sopenharmony_ci try { 6816e41f4b71Sopenharmony_ci biasRangeArray = captureSession.getExposureBiasRange(); 6817e41f4b71Sopenharmony_ci } catch (error) { 6818e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 6819e41f4b71Sopenharmony_ci let err = error as BusinessError; 6820e41f4b71Sopenharmony_ci console.error(`The getExposureBiasRange call failed. error code: ${err.code}`); 6821e41f4b71Sopenharmony_ci } 6822e41f4b71Sopenharmony_ci return biasRangeArray; 6823e41f4b71Sopenharmony_ci} 6824e41f4b71Sopenharmony_ci``` 6825e41f4b71Sopenharmony_ci 6826e41f4b71Sopenharmony_ci### setExposureBias<sup>(deprecated)</sup> 6827e41f4b71Sopenharmony_ci 6828e41f4b71Sopenharmony_cisetExposureBias(exposureBias: number): void 6829e41f4b71Sopenharmony_ci 6830e41f4b71Sopenharmony_ciSets an exposure compensation value (EV). 6831e41f4b71Sopenharmony_ci 6832e41f4b71Sopenharmony_ciBefore the setting, you are advised to use [getExposureBiasRange](#getexposurebiasrangedeprecated) to obtain the supported values. 6833e41f4b71Sopenharmony_ci 6834e41f4b71Sopenharmony_ci> **NOTE** 6835e41f4b71Sopenharmony_ci> 6836e41f4b71Sopenharmony_ci>This API is supported since API version 10 and deprecated since API version 11. You are advised to use [AutoExposure.setExposureBias](#setexposurebias11) instead. 6837e41f4b71Sopenharmony_ci 6838e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 6839e41f4b71Sopenharmony_ci 6840e41f4b71Sopenharmony_ci**Parameters** 6841e41f4b71Sopenharmony_ci 6842e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 6843e41f4b71Sopenharmony_ci| -------- | -------------------------------|-----|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| 6844e41f4b71Sopenharmony_ci| exposureBias | number | Yes | EV. The supported EV range can be obtained by calling [getExposureBiasRange](#getexposurebiasrange11). If the value passed is not within the supported range, the nearest critical point is used. There is a step for EV. For example, if the step is 0.5 and this parameter is set to 1.2, the EV that takes effect is 1.0. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 6845e41f4b71Sopenharmony_ci 6846e41f4b71Sopenharmony_ci**Error codes** 6847e41f4b71Sopenharmony_ci 6848e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 6849e41f4b71Sopenharmony_ci 6850e41f4b71Sopenharmony_ci| ID | Error Message | 6851e41f4b71Sopenharmony_ci| --------------- | --------------- | 6852e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 6853e41f4b71Sopenharmony_ci 6854e41f4b71Sopenharmony_ci**Example** 6855e41f4b71Sopenharmony_ci 6856e41f4b71Sopenharmony_ci```ts 6857e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 6858e41f4b71Sopenharmony_ci 6859e41f4b71Sopenharmony_cifunction setExposureBias(captureSession: camera.CaptureSession, biasRangeArray: Array<number>): void { 6860e41f4b71Sopenharmony_ci if (biasRangeArray && biasRangeArray.length > 0) { 6861e41f4b71Sopenharmony_ci let exposureBias = biasRangeArray[0]; 6862e41f4b71Sopenharmony_ci try { 6863e41f4b71Sopenharmony_ci captureSession.setExposureBias(exposureBias); 6864e41f4b71Sopenharmony_ci } catch (error) { 6865e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 6866e41f4b71Sopenharmony_ci let err = error as BusinessError; 6867e41f4b71Sopenharmony_ci console.error(`The setExposureBias call failed. error code: ${err.code}`); 6868e41f4b71Sopenharmony_ci } 6869e41f4b71Sopenharmony_ci } 6870e41f4b71Sopenharmony_ci} 6871e41f4b71Sopenharmony_ci``` 6872e41f4b71Sopenharmony_ci 6873e41f4b71Sopenharmony_ci### getExposureValue<sup>(deprecated)</sup> 6874e41f4b71Sopenharmony_ci 6875e41f4b71Sopenharmony_cigetExposureValue(): number 6876e41f4b71Sopenharmony_ci 6877e41f4b71Sopenharmony_ciObtains the exposure value in use. 6878e41f4b71Sopenharmony_ci 6879e41f4b71Sopenharmony_ci> **NOTE** 6880e41f4b71Sopenharmony_ci> 6881e41f4b71Sopenharmony_ci>This API is supported since API version 10 and deprecated since API version 11. You are advised to use [AutoExposure.getExposureValue](#getexposurevalue11) instead. 6882e41f4b71Sopenharmony_ci 6883e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 6884e41f4b71Sopenharmony_ci 6885e41f4b71Sopenharmony_ci**Return value** 6886e41f4b71Sopenharmony_ci 6887e41f4b71Sopenharmony_ci| Type | Description | 6888e41f4b71Sopenharmony_ci| ---------- | ----------------------------- | 6889e41f4b71Sopenharmony_ci| number | Exposure value obtained. There is a step for EV. For example, if the step is 0.5 and this parameter is set to 1.2, the EV that takes effect is 1.0. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 6890e41f4b71Sopenharmony_ci 6891e41f4b71Sopenharmony_ci**Error codes** 6892e41f4b71Sopenharmony_ci 6893e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 6894e41f4b71Sopenharmony_ci 6895e41f4b71Sopenharmony_ci| ID | Error Message | 6896e41f4b71Sopenharmony_ci| --------------- | --------------- | 6897e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 6898e41f4b71Sopenharmony_ci 6899e41f4b71Sopenharmony_ci**Example** 6900e41f4b71Sopenharmony_ci 6901e41f4b71Sopenharmony_ci```ts 6902e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 6903e41f4b71Sopenharmony_ci 6904e41f4b71Sopenharmony_cifunction getExposureValue(captureSession: camera.CaptureSession): number { 6905e41f4b71Sopenharmony_ci const invalidValue: number = -1; 6906e41f4b71Sopenharmony_ci let exposureValue: number = invalidValue; 6907e41f4b71Sopenharmony_ci try { 6908e41f4b71Sopenharmony_ci exposureValue = captureSession.getExposureValue(); 6909e41f4b71Sopenharmony_ci } catch (error) { 6910e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 6911e41f4b71Sopenharmony_ci let err = error as BusinessError; 6912e41f4b71Sopenharmony_ci console.error(`The getExposureValue call failed. error code: ${err.code}`); 6913e41f4b71Sopenharmony_ci } 6914e41f4b71Sopenharmony_ci return exposureValue; 6915e41f4b71Sopenharmony_ci} 6916e41f4b71Sopenharmony_ci``` 6917e41f4b71Sopenharmony_ci 6918e41f4b71Sopenharmony_ci### isFocusModeSupported<sup>(deprecated)</sup> 6919e41f4b71Sopenharmony_ci 6920e41f4b71Sopenharmony_ciisFocusModeSupported(afMode: FocusMode): boolean 6921e41f4b71Sopenharmony_ci 6922e41f4b71Sopenharmony_ciChecks whether a focus mode is supported. 6923e41f4b71Sopenharmony_ci 6924e41f4b71Sopenharmony_ci> **NOTE** 6925e41f4b71Sopenharmony_ci> 6926e41f4b71Sopenharmony_ci>This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Focus.isFocusModeSupported](#isfocusmodesupported11) instead. 6927e41f4b71Sopenharmony_ci 6928e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 6929e41f4b71Sopenharmony_ci 6930e41f4b71Sopenharmony_ci**Parameters** 6931e41f4b71Sopenharmony_ci 6932e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 6933e41f4b71Sopenharmony_ci| -------- | ----------------------- | ---- | -------------------------------- | 6934e41f4b71Sopenharmony_ci| afMode | [FocusMode](#focusmode) | Yes | Focus mode. | 6935e41f4b71Sopenharmony_ci 6936e41f4b71Sopenharmony_ci**Return value** 6937e41f4b71Sopenharmony_ci 6938e41f4b71Sopenharmony_ci| Type | Description | 6939e41f4b71Sopenharmony_ci| ---------- | ----------------------------- | 6940e41f4b71Sopenharmony_ci| boolean | **true**: The focus mode is supported.<br>**false**: The focus mode is not supported. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 6941e41f4b71Sopenharmony_ci 6942e41f4b71Sopenharmony_ci**Error codes** 6943e41f4b71Sopenharmony_ci 6944e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 6945e41f4b71Sopenharmony_ci 6946e41f4b71Sopenharmony_ci| ID | Error Message | 6947e41f4b71Sopenharmony_ci| --------------- | --------------- | 6948e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 6949e41f4b71Sopenharmony_ci 6950e41f4b71Sopenharmony_ci**Example** 6951e41f4b71Sopenharmony_ci 6952e41f4b71Sopenharmony_ci```ts 6953e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 6954e41f4b71Sopenharmony_ci 6955e41f4b71Sopenharmony_cifunction isFocusModeSupported(captureSession: camera.CaptureSession): boolean { 6956e41f4b71Sopenharmony_ci let status: boolean = false; 6957e41f4b71Sopenharmony_ci try { 6958e41f4b71Sopenharmony_ci status = captureSession.isFocusModeSupported(camera.FocusMode.FOCUS_MODE_AUTO); 6959e41f4b71Sopenharmony_ci } catch (error) { 6960e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 6961e41f4b71Sopenharmony_ci let err = error as BusinessError; 6962e41f4b71Sopenharmony_ci console.error(`The isFocusModeSupported call failed. error code: ${err.code}`); 6963e41f4b71Sopenharmony_ci } 6964e41f4b71Sopenharmony_ci return status; 6965e41f4b71Sopenharmony_ci} 6966e41f4b71Sopenharmony_ci``` 6967e41f4b71Sopenharmony_ci 6968e41f4b71Sopenharmony_ci### setFocusMode<sup>(deprecated)</sup> 6969e41f4b71Sopenharmony_ci 6970e41f4b71Sopenharmony_cisetFocusMode(afMode: FocusMode): void 6971e41f4b71Sopenharmony_ci 6972e41f4b71Sopenharmony_ciSets a focus mode. 6973e41f4b71Sopenharmony_ci 6974e41f4b71Sopenharmony_ciBefore the setting, call [isFocusModeSupported](#isfocusmodesupporteddeprecated) to check whether the focus mode is supported. 6975e41f4b71Sopenharmony_ci 6976e41f4b71Sopenharmony_ci> **NOTE** 6977e41f4b71Sopenharmony_ci> 6978e41f4b71Sopenharmony_ci>This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Focus.setFocusMode](#setfocusmode11) instead. 6979e41f4b71Sopenharmony_ci 6980e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 6981e41f4b71Sopenharmony_ci 6982e41f4b71Sopenharmony_ci**Parameters** 6983e41f4b71Sopenharmony_ci 6984e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 6985e41f4b71Sopenharmony_ci| -------- | ----------------------- | ---- | ------------------- | 6986e41f4b71Sopenharmony_ci| afMode | [FocusMode](#focusmode) | Yes | Focus mode. | 6987e41f4b71Sopenharmony_ci 6988e41f4b71Sopenharmony_ci**Error codes** 6989e41f4b71Sopenharmony_ci 6990e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 6991e41f4b71Sopenharmony_ci 6992e41f4b71Sopenharmony_ci| ID | Error Message | 6993e41f4b71Sopenharmony_ci| --------------- | --------------- | 6994e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 6995e41f4b71Sopenharmony_ci 6996e41f4b71Sopenharmony_ci**Example** 6997e41f4b71Sopenharmony_ci 6998e41f4b71Sopenharmony_ci```ts 6999e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 7000e41f4b71Sopenharmony_ci 7001e41f4b71Sopenharmony_cifunction setFocusMode(captureSession: camera.CaptureSession): void { 7002e41f4b71Sopenharmony_ci try { 7003e41f4b71Sopenharmony_ci captureSession.setFocusMode(camera.FocusMode.FOCUS_MODE_AUTO); 7004e41f4b71Sopenharmony_ci } catch (error) { 7005e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 7006e41f4b71Sopenharmony_ci let err = error as BusinessError; 7007e41f4b71Sopenharmony_ci console.error(`The setFocusMode call failed. error code: ${err.code}`); 7008e41f4b71Sopenharmony_ci } 7009e41f4b71Sopenharmony_ci} 7010e41f4b71Sopenharmony_ci``` 7011e41f4b71Sopenharmony_ci 7012e41f4b71Sopenharmony_ci### getFocusMode<sup>(deprecated)</sup> 7013e41f4b71Sopenharmony_ci 7014e41f4b71Sopenharmony_cigetFocusMode(): FocusMode 7015e41f4b71Sopenharmony_ci 7016e41f4b71Sopenharmony_ciObtains the focus mode in use. 7017e41f4b71Sopenharmony_ci 7018e41f4b71Sopenharmony_ci> **NOTE** 7019e41f4b71Sopenharmony_ci> 7020e41f4b71Sopenharmony_ci>This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Focus.getFocusMode](#getfocusmode11) instead. 7021e41f4b71Sopenharmony_ci 7022e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 7023e41f4b71Sopenharmony_ci 7024e41f4b71Sopenharmony_ci**Return value** 7025e41f4b71Sopenharmony_ci 7026e41f4b71Sopenharmony_ci| Type | Description | 7027e41f4b71Sopenharmony_ci| ---------- | ----------------------------- | 7028e41f4b71Sopenharmony_ci| [FocusMode](#focusmode) | Focus mode obtained. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 7029e41f4b71Sopenharmony_ci 7030e41f4b71Sopenharmony_ci**Error codes** 7031e41f4b71Sopenharmony_ci 7032e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 7033e41f4b71Sopenharmony_ci 7034e41f4b71Sopenharmony_ci| ID | Error Message | 7035e41f4b71Sopenharmony_ci| --------------- | --------------- | 7036e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 7037e41f4b71Sopenharmony_ci 7038e41f4b71Sopenharmony_ci**Example** 7039e41f4b71Sopenharmony_ci 7040e41f4b71Sopenharmony_ci```ts 7041e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 7042e41f4b71Sopenharmony_ci 7043e41f4b71Sopenharmony_cifunction getFocusMode(captureSession: camera.CaptureSession): camera.FocusMode | undefined { 7044e41f4b71Sopenharmony_ci let afMode: camera.FocusMode | undefined = undefined; 7045e41f4b71Sopenharmony_ci try { 7046e41f4b71Sopenharmony_ci afMode = captureSession.getFocusMode(); 7047e41f4b71Sopenharmony_ci } catch (error) { 7048e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 7049e41f4b71Sopenharmony_ci let err = error as BusinessError; 7050e41f4b71Sopenharmony_ci console.error(`The getFocusMode call failed. error code: ${err.code}`); 7051e41f4b71Sopenharmony_ci } 7052e41f4b71Sopenharmony_ci return afMode; 7053e41f4b71Sopenharmony_ci} 7054e41f4b71Sopenharmony_ci``` 7055e41f4b71Sopenharmony_ci 7056e41f4b71Sopenharmony_ci### setFocusPoint<sup>(deprecated)</sup> 7057e41f4b71Sopenharmony_ci 7058e41f4b71Sopenharmony_cisetFocusPoint(point: Point): void 7059e41f4b71Sopenharmony_ci 7060e41f4b71Sopenharmony_ciSets the focal point. The focal point must be in the coordinate system (0-1), where the upper left corner is {0, 0} and the lower right corner is {1, 1}. 7061e41f4b71Sopenharmony_ci 7062e41f4b71Sopenharmony_ciThe coordinate system is based on the horizontal device direction with the device's charging port on the right. If the layout of the preview screen of an application is based on the vertical direction with the charging port on the lower side, the layout width and height are {w, h}, and the touch point is {x, y}, then the coordinate point after conversion is {y/h, 1-x/w}. 7063e41f4b71Sopenharmony_ci 7064e41f4b71Sopenharmony_ci> **NOTE** 7065e41f4b71Sopenharmony_ci> 7066e41f4b71Sopenharmony_ci> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Focus.setFocusPoint](#setfocuspoint11) instead. 7067e41f4b71Sopenharmony_ci 7068e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 7069e41f4b71Sopenharmony_ci 7070e41f4b71Sopenharmony_ci**Parameters** 7071e41f4b71Sopenharmony_ci 7072e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 7073e41f4b71Sopenharmony_ci|-------| ----------------------- |-----| ------------------- | 7074e41f4b71Sopenharmony_ci| point | [Point](#point) | Yes | Focal point. The value range of x and y must be within [0,1]. If a value less than 0 is passed, the value **0** is used. If a value greater than **1** is passed, the value **1** is used. | 7075e41f4b71Sopenharmony_ci 7076e41f4b71Sopenharmony_ci**Error codes** 7077e41f4b71Sopenharmony_ci 7078e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 7079e41f4b71Sopenharmony_ci 7080e41f4b71Sopenharmony_ci| ID | Error Message | 7081e41f4b71Sopenharmony_ci| --------------- | --------------- | 7082e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 7083e41f4b71Sopenharmony_ci 7084e41f4b71Sopenharmony_ci**Example** 7085e41f4b71Sopenharmony_ci 7086e41f4b71Sopenharmony_ci```ts 7087e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 7088e41f4b71Sopenharmony_ci 7089e41f4b71Sopenharmony_cifunction setFocusPoint(captureSession: camera.CaptureSession): void { 7090e41f4b71Sopenharmony_ci const focusPoint: camera.Point = {x: 1, y: 1}; 7091e41f4b71Sopenharmony_ci try { 7092e41f4b71Sopenharmony_ci captureSession.setFocusPoint(focusPoint); 7093e41f4b71Sopenharmony_ci } catch (error) { 7094e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 7095e41f4b71Sopenharmony_ci let err = error as BusinessError; 7096e41f4b71Sopenharmony_ci console.error(`The setFocusPoint call failed. error code: ${err.code}`); 7097e41f4b71Sopenharmony_ci } 7098e41f4b71Sopenharmony_ci} 7099e41f4b71Sopenharmony_ci``` 7100e41f4b71Sopenharmony_ci 7101e41f4b71Sopenharmony_ci### getFocusPoint<sup>(deprecated)</sup> 7102e41f4b71Sopenharmony_ci 7103e41f4b71Sopenharmony_cigetFocusPoint(): Point 7104e41f4b71Sopenharmony_ci 7105e41f4b71Sopenharmony_ciObtains the focal point of the camera device. 7106e41f4b71Sopenharmony_ci 7107e41f4b71Sopenharmony_ci> **NOTE** 7108e41f4b71Sopenharmony_ci> 7109e41f4b71Sopenharmony_ci> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Focus.getFocusPoint](#getfocuspoint11) instead. 7110e41f4b71Sopenharmony_ci 7111e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 7112e41f4b71Sopenharmony_ci 7113e41f4b71Sopenharmony_ci**Return value** 7114e41f4b71Sopenharmony_ci 7115e41f4b71Sopenharmony_ci| Type | Description | 7116e41f4b71Sopenharmony_ci| ---------- | ----------------------------- | 7117e41f4b71Sopenharmony_ci| [Point](#point) | Focal point obtained. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 7118e41f4b71Sopenharmony_ci 7119e41f4b71Sopenharmony_ci**Error codes** 7120e41f4b71Sopenharmony_ci 7121e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 7122e41f4b71Sopenharmony_ci 7123e41f4b71Sopenharmony_ci| ID | Error Message | 7124e41f4b71Sopenharmony_ci| --------------- | --------------- | 7125e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 7126e41f4b71Sopenharmony_ci 7127e41f4b71Sopenharmony_ci**Example** 7128e41f4b71Sopenharmony_ci 7129e41f4b71Sopenharmony_ci```ts 7130e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 7131e41f4b71Sopenharmony_ci 7132e41f4b71Sopenharmony_cifunction getFocusPoint(captureSession: camera.CaptureSession): camera.Point | undefined { 7133e41f4b71Sopenharmony_ci let point: camera.Point | undefined = undefined; 7134e41f4b71Sopenharmony_ci try { 7135e41f4b71Sopenharmony_ci point = captureSession.getFocusPoint(); 7136e41f4b71Sopenharmony_ci } catch (error) { 7137e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 7138e41f4b71Sopenharmony_ci let err = error as BusinessError; 7139e41f4b71Sopenharmony_ci console.error(`The getFocusPoint call failed. error code: ${err.code}`); 7140e41f4b71Sopenharmony_ci } 7141e41f4b71Sopenharmony_ci return point; 7142e41f4b71Sopenharmony_ci} 7143e41f4b71Sopenharmony_ci``` 7144e41f4b71Sopenharmony_ci 7145e41f4b71Sopenharmony_ci### getFocalLength<sup>(deprecated)</sup> 7146e41f4b71Sopenharmony_ci 7147e41f4b71Sopenharmony_cigetFocalLength(): number 7148e41f4b71Sopenharmony_ci 7149e41f4b71Sopenharmony_ciObtains the focal length of the camera device. 7150e41f4b71Sopenharmony_ci 7151e41f4b71Sopenharmony_ci> **NOTE** 7152e41f4b71Sopenharmony_ci> 7153e41f4b71Sopenharmony_ci> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Focus.getFocalLength](#getfocallength11) instead. 7154e41f4b71Sopenharmony_ci 7155e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 7156e41f4b71Sopenharmony_ci 7157e41f4b71Sopenharmony_ci**Return value** 7158e41f4b71Sopenharmony_ci 7159e41f4b71Sopenharmony_ci| Type | Description | 7160e41f4b71Sopenharmony_ci| ---------- | ----------------------------- | 7161e41f4b71Sopenharmony_ci| number | Focal length obtained. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 7162e41f4b71Sopenharmony_ci 7163e41f4b71Sopenharmony_ci**Error codes** 7164e41f4b71Sopenharmony_ci 7165e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 7166e41f4b71Sopenharmony_ci 7167e41f4b71Sopenharmony_ci| ID | Error Message | 7168e41f4b71Sopenharmony_ci| --------------- | --------------- | 7169e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 7170e41f4b71Sopenharmony_ci 7171e41f4b71Sopenharmony_ci**Example** 7172e41f4b71Sopenharmony_ci 7173e41f4b71Sopenharmony_ci```ts 7174e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 7175e41f4b71Sopenharmony_ci 7176e41f4b71Sopenharmony_cifunction getFocalLength(captureSession: camera.CaptureSession): number { 7177e41f4b71Sopenharmony_ci const invalidValue: number = -1; 7178e41f4b71Sopenharmony_ci let focalLength: number = invalidValue; 7179e41f4b71Sopenharmony_ci try { 7180e41f4b71Sopenharmony_ci focalLength = captureSession.getFocalLength(); 7181e41f4b71Sopenharmony_ci } catch (error) { 7182e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 7183e41f4b71Sopenharmony_ci let err = error as BusinessError; 7184e41f4b71Sopenharmony_ci console.error(`The getFocalLength call failed. error code: ${err.code}`); 7185e41f4b71Sopenharmony_ci } 7186e41f4b71Sopenharmony_ci return focalLength; 7187e41f4b71Sopenharmony_ci} 7188e41f4b71Sopenharmony_ci``` 7189e41f4b71Sopenharmony_ci 7190e41f4b71Sopenharmony_ci### getZoomRatioRange<sup>(deprecated)</sup> 7191e41f4b71Sopenharmony_ci 7192e41f4b71Sopenharmony_cigetZoomRatioRange(): Array\<number\> 7193e41f4b71Sopenharmony_ci 7194e41f4b71Sopenharmony_ciObtains the supported zoom ratio range. 7195e41f4b71Sopenharmony_ci 7196e41f4b71Sopenharmony_ci> **NOTE** 7197e41f4b71Sopenharmony_ci> 7198e41f4b71Sopenharmony_ci> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Zoom.getZoomRatioRange](#getzoomratiorange11) instead. 7199e41f4b71Sopenharmony_ci 7200e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 7201e41f4b71Sopenharmony_ci 7202e41f4b71Sopenharmony_ci**Return value** 7203e41f4b71Sopenharmony_ci 7204e41f4b71Sopenharmony_ci| Type | Description | 7205e41f4b71Sopenharmony_ci| ---------- | ----------------------------- | 7206e41f4b71Sopenharmony_ci| Array\<number\> | Array containing the minimum and maximum zoom ratios. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 7207e41f4b71Sopenharmony_ci 7208e41f4b71Sopenharmony_ci**Error codes** 7209e41f4b71Sopenharmony_ci 7210e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 7211e41f4b71Sopenharmony_ci 7212e41f4b71Sopenharmony_ci| ID | Error Message | 7213e41f4b71Sopenharmony_ci| --------------- | --------------- | 7214e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 7215e41f4b71Sopenharmony_ci 7216e41f4b71Sopenharmony_ci**Example** 7217e41f4b71Sopenharmony_ci 7218e41f4b71Sopenharmony_ci```ts 7219e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 7220e41f4b71Sopenharmony_ci 7221e41f4b71Sopenharmony_cifunction getZoomRatioRange(captureSession: camera.CaptureSession): Array<number> { 7222e41f4b71Sopenharmony_ci let zoomRatioRange: Array<number> = []; 7223e41f4b71Sopenharmony_ci try { 7224e41f4b71Sopenharmony_ci zoomRatioRange = captureSession.getZoomRatioRange(); 7225e41f4b71Sopenharmony_ci } catch (error) { 7226e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 7227e41f4b71Sopenharmony_ci let err = error as BusinessError; 7228e41f4b71Sopenharmony_ci console.error(`The getZoomRatioRange call failed. error code: ${err.code}`); 7229e41f4b71Sopenharmony_ci } 7230e41f4b71Sopenharmony_ci return zoomRatioRange; 7231e41f4b71Sopenharmony_ci} 7232e41f4b71Sopenharmony_ci``` 7233e41f4b71Sopenharmony_ci 7234e41f4b71Sopenharmony_ci### setZoomRatio<sup>(deprecated)</sup> 7235e41f4b71Sopenharmony_ci 7236e41f4b71Sopenharmony_cisetZoomRatio(zoomRatio: number): void 7237e41f4b71Sopenharmony_ci 7238e41f4b71Sopenharmony_ciSets a zoom ratio, with a maximum precision of two decimal places. 7239e41f4b71Sopenharmony_ci 7240e41f4b71Sopenharmony_ci> **NOTE** 7241e41f4b71Sopenharmony_ci> 7242e41f4b71Sopenharmony_ci> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Zoom.setZoomRatio](#setzoomratio11) instead. 7243e41f4b71Sopenharmony_ci 7244e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 7245e41f4b71Sopenharmony_ci 7246e41f4b71Sopenharmony_ci**Parameters** 7247e41f4b71Sopenharmony_ci 7248e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 7249e41f4b71Sopenharmony_ci| --------- | -------------------- |-----| ------------------- | 7250e41f4b71Sopenharmony_ci| zoomRatio | number | Yes | Zoom ratio. The supported zoom ratio range can be obtained by calling [getZoomRatioRange](#getzoomratiorange11). If the value passed in is not within the supported range, the value within the precision range is retained.| 7251e41f4b71Sopenharmony_ci 7252e41f4b71Sopenharmony_ci**Error codes** 7253e41f4b71Sopenharmony_ci 7254e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 7255e41f4b71Sopenharmony_ci 7256e41f4b71Sopenharmony_ci| ID | Error Message | 7257e41f4b71Sopenharmony_ci| --------------- | --------------- | 7258e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 7259e41f4b71Sopenharmony_ci 7260e41f4b71Sopenharmony_ci**Example** 7261e41f4b71Sopenharmony_ci 7262e41f4b71Sopenharmony_ci```ts 7263e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 7264e41f4b71Sopenharmony_ci 7265e41f4b71Sopenharmony_cifunction setZoomRatio(captureSession: camera.CaptureSession, zoomRatioRange: Array<number>): void { 7266e41f4b71Sopenharmony_ci if (zoomRatioRange === undefined || zoomRatioRange.length <= 0) { 7267e41f4b71Sopenharmony_ci return; 7268e41f4b71Sopenharmony_ci } 7269e41f4b71Sopenharmony_ci let zoomRatio = zoomRatioRange[0]; 7270e41f4b71Sopenharmony_ci try { 7271e41f4b71Sopenharmony_ci captureSession.setZoomRatio(zoomRatio); 7272e41f4b71Sopenharmony_ci } catch (error) { 7273e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 7274e41f4b71Sopenharmony_ci let err = error as BusinessError; 7275e41f4b71Sopenharmony_ci console.error(`The setZoomRatio call failed. error code: ${err.code}`); 7276e41f4b71Sopenharmony_ci } 7277e41f4b71Sopenharmony_ci} 7278e41f4b71Sopenharmony_ci``` 7279e41f4b71Sopenharmony_ci 7280e41f4b71Sopenharmony_ci### getZoomRatio<sup>(deprecated)</sup> 7281e41f4b71Sopenharmony_ci 7282e41f4b71Sopenharmony_cigetZoomRatio(): number 7283e41f4b71Sopenharmony_ci 7284e41f4b71Sopenharmony_ciObtains the zoom ratio in use. 7285e41f4b71Sopenharmony_ci 7286e41f4b71Sopenharmony_ci> **NOTE** 7287e41f4b71Sopenharmony_ci> 7288e41f4b71Sopenharmony_ci> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Zoom.getZoomRatio](#getzoomratio11) instead. 7289e41f4b71Sopenharmony_ci 7290e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 7291e41f4b71Sopenharmony_ci 7292e41f4b71Sopenharmony_ci**Return value** 7293e41f4b71Sopenharmony_ci 7294e41f4b71Sopenharmony_ci| Type | Description | 7295e41f4b71Sopenharmony_ci| ---------- | ----------------------------- | 7296e41f4b71Sopenharmony_ci| number | Zoom ratio obtained. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 7297e41f4b71Sopenharmony_ci 7298e41f4b71Sopenharmony_ci**Error codes** 7299e41f4b71Sopenharmony_ci 7300e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 7301e41f4b71Sopenharmony_ci 7302e41f4b71Sopenharmony_ci| ID | Error Message | 7303e41f4b71Sopenharmony_ci| --------------- | --------------- | 7304e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 7305e41f4b71Sopenharmony_ci 7306e41f4b71Sopenharmony_ci**Example** 7307e41f4b71Sopenharmony_ci 7308e41f4b71Sopenharmony_ci```ts 7309e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 7310e41f4b71Sopenharmony_ci 7311e41f4b71Sopenharmony_cifunction getZoomRatio(captureSession: camera.CaptureSession): number { 7312e41f4b71Sopenharmony_ci const invalidValue: number = -1; 7313e41f4b71Sopenharmony_ci let zoomRatio: number = invalidValue; 7314e41f4b71Sopenharmony_ci try { 7315e41f4b71Sopenharmony_ci zoomRatio = captureSession.getZoomRatio(); 7316e41f4b71Sopenharmony_ci } catch (error) { 7317e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 7318e41f4b71Sopenharmony_ci let err = error as BusinessError; 7319e41f4b71Sopenharmony_ci console.error(`The getZoomRatio call failed. error code: ${err.code}`); 7320e41f4b71Sopenharmony_ci } 7321e41f4b71Sopenharmony_ci return zoomRatio; 7322e41f4b71Sopenharmony_ci} 7323e41f4b71Sopenharmony_ci``` 7324e41f4b71Sopenharmony_ci 7325e41f4b71Sopenharmony_ci### isVideoStabilizationModeSupported<sup>(deprecated)</sup> 7326e41f4b71Sopenharmony_ci 7327e41f4b71Sopenharmony_ciisVideoStabilizationModeSupported(vsMode: VideoStabilizationMode): boolean 7328e41f4b71Sopenharmony_ci 7329e41f4b71Sopenharmony_ciChecks whether a video stabilization mode is supported. 7330e41f4b71Sopenharmony_ci 7331e41f4b71Sopenharmony_ci> **NOTE** 7332e41f4b71Sopenharmony_ci> 7333e41f4b71Sopenharmony_ci> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Stabilization.isVideoStabilizationModeSupported](#isvideostabilizationmodesupported11) instead. 7334e41f4b71Sopenharmony_ci 7335e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 7336e41f4b71Sopenharmony_ci 7337e41f4b71Sopenharmony_ci**Parameters** 7338e41f4b71Sopenharmony_ci 7339e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 7340e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------- | ---- | ------------------------------ | 7341e41f4b71Sopenharmony_ci| vsMode | [VideoStabilizationMode](#videostabilizationmode) | Yes | Video stabilization mode. | 7342e41f4b71Sopenharmony_ci 7343e41f4b71Sopenharmony_ci**Return value** 7344e41f4b71Sopenharmony_ci 7345e41f4b71Sopenharmony_ci| Type | Description | 7346e41f4b71Sopenharmony_ci| ---------- | ----------------------------- | 7347e41f4b71Sopenharmony_ci| boolean | **true**: The video stabilization mode is supported.<br>**false**: The video stabilization mode is not supported. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 7348e41f4b71Sopenharmony_ci 7349e41f4b71Sopenharmony_ci**Error codes** 7350e41f4b71Sopenharmony_ci 7351e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 7352e41f4b71Sopenharmony_ci 7353e41f4b71Sopenharmony_ci| ID | Error Message | 7354e41f4b71Sopenharmony_ci| --------------- | --------------- | 7355e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 7356e41f4b71Sopenharmony_ci 7357e41f4b71Sopenharmony_ci**Example** 7358e41f4b71Sopenharmony_ci 7359e41f4b71Sopenharmony_ci```ts 7360e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 7361e41f4b71Sopenharmony_ci 7362e41f4b71Sopenharmony_cifunction isVideoStabilizationModeSupported(captureSession: camera.CaptureSession): boolean { 7363e41f4b71Sopenharmony_ci let isSupported: boolean = false; 7364e41f4b71Sopenharmony_ci try { 7365e41f4b71Sopenharmony_ci isSupported = captureSession.isVideoStabilizationModeSupported(camera.VideoStabilizationMode.OFF); 7366e41f4b71Sopenharmony_ci } catch (error) { 7367e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 7368e41f4b71Sopenharmony_ci let err = error as BusinessError; 7369e41f4b71Sopenharmony_ci console.error(`The isVideoStabilizationModeSupported call failed. error code: ${err.code}`); 7370e41f4b71Sopenharmony_ci } 7371e41f4b71Sopenharmony_ci return isSupported; 7372e41f4b71Sopenharmony_ci} 7373e41f4b71Sopenharmony_ci``` 7374e41f4b71Sopenharmony_ci 7375e41f4b71Sopenharmony_ci### getActiveVideoStabilizationMode<sup>(deprecated)</sup> 7376e41f4b71Sopenharmony_ci 7377e41f4b71Sopenharmony_cigetActiveVideoStabilizationMode(): VideoStabilizationMode 7378e41f4b71Sopenharmony_ci 7379e41f4b71Sopenharmony_ciObtains the video stabilization mode in use. 7380e41f4b71Sopenharmony_ci 7381e41f4b71Sopenharmony_ci> **NOTE** 7382e41f4b71Sopenharmony_ci> 7383e41f4b71Sopenharmony_ci> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Stabilization.getActiveVideoStabilizationMode](#getactivevideostabilizationmode11) instead. 7384e41f4b71Sopenharmony_ci 7385e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 7386e41f4b71Sopenharmony_ci 7387e41f4b71Sopenharmony_ci**Return value** 7388e41f4b71Sopenharmony_ci 7389e41f4b71Sopenharmony_ci| Type | Description | 7390e41f4b71Sopenharmony_ci| ---------- | ----------------------------- | 7391e41f4b71Sopenharmony_ci| [VideoStabilizationMode](#videostabilizationmode) | Video stabilization mode obtained. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 7392e41f4b71Sopenharmony_ci 7393e41f4b71Sopenharmony_ci**Error codes** 7394e41f4b71Sopenharmony_ci 7395e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 7396e41f4b71Sopenharmony_ci 7397e41f4b71Sopenharmony_ci| ID | Error Message | 7398e41f4b71Sopenharmony_ci| --------------- | --------------- | 7399e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 7400e41f4b71Sopenharmony_ci 7401e41f4b71Sopenharmony_ci**Example** 7402e41f4b71Sopenharmony_ci 7403e41f4b71Sopenharmony_ci```ts 7404e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 7405e41f4b71Sopenharmony_ci 7406e41f4b71Sopenharmony_cifunction getActiveVideoStabilizationMode(captureSession: camera.CaptureSession): camera.VideoStabilizationMode | undefined { 7407e41f4b71Sopenharmony_ci let vsMode: camera.VideoStabilizationMode | undefined = undefined; 7408e41f4b71Sopenharmony_ci try { 7409e41f4b71Sopenharmony_ci vsMode = captureSession.getActiveVideoStabilizationMode(); 7410e41f4b71Sopenharmony_ci } catch (error) { 7411e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 7412e41f4b71Sopenharmony_ci let err = error as BusinessError; 7413e41f4b71Sopenharmony_ci console.error(`The getActiveVideoStabilizationMode call failed. error code: ${err.code}`); 7414e41f4b71Sopenharmony_ci } 7415e41f4b71Sopenharmony_ci return vsMode; 7416e41f4b71Sopenharmony_ci} 7417e41f4b71Sopenharmony_ci``` 7418e41f4b71Sopenharmony_ci 7419e41f4b71Sopenharmony_ci### setVideoStabilizationMode<sup>(deprecated)</sup> 7420e41f4b71Sopenharmony_ci 7421e41f4b71Sopenharmony_cisetVideoStabilizationMode(mode: VideoStabilizationMode): void 7422e41f4b71Sopenharmony_ci 7423e41f4b71Sopenharmony_ciSets a video stabilization mode. Before the setting, call [isVideoStabilizationModeSupported](#isvideostabilizationmodesupporteddeprecated) to check whether the target video stabilization mode is supported. 7424e41f4b71Sopenharmony_ci 7425e41f4b71Sopenharmony_ci> **NOTE** 7426e41f4b71Sopenharmony_ci> 7427e41f4b71Sopenharmony_ci> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Stabilization.setVideoStabilizationMode](#setvideostabilizationmode11) instead. 7428e41f4b71Sopenharmony_ci 7429e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 7430e41f4b71Sopenharmony_ci 7431e41f4b71Sopenharmony_ci**Parameters** 7432e41f4b71Sopenharmony_ci 7433e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 7434e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------- | ---- | --------------------- | 7435e41f4b71Sopenharmony_ci| mode | [VideoStabilizationMode](#videostabilizationmode) | Yes | Video stabilization mode. | 7436e41f4b71Sopenharmony_ci 7437e41f4b71Sopenharmony_ci**Error codes** 7438e41f4b71Sopenharmony_ci 7439e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 7440e41f4b71Sopenharmony_ci 7441e41f4b71Sopenharmony_ci| ID | Error Message | 7442e41f4b71Sopenharmony_ci| --------------- | --------------- | 7443e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 7444e41f4b71Sopenharmony_ci 7445e41f4b71Sopenharmony_ci**Example** 7446e41f4b71Sopenharmony_ci 7447e41f4b71Sopenharmony_ci```ts 7448e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 7449e41f4b71Sopenharmony_ci 7450e41f4b71Sopenharmony_cifunction setVideoStabilizationMode(captureSession: camera.CaptureSession): void { 7451e41f4b71Sopenharmony_ci try { 7452e41f4b71Sopenharmony_ci captureSession.setVideoStabilizationMode(camera.VideoStabilizationMode.OFF); 7453e41f4b71Sopenharmony_ci } catch (error) { 7454e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 7455e41f4b71Sopenharmony_ci let err = error as BusinessError; 7456e41f4b71Sopenharmony_ci console.error(`The setVideoStabilizationMode call failed. error code: ${err.code}`); 7457e41f4b71Sopenharmony_ci } 7458e41f4b71Sopenharmony_ci} 7459e41f4b71Sopenharmony_ci``` 7460e41f4b71Sopenharmony_ci 7461e41f4b71Sopenharmony_ci### on('focusStateChange')<sup>(deprecated)</sup> 7462e41f4b71Sopenharmony_ci 7463e41f4b71Sopenharmony_cion(type: 'focusStateChange', callback: AsyncCallback\<FocusState\>): void 7464e41f4b71Sopenharmony_ci 7465e41f4b71Sopenharmony_ciSubscribes to focus state change events. This API uses an asynchronous callback to return the result. 7466e41f4b71Sopenharmony_ci 7467e41f4b71Sopenharmony_ci> **NOTE** 7468e41f4b71Sopenharmony_ci> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [VideoSession.on('focusStateChange')](#onfocusstatechange11-1) instead. 7469e41f4b71Sopenharmony_ci> 7470e41f4b71Sopenharmony_ci> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**. 7471e41f4b71Sopenharmony_ci 7472e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 7473e41f4b71Sopenharmony_ci 7474e41f4b71Sopenharmony_ci**Parameters** 7475e41f4b71Sopenharmony_ci 7476e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 7477e41f4b71Sopenharmony_ci| -------- | ----------------------------------------- | ---- | ------------------------ | 7478e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'focusStateChange'**. The event can be listened for when a session is created. This event is triggered only when the camera focus state changes in auto focus mode.| 7479e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[FocusState](#focusstate)\> | Yes | Callback used to return the focus state change. | 7480e41f4b71Sopenharmony_ci 7481e41f4b71Sopenharmony_ci**Example** 7482e41f4b71Sopenharmony_ci 7483e41f4b71Sopenharmony_ci```ts 7484e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 7485e41f4b71Sopenharmony_ci 7486e41f4b71Sopenharmony_cifunction registerFocusStateChange(captureSession: camera.CaptureSession): void { 7487e41f4b71Sopenharmony_ci captureSession.on('focusStateChange', (err: BusinessError, focusState: camera.FocusState) => { 7488e41f4b71Sopenharmony_ci if (err !== undefined && err.code !== 0) { 7489e41f4b71Sopenharmony_ci console.error(`Callback Error, errorCode: ${err.code}`); 7490e41f4b71Sopenharmony_ci return; 7491e41f4b71Sopenharmony_ci } 7492e41f4b71Sopenharmony_ci console.info(`Focus state: ${focusState}`); 7493e41f4b71Sopenharmony_ci }); 7494e41f4b71Sopenharmony_ci} 7495e41f4b71Sopenharmony_ci``` 7496e41f4b71Sopenharmony_ci 7497e41f4b71Sopenharmony_ci### off('focusStateChange')<sup>(deprecated)</sup> 7498e41f4b71Sopenharmony_ci 7499e41f4b71Sopenharmony_cioff(type: 'focusStateChange', callback?: AsyncCallback\<FocusState\>): void 7500e41f4b71Sopenharmony_ci 7501e41f4b71Sopenharmony_ciUnsubscribes from focus state change events. 7502e41f4b71Sopenharmony_ci 7503e41f4b71Sopenharmony_ci> **NOTE** 7504e41f4b71Sopenharmony_ci> 7505e41f4b71Sopenharmony_ci> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [VideoSession.off('focusStateChange')](#offfocusstatechange11-1) instead. 7506e41f4b71Sopenharmony_ci 7507e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 7508e41f4b71Sopenharmony_ci 7509e41f4b71Sopenharmony_ci**Parameters** 7510e41f4b71Sopenharmony_ci 7511e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 7512e41f4b71Sopenharmony_ci| -------- | ----------------------------------------- | ---- | ------------------------ | 7513e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'focusStateChange'**. The event can be listened for when a session is created.| 7514e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[FocusState](#focusstate)\> | No | Callback used to return the result. If this parameter is specified, the subscription to the specified event with the specified callback is canceled. (The callback object cannot be an anonymous function.) Otherwise, the subscriptions to the specified event with all the callbacks are canceled.| 7515e41f4b71Sopenharmony_ci 7516e41f4b71Sopenharmony_ci**Example** 7517e41f4b71Sopenharmony_ci 7518e41f4b71Sopenharmony_ci```ts 7519e41f4b71Sopenharmony_cifunction unregisterFocusStateChange(captureSession: camera.CaptureSession): void { 7520e41f4b71Sopenharmony_ci captureSession.off('focusStateChange'); 7521e41f4b71Sopenharmony_ci} 7522e41f4b71Sopenharmony_ci``` 7523e41f4b71Sopenharmony_ci 7524e41f4b71Sopenharmony_ci### on('error')<sup>(deprecated)</sup> 7525e41f4b71Sopenharmony_ci 7526e41f4b71Sopenharmony_cion(type: 'error', callback: ErrorCallback): void 7527e41f4b71Sopenharmony_ci 7528e41f4b71Sopenharmony_ciSubscribes to **CaptureSession** error events. This API uses an asynchronous callback to return the result. 7529e41f4b71Sopenharmony_ci 7530e41f4b71Sopenharmony_ci> **NOTE** 7531e41f4b71Sopenharmony_ci> 7532e41f4b71Sopenharmony_ci> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**. 7533e41f4b71Sopenharmony_ci 7534e41f4b71Sopenharmony_ci> **NOTE** 7535e41f4b71Sopenharmony_ci> 7536e41f4b71Sopenharmony_ci> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [VideoSession.on('error')](#onerror11-1) instead. 7537e41f4b71Sopenharmony_ci 7538e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 7539e41f4b71Sopenharmony_ci 7540e41f4b71Sopenharmony_ci**Parameters** 7541e41f4b71Sopenharmony_ci 7542e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 7543e41f4b71Sopenharmony_ci| -------- |--------------------------------------------------------------------------| ---- | ------------------------------ | 7544e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a session is created. This event is triggered and the error message is returned when an error occurs during the calling of a session-related API such as [beginConfig](#beginconfigdeprecated), [commitConfig](#commitconfigdeprecated-1), and [addInput](#addinputdeprecated).| 7545e41f4b71Sopenharmony_ci| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | Yes | Callback used to return an error code defined in [CameraErrorCode](#cameraerrorcode). | 7546e41f4b71Sopenharmony_ci 7547e41f4b71Sopenharmony_ci**Example** 7548e41f4b71Sopenharmony_ci 7549e41f4b71Sopenharmony_ci```ts 7550e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 7551e41f4b71Sopenharmony_ci 7552e41f4b71Sopenharmony_cifunction registerCaptureSessionError(captureSession: camera.CaptureSession): void { 7553e41f4b71Sopenharmony_ci captureSession.on('error', (error: BusinessError) => { 7554e41f4b71Sopenharmony_ci console.error(`Capture session error code: ${error.code}`); 7555e41f4b71Sopenharmony_ci }); 7556e41f4b71Sopenharmony_ci} 7557e41f4b71Sopenharmony_ci``` 7558e41f4b71Sopenharmony_ci 7559e41f4b71Sopenharmony_ci### off('error')<sup>(deprecated)</sup> 7560e41f4b71Sopenharmony_ci 7561e41f4b71Sopenharmony_cioff(type: 'error', callback?: ErrorCallback): void 7562e41f4b71Sopenharmony_ci 7563e41f4b71Sopenharmony_ciUnsubscribes from **CaptureSession** error events. This API uses a callback to return the result. 7564e41f4b71Sopenharmony_ci 7565e41f4b71Sopenharmony_ci> **NOTE** 7566e41f4b71Sopenharmony_ci> 7567e41f4b71Sopenharmony_ci> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [VideoSession.off('error')](#offerror11-1) instead. 7568e41f4b71Sopenharmony_ci 7569e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 7570e41f4b71Sopenharmony_ci 7571e41f4b71Sopenharmony_ci**Parameters** 7572e41f4b71Sopenharmony_ci 7573e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 7574e41f4b71Sopenharmony_ci| -------- | ----------------------------------------------------------- | ---- | ------------------------------ | 7575e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a session is created.| 7576e41f4b71Sopenharmony_ci| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback)| No | Callback used to return the result. If this parameter is specified, the subscription to the specified event with the specified callback is canceled. (The callback object cannot be an anonymous function.) Otherwise, the subscriptions to the specified event with all the callbacks are canceled.| 7577e41f4b71Sopenharmony_ci 7578e41f4b71Sopenharmony_ci**Example** 7579e41f4b71Sopenharmony_ci 7580e41f4b71Sopenharmony_ci```ts 7581e41f4b71Sopenharmony_cifunction unregisterCaptureSessionError(captureSession: camera.CaptureSession): void { 7582e41f4b71Sopenharmony_ci captureSession.off('error'); 7583e41f4b71Sopenharmony_ci} 7584e41f4b71Sopenharmony_ci``` 7585e41f4b71Sopenharmony_ci## ColorManagementQuery<sup>12+</sup> 7586e41f4b71Sopenharmony_ci 7587e41f4b71Sopenharmony_ciProvides the APIs for color space query. 7588e41f4b71Sopenharmony_ci 7589e41f4b71Sopenharmony_ci### getSupportedColorSpaces<sup>12+</sup> 7590e41f4b71Sopenharmony_ci 7591e41f4b71Sopenharmony_cigetSupportedColorSpaces(): Array\<colorSpaceManager.ColorSpace\> 7592e41f4b71Sopenharmony_ci 7593e41f4b71Sopenharmony_ciObtains the supported color spaces. 7594e41f4b71Sopenharmony_ci 7595e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 7596e41f4b71Sopenharmony_ci 7597e41f4b71Sopenharmony_ci**Return value** 7598e41f4b71Sopenharmony_ci 7599e41f4b71Sopenharmony_ci| Type | Description | 7600e41f4b71Sopenharmony_ci| ----------------------------------------------- | ---------------------------- | 7601e41f4b71Sopenharmony_ci| Array<[colorSpaceManager.ColorSpace](../apis-arkgraphics2d/js-apis-colorSpaceManager.md#colorspace)>| Array of color spaces supported. | 7602e41f4b71Sopenharmony_ci 7603e41f4b71Sopenharmony_ci**Error codes** 7604e41f4b71Sopenharmony_ci 7605e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 7606e41f4b71Sopenharmony_ci 7607e41f4b71Sopenharmony_ci| ID | Error Message | 7608e41f4b71Sopenharmony_ci| --------------- | --------------- | 7609e41f4b71Sopenharmony_ci| 7400103 | Session not config, only throw in session usage. | 7610e41f4b71Sopenharmony_ci 7611e41f4b71Sopenharmony_ci**Example** 7612e41f4b71Sopenharmony_ci 7613e41f4b71Sopenharmony_ci```ts 7614e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 7615e41f4b71Sopenharmony_ciimport { colorSpaceManager } from '@kit.ArkGraphics2D'; 7616e41f4b71Sopenharmony_ci 7617e41f4b71Sopenharmony_cifunction getSupportedColorSpaces(session: camera.PhotoSession): Array<colorSpaceManager.ColorSpace> { 7618e41f4b71Sopenharmony_ci let colorSpaces: Array<colorSpaceManager.ColorSpace> = []; 7619e41f4b71Sopenharmony_ci try { 7620e41f4b71Sopenharmony_ci colorSpaces = session.getSupportedColorSpaces(); 7621e41f4b71Sopenharmony_ci } catch (error) { 7622e41f4b71Sopenharmony_ci let err = error as BusinessError; 7623e41f4b71Sopenharmony_ci console.error(`The getSupportedColorSpaces call failed. error code: ${err.code}`); 7624e41f4b71Sopenharmony_ci } 7625e41f4b71Sopenharmony_ci return colorSpaces; 7626e41f4b71Sopenharmony_ci} 7627e41f4b71Sopenharmony_ci``` 7628e41f4b71Sopenharmony_ci## ColorManagement<sup>12+</sup> 7629e41f4b71Sopenharmony_ci 7630e41f4b71Sopenharmony_ciColorManagement extends [ColorManagementQuery](#colormanagementquery12) 7631e41f4b71Sopenharmony_ci 7632e41f4b71Sopenharmony_ciImplements color space management. It inherits from [ColorManagementQuery](#colormanagementquery12). 7633e41f4b71Sopenharmony_ci 7634e41f4b71Sopenharmony_ci### setColorSpace<sup>12+</sup> 7635e41f4b71Sopenharmony_ci 7636e41f4b71Sopenharmony_cisetColorSpace(colorSpace: colorSpaceManager.ColorSpace): void 7637e41f4b71Sopenharmony_ci 7638e41f4b71Sopenharmony_ciSets a color space. Before the setting, call [getSupportedColorSpaces](#getsupportedcolorspaces12) to obtain the supported color spaces. 7639e41f4b71Sopenharmony_ci 7640e41f4b71Sopenharmony_ciP3 and HDR Imaging 7641e41f4b71Sopenharmony_ci 7642e41f4b71Sopenharmony_ciAn application can deliver different color space parameters to declare its support for P3 and HDR. 7643e41f4b71Sopenharmony_ci 7644e41f4b71Sopenharmony_ciIf an application does not proactively set the color space, HDR is used by default in photographing and video recording scenarios. 7645e41f4b71Sopenharmony_ci 7646e41f4b71Sopenharmony_ciIn photo mode, P3 can be directly supported by setting the HDR effect. 7647e41f4b71Sopenharmony_ci 7648e41f4b71Sopenharmony_ciFor details about how to enable the HDR effect and set the color space in different modes, see the following table. 7649e41f4b71Sopenharmony_ci 7650e41f4b71Sopenharmony_ci**Recording Mode** 7651e41f4b71Sopenharmony_ci 7652e41f4b71Sopenharmony_ci| SDR/HRD Photographing | CameraFormat | ColorSpace | 7653e41f4b71Sopenharmony_ci|--------------------|--------------------------|------------------| 7654e41f4b71Sopenharmony_ci| SDR | CAMERA_FORMAT_YUV_420_SP | BT709_LIMIT | 7655e41f4b71Sopenharmony_ci| HDR_VIVID(Default) | CAMERA_FORMAT_YCRCB_P010 | BT2020_HLG_LIMIT | 7656e41f4b71Sopenharmony_ci 7657e41f4b71Sopenharmony_ci**Photo Mode** 7658e41f4b71Sopenharmony_ci 7659e41f4b71Sopenharmony_ci| SDR/HRD Photographing | ColorSpace | 7660e41f4b71Sopenharmony_ci|--------------|------------| 7661e41f4b71Sopenharmony_ci| SDR | SRGB | 7662e41f4b71Sopenharmony_ci| HDR(Default) | DISPLAY_P3 | 7663e41f4b71Sopenharmony_ci 7664e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 7665e41f4b71Sopenharmony_ci 7666e41f4b71Sopenharmony_ci**Parameters** 7667e41f4b71Sopenharmony_ci 7668e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 7669e41f4b71Sopenharmony_ci| ------------ |---------------------- | -- | -------------------------- | 7670e41f4b71Sopenharmony_ci| colorSpace | [colorSpaceManager.ColorSpace](../apis-arkgraphics2d/js-apis-colorSpaceManager.md#colorspace) | Yes| Color space, which can be obtained through [getSupportedColorSpaces](#getsupportedcolorspaces12). | 7671e41f4b71Sopenharmony_ci 7672e41f4b71Sopenharmony_ci**Error codes** 7673e41f4b71Sopenharmony_ci 7674e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 7675e41f4b71Sopenharmony_ci 7676e41f4b71Sopenharmony_ci| ID | Error Message | 7677e41f4b71Sopenharmony_ci| --------------- | --------------- | 7678e41f4b71Sopenharmony_ci| 7400101 | Parameter missing or parameter type incorrect. | 7679e41f4b71Sopenharmony_ci| 7400102 | The colorSpace does not match the format. | 7680e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 7681e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 7682e41f4b71Sopenharmony_ci 7683e41f4b71Sopenharmony_ci**Example** 7684e41f4b71Sopenharmony_ci 7685e41f4b71Sopenharmony_ci```ts 7686e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 7687e41f4b71Sopenharmony_ciimport { colorSpaceManager } from '@kit.ArkGraphics2D'; 7688e41f4b71Sopenharmony_ci 7689e41f4b71Sopenharmony_cifunction setColorSpace(session: camera.PhotoSession, colorSpaces: Array<colorSpaceManager.ColorSpace>): void { 7690e41f4b71Sopenharmony_ci if (colorSpaces === undefined || colorSpaces.length <= 0) { 7691e41f4b71Sopenharmony_ci return; 7692e41f4b71Sopenharmony_ci } 7693e41f4b71Sopenharmony_ci try { 7694e41f4b71Sopenharmony_ci session.setColorSpace(colorSpaces[0]); 7695e41f4b71Sopenharmony_ci } catch (error) { 7696e41f4b71Sopenharmony_ci let err = error as BusinessError; 7697e41f4b71Sopenharmony_ci console.error(`The setColorSpace call failed, error code: ${err.code}`); 7698e41f4b71Sopenharmony_ci } 7699e41f4b71Sopenharmony_ci} 7700e41f4b71Sopenharmony_ci``` 7701e41f4b71Sopenharmony_ci 7702e41f4b71Sopenharmony_ci### getActiveColorSpace<sup>12+</sup> 7703e41f4b71Sopenharmony_ci 7704e41f4b71Sopenharmony_cigetActiveColorSpace(): colorSpaceManager.ColorSpace 7705e41f4b71Sopenharmony_ci 7706e41f4b71Sopenharmony_ciObtains the color space in use. 7707e41f4b71Sopenharmony_ci 7708e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 7709e41f4b71Sopenharmony_ci 7710e41f4b71Sopenharmony_ci**Return value** 7711e41f4b71Sopenharmony_ci 7712e41f4b71Sopenharmony_ci| Type | Description | 7713e41f4b71Sopenharmony_ci| ----------------------------------------------- | ---------------------------- | 7714e41f4b71Sopenharmony_ci| [colorSpaceManager.ColorSpace](../apis-arkgraphics2d/js-apis-colorSpaceManager.md#colorspace) | Color space. | 7715e41f4b71Sopenharmony_ci 7716e41f4b71Sopenharmony_ci**Error codes** 7717e41f4b71Sopenharmony_ci 7718e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 7719e41f4b71Sopenharmony_ci 7720e41f4b71Sopenharmony_ci| ID | Error Message | 7721e41f4b71Sopenharmony_ci| --------------- | --------------- | 7722e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 7723e41f4b71Sopenharmony_ci 7724e41f4b71Sopenharmony_ci**Example** 7725e41f4b71Sopenharmony_ci 7726e41f4b71Sopenharmony_ci```ts 7727e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 7728e41f4b71Sopenharmony_ciimport { colorSpaceManager } from '@kit.ArkGraphics2D'; 7729e41f4b71Sopenharmony_ci 7730e41f4b71Sopenharmony_cifunction getActiveColorSpace(session: camera.PhotoSession): colorSpaceManager.ColorSpace | undefined { 7731e41f4b71Sopenharmony_ci let colorSpace: colorSpaceManager.ColorSpace | undefined = undefined; 7732e41f4b71Sopenharmony_ci try { 7733e41f4b71Sopenharmony_ci colorSpace = session.getActiveColorSpace(); 7734e41f4b71Sopenharmony_ci } catch (error) { 7735e41f4b71Sopenharmony_ci let err = error as BusinessError; 7736e41f4b71Sopenharmony_ci console.error(`The getActiveColorSpace call failed. error code: ${err.code}`); 7737e41f4b71Sopenharmony_ci } 7738e41f4b71Sopenharmony_ci return colorSpace; 7739e41f4b71Sopenharmony_ci} 7740e41f4b71Sopenharmony_ci``` 7741e41f4b71Sopenharmony_ci 7742e41f4b71Sopenharmony_ci## PreconfigType<sup>12+</sup> 7743e41f4b71Sopenharmony_ci 7744e41f4b71Sopenharmony_ciEnumerates the preconfigured resolution types. 7745e41f4b71Sopenharmony_ci 7746e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 7747e41f4b71Sopenharmony_ci 7748e41f4b71Sopenharmony_ci| Name | Value| Description | 7749e41f4b71Sopenharmony_ci|-------------------------|---|------------| 7750e41f4b71Sopenharmony_ci| PRECONFIG_720P | 0 | 720p resolution. | 7751e41f4b71Sopenharmony_ci| PRECONFIG_1080P | 1 | 1080p resolution. | 7752e41f4b71Sopenharmony_ci| PRECONFIG_4K | 2 | 4K resolution. | 7753e41f4b71Sopenharmony_ci| PRECONFIG_HIGH_QUALITY | 3 | High-quality resolution. | 7754e41f4b71Sopenharmony_ci 7755e41f4b71Sopenharmony_ci## PreconfigRatio<sup>12+</sup> 7756e41f4b71Sopenharmony_ci 7757e41f4b71Sopenharmony_ciEnumerates the preconfigured aspect ratios. 7758e41f4b71Sopenharmony_ci 7759e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 7760e41f4b71Sopenharmony_ci 7761e41f4b71Sopenharmony_ci| Name | Value| Description | 7762e41f4b71Sopenharmony_ci|--------------------------|---|---------| 7763e41f4b71Sopenharmony_ci| PRECONFIG_RATIO_1_1 | 0 | 1:1 aspect ratio. | 7764e41f4b71Sopenharmony_ci| PRECONFIG_RATIO_4_3 | 1 | 4:3 aspect ratio. | 7765e41f4b71Sopenharmony_ci| PRECONFIG_RATIO_16_9 | 2 | 16:9 aspect ratio.| 7766e41f4b71Sopenharmony_ci 7767e41f4b71Sopenharmony_ci## PhotoSession<sup>11+</sup> 7768e41f4b71Sopenharmony_ci 7769e41f4b71Sopenharmony_ciPhotoSession extends [Session](#session11), [Flash](#flash11), [AutoExposure](#autoexposure11), [Focus](#focus11), [Zoom](#zoom11), [ColorManagement](#colormanagement12) 7770e41f4b71Sopenharmony_ci 7771e41f4b71Sopenharmony_ciImplements a photo session, which provides operations on the flash, exposure, focus, zoom, and color space. 7772e41f4b71Sopenharmony_ci 7773e41f4b71Sopenharmony_ci> **NOTE** 7774e41f4b71Sopenharmony_ci> 7775e41f4b71Sopenharmony_ci> This class is provided for the default photo mode. It is used to take standard photos. It supports multiple photo formats and resolutions, which are suitable for most daily photographing scenarios. 7776e41f4b71Sopenharmony_ci 7777e41f4b71Sopenharmony_ci### canPreconfig<sup>12+</sup> 7778e41f4b71Sopenharmony_ci 7779e41f4b71Sopenharmony_cicanPreconfig(preconfigType: PreconfigType, preconfigRatio?: PreconfigRatio): boolean 7780e41f4b71Sopenharmony_ci 7781e41f4b71Sopenharmony_ciChecks whether this session supports a preconfigured resolution. 7782e41f4b71Sopenharmony_ci 7783e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 7784e41f4b71Sopenharmony_ci 7785e41f4b71Sopenharmony_ci**Parameters** 7786e41f4b71Sopenharmony_ci 7787e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 7788e41f4b71Sopenharmony_ci|----------------|-------------------------------------|-----|-----------------| 7789e41f4b71Sopenharmony_ci| preconfigType | [PreconfigType](#preconfigtype12) | Yes | Resolution type. | 7790e41f4b71Sopenharmony_ci| preconfigRatio | [PreconfigRatio](#preconfigratio12) | No | Aspect ratio. The default value is 4:3. | 7791e41f4b71Sopenharmony_ci 7792e41f4b71Sopenharmony_ci**Return value** 7793e41f4b71Sopenharmony_ci 7794e41f4b71Sopenharmony_ci| Type | Description | 7795e41f4b71Sopenharmony_ci|---------|-----------------------------------------| 7796e41f4b71Sopenharmony_ci| boolean | **true**: The preconfigured resolution is supported.<br>**false**: The preconfigured resolution is not supported.| 7797e41f4b71Sopenharmony_ci 7798e41f4b71Sopenharmony_ci**Error codes** 7799e41f4b71Sopenharmony_ci 7800e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 7801e41f4b71Sopenharmony_ci 7802e41f4b71Sopenharmony_ci| ID | Error Message | 7803e41f4b71Sopenharmony_ci|---------|-----------------------------| 7804e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 7805e41f4b71Sopenharmony_ci 7806e41f4b71Sopenharmony_ci**Example** 7807e41f4b71Sopenharmony_ci 7808e41f4b71Sopenharmony_ci```ts 7809e41f4b71Sopenharmony_cifunction testCanPreconfig(photoSession: camera.PhotoSession, preconfigType: camera.PreconfigType, 7810e41f4b71Sopenharmony_ci preconfigRatio: camera.PreconfigRatio): void { 7811e41f4b71Sopenharmony_ci try { 7812e41f4b71Sopenharmony_ci let result = photoSession.canPreconfig(preconfigType, preconfigRatio); 7813e41f4b71Sopenharmony_ci console.info(`canPreconfig ${preconfigType} ${preconfigRatio} result is : ${result}`); 7814e41f4b71Sopenharmony_ci } catch (error) { 7815e41f4b71Sopenharmony_ci let err = error as BusinessError; 7816e41f4b71Sopenharmony_ci console.error(`The canPreconfig call failed. error code: ${err.code}`); 7817e41f4b71Sopenharmony_ci } 7818e41f4b71Sopenharmony_ci} 7819e41f4b71Sopenharmony_ci``` 7820e41f4b71Sopenharmony_ci 7821e41f4b71Sopenharmony_ci### preconfig<sup>12+</sup> 7822e41f4b71Sopenharmony_ci 7823e41f4b71Sopenharmony_cipreconfig(preconfigType: PreconfigType, preconfigRatio?: PreconfigRatio): void 7824e41f4b71Sopenharmony_ci 7825e41f4b71Sopenharmony_ciPreconfigures this session. 7826e41f4b71Sopenharmony_ci 7827e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 7828e41f4b71Sopenharmony_ci 7829e41f4b71Sopenharmony_ci**Parameters** 7830e41f4b71Sopenharmony_ci 7831e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 7832e41f4b71Sopenharmony_ci|----------------|-------------------------------------|-----|-----------------| 7833e41f4b71Sopenharmony_ci| preconfigType | [PreconfigType](#preconfigtype12) | Yes | Resolution type. | 7834e41f4b71Sopenharmony_ci| preconfigRatio | [PreconfigRatio](#preconfigratio12) | No | Aspect ratio. The default value is 4:3. | 7835e41f4b71Sopenharmony_ci 7836e41f4b71Sopenharmony_ci**Error codes** 7837e41f4b71Sopenharmony_ci 7838e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 7839e41f4b71Sopenharmony_ci 7840e41f4b71Sopenharmony_ci| ID | Error Message | 7841e41f4b71Sopenharmony_ci|---------|-----------------------------| 7842e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 7843e41f4b71Sopenharmony_ci 7844e41f4b71Sopenharmony_ci**Example** 7845e41f4b71Sopenharmony_ci 7846e41f4b71Sopenharmony_ci```ts 7847e41f4b71Sopenharmony_cifunction testPreconfig(photoSession: camera.PhotoSession, preconfigType: camera.PreconfigType, 7848e41f4b71Sopenharmony_ci preconfigRatio: camera.PreconfigRatio): void { 7849e41f4b71Sopenharmony_ci try { 7850e41f4b71Sopenharmony_ci photoSession.preconfig(preconfigType, preconfigRatio); 7851e41f4b71Sopenharmony_ci console.info(`preconfig ${preconfigType} ${preconfigRatio} success`); 7852e41f4b71Sopenharmony_ci } catch (error) { 7853e41f4b71Sopenharmony_ci let err = error as BusinessError; 7854e41f4b71Sopenharmony_ci console.error(`The preconfig call failed. error code: ${err.code}`); 7855e41f4b71Sopenharmony_ci } 7856e41f4b71Sopenharmony_ci} 7857e41f4b71Sopenharmony_ci``` 7858e41f4b71Sopenharmony_ci 7859e41f4b71Sopenharmony_ci### on('error')<sup>11+</sup> 7860e41f4b71Sopenharmony_ci 7861e41f4b71Sopenharmony_cion(type: 'error', callback: ErrorCallback): void 7862e41f4b71Sopenharmony_ci 7863e41f4b71Sopenharmony_ciSubscribes to **PhotoSession** error events. This API uses an asynchronous callback to return the result. 7864e41f4b71Sopenharmony_ci 7865e41f4b71Sopenharmony_ci> **NOTE** 7866e41f4b71Sopenharmony_ci> 7867e41f4b71Sopenharmony_ci> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**. 7868e41f4b71Sopenharmony_ci 7869e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 7870e41f4b71Sopenharmony_ci 7871e41f4b71Sopenharmony_ci**Parameters** 7872e41f4b71Sopenharmony_ci 7873e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 7874e41f4b71Sopenharmony_ci| -------- | ----------------------------------------------------------- | ---- | ------------------------------ | 7875e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a session is created. This event is triggered and the error message is returned when an error occurs during the calling of a session-related API such as [beginConfig](#beginconfig11), [commitConfig](#commitconfig11-1), and [addInput](#addinput11).| 7876e41f4b71Sopenharmony_ci| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback)| Yes | Callback used to return an error code defined in [CameraErrorCode](#cameraerrorcode). | 7877e41f4b71Sopenharmony_ci 7878e41f4b71Sopenharmony_ci**Example** 7879e41f4b71Sopenharmony_ci 7880e41f4b71Sopenharmony_ci```ts 7881e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 7882e41f4b71Sopenharmony_ci 7883e41f4b71Sopenharmony_cifunction callback(err: BusinessError): void { 7884e41f4b71Sopenharmony_ci console.error(`Photo session error code: ${err.code}`); 7885e41f4b71Sopenharmony_ci} 7886e41f4b71Sopenharmony_ci 7887e41f4b71Sopenharmony_cifunction registerSessionError(photoSession: camera.PhotoSession): void { 7888e41f4b71Sopenharmony_ci photoSession.on('error', callback); 7889e41f4b71Sopenharmony_ci} 7890e41f4b71Sopenharmony_ci``` 7891e41f4b71Sopenharmony_ci 7892e41f4b71Sopenharmony_ci### off('error')<sup>11+</sup> 7893e41f4b71Sopenharmony_ci 7894e41f4b71Sopenharmony_cioff(type: 'error', callback?: ErrorCallback): void 7895e41f4b71Sopenharmony_ci 7896e41f4b71Sopenharmony_ciUnsubscribes from **PhotoSession** error events. This API uses a callback to return the result. 7897e41f4b71Sopenharmony_ci 7898e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 7899e41f4b71Sopenharmony_ci 7900e41f4b71Sopenharmony_ci**Parameters** 7901e41f4b71Sopenharmony_ci 7902e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 7903e41f4b71Sopenharmony_ci| -------- | -------------------------------- | ---- | ------------------------------ | 7904e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a session is created.| 7905e41f4b71Sopenharmony_ci| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback)| No | Callback used to return the result. If this parameter is specified, the subscription to the specified event with the specified callback is canceled. (The callback object cannot be an anonymous function.) Otherwise, the subscriptions to the specified event with all the callbacks are canceled.| 7906e41f4b71Sopenharmony_ci 7907e41f4b71Sopenharmony_ci**Example** 7908e41f4b71Sopenharmony_ci 7909e41f4b71Sopenharmony_ci```ts 7910e41f4b71Sopenharmony_cifunction unregisterSessionError(photoSession: camera.PhotoSession): void { 7911e41f4b71Sopenharmony_ci photoSession.off('error'); 7912e41f4b71Sopenharmony_ci} 7913e41f4b71Sopenharmony_ci``` 7914e41f4b71Sopenharmony_ci 7915e41f4b71Sopenharmony_ci### on('focusStateChange')<sup>11+</sup> 7916e41f4b71Sopenharmony_ci 7917e41f4b71Sopenharmony_cion(type: 'focusStateChange', callback: AsyncCallback\<FocusState\>): void 7918e41f4b71Sopenharmony_ci 7919e41f4b71Sopenharmony_ciSubscribes to focus state change events. This API uses an asynchronous callback to return the result. 7920e41f4b71Sopenharmony_ci 7921e41f4b71Sopenharmony_ci> **NOTE** 7922e41f4b71Sopenharmony_ci> 7923e41f4b71Sopenharmony_ci> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**. 7924e41f4b71Sopenharmony_ci 7925e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 7926e41f4b71Sopenharmony_ci 7927e41f4b71Sopenharmony_ci**Parameters** 7928e41f4b71Sopenharmony_ci 7929e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 7930e41f4b71Sopenharmony_ci| -------- | ---------------- | ---- | ------------------------ | 7931e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'focusStateChange'**. The event can be listened for when a session is created. This event is triggered only when the camera focus state changes in auto focus mode.| 7932e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[FocusState](#focusstate)\> | Yes | Callback used to return the focus state change. | 7933e41f4b71Sopenharmony_ci 7934e41f4b71Sopenharmony_ci**Example** 7935e41f4b71Sopenharmony_ci 7936e41f4b71Sopenharmony_ci```ts 7937e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 7938e41f4b71Sopenharmony_ci 7939e41f4b71Sopenharmony_cifunction callback(err: BusinessError, focusState: camera.FocusState): void { 7940e41f4b71Sopenharmony_ci if (err !== undefined && err.code !== 0) { 7941e41f4b71Sopenharmony_ci console.error(`Callback Error, errorCode: ${err.code}`); 7942e41f4b71Sopenharmony_ci return; 7943e41f4b71Sopenharmony_ci } 7944e41f4b71Sopenharmony_ci console.info(`Focus state: ${focusState}`); 7945e41f4b71Sopenharmony_ci} 7946e41f4b71Sopenharmony_ci 7947e41f4b71Sopenharmony_cifunction registerFocusStateChange(photoSession: camera.PhotoSession): void { 7948e41f4b71Sopenharmony_ci photoSession.on('focusStateChange', callback); 7949e41f4b71Sopenharmony_ci} 7950e41f4b71Sopenharmony_ci``` 7951e41f4b71Sopenharmony_ci 7952e41f4b71Sopenharmony_ci### off('focusStateChange')<sup>11+</sup> 7953e41f4b71Sopenharmony_ci 7954e41f4b71Sopenharmony_cioff(type: 'focusStateChange', callback?: AsyncCallback\<FocusState\>): void 7955e41f4b71Sopenharmony_ci 7956e41f4b71Sopenharmony_ciUnsubscribes from focus state change events. 7957e41f4b71Sopenharmony_ci 7958e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 7959e41f4b71Sopenharmony_ci 7960e41f4b71Sopenharmony_ci**Parameters** 7961e41f4b71Sopenharmony_ci 7962e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 7963e41f4b71Sopenharmony_ci| -------- | ----------------------------------------- | ---- | ------------------------ | 7964e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'focusStateChange'**. The event can be listened for when a session is created.| 7965e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[FocusState](#focusstate)\> | No | Callback used to return the result. If this parameter is specified, the subscription to the specified event with the specified callback is canceled. (The callback object cannot be an anonymous function.) Otherwise, the subscriptions to the specified event with all the callbacks are canceled.| 7966e41f4b71Sopenharmony_ci 7967e41f4b71Sopenharmony_ci**Example** 7968e41f4b71Sopenharmony_ci 7969e41f4b71Sopenharmony_ci```ts 7970e41f4b71Sopenharmony_cifunction unregisterFocusStateChange(photoSession: camera.PhotoSession): void { 7971e41f4b71Sopenharmony_ci photoSession.off('focusStateChange'); 7972e41f4b71Sopenharmony_ci} 7973e41f4b71Sopenharmony_ci``` 7974e41f4b71Sopenharmony_ci 7975e41f4b71Sopenharmony_ci### on('smoothZoomInfoAvailable')<sup>11+</sup> 7976e41f4b71Sopenharmony_ci 7977e41f4b71Sopenharmony_cion(type: 'smoothZoomInfoAvailable', callback: AsyncCallback\<SmoothZoomInfo\>): void 7978e41f4b71Sopenharmony_ci 7979e41f4b71Sopenharmony_ciSubscribes to smooth zoom state change events. This API uses an asynchronous callback to return the result. 7980e41f4b71Sopenharmony_ci 7981e41f4b71Sopenharmony_ci> **NOTE** 7982e41f4b71Sopenharmony_ci> 7983e41f4b71Sopenharmony_ci> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**. 7984e41f4b71Sopenharmony_ci 7985e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 7986e41f4b71Sopenharmony_ci 7987e41f4b71Sopenharmony_ci**Parameters** 7988e41f4b71Sopenharmony_ci 7989e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 7990e41f4b71Sopenharmony_ci| -------- | ----------------------- | ---- | ------------------------ | 7991e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'smoothZoomInfoAvailable'**. The event can be listened for when a session is created.| 7992e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[SmoothZoomInfo](#smoothzoominfo11)\> | Yes | Callback used to return the smooth zoom state change. | 7993e41f4b71Sopenharmony_ci 7994e41f4b71Sopenharmony_ci**Example** 7995e41f4b71Sopenharmony_ci 7996e41f4b71Sopenharmony_ci```ts 7997e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 7998e41f4b71Sopenharmony_ci 7999e41f4b71Sopenharmony_cifunction callback(err: BusinessError, smoothZoomInfo: camera.SmoothZoomInfo): void { 8000e41f4b71Sopenharmony_ci if (err !== undefined && err.code !== 0) { 8001e41f4b71Sopenharmony_ci console.error(`Callback Error, errorCode: ${err.code}`); 8002e41f4b71Sopenharmony_ci return; 8003e41f4b71Sopenharmony_ci } 8004e41f4b71Sopenharmony_ci console.info(`The duration of smooth zoom: ${smoothZoomInfo.duration}`); 8005e41f4b71Sopenharmony_ci} 8006e41f4b71Sopenharmony_ci 8007e41f4b71Sopenharmony_cifunction registerSmoothZoomInfo(photoSession: camera.PhotoSession): void { 8008e41f4b71Sopenharmony_ci photoSession.on('smoothZoomInfoAvailable', callback); 8009e41f4b71Sopenharmony_ci} 8010e41f4b71Sopenharmony_ci``` 8011e41f4b71Sopenharmony_ci 8012e41f4b71Sopenharmony_ci### off('smoothZoomInfoAvailable')<sup>11+</sup> 8013e41f4b71Sopenharmony_ci 8014e41f4b71Sopenharmony_cioff(type: 'smoothZoomInfoAvailable', callback?: AsyncCallback\<SmoothZoomInfo\>): void 8015e41f4b71Sopenharmony_ci 8016e41f4b71Sopenharmony_ciUnsubscribes from smooth zoom state change events. 8017e41f4b71Sopenharmony_ci 8018e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 8019e41f4b71Sopenharmony_ci 8020e41f4b71Sopenharmony_ci**Parameters** 8021e41f4b71Sopenharmony_ci 8022e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 8023e41f4b71Sopenharmony_ci| -------- | ----------------------------------------- | ---- | ------------------------ | 8024e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'smoothZoomInfoAvailable'**. The event can be listened for when a session is created.| 8025e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[SmoothZoomInfo](#smoothzoominfo11)\> | No | Callback used to return the result. If this parameter is specified, the subscription to the specified event with the specified callback is canceled. (The callback object cannot be an anonymous function.) Otherwise, the subscriptions to the specified event with all the callbacks are canceled.| 8026e41f4b71Sopenharmony_ci 8027e41f4b71Sopenharmony_ci**Example** 8028e41f4b71Sopenharmony_ci 8029e41f4b71Sopenharmony_ci```ts 8030e41f4b71Sopenharmony_cifunction unregisterSmoothZoomInfo(photoSession: camera.PhotoSession): void { 8031e41f4b71Sopenharmony_ci photoSession.off('smoothZoomInfoAvailable'); 8032e41f4b71Sopenharmony_ci} 8033e41f4b71Sopenharmony_ci``` 8034e41f4b71Sopenharmony_ci 8035e41f4b71Sopenharmony_ci## VideoSession<sup>11+</sup> 8036e41f4b71Sopenharmony_ci 8037e41f4b71Sopenharmony_ciVideoSession extends [Session](#session11), [Flash](#flash11), [AutoExposure](#autoexposure11), [Focus](#focus11), [Zoom](#zoom11), [Stabilization](#stabilization11), [ColorManagement](#colormanagement12) 8038e41f4b71Sopenharmony_ci 8039e41f4b71Sopenharmony_ciImplements a video session, which provides operations on the flash, exposure, focus, zoom, video stabilization, and color space. 8040e41f4b71Sopenharmony_ci 8041e41f4b71Sopenharmony_ci> **NOTE** 8042e41f4b71Sopenharmony_ci> 8043e41f4b71Sopenharmony_ci> This class is provided for the default video recording mode. It applies to common scenarios. It supports recording at various resolutions (such as 720p and 1080p) and frame rates (such as 30 fps and 60 fps). 8044e41f4b71Sopenharmony_ci 8045e41f4b71Sopenharmony_ci### canPreconfig<sup>12+</sup> 8046e41f4b71Sopenharmony_ci 8047e41f4b71Sopenharmony_cicanPreconfig(preconfigType: PreconfigType), preconfigRatio?: PreconfigRatio): boolean 8048e41f4b71Sopenharmony_ci 8049e41f4b71Sopenharmony_ciChecks whether this session supports a preconfigured resolution. 8050e41f4b71Sopenharmony_ci 8051e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 8052e41f4b71Sopenharmony_ci 8053e41f4b71Sopenharmony_ci**Parameters** 8054e41f4b71Sopenharmony_ci 8055e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 8056e41f4b71Sopenharmony_ci|----------------|-------------------------------------|-----|-----------------| 8057e41f4b71Sopenharmony_ci| preconfigType | [PreconfigType](#preconfigtype12) | Yes | Resolution type. | 8058e41f4b71Sopenharmony_ci| preconfigRatio | [PreconfigRatio](#preconfigratio12) | No | Aspect ratio. The default value is 16:9.| 8059e41f4b71Sopenharmony_ci 8060e41f4b71Sopenharmony_ci**Return value** 8061e41f4b71Sopenharmony_ci 8062e41f4b71Sopenharmony_ci| Type | Description | 8063e41f4b71Sopenharmony_ci|---------|-----------------------------------------| 8064e41f4b71Sopenharmony_ci| boolean | **true**: The preconfigured resolution is supported.<br>**false**: The preconfigured resolution is not supported.| 8065e41f4b71Sopenharmony_ci 8066e41f4b71Sopenharmony_ci**Error codes** 8067e41f4b71Sopenharmony_ci 8068e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 8069e41f4b71Sopenharmony_ci 8070e41f4b71Sopenharmony_ci| ID | Error Message | 8071e41f4b71Sopenharmony_ci|---------|-----------------------------| 8072e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 8073e41f4b71Sopenharmony_ci 8074e41f4b71Sopenharmony_ci**Example** 8075e41f4b71Sopenharmony_ci 8076e41f4b71Sopenharmony_ci```ts 8077e41f4b71Sopenharmony_cifunction testCanPreconfig(videoSession: camera.VideoSession, preconfigType: camera.PreconfigType, 8078e41f4b71Sopenharmony_ci preconfigRatio: camera.PreconfigRatio): void { 8079e41f4b71Sopenharmony_ci try { 8080e41f4b71Sopenharmony_ci let result = videoSession.canPreconfig(preconfigType, preconfigRatio); 8081e41f4b71Sopenharmony_ci console.info(`canPreconfig ${preconfigType} ${preconfigRatio} result is : ${result}`); 8082e41f4b71Sopenharmony_ci } catch (error) { 8083e41f4b71Sopenharmony_ci let err = error as BusinessError; 8084e41f4b71Sopenharmony_ci console.error(`The canPreconfig call failed. error code: ${err.code}`); 8085e41f4b71Sopenharmony_ci } 8086e41f4b71Sopenharmony_ci} 8087e41f4b71Sopenharmony_ci``` 8088e41f4b71Sopenharmony_ci 8089e41f4b71Sopenharmony_ci### preconfig<sup>12+</sup> 8090e41f4b71Sopenharmony_ci 8091e41f4b71Sopenharmony_cipreconfig(preconfigType: PreconfigType, preconfigRatio?: PreconfigRatio): void 8092e41f4b71Sopenharmony_ci 8093e41f4b71Sopenharmony_ciPreconfigures this session. 8094e41f4b71Sopenharmony_ci 8095e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 8096e41f4b71Sopenharmony_ci 8097e41f4b71Sopenharmony_ci**Parameters** 8098e41f4b71Sopenharmony_ci 8099e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 8100e41f4b71Sopenharmony_ci|----------------|-------------------------------------|-----|-----------------| 8101e41f4b71Sopenharmony_ci| preconfigType | [PreconfigType](#preconfigtype12) | Yes | Resolution type. | 8102e41f4b71Sopenharmony_ci| preconfigRatio | [PreconfigRatio](#preconfigratio12) | No | Aspect ratio. The default value is 16:9.| 8103e41f4b71Sopenharmony_ci 8104e41f4b71Sopenharmony_ci**Error codes** 8105e41f4b71Sopenharmony_ci 8106e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 8107e41f4b71Sopenharmony_ci 8108e41f4b71Sopenharmony_ci| ID | Error Message | 8109e41f4b71Sopenharmony_ci|---------|-----------------------------| 8110e41f4b71Sopenharmony_ci| 7400201 | Camera service fatal error. | 8111e41f4b71Sopenharmony_ci 8112e41f4b71Sopenharmony_ci**Example** 8113e41f4b71Sopenharmony_ci 8114e41f4b71Sopenharmony_ci```ts 8115e41f4b71Sopenharmony_cifunction testPreconfig(videoSession: camera.VideoSession, preconfigType: camera.PreconfigType, 8116e41f4b71Sopenharmony_ci preconfigRatio: camera.PreconfigRatio): void { 8117e41f4b71Sopenharmony_ci try { 8118e41f4b71Sopenharmony_ci videoSession.preconfig(preconfigType, preconfigRatio); 8119e41f4b71Sopenharmony_ci console.info(`preconfig ${preconfigType} ${preconfigRatio} success`); 8120e41f4b71Sopenharmony_ci } catch (error) { 8121e41f4b71Sopenharmony_ci let err = error as BusinessError; 8122e41f4b71Sopenharmony_ci console.error(`The preconfig call failed. error code: ${err.code}`); 8123e41f4b71Sopenharmony_ci } 8124e41f4b71Sopenharmony_ci} 8125e41f4b71Sopenharmony_ci``` 8126e41f4b71Sopenharmony_ci 8127e41f4b71Sopenharmony_ci### on('error')<sup>11+</sup> 8128e41f4b71Sopenharmony_ci 8129e41f4b71Sopenharmony_cion(type: 'error', callback: ErrorCallback): void 8130e41f4b71Sopenharmony_ci 8131e41f4b71Sopenharmony_ciSubscribes to **VideoSession** error events. This API uses an asynchronous callback to return the result. 8132e41f4b71Sopenharmony_ci 8133e41f4b71Sopenharmony_ci> **NOTE** 8134e41f4b71Sopenharmony_ci> 8135e41f4b71Sopenharmony_ci> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**. 8136e41f4b71Sopenharmony_ci 8137e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 8138e41f4b71Sopenharmony_ci 8139e41f4b71Sopenharmony_ci**Parameters** 8140e41f4b71Sopenharmony_ci 8141e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 8142e41f4b71Sopenharmony_ci| -------- | ------------------ | ---- | ------------------------------ | 8143e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a session is created. This event is triggered and the error message is returned when an error occurs during the calling of a session-related API such as [beginConfig](#beginconfig11), [commitConfig](#commitconfig11-1), and [addInput](#addinput11).| 8144e41f4b71Sopenharmony_ci| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | Yes | Callback used to return an error code defined in [CameraErrorCode](#cameraerrorcode). | 8145e41f4b71Sopenharmony_ci 8146e41f4b71Sopenharmony_ci**Example** 8147e41f4b71Sopenharmony_ci 8148e41f4b71Sopenharmony_ci```ts 8149e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 8150e41f4b71Sopenharmony_ci 8151e41f4b71Sopenharmony_cifunction callback(err: BusinessError): void { 8152e41f4b71Sopenharmony_ci console.error(`Video session error code: ${err.code}`); 8153e41f4b71Sopenharmony_ci} 8154e41f4b71Sopenharmony_ci 8155e41f4b71Sopenharmony_cifunction registerSessionError(videoSession: camera.VideoSession): void { 8156e41f4b71Sopenharmony_ci videoSession.on('error', callback); 8157e41f4b71Sopenharmony_ci} 8158e41f4b71Sopenharmony_ci``` 8159e41f4b71Sopenharmony_ci 8160e41f4b71Sopenharmony_ci### off('error')<sup>11+</sup> 8161e41f4b71Sopenharmony_ci 8162e41f4b71Sopenharmony_cioff(type: 'error', callback?: ErrorCallback): void 8163e41f4b71Sopenharmony_ci 8164e41f4b71Sopenharmony_ciUnsubscribes from **VideoSession** error events. This API uses a callback to return the result. 8165e41f4b71Sopenharmony_ci 8166e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 8167e41f4b71Sopenharmony_ci 8168e41f4b71Sopenharmony_ci**Parameters** 8169e41f4b71Sopenharmony_ci 8170e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 8171e41f4b71Sopenharmony_ci| -------- | --------------------------- | ---- | ------------------------------ | 8172e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a session is created.| 8173e41f4b71Sopenharmony_ci| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback)| No | Callback used to return the result. If this parameter is specified, the subscription to the specified event with the specified callback is canceled. (The callback object cannot be an anonymous function.) Otherwise, the subscriptions to the specified event with all the callbacks are canceled.| 8174e41f4b71Sopenharmony_ci 8175e41f4b71Sopenharmony_ci**Example** 8176e41f4b71Sopenharmony_ci 8177e41f4b71Sopenharmony_ci```ts 8178e41f4b71Sopenharmony_cifunction unregisterSessionError(videoSession: camera.VideoSession): void { 8179e41f4b71Sopenharmony_ci videoSession.off('error'); 8180e41f4b71Sopenharmony_ci} 8181e41f4b71Sopenharmony_ci``` 8182e41f4b71Sopenharmony_ci 8183e41f4b71Sopenharmony_ci### on('focusStateChange')<sup>11+</sup> 8184e41f4b71Sopenharmony_ci 8185e41f4b71Sopenharmony_cion(type: 'focusStateChange', callback: AsyncCallback\<FocusState\>): void 8186e41f4b71Sopenharmony_ci 8187e41f4b71Sopenharmony_ciSubscribes to focus state change events. This API uses an asynchronous callback to return the result. 8188e41f4b71Sopenharmony_ci 8189e41f4b71Sopenharmony_ci> **NOTE** 8190e41f4b71Sopenharmony_ci> 8191e41f4b71Sopenharmony_ci> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**. 8192e41f4b71Sopenharmony_ci 8193e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 8194e41f4b71Sopenharmony_ci 8195e41f4b71Sopenharmony_ci**Parameters** 8196e41f4b71Sopenharmony_ci 8197e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 8198e41f4b71Sopenharmony_ci| -------- | ---------------- | ---- | ------------------------ | 8199e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'focusStateChange'**. The event can be listened for when a session is created. This event is triggered only when the camera focus state changes in auto focus mode.| 8200e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[FocusState](#focusstate)\> | Yes | Callback used to return the focus state change. | 8201e41f4b71Sopenharmony_ci 8202e41f4b71Sopenharmony_ci**Example** 8203e41f4b71Sopenharmony_ci 8204e41f4b71Sopenharmony_ci```ts 8205e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 8206e41f4b71Sopenharmony_ci 8207e41f4b71Sopenharmony_cifunction callback(err: BusinessError, focusState: camera.FocusState): void { 8208e41f4b71Sopenharmony_ci if (err !== undefined && err.code !== 0) { 8209e41f4b71Sopenharmony_ci console.error(`Callback Error, errorCode: ${err.code}`); 8210e41f4b71Sopenharmony_ci return; 8211e41f4b71Sopenharmony_ci } 8212e41f4b71Sopenharmony_ci console.info(`Focus state: ${focusState}`); 8213e41f4b71Sopenharmony_ci} 8214e41f4b71Sopenharmony_ci 8215e41f4b71Sopenharmony_cifunction registerFocusStateChange(videoSession: camera.VideoSession): void { 8216e41f4b71Sopenharmony_ci videoSession.on('focusStateChange', callback); 8217e41f4b71Sopenharmony_ci} 8218e41f4b71Sopenharmony_ci``` 8219e41f4b71Sopenharmony_ci 8220e41f4b71Sopenharmony_ci### off('focusStateChange')<sup>11+</sup> 8221e41f4b71Sopenharmony_ci 8222e41f4b71Sopenharmony_cioff(type: 'focusStateChange', callback?: AsyncCallback\<FocusState\>): void 8223e41f4b71Sopenharmony_ci 8224e41f4b71Sopenharmony_ciUnsubscribes from focus state change events. 8225e41f4b71Sopenharmony_ci 8226e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 8227e41f4b71Sopenharmony_ci 8228e41f4b71Sopenharmony_ci**Parameters** 8229e41f4b71Sopenharmony_ci 8230e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 8231e41f4b71Sopenharmony_ci| -------- | ----------------------------------------- | ---- | ------------------------ | 8232e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'focusStateChange'**. The event can be listened for when a session is created.| 8233e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[FocusState](#focusstate)\> | No | Callback used to return the result. If this parameter is specified, the subscription to the specified event with the specified callback is canceled. (The callback object cannot be an anonymous function.) Otherwise, the subscriptions to the specified event with all the callbacks are canceled.| 8234e41f4b71Sopenharmony_ci 8235e41f4b71Sopenharmony_ci**Example** 8236e41f4b71Sopenharmony_ci 8237e41f4b71Sopenharmony_ci```ts 8238e41f4b71Sopenharmony_cifunction unregisterFocusStateChange(videoSession: camera.VideoSession): void { 8239e41f4b71Sopenharmony_ci videoSession.off('focusStateChange'); 8240e41f4b71Sopenharmony_ci} 8241e41f4b71Sopenharmony_ci``` 8242e41f4b71Sopenharmony_ci 8243e41f4b71Sopenharmony_ci### on('smoothZoomInfoAvailable')<sup>11+</sup> 8244e41f4b71Sopenharmony_ci 8245e41f4b71Sopenharmony_cion(type: 'smoothZoomInfoAvailable', callback: AsyncCallback\<SmoothZoomInfo\>): void 8246e41f4b71Sopenharmony_ci 8247e41f4b71Sopenharmony_ciSubscribes to smooth zoom state change events. This API uses an asynchronous callback to return the result. 8248e41f4b71Sopenharmony_ci 8249e41f4b71Sopenharmony_ci> **NOTE** 8250e41f4b71Sopenharmony_ci> 8251e41f4b71Sopenharmony_ci> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**. 8252e41f4b71Sopenharmony_ci 8253e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 8254e41f4b71Sopenharmony_ci 8255e41f4b71Sopenharmony_ci**Parameters** 8256e41f4b71Sopenharmony_ci 8257e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 8258e41f4b71Sopenharmony_ci| -------- | ----------------------- | ---- | ------------------------ | 8259e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'smoothZoomInfoAvailable'**. The event can be listened for when a session is created.| 8260e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[SmoothZoomInfo](#smoothzoominfo11)\> | Yes | Callback used to return the smooth zoom state change. | 8261e41f4b71Sopenharmony_ci 8262e41f4b71Sopenharmony_ci**Example** 8263e41f4b71Sopenharmony_ci 8264e41f4b71Sopenharmony_ci```ts 8265e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 8266e41f4b71Sopenharmony_ci 8267e41f4b71Sopenharmony_cifunction callback(err: BusinessError, smoothZoomInfo: camera.SmoothZoomInfo): void { 8268e41f4b71Sopenharmony_ci if (err !== undefined && err.code !== 0) { 8269e41f4b71Sopenharmony_ci console.error(`Callback Error, errorCode: ${err.code}`); 8270e41f4b71Sopenharmony_ci return; 8271e41f4b71Sopenharmony_ci } 8272e41f4b71Sopenharmony_ci console.info(`The duration of smooth zoom: ${smoothZoomInfo.duration}`); 8273e41f4b71Sopenharmony_ci} 8274e41f4b71Sopenharmony_ci 8275e41f4b71Sopenharmony_cifunction registerSmoothZoomInfo(videoSession: camera.VideoSession): void { 8276e41f4b71Sopenharmony_ci videoSession.on('smoothZoomInfoAvailable', callback); 8277e41f4b71Sopenharmony_ci} 8278e41f4b71Sopenharmony_ci``` 8279e41f4b71Sopenharmony_ci 8280e41f4b71Sopenharmony_ci### off('smoothZoomInfoAvailable')<sup>11+</sup> 8281e41f4b71Sopenharmony_ci 8282e41f4b71Sopenharmony_cioff(type: 'smoothZoomInfoAvailable', callback?: AsyncCallback\<SmoothZoomInfo\>): void 8283e41f4b71Sopenharmony_ci 8284e41f4b71Sopenharmony_ciUnsubscribes from smooth zoom state change events. 8285e41f4b71Sopenharmony_ci 8286e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 8287e41f4b71Sopenharmony_ci 8288e41f4b71Sopenharmony_ci**Parameters** 8289e41f4b71Sopenharmony_ci 8290e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 8291e41f4b71Sopenharmony_ci| -------- | ----------------------------------------- | ---- | ------------------------ | 8292e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'smoothZoomInfoAvailable'**. The event can be listened for when a session is created.| 8293e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[SmoothZoomInfo](#smoothzoominfo11)\> | No | Callback used to return the result. If this parameter is specified, the subscription to the specified event with the specified callback is canceled. (The callback object cannot be an anonymous function.) Otherwise, the subscriptions to the specified event with all the callbacks are canceled.| 8294e41f4b71Sopenharmony_ci 8295e41f4b71Sopenharmony_ci**Example** 8296e41f4b71Sopenharmony_ci 8297e41f4b71Sopenharmony_ci```ts 8298e41f4b71Sopenharmony_cifunction unregisterSmoothZoomInfo(videoSession: camera.VideoSession): void { 8299e41f4b71Sopenharmony_ci videoSession.off('smoothZoomInfoAvailable'); 8300e41f4b71Sopenharmony_ci} 8301e41f4b71Sopenharmony_ci``` 8302e41f4b71Sopenharmony_ci 8303e41f4b71Sopenharmony_ci## SecureSession<sup>12+</sup> 8304e41f4b71Sopenharmony_ci 8305e41f4b71Sopenharmony_ciSecureSession extends [Session](#session11), [Flash](#flash11), [AutoExposure](#autoexposure11), [Focus](#focus11), [Zoom](#zoom11) 8306e41f4b71Sopenharmony_ci 8307e41f4b71Sopenharmony_ciImplements a secure session, which provides operations on the flash, exposure, focus, and zoom. 8308e41f4b71Sopenharmony_ci 8309e41f4b71Sopenharmony_ci> **NOTE** 8310e41f4b71Sopenharmony_ci> 8311e41f4b71Sopenharmony_ci> You can call [createSession](#createsession11) with [SceneMode](#scenemode11) set to **SECURE_PHOTO** to create a session in secure mode. This class is designed for applications with high security requirements, such as facial recognition systems and banking services. It must be used together with the security TA to support service scenarios where both standard preview streams and security streams are generated. 8312e41f4b71Sopenharmony_ci> The security TA can verify the signature of data delivered by the server, sign images, parse and assemble TLV logic, and read, create, and operate keys. It applies to image processing. 8313e41f4b71Sopenharmony_ci 8314e41f4b71Sopenharmony_ci### addSecureOutput<sup>12+</sup> 8315e41f4b71Sopenharmony_ci 8316e41f4b71Sopenharmony_ciaddSecureOutput(previewOutput: PreviewOutput): void 8317e41f4b71Sopenharmony_ci 8318e41f4b71Sopenharmony_ciMarks a [PreviewOutput](#previewoutput) stream as secure output. 8319e41f4b71Sopenharmony_ci 8320e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 8321e41f4b71Sopenharmony_ci 8322e41f4b71Sopenharmony_ci**Parameters** 8323e41f4b71Sopenharmony_ci 8324e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 8325e41f4b71Sopenharmony_ci| ------------- | ------------------------------- | ---- |---------------| 8326e41f4b71Sopenharmony_ci| previewOutput | [PreviewOutput](#previewoutput) | Yes | Preview output stream.| 8327e41f4b71Sopenharmony_ci 8328e41f4b71Sopenharmony_ci**Error codes** 8329e41f4b71Sopenharmony_ci 8330e41f4b71Sopenharmony_ciFor details about the error codes, see [Camera Error Codes](errorcode-camera.md). 8331e41f4b71Sopenharmony_ci 8332e41f4b71Sopenharmony_ci| ID | Error Message | 8333e41f4b71Sopenharmony_ci| --------------- | --------------- | 8334e41f4b71Sopenharmony_ci| 7400101 | Parameter missing or parameter type incorrect. | 8335e41f4b71Sopenharmony_ci| 7400102 | Operation not allowed. | 8336e41f4b71Sopenharmony_ci| 7400103 | Session not config. | 8337e41f4b71Sopenharmony_ci 8338e41f4b71Sopenharmony_ci**Example** 8339e41f4b71Sopenharmony_ci 8340e41f4b71Sopenharmony_ci```ts 8341e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 8342e41f4b71Sopenharmony_ci 8343e41f4b71Sopenharmony_cifunction addSecureOutput(session: camera.SecureSession, previewOutput: camera.PreviewOutput): void { 8344e41f4b71Sopenharmony_ci try { 8345e41f4b71Sopenharmony_ci session.addSecureOutput(previewOutput); 8346e41f4b71Sopenharmony_ci } catch (error) { 8347e41f4b71Sopenharmony_ci // If the operation fails, error.code is returned and processed. 8348e41f4b71Sopenharmony_ci let err = error as BusinessError; 8349e41f4b71Sopenharmony_ci console.error(`The addOutput call failed. error code: ${err.code}`); 8350e41f4b71Sopenharmony_ci } 8351e41f4b71Sopenharmony_ci} 8352e41f4b71Sopenharmony_ci``` 8353e41f4b71Sopenharmony_ci### on('error')<sup>12+</sup> 8354e41f4b71Sopenharmony_ci 8355e41f4b71Sopenharmony_cion(type: 'error', callback: ErrorCallback): void 8356e41f4b71Sopenharmony_ci 8357e41f4b71Sopenharmony_ciSubscribes to **SecureSession** error events. This API uses an asynchronous callback to return the result. 8358e41f4b71Sopenharmony_ci 8359e41f4b71Sopenharmony_ci> **NOTE** 8360e41f4b71Sopenharmony_ci> 8361e41f4b71Sopenharmony_ci> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**. 8362e41f4b71Sopenharmony_ci 8363e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 8364e41f4b71Sopenharmony_ci 8365e41f4b71Sopenharmony_ci**Parameters** 8366e41f4b71Sopenharmony_ci 8367e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 8368e41f4b71Sopenharmony_ci| -------- | ------------------ | ---- | ------------------------------ | 8369e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a session is created. This event is triggered and the error message is returned when an error occurs during the calling of a session-related API such as [beginConfig](#beginconfig11), [commitConfig](#commitconfig11-1), and [addInput](#addinput11).| 8370e41f4b71Sopenharmony_ci| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | Yes | Callback used to return an error code defined in [CameraErrorCode](#cameraerrorcode). | 8371e41f4b71Sopenharmony_ci 8372e41f4b71Sopenharmony_ci**Example** 8373e41f4b71Sopenharmony_ci 8374e41f4b71Sopenharmony_ci```ts 8375e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 8376e41f4b71Sopenharmony_ci 8377e41f4b71Sopenharmony_cifunction callback(err: BusinessError): void { 8378e41f4b71Sopenharmony_ci console.error(`Video session error code: ${err.code}`); 8379e41f4b71Sopenharmony_ci} 8380e41f4b71Sopenharmony_ci 8381e41f4b71Sopenharmony_cifunction registerSessionError(secureSession: camera.SecureSession): void { 8382e41f4b71Sopenharmony_ci secureSession.on('error', callback); 8383e41f4b71Sopenharmony_ci} 8384e41f4b71Sopenharmony_ci``` 8385e41f4b71Sopenharmony_ci 8386e41f4b71Sopenharmony_ci### off('error')<sup>12+</sup> 8387e41f4b71Sopenharmony_ci 8388e41f4b71Sopenharmony_cioff(type: 'error', callback?: ErrorCallback): void 8389e41f4b71Sopenharmony_ci 8390e41f4b71Sopenharmony_ciUnsubscribes from **SecureSession** error events. 8391e41f4b71Sopenharmony_ci 8392e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 8393e41f4b71Sopenharmony_ci 8394e41f4b71Sopenharmony_ci**Parameters** 8395e41f4b71Sopenharmony_ci 8396e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 8397e41f4b71Sopenharmony_ci| -------- | --------------------------- | ---- | ------------------------------ | 8398e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a session is created.| 8399e41f4b71Sopenharmony_ci| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback)| No | Callback used to return the result. If this parameter is specified, the subscription to the specified event with the specified callback is canceled. (The callback object cannot be an anonymous function.) Otherwise, the subscriptions to the specified event with all the callbacks are canceled.| 8400e41f4b71Sopenharmony_ci 8401e41f4b71Sopenharmony_ci**Example** 8402e41f4b71Sopenharmony_ci 8403e41f4b71Sopenharmony_ci```ts 8404e41f4b71Sopenharmony_cifunction unregisterSessionError(secureSession: camera.SecureSession): void { 8405e41f4b71Sopenharmony_ci secureSession.off('error'); 8406e41f4b71Sopenharmony_ci} 8407e41f4b71Sopenharmony_ci``` 8408e41f4b71Sopenharmony_ci 8409e41f4b71Sopenharmony_ci### on('focusStateChange')<sup>12+</sup> 8410e41f4b71Sopenharmony_ci 8411e41f4b71Sopenharmony_cion(type: 'focusStateChange', callback: AsyncCallback\<FocusState\>): void 8412e41f4b71Sopenharmony_ci 8413e41f4b71Sopenharmony_ciSubscribes to focus state change events. This API uses an asynchronous callback to return the result. 8414e41f4b71Sopenharmony_ci 8415e41f4b71Sopenharmony_ci> **NOTE** 8416e41f4b71Sopenharmony_ci> 8417e41f4b71Sopenharmony_ci> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**. 8418e41f4b71Sopenharmony_ci 8419e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 8420e41f4b71Sopenharmony_ci 8421e41f4b71Sopenharmony_ci**Parameters** 8422e41f4b71Sopenharmony_ci 8423e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 8424e41f4b71Sopenharmony_ci| -------- | ---------------- | ---- | ------------------------ | 8425e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'focusStateChange'**. The event can be listened for when a session is created. This event is triggered only when the camera focus state changes in auto focus mode.| 8426e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[FocusState](#focusstate)\> | Yes | Callback used to return the focus state change. | 8427e41f4b71Sopenharmony_ci 8428e41f4b71Sopenharmony_ci**Example** 8429e41f4b71Sopenharmony_ci 8430e41f4b71Sopenharmony_ci```ts 8431e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 8432e41f4b71Sopenharmony_ci 8433e41f4b71Sopenharmony_cifunction callback(err: BusinessError, focusState: camera.FocusState): void { 8434e41f4b71Sopenharmony_ci if (err !== undefined && err.code !== 0) { 8435e41f4b71Sopenharmony_ci console.error(`Callback Error, errorCode: ${err.code}`); 8436e41f4b71Sopenharmony_ci return; 8437e41f4b71Sopenharmony_ci } 8438e41f4b71Sopenharmony_ci console.info(`Focus state: ${focusState}`); 8439e41f4b71Sopenharmony_ci} 8440e41f4b71Sopenharmony_ci 8441e41f4b71Sopenharmony_cifunction registerFocusStateChange(secureSession: camera.SecureSession): void { 8442e41f4b71Sopenharmony_ci secureSession.on('focusStateChange', callback); 8443e41f4b71Sopenharmony_ci} 8444e41f4b71Sopenharmony_ci``` 8445e41f4b71Sopenharmony_ci 8446e41f4b71Sopenharmony_ci### off('focusStateChange')<sup>12+</sup> 8447e41f4b71Sopenharmony_ci 8448e41f4b71Sopenharmony_cioff(type: 'focusStateChange', callback?: AsyncCallback\<FocusState\>): void 8449e41f4b71Sopenharmony_ci 8450e41f4b71Sopenharmony_ciUnsubscribes from focus state change events. 8451e41f4b71Sopenharmony_ci 8452e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Camera.Core 8453e41f4b71Sopenharmony_ci 8454e41f4b71Sopenharmony_ci**Parameters** 8455e41f4b71Sopenharmony_ci 8456e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 8457e41f4b71Sopenharmony_ci| -------- | ----------------------------------------- | ---- | ------------------------ | 8458e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at **'focusStateChange'**. The event can be listened for when a session is created.| 8459e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[FocusState](#focusstate)\> | No | Callback used to return the result. If this parameter is specified, the subscription to the specified event with the specified callback is canceled. (The callback object cannot be an anonymous function.) Otherwise, the subscriptions to the specified event with all the callbacks are canceled.| 8460e41f4b71Sopenharmony_ci 8461e41f4b71Sopenharmony_ci**Example** 8462e41f4b71Sopenharmony_ci 8463e41f4b71Sopenharmony_ci```ts 8464e41f4b71Sopenharmony_cifunction unregisterFocusStateChange(secureSession: camera.SecureSession): void { 8465e41f4b71Sopenharmony_ci secureSession.off('focusStateChange'); 8466e41f4b71Sopenharmony_ci} 8467e41f4b71Sopenharmony_ci``` 8468