# @ohos.multimedia.camera (Camera Management)
The module provides a set of easy-to-use camera service APIs. With these APIs, you can create camera applications that access and control camera hardware to achieve basic functions like previewing, taking photos, and recording videos. In addition, you can combine these APIs to perform advanced operations, such as controlling the flash, exposure time, and focus.
> **NOTE**
>
> 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.
## Modules to Import
```ts
import { camera } from '@kit.CameraKit';
```
## camera.getCameraManager
getCameraManager(context: Context): CameraManager
Obtains a CameraManager instance. This API returns the result synchronously.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------------------------------- | ---- | ---------------------------- |
| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Application context. |
**Return value**
| Type | Description |
| ----------------------------------------------- | ---------------------------- |
| [CameraManager](#cameramanager) | CameraManager instance obtained. |
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400101 | Parameter missing or parameter type incorrect. |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { common } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
function getCameraManager(context: common.BaseContext): camera.CameraManager | undefined {
let cameraManager: camera.CameraManager | undefined = undefined;
try {
cameraManager = camera.getCameraManager(context);
} catch (error) {
let err = error as BusinessError;
console.error(`The getCameraManager call failed. error code: ${err.code}`);
}
return cameraManager;
}
```
## CameraDevice
Describes the camera device information.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Type | Read-only| Optional| Description |
|---------------------------------|-------------------------------------| ---- |----|---------- |
| cameraId | string | Yes | No | Camera ID.|
| cameraPosition | [CameraPosition](#cameraposition) | Yes | No | Camera position. |
| cameraType | [CameraType](#cameratype) | Yes | No | Camera type. |
| connectionType | [ConnectionType](#connectiontype) | Yes | No | Camera connection type.|
| cameraOrientation12+ | number | Yes | No | Camera installation angle, which does not change as the screen rotates. The value ranges from 0° to 360°, measured in degrees.|
| hostDeviceName15+ | string | Yes | No | Remote device name.|
| hostDeviceType15+ | [HostDeviceType](#hostdevicetype15) | Yes | No | Remote device type.|
## CameraPosition
Enumerates the camera positions.
**Atomic service API**: This API can be used in atomic services since API version 12.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Value | Description |
| --------------------------- | ---- |-----------------------------------------------------------------|
| CAMERA_POSITION_UNSPECIFIED | 0 | A camera that does not have a fixed orientation relative to the device screen. |
| CAMERA_POSITION_BACK | 1 | Rear camera. |
| CAMERA_POSITION_FRONT | 2 | Front camera. |
| CAMERA_POSITION_FOLD_INNER(deprecated) | 3 | Folded camera.
This API is supported since API version 11 and deprecated since API version 12.|
## CameraType
Enumerates the camera types.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Value | Description |
| ----------------------- | ---- | -------------- |
| CAMERA_TYPE_DEFAULT | 0 | Unspecified camera type. |
| CAMERA_TYPE_WIDE_ANGLE | 1 | Wide camera. |
| CAMERA_TYPE_ULTRA_WIDE | 2 | Ultra wide camera. |
| CAMERA_TYPE_TELEPHOTO | 3 | Telephoto camera. |
| CAMERA_TYPE_TRUE_DEPTH | 4 | Camera with depth of field information.|
## ConnectionType
Enumerates the camera connection types.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Value | Description |
| ---------------------------- | ---- | ------------- |
| CAMERA_CONNECTION_BUILT_IN | 0 | Built-in camera. |
| CAMERA_CONNECTION_USB_PLUGIN | 1 | Camera connected using USB.|
| CAMERA_CONNECTION_REMOTE | 2 | Remote camera.|
## HostDeviceType15+
Enumerates the remote camera types.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Value | Description |
| ---------------------------- | ---- |---------|
| UNKNOWN_TYPE | 0 | Unknown type.|
| PHONE | 0x0E | Mobile phone. |
| TABLET | 0x11 | Tablet. |
## CameraStatus
Enumerates the camera statuses.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Value | Description |
| ------------------------- | ---- | ------------ |
| CAMERA_STATUS_APPEAR | 0 | A camera appears. |
| CAMERA_STATUS_DISAPPEAR | 1 | The camera disappears. |
| CAMERA_STATUS_AVAILABLE | 2 | The camera is available. |
| CAMERA_STATUS_UNAVAILABLE | 3 | The camera is unavailable. |
## FoldStatus12+
Enumerates the fold states available for a fordable device.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Value | Description |
| ------------------------- | ---- | ------------ |
| NON_FOLDABLE | 0 | The device is not foldable. |
| EXPANDED | 1 | The device is fully unfolded.|
| FOLDED | 2 | The device is folded. |
## CameraStatusInfo
Describes the camera status information.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Type | Read-only | Optional | Description |
| ------ | ----------------------------- | --------- |------------ | ---------- |
| camera | [CameraDevice](#cameradevice) | No | No | Camera device.|
| status | [CameraStatus](#camerastatus) | No | No | Camera status.|
## FoldStatusInfo12+
Describes the fold state information about a foldable device.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Type | Read-only | Optional | Description |
| ------ | ----------------------------- | --------- |------------ | ---------- |
| supportedCameras | [Array](#cameradevice) | No | No | List of cameras supported in the current fold state.|
| foldStatus | [FoldStatus](#foldstatus12) | No | No | Fold state.|
## Profile
Describes the camera profile.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Type | Read-only| Optional| Description |
| -------- | ----------------------------- |---- | ---- | ------------- |
| format | [CameraFormat](#cameraformat) | Yes | No | Output format. |
| size | [Size](#size) | Yes | No | Resolution.
The size setting corresponds to the camera's resolution width and height, rather than the actual dimensions of the output image. |
## FrameRateRange
Describes the frame rate range.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Type | Read-only| Optional| Description |
| -------- | ----------------------------- |----- |---| -------------- |
| min | number | Yes | No| Minimum frame rate. |
| max | number | Yes | No| Maximum frame rate. |
## VideoProfile
Describes the video configuration information. It inherits from [Profile](#profile).
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Type | Read-only| Optional| Description |
| ------------------------- | ----------------------------------------- | --- | ---- |----------- |
| frameRateRange | [FrameRateRange](#frameraterange) | Yes | No | Frame rate range, in units of frames per second (FPS).|
## CameraOutputCapability
Describes the camera output capability.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Type | Read-only| Optional| Description |
| ----------------------------- | --------------------------------------------------- | ---- | ---- |-------------------|
| previewProfiles | Array\<[Profile](#profile)\> | Yes | No| Supported preview profiles. |
| photoProfiles | Array\<[Profile](#profile)\> | Yes | No| Supported photo profiles. |
| videoProfiles | Array\<[VideoProfile](#videoprofile)\> | Yes | No| Supported video profiles. |
| supportedMetadataObjectTypes | Array\<[MetadataObjectType](#metadataobjecttype)\> | Yes | No| Supported metadata object types.|
## SceneMode11+
Enumerates the camera scene modes.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Value | Description |
|----------------------------|---------|---------------------------------------------|
| NORMAL_PHOTO | 1 | Normal photo mode. For details, see [PhotoSession](#photosession11). |
| NORMAL_VIDEO | 2 | Normal record mode. For details, see [VideoSession](#videosession11). |
| SECURE_PHOTO12+ | 12 | Secure mode. For details, see [SecureSession](#securesession12).|
## CameraErrorCode
Enumerates the camera error codes,
which are returned when an API call is incorrect or the **on()** API is used to listen for the error status.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Value | Description |
| ------------------------- | ---- | ------------ |
| INVALID_ARGUMENT | 7400101 | A parameter is missing or the parameter type is incorrect. |
| OPERATION_NOT_ALLOWED | 7400102 | The operation is not allowed. |
| SESSION_NOT_CONFIG | 7400103 | The session is not configured. |
| SESSION_NOT_RUNNING | 7400104 | The session is not running. |
| SESSION_CONFIG_LOCKED | 7400105 | The session configuration is locked. |
| DEVICE_SETTING_LOCKED | 7400106 | The device setting is locked. |
| CONFLICT_CAMERA | 7400107 | The device is already started. |
| DEVICE_DISABLED | 7400108 | The camera is disabled for security reasons. |
| DEVICE_PREEMPTED | 7400109 | The camera is preempted. |
| UNRESOLVED_CONFLICTS_WITH_CURRENT_CONFIGURATIONS12+ | 7400110 | The configuration conflicts with the current configuration. |
| SERVICE_FATAL_ERROR | 7400201 | An error occurs in the camera service. |
## CameraManager
Implements camera management. Before calling any API in CameraManager, you must use [getCameraManager](#cameragetcameramanager) to obtain a CameraManager instance.
### getSupportedCameras
getSupportedCameras(): Array\
Obtains the supported camera devices. This API returns the result synchronously.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| ----------------------------------------------- | ---------------------------- |
| Array\<[CameraDevice](#cameradevice)> | Array of camera devices supported. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function getSupportedCameras(cameraManager: camera.CameraManager): Array {
let cameras: Array = [];
try {
cameras = cameraManager.getSupportedCameras();
} catch (error) {
let err = error as BusinessError;
console.error(`The getSupportedCameras call failed. error code: ${err.code}`);
}
return cameras;
}
```
### getSupportedSceneModes11+
getSupportedSceneModes(camera: CameraDevice): Array\
Obtains the scene modes supported by a camera device. This API returns the result synchronously.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ------------ |--------------------------------------------------------------- | -- | -------------------------- |
| camera | [CameraDevice](#cameradevice) | Yes| CameraDevice instance, which is obtained through [getSupportedCameras](#getsupportedcameras). An error code is returned if the input parameter is invalid. |
**Return value**
| Type | Description |
| ----------------------------------------------- | ---------------------------- |
| Array\<[SceneMode](#scenemode11)> | Array of scene modes supported. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function getSupportedSceneModes(cameraManager: camera.CameraManager, camera: camera.CameraDevice): Array {
let modes: Array = [];
try {
modes = cameraManager.getSupportedSceneModes(camera);
} catch (error) {
let err = error as BusinessError;
console.error(`The getSupportedSceneModes call failed. error code: ${err.code}`);
}
return modes;
}
```
### getSupportedOutputCapability(deprecated)
getSupportedOutputCapability(camera: CameraDevice): CameraOutputCapability
Obtains the output capability supported by a camera device. This API returns the result synchronously.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [getSupportedOutputCapability](#getsupportedoutputcapability11) instead.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ------------ |--------------------------------------------------------------- | -- | -------------------------- |
| camera | [CameraDevice](#cameradevice) | Yes| CameraDevice instance, which is obtained through [getSupportedCameras](#getsupportedcameras). An error code is returned if the input parameter is invalid. |
**Return value**
| Type | Description |
| ----------------------------------------------- | ---------------------------- |
| [CameraOutputCapability](#cameraoutputcapability) | Camera output capability obtained. |
**Example**
```ts
function getSupportedOutputCapability(camera: camera.CameraDevice, cameraManager: camera.CameraManager): camera.CameraOutputCapability {
let cameraOutputCapability: camera.CameraOutputCapability = cameraManager.getSupportedOutputCapability(camera);
return cameraOutputCapability;
}
```
### getSupportedOutputCapability11+
getSupportedOutputCapability(camera: CameraDevice, mode: SceneMode): CameraOutputCapability
Obtains the output capability supported by a camera device in a given scene mode. This API returns the result synchronously.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ------------ |--------------------------------------------------------------- | -- | -------------------------- |
| camera | [CameraDevice](#cameradevice) | Yes| CameraDevice instance, which is obtained through [getSupportedCameras](#getsupportedcameras). |
| mode | [SceneMode](#scenemode11) | Yes| Scene mode, which is obtained through [getSupportedSceneModes](#getsupportedscenemodes11). |
**Return value**
| Type | Description |
| ----------------------------------------------- | ---------------------------- |
| [CameraOutputCapability](#cameraoutputcapability) | Camera output capability obtained. |
**Example**
```ts
function getSupportedOutputCapability(camera: camera.CameraDevice, cameraManager: camera.CameraManager, sceneMode: camera.SceneMode): camera.CameraOutputCapability {
let cameraOutputCapability: camera.CameraOutputCapability = cameraManager.getSupportedOutputCapability(camera, sceneMode);
return cameraOutputCapability;
}
```
### isCameraMuted
isCameraMuted(): boolean
Checks whether this camera is muted.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| ---------- | -------------------------------------------- |
| boolean | Check result. The value **true** means that the camera device is muted, and **false** means the opposite.|
**Example**
```ts
function isCameraMuted(cameraManager: camera.CameraManager): boolean {
let isMuted: boolean = cameraManager.isCameraMuted();
return isMuted;
}
```
### createCameraInput
createCameraInput(camera: CameraDevice): CameraInput
Creates a CameraInput instance with the specified CameraDevice instance. This API returns the result synchronously.
Before calling this API, call [getSupportedCameras](#getsupportedcameras) to obtain the list of supported camera devices, select the camera device that meets the requirements based on the actual usage scenario, and then create the CameraInput instance.
**Required permissions**: ohos.permission.CAMERA
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------- | ---- |--------------------------------------------------|
| camera | [CameraDevice](#cameradevice) | Yes | CameraDevice instance, which is obtained through [getSupportedCameras](#getsupportedcameras).|
**Return value**
| Type | Description |
| ---------- | ----------------------------- |
| [CameraInput](#camerainput) | CameraInput instance created. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400101 | Parameter missing or parameter type incorrect. |
| 7400102 | Operation not allowed. |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function createCameraInput(camera: camera.CameraDevice, cameraManager: camera.CameraManager): camera.CameraInput | undefined {
let cameraInput: camera.CameraInput | undefined = undefined;
try {
cameraInput = cameraManager.createCameraInput(camera);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The createCameraInput call failed. error code: ${err.code}`);
}
return cameraInput;
}
```
### createCameraInput
createCameraInput(position: CameraPosition, type: CameraType): CameraInput
Creates a CameraInput instance with the specified camera position and type. This API returns the result synchronously.
Before calling this API, specify the camera position and type based on the usage scenario. For example, open the front camera for the selfie feature
**Required permissions**: ohos.permission.CAMERA
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------- | ---- | --------------------------------- |
| position | [CameraPosition](#cameraposition) | Yes | Camera position. You need to obtain the supported camera object by calling [getSupportedCameras](#getsupportedcameras) and then obtain the device position information based on the returned camera object. |
| type | [CameraType](#cameratype) | Yes | Camera type. You need to obtain the supported camera object by calling [getSupportedCameras](#getsupportedcameras) and then obtain the camera type based on the returned camera object.|
**Return value**
| Type | Description |
| ---------- | ----------------------------- |
| [CameraInput](#camerainput) | CameraInput instance created. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400101 | Parameter missing or parameter type incorrect. |
| 7400102 | Operation not allowed. |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function createCameraInput(camera: camera.CameraDevice, cameraManager: camera.CameraManager): camera.CameraInput | undefined {
let position: camera.CameraPosition = camera.cameraPosition;
let type: camera.CameraType = camera.cameraType;
let cameraInput: camera.CameraInput | undefined = undefined;
try {
cameraInput = cameraManager.createCameraInput(position, type);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The createCameraInput call failed. error code: ${err.code}`);
}
return cameraInput;
}
```
### createPreviewOutput
createPreviewOutput(profile: Profile, surfaceId: string): PreviewOutput
Creates a PreviewOutput instance. This API returns the result synchronously.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------------------------------- | ---- | ------------------------------- |
| profile | [Profile](#profile) | Yes | Supported preview profile, which is obtained through [getSupportedOutputCapability](#getsupportedoutputcapability11).|
| surfaceId| string | Yes | Surface ID, which is obtained from [XComponent](../apis-arkui/arkui-ts/ts-basic-components-xcomponent.md) or [ImageReceiver](../apis-image-kit/arkts-apis-image-ImageReceiver.md).|
**Return value**
| Type | Description |
| ---------- | ----------------------------- |
| [PreviewOutput](#previewoutput) | PreviewOutput instance created. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400101 | Parameter missing or parameter type incorrect. |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function createPreviewOutput(cameraOutputCapability: camera.CameraOutputCapability, cameraManager: camera.CameraManager, surfaceId: string): camera.PreviewOutput | undefined {
let profile: camera.Profile = cameraOutputCapability.previewProfiles[0];
let previewOutput: camera.PreviewOutput | undefined = undefined;
try {
previewOutput = cameraManager.createPreviewOutput(profile, surfaceId);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The createPreviewOutput call failed. error code: ${err.code}`);
}
return previewOutput;
}
```
### createPreviewOutput12+
createPreviewOutput(surfaceId: string): PreviewOutput
Creates a PreviewOutput instance without configuration. This API returns the result synchronously. It must be used together with [preconfig](#preconfig12).
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------------------------------- | ---- | ------------------------------- |
| surfaceId| string | Yes | Surface ID, which is obtained from [XComponent](../apis-arkui/arkui-ts/ts-basic-components-xcomponent.md) or [ImageReceiver](../apis-image-kit/arkts-apis-image-ImageReceiver.md).|
**Return value**
| Type | Description |
| ---------- | ----------------------------- |
| [PreviewOutput](#previewoutput) | PreviewOutput instance created. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
|---------|------------------------------------------------|
| 7400101 | Parameter missing or parameter type incorrect. |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function createPreviewOutput(cameraManager: camera.CameraManager, surfaceId: string): camera.PreviewOutput | undefined {
let previewOutput: camera.PreviewOutput | undefined = undefined;
try {
previewOutput = cameraManager.createPreviewOutput(surfaceId);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The createPreviewOutput call failed. error code: ${err.code}`);
}
return previewOutput;
}
```
### createPhotoOutput(deprecated)
createPhotoOutput(profile: Profile, surfaceId: string): PhotoOutput
Creates a PhotoOutput instance. This API returns the result synchronously.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [createPhotoOutput](#createphotooutput11) instead.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------- | ---- | ----------------------------------- |
| profile | [Profile](#profile) | Yes | Supported photo profile, which is obtained through [getSupportedOutputCapability](#getsupportedoutputcapability11).|
| surfaceId| string | Yes | Surface ID, which is obtained from [ImageReceiver](../apis-image-kit/arkts-apis-image-ImageReceiver.md).|
**Return value**
| Type | Description |
| ---------- | ----------------------------- |
| [PhotoOutput](#photooutput) | PhotoOutput instance created. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400101 | Parameter missing or parameter type incorrect. |
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function createPhotoOutput(cameraOutputCapability: camera.CameraOutputCapability, cameraManager: camera.CameraManager, surfaceId: string): camera.PhotoOutput | undefined {
let profile: camera.Profile = cameraOutputCapability.photoProfiles[0];
let photoOutput: camera.PhotoOutput | undefined = undefined;
try {
photoOutput = cameraManager.createPhotoOutput(profile, surfaceId);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The createPhotoOutput call failed. error code: ${err.code}`);
}
return photoOutput;
}
```
### createPhotoOutput11+
createPhotoOutput(profile?: Profile): PhotoOutput
Creates a PhotoOutput instance. This API returns the result synchronously.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------- |----| ----------------------------------- |
| profile | [Profile](#profile) | No | Supported photo profile, which is obtained through [getSupportedOutputCapability](#getsupportedoutputcapability11).
In API version 11, this parameter is mandatory. Since API version 12, it will overwrite the preconfigured parameters passed in through **preconfig**.|
**Return value**
| Type | Description |
| ---------- | ----------------------------- |
| [PhotoOutput](#photooutput) | PhotoOutput instance created. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
|----------|------------------------------------------------|
| 7400101 | Parameter missing or parameter type incorrect. |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function createPhotoOutput(cameraOutputCapability: camera.CameraOutputCapability, cameraManager: camera.CameraManager): camera.PhotoOutput | undefined {
let profile: camera.Profile = cameraOutputCapability.photoProfiles[0];
let photoOutput: camera.PhotoOutput | undefined = undefined;
try {
photoOutput = cameraManager.createPhotoOutput(profile);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The createPhotoOutput call failed. error code: ${err.code}`);
}
return photoOutput;
}
```
### createVideoOutput
createVideoOutput(profile: VideoProfile, surfaceId: string): VideoOutput
Creates a VideoOutput instance. This API returns the result synchronously.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------- | ---- | ------------------------------ |
| profile | [VideoProfile](#videoprofile) | Yes | Supported video profile, which is obtained through [getSupportedOutputCapability](#getsupportedoutputcapability11).|
| surfaceId| string | Yes | Surface ID, which is obtained from [AVRecorder](../apis-media-kit/js-apis-media.md#avrecorder9).|
**Return value**
| Type | Description |
| ---------- | ----------------------------- |
| [VideoOutput](#videooutput) | VideoOutput instance created. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400101 | Parameter missing or parameter type incorrect. |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function createVideoOutput(cameraOutputCapability: camera.CameraOutputCapability, cameraManager: camera.CameraManager, surfaceId: string): camera.VideoOutput | undefined {
let profile: camera.VideoProfile = cameraOutputCapability.videoProfiles[0];
let videoOutput: camera.VideoOutput | undefined = undefined;
try {
videoOutput = cameraManager.createVideoOutput(profile, surfaceId);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The createVideoOutput call failed. error code: ${err.code}`);
}
return videoOutput;
}
```
### createVideoOutput12+
createVideoOutput(surfaceId: string): VideoOutput
Creates a VideoOutput instance without configuration. This API returns the result synchronously. It must be used together with [preconfig](#preconfig12-1).
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory | Description |
|-----------|--------|-------|----------------------------------------------------------------------------|
| surfaceId | string | Yes | Surface ID, which is obtained from [AVRecorder](../apis-media-kit/js-apis-media.md#avrecorder9).|
**Return value**
| Type | Description |
| ---------- | ----------------------------- |
| [VideoOutput](#videooutput) | VideoOutput instance created. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
|----------|------------------------------------------------|
| 7400101 | Parameter missing or parameter type incorrect. |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function createVideoOutput(cameraManager: camera.CameraManager, surfaceId: string): camera.VideoOutput | undefined {
let videoOutput: camera.VideoOutput | undefined = undefined;
try {
videoOutput = cameraManager.createVideoOutput(surfaceId);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The createVideoOutput call failed. error code: ${err.code}`);
}
return videoOutput;
}
```
### createMetadataOutput
createMetadataOutput(metadataObjectTypes: Array\): MetadataOutput
Creates a MetadataOutput instance. This API returns the result synchronously.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------------------- | -------------------------------------------------- | --- | ---------------------------- |
| metadataObjectTypes | Array\<[MetadataObjectType](#metadataobjecttype)\> | Yes | Metadata object types, which are obtained through [getSupportedOutputCapability](#getsupportedoutputcapability11).|
**Return value**
| Type | Description |
| ---------- | ----------------------------- |
| [MetadataOutput](#metadataoutput) | MetadataOutput instance created. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400101 | Parameter missing or parameter type incorrect. |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function createMetadataOutput(cameraManager: camera.CameraManager, cameraOutputCapability: camera.CameraOutputCapability): void {
let metadataObjectTypes: Array = cameraOutputCapability.supportedMetadataObjectTypes;
let metadataOutput: camera.MetadataOutput | undefined = undefined;
try {
metadataOutput = cameraManager.createMetadataOutput(metadataObjectTypes);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`createMetadataOutput error. error code: ${err.code}`);
}
}
```
### createCaptureSession(deprecated)
createCaptureSession(): CaptureSession
Creates a CaptureSession instance. This API returns the result synchronously.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [createSession](#createsession11) instead.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| ---------- | ----------------------------- |
| [CaptureSession](#capturesessiondeprecated) | CaptureSession instance created. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function createCaptureSession(cameraManager: camera.CameraManager): camera.CaptureSession | undefined {
let captureSession: camera.CaptureSession | undefined = undefined;
try {
captureSession = cameraManager.createCaptureSession();
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`createCaptureSession error. error code: ${err.code}`);
}
return captureSession;
}
```
### createSession11+
createSession\(mode: SceneMode): T
Creates a Session instance with a given scene mode. This API returns the result synchronously.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -----------------| ---- | --------- |
| mode | [SceneMode](#scenemode11) | Yes | Scene mode. The API does not take effect if the input parameter is invalid (for example, the value is out of range, null, or undefined).|
**Return value**
| Type | Description |
| ---------- | ----------------------------- |
| [T extends Session](#session11) | Session instance created. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
|---------|------------------------------------------------------------------------------------------------------------------------------------------------|
| 7400101 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3.Parameter verification failed. |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function createSession(cameraManager: camera.CameraManager, mode: camera.SceneMode): camera.Session | undefined {
let photoSession: camera.PhotoSession | undefined = undefined;
try {
photoSession = cameraManager.createSession(mode) as camera.PhotoSession;
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`createCaptureSession error. error code: ${err.code}`);
}
return photoSession;
}
```
### on('cameraStatus')
on(type: 'cameraStatus', callback: AsyncCallback\): void
Subscribes to camera status events. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -----------------| ---- | --------- |
| 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.|
| callback | AsyncCallback\<[CameraStatusInfo](#camerastatusinfo)\> | Yes | Callback used to return the camera status change.| |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function callback(err: BusinessError, cameraStatusInfo: camera.CameraStatusInfo): void {
if (err !== undefined && err.code !== 0) {
console.error('cameraStatus with errorCode = ' + err.code);
return;
}
console.info(`camera : ${cameraStatusInfo.camera.cameraId}`);
console.info(`status: ${cameraStatusInfo.status}`);
}
function registerCameraStatus(cameraManager: camera.CameraManager): void {
cameraManager.on('cameraStatus', callback);
}
```
### off('cameraStatus')
off(type: 'cameraStatus', callback?: AsyncCallback\): void
Unsubscribes from camera status events. This API uses an asynchronous callback to return the result.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -----------------| ---- | --------- |
| type | string | Yes | Event type. The value is fixed at **'cameraStatus'**. The event can be listened for when a CameraManager instance is obtained.|
| 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.|
**Example**
```ts
function unregisterCameraStatus(cameraManager: camera.CameraManager): void {
cameraManager.off('cameraStatus');
}
```
### on('foldStatusChange')12+
on(type: 'foldStatusChange', callback: AsyncCallback\): void
Subscribes to fold status change events of the foldable device. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -----------------| ---- | --------- |
| type | string | Yes | Event type. The value is fixed at **'foldStatusChange'**. The event is triggered when the fold state of the foldable device changes.|
| callback | AsyncCallback\<[FoldStatusInfo](#foldstatusinfo12)\> | Yes | Callback used to return the fold state information about the foldable device.|
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function callback(err: BusinessError, foldStatusInfo: camera.FoldStatusInfo): void {
if (err !== undefined && err.code !== 0) {
console.error('foldStatusChange with errorCode = ' + err.code);
return;
}
console.info(`camera length: ${foldStatusInfo.supportedCameras.length}`);
console.info(`foldStatus: ${foldStatusInfo.foldStatus}`);
}
function registerFoldStatusChange(cameraManager: camera.CameraManager): void {
cameraManager.on('foldStatusChange', callback);
}
```
### off('foldStatusChange')12+
off(type: 'foldStatusChange', callback?: AsyncCallback\): void
Unsubscribes from fold state change events of the foldable device.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -----------------| ---- | --------- |
| type | string | Yes | Event type. The value is fixed at **'foldStatusChange'**. The event is triggered when the fold state of the foldable device changes.|
| callback | AsyncCallback\<[FoldStatusInfo](#foldstatusinfo12)\> | No | Callback used to return the fold state 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.|
**Example**
```ts
function unregisterFoldStatusChange(cameraManager: camera.CameraManager): void {
cameraManager.off('foldStatusChange');
}
```
### isTorchSupported11+
isTorchSupported(): boolean
Checks whether the camera device supports the flashlight.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| ---------- | ----------------------------- |
| boolean | Check result for the support of the flashlight. **true** if supported, **false** otherwise.|
**Example**
```ts
function isTorchSupported(cameraManager: camera.CameraManager): boolean {
let isSupported = cameraManager.isTorchSupported();
return isSupported;
}
```
### isTorchModeSupported11+
isTorchModeSupported(mode: TorchMode): boolean
Checks whether a flashlight mode is supported.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------- | ---- | --------- |
| mode | [TorchMode](#torchmode11) | Yes| Flashlight mode. If the input parameter is null or undefined, it is treated as 0 and the flashlight is turned off.|
**Return value**
| Type | Description |
| ---------- | ----------------------------- |
| boolean | Check result for the support of the flashlight mode. **true** if supported, **false** otherwise.|
**Example**
```ts
function isTorchModeSupported(cameraManager: camera.CameraManager, torchMode: camera.TorchMode): boolean {
let isSupported = cameraManager.isTorchModeSupported(torchMode);
return isSupported;
}
```
### getTorchMode11+
getTorchMode(): TorchMode
Obtains the flashlight mode of this camera device.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| ---------- | ----------------------------- |
| [TorchMode](#torchmode11) | Flashlight mode.|
**Example**
```ts
function getTorchMode(cameraManager: camera.CameraManager): camera.TorchMode | undefined {
let torchMode: camera.TorchMode | undefined = undefined;
torchMode = cameraManager.getTorchMode();
return torchMode;
}
```
### setTorchMode11+
setTorchMode(mode: TorchMode): void
Sets the flashlight mode.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------- | ---- | --------- |
| mode | [TorchMode](#torchmode11) | Yes| Flashlight mode. If the input parameter is null or undefined, it is treated as 0 and the flashlight is turned off.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400102 | Operation not allowed. |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function setTorchMode(cameraManager: camera.CameraManager, torchMode: camera.TorchMode): void {
try {
cameraManager.setTorchMode(torchMode);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The setTorchMode call failed. error code: ${err.code}`);
}
}
```
### on('torchStatusChange')11+
on(type: 'torchStatusChange', callback: AsyncCallback\): void
Subscribes to flashlight status change events. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------- | ---- | --------- |
| 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.|
| callback | AsyncCallback\ | Yes | Callback used to return the flashlight status. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function callback(err: BusinessError, torchStatusInfo: camera.TorchStatusInfo): void {
if (err !== undefined && err.code !== 0) {
console.error(`Callback Error, errorCode: ${err.code}`);
return;
}
console.info(`onTorchStatusChange, isTorchAvailable: ${torchStatusInfo.isTorchAvailable}, isTorchActive: ${torchStatusInfo.isTorchActive}, level: ${torchStatusInfo.torchLevel}`);
}
function registerTorchStatusChange(cameraManager: camera.CameraManager): void {
cameraManager.on('torchStatusChange', callback);
}
```
### off('torchStatusChange')11+
off(type: 'torchStatusChange', callback?: AsyncCallback\): void
Unsubscribes from flashlight status change events. This API uses an asynchronous callback to return the result.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------- | ---- | --------- |
| type | string | Yes | Event type. The value is fixed at **'torchStatusChange'**. The event can be listened for when a CameraManager instance is obtained.|
| callback | AsyncCallback\ | 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.|
**Example**
```ts
function unregisterTorchStatusChange(cameraManager: camera.CameraManager): void {
cameraManager.off('torchStatusChange');
}
```
### getCameraDevice18+
getCameraDevice(position:CameraPosition, type: CameraType): CameraDevice
Obtains the specified camera based on the camera position and type.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------- | ---- | --------- |
| position | [CameraPosition](#cameraposition) | Yes | Camera position.|
| type | [CameraType](#cameratype) | Yes | Camera type.|
**Return value**
| Type | Description |
| -----------------| ------------------------ |
| [CameraDevice](#cameradevice) | Camera obtained. |
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { camera } from '@kit.CameraKit';
function getCameraDevice(cameraManager: camera.CameraManager, position: camera.CameraPosition, type: camera.CameraType): void {
try {
let curCameraDev: camera.CameraDevice | undefined = undefined;
curCameraDev = cameraManager.getCameraDevice(position, type);
} catch (error) {
// If the operation fails, an error code is returned and processed.
let err = error as BusinessError;
console.error(`The getCameraDevice call failed. error code: ${err.code}`);
}
}
```
### getCameraConcurrentInfos18+
getCameraConcurrentInfos(cameras: Array\): Array\
Obtains the concurrency information of the specified cameras. If the return value is an empty array, concurrency is not supported.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------- | ---- | --------- |
| cameras | Array\<[CameraDevice](#cameradevice)\> | Yes | Array of CameraDevice objects. You are advised to use the front and rear cameras obtained by calling [getCameraDevice](#getcameradevice18).|
**Return value**
| Type | Description |
| -----------------| ------------------------ |
| Array\<[CameraConcurrentInfo](#cameraconcurrentinfo18)\> | Array of concurrency information corresponding to the provided CameraDevice objects, with a one-to-one mapping. |
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { camera } from '@kit.CameraKit';
function getCameraConcurrentInfos(cameraManager: camera.CameraManager, cameraDeviceArray: Array): void {
try {
let cameraconcurrentinfos: Array = [];
cameraconcurrentinfos = cameraManager.getCameraConcurrentInfos(cameraDeviceArray);
} catch (error) {
// If the operation fails, an error code is returned and processed.
let err = error as BusinessError;
console.error(`The getCameraConcurrentInfos call failed. error code: ${err.code}`);
}
}
```
## TorchMode11+
Enumerates the flashlight modes.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Value | Description |
| ---------------------------- | ---- | ------------- |
| OFF | 0 | The flashlight is off. |
| ON | 1 | The flashlight is on.|
| AUTO | 2 | The system automatically adjusts the flashlight brightness according to the environment.|
## TorchStatusInfo11+
Describes the flashlight status information.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Type | Read-only| Optional| Description |
| ---------------- | ---------- | ---- | ---- | ----------- |
| isTorchAvailable | boolean | Yes | No | Whether the flashlight is available. **true** if available, **false** otherwise.|
| isTorchActive | boolean | Yes | No | Whether the flashlight is activated. **true** if activated, **false** otherwise.|
| torchLevel | number | Yes | No | Flashlight brightness level. The value range is [0, 1]. A larger value indicates a greater luminance. |
## Size
Describes the output capability.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Type | Read-only| Optional | Description |
| ------ | ------ | ---- |-----| ------------ |
| height | number | No | No | Image height, in pixels.|
| width | number | No | No | Image width, in pixels.|
## Point
Describes the point coordinates, which are used for focus and exposure configuration.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Type | Read-only | Optional | Description |
| ------ | ------ | ------ | ------ | ------------ |
| x | number | No | No | X coordinate of a point. |
| y | number | No | No | Y coordinate of a point. |
## CameraFormat
Enumerates the camera output formats.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Value | Description |
| ----------------------- | --------- | ------------ |
| CAMERA_FORMAT_RGBA_8888 | 3 | RGBA_8888 image. |
| CAMERA_FORMAT_YUV_420_SP| 1003 | YUV_420_SP image. |
| CAMERA_FORMAT_JPEG | 2000 | JPEG image. |
| CAMERA_FORMAT_YCBCR_P01011+ | 2001 | YCBCR_P010 image. |
| CAMERA_FORMAT_YCRCB_P01011+ | 2002 | YCRCB_P010 image. |
| CAMERA_FORMAT_HEIC13+ | 2003 | HEIF image. |
## VideoCodecType13+
Enumerates the video codec types.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Value | Description |
|------|------|-------------|
| AVC | 0 | AVC.|
| HEVC | 1 | HEVC.|
## CameraConcurrentType18+
Enumerates the camera concurrency types.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Value | Description |
|------|------|-------------|
| CAMERA_LIMITED_CAPABILITY | 0 | Limited camera concurrency. |
| CAMERA_FULL_CAPABILITY | 1 | Full camera concurrency.|
## CameraConcurrentInfo18+
Describes the camera's concurrency information.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Type | Read-only| Optional | Description |
| ------ | ------ | ---- |-----| ------------ |
| device | [CameraDevice](#cameradevice) | Yes | No | Concurrent camera device.|
| type | [CameraConcurrentType](#cameraconcurrenttype18) | Yes | No | Concurrency type.|
| modes | Array\<[SceneMode](#scenemode11) \> | Yes | No | Scene mode.|
| outputCapabilities | Array\<[CameraOutputCapability](#cameraoutputcapability) \> | Yes | No | Output capabilities of the camera.|
## CameraInput
Defines the camera input object.
It provides camera device information used in [Session](#session11).
### open
open(callback: AsyncCallback\): void
Opens this camera device. This API uses an asynchronous callback to return the result.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------- |
| callback | AsyncCallback\ | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400107 | Can not use camera cause of conflict. |
| 7400108 | Camera disabled cause of security reason. |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function openCameraInput(cameraInput: camera.CameraInput): void {
cameraInput.open((err: BusinessError) => {
if (err) {
console.error(`Failed to open the camera, error code: ${err.code}.`);
return;
}
console.info('Callback returned with camera opened.');
});
}
```
### open
open(): Promise\
Opens this camera device. This API uses a promise to return the result.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| -------------- | ----------------------- |
| Promise\ | Promise that returns no value.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
|---------|-------------------------------------------|
| 7400102 | Operation not allowed. |
| 7400107 | Can not use camera cause of conflict. |
| 7400108 | Camera disabled cause of security reason. |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function openCameraInput(cameraInput: camera.CameraInput): void {
cameraInput.open().then(() => {
console.info('Promise returned with camera opened.');
}).catch((error: BusinessError) => {
console.error(`Failed to open the camera, error code: ${error.code}.`);
});
}
```
### open12+
open(isSecureEnabled: boolean): Promise\
Opens this camera device and obtains the handle to the camera in secure mode.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- |-------------------------------------------------------------------------|
| isSecureEnabled | boolean | Yes | Whether to open the camera device in secure mode. **true** to open in secure mode, **false** otherwise. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Return value**
| Type | Description |
| -------------- | ----------------------- |
| Promise\ | Promise used to return the handle to the camera.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400107 | Can not use camera cause of conflict. |
| 7400108 | Camera disabled cause of security reason. |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function openCameraInput(cameraInput: camera.CameraInput): void {
cameraInput.open(true).then(() => {
console.info('Promise returned with camera opened.');
}).catch((error: BusinessError) => {
console.error(`Failed to open the camera, error code: ${error.code}.`);
});
}
```
### open18+
open(type: CameraConcurrentType): Promise\
Opens the camera with the specified concurrency type.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- |-------------------------------------------------------------------------|
| type | [CameraConcurrentType](#cameraconcurrenttype18) | Yes | Concurrency type. If the API fails to be called, an error code is returned.|
**Return value**
| Type | Description |
| -------------- | ----------------------- |
| Promise\ | Promise that returns no value.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
|---------|-------------------------------------------|
| 7400102 | Operation not allowed. |
| 7400107 | Can not use camera cause of conflict. |
| 7400108 | Camera disabled cause of security reason. |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function openCameraInput(cameraInput: camera.CameraInput): void {
cameraInput.open(0).then(() => {
console.info('Promise returned with camera opened.');
}).catch((error: BusinessError) => {
console.error(`Failed to open the camera, error code: ${error.code}.`);
});
}
```
### close
close(callback: AsyncCallback\\): void
Closes this camera device. This API uses an asynchronous callback to return the result.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | -------------------- |
| callback | AsyncCallback\ | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function closeCameraInput(cameraInput: camera.CameraInput): void {
cameraInput.close((err: BusinessError) => {
if (err) {
console.error(`Failed to close the cameras, error code: ${err.code}.`);
return;
}
console.info('Callback returned with camera closed.');
});
}
```
### close
close(): Promise\
Closes this camera device. This API uses a promise to return the result.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| -------------- | ----------------------- |
| Promise\ | Promise that returns no value.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function closeCameraInput(cameraInput: camera.CameraInput): void {
cameraInput.close().then(() => {
console.info('Promise returned with camera closed.');
}).catch((error: BusinessError) => {
console.error(`Failed to close the cameras, error code: ${error.code}.`);
});
}
```
### on('error')
on(type: 'error', camera: CameraDevice, callback: ErrorCallback): void
Subscribes to CameraInput error events. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------------------- | --- | ------------------------------------------- |
| 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.|
| camera | [CameraDevice](#cameradevice) | Yes | Camera device.|
| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | Yes | Callback used to return an error code defined in [CameraErrorCode](#cameraerrorcode). |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function callback(err: BusinessError): void {
console.error(`Camera input error code: ${err.code}`);
}
function registerCameraInputError(cameraInput: camera.CameraInput, camera: camera.CameraDevice): void {
cameraInput.on('error', camera, callback);
}
```
### off('error')
off(type: 'error', camera: CameraDevice, callback?: ErrorCallback): void
Unsubscribes from CameraInput error events.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------------------- | --- | ------------------------------------------- |
| 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.|
| camera | [CameraDevice](#cameradevice) | Yes | Camera device.|
| 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.|
**Example**
```ts
function unregisterCameraInputError(cameraInput: camera.CameraInput, camera: camera.CameraDevice): void {
cameraInput.off('error', camera);
}
```
## CameraOutput
Implements output information used in [Session](#session11). It is the base class of **output**.
### release
release(callback: AsyncCallback\): void
Releases output resources. This API uses an asynchronous callback to return the result.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------- |
| callback | AsyncCallback\ | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function releasePreviewOutput(previewOutput: camera.PreviewOutput): void {
previewOutput.release((err: BusinessError) => {
if (err) {
console.error(`Failed to release the Preview output instance ${err.code}`);
return;
}
console.info('Callback invoked to indicate that the preview output instance is released successfully.');
});
}
function releaseVideoOutput(videoOutput: camera.VideoOutput): void {
videoOutput.release((err: BusinessError) => {
if (err) {
console.error(`Failed to release the video output instance ${err.code}`);
return;
}
console.info('Callback invoked to indicate that the video output instance is released successfully.');
});
}
```
### release
release(): Promise\
Releases output resources. This API uses a promise to return the result.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| -------------- | ----------------------- |
| Promise\ | Promise that returns no value.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function releasePreviewOutput(previewOutput: camera.PreviewOutput): void {
previewOutput.release().then(() => {
console.info('Promise returned to indicate that the preview output instance is released successfully.');
}).catch((error: BusinessError) => {
console.error(`Failed to preview output release, error code: ${error.code}`);
});
}
function releaseVideoOutput(videoOutput: camera.VideoOutput): void {
videoOutput.release().then(() => {
console.info('Promise returned to indicate that the video output instance is released successfully.');
}).catch((error: BusinessError) => {
console.error(`Failed to video output release, error code: ${error.code}`);
});
}
```
## PreviewOutput
Implements preview output. It inherits from [CameraOutput](#cameraoutput).
### start(deprecated)
start(callback: AsyncCallback\): void
Starts to output preview streams. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Session.start](#start11) instead.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | -------------------- |
| callback | AsyncCallback\ | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400103 | Session not config. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function startPreviewOutput(previewOutput: camera.PreviewOutput): void {
previewOutput.start((err: BusinessError) => {
if (err) {
console.error(`Failed to start the preview output, error code: ${err.code}.`);
return;
}
console.info('Callback returned with preview output started.');
});
}
```
### start(deprecated)
start(): Promise\
Starts to output preview streams. This API uses a promise to return the result.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Session.start](#start11-1) instead.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| -------------- |-------------------|
| Promise\ | Promise that returns no value. |
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400103 | Session not config. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function startPreviewOutput(previewOutput: camera.PreviewOutput): void {
previewOutput.start().then(() => {
console.info('Promise returned with preview output started.');
}).catch((error: BusinessError) => {
console.error(`Failed to preview output start, error code: ${error.code}.`);
});
}
```
### stop(deprecated)
stop(callback: AsyncCallback\): void
Stops outputting preview streams. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Session.stop](#stop11) instead.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | -------------------- |
| callback | AsyncCallback\ | Yes | Callback used to return the result.|
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function stopPreviewOutput(previewOutput: camera.PreviewOutput): void {
previewOutput.stop((err: BusinessError) => {
if (err) {
console.error(`Failed to stop the preview output, error code: ${err.code}.`);
return;
}
console.info('Returned with preview output stopped.');
})
}
```
### stop(deprecated)
stop(): Promise\
Stops outputting preview streams. This API uses a promise to return the result.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Session.stop](#stop11-1) instead.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| -------------- | ------------------------ |
| Promise\ | Promise that returns no value.|
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function stopPreviewOutput(previewOutput: camera.PreviewOutput): void {
previewOutput.stop().then(() => {
console.info('Callback returned with preview output stopped.');
}).catch((error: BusinessError) => {
console.error(`Failed to preview output stop, error code: ${error.code}.`);
});
}
```
### on('frameStart')
on(type: 'frameStart', callback: AsyncCallback\): void
Subscribes to preview frame start events. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | --------------------------------------- |
| 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.|
| callback | AsyncCallback\ | Yes | Callback used to return the result. The preview starts as long as this event is returned. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function callback(err: BusinessError): void {
if (err !== undefined && err.code !== 0) {
console.error(`Callback Error, errorCode: ${err.code}`);
return;
}
console.info('Preview frame started');
}
function registerPreviewOutputFrameStart(previewOutput: camera.PreviewOutput): void {
previewOutput.on('frameStart', callback);
}
```
### off('frameStart')
off(type: 'frameStart', callback?: AsyncCallback\): void
Unsubscribes from preview frame start events.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | --------------------------------------- |
| type | string | Yes | Event type. The value is fixed at **'frameStart'**. The event can be listened for when a previewOutput instance is created.|
| callback | AsyncCallback\ | 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.|
**Example**
```ts
function unregisterPreviewOutputFrameStart(previewOutput: camera.PreviewOutput): void {
previewOutput.off('frameStart');
}
```
### on('frameEnd')
on(type: 'frameEnd', callback: AsyncCallback\): void
Subscribes to preview frame end events. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------------------------- |
| 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.|
| callback | AsyncCallback\ | Yes | Callback used to return the result. The preview ends as long as this event is returned. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function callback(err: BusinessError): void {
if (err !== undefined && err.code !== 0) {
console.error(`Callback Error, errorCode: ${err.code}`);
return;
}
console.info('Preview frame ended');
}
function registerPreviewOutputFrameEnd(previewOutput: camera.PreviewOutput): void {
previewOutput.on('frameEnd', callback);
}
```
### off('frameEnd')
off(type: 'frameEnd', callback?: AsyncCallback\): void
Unsubscribes from preview frame end events.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------------------------- |
| type | string | Yes | Event type. The value is fixed at **'frameEnd'**. The event can be listened for when a previewOutput instance is created.|
| callback | AsyncCallback\ | 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.|
**Example**
```ts
function unregisterPreviewOutputFrameEnd(previewOutput: camera.PreviewOutput): void {
previewOutput.off('frameEnd');
}
```
### on('error')
on(type: 'error', callback: ErrorCallback): void
Subscribes to PreviewOutput error events. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------| ---- | ------------------------ |
| 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).|
| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | Yes | Callback used to return an error code defined in [CameraErrorCode](#cameraerrorcode). |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function callback(previewOutputError: BusinessError): void {
console.error(`Preview output error code: ${previewOutputError.code}`);
}
function registerPreviewOutputError(previewOutput: camera.PreviewOutput): void {
previewOutput.on('error', callback)
}
```
### off('error')
off(type: 'error', callback?: ErrorCallback): void
Unsubscribes from PreviewOutput error events.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------| ---- | ------------------------ |
| type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a previewOutput instance is created.|
| 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.|
**Example**
```ts
function unregisterPreviewOutputError(previewOutput: camera.PreviewOutput): void {
previewOutput.off('error');
}
```
### getSupportedFrameRates12+
getSupportedFrameRates(): Array\
Obtains the supported frame rates.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| ------------- | ------------ |
| Array<[FrameRateRange](#frameraterange)> | Array of supported frame rates.|
**Example**
```ts
function getSupportedFrameRates(previewOutput: camera.PreviewOutput): Array {
let supportedFrameRatesArray: Array = previewOutput.getSupportedFrameRates();
return supportedFrameRatesArray;
}
```
### setFrameRate12+
setFrameRate(minFps: number, maxFps: number): void
Sets 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).
> **NOTE**
>
> This API is valid only in [PhotoSession](#photosession11) or [VideoSession](#videosession11) mode.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------| ---- | ------------------------ |
| minFps | number | Yes | Minimum frame rate, in fps.|
| maxFps | number | Yes | Maximum frame rate, in fps. When the minimum value is greater than the maximum value, the API does not take effect.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400101 | Parameter missing or parameter type incorrect. |
| 7400110 | Unresolved conflicts with current configurations. |
**Example**
```ts
function setFrameRateRange(previewOutput: camera.PreviewOutput, frameRateRange: Array): void {
previewOutput.setFrameRate(frameRateRange[0], frameRateRange[1]);
}
```
### getActiveFrameRate12+
getActiveFrameRate(): FrameRateRange
Obtains the configured frame rate range.
This API is valid only after [setFrameRate](#setframerate12) is called to set a frame rate range for preview streams.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| ------------- | ------------ |
| [FrameRateRange](#frameraterange) | Frame rate range.|
**Example**
```ts
function getActiveFrameRate(previewOutput: camera.PreviewOutput): camera.FrameRateRange {
let activeFrameRate: camera.FrameRateRange = previewOutput.getActiveFrameRate();
return activeFrameRate;
}
```
### getActiveProfile12+
getActiveProfile(): Profile
Obtains the profile that takes effect currently.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| ------------- |-----------|
| [Profile](#profile) | Profile obtained.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
|---------|------------------------------|
| 7400201 | Camera service fatal error. |
**Example**
```ts
function testGetActiveProfile(previewOutput: camera.PreviewOutput): camera.Profile | undefined {
let activeProfile: camera.Profile | undefined = undefined;
try {
activeProfile = previewOutput.getActiveProfile();
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The previewOutput.getActiveProfile call failed. error code: ${err.code}`);
}
return activeProfile;
}
```
### getPreviewRotation12+
getPreviewRotation(displayRotation: number): ImageRotation
Obtains the preview rotation degree.
- Device' natural orientation: The default orientation of the device (phone) is in portrait mode, with the charging port facing downward.
- 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 landscape mode. Therefore, it needs to be rotated by 90 degrees clockwise to match the device's natural direction.
- 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.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------| ---- | ------------------------ |
| displayRotation | number | Yes | Screen rotation angle of the display. It is obtained by calling [display.getDefaultDisplaySync](../apis-arkui/js-apis-display.md#displaygetdefaultdisplaysync9).|
**Return value**
| Type | Description |
| ------------- |-----------|
| [ImageRotation](#imagerotation) | Preview rotation degree.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
|---------|------------------------------|
| 7400101 | Parameter missing or parameter type incorrect. |
| 7400201 | Camera service fatal error. |
**Example**
```ts
function testGetPreviewRotation(previewOutput: camera.PreviewOutput, imageRotation : camera.ImageRotation): camera.ImageRotation {
let previewRotation: camera.ImageRotation = camera.ImageRotation.ROTATION_0;
try {
previewRotation = previewOutput.getPreviewRotation(imageRotation);
console.log(`Preview rotation is: ${previewRotation}`);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The previewOutput.getPreviewRotation call failed. error code: ${err.code}`);
}
return previewRotation;
}
```
### setPreviewRotation12+
setPreviewRotation(previewRotation: ImageRotation, isDisplayLocked?: boolean): void
Sets the preview rotation degree.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------| ---- | ------------------------ |
| previewRotation | [ImageRotation](#imagerotation) | Yes | Preview rotation angle.|
| isDisplayLocked | boolean | No | Whether the display is locked.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
|---------|------------------------------|
| 7400101 | Parameter missing or parameter type incorrect. |
| 7400201 | Camera service fatal error. |
**Example**
```ts
function testSetPreviewRotation(previewOutput: camera.PreviewOutput, previewRotation : camera.ImageRotation, isDisplayLocked: boolean): void {
try {
previewOutput.setPreviewRotation(previewRotation, isDisplayLocked);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The previewOutput.setPreviewRotation call failed. error code: ${err.code}`);
}
return;
}
```
## ImageRotation
Enumerates the image rotation angles.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Value | Description |
| ------------ | ---- | ------------- |
| ROTATION_0 | 0 | The image rotates 0 degrees. |
| ROTATION_90 | 90 | The image rotates 90 degrees. |
| ROTATION_180 | 180 | The image rotates 180 degrees.|
| ROTATION_270 | 270 | The image rotates 270 degrees.|
## Location
Describes the geolocation information.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Type | Read-only| Optional |Description |
| ------------ | ------ | ---- |-----|------------ |
| latitude | number | No | No |Latitude, in degrees. |
| longitude | number | No | No |Longitude, in degrees. |
| altitude | number | No | No |Altitude, in meters. |
## QualityLevel
Enumerates the image quality levels.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Value | Description |
| -------------------- | ---- | ------------ |
| QUALITY_LEVEL_HIGH | 0 | High image quality. |
| QUALITY_LEVEL_MEDIUM | 1 | Medium image quality.|
| QUALITY_LEVEL_LOW | 2 | Low image quality. |
## PhotoCaptureSetting
Describes the settings for taking an image.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Type | Read-only| Optional| Description |
| -------- | ------------------------------- | ---- | ---- |----------------------------------------------------------------------|
| quality | [QualityLevel](#qualitylevel) | No | Yes | Image quality (low by default). |
| rotation | [ImageRotation](#imagerotation) | No | Yes | Rotation angle of the image. The default value is **0**, indicating clockwise rotation. |
| location | [Location](#location) | No | Yes | Geolocation information of the image (depending on the device hardware information by default). |
| 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.|
## Photo11+
Defines a full-quality image object.
### Properties
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Type | Mandatory | Description |
| ------ | ----------------------------- | -------------- | ---------- |
| main11+ | [image.Image](../apis-image-kit/arkts-apis-image-Image.md) | Yes | Full-quality image.|
### release11+
release(): Promise\
Releases output resources. This API uses a promise to return the result.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| -------------- | ----------------------- |
| Promise\ | Promise that returns no value.|
**Example**
```ts
async function releasePhoto(photo: camera.Photo): Promise {
await photo.release();
}
```
## PhotoOutput
Implements output information used in a photo session. It inherits from [CameraOutput](#cameraoutput).
### capture
capture(callback: AsyncCallback\): void
Captures a photo with the default photo capture parameters. This API uses an asynchronous callback to return the result.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------- |
| callback | AsyncCallback\ | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400104 | Session not running. |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function capture(photoOutput: camera.PhotoOutput): void {
photoOutput.capture((err: BusinessError) => {
if (err) {
console.error(`Failed to capture the photo, error code: ${err.code}.`);
return;
}
console.info('Callback invoked to indicate the photo capture request success.');
});
}
```
### capture
capture(): Promise\
Captures a photo with the default photo capture parameters. This API uses a promise to return the result.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| -------------- | ------------------------ |
| Promise\ | Promise that returns no value.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400104 | Session not running. |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function capture(photoOutput: camera.PhotoOutput): void {
photoOutput.capture().then(() => {
console.info('Promise returned to indicate that photo capture request success.');
}).catch((error: BusinessError) => {
console.error(`Failed to photo output capture, error code: ${error.code}.`);
});
}
```
### capture
capture(setting: PhotoCaptureSetting, callback: AsyncCallback\): void
Captures a photo with the specified photo capture parameters. This API uses an asynchronous callback to return the result.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------- | ---- | -------------------- |
| setting | [PhotoCaptureSetting](#photocapturesetting) | Yes | Photo capture settings. |
| callback | AsyncCallback\ | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned. |
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400101 | Parameter missing or parameter type incorrect. |
| 7400104 | Session not running. |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function capture(photoOutput: camera.PhotoOutput): void {
let captureLocation: camera.Location = {
latitude: 0,
longitude: 0,
altitude: 0
}
let settings: camera.PhotoCaptureSetting = {
quality: camera.QualityLevel.QUALITY_LEVEL_LOW,
rotation: camera.ImageRotation.ROTATION_0,
location: captureLocation,
mirror: false
}
photoOutput.capture(settings, (err: BusinessError) => {
if (err) {
console.error(`Failed to capture the photo, error code: ${err.code}.`);
return;
}
console.info('Callback invoked to indicate the photo capture request success.');
});
}
```
### capture
capture(setting: PhotoCaptureSetting): Promise\
Captures a photo with the specified photo capture parameters. This API uses a promise to return the result.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ------- | ------------------------------------------- | ---- | -------- |
| setting | [PhotoCaptureSetting](#photocapturesetting) | Yes | Photo capture parameters. The input of **undefined** is processed as if no parameters were passed.|
**Return value**
| Type | Description |
| -------------- | ------------------------ |
| Promise\ | Promise that returns no value.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400101 | Parameter missing or parameter type incorrect. |
| 7400104 | Session not running. |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function capture(photoOutput: camera.PhotoOutput): void {
let captureLocation: camera.Location = {
latitude: 0,
longitude: 0,
altitude: 0
}
let settings: camera.PhotoCaptureSetting = {
quality: camera.QualityLevel.QUALITY_LEVEL_LOW,
rotation: camera.ImageRotation.ROTATION_0,
location: captureLocation,
mirror: false
}
photoOutput.capture(settings).then(() => {
console.info('Promise returned to indicate that photo capture request success.');
}).catch((error: BusinessError) => {
console.error(`Failed to photo output capture, error code: ${error.code}.`);
});
}
```
### on('photoAvailable')11+
on(type: 'photoAvailable', callback: AsyncCallback\): void
Subscribes to events indicating available high-resolution images. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------- | --- | ------------------------------------ |
| type | string | Yes | Event type. The value is fixed at **'photoAvailable'**. The event can be listened for when a photoOutput instance is created.|
| callback | AsyncCallback\<[Photo](#photo11)\> | Yes | Callback used to return the high-resolution image.|
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
import { image } from '@kit.ImageKit';
function callback(err: BusinessError, photo: camera.Photo): void {
if (err !== undefined && err.code !== 0) {
console.error(`Callback Error, errorCode: ${err.code}`);
return;
}
let mainImage: image.Image = photo.main;
}
function registerPhotoOutputPhotoAvailable(photoOutput: camera.PhotoOutput): void {
photoOutput.on('photoAvailable', callback);
}
```
### off('photoAvailable')11+
off(type: 'photoAvailable', callback?: AsyncCallback\): void
Unsubscribes from events indicating available high-resolution images.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | ------------------------------------------ |
| type | string | Yes | Event type. The value is fixed at **'photoAvailable'**. The event can be listened for when a photoOutput instance is created.|
| 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.|
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
import { image } from '@kit.ImageKit';
function callback(err: BusinessError, photo: camera.Photo): void {
if (err !== undefined && err.code !== 0) {
console.error(`Callback Error, errorCode: ${err.code}`);
return;
}
let mainImage: image.Image = photo.main;
}
function unRegisterPhotoOutputPhotoAvailable(photoOutput: camera.PhotoOutput): void {
photoOutput.off('photoAvailable', callback);
}
```
### on('captureStartWithInfo')11+
on(type: 'captureStartWithInfo', callback: AsyncCallback\): void
Subscribes to capture start events. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------- | --- | ------------------------------------ |
| type | string | Yes | Event type. The value is fixed at **'captureStartWithInfo'**. The event can be listened for when a photoOutput instance is created.|
| callback | AsyncCallback\<[CaptureStartInfo](#capturestartinfo11)\> | Yes | Callback used to return the capture ID.|
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function callback(err: BusinessError, captureStartInfo: camera.CaptureStartInfo): void {
if (err !== undefined && err.code !== 0) {
console.error(`Callback Error, errorCode: ${err.code}`);
return;
}
console.info(`photo capture started, captureStartInfo : ${captureStartInfo}`);
}
function registerCaptureStartWithInfo(photoOutput: camera.PhotoOutput): void {
photoOutput.on('captureStartWithInfo', callback);
}
```
### off('captureStartWithInfo')11+
off(type: 'captureStartWithInfo', callback?: AsyncCallback\): void
Unsubscribes from capture start events.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | ------------------------------------------ |
| type | string | Yes | Event type. The value is fixed at **'captureStartWithInfo'**. The event can be listened for when a photoOutput instance is created.|
| 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.|
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function unRegisterCaptureStartWithInfo(photoOutput: camera.PhotoOutput): void {
photoOutput.off('captureStartWithInfo');
}
```
### isMovingPhotoSupported12+
isMovingPhotoSupported(): boolean
Checks whether taking moving photos is supported.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| -------------- | ----------------------- |
| boolean | Check result for the support of taking moving photos. **true** if supported, **false** otherwise.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| -------------- | --------------- |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function isMovingPhotoSupported(photoOutput: camera.PhotoOutput): boolean {
let isSupported: boolean = false;
try {
isSupported = photoOutput.isMovingPhotoSupported();
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The isMovingPhotoSupported call failed. error code: ${err.code}`);
}
return isSupported;
}
```
### enableMovingPhoto12+
enableMovingPhoto(enabled: boolean): void
Enables or disables the feature of taking moving photos.
**Required permissions:** ohos.permission.MICROPHONE
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | ------------------------------------------ |
| enabled | boolean | Yes | Whether to enable the feature of taking moving photos. **true** to enable, **false** otherwise. |
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| -------- |------------------------------------------------|
| 201 | permission denied. |
| 7400101 | Parameter missing or parameter type incorrect. |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function enableMovingPhoto(photoOutput: camera.PhotoOutput): void {
try {
photoOutput.enableMovingPhoto(true);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The enableMovingPhoto call failed. error code: ${err.code}`);
}
}
```
### on('photoAssetAvailable')12+
on(type: 'photoAssetAvailable', callback: AsyncCallback\): void
Subscribes to photo asset available events. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------- | --- | ------------------------------------ |
| type | string | Yes | Event type. The value is fixed at **'photoAssetAvailable'**. The event can be listened for when a photoOutput instance is created.|
| callback | AsyncCallback\<[photoAccessHelper.PhotoAsset](../apis-media-library-kit/js-apis-photoAccessHelper.md#photoasset)\> | Yes | Callback used to return the photo asset.|
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
import { photoAccessHelper } from '@kit.MediaLibraryKit';
function photoAssetAvailableCallback(err: BusinessError, photoAsset: photoAccessHelper.PhotoAsset): void {
if (err) {
console.info(`photoAssetAvailable error: ${JSON.stringify(err)}.`);
return;
}
console.info('photoOutPutCallBack photoAssetAvailable');
// You can use photoAsset to obtain image information.
}
function onPhotoOutputPhotoAssetAvailable(photoOutput: camera.PhotoOutput): void {
photoOutput.on('photoAssetAvailable', photoAssetAvailableCallback);
}
```
### off('photoAssetAvailable')12+
off(type: 'photoAssetAvailable', callback?: AsyncCallback\): void
Unsubscribes from photo asset available events.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------- |-----|----------------------------------------------------------------------------|
| type | string | Yes | Event type. The value is fixed at **'photoAssetAvailable'**. The event can be listened for when a photoOutput instance is created. |
| 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.|
**Example**
```ts
function offPhotoOutputPhotoAssetAvailable(photoOutput: camera.PhotoOutput): void {
photoOutput.off('photoAssetAvailable');
}
```
### isMirrorSupported
isMirrorSupported(): boolean
Checks whether mirror photography is supported.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| -------------- | ----------------------- |
| boolean | Check result for the support of mirror photography. **true** if supported, **false** otherwise.|
**Example**
```ts
function isMirrorSupported(photoOutput: camera.PhotoOutput): boolean {
let isSupported: boolean = photoOutput.isMirrorSupported();
return isSupported;
}
```
### enableMirror13+
enableMirror(enabled: boolean): void
Enables dynamic photo capture.
Before calling this API, check whether dynamic photo capture is supported by calling [isMovingPhotoSupported](#ismovingphotosupported12) and whether mirroring is supported by calling [isMirrorSupported](#ismirrorsupported).
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
|----------| ---------------------- | ---- |---------------------------|
| enabled | boolean | Yes | Whether to enable or disable dynamic photo capture. **true** to enable, **false** otherwise.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| -------- |------------------------------------------------|
| 7400101 | Parameter missing or parameter type incorrect. |
| 7400103 | Session not config. |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function enableMirror(photoOutput: camera.PhotoOutput): void {
try {
photoOutput.enableMirror(true);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The enableMirror call failed. error code: ${err.code}`);
}
}
```
### getSupportedMovingPhotoVideoCodecTypes13+
getSupportedMovingPhotoVideoCodecTypes(): Array\
Obtains the supported video codec types of moving photos.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| -------------- |-------------------|
| Array\<[VideoCodecType](#videocodectype13)\> | Array holding the supported video codec types.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400201 | Camera service fatal error. |
**Example**
```ts
function getSupportedMovingPhotoVideoCodecType(photoOutput: camera.PhotoOutput): Array {
let supportedVideoCodecTypesArray: Array = photoOutput.getSupportedMovingPhotoVideoCodecTypes();
return supportedVideoCodecTypesArray;
}
```
### setMovingPhotoVideoCodecType13+
setMovingPhotoVideoCodecType(codecType: VideoCodecType): void
Sets a video codec type for moving photos.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ------------- |-------------------------------------|-------| ------------ |
| codecType | [VideoCodecType](#videocodectype13) | Yes |Video codec type. |
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400201 | Camera service fatal error. |
**Example**
```ts
function setMovingPhotoVideoCodecTypes(photoOutput: camera.PhotoOutput, videoCodecType: camera.VideoCodecType): void {
photoOutput.setMovingPhotoVideoCodecType(videoCodecType);
}
```
### on('captureStart')(deprecated)
on(type: 'captureStart', callback: AsyncCallback\): void
Subscribes to capture start events. This API uses an asynchronous callback to return the result.
> **NOTE**
> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [on('captureStartWithInfo')](#oncapturestartwithinfo11) instead.
>
> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | ------------------------------------------ |
| 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.|
| callback | AsyncCallback\ | Yes | Callback used to return the capture ID. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function callback(err: BusinessError, captureId: number): void {
if (err !== undefined && err.code !== 0) {
console.error(`Callback Error, errorCode: ${err.code}`);
return;
}
console.info(`photo capture started, captureId : ${captureId}`);
}
function registerPhotoOutputCaptureStart(photoOutput: camera.PhotoOutput): void {
photoOutput.on('captureStart', callback);
}
```
### off('captureStart')(deprecated)
off(type: 'captureStart', callback?: AsyncCallback\): void
Unsubscribes from capture start events.
> **NOTE**
> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [off('captureStartWithInfo')](#offcapturestartwithinfo11) instead.
>
> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | ------------------------------------------ |
| type | string | Yes | Event type. The value is fixed at **'captureStart'**. The event can be listened for when a photoOutput instance is created.|
| callback | AsyncCallback\ | 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.|
**Example**
```ts
function unregisterPhotoOutputCaptureStart(photoOutput: camera.PhotoOutput): void {
photoOutput.off('captureStart');
}
```
### on('frameShutter')
on(type: 'frameShutter', callback: AsyncCallback\): void
Subscribes to frame shutter events. This API uses an asynchronous callback to return the result.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------- | --- | ------------------------------------ |
| type | string | Yes | Event type. The value is fixed at **'frameShutter'**. The event can be listened for when a photoOutput instance is created.|
| callback | AsyncCallback\<[FrameShutterInfo](#frameshutterinfo)\> | Yes | Callback used to return the result. A new photo capture request can be delivered as long as this event is returned. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function callback(err: BusinessError, frameShutterInfo: camera.FrameShutterInfo): void {
if (err !== undefined && err.code !== 0) {
console.error(`Callback Error, errorCode: ${err.code}`);
return;
}
console.info(`CaptureId for frame : ${frameShutterInfo.captureId}`);
console.info(`Timestamp for frame : ${frameShutterInfo.timestamp}`);
}
function registerPhotoOutputFrameShutter(photoOutput: camera.PhotoOutput): void {
photoOutput.on('frameShutter', callback);
}
```
### off('frameShutter')
off(type: 'frameShutter', callback?: AsyncCallback\): void
Unsubscribes from frame shutter events.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------- | --- | ------------------------------------ |
| type | string | Yes | Event type. The value is fixed at **'frameShutter'**. The event can be listened for when a photoOutput instance is created.|
| 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.|
**Example**
```ts
function unregisterPhotoOutputFrameShutter(photoOutput: camera.PhotoOutput): void {
photoOutput.off('frameShutter');
}
```
### on('captureEnd')
on(type: 'captureEnd', callback: AsyncCallback\): void
Subscribes to capture end events. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------- | ---- | ---------------------------------------- |
| 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 photo capture is complete.|
| callback | AsyncCallback\<[CaptureEndInfo](#captureendinfo)\> | Yes | Callback used to return the result. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function callback(err: BusinessError, captureEndInfo: camera.CaptureEndInfo): void {
if (err !== undefined && err.code !== 0) {
console.error(`Callback Error, errorCode: ${err.code}`);
return;
}
console.info(`photo capture end, captureId : ${captureEndInfo.captureId}`);
console.info(`frameCount : ${captureEndInfo.frameCount}`);
}
function registerPhotoOutputCaptureEnd(photoOutput: camera.PhotoOutput): void {
photoOutput.on('captureEnd', callback);
}
```
### off('captureEnd')
off(type: 'captureEnd', callback?: AsyncCallback\): void
Unsubscribes from capture end events.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value is fixed at **'captureEnd'**. The event can be listened for when a photoOutput instance is created.|
| 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.|
**Example**
```ts
function unregisterPhotoOutputCaptureEnd(photoOutput: camera.PhotoOutput): void {
photoOutput.off('captureEnd');
}
```
### on('frameShutterEnd')12+
on(type: 'frameShutterEnd', callback: AsyncCallback\): void
Subscribes to frame shutter end events. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type | string | Yes | Event type. The value is fixed at **'frameShutterEnd'**. The event can be listened for when a photoOutput instance is created.|
| callback | AsyncCallback\<[FrameShutterEndInfo](#frameshutterendinfo12)\> | Yes | Callback used to return the result. It is invoked when the frame shutter ends. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function callback(err: BusinessError, frameShutterEndInfo: camera.FrameShutterEndInfo): void {
if (err !== undefined && err.code !== 0) {
console.error(`Callback Error, errorCode: ${err.code}`);
return;
}
console.info(`CaptureId for frame : ${frameShutterEndInfo.captureId}`);
}
function registerPhotoOutputFrameShutterEnd(photoOutput: camera.PhotoOutput): void {
photoOutput.on('frameShutterEnd', callback);
}
```
### off('frameShutterEnd')12+
off(type: 'frameShutterEnd', callback?: AsyncCallback\): void
Unsubscribes from frame shutter end events.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type | string | Yes | Event type. The value is fixed at **'frameShutterEnd'**. The event can be listened for when a photoOutput instance is created.|
| 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.|
**Example**
```ts
function unregisterPhotoOutputFrameShutterEnd(photoOutput: camera.PhotoOutput): void {
photoOutput.off('frameShutterEnd');
}
```
### on('captureReady')12+
on(type: 'captureReady', callback: AsyncCallback\): void
Subscribes to capture ready events. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------- | ---- | ------------------------------------------------------------ |
| 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.|
| callback | AsyncCallback\ | Yes | Callback used to return the result. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function callback(err: BusinessError): void {
if (err !== undefined && err.code !== 0) {
console.error(`Callback Error, errorCode: ${err.code}`);
return;
}
console.info(`photo capture ready`);
}
function registerPhotoOutputCaptureReady(photoOutput: camera.PhotoOutput): void {
photoOutput.on('captureReady', callback);
}
```
### off('captureReady')12+
off(type: 'captureReady', callback?: AsyncCallback\): void
Unsubscribes from capture ready events.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type | string | Yes | Event type. The value is fixed at **'captureReady'**. The event can be listened for when a photoOutput instance is created.|
| 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.|
**Example**
```ts
function unregisterPhotoOutputCaptureReady(photoOutput: camera.PhotoOutput): void {
photoOutput.off('captureReady');
}
```
### on('estimatedCaptureDuration')12+
on(type: 'estimatedCaptureDuration', callback: AsyncCallback\): void
Subscribes to estimated capture duration events. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | ------------------------------------------------------------ |
| 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 photo capture is complete.|
| callback | AsyncCallback\ | 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. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function callback(err: BusinessError, duration: number): void {
if (err !== undefined && err.code !== 0) {
console.error(`Callback Error, errorCode: ${err.code}`);
return;
}
console.info(`photo estimated capture duration : ${duration}`);
}
function registerPhotoOutputEstimatedCaptureDuration(photoOutput: camera.PhotoOutput): void {
photoOutput.on('estimatedCaptureDuration', callback);
}
```
### off('estimatedCaptureDuration')12+
off(type: 'estimatedCaptureDuration', callback?: AsyncCallback\): void
Unsubscribes from estimated capture duration events.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | ------------------------------------------------------------ |
| type | string | Yes | Event type. The value is fixed at **'estimatedCaptureDuration'**. The event can be listened for when a photoOutput instance is created.|
| callback | AsyncCallback\ | 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.|
**Example**
```ts
function unregisterPhotoOutputEstimatedCaptureDuration(photoOutput: camera.PhotoOutput): void {
photoOutput.off('estimatedCaptureDuration');
}
```
### on('error')
on(type: 'error', callback: ErrorCallback): void
Subscribes to PhotoOutput error events. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------- | ---- | ----------------------------------- |
| 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.|
| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | Yes | Callback used to return an error code defined in [CameraErrorCode](#cameraerrorcode). |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function callback(err: BusinessError): void {
console.error(`Photo output error code: ${err.code}`);
}
function registerPhotoOutputError(photoOutput: camera.PhotoOutput): void {
photoOutput.on('error', callback);
}
```
### off('error')
off(type: 'error', callback?: ErrorCallback): void
Unsubscribes from PhotoOutput error events.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------- | ---- | ----------------------------------- |
| type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a photoOutput instance is created.|
| 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.|
**Example**
```ts
function unregisterPhotoOutputError(photoOutput: camera.PhotoOutput): void {
photoOutput.off('error');
}
```
### getActiveProfile12+
getActiveProfile(): Profile
Obtains the profile that takes effect currently.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| ------------- |-----------|
| [Profile](#profile) | Profile obtained.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
|---------|------------------------------|
| 7400201 | Camera service fatal error. |
**Example**
```ts
function testGetActiveProfile(photoOutput: camera.PhotoOutput): camera.Profile | undefined {
let activeProfile: camera.Profile | undefined = undefined;
try {
activeProfile = photoOutput.getActiveProfile();
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The photoOutput.getActiveProfile call failed. error code: ${err.code}`);
}
return activeProfile;
}
```
### getPhotoRotation12+
getPhotoRotation(deviceDegree: number): ImageRotation
Obtains the photo rotation degree.
- Device' natural orientation: The default orientation of the device (phone) is in portrait mode, with the charging port facing downward.
- 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 landscape mode. Therefore, it needs to be rotated by 90 degrees clockwise to match the device's natural direction.
- 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.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------| ---- | ------------------------ |
| deviceDegree | number | Yes | Rotation angle.|
**Return value**
| Type | Description |
| ------------- |-----------|
| [ImageRotation](#imagerotation) | Photo rotation degree.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
|---------|------------------------------|
| 7400101 | Parameter missing or parameter type incorrect. |
| 7400201 | Camera service fatal error. |
**Example**
```ts
function testGetPhotoRotation(photoOutput: camera.PhotoOutput, deviceDegree : number): camera.ImageRotation {
let photoRotation: camera.ImageRotation = camera.ImageRotation.ROTATION_0;
try {
photoRotation = photoOutput.getPhotoRotation(deviceDegree);
console.log(`Photo rotation is: ${photoRotation}`);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The photoOutput.getPhotoRotation call failed. error code: ${err.code}`);
}
return photoRotation;
}
```
## FrameShutterInfo
Describes the frame shutter information.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Type | Read-only| Optional| Description |
| --------- | ------ | ---- | ---- | ---------- |
| captureId | number | No | No | ID of this capture action.|
| timestamp | number | No | No | Timestamp when the frame shutter event is triggered.|
## FrameShutterEndInfo12+
Describes the frame shutter end information during capture.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Type | Read-only| Optional| Description |
| --------- | ------ | ---- | ---- | ---------- |
| captureId | number | No | No | ID of this capture action.|
## CaptureStartInfo11+
Describes the capture start information.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Type | Read-only| Optional| Description |
| ---------- | ------ | ---- | ---- | --------- |
| captureId | number | No | No | ID of this capture action.|
| 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. |
## CaptureEndInfo
Describes the capture end information.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Type | Read-only| Optional| Description |
| ---------- | ------ | ---- | ---- | ---------|
| captureId | number | No | No | ID of this capture action.|
| frameCount | number | No | No | Number of frames captured.|
## AutoDeviceSwitchStatus13+
Describes the information about the automatic camera switch status.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Type | Read-only| Optional| Description |
| ---------- |---------| ---- | ---- |-------------------------|
| isDeviceSwitched | boolean | No | No | Whether the camera is automatically switched. **true** if auto-switched, **false** otherwise. |
| isDeviceCapabilityChanged | boolean | No | No | Whether the camera capability is changed after the camera is automatically switched. **true** if changed, **false** otherwise.|
## VideoOutput
Implements output information used in a video session. It inherits from [CameraOutput](#cameraoutput).
### start
start(callback: AsyncCallback\): void
Starts video recording. This API uses an asynchronous callback to return the result.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | -------------------- |
| callback | AsyncCallback\ | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400103 | Session not config. |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function startVideoOutput(videoOutput: camera.VideoOutput): void {
videoOutput.start((err: BusinessError) => {
if (err) {
console.error(`Failed to start the video output, error code: ${err.code}.`);
return;
}
console.info('Callback invoked to indicate the video output start success.');
});
}
```
### start
start(): Promise\
Starts video recording. This API uses a promise to return the result.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| -------------- | ----------------------- |
| Promise\ | Promise that returns no value.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400103 | Session not config. |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function startVideoOutput(videoOutput: camera.VideoOutput): void {
videoOutput.start().then(() => {
console.info('Promise returned to indicate that start method execution success.');
}).catch((error: BusinessError) => {
console.error(`Failed to video output start, error code: ${error.code}.`);
});
}
```
### stop
stop(callback: AsyncCallback\): void
Stops video recording. This API uses an asynchronous callback to return the result.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback\ | Yes | Callback used to return the result.|
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function stopVideoOutput(videoOutput: camera.VideoOutput): void {
videoOutput.stop((err: BusinessError) => {
if (err) {
console.error(`Failed to stop the video output, error code: ${err.code}.`);
return;
}
console.info('Callback invoked to indicate the video output stop success.');
});
}
```
### stop
stop(): Promise\
Stops video recording. This API uses a promise to return the result.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| -------------- | ----------------------- |
| Promise\ | Promise that returns no value.|
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function stopVideoOutput(videoOutput: camera.VideoOutput): void {
videoOutput.stop().then(() => {
console.info('Promise returned to indicate that stop method execution success.');
}).catch((error: BusinessError) => {
console.error(`Failed to video output stop, error code: ${error.code}.`);
});
}
```
### on('frameStart')
on(type: 'frameStart', callback: AsyncCallback\): void
Subscribes to video recording start events. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ----------------------------------------- |
| 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.|
| callback | AsyncCallback\ | Yes | Callback used to return the result. The recording starts as long as this event is returned. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function callback(err: BusinessError): void {
if (err !== undefined && err.code !== 0) {
console.error(`Callback Error, errorCode: ${err.code}`);
return;
}
console.info('Video frame started');
}
function registerVideoOutputFrameStart(videoOutput: camera.VideoOutput): void {
videoOutput.on('frameStart', callback);
}
```
### off('frameStart')
off(type: 'frameStart', callback?: AsyncCallback\): void
Unsubscribes from video recording start events.
> **NOTE**
>
> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ----------------------------------------- |
| type | string | Yes | Event type. The value is fixed at **'frameStart'**. The event can be listened for when a videoOutput instance is created.|
| callback | AsyncCallback\ | 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.|
**Example**
```ts
function unregisterVideoOutputFrameStart(videoOutput: camera.VideoOutput): void {
videoOutput.off('frameStart');
}
```
### on('frameEnd')
on(type: 'frameEnd', callback: AsyncCallback\): void
Subscribes to video recording stop events. This API uses an asynchronous callback to return the result.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------------------------------ |
| 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.|
| callback | AsyncCallback\ | Yes | Callback used to return the result. The recording ends as long as this event is returned. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function callback(err: BusinessError): void {
if (err !== undefined && err.code !== 0) {
console.error(`Callback Error, errorCode: ${err.code}`);
return;
}
console.info('Video frame ended');
}
function registerVideoOutputFrameEnd(videoOutput: camera.VideoOutput): void {
videoOutput.on('frameEnd', callback);
}
```
### off('frameEnd')
off(type: 'frameEnd', callback?: AsyncCallback\): void
Unsubscribes from video recording stop events.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------------------------------ |
| type | string | Yes | Event type. The value is fixed at **'frameEnd'**. The event can be listened for when a videoOutput instance is created.|
| callback | AsyncCallback\ | 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.|
**Example**
```ts
function unregisterVideoOutputFrameEnd(videoOutput: camera.VideoOutput): void {
videoOutput.off('frameEnd');
}
```
### on('error')
on(type: 'error', callback: ErrorCallback): void
Subscribes to VideoOutput error events. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------- | ---- | -------------------------------------- |
| 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).|
| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | Yes | Callback used to return an error code defined in [CameraErrorCode](#cameraerrorcode). |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function callback(err: BusinessError): void {
console.error(`Video output error code: ${err.code}`);
}
function registerVideoOutputError(videoOutput: camera.VideoOutput): void {
videoOutput.on('error', callback);
}
```
### off('error')
off(type: 'error', callback?: ErrorCallback): void
Unsubscribes from VideoOutput error events.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------- | ---- | ----------------------------------- |
| type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a photoOutput instance is created.|
| 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.|
**Example**
```ts
function unregisterVideoOutputError(videoOutput: camera.VideoOutput): void {
videoOutput.off('error');
}
```
### getSupportedFrameRates12+
getSupportedFrameRates(): Array\
Obtains the supported frame rates.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| ------------- | ------------ |
| Array<[FrameRateRange](#frameraterange)> | Array of supported frame rates.|
**Example**
```ts
function getSupportedFrameRates(videoOutput: camera.VideoOutput): Array {
let supportedFrameRatesArray: Array = videoOutput.getSupportedFrameRates();
return supportedFrameRatesArray;
}
```
### setFrameRate12+
setFrameRate(minFps: number, maxFps: number): void
Sets a frame rate range for video streams. The range must be within the supported frame rate range, which can be obtained by calling [getSupportedFrameRates](#getsupportedframerates12-1).
> **NOTE**
>
> This API is valid only in [PhotoSession](#photosession11) or [VideoSession](#videosession11) mode.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------| ---- | ------------------------ |
| minFps | number | Yes | Minimum frame rate.|
| maxFps | number | Yes | Maximum frame rate. When the minimum value is greater than the maximum value, the API does not take effect.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400101 | Parameter missing or parameter type incorrect. |
| 7400110 | Unresolved conflicts with current configurations. |
**Example**
```ts
function setFrameRateRange(videoOutput: camera.VideoOutput, frameRateRange: Array): void {
videoOutput.setFrameRate(frameRateRange[0], frameRateRange[1]);
}
```
### getActiveFrameRate12+
getActiveFrameRate(): FrameRateRange
Obtains the configured frame rate range.
This API is valid only after [setFrameRate](#setframerate12-1) is called to set a frame rate range for video streams.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| ------------- | ------------ |
| [FrameRateRange](#frameraterange) | Frame rate range.|
**Example**
```ts
function getActiveFrameRate(videoOutput: camera.VideoOutput): camera.FrameRateRange {
let activeFrameRate: camera.FrameRateRange = videoOutput.getActiveFrameRate();
return activeFrameRate;
}
```
### getActiveProfile12+
getActiveProfile(): VideoProfile
Obtains the profile that takes effect currently.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| ------------- |-----------|
| [VideoProfile](#videoprofile) | Profile obtained.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
|---------|------------------------------|
| 7400201 | Camera service fatal error. |
**Example**
```ts
function testGetActiveProfile(videoOutput: camera.VideoOutput): camera.Profile | undefined {
let activeProfile: camera.VideoProfile | undefined = undefined;
try {
activeProfile = videoOutput.getActiveProfile();
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The videoOutput.getActiveProfile call failed. error code: ${err.code}`);
}
return activeProfile;
}
```
### isMirrorSupported15+
isMirrorSupported(): boolean
Checks whether mirror recording is supported.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| -------------- |---------------------------------|
| boolean | Check result for the support of mirror recording. **true** if supported, **false** otherwise.|
**Example**
```ts
function testIsMirrorSupported(videoOutput: camera.VideoOutput): boolean {
let isSupported: boolean = videoOutput.isMirrorSupported();
return isSupported;
}
```
### enableMirror15+
enableMirror(enabled: boolean): void
Enables or disables mirror recording.
- Before calling this API, check whether mirror recording is supported by using [isMirrorSupported](#ismirrorsupported15).
- After enabling or disabling mirror recording, call [getVideoRotation](#getvideorotation12) and [updateRotation](../apis-media-kit/js-apis-media.md#updaterotation12) to update the rotation angle.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
|----------| ---------------------- | ---- |---------------------------|
| enabled | boolean | Yes | Whether to enable mirror recording. **true** to enable, **false** otherwise.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| -------- |------------------------------------------------|
| 7400101 | Parameter missing or parameter type incorrect. |
| 7400103 | Session not config. |
**Example**
```ts
import { camera } from '@kit.CameraKit';
import { media } from '@kit.MediaKit';
import { BusinessError } from '@kit.BasicServicesKit';
function enableMirror(videoOutput: camera.VideoOutput, mirrorMode: boolean, aVRecorder: media.AVRecorder, deviceDegree : number): void {
try {
videoOutput.enableMirror(mirrorMode);
aVRecorder.updateRotation(videoOutput.getVideoRotation(deviceDegree));
} catch (error) {
let err = error as BusinessError;
}
}
```
### getVideoRotation12+
getVideoRotation(deviceDegree: number): ImageRotation
Obtains the video rotation degree.
- Device' natural orientation: The default orientation of the device (phone) is in portrait mode, with the charging port facing downward.
- 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 landscape mode. Therefore, it needs to be rotated by 90 degrees clockwise to match the device's natural direction.
- 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.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------| ---- | ------------------------ |
| deviceDegree | number | Yes | Rotation angle, in degrees.|
**Return value**
| Type | Description |
| ------------- |-----------|
| [ImageRotation](#imagerotation) | Video rotation degree.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
|---------|------------------------------|
| 7400101 | Parameter missing or parameter type incorrect. |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { camera } from '@kit.CameraKit';
import { Decimal } from '@kit.ArkTS';
import { sensor } from '@kit.SensorServiceKit';
import { BusinessError } from '@kit.BasicServicesKit';
function getVideoRotation(videoOutput: camera.VideoOutput): camera.ImageRotation {
let videoRotation: camera.ImageRotation = camera.ImageRotation.ROTATION_0;
try {
videoRotation = videoOutput.getVideoRotation(getDeviceDegree());
} catch (error) {
let err = error as BusinessError;
}
return videoRotation;
}
// Obtain deviceDegree.
function getDeviceDegree(): number {
let deviceDegree: number = -1;
try {
sensor.once(sensor.SensorId.GRAVITY, (data: sensor.GravityResponse) => {
console.info('Succeeded in invoking once. X-coordinate component: ' + data.x);
console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y);
console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z);
let x = data.x;
let y = data.y;
let z = data.z;
if ((x * x + y * y) * 3 < z * z) {
deviceDegree = -1;
} else {
let sd: Decimal = Decimal.atan2(y, -x);
let sc: Decimal = Decimal.round(Number(sd) / 3.141592653589 * 180)
deviceDegree = 90 - Number(sc);
deviceDegree = deviceDegree >= 0 ? deviceDegree% 360 : deviceDegree% 360 + 360;
}
});
} catch (error) {
let err: BusinessError = error as BusinessError;
}
return deviceDegree;
}
```
## MetadataOutput
Implements metadata streams. It inherits from [CameraOutput](#cameraoutput).
### start
start(callback: AsyncCallback\): void
Starts to output metadata. This API uses an asynchronous callback to return the result.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------------- | ---- | ------------------- |
| callback | AsyncCallback\ | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400103 | Session not config. |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function startMetadataOutput(metadataOutput: camera.MetadataOutput): void {
metadataOutput.start((err: BusinessError) => {
if (err) {
console.error(`Failed to start metadata output, error code: ${err.code}.`);
return;
}
console.info('Callback returned with metadata output started.');
});
}
```
### start
start(): Promise\
Starts to output metadata. This API uses a promise to return the result.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| ---------------------- | ------------------------ |
| Promise\ | Promise that returns no value.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400103 | Session not config. |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function startMetadataOutput(metadataOutput: camera.MetadataOutput): void {
metadataOutput.start().then(() => {
console.info('Callback returned with metadata output started.');
}).catch((error: BusinessError) => {
console.error(`Failed to metadata output stop, error code: ${error.code}`);
});
}
```
### stop
stop(callback: AsyncCallback\): void
Stops outputting metadata. This API uses an asynchronous callback to return the result.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------------- | ---- | ------------------- |
| callback | AsyncCallback\ | Yes | Callback used to return the result.|
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function stopMetadataOutput(metadataOutput: camera.MetadataOutput): void {
metadataOutput.stop((err: BusinessError) => {
if (err) {
console.error(`Failed to stop the metadata output, error code: ${err.code}.`);
return;
}
console.info('Callback returned with metadata output stopped.');
})
}
```
### stop
stop(): Promise\
Stops outputting metadata. This API uses a promise to return the result.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| ---------------------- | --------------------------- |
| Promise\ | Promise that returns no value.|
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function stopMetadataOutput(metadataOutput: camera.MetadataOutput): void {
metadataOutput.stop().then(() => {
console.info('Callback returned with metadata output stopped.');
}).catch((error: BusinessError) => {
console.error(`Failed to metadata output stop, error code: ${error.code}`);
});
}
```
### on('metadataObjectsAvailable')
on(type: 'metadataObjectsAvailable', callback: AsyncCallback\\>): void
Subscribes to events indicating available metadata objects. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------- | ---- | ------------------------------------ |
| 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.|
| callback | AsyncCallback\\> | Yes | Callback used to return the metadata.|
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function callback(err: BusinessError, metadataObjectArr: Array): void {
if (err !== undefined && err.code !== 0) {
console.error(`Callback Error, errorCode: ${err.code}`);
return;
}
console.info('metadata output metadataObjectsAvailable');
}
function registerMetadataObjectsAvailable(metadataOutput: camera.MetadataOutput): void {
metadataOutput.on('metadataObjectsAvailable', callback);
}
```
### off('metadataObjectsAvailable')
off(type: 'metadataObjectsAvailable', callback?: AsyncCallback\\>): void
Unsubscribes from events indicating available metadata objects.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------- | ---- | ------------------------------------ |
| type | string | Yes | Event type. The value is fixed at **'metadataObjectsAvailable'**. The event can be listened for when a metadataOutput instance is created.|
| callback | AsyncCallback\\> | 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.|
**Example**
```ts
function unregisterMetadataObjectsAvailable(metadataOutput: camera.MetadataOutput): void {
metadataOutput.off('metadataObjectsAvailable');
}
```
### on('error')
on(type: 'error', callback: ErrorCallback): void
Subscribes to metadata error events. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------- | ---- | --------------------------------------- |
| 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).|
| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | Yes | Callback used to return an error code defined in [CameraErrorCode](#cameraerrorcode). |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function callback(metadataOutputError: BusinessError): void {
console.error(`Metadata output error code: ${metadataOutputError.code}`);
}
function registerMetadataOutputError(metadataOutput: camera.MetadataOutput): void {
metadataOutput.on('error', callback);
}
```
### off('error')
off(type: 'error', callback?: ErrorCallback): void
Unsubscribes from metadata error events.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------- | ---- | --------------------------------------- |
| type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a metadataOutput instance is created.|
| 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.|
**Example**
```ts
function unregisterMetadataOutputError(metadataOutput: camera.MetadataOutput): void {
metadataOutput.off('error');
}
```
## MetadataObjectType
Enumerates the metadata object types.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Value | Description |
| ------------------------- | ---- | ----------------- |
| FACE_DETECTION | 0 | Metadata object used for face detection.
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).
The coordinate system is based on the horizontal device direction with the device's charging port on the right.
If the layout of a 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 return point is (x, y), then the coordinate point after conversion is (1-y, x).|
## Rect
Describes a rectangle.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Type | Read-only | Optional | Description |
| -------- | ------ | ------ |-----| --------------------- |
| topLeftX | number | No | No | X-axis coordinate of the upper left corner of the rectangle. |
| topLeftY | number | No | No | Y-axis coordinate of the upper left corner of the rectangle. |
| width | number | No | No | Width of the rectangle, which is a relative value. The value range is [0, 1]. |
| height | number | No | No | Height of the rectangle, which is a relative value. The value range is [0, 1]. |
## MetadataObject
Describes the camera metadata, which is the data source of [CameraInput](#camerainput). The metadata is obtained through metadataOutput.on('metadataObjectsAvailable').
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Type | Read-only| Optional|Description |
| ----------- | ------------------------------------------- | ---- | ---- | ----------------- |
| type | [MetadataObjectType](#metadataobjecttype) | Yes | No | Metadata object type. |
| timestamp | number | Yes | No | Current timestamp, in milliseconds.|
| boundingBox | [Rect](#rect) | Yes | No | Metadata rectangle. |
## FlashMode
Enumerates the flash modes.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Value | Description |
| ---------------------- | ---- | ---------- |
| FLASH_MODE_CLOSE | 0 | The flash is off.|
| FLASH_MODE_OPEN | 1 | The flash is on.|
| FLASH_MODE_AUTO | 2 | The flash mode is auto, indicating that the flash fires automatically depending on the photo capture conditions.|
| FLASH_MODE_ALWAYS_OPEN | 3 | The flash is steady on.|
## ExposureMode
Enumerates the exposure modes.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Value | Description |
| ----------------------------- | ---- | ----------- |
| EXPOSURE_MODE_LOCKED | 0 | Exposure locked. The metering point cannot be set.|
| EXPOSURE_MODE_AUTO | 1 | Auto exposure. The metering point can be set by calling [AutoExposure.setMeteringPoint](#setmeteringpoint11).|
| EXPOSURE_MODE_CONTINUOUS_AUTO | 2 | Continuous auto exposure. The metering point cannot be set.|
## FocusMode
Enumerates the focus modes.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Value | Description |
| -------------------------- | ---- | ------------ |
| 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. |
| FOCUS_MODE_CONTINUOUS_AUTO | 1 | Continuous auto focus. The focal point cannot be set.|
| 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. |
| FOCUS_MODE_LOCKED | 3 | Focus locked. The focal point cannot be set. |
## FocusState
Enumerates the focus states.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Value | Description |
| --------------------- | ---- | --------- |
| FOCUS_STATE_SCAN | 0 | Focusing. |
| FOCUS_STATE_FOCUSED | 1 | Focused. |
| FOCUS_STATE_UNFOCUSED | 2 | Unfocused.|
## VideoStabilizationMode
Enumerates the video stabilization modes.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Value | Description |
| --------- | ---- | ------------ |
| OFF | 0 | Video stabilization is disabled. |
| LOW | 1 | The basic video stabilization algorithm is used. |
| MIDDLE | 2 | A video stabilization algorithm with a stabilization effect better than that of the **LOW** type is used. |
| HIGH | 3 | A video stabilization algorithm with a stabilization effect better than that of the **MIDDLE** type is used. |
| AUTO | 4 | The system automatically selects a video stabilization algorithm. |
## Session11+
Implements 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.
### beginConfig11+
beginConfig(): void
Starts configuration for the session.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400105 | Session config locked. |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function beginConfig(session: camera.Session): void {
try {
session.beginConfig();
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The beginConfig call failed. error code: ${err.code}`);
}
}
```
### commitConfig11+
commitConfig(callback: AsyncCallback\): void
Commits the configuration for this session. This API uses an asynchronous callback to return the result.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | -------------------- |
| callback | AsyncCallback\ | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned. For example, if the aspect ratio of the preview stream is different from that of the video output stream, error code 7400201 is returned.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400102 | Operation not allowed. |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function commitConfig(session: camera.Session): void {
session.commitConfig((err: BusinessError) => {
if (err) {
console.error(`The commitConfig call failed. error code: ${err.code}`);
return;
}
console.info('Callback invoked to indicate the commit config success.');
});
}
```
### commitConfig11+
commitConfig(): Promise\
Commits the configuration for this session. This API uses a promise to return the result.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| -------------- | ------------------------ |
| Promise\ | Promise that returns no value.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400102 | Operation not allowed. |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function commitConfig(session: camera.Session): void {
session.commitConfig().then(() => {
console.info('Promise returned to indicate the commit config success.');
}).catch((error: BusinessError) => {
// If the operation fails, error.code is returned and processed.
console.error(`The commitConfig call failed. error code: ${error.code}`);
});
}
```
### canAddInput11+
canAddInput(cameraInput: CameraInput): boolean
Checks whether a CameraInput instance can be added to this session. This API must be called after [beginConfig](#beginconfig11) and before [commitConfig](#commitconfig11-1).
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | --------------------------- | ---- | ------------------------ |
| cameraInput | [CameraInput](#camerainput) | Yes | CameraInput instance to add. The API does not take effect if the input parameter is invalid (for example, the value is out of range, null, or undefined).|
**Return value**
| Type | Description |
| -------------- | ------------------------ |
| boolean | Check result for adding the CameraInput instance. **true** if it can be added, **false** otherwise.|
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function canAddInput(session: camera.Session, cameraInput: camera.CameraInput): void {
let canAdd: boolean = session.canAddInput(cameraInput);
console.info(`The input canAddInput: ${canAdd}`);
}
```
### addInput11+
addInput(cameraInput: CameraInput): void
Adds a [CameraInput](#camerainput) instance to this session.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | --------------------------- | ---- | ------------------------ |
| cameraInput | [CameraInput](#camerainput) | Yes | CameraInput instance to add.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400101 | Parameter missing or parameter type incorrect. |
| 7400102 | Operation not allowed. |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function addInput(session: camera.Session, cameraInput: camera.CameraInput): void {
try {
session.addInput(cameraInput);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The addInput call failed. error code: ${err.code}`);
}
}
```
### removeInput11+
removeInput(cameraInput: CameraInput): void
Removes a [CameraInput](#camerainput) instance from this session. This API must be called after [beginConfig](#beginconfig11) and before [commitConfig](#commitconfig11-1).
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | --------------------------- | ---- | ------------------------ |
| cameraInput | [CameraInput](#camerainput) | Yes | CameraInput instance to remove.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400101 | Parameter missing or parameter type incorrect. |
| 7400102 | Operation not allowed. |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function removeInput(session: camera.Session, cameraInput: camera.CameraInput): void {
try {
session.removeInput(cameraInput);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The removeInput call failed. error code: ${err.code}`);
}
}
```
### canAddOutput11+
canAddOutput(cameraOutput: CameraOutput): boolean
Determines whether a CameraOutput instance can be added to this session. This API must be called after [addInput](#addinput11) and before [commitConfig](#commitconfig11-1).
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | --------------------------- | ---- | ------------------------ |
| cameraOutput | [CameraOutput](#cameraoutput) | Yes | CameraOutput instance to add. The API does not take effect if the input parameter is invalid (for example, the value is out of range, null, or undefined).|
**Return value**
| Type | Description |
| -------------- | ------------------------ |
| boolean | Check result for adding the CameraOutput instance. **true** if it can be added, **false** otherwise.|
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function canAddOutput(session: camera.Session, cameraOutput: camera.CameraOutput): void {
let canAdd: boolean = session.canAddOutput(cameraOutput);
console.info(`This addOutput can add: ${canAdd}`);
}
```
### addOutput11+
addOutput(cameraOutput: CameraOutput): void
Adds a [CameraOutput](#cameraoutput) instance to this session.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ------------- | ------------------------------- | ---- | ------------------------ |
| cameraOutput | [CameraOutput](#cameraoutput) | Yes | CameraOutput instance to add.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400101 | Parameter missing or parameter type incorrect. |
| 7400102 | Operation not allowed. |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function addOutput(session: camera.Session, cameraOutput: camera.CameraOutput): void {
try {
session.addOutput(cameraOutput);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The addOutput call failed. error code: ${err.code}`);
}
}
```
### removeOutput11+
removeOutput(cameraOutput: CameraOutput): void
Removes a [CameraOutput](#cameraoutput) instance from this session.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ------------- | ------------------------------- | ---- | ------------------------ |
| cameraOutput | [CameraOutput](#cameraoutput) | Yes | CameraOutput instance to remove.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400101 | Parameter missing or parameter type incorrect. |
| 7400102 | Operation not allowed. |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function removeOutput(session: camera.Session, previewOutput: camera.PreviewOutput): void {
try {
session.removeOutput(previewOutput);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The removeOutput call failed. error code: ${err.code}`);
}
}
```
### start11+
start(callback: AsyncCallback\): void
Starts this session. This API uses an asynchronous callback to return the result.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | -------------------- |
| callback | AsyncCallback\ | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400102 | Operation not allowed. |
| 7400103 | Session not config. |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function startCaptureSession(session: camera.Session): void {
session.start((err: BusinessError) => {
if (err) {
console.error(`Failed to start the session, error code: ${err.code}.`);
return;
}
console.info('Callback invoked to indicate the session start success.');
});
}
```
### start11+
start(): Promise\
Starts this session. This API uses a promise to return the result.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| -------------- | ------------------------ |
| Promise\ | Promise that returns no value.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400102 | Operation not allowed. |
| 7400103 | Session not config. |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function startCaptureSession(session: camera.Session): void {
session.start().then(() => {
console.info('Promise returned to indicate the session start success.');
}).catch((error: BusinessError) => {
console.error(`Failed to start the session, error code: ${error.code}.`);
});
}
```
### stop11+
stop(callback: AsyncCallback\): void
Stops this session. This API uses an asynchronous callback to return the result.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------- |
| callback | AsyncCallback\ | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function stopCaptureSession(session: camera.Session): void {
session.stop((err: BusinessError) => {
if (err) {
console.error(`Failed to stop the session, error code: ${err.code}.`);
return;
}
console.info('Callback invoked to indicate the session stop success.');
});
}
```
### stop11+
stop(): Promise\
Stops this session. This API uses a promise to return the result.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| -------------- |-------------------|
| Promise\ | Promise that returns no value. |
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function stopCaptureSession(session: camera.Session): void {
session.stop().then(() => {
console.info('Promise returned to indicate the session stop success.');
}).catch((error: BusinessError) => {
console.error(`Failed to stop the session, error code: ${error.code}.`);
});
}
```
### release11+
release(callback: AsyncCallback\): void
Releases this session. This API uses an asynchronous callback to return the result.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | -------------------- |
| callback | AsyncCallback\ | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function releaseCaptureSession(session: camera.Session): void {
session.release((err: BusinessError) => {
if (err) {
console.error(`Failed to release the session instance, error code: ${err.code}.`);
return;
}
console.info('Callback invoked to indicate that the session instance is released successfully.');
});
}
```
### release11+
release(): Promise\
Releases this session. This API uses a promise to return the result.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| -------------- | ------------------------ |
| Promise\ | Promise that returns no value.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function releaseCaptureSession(session: camera.Session): void {
session.release().then(() => {
console.info('Promise returned to indicate that the session instance is released successfully.');
}).catch((error: BusinessError) => {
console.error(`Failed to release the session instance, error code: ${error.code}.`);
});
}
```
## Flash11+
Flash extends [FlashQuery](#flashquery12).
It provides APIs related to the flash.
### setFlashMode11+
setFlashMode(flashMode: FlashMode): void
Sets a flash mode.
Before the setting, do the following checks:
1. Use [hasFlash](#hasflash11) to check whether the camera device has flash.
2. Use [isFlashModeSupported](#isflashmodesupported11) to check whether the camera device supports the flash mode.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ----------------------- | ---- | --------------------- |
| flashMode | [FlashMode](#flashmode) | Yes | Flash mode. If the input parameter is null or undefined, it is treated as 0 and the flash is turned off. |
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400103 | Session not config. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function setFlashMode(photoSession: camera.PhotoSession): void {
try {
photoSession.setFlashMode(camera.FlashMode.FLASH_MODE_AUTO);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The setFlashMode call failed. error code: ${err.code}`);
}
}
```
### getFlashMode11+
getFlashMode(): FlashMode
Obtains the flash mode in use.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| ---------- | ----------------------------- |
| [FlashMode](#flashmode) | Flash mode obtained. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400103 | Session not config. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function getFlashMode(photoSession: camera.PhotoSession): camera.FlashMode | undefined {
let flashMode: camera.FlashMode | undefined = undefined;
try {
flashMode = photoSession.getFlashMode();
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The getFlashMode call failed.error code: ${err.code}`);
}
return flashMode;
}
```
## FlashQuery12+
Provides APIs to query the flash status and mode of a camera device.
### hasFlash11+
hasFlash(): boolean
Checks whether the camera device has flash. This API uses an asynchronous callback to return the result.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| ---------- | ----------------------------- |
| boolean | Check result for whether the camera device has flash. **true** if it has flash, **false** otherwise. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400103 | Session not config, only throw in session usage. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function hasFlash(photoSession: camera.PhotoSession): boolean {
let status: boolean = false;
try {
status = photoSession.hasFlash();
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The hasFlash call failed. error code: ${err.code}`);
}
return status;
}
```
### isFlashModeSupported11+
isFlashModeSupported(flashMode: FlashMode): boolean
Checks whether a flash mode is supported.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ----------------------- | ---- | --------------------------------- |
| flashMode | [FlashMode](#flashmode) | Yes | Flash mode. If the input parameter is null or undefined, it is treated as 0 and the flash is turned off. |
**Return value**
| Type | Description |
| ---------- | ----------------------------- |
| boolean | Check result for the support of the flash mode. **true** if supported, **false** otherwise. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400103 | Session not config, only throw in session usage. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function isFlashModeSupported(photoSession: camera.PhotoSession): boolean {
let status: boolean = false;
try {
status = photoSession.isFlashModeSupported(camera.FlashMode.FLASH_MODE_AUTO);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The isFlashModeSupported call failed. error code: ${err.code}`);
}
return status;
}
```
## AutoExposure11+
AutoExposure extends [AutoExposureQuery](#autoexposurequery12).
It provides APIs related to auto exposure.
### getExposureMode11+
getExposureMode(): ExposureMode
Obtains the exposure mode in use.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| ---------- | ----------------------------- |
| [ExposureMode](#exposuremode) | Exposure mode obtained. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400103 | Session not config. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function getExposureMode(photoSession: camera.PhotoSession): camera.ExposureMode | undefined {
let exposureMode: camera.ExposureMode | undefined = undefined;
try {
exposureMode = photoSession.getExposureMode();
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The getExposureMode call failed. error code: ${err.code}`);
}
return exposureMode;
}
```
### setExposureMode11+
setExposureMode(aeMode: ExposureMode): void
Sets an exposure mode. Before the setting, call [isExposureModeSupported](#isexposuremodesupported11) to check whether the target exposure mode is supported.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------------------| ---- | ----------------------- |
| aeMode | [ExposureMode](#exposuremode) | Yes | Exposure mode. If the input parameter is null or undefined, it is treated as 0 and exposure is locked. |
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400102 | Operation not allowed. |
| 7400103 | Session not config. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function setExposureMode(photoSession: camera.PhotoSession): void {
try {
photoSession.setExposureMode(camera.ExposureMode.EXPOSURE_MODE_LOCKED);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The setExposureMode call failed. error code: ${err.code}`);
}
}
```
### getMeteringPoint11+
getMeteringPoint(): Point
Obtains the metering point of the camera device.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| ---------- | ----------------------------- |
| [Point](#point) | Metering point obtained. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
|---------| --------------- |
| 7400103 | Session not config. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function getMeteringPoint(photoSession: camera.PhotoSession): camera.Point | undefined {
let exposurePoint: camera.Point | undefined = undefined;
try {
exposurePoint = photoSession.getMeteringPoint();
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The getMeteringPoint call failed. error code: ${err.code}`);
}
return exposurePoint;
}
```
### setMeteringPoint11+
setMeteringPoint(point: Point): void
Sets the metering point, which is the center point of the metering rectangle.
The 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}.
The 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}.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ------------- | -------------------------------| ---- | ------------------- |
| 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. |
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400103 | Session not config. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function setMeteringPoint(photoSession: camera.PhotoSession): void {
const point: camera.Point = {x: 1, y: 1};
try {
photoSession.setMeteringPoint(point);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The setMeteringPoint call failed. error code: ${err.code}`);
}
}
```
### setExposureBias11+
setExposureBias(exposureBias: number): void
Sets an exposure compensation value (EV).
Before the setting, you are advised to use [getExposureBiasRange](#getexposurebiasrange11) to obtain the supported values.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------------------| ---- |-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 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.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400102 | Operation not allowed. |
| 7400103 | Session not config. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function setExposureBias(photoSession: camera.PhotoSession, biasRangeArray: Array): void {
if (biasRangeArray && biasRangeArray.length > 0) {
let exposureBias = biasRangeArray[0];
try {
photoSession.setExposureBias(exposureBias);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The setExposureBias call failed. error code: ${err.code}`);
}
}
}
```
### getExposureValue11+
getExposureValue(): number
Obtains the exposure value in use.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| ---------- | ----------------------------- |
| 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.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400103 | Session not config. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function getExposureValue(photoSession: camera.PhotoSession): number {
const invalidValue: number = -1;
let exposureValue: number = invalidValue;
try {
exposureValue = photoSession.getExposureValue();
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The getExposureValue call failed. error code: ${err.code}`);
}
return exposureValue;
}
```
## AutoExposureQuery12+
Provides APIs to query the automatic exposure feature of a camera device.
### isExposureModeSupported11+
isExposureModeSupported(aeMode: ExposureMode): boolean
Checks whether an exposure mode is supported.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------------------------------| ---- | ----------------------------- |
| aeMode | [ExposureMode](#exposuremode) | Yes | Exposure mode. If the input parameter is null or undefined, it is treated as 0 and exposure is locked. |
**Return value**
| Type | Description |
| ---------- | ----------------------------- |
| boolean | Check result for the support of the exposure mode. **true** if supported, **false** otherwise. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400103 | Session not config, only throw in session usage. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function isExposureModeSupported(photoSession: camera.PhotoSession): boolean {
let isSupported: boolean = false;
try {
isSupported = photoSession.isExposureModeSupported(camera.ExposureMode.EXPOSURE_MODE_LOCKED);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The isExposureModeSupported call failed. error code: ${err.code}`);
}
return isSupported;
}
```
### getExposureBiasRange11+
getExposureBiasRange(): Array\
Obtains the exposure compensation values of the camera device.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| ---------- | ----------------------------- |
| Array\ | Array of compensation values. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400103 | Session not config, only throw in session usage. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function getExposureBiasRange(photoSession: camera.PhotoSession): Array {
let biasRangeArray: Array = [];
try {
biasRangeArray = photoSession.getExposureBiasRange();
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The getExposureBiasRange call failed. error code: ${err.code}`);
}
return biasRangeArray;
}
```
## Focus11+
Focus extends [FocusQuery](#focusquery12)
Provides APIs related to focus operations.
### setFocusMode11+
setFocusMode(afMode: FocusMode): void
Sets a focus mode.
Before the setting, call [isFocusModeSupported](#isfocusmodesupported11) to check whether the focus mode is supported.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | ------------------- |
| afMode | [FocusMode](#focusmode) | Yes | Focus mode. If the input parameter is null or undefined, it is treated as 0 and manual focus is used. |
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400103 | Session not config. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function setFocusMode(photoSession: camera.PhotoSession): void {
try {
photoSession.setFocusMode(camera.FocusMode.FOCUS_MODE_AUTO);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The setFocusMode call failed. error code: ${err.code}`);
}
}
```
### getFocusMode11+
getFocusMode(): FocusMode
Obtains the focus mode in use.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| ---------- | ----------------------------- |
| [FocusMode](#focusmode) | Focus mode obtained. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400103 | Session not config. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function getFocusMode(photoSession: camera.PhotoSession): camera.FocusMode | undefined {
let afMode: camera.FocusMode | undefined = undefined;
try {
afMode = photoSession.getFocusMode();
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The getFocusMode call failed. error code: ${err.code}`);
}
return afMode;
}
```
### setFocusPoint11+
setFocusPoint(point: Point): void
Sets 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}.
The 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}.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | ------------------- |
| 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. |
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400103 | Session not config. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function setFocusPoint(photoSession: camera.PhotoSession): void {
const focusPoint: camera.Point = {x: 1, y: 1};
try {
photoSession.setFocusPoint(focusPoint);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The setFocusPoint call failed. error code: ${err.code}`);
}
}
```
### getFocusPoint11+
getFocusPoint(): Point
Obtains the focal point in use.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| ---------- | ----------------------------- |
| [Point](#point) | Focal point obtained. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400103 | Session not config. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function getFocusPoint(photoSession: camera.PhotoSession): camera.Point | undefined {
let point: camera.Point | undefined = undefined;
try {
point = photoSession.getFocusPoint();
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The getFocusPoint call failed. error code: ${err.code}`);
}
return point;
}
```
### getFocalLength11+
getFocalLength(): number
Obtains the focal length in use.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| ---------- | ----------------------------- |
| number | Focal length, in mm. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400103 | Session not config. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function getFocalLength(photoSession: camera.PhotoSession): number {
const invalidValue: number = -1;
let focalLength: number = invalidValue;
try {
focalLength = photoSession.getFocalLength();
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The getFocalLength call failed. error code: ${err.code}`);
}
return focalLength;
}
```
## FocusQuery12+
Provides APIs to check whether a focus mode is supported.
### isFocusModeSupported11+
isFocusModeSupported(afMode: FocusMode): boolean
Checks whether a focus mode is supported.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | -------------------------------- |
| afMode | [FocusMode](#focusmode) | Yes | Focus mode. If the input parameter is null or undefined, it is treated as 0 and manual focus is used. |
**Return value**
| Type | Description |
| ---------- | ----------------------------- |
| boolean | Check result for the support of the focus mode. **true** if supported, **false** otherwise. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400103 | Session not config, only throw in session usage. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function isFocusModeSupported(photoSession: camera.PhotoSession): boolean {
let status: boolean = false;
try {
status = photoSession.isFocusModeSupported(camera.FocusMode.FOCUS_MODE_AUTO);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The isFocusModeSupported call failed. error code: ${err.code}`);
}
return status;
}
```
## MacroQuery19+
Provides the API to check the support for macro photography.
### isMacroSupported19+
isMacroSupported(): boolean
Checks whether macro photography is supported in the current state. This API must be called after [commitConfig](#commitconfig11-1).
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| ---------- | ----------------------------- |
| boolean | Check result for the support of macro photography. **true** if supported, **false** otherwise.|
**Example**
```ts
function isMacroSupported(photoSession: camera.PhotoSession): boolean {
let isSupported: boolean = photoSession.isMacroSupported();
return isSupported;
}
```
## Macro19+
Macro extends [MacroQuery](#macroquery19).
It provides the API to enable macro photography.
### enableMacro19+
enableMacro(enabled: boolean): void
Enables or disables macro photography. This API can be called only when macro photography is supported.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | -------------------- |
| enabled | boolean | Yes | Whether to enable macro photography. **true** to enable, **false** otherwise.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
|----------|--------------------------|
| 7400102 | Operation not allowed. |
| 7400103 | Session not config. |
**Example**
```ts
function enableMacro(photoSession: camera.PhotoSession): void {
let isSupported: boolean = photoSession.isMacroSupported();
if (isSupported) {
photoSession.enableMacro(true);
}
}
```
## SmoothZoomMode11+
Enumerates the smooth zoom modes.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Value | Description |
| ------------ | ---- | -------------- |
| NORMAL | 0 | Bessel curve mode. |
## SmoothZoomInfo11+
Describes the smooth zoom information.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Type | Read-only | Optional | Description |
| -------- | ---------- | -------- | -------- | ---------- |
| duration | number | No | No | Total duration of smooth zoom, in ms.|
## Zoom11+
Zoom extends [ZoomQuery](#zoomquery12).
It provides APIs related to zoom operations.
### setZoomRatio11+
setZoomRatio(zoomRatio: number): void
Sets a zoom ratio, with a maximum precision of two decimal places.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | -------------------- | ---- |---------------------------------------------------------------------------------------------------------------------------------|
| 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.
It takes some time for the zoom ratio to take effect at the bottom layer. To obtain the correct zoom ratio, you need to wait for one to two frames.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400103 | Session not config. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function setZoomRatio(photoSession: camera.PhotoSession, zoomRatioRange: Array): void {
if (zoomRatioRange === undefined || zoomRatioRange.length <= 0) {
return;
}
let zoomRatio = zoomRatioRange[0];
try {
photoSession.setZoomRatio(zoomRatio);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The setZoomRatio call failed. error code: ${err.code}`);
}
}
```
### getZoomRatio11+
getZoomRatio(): number
Obtains the zoom ratio in use.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| ---------- | ----------------------------- |
| number | Zoom ratio obtained. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400103 | Session not config. |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function getZoomRatio(photoSession: camera.PhotoSession): number {
const invalidValue: number = -1;
let zoomRatio: number = invalidValue;
try {
zoomRatio = photoSession.getZoomRatio();
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The getZoomRatio call failed. error code: ${err.code}`);
}
return zoomRatio;
}
```
### setSmoothZoom11+
setSmoothZoom(targetRatio: number, mode?: SmoothZoomMode): void
Sets smooth zoom.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ------------ | -------------- | ---- | ----------------- |
| targetRatio | number | Yes | Target zoom ratio. |
| mode | [SmoothZoomMode](#smoothzoommode11) | No | Smooth zoom mode. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function setSmoothZoom(sessionExtendsZoom: camera.Zoom, targetZoomRatio: number, mode: camera.SmoothZoomMode): void {
sessionExtendsZoom.setSmoothZoom(targetZoomRatio, mode);
}
```
## ZoomQuery12+
Provides APIs to query the zoom feature of a device camera, including the API to obtain the supported zoom ratio range.
### getZoomRatioRange11+
getZoomRatioRange(): Array\
Obtains the supported zoom ratio range.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| ---------- | ----------------------------- |
| Array\ | Array containing the minimum and maximum zoom ratios. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400103 | Session not config, only throw in session usage. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function getZoomRatioRange(photoSession: camera.PhotoSession): Array {
let zoomRatioRange: Array = [];
try {
zoomRatioRange = photoSession.getZoomRatioRange();
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The getZoomRatioRange call failed. error code: ${err.code}`);
}
return zoomRatioRange;
}
```
## Stabilization11+
Stabilization extends [StabilizationQuery](#stabilizationquery12).
It provides APIs to set video stabilization.
> **NOTE**
>
> You can set video stabilization only when a [VideoOutput](#videooutput) stream exists in the session.
> The enumerated value **HIGH** of [VideoStabilizationMode](#videostabilizationmode) takes effect only when the resolution of [Profile](#profile) is 1920 x 1080.
### getActiveVideoStabilizationMode11+
getActiveVideoStabilizationMode(): VideoStabilizationMode
Obtains the video stabilization mode in use.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| ---------- |-------------|
| [VideoStabilizationMode](#videostabilizationmode) | Video stabilization mode obtained.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400103 | Session not config. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function getActiveVideoStabilizationMode(videoSession: camera.VideoSession): camera.VideoStabilizationMode | undefined {
let vsMode: camera.VideoStabilizationMode | undefined = undefined;
try {
vsMode = videoSession.getActiveVideoStabilizationMode();
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The getActiveVideoStabilizationMode call failed. error code: ${err.code}`);
}
return vsMode;
}
```
### setVideoStabilizationMode11+
setVideoStabilizationMode(mode: VideoStabilizationMode): void
Sets a video stabilization mode. Before the setting, call [isVideoStabilizationModeSupported](#isvideostabilizationmodesupported11) to check whether the target video stabilization mode is supported.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------- | ---- | --------------------- |
| mode | [VideoStabilizationMode](#videostabilizationmode) | Yes | Video stabilization mode. |
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400103 | Session not config. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function setVideoStabilizationMode(videoSession: camera.VideoSession): void {
try {
videoSession.setVideoStabilizationMode(camera.VideoStabilizationMode.OFF);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The setVideoStabilizationMode call failed. error code: ${err.code}`);
}
}
```
## StabilizationQuery12+
Provides APIs to check the support for video stabilization.
### isVideoStabilizationModeSupported11+
isVideoStabilizationModeSupported(vsMode: VideoStabilizationMode): boolean
Checks whether a video stabilization mode is supported.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------- | ---- | ------------------------------ |
| vsMode | [VideoStabilizationMode](#videostabilizationmode) | Yes | Video stabilization mode. |
**Return value**
| Type | Description |
| ---------- | ----------------------------- |
| boolean | Check result for the support of the video stabilization mode. **true** if supported, **false** otherwise. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400103 | Session not config, only throw in session usage. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function isVideoStabilizationModeSupported(videoSession: camera.VideoSession): boolean {
let isSupported: boolean = false;
try {
isSupported = videoSession.isVideoStabilizationModeSupported(camera.VideoStabilizationMode.OFF);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The isVideoStabilizationModeSupported call failed. error code: ${err.code}`);
}
return isSupported;
}
```
## CaptureSession(deprecated)
Implements 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.
> **NOTE**
>
> 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.
### beginConfig(deprecated)
beginConfig(): void
Starts configuration for the session.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Session.beginConfig](#beginconfig11) instead.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400105 | Session config locked. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function beginConfig(captureSession: camera.CaptureSession): void {
try {
captureSession.beginConfig();
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The beginConfig call failed. error code: ${err.code}`);
}
}
```
### commitConfig(deprecated)
commitConfig(callback: AsyncCallback\): void
Commits the configuration for this session. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Session.commitConfig](#commitconfig11) instead.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | -------------------- |
| callback | AsyncCallback\ | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400102 | Operation not allowed. |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function commitConfig(captureSession: camera.CaptureSession): void {
captureSession.commitConfig((err: BusinessError) => {
if (err) {
console.error(`The commitConfig call failed. error code: ${err.code}`);
return;
}
console.info('Callback invoked to indicate the commit config success.');
});
}
```
### commitConfig(deprecated)
commitConfig(): Promise\
Commits the configuration for this session. This API uses a promise to return the result.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Session.commitConfig](#commitconfig11-1) instead.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| -------------- |-------------------|
| Promise\ | Promise that returns no value.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400102 | Operation not allowed. |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function commitConfig(captureSession: camera.CaptureSession): void {
captureSession.commitConfig().then(() => {
console.info('Promise returned to indicate the commit config success.');
}).catch((error: BusinessError) => {
// If the operation fails, error.code is returned and processed.
console.error(`The commitConfig call failed. error code: ${error.code}`);
});
}
```
### addInput(deprecated)
addInput(cameraInput: CameraInput): void
Adds a [CameraInput](#camerainput) instance to this session.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Session.addInput](#addinput11) instead.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | --------------------------- | ---- | ------------------------ |
| cameraInput | [CameraInput](#camerainput) | Yes | CameraInput instance to add.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
|---------|-----------------------------------------------|
| 7400101 | Parameter missing or parameter type incorrect. |
| 7400102 | Operation not allowed. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function addInput(captureSession: camera.CaptureSession, cameraInput: camera.CameraInput): void {
try {
captureSession.addInput(cameraInput);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The addInput call failed. error code: ${err.code}`);
}
}
```
### removeInput(deprecated)
removeInput(cameraInput: CameraInput): void
Removes a [CameraInput](#camerainput) instance from this session.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Session.removeInput](#removeinput11) instead.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | --------------------------- | ---- | ------------------------ |
| cameraInput | [CameraInput](#camerainput) | Yes | CameraInput instance to remove.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400101 | Parameter missing or parameter type incorrect. |
| 7400102 | Operation not allowed. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function removeInput(captureSession: camera.CaptureSession, cameraInput: camera.CameraInput): void {
try {
captureSession.removeInput(cameraInput);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The removeInput call failed. error code: ${err.code}`);
}
}
```
### addOutput(deprecated)
addOutput(cameraOutput: CameraOutput): void
Adds a [CameraOutput](#cameraoutput) instance to this session.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Session.addOutput](#addoutput11) instead.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ------------- | ------------------------------- | ---- | ------------------------ |
| cameraOutput | [CameraOutput](#cameraoutput) | Yes | CameraOutput instance to add.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400101 | Parameter missing or parameter type incorrect. |
| 7400102 | Operation not allowed. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function addOutput(captureSession: camera.CaptureSession, cameraOutput: camera.CameraOutput): void {
try {
captureSession.addOutput(cameraOutput);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The addOutput call failed. error code: ${err.code}`);
}
}
```
### removeOutput(deprecated)
removeOutput(cameraOutput: CameraOutput): void
Removes a [CameraOutput](#cameraoutput) instance from this session.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Session.removeOutput](#removeoutput11) instead.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ------------- | ------------------------------- | ---- | ------------------------ |
| cameraOutput | [CameraOutput](#cameraoutput) | Yes | CameraOutput instance to remove.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400101 | Parameter missing or parameter type incorrect. |
| 7400102 | Operation not allowed. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function removeOutput(captureSession: camera.CaptureSession, previewOutput: camera.PreviewOutput): void {
try {
captureSession.removeOutput(previewOutput);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The removeOutput call failed. error code: ${err.code}`);
}
}
```
### start(deprecated)
start(callback: AsyncCallback\): void
Starts this session. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Session.start](#start11) instead.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | -------------------- |
| callback | AsyncCallback\ | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400103 | Session not config. |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function startCaptureSession(captureSession: camera.CaptureSession): void {
captureSession.start((err: BusinessError) => {
if (err) {
console.error(`Failed to start the session, error code: ${err.code}.`);
return;
}
console.info('Callback invoked to indicate the session start success.');
});
}
```
### start(deprecated)
start(): Promise\
Starts this session. This API uses a promise to return the result.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Session.start](#start11-1) instead.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| -------------- | ------------------------ |
| Promise\ | Promise that returns no value.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400103 | Session not config. |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function startCaptureSession(captureSession: camera.CaptureSession): void {
captureSession.start().then(() => {
console.info('Promise returned to indicate the session start success.');
}).catch((err: BusinessError) => {
console.error(`Failed to start the session, error code: ${err.code}.`);
});
}
```
### stop(deprecated)
stop(callback: AsyncCallback\): void
Stops this session. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Session.stop](#stop11) instead.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------- |
| callback | AsyncCallback\ | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function stopCaptureSession(captureSession: camera.CaptureSession): void {
captureSession.stop((err: BusinessError) => {
if (err) {
console.error(`Failed to stop the session, error code: ${err.code}.`);
return;
}
console.info('Callback invoked to indicate the session stop success.');
});
}
```
### stop(deprecated)
stop(): Promise\
Stops this session. This API uses a promise to return the result.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Session.stop](#stop11-1) instead.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| -------------- | ----------------------- |
| Promise\ | Promise that returns no value.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function stopCaptureSession(captureSession: camera.CaptureSession): void {
captureSession.stop().then(() => {
console.info('Promise returned to indicate the session stop success.');
}).catch((err: BusinessError) => {
console.error(`Failed to stop the session, error code: ${err.code}.`);
});
}
```
### release(deprecated)
release(callback: AsyncCallback\): void
Releases this session. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Session.release](#release11-1) instead.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | -------------------- |
| callback | AsyncCallback\ | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function releaseCaptureSession(captureSession: camera.CaptureSession): void {
captureSession.release((err: BusinessError) => {
if (err) {
console.error(`Failed to release the CaptureSession instance, error code: ${err.code}.`);
return;
}
console.info('Callback invoked to indicate that the CaptureSession instance is released successfully.');
});
}
```
### release(deprecated)
release(): Promise\
Releases this session. This API uses a promise to return the result.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Session.release](#release11-2) instead.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| -------------- | ------------------------ |
| Promise\ | Promise that returns no value.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function releaseCaptureSession(captureSession: camera.CaptureSession): void {
captureSession.release().then(() => {
console.info('Promise returned to indicate that the CaptureSession instance is released successfully.');
}).catch((err: BusinessError) => {
console.error(`Failed to release the CaptureSession instance, error code: ${err.code}.`);
});
}
```
### hasFlash(deprecated)
hasFlash(): boolean
Checks whether the camera device has flash.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Flash.hasFlash](#hasflash11) instead.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| ---------- | ----------------------------- |
| boolean | Check result for whether the camera device has flash. **true** if it has flash, **false** otherwise. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400103 | Session not config. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function hasFlash(captureSession: camera.CaptureSession): boolean {
let status: boolean = false;
try {
status = captureSession.hasFlash();
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The hasFlash call failed. error code: ${err.code}`);
}
return status;
}
```
### isFlashModeSupported(deprecated)
isFlashModeSupported(flashMode: FlashMode): boolean
Checks whether a flash mode is supported.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Flash.isFlashModeSupported](#isflashmodesupported11) instead.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ----------------------- | ---- | --------------------------------- |
| flashMode | [FlashMode](#flashmode) | Yes | Flash mode. |
**Return value**
| Type | Description |
| ---------- | ----------------------------- |
| boolean | Check result for the support of the flash mode. **true** if supported, **false** otherwise. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400103 | Session not config. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function isFlashModeSupported(captureSession: camera.CaptureSession): boolean {
let status: boolean = false;
try {
status = captureSession.isFlashModeSupported(camera.FlashMode.FLASH_MODE_AUTO);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The isFlashModeSupported call failed. error code: ${err.code}`);
}
return status;
}
```
### setFlashMode(deprecated)
setFlashMode(flashMode: FlashMode): void
Sets a flash mode.
Before the setting, do the following checks:
1. Use [hasFlash](#hasflashdeprecated) to check whether the camera device has flash.
2. Use [isFlashModeSupported](#isflashmodesupporteddeprecated) to check whether the camera device supports the flash mode.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Flash.setFlashMode](#setflashmode11) instead.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ----------------------- | ---- | -------------------- |
| flashMode | [FlashMode](#flashmode) | Yes | Flash mode. |
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400103 | Session not config. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function setFlashMode(captureSession: camera.CaptureSession): void {
try {
captureSession.setFlashMode(camera.FlashMode.FLASH_MODE_AUTO);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The setFlashMode call failed. error code: ${err.code}`);
}
}
```
### getFlashMode(deprecated)
getFlashMode(): FlashMode
Obtains the flash mode in use.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Flash.getFlashMode](#getflashmode11) instead.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| ---------- | ----------------------------- |
| [FlashMode](#flashmode) | Flash mode obtained. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400103 | Session not config. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function getFlashMode(captureSession: camera.CaptureSession): camera.FlashMode | undefined {
let flashMode: camera.FlashMode | undefined = undefined;
try {
flashMode = captureSession.getFlashMode();
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The getFlashMode call failed.error code: ${err.code}`);
}
return flashMode;
}
```
### isExposureModeSupported(deprecated)
isExposureModeSupported(aeMode: ExposureMode): boolean
Checks whether an exposure mode is supported.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [AutoExposure.isExposureModeSupported](#isexposuremodesupported11) instead.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------------------------------| ---- | ----------------------------- |
| aeMode | [ExposureMode](#exposuremode) | Yes | Exposure mode. |
**Return value**
| Type | Description |
| ---------- | ----------------------------- |
| boolean | Check result for the support of the exposure mode. **true** if supported, **false** otherwise. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400103 | Session not config. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function isExposureModeSupported(captureSession: camera.CaptureSession): boolean {
let isSupported: boolean = false;
try {
isSupported = captureSession.isExposureModeSupported(camera.ExposureMode.EXPOSURE_MODE_LOCKED);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The isExposureModeSupported call failed. error code: ${err.code}`);
}
return isSupported;
}
```
### getExposureMode(deprecated)
getExposureMode(): ExposureMode
Obtains the exposure mode in use.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [AutoExposure.getExposureMode](#getexposuremode11) instead.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| ---------- | ----------------------------- |
| [ExposureMode](#exposuremode) | Exposure mode obtained. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400103 | Session not config. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function getExposureMode(captureSession: camera.CaptureSession): camera.ExposureMode | undefined {
let exposureMode: camera.ExposureMode | undefined = undefined;
try {
exposureMode = captureSession.getExposureMode();
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The getExposureMode call failed. error code: ${err.code}`);
}
return exposureMode;
}
```
### setExposureMode(deprecated)
setExposureMode(aeMode: ExposureMode): void
Sets an exposure mode. Before the setting, call [isExposureModeSupported](#isexposuremodesupporteddeprecated) to check whether the target exposure mode is supported.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [AutoExposure.setExposureMode](#setexposuremode11) instead.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------------------| ---- | ----------------------- |
| aeMode | [ExposureMode](#exposuremode) | Yes | Exposure mode. |
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400103 | Session not config. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function setExposureMode(captureSession: camera.CaptureSession): void {
try {
captureSession.setExposureMode(camera.ExposureMode.EXPOSURE_MODE_LOCKED);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The setExposureMode call failed. error code: ${err.code}`);
}
}
```
### getMeteringPoint(deprecated)
getMeteringPoint(): Point
Obtains the metering point of the camera device.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [AutoExposure.getMeteringPoint](#getmeteringpoint11) instead.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| ---------- | ----------------------------- |
| [Point](#point) | Metering point obtained. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400103 | Session not config. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function getMeteringPoint(captureSession: camera.CaptureSession): camera.Point | undefined {
let exposurePoint: camera.Point | undefined = undefined;
try {
exposurePoint = captureSession.getMeteringPoint();
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The getMeteringPoint call failed. error code: ${err.code}`);
}
return exposurePoint;
}
```
### setMeteringPoint(deprecated)
setMeteringPoint(point: Point): void
Sets the metering point, which is the center point of the metering rectangle.
The 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}.
The 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}.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [AutoExposure.setMeteringPoint](#setmeteringpoint11) instead.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ------------- | -------------------------------| ---- | ------------------- |
| 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. |
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400103 | Session not config. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function setMeteringPoint(captureSession: camera.CaptureSession): void {
const point: camera.Point = {x: 1, y: 1};
try {
captureSession.setMeteringPoint(point);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The setMeteringPoint call failed. error code: ${err.code}`);
}
}
```
### getExposureBiasRange(deprecated)
getExposureBiasRange(): Array\
Obtains the exposure compensation values of the camera device.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [AutoExposure.getExposureBiasRange](#getexposurebiasrange11) instead.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| ---------- | ----------------------------- |
| Array\ | Array of compensation values. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400103 | Session not config. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function getExposureBiasRange(captureSession: camera.CaptureSession): Array {
let biasRangeArray: Array = [];
try {
biasRangeArray = captureSession.getExposureBiasRange();
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The getExposureBiasRange call failed. error code: ${err.code}`);
}
return biasRangeArray;
}
```
### setExposureBias(deprecated)
setExposureBias(exposureBias: number): void
Sets an exposure compensation value (EV).
Before the setting, you are advised to use [getExposureBiasRange](#getexposurebiasrangedeprecated) to obtain the supported values.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [AutoExposure.setExposureBias](#setexposurebias11) instead.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------------------------------|-----|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 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. If the input parameter is null or undefined, the EV is set to 0.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400103 | Session not config. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function setExposureBias(captureSession: camera.CaptureSession, biasRangeArray: Array): void {
if (biasRangeArray && biasRangeArray.length > 0) {
let exposureBias = biasRangeArray[0];
try {
captureSession.setExposureBias(exposureBias);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The setExposureBias call failed. error code: ${err.code}`);
}
}
}
```
### getExposureValue(deprecated)
getExposureValue(): number
Obtains the exposure value in use.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [AutoExposure.getExposureValue](#getexposurevalue11) instead.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| ---------- | ----------------------------- |
| 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.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400103 | Session not config. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function getExposureValue(captureSession: camera.CaptureSession): number {
const invalidValue: number = -1;
let exposureValue: number = invalidValue;
try {
exposureValue = captureSession.getExposureValue();
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The getExposureValue call failed. error code: ${err.code}`);
}
return exposureValue;
}
```
### isFocusModeSupported(deprecated)
isFocusModeSupported(afMode: FocusMode): boolean
Checks whether a focus mode is supported.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Focus.isFocusModeSupported](#isfocusmodesupported11) instead.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | -------------------------------- |
| afMode | [FocusMode](#focusmode) | Yes | Focus mode. |
**Return value**
| Type | Description |
| ---------- | ----------------------------- |
| boolean | Check result for the support of the focus mode. **true** if supported, **false** otherwise. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400103 | Session not config. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function isFocusModeSupported(captureSession: camera.CaptureSession): boolean {
let status: boolean = false;
try {
status = captureSession.isFocusModeSupported(camera.FocusMode.FOCUS_MODE_AUTO);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The isFocusModeSupported call failed. error code: ${err.code}`);
}
return status;
}
```
### setFocusMode(deprecated)
setFocusMode(afMode: FocusMode): void
Sets a focus mode.
Before the setting, call [isFocusModeSupported](#isfocusmodesupporteddeprecated) to check whether the focus mode is supported.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Focus.setFocusMode](#setfocusmode11) instead.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | ------------------- |
| afMode | [FocusMode](#focusmode) | Yes | Focus mode. |
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400103 | Session not config. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function setFocusMode(captureSession: camera.CaptureSession): void {
try {
captureSession.setFocusMode(camera.FocusMode.FOCUS_MODE_AUTO);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The setFocusMode call failed. error code: ${err.code}`);
}
}
```
### getFocusMode(deprecated)
getFocusMode(): FocusMode
Obtains the focus mode in use.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Focus.getFocusMode](#getfocusmode11) instead.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| ---------- | ----------------------------- |
| [FocusMode](#focusmode) | Focus mode obtained. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400103 | Session not config. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function getFocusMode(captureSession: camera.CaptureSession): camera.FocusMode | undefined {
let afMode: camera.FocusMode | undefined = undefined;
try {
afMode = captureSession.getFocusMode();
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The getFocusMode call failed. error code: ${err.code}`);
}
return afMode;
}
```
### setFocusPoint(deprecated)
setFocusPoint(point: Point): void
Sets 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}.
The 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}.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Focus.setFocusPoint](#setfocuspoint11) instead.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory | Description |
|-------| ----------------------- |-----| ------------------- |
| 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. |
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400103 | Session not config. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function setFocusPoint(captureSession: camera.CaptureSession): void {
const focusPoint: camera.Point = {x: 1, y: 1};
try {
captureSession.setFocusPoint(focusPoint);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The setFocusPoint call failed. error code: ${err.code}`);
}
}
```
### getFocusPoint(deprecated)
getFocusPoint(): Point
Obtains the focal point of the camera device.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Focus.getFocusPoint](#getfocuspoint11) instead.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| ---------- | ----------------------------- |
| [Point](#point) | Focal point obtained. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400103 | Session not config. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function getFocusPoint(captureSession: camera.CaptureSession): camera.Point | undefined {
let point: camera.Point | undefined = undefined;
try {
point = captureSession.getFocusPoint();
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The getFocusPoint call failed. error code: ${err.code}`);
}
return point;
}
```
### getFocalLength(deprecated)
getFocalLength(): number
Obtains the focal length of the camera device.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Focus.getFocalLength](#getfocallength11) instead.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| ---------- | ----------------------------- |
| number | Focal length obtained. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400103 | Session not config. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function getFocalLength(captureSession: camera.CaptureSession): number {
const invalidValue: number = -1;
let focalLength: number = invalidValue;
try {
focalLength = captureSession.getFocalLength();
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The getFocalLength call failed. error code: ${err.code}`);
}
return focalLength;
}
```
### getZoomRatioRange(deprecated)
getZoomRatioRange(): Array\
Obtains the supported zoom ratio range.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Zoom.getZoomRatioRange](#getzoomratiorange11) instead.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| ---------- | ----------------------------- |
| Array\ | Array containing the minimum and maximum zoom ratios. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400103 | Session not config. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function getZoomRatioRange(captureSession: camera.CaptureSession): Array {
let zoomRatioRange: Array = [];
try {
zoomRatioRange = captureSession.getZoomRatioRange();
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The getZoomRatioRange call failed. error code: ${err.code}`);
}
return zoomRatioRange;
}
```
### setZoomRatio(deprecated)
setZoomRatio(zoomRatio: number): void
Sets a zoom ratio, with a maximum precision of two decimal places.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Zoom.setZoomRatio](#setzoomratio11) instead.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory | Description |
| --------- | -------------------- |-----| ------------------- |
| 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. If the input parameter is null or undefined, it is treated as 0 and the minimum zoom ratio is used.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400103 | Session not config. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function setZoomRatio(captureSession: camera.CaptureSession, zoomRatioRange: Array): void {
if (zoomRatioRange === undefined || zoomRatioRange.length <= 0) {
return;
}
let zoomRatio = zoomRatioRange[0];
try {
captureSession.setZoomRatio(zoomRatio);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The setZoomRatio call failed. error code: ${err.code}`);
}
}
```
### getZoomRatio(deprecated)
getZoomRatio(): number
Obtains the zoom ratio in use.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Zoom.getZoomRatio](#getzoomratio11) instead.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| ---------- | ----------------------------- |
| number | Zoom ratio obtained. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400103 | Session not config. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function getZoomRatio(captureSession: camera.CaptureSession): number {
const invalidValue: number = -1;
let zoomRatio: number = invalidValue;
try {
zoomRatio = captureSession.getZoomRatio();
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The getZoomRatio call failed. error code: ${err.code}`);
}
return zoomRatio;
}
```
### isVideoStabilizationModeSupported(deprecated)
isVideoStabilizationModeSupported(vsMode: VideoStabilizationMode): boolean
Checks whether a video stabilization mode is supported.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Stabilization.isVideoStabilizationModeSupported](#isvideostabilizationmodesupported11) instead.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------- | ---- | ------------------------------ |
| vsMode | [VideoStabilizationMode](#videostabilizationmode) | Yes | Video stabilization mode. If the input parameter is null or undefined, it is treated as 0 and video stabilization is disabled. |
**Return value**
| Type | Description |
| ---------- | ----------------------------- |
| boolean | Check result for the support of the video stabilization mode. **true** if supported, **false** otherwise. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400103 | Session not config. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function isVideoStabilizationModeSupported(captureSession: camera.CaptureSession): boolean {
let isSupported: boolean = false;
try {
isSupported = captureSession.isVideoStabilizationModeSupported(camera.VideoStabilizationMode.OFF);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The isVideoStabilizationModeSupported call failed. error code: ${err.code}`);
}
return isSupported;
}
```
### getActiveVideoStabilizationMode(deprecated)
getActiveVideoStabilizationMode(): VideoStabilizationMode
Obtains the video stabilization mode in use.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Stabilization.getActiveVideoStabilizationMode](#getactivevideostabilizationmode11) instead.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| ---------- | ----------------------------- |
| [VideoStabilizationMode](#videostabilizationmode) | Video stabilization mode obtained. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400103 | Session not config. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function getActiveVideoStabilizationMode(captureSession: camera.CaptureSession): camera.VideoStabilizationMode | undefined {
let vsMode: camera.VideoStabilizationMode | undefined = undefined;
try {
vsMode = captureSession.getActiveVideoStabilizationMode();
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The getActiveVideoStabilizationMode call failed. error code: ${err.code}`);
}
return vsMode;
}
```
### setVideoStabilizationMode(deprecated)
setVideoStabilizationMode(mode: VideoStabilizationMode): void
Sets a video stabilization mode. Before the setting, call [isVideoStabilizationModeSupported](#isvideostabilizationmodesupporteddeprecated) to check whether the target video stabilization mode is supported.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Stabilization.setVideoStabilizationMode](#setvideostabilizationmode11) instead.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------- | ---- | --------------------- |
| mode | [VideoStabilizationMode](#videostabilizationmode) | Yes | Video stabilization mode. If the input parameter is null or undefined, it is treated as 0 and video stabilization is disabled. |
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400103 | Session not config. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function setVideoStabilizationMode(captureSession: camera.CaptureSession): void {
try {
captureSession.setVideoStabilizationMode(camera.VideoStabilizationMode.OFF);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The setVideoStabilizationMode call failed. error code: ${err.code}`);
}
}
```
### on('focusStateChange')(deprecated)
on(type: 'focusStateChange', callback: AsyncCallback\): void
Subscribes to focus state change events. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> 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.
>
> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------------------------- | ---- | ------------------------ |
| 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.|
| callback | AsyncCallback\<[FocusState](#focusstate)\> | Yes | Callback used to return the focus state change. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function registerFocusStateChange(captureSession: camera.CaptureSession): void {
captureSession.on('focusStateChange', (err: BusinessError, focusState: camera.FocusState) => {
if (err !== undefined && err.code !== 0) {
console.error(`Callback Error, errorCode: ${err.code}`);
return;
}
console.info(`Focus state: ${focusState}`);
});
}
```
### off('focusStateChange')(deprecated)
off(type: 'focusStateChange', callback?: AsyncCallback\): void
Unsubscribes from focus state change events.
> **NOTE**
>
> 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.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------------------------- | ---- | ------------------------ |
| type | string | Yes | Event type. The value is fixed at **'focusStateChange'**. The event can be listened for when a session is created.|
| 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.|
**Example**
```ts
function unregisterFocusStateChange(captureSession: camera.CaptureSession): void {
captureSession.off('focusStateChange');
}
```
### on('error')(deprecated)
on(type: 'error', callback: ErrorCallback): void
Subscribes to CaptureSession error events. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**.
> **NOTE**
>
> 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.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- |--------------------------------------------------------------------------| ---- | ------------------------------ |
| 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).|
| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | Yes | Callback used to return an error code defined in [CameraErrorCode](#cameraerrorcode). |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function registerCaptureSessionError(captureSession: camera.CaptureSession): void {
captureSession.on('error', (error: BusinessError) => {
console.error(`Capture session error code: ${error.code}`);
});
}
```
### off('error')(deprecated)
off(type: 'error', callback?: ErrorCallback): void
Unsubscribes from CaptureSession error events. This API uses a callback to return the result.
> **NOTE**
>
> 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.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------------------------------------------- | ---- | ------------------------------ |
| type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a session is created.|
| 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.|
**Example**
```ts
function unregisterCaptureSessionError(captureSession: camera.CaptureSession): void {
captureSession.off('error');
}
```
## ColorManagementQuery12+
Provides the APIs for color space query.
### getSupportedColorSpaces12+
getSupportedColorSpaces(): Array\
Obtains the supported color spaces.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| ----------------------------------------------- | ---------------------------- |
| Array<[colorSpaceManager.ColorSpace](../apis-arkgraphics2d/js-apis-colorSpaceManager.md#colorspace)>| Array of color spaces supported. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
import { colorSpaceManager } from '@kit.ArkGraphics2D';
function getSupportedColorSpaces(session: camera.PhotoSession): Array {
let colorSpaces: Array = [];
colorSpaces = session.getSupportedColorSpaces();
return colorSpaces;
}
```
## ColorManagement12+
ColorManagement extends [ColorManagementQuery](#colormanagementquery12).
It implements color space management. It inherits from [ColorManagementQuery](#colormanagementquery12).
### setColorSpace12+
setColorSpace(colorSpace: colorSpaceManager.ColorSpace): void
Sets a color space. Before the setting, call [getSupportedColorSpaces](#getsupportedcolorspaces12) to obtain the supported color spaces.
**P3 and HDR Imaging**
An application can deliver different color space parameters to declare its support for P3 and HDR.
If an application does not proactively set the color space, SDR is used by default in photo capture scenarios.
In photo mode, P3 can be directly supported by setting the HDR effect.
For details about how to enable the HDR effect and set the color space in different modes, see the following table.
**Recording Mode**
| SDR/HRD Photo Capture | CameraFormat | ColorSpace |
|--------------------|--------------------------|------------------|
| SDR | CAMERA_FORMAT_YUV_420_SP | BT709_LIMIT |
| HDR_VIVID | CAMERA_FORMAT_YCRCB_P010 | BT2020_HLG_LIMIT |
**Photo Mode**
| SDR/HRD Photo Capture | ColorSpace |
|--------------------|------------|
| SDR(Default) | SRGB |
| HDR | DISPLAY_P3 |
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ------------ |---------------------- | -- | -------------------------- |
| colorSpace | [colorSpaceManager.ColorSpace](../apis-arkgraphics2d/js-apis-colorSpaceManager.md#colorspace) | Yes| Color space, which is obtained by calling [getSupportedColorSpaces](#getsupportedcolorspaces12). |
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400101 | Parameter missing or parameter type incorrect. |
| 7400102 | The colorSpace does not match the format. |
| 7400103 | Session not config. |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
import { colorSpaceManager } from '@kit.ArkGraphics2D';
function setColorSpace(session: camera.PhotoSession, colorSpaces: Array): void {
if (colorSpaces === undefined || colorSpaces.length <= 0) {
return;
}
try {
session.setColorSpace(colorSpaces[0]);
} catch (error) {
let err = error as BusinessError;
console.error(`The setColorSpace call failed, error code: ${err.code}`);
}
}
```
### getActiveColorSpace12+
getActiveColorSpace(): colorSpaceManager.ColorSpace
Obtains the color space in use.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| ----------------------------------------------- | ---------------------------- |
| [colorSpaceManager.ColorSpace](../apis-arkgraphics2d/js-apis-colorSpaceManager.md#colorspace) | Color space. |
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400103 | Session not config. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
import { colorSpaceManager } from '@kit.ArkGraphics2D';
function getActiveColorSpace(session: camera.PhotoSession): colorSpaceManager.ColorSpace | undefined {
let colorSpace: colorSpaceManager.ColorSpace | undefined = undefined;
try {
colorSpace = session.getActiveColorSpace();
} catch (error) {
let err = error as BusinessError;
console.error(`The getActiveColorSpace call failed. error code: ${err.code}`);
}
return colorSpace;
}
```
## AutoDeviceSwitchQuery13+
A class for checking whether a device supports automatic camera switch.
### isAutoDeviceSwitchSupported13+
isAutoDeviceSwitchSupported(): boolean
Checks whether the device supports automatic camera switch.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| ----------------------------------------------- |-------------|
| boolean | Check result for the support of automatic camera switch. **true** if supported, **false** otherwise.|
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function isAutoDeviceSwitchSupported(session: camera.PhotoSession): boolean {
let isSupported = false;
isSupported = session.isAutoDeviceSwitchSupported();
return isSupported;
}
```
## AutoDeviceSwitch13+
AutoDeviceSwitch extends [AutoDeviceSwitchQuery](#autodeviceswitchquery13).
It is a class used to enable or disable automatic camera switch. This class inherits from [AutoDeviceSwitchQuery](#autodeviceswitchquery13).
It is recommended that the system completes input device switch, session configuration, and parameter connection during automatic camera switch. If the system detects that the zoom ranges of the two cameras are different, it notifies the application through the **isDeviceCapabilityChanged** field in [AutoDeviceSwitchStatus](#autodeviceswitchstatus13). The application needs to process the UX change by itself. For example, if the zoom range is different, the application needs to call [getZoomRatioRange](#getzoomratiorange11) to obtain data and update the UX. Therefore, this class is more applicable to a simplified UX exchange scenario.
### enableAutoDeviceSwitch13+
enableAutoDeviceSwitch(enabled: boolean): void
Enables or disables automatic camera switch. You can use [isAutoDeviceSwitchSupported](#isautodeviceswitchsupported13) to check whether the device supports automatic camera switch.
> **NOTE**
>
> This API is used only for foldable devices with multiple front cameras. In different fold states, the system can automatically switch to an available front camera. It does not enable automatic switching between front and rear cameras.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- |---------------------- |---| -------------------------- |
| enabled | boolean | Yes| Whether to enable automatic camera switch. **true** to enable, **false** otherwise. |
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
|---------|------------------------------------------------------------------------------------------------------------------------------------------------|
| 7400101 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameters verification failed. |
| 7400102 | Operation not allowed. |
| 7400103 | Session not config. |
| 7400201 | Camera service fatal error. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function enableAutoDeviceSwitch(session: camera.PhotoSession, isEnable: boolean): void {
try {
session.enableAutoDeviceSwitch(isEnable);
} catch (error) {
let err = error as BusinessError;
console.error(`The enableAutoDeviceSwitch call failed, error code: ${err.code}`);
}
}
```
## PreconfigType12+
Enumerates the preconfigured resolution types.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Value| Description |
|-------------------------|---|------------|
| PRECONFIG_720P | 0 | 720p resolution. |
| PRECONFIG_1080P | 1 | 1080p resolution. |
| PRECONFIG_4K | 2 | 4K resolution. |
| PRECONFIG_HIGH_QUALITY | 3 | High-quality resolution. |
## PreconfigRatio12+
Enumerates the preconfigured aspect ratios.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Value| Description |
|--------------------------|---|---------|
| PRECONFIG_RATIO_1_1 | 0 | 1:1 aspect ratio. |
| PRECONFIG_RATIO_4_3 | 1 | 4:3 aspect ratio. |
| PRECONFIG_RATIO_16_9 | 2 | 16:9 aspect ratio.|
## PhotoSession11+
PhotoSession extends [Session](#session11), [Flash](#flash11), [AutoExposure](#autoexposure11), [Focus](#focus11), [Zoom](#zoom11), [ColorManagement](#colormanagement12), [AutoDeviceSwitch](#autodeviceswitch13), and [Macro](#macro19).
It implements a photo session, which provides operations on the flash, exposure, focus, zoom, color space, and macro mode.
> **NOTE**
>
> 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 photo capture scenarios.
### canPreconfig12+
canPreconfig(preconfigType: PreconfigType, preconfigRatio?: PreconfigRatio): boolean
Checks whether this session supports a preconfigured resolution.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory | Description |
|----------------|-------------------------------------|-----|-----------------|
| preconfigType | [PreconfigType](#preconfigtype12) | Yes | Resolution type. |
| preconfigRatio | [PreconfigRatio](#preconfigratio12) | No | Aspect ratio. The default value is 4:3. |
**Return value**
| Type | Description |
|---------|-----------------------------------------|
| boolean | **true**: The preconfigured resolution is supported.
**false**: The preconfigured resolution is not supported.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
|---------|-----------------------------|
| 7400201 | Camera service fatal error. |
**Example**
```ts
function testCanPreconfig(photoSession: camera.PhotoSession, preconfigType: camera.PreconfigType,
preconfigRatio: camera.PreconfigRatio): void {
try {
let result = photoSession.canPreconfig(preconfigType, preconfigRatio);
console.info(`canPreconfig ${preconfigType} ${preconfigRatio} result is : ${result}`);
} catch (error) {
let err = error as BusinessError;
console.error(`The canPreconfig call failed. error code: ${err.code}`);
}
}
```
### preconfig12+
preconfig(preconfigType: PreconfigType, preconfigRatio?: PreconfigRatio): void
Preconfigures this session.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory | Description |
|----------------|-------------------------------------|-----|-----------------|
| preconfigType | [PreconfigType](#preconfigtype12) | Yes | Resolution type. |
| preconfigRatio | [PreconfigRatio](#preconfigratio12) | No | Aspect ratio. The default value is 4:3. |
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
|---------|-----------------------------|
| 7400201 | Camera service fatal error. |
**Example**
```ts
function testPreconfig(photoSession: camera.PhotoSession, preconfigType: camera.PreconfigType,
preconfigRatio: camera.PreconfigRatio): void {
try {
photoSession.preconfig(preconfigType, preconfigRatio);
console.info(`preconfig ${preconfigType} ${preconfigRatio} success`);
} catch (error) {
let err = error as BusinessError;
console.error(`The preconfig call failed. error code: ${err.code}`);
}
}
```
### on('error')11+
on(type: 'error', callback: ErrorCallback): void
Subscribes to PhotoSession error events. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------------------------------------------- | ---- | ------------------------------ |
| 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).|
| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback)| Yes | Callback used to return an error code defined in [CameraErrorCode](#cameraerrorcode). |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function callback(err: BusinessError): void {
console.error(`Photo session error code: ${err.code}`);
}
function registerSessionError(photoSession: camera.PhotoSession): void {
photoSession.on('error', callback);
}
```
### off('error')11+
off(type: 'error', callback?: ErrorCallback): void
Unsubscribes from PhotoSession error events. This API uses a callback to return the result.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------------------- | ---- | ------------------------------ |
| type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a session is created.|
| 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.|
**Example**
```ts
function unregisterSessionError(photoSession: camera.PhotoSession): void {
photoSession.off('error');
}
```
### on('focusStateChange')11+
on(type: 'focusStateChange', callback: AsyncCallback\): void
Subscribes to focus state change events. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------- | ---- | ------------------------ |
| 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.|
| callback | AsyncCallback\<[FocusState](#focusstate)\> | Yes | Callback used to return the focus state change. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function callback(err: BusinessError, focusState: camera.FocusState): void {
if (err !== undefined && err.code !== 0) {
console.error(`Callback Error, errorCode: ${err.code}`);
return;
}
console.info(`Focus state: ${focusState}`);
}
function registerFocusStateChange(photoSession: camera.PhotoSession): void {
photoSession.on('focusStateChange', callback);
}
```
### off('focusStateChange')11+
off(type: 'focusStateChange', callback?: AsyncCallback\): void
Unsubscribes from focus state change events.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------------------------- | ---- | ------------------------ |
| type | string | Yes | Event type. The value is fixed at **'focusStateChange'**. The event can be listened for when a session is created.|
| 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.|
**Example**
```ts
function unregisterFocusStateChange(photoSession: camera.PhotoSession): void {
photoSession.off('focusStateChange');
}
```
### on('smoothZoomInfoAvailable')11+
on(type: 'smoothZoomInfoAvailable', callback: AsyncCallback\): void
Subscribes to smooth zoom state change events. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | ------------------------ |
| type | string | Yes | Event type. The value is fixed at **'smoothZoomInfoAvailable'**. The event can be listened for when a session is created.|
| callback | AsyncCallback\<[SmoothZoomInfo](#smoothzoominfo11)\> | Yes | Callback used to return the smooth zoom state change. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function callback(err: BusinessError, smoothZoomInfo: camera.SmoothZoomInfo): void {
if (err !== undefined && err.code !== 0) {
console.error(`Callback Error, errorCode: ${err.code}`);
return;
}
console.info(`The duration of smooth zoom: ${smoothZoomInfo.duration}`);
}
function registerSmoothZoomInfo(photoSession: camera.PhotoSession): void {
photoSession.on('smoothZoomInfoAvailable', callback);
}
```
### off('smoothZoomInfoAvailable')11+
off(type: 'smoothZoomInfoAvailable', callback?: AsyncCallback\): void
Unsubscribes from smooth zoom state change events.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------------------------- | ---- | ------------------------ |
| type | string | Yes | Event type. The value is fixed at **'smoothZoomInfoAvailable'**. The event can be listened for when a session is created.|
| 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.|
**Example**
```ts
function unregisterSmoothZoomInfo(photoSession: camera.PhotoSession): void {
photoSession.off('smoothZoomInfoAvailable');
}
```
### on('autoDeviceSwitchStatusChange')13+
on(type: 'autoDeviceSwitchStatusChange', callback: AsyncCallback\): void
Subscribes to automatic camera switch status change events. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- |----------------------------------------------------------------------| ---- |--------------------------------------------------------|
| type | string | Yes | Event type. The value is fixed at **'autoDeviceSwitchStatusChange'**. The event can be listened for when a session is created.|
| callback | AsyncCallback\<[AutoDeviceSwitchStatus](#autodeviceswitchstatus13)\> | Yes | Callback function, which is used to obtain the status of automatic camera switch. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function callback(err: BusinessError, autoDeviceSwitchStatus: camera.AutoDeviceSwitchStatus): void {
if (err !== undefined && err.code !== 0) {
console.error(`Callback Error, errorCode: ${err.code}`);
return;
}
console.info(`isDeviceSwitched: ${autoDeviceSwitchStatus.isDeviceSwitched}, isDeviceCapabilityChanged: ${autoDeviceSwitchStatus.isDeviceCapabilityChanged}`);
}
function registerAutoDeviceSwitchStatus(photoSession: camera.PhotoSession): void {
photoSession.on('autoDeviceSwitchStatusChange', callback);
}
```
### off('autoDeviceSwitchStatusChange')13+
off(type: 'autoDeviceSwitchStatusChange', callback?: AsyncCallback\): void
Unsubscribes from automatic camera switch status change events.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- |----------------------------------------------| ---- | ------------------------ |
| type | string | Yes | Event type. The value is fixed at **'autoDeviceSwitchStatusChange'**. The event can be listened for when a session is created.|
| callback | AsyncCallback\<[AutoDeviceSwitchStatus](#autodeviceswitchstatus13)\> | 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.|
**Example**
```ts
function unregisterSmoothZoomInfo(photoSession: camera.PhotoSession): void {
photoSession.off('autoDeviceSwitchStatusChange');
}
```
## QualityPrioritization14+
Enumerates the priority levels for video recording quality.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Value | Description |
| ------------- | --- | ---------- |
| HIGH_QUALITY | 0 | Prioritizes high-quality video recording. |
| POWER_BALANCE | 1 | Prioritizes video recording quality while balancing power consumption.|
## VideoSession11+
VideoSession extends [Session](#session11), [Flash](#flash11), [AutoExposure](#autoexposure11), [Focus](#focus11), [Zoom](#zoom11), [Stabilization](#stabilization11), [ColorManagement](#colormanagement12), [AutoDeviceSwitch](#autodeviceswitch13), and [Macro](#macro19).
It implements a video session, which provides operations on the flash, exposure, focus, zoom, video stabilization, color space, and macro mode.
> **NOTE**
>
> 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).
### canPreconfig12+
canPreconfig(preconfigType: PreconfigType, preconfigRatio?: PreconfigRatio): boolean
Checks whether this session supports a preconfigured resolution.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory | Description |
|----------------|-------------------------------------|-----|-----------------|
| preconfigType | [PreconfigType](#preconfigtype12) | Yes | Resolution type. |
| preconfigRatio | [PreconfigRatio](#preconfigratio12) | No | Aspect ratio. The default value is 16:9.|
**Return value**
| Type | Description |
|---------|-----------------------------------------|
| boolean | **true**: The preconfigured resolution is supported.
**false**: The preconfigured resolution is not supported.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
|---------|-----------------------------|
| 7400201 | Camera service fatal error. |
**Example**
```ts
function testCanPreconfig(videoSession: camera.VideoSession, preconfigType: camera.PreconfigType,
preconfigRatio: camera.PreconfigRatio): void {
try {
let result = videoSession.canPreconfig(preconfigType, preconfigRatio);
console.info(`canPreconfig ${preconfigType} ${preconfigRatio} result is : ${result}`);
} catch (error) {
let err = error as BusinessError;
console.error(`The canPreconfig call failed. error code: ${err.code}`);
}
}
```
### preconfig12+
preconfig(preconfigType: PreconfigType, preconfigRatio?: PreconfigRatio): void
Preconfigures this session.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory | Description |
|----------------|-------------------------------------|-----|-----------------|
| preconfigType | [PreconfigType](#preconfigtype12) | Yes | Resolution type. |
| preconfigRatio | [PreconfigRatio](#preconfigratio12) | No | Aspect ratio. The default value is 16:9.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
|---------|-----------------------------|
| 7400201 | Camera service fatal error. |
**Example**
```ts
function testPreconfig(videoSession: camera.VideoSession, preconfigType: camera.PreconfigType,
preconfigRatio: camera.PreconfigRatio): void {
try {
videoSession.preconfig(preconfigType, preconfigRatio);
console.info(`preconfig ${preconfigType} ${preconfigRatio} success`);
} catch (error) {
let err = error as BusinessError;
console.error(`The preconfig call failed. error code: ${err.code}`);
}
}
```
### on('error')11+
on(type: 'error', callback: ErrorCallback): void
Subscribes to VideoSession error events. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------ | ---- | ------------------------------ |
| 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).|
| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | Yes | Callback used to return an error code defined in [CameraErrorCode](#cameraerrorcode). |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function callback(err: BusinessError): void {
console.error(`Video session error code: ${err.code}`);
}
function registerSessionError(videoSession: camera.VideoSession): void {
videoSession.on('error', callback);
}
```
### off('error')11+
off(type: 'error', callback?: ErrorCallback): void
Unsubscribes from VideoSession error events. This API uses a callback to return the result.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------- | ---- | ------------------------------ |
| type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a session is created.|
| 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.|
**Example**
```ts
function unregisterSessionError(videoSession: camera.VideoSession): void {
videoSession.off('error');
}
```
### on('focusStateChange')11+
on(type: 'focusStateChange', callback: AsyncCallback\): void
Subscribes to focus state change events. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------- | ---- | ------------------------ |
| 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.|
| callback | AsyncCallback\<[FocusState](#focusstate)\> | Yes | Callback used to return the focus state change. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function callback(err: BusinessError, focusState: camera.FocusState): void {
if (err !== undefined && err.code !== 0) {
console.error(`Callback Error, errorCode: ${err.code}`);
return;
}
console.info(`Focus state: ${focusState}`);
}
function registerFocusStateChange(videoSession: camera.VideoSession): void {
videoSession.on('focusStateChange', callback);
}
```
### off('focusStateChange')11+
off(type: 'focusStateChange', callback?: AsyncCallback\): void
Unsubscribes from focus state change events.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------------------------- | ---- | ------------------------ |
| type | string | Yes | Event type. The value is fixed at **'focusStateChange'**. The event can be listened for when a session is created.|
| 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.|
**Example**
```ts
function unregisterFocusStateChange(videoSession: camera.VideoSession): void {
videoSession.off('focusStateChange');
}
```
### on('smoothZoomInfoAvailable')11+
on(type: 'smoothZoomInfoAvailable', callback: AsyncCallback\): void
Subscribes to smooth zoom state change events. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | ------------------------ |
| type | string | Yes | Event type. The value is fixed at **'smoothZoomInfoAvailable'**. The event can be listened for when a session is created.|
| callback | AsyncCallback\<[SmoothZoomInfo](#smoothzoominfo11)\> | Yes | Callback used to return the smooth zoom state change. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function callback(err: BusinessError, smoothZoomInfo: camera.SmoothZoomInfo): void {
if (err !== undefined && err.code !== 0) {
console.error(`Callback Error, errorCode: ${err.code}`);
return;
}
console.info(`The duration of smooth zoom: ${smoothZoomInfo.duration}`);
}
function registerSmoothZoomInfo(videoSession: camera.VideoSession): void {
videoSession.on('smoothZoomInfoAvailable', callback);
}
```
### off('smoothZoomInfoAvailable')11+
off(type: 'smoothZoomInfoAvailable', callback?: AsyncCallback\): void
Unsubscribes from smooth zoom state change events.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------------------------- | ---- | ------------------------ |
| type | string | Yes | Event type. The value is fixed at **'smoothZoomInfoAvailable'**. The event can be listened for when a session is created.|
| 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.|
**Example**
```ts
function unregisterSmoothZoomInfo(videoSession: camera.VideoSession): void {
videoSession.off('smoothZoomInfoAvailable');
}
```
### on('autoDeviceSwitchStatusChange')13+
on(type: 'autoDeviceSwitchStatusChange', callback: AsyncCallback\): void
Subscribes to automatic camera switch status change events. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- |----------------------------------------------------------------------| ---- | ------------------------ |
| type | string | Yes | Event type. The value is fixed at **'autoDeviceSwitchStatusChange'**. The event can be listened for when a session is created.|
| callback | AsyncCallback\<[AutoDeviceSwitchStatus](#autodeviceswitchstatus13)\> | Yes | Callback function, which is used to obtain the status of automatic camera switch. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function callback(err: BusinessError, autoDeviceSwitchStatus: camera.AutoDeviceSwitchStatus): void {
if (err !== undefined && err.code !== 0) {
console.error(`Callback Error, errorCode: ${err.code}`);
return;
}
console.info(`isDeviceSwitched: ${autoDeviceSwitchStatus.isDeviceSwitched}, isDeviceCapabilityChanged: ${autoDeviceSwitchStatus.isDeviceCapabilityChanged}`);
}
function registerAutoDeviceSwitchStatus(videoSession: camera.VideoSession): void {
videoSession.on('autoDeviceSwitchStatusChange', callback);
}
```
### off('autoDeviceSwitchStatusChange')13+
off(type: 'autoDeviceSwitchStatusChange', callback?: AsyncCallback\): void
Unsubscribes from automatic camera switch status change events.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- |----------------------------------------------| ---- | ------------------------ |
| type | string | Yes | Event type. The value is fixed at **'autoDeviceSwitchStatusChange'**. The event can be listened for when a session is created.|
| callback | AsyncCallback\<[AutoDeviceSwitchStatus](#autodeviceswitchstatus13)\> | 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.|
**Example**
```ts
function unregisterSmoothZoomInfo(videoSession: camera.VideoSession): void {
videoSession.off('autoDeviceSwitchStatusChange');
}
```
### setQualityPrioritization14+
setQualityPrioritization(quality : QualityPrioritization) : void;
Sets the priority level for video recording quality.
> **NOTE**
>
> The default value is **HIGH_QUALITY**. Switching to **POWER_BALANCE** will compromise video recording quality to achieve lower power usage. The extent of power conservation achieved varies depending on the platform.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ------- | ------------------------------------------------- | ---- | ------------------------------------------ |
| quality | [QualityPrioritization](#qualityprioritization14) | Yes | Priority level to set. The default value is **HIGH_QUALITY**.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID| Error Message |
| -------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
| 7400103 | Session not config. The session has not been committed or configured. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function setQualityPrioritization(videoSession: camera.VideoSession): void {
try {
videoSession.setQualityPrioritization(camera.QualityPrioritization.POWER_BALANCE);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The setQualityPrioritization call failed. error code: ${err.code}`);
}
}
```
## SecureSession12+
SecureSession extends [Session](#session11), [Flash](#flash11), [AutoExposure](#autoexposure11), [Focus](#focus11), and [Zoom](#zoom11).
It implements a secure session, which provides operations on the flash, exposure, focus, and zoom.
> **NOTE**
>
> 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.
>
> 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.
### addSecureOutput12+
addSecureOutput(previewOutput: PreviewOutput): void
Marks a [PreviewOutput](#previewoutput) stream as secure output.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ------------- | ------------------------------- | ---- |---------------|
| previewOutput | [PreviewOutput](#previewoutput) | Yes | Preview output stream. An error code is returned if the input parameter is invalid.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400101 | Parameter missing or parameter type incorrect. |
| 7400102 | Operation not allowed. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function addSecureOutput(session: camera.SecureSession, previewOutput: camera.PreviewOutput): void {
try {
session.addSecureOutput(previewOutput);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The addOutput call failed. error code: ${err.code}`);
}
}
```
### on('error')12+
on(type: 'error', callback: ErrorCallback): void
Subscribes to SecureSession error events. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------ | ---- | ------------------------------ |
| 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).|
| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | Yes | Callback used to return an error code defined in [CameraErrorCode](#cameraerrorcode). |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function callback(err: BusinessError): void {
console.error(`Video session error code: ${err.code}`);
}
function registerSessionError(secureSession: camera.SecureSession): void {
secureSession.on('error', callback);
}
```
### off('error')12+
off(type: 'error', callback?: ErrorCallback): void
Unsubscribes from SecureSession error events.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------- | ---- | ------------------------------ |
| type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a session is created.|
| 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.|
**Example**
```ts
function unregisterSessionError(secureSession: camera.SecureSession): void {
secureSession.off('error');
}
```
### on('focusStateChange')12+
on(type: 'focusStateChange', callback: AsyncCallback\): void
Subscribes to focus state change events. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------- | ---- | ------------------------ |
| 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.|
| callback | AsyncCallback\<[FocusState](#focusstate)\> | Yes | Callback used to return the focus state change. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function callback(err: BusinessError, focusState: camera.FocusState): void {
if (err !== undefined && err.code !== 0) {
console.error(`Callback Error, errorCode: ${err.code}`);
return;
}
console.info(`Focus state: ${focusState}`);
}
function registerFocusStateChange(secureSession: camera.SecureSession): void {
secureSession.on('focusStateChange', callback);
}
```
### off('focusStateChange')12+
off(type: 'focusStateChange', callback?: AsyncCallback\): void
Unsubscribes from focus state change events.
**Atomic service API**: This API can be used in atomic services since API version 19.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------------------------- | ---- | ------------------------ |
| type | string | Yes | Event type. The value is fixed at **'focusStateChange'**. The event can be listened for when a session is created.|
| 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.|
**Example**
```ts
function unregisterFocusStateChange(secureSession: camera.SecureSession): void {
secureSession.off('focusStateChange');
}
```
## WhiteBalanceMode20+
Enumerates the white balance modes.
**Atomic service API**: This API can be used in atomic services since API version 20.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Value| Description |
|----------------|---| ----------- |
| AUTO | 0 | Automatic.|
| CLOUDY | 1 | Cloudy.|
| INCANDESCENT | 2 | Incandescent light.|
| FLUORESCENT | 3 | Fluorescence light.|
| DAYLIGHT | 4 | Daylight.|
| MANUAL | 5 | Manual.|
## WhiteBalanceQuery20+
Provides APIs to check whether a white balance mode is supported and obtain the white balance mode range supported.
**Atomic service API**: This API can be used in atomic services since API version 20.
**System capability**: SystemCapability.Multimedia.Camera.Core
### isWhiteBalanceModeSupported20+
isWhiteBalanceModeSupported(mode: WhiteBalanceMode): boolean
Checks whether a white balance mode is supported.
**Atomic service API**: This API can be used in atomic services since API version 20.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- |-----------------------------------------| ---- | ----------------------------- |
| mode | [WhiteBalanceMode](#whitebalancemode20) | Yes | White balance mode. |
**Return value**
| Type | Description |
| ---------- | ----------------------------- |
| boolean | Check result for the support of the white balance mode. **true** if supported, **false** otherwise.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400101 | Parameter missing or parameter type incorrect. |
| 7400103 | Session not config, only throw in session usage. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function isWhiteBalanceModeSupported(session: camera.PhotoSession | camera.VideoSession): boolean {
let status: boolean = false;
try {
let mode: WhiteBalanceMode = camera.WhiteBalanceMode.DAYLIGHT;
status = session.isWhiteBalanceModeSupported(mode);
} catch (error) {
let err = error as BusinessError;
console.error(`The isWhiteBalanceModeSupported call failed. error code: ${err.code}`);
}
return status;
}
```
### getWhiteBalanceRange20+
getWhiteBalanceRange(): Array\
Obtains the range of white balance values in manual white balance mode.
**Atomic service API**: This API can be used in atomic services since API version 20.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| ---------- | ----------------------------- |
| Array\ | Range of white balance values, for example, [2800, ...,10000], in units of K (Kelvin). The actual value depends on the bottom-layer capability.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400103 | Session not config, only throw in session usage. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function getWhiteBalanceRange(session: camera.PhotoSession | camera.VideoSession): Array {
let range: Array = [];
try {
range = session.getWhiteBalanceRange();
} catch (error) {
let err = error as BusinessError;
console.error(`The getWhiteBalanceRange call failed. error code: ${err.code}`);
}
return range;
}
```
## WhiteBalance20+
WhiteBalance extends [WhiteBalanceQuery](#whitebalancequery20).
It provides APIs to process white balance, including obtaining and setting the white balance mode and white balance value.
**Atomic service API**: This API can be used in atomic services since API version 20.
**System capability**: SystemCapability.Multimedia.Camera.Core
### setWhiteBalanceMode20+
setWhiteBalanceMode(mode: WhiteBalanceMode): void
Sets a white balance mode. Before setting the white balance mode, run [isWhiteBalanceModeSupported](#iswhitebalancemodesupported20) to check whether the device supports the specified white balance mode.
**Atomic service API**: This API can be used in atomic services since API version 20.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- |-----------------------------------------| ---- | ----------------------- |
| mode | [WhiteBalanceMode](#whitebalancemode20) | Yes | White balance mode. |
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400101 | Parameter missing or parameter type incorrect. |
| 7400103 | Session not config. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function setWhiteBalanceMode(session: camera.PhotoSession | camera.VideoSession): void {
try {
session.setWhiteBalanceMode(camera.WhiteBalanceMode.DAYLIGHT);
} catch (error) {
let err = error as BusinessError;
console.error(`The setWhiteBalanceMode call failed. error code: ${err.code}`);
}
}
```
### getWhiteBalanceMode20+
getWhiteBalanceMode(): WhiteBalanceMode
Obtains the white balance mode in use.
**Atomic service API**: This API can be used in atomic services since API version 20.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
|-----------------------------------------| ----------------------------- |
| [WhiteBalanceMode](#whitebalancemode20) | White balance mode in use.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400103 | Session not config. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function getWhiteBalanceMode(session: camera.PhotoSession | camera.VideoSession): camera.WhiteBalanceMode | undefined {
let whiteBalanceMode: camera.WhiteBalanceMode | undefined = undefined;
try {
whiteBalanceMode = session.getWhiteBalanceMode();
} catch (error) {
let err = error as BusinessError;
console.error(`The getWhiteBalanceMode call failed. error code: ${err.code}`);
}
return whiteBalanceMode;
}
```
### setWhiteBalance20+
setWhiteBalance(whiteBalance: number): void
Sets a white balance value.
**Atomic service API**: This API can be used in atomic services since API version 20.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | ------------------- |
| whiteBalance | number | Yes | White balance value.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400101 | Parameter missing or parameter type incorrect. |
| 7400103 | Session not config. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function setWhiteBalance(session: camera.PhotoSession | camera.VideoSession): void {
try {
let whiteBalance: number = 1000;
session.setWhiteBalance(whiteBalance);
} catch (error) {
let err = error as BusinessError;
console.error(`The setWhiteBalance call failed. error code: ${err.code}`);
}
}
```
### getWhiteBalance20+
getWhiteBalance(): number
Obtains the current white balance value.
**Atomic service API**: This API can be used in atomic services since API version 20.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| ---------- | ----------------------------- |
| number | White balance value.|
**Error codes**
For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
| ID | Error Message |
| --------------- | --------------- |
| 7400103 | Session not config. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
function getWhiteBalance(session: camera.PhotoSession | camera.VideoSession): number {
let whiteBalance: number = 0;
try {
whiteBalance = session.getWhiteBalance();
} catch (error) {
let err = error as BusinessError;
console.error(`The getWhiteBalance call failed. error code: ${err.code}`);
}
return whiteBalance;
}
```