未验证 提交 acfc24a0 编写于 作者: O openharmony_ci 提交者: Gitee

!1599 Added focus, zoom and On apis

Merge pull request !1599 from nikhilraut/camera_api_update
...@@ -13,6 +13,12 @@ ohos.permission.CAMERA ...@@ -13,6 +13,12 @@ ohos.permission.CAMERA
``` ```
## getCameraManager(context: Context, callback: AsyncCallback<CameraManager\>): void; ## getCameraManager(context: Context, callback: AsyncCallback<CameraManager\>): void;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Gets a **CameraManager** instance. This method uses an asynchronous callback to return the result. Gets a **CameraManager** instance. This method uses an asynchronous callback to return the result.
**Parameters** **Parameters**
...@@ -41,6 +47,12 @@ camera.getCameraManager(context, (err, cameraManager) => { ...@@ -41,6 +47,12 @@ camera.getCameraManager(context, (err, cameraManager) => {
## getCameraManager(context: Context): Promise<CameraManager\>; ## getCameraManager(context: Context): Promise<CameraManager\>;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Gets a **CameraManager** instance. This method uses a promise to return the result. Gets a **CameraManager** instance. This method uses a promise to return the result.
**Parameters** **Parameters**
...@@ -69,10 +81,10 @@ Enumerates camera status types. ...@@ -69,10 +81,10 @@ Enumerates camera status types.
| Name | Default Value | Description | | Name | Default Value | Description |
|---------------------------|---------------|--------------------| |---------------------------|---------------|--------------------|
| CAMERA_STATUS_APPEAR | 0 | Camera appear | | CAMERA_STATUS_APPEAR | 0 | Camera appear<br/>System Capabilities: SystemCapability.Multimedia.Camera.Core |
| CAMERA_STATUS_DISAPPEAR | 1 | Camera disappear | | CAMERA_STATUS_DISAPPEAR | 1 | Camera disappear <br/>System Capabilities: SystemCapability.Multimedia.Camera.Core |
| CAMERA_STATUS_AVAILABLE | 2 | Camera available | | CAMERA_STATUS_AVAILABLE | 2 | Camera available<br/>System Capabilities: SystemCapability.Multimedia.Camera.Core |
| CAMERA_STATUS_UNAVAILABLE | 3 | Camera unavailable | | CAMERA_STATUS_UNAVAILABLE | 3 | Camera unavailable <br/>System Capabilities: SystemCapability.Multimedia.Camera.Core|
## CameraPosition<a name="section_camera_position"></a> ## CameraPosition<a name="section_camera_position"></a>
...@@ -81,9 +93,9 @@ Enumerates the camera positions. ...@@ -81,9 +93,9 @@ Enumerates the camera positions.
| Name | Default value | Description | | Name | Default value | Description |
|-----------------------------|---------------|-----------------------| |-----------------------------|---------------|-----------------------|
| CAMERA_POSITION_UNSPECIFIED | 0 | Unspecified position | | CAMERA_POSITION_UNSPECIFIED | 0 | Unspecified position <br/>System Capabilities: SystemCapability.Multimedia.Camera.Core |
| CAMERA_POSITION_BACK | 1 | Rear camera | | CAMERA_POSITION_BACK | 1 | Rear camera <br/>System Capabilities: SystemCapability.Multimedia.Camera.Core |
| CAMERA_POSITION_FRONT | 2 | Front camera | | CAMERA_POSITION_FRONT | 2 | Front camera <br/>System Capabilities: SystemCapability.Multimedia.Camera.Core |
## CameraType<a name="section_camera_type"></a> ## CameraType<a name="section_camera_type"></a>
...@@ -91,11 +103,11 @@ Enumerates the camera types. ...@@ -91,11 +103,11 @@ Enumerates the camera types.
| Name | Default value | Description | | Name | Default value | Description |
|-------------------------|---------------|-------------------------| |-------------------------|---------------|-------------------------|
| CAMERA_TYPE_UNSPECIFIED | 0 | Unspecified camera type | | CAMERA_TYPE_UNSPECIFIED | 0 | Unspecified camera type <br/>System Capabilities: SystemCapability.Multimedia.Camera.Core |
| CAMERA_TYPE_WIDE_ANGLE | 1 | Wide camera | | CAMERA_TYPE_WIDE_ANGLE | 1 | Wide camera <br/>System Capabilities: SystemCapability.Multimedia.Camera.Core |
| CAMERA_TYPE_ULTRA_WIDE | 2 | Ultra wide camera | | CAMERA_TYPE_ULTRA_WIDE | 2 | Ultra wide camera <br/>System Capabilities: SystemCapability.Multimedia.Camera.Core |
| CAMERA_TYPE_TELEPHOTO | 3 | Telephoto camera | | CAMERA_TYPE_TELEPHOTO | 3 | Telephoto camera <br/>System Capabilities: SystemCapability.Multimedia.Camera.Core |
| CAMERA_TYPE_TRUE_DEPTH | 4 | True depth camera | | CAMERA_TYPE_TRUE_DEPTH | 4 | True depth camera <br/>System Capabilities: SystemCapability.Multimedia.Camera.Core |
## ConnectionType<a name="section_ConnectionType"></a> ## ConnectionType<a name="section_ConnectionType"></a>
...@@ -104,9 +116,9 @@ Enumerates camera connection types. ...@@ -104,9 +116,9 @@ Enumerates camera connection types.
| Name | Default value | Description | | Name | Default value | Description |
|------------------------------|---------------|----------------------------| |------------------------------|---------------|----------------------------|
| CAMERA_CONNECTION_BUILT_IN | 0 | Built-in camera | | CAMERA_CONNECTION_BUILT_IN | 0 | Built-in camera <br/>System Capabilities: SystemCapability.Multimedia.Camera.Core |
| CAMERA_CONNECTION_USB_PLUGIN | 1 | Camera connected using USB | | CAMERA_CONNECTION_USB_PLUGIN | 1 | Camera connected using USB <br/>System Capabilities: SystemCapability.Multimedia.Camera.Core |
| CAMERA_CONNECTION_REMOTE | 2 | Remote camera | | CAMERA_CONNECTION_REMOTE | 2 | Remote camera <br/>System Capabilities: SystemCapability.Multimedia.Camera.Core |
## CameraFormat<a name="section_CameraFormat"></a> ## CameraFormat<a name="section_CameraFormat"></a>
...@@ -115,10 +127,10 @@ Enumerates the camera formats. ...@@ -115,10 +127,10 @@ Enumerates the camera formats.
| Name | Default value | Description | | Name | Default value | Description |
|----------------------------|---------------|---------------------| |----------------------------|---------------|---------------------|
| CAMERA_FORMAT_YCRCb_420_SP | 1003 | Camera YCRCb | | CAMERA_FORMAT_YCRCb_420_SP | 1003 | Camera YCRCb <br/>System Capabilities: SystemCapability.Multimedia.Camera.Core |
| CAMERA_FORMAT_JPEG | 2000 | Camera format jpeg | | CAMERA_FORMAT_JPEG | 2000 | Camera format jpeg <br/>System Capabilities: SystemCapability.Multimedia.Camera.Core |
| CAMERA_FORMAT_AVC | 3000 | Camera format avc | | CAMERA_FORMAT_AVC | 3000 | Camera format avc <br/>System Capabilities: SystemCapability.Multimedia.Camera.Core |
| CAMERA_FORMAT_HEVC | 3001 | Camera format hevc | | CAMERA_FORMAT_HEVC | 3001 | Camera format hevc <br/>System Capabilities: SystemCapability.Multimedia.Camera.Core |
## CameraManager<a name="section_CameraManager"></a> ## CameraManager<a name="section_CameraManager"></a>
...@@ -127,6 +139,12 @@ Implements camera management, including getting supported cameras and creating * ...@@ -127,6 +139,12 @@ Implements camera management, including getting supported cameras and creating *
### getCameras(callback: AsyncCallback<Array<Camera\>\>): void; ### getCameras(callback: AsyncCallback<Array<Camera\>\>): void;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Gets all cameras supported by the device. This method uses an asynchronous callback to return the array of supported cameras. Gets all cameras supported by the device. This method uses an asynchronous callback to return the array of supported cameras.
**Parameters** **Parameters**
...@@ -153,6 +171,12 @@ cameraManager.getCameras((err, cameras) => { ...@@ -153,6 +171,12 @@ cameraManager.getCameras((err, cameras) => {
### getCameras(): Promise<Array<Camera\>\>; ### getCameras(): Promise<Array<Camera\>\>;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Gets all cameras supported by the device. This method uses a promise to return the array of supported cameras. Gets all cameras supported by the device. This method uses a promise to return the array of supported cameras.
**Parameters** **Parameters**
...@@ -176,6 +200,12 @@ cameraManager.getCameras().then((cameraArray) => { ...@@ -176,6 +200,12 @@ cameraManager.getCameras().then((cameraArray) => {
### createCameraInput(cameraId: string, callback: AsyncCallback<CameraInput\>): void; ### createCameraInput(cameraId: string, callback: AsyncCallback<CameraInput\>): void;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Creates a **CameraInput** instance with the specified camera ID. This method uses an asynchronous callback to return the instance. Creates a **CameraInput** instance with the specified camera ID. This method uses an asynchronous callback to return the instance.
**Parameters** **Parameters**
...@@ -203,6 +233,12 @@ cameraManager.createCameraInput(cameraId, (err, cameraInput) => { ...@@ -203,6 +233,12 @@ cameraManager.createCameraInput(cameraId, (err, cameraInput) => {
### createCameraInput(cameraId: string): Promise<CameraInput\>; ### createCameraInput(cameraId: string): Promise<CameraInput\>;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Creates a **CameraInput** instance with the specified camera ID. This method uses a promise to return the instance. Creates a **CameraInput** instance with the specified camera ID. This method uses a promise to return the instance.
**Parameters** **Parameters**
...@@ -227,6 +263,12 @@ cameraManager.createCameraInput(cameraId).then((cameraInput) => { ...@@ -227,6 +263,12 @@ cameraManager.createCameraInput(cameraId).then((cameraInput) => {
### createCameraInput(position: CameraPosition, type: CameraType, callback: AsyncCallback<CameraInput\>): void; ### createCameraInput(position: CameraPosition, type: CameraType, callback: AsyncCallback<CameraInput\>): void;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Creates a **CameraInput** instance with the specified camera position and camera type. This method uses an asynchronous callback to return the instance. Creates a **CameraInput** instance with the specified camera position and camera type. This method uses an asynchronous callback to return the instance.
**Parameters** **Parameters**
...@@ -255,6 +297,12 @@ cameraManager.createCameraInput(cameraPosition, cameraType, (err, cameraInput) = ...@@ -255,6 +297,12 @@ cameraManager.createCameraInput(cameraPosition, cameraType, (err, cameraInput) =
### createCameraInput(position: CameraPosition, type: CameraType): Promise<CameraInput\>; ### createCameraInput(position: CameraPosition, type: CameraType): Promise<CameraInput\>;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Creates a **CameraInput** instance with the specified camera position and camera type. This method uses a promise to return the instance. Creates a **CameraInput** instance with the specified camera position and camera type. This method uses a promise to return the instance.
**Parameters** **Parameters**
...@@ -278,6 +326,36 @@ cameraManager.createCameraInput(cameraPosition, cameraType).then((cameraInput) = ...@@ -278,6 +326,36 @@ cameraManager.createCameraInput(cameraPosition, cameraType).then((cameraInput) =
}) })
``` ```
### on(type: 'cameraStatus', callback: Callback<CameraStatusInfo\>): void;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Listens for camera status changes. This method uses a callback to get camera status changes.
**Parameters**
| Name | Type | Mandatory | Description |
| :------- | :--------------------- | :-------- | :--------------------------------------------------- |
| type | string | Yes | Name of the event to listen for. |
| callback | Callback<CameraStatusInfo\> | Yes | Callback used to get the camera status change. |
**Return value**
None
**Example**
```
cameraManager.on('cameraStatus', (cameraStatusInfo) => {
console.log('camera : ' + cameraStatusInfo.camera.cameraId);
console.log('status: ' + cameraStatusInfo.status);
})
```
## Camera<a name="section_Camera"></a> ## Camera<a name="section_Camera"></a>
Camera class. Camera class.
...@@ -286,10 +364,10 @@ Camera class. ...@@ -286,10 +364,10 @@ Camera class.
| Name | Type | Access | Description | | Name | Type | Access | Description |
|----------------|----------------|----------|------------------------| |----------------|----------------|----------|------------------------|
| cameraId | string | readonly | Camera ID | | cameraId | string | readonly | Camera ID <br/>System Capabilities: SystemCapability.Multimedia.Camera.Core |
| cameraPosition | cameraPosition | readonly | Camera position | | cameraPosition | cameraPosition | readonly | Camera position <br/>System Capabilities: SystemCapability.Multimedia.Camera.Core |
| cameraType | cameraType | readonly | Camera type | | cameraType | cameraType | readonly | Camera type <br/>System Capabilities: SystemCapability.Multimedia.Camera.Core |
| connectionType | connectionType | readonly | Camera connection type | | connectionType | connectionType | readonly | Camera connection type <br/>System Capabilities: SystemCapability.Multimedia.Camera.Core|
``` ```
var cameraManager = await camera.getCameraManager(); var cameraManager = await camera.getCameraManager();
...@@ -302,12 +380,30 @@ var cameraId = cameraObj.connectionType; ...@@ -302,12 +380,30 @@ var cameraId = cameraObj.connectionType;
``` ```
## CameraStatusInfo<a name="section_Camera"></a>
CameraStatusInfo class.
**Fields**
| Name | Type | Description |
|----------------|----------------|------------------|
| camera | Camera | Camera object <br/>System Capabilities: SystemCapability.Multimedia.Camera.Core |
| status | CameraStatus | Camera status <br/>System Capabilities: SystemCapability.Multimedia.Camera.Core |
## CameraInput<a name="section_CameraInput"></a> ## CameraInput<a name="section_CameraInput"></a>
Implements a **CameraInput** instance. Implements a **CameraInput** instance.
### getCameraId(callback: AsyncCallback<string\>\): void; ### getCameraId(callback: AsyncCallback<string\>\): void;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Gets the camera ID based on which this **CameraInput** instance is created. This method uses an asynchronous callback to return the camera ID. Gets the camera ID based on which this **CameraInput** instance is created. This method uses an asynchronous callback to return the camera ID.
**Parameters** **Parameters**
...@@ -332,6 +428,12 @@ cameraInput.getCameraId((err, cameraId) => { ...@@ -332,6 +428,12 @@ cameraInput.getCameraId((err, cameraId) => {
### getCameraId(): Promise<string\>; ### getCameraId(): Promise<string\>;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Gets the camera ID based on which this **CameraInput** instance is created. This method uses a promise to return the camera ID. Gets the camera ID based on which this **CameraInput** instance is created. This method uses a promise to return the camera ID.
**Parameters** **Parameters**
...@@ -354,6 +456,12 @@ cameraInput.getCameraId().then((cameraId) => { ...@@ -354,6 +456,12 @@ cameraInput.getCameraId().then((cameraId) => {
### getSupportedSizes\(format: CameraFormat, callback: AsyncCallback<Array<Size\>\>\): void; ### getSupportedSizes\(format: CameraFormat, callback: AsyncCallback<Array<Size\>\>\): void;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Gets supported sizes for a given format. This method uses an asynchronous callback to return the supported sizes. Gets supported sizes for a given format. This method uses an asynchronous callback to return the supported sizes.
**Parameters** **Parameters**
...@@ -382,6 +490,12 @@ cameraInput.getSupportedSizes(format, (err, sizes) => { ...@@ -382,6 +490,12 @@ cameraInput.getSupportedSizes(format, (err, sizes) => {
### getSupportedSizes\(format: CameraFormat\): Promise<Array<Size\>\>; ### getSupportedSizes\(format: CameraFormat\): Promise<Array<Size\>\>;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Gets supported sizes for a given format. This method uses a promise to return the supported sizes. Gets supported sizes for a given format. This method uses a promise to return the supported sizes.
**Parameters** **Parameters**
...@@ -406,6 +520,12 @@ cameraInput.getSupportedSizes(format).then((sizes) => { ...@@ -406,6 +520,12 @@ cameraInput.getSupportedSizes(format).then((sizes) => {
### getSupportedPreviewFormats\(callback: AsyncCallback<Array<CameraFormat\>\>\): void; ### getSupportedPreviewFormats\(callback: AsyncCallback<Array<CameraFormat\>\>\): void;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Gets supported formats for preview. This method uses an asynchronous callback to return the supported formats. Gets supported formats for preview. This method uses an asynchronous callback to return the supported formats.
**Parameters** **Parameters**
...@@ -431,9 +551,14 @@ cameraInput.getSupportedPreviewFormats((err, previewFormats) => { ...@@ -431,9 +551,14 @@ cameraInput.getSupportedPreviewFormats((err, previewFormats) => {
}) })
``` ```
### getSupportedPreviewFormats\(\): Promise<Array<CameraFormat\>\>; ### getSupportedPreviewFormats\(\): Promise<Array<CameraFormat\>\>;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Gets supported formats for preview. This method uses a promise to return the supported formats. Gets supported formats for preview. This method uses a promise to return the supported formats.
**Parameters** **Parameters**
...@@ -456,6 +581,12 @@ cameraInput.getSupportedPreviewFormats().then((previewFormats) => { ...@@ -456,6 +581,12 @@ cameraInput.getSupportedPreviewFormats().then((previewFormats) => {
### getSupportedPhotoFormats\(callback: AsyncCallback<Array<CameraFormat\>\>\): void;<a name="section189141826104616"></a> ### getSupportedPhotoFormats\(callback: AsyncCallback<Array<CameraFormat\>\>\): void;<a name="section189141826104616"></a>
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Gets supported formats for photographing. This method uses an asynchronous callback to return the supported formats. Gets supported formats for photographing. This method uses an asynchronous callback to return the supported formats.
**Parameters** **Parameters**
...@@ -482,6 +613,12 @@ cameraInput.getSupportedPhotoFormats((err, photoFormats) => { ...@@ -482,6 +613,12 @@ cameraInput.getSupportedPhotoFormats((err, photoFormats) => {
### getSupportedPhotoFormats\(\): Promise<Array<CameraFormat\>\>;<a name="section189141826104616"></a> ### getSupportedPhotoFormats\(\): Promise<Array<CameraFormat\>\>;<a name="section189141826104616"></a>
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Gets supported formats for photographing. This method uses a promise to return the supported formats. Gets supported formats for photographing. This method uses a promise to return the supported formats.
**Parameters** **Parameters**
...@@ -504,6 +641,12 @@ cameraInput.getSupportedPhotoFormats().then((photoFormats) => { ...@@ -504,6 +641,12 @@ cameraInput.getSupportedPhotoFormats().then((photoFormats) => {
### getSupportedVideoFormats\(callback: AsyncCallback<Array<CameraFormat\>\>\): void; ### getSupportedVideoFormats\(callback: AsyncCallback<Array<CameraFormat\>\>\): void;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Gets supported formats for video recording. This method uses an asynchronous callback to return the supported video formats. Gets supported formats for video recording. This method uses an asynchronous callback to return the supported video formats.
**Parameters** **Parameters**
...@@ -530,6 +673,12 @@ cameraInput.getSupportedVideoFormats((err, videoFormats) => { ...@@ -530,6 +673,12 @@ cameraInput.getSupportedVideoFormats((err, videoFormats) => {
### getSupportedVideoFormats\(\): Promise<Array<CameraFormat\>\>; ### getSupportedVideoFormats\(\): Promise<Array<CameraFormat\>\>;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Gets supported formats for video recording. This method uses a promise to return the supported video format. Gets supported formats for video recording. This method uses a promise to return the supported video format.
**Parameters** **Parameters**
...@@ -552,6 +701,12 @@ cameraInput.getSupportedVideoFormats().then((videoFormats) => { ...@@ -552,6 +701,12 @@ cameraInput.getSupportedVideoFormats().then((videoFormats) => {
### hasFlash(callback: AsyncCallback<boolean\>): void; <a name="sec_hasFlash"></a> ### hasFlash(callback: AsyncCallback<boolean\>): void; <a name="sec_hasFlash"></a>
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Checks whether the device has flash light. This method uses an asynchronous callback to return the result. Checks whether the device has flash light. This method uses an asynchronous callback to return the result.
**Parameters** **Parameters**
...@@ -578,6 +733,12 @@ cameraInput.hasFlash((err, status) => { ...@@ -578,6 +733,12 @@ cameraInput.hasFlash((err, status) => {
### hasFlash(): Promise<boolean\>; ### hasFlash(): Promise<boolean\>;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Checks whether the device has flash light. This method uses a promise to return the result. Checks whether the device has flash light. This method uses a promise to return the result.
**Parameters** **Parameters**
...@@ -600,6 +761,12 @@ cameraInput.hasFlash().then((status) => { ...@@ -600,6 +761,12 @@ cameraInput.hasFlash().then((status) => {
### isFlashModeSupported(flashMode: FlashMode, callback: AsyncCallback<boolean\>): void; <a name="sec_isFlashModeSupported"></a> ### isFlashModeSupported(flashMode: FlashMode, callback: AsyncCallback<boolean\>): void; <a name="sec_isFlashModeSupported"></a>
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Checks whether a specified flash mode is supported. This method uses an asynchronous callback to return the result. Checks whether a specified flash mode is supported. This method uses an asynchronous callback to return the result.
**Parameters** **Parameters**
...@@ -627,6 +794,12 @@ cameraInput.isFlashModeSupported(flashMode, (err, status) => { ...@@ -627,6 +794,12 @@ cameraInput.isFlashModeSupported(flashMode, (err, status) => {
### isFlashModeSupported(flashMode: FlashMode): Promise<boolean\>; ### isFlashModeSupported(flashMode: FlashMode): Promise<boolean\>;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Checks whether a specified flash mode is supported. This method uses a promise to return the result. Checks whether a specified flash mode is supported. This method uses a promise to return the result.
**Parameters** **Parameters**
...@@ -651,6 +824,12 @@ cameraInput.isFlashModeSupported(flashMode).then((status) => { ...@@ -651,6 +824,12 @@ cameraInput.isFlashModeSupported(flashMode).then((status) => {
### setFlashMode(flashMode: FlashMode, callback: AsyncCallback<void\>): void; ### setFlashMode(flashMode: FlashMode, callback: AsyncCallback<void\>): void;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Sets flash mode. This method uses an asynchronous callback to return the result. Sets flash mode. This method uses an asynchronous callback to return the result.
Note: Before setting the flash mode, check the support for the flash light (<a href="#sec_hasFlash">hasFlash</a> method) and flash mode support (<a href="#sec_isFlashModeSupported">isFlashModeSupported</a> method); Note: Before setting the flash mode, check the support for the flash light (<a href="#sec_hasFlash">hasFlash</a> method) and flash mode support (<a href="#sec_isFlashModeSupported">isFlashModeSupported</a> method);
...@@ -680,6 +859,12 @@ cameraInput.setFlashMode(flashMode, (err) => { ...@@ -680,6 +859,12 @@ cameraInput.setFlashMode(flashMode, (err) => {
### setFlashMode(flashMode: FlashMode): Promise<void\>; ### setFlashMode(flashMode: FlashMode): Promise<void\>;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Sets flash mode. This method uses a promise to return the result. Sets flash mode. This method uses a promise to return the result.
Note: Before setting the flash mode, check the support for the flash light (<a href="#sec_hasFlash">hasFlash</a> method) and flash mode support (<a href="#sec_isFlashModeSupported">isFlashModeSupported</a> method); Note: Before setting the flash mode, check the support for the flash light (<a href="#sec_hasFlash">hasFlash</a> method) and flash mode support (<a href="#sec_isFlashModeSupported">isFlashModeSupported</a> method);
...@@ -706,6 +891,12 @@ cameraInput.setFlashMode(flashMode).then() => { ...@@ -706,6 +891,12 @@ cameraInput.setFlashMode(flashMode).then() => {
### getFlashMode(callback: AsyncCallback<FlashMode\>): void; ### getFlashMode(callback: AsyncCallback<FlashMode\>): void;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Gets current flash mode. This method uses an asynchronous callback to return the result. Gets current flash mode. This method uses an asynchronous callback to return the result.
**Parameters** **Parameters**
...@@ -732,6 +923,12 @@ cameraInput.getFlashMode((err, flashMode) => { ...@@ -732,6 +923,12 @@ cameraInput.getFlashMode((err, flashMode) => {
### getFlashMode(): Promise<FlashMode\>; ### getFlashMode(): Promise<FlashMode\>;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Gets current flash mode. This method uses a promise to return the result. Gets current flash mode. This method uses a promise to return the result.
**Parameters** **Parameters**
...@@ -752,28 +949,22 @@ cameraInput.getFlashMode().then(flashMode) => { ...@@ -752,28 +949,22 @@ cameraInput.getFlashMode().then(flashMode) => {
}) })
``` ```
## FlashMode <a name="sec_FlashMode"></a> ### isFocusModeSupported(afMode: FocusMode, callback: AsyncCallback<boolean\>): void; <a name="sec_isFocusModeSupported"></a>
Enumerates the flash modes.
| Name | Default value | Description | **System Capabilities:**
|------------------------|---------------|------------------------|
| FLASH_MODE_CLOSE | 0 | Flash mode close |
| FLASH_MODE_OPEN | 1 | Flash mode open |
| FLASH_MODE_AUTO | 2 | Flash mode auto |
| FLASH_MODE_ALWAYS_OPEN | 3 | Flash mode always open |
SystemCapability.Multimedia.Camera.Core
## createCaptureSession\(context: Context, callback: AsyncCallback<CaptureSession\>\): void; **Description**
Creates a **CaptureSession** instance. This method uses an asynchronous callback to return the instance. Checks whether a specified focus mode is supported. This method uses an asynchronous callback to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
|----------|--------------------------------|-----------|-----------------------------------------------------| |-----------|------------------------|-----------|----------------------------------------------------|
| context | Context | Yes | Application context | | afMode | <a href="#sec_FocusMode">FocusMode</a> | Yes | Focus mode |
| callback | AsyncCallback<CaptureSession\> | Yes | Callback used to return the CaptureSession instance | | callback | AsyncCallback<boolean\> | Yes | Callback used to return the device focus support status |
**Return values** **Return values**
...@@ -782,53 +973,63 @@ none ...@@ -782,53 +973,63 @@ none
**Example** **Example**
``` ```
camera.createCaptureSession(context), (err, captureSession) => { cameraInput.isFocusModeSupported(afMode, (err, status) => {
if (err) { if (err) {
console.error('Failed to create the CaptureSession instance. ${err.message}'); console.error('Failed to check whether the focus mode is supported. ${err.message}');
return; return;
} }
console.log('Callback returned with the CaptureSession instance.' + captureSession); console.log('Callback returned with the focus mode support status: ' + status);
}); })
``` ```
## createCaptureSession(context: Context\): Promise<CaptureSession\>; ### isFocusModeSupported(afMode: FocusMode): Promise<boolean\>;
Creates a **CaptureSession** instance. This method uses a promise to return the instance. **System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Checks whether a specified focus mode is supported. This method uses a promise to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
|----------|-------------------------------|-----------|-----------------------------------------------------| |-----------|----------------------------------------|-----------|-------------|
| context | Context | Yes | Application context | | afMode | <a href="#sec_FocusMode">FocusMode</a> | Yes | Focus mode |
**Return values** **Return values**
| Type | Description | | Type | Description |
|---------------------------|---------------------------------------------------| |-----------------------|---------------------------------------------------|
| Promise<CaptureSession\> | Promise used to return the CaptureSession instance. | | Promise<boolean\> | Promise used to return the focus mode support status. |
**Example** **Example**
``` ```
camera.createCaptureSession(context).then((captureSession) => { cameraInput.isFocusModeSupported(afMode).then((status) => {
console.log('Promise returned with the CaptureSession instance'); console.log('Promise returned with focus mode support status.' + status);
}) })
``` ```
## CaptureSession<a name="sec_CaptureSession"></a> ### setFocusMode(afMode: FocusMode, callback: AsyncCallback<void\>): void;
Implements session capture. **System Capabilities:**
### beginConfig\(callback: AsyncCallback<void\>\): void;<a name="section84581011418"></a> SystemCapability.Multimedia.Camera.Core
Starts configuration for this CaptureSession instance. This method uses an asynchronous callback to return the result. **Description**
**Parameters** Sets focus mode. This method uses an asynchronous callback to return the result.
| Name | Type | Mandatory | Description | Note: Before setting the focus mode, check focus mode support (<a href="#sec_isFocusModeSupported">isFocusModeSupported</a> method);
|----------|----------------------|-----------|----------------------------------------------|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result |
**Parameters**
| Name | Type | Mandatory | Description |
|-----------|------------------------|-----------|------------------------------------|
| afMode | <a href="#sec_FocusMode">FocusMode</a> | Yes | Focus mode |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result |
**Return values** **Return values**
...@@ -837,47 +1038,62 @@ none ...@@ -837,47 +1038,62 @@ none
**Example** **Example**
``` ```
camera.beginConfig((err) => { cameraInput.setFocusMode(afMode, (err) => {
if (err) { if (err) {
console.error('Failed to start the configuration. ${err.message}'); console.error('Failed to set the focus mode ${err.message}');
return; return;
} }
console.log('Callback invoked to indicate the begin config success.'); console.log('Callback returned with the successful execution of setFocusMode.');
}); })
``` ```
### beginConfig\(\): Promise<void\>; ### setFocusMode(afMode: FocusMode): Promise<void\>;
Starts configuration for this CaptureSession instance. This method uses a promise to return the result. **System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Sets focus mode. This method uses a promise to return the result.
Note: Before setting the focus mode, check focus mode support (<a href="#sec_isFocusModeSupported">isFocusModeSupported</a> method);
**Parameters** **Parameters**
none | Name | Type | Mandatory | Description |
|-----------|-----------------------------------------|-----------|-------------|
| afMode | <a href="#sec_FocusMode">FocusMode</a> | Yes | Focus mode |
**Return values** **Return values**
| Type | Description | | Type | Description |
|---------------|---------------------------------------------| |-----------------------|-----------------------------------------|
| Promise<void\> | Promise used to return the result | | Promise<void\> | Promise used to return the result |
**Example** **Example**
``` ```
camera.beginConfig().then(() => { cameraInput.setFocusMode(afMode).then() => {
console.log('Promise returned to indicate the begin config success.'); console.log('Promise returned with the successful execution of setFocusMode.');
}) })
``` ```
### commitConfig\(callback: AsyncCallback<void\>\): void;<a name="section84581011418"></a> ### getFocusMode(callback: AsyncCallback<FocusMode\>): void;
Commits the configuration for this CaptureSession instance. This method uses an asynchronous callback to return the result. **System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Gets the current focus mode. This method uses an asynchronous callback to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
|----------|---------------------|-----------|----------------------------------------------| |-----------|---------------------------|-----------|------------------------------------------------|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result | | callback | AsyncCallback<FocusMode\> | Yes | Callback used to return the current focus mode |
**Return values** **Return values**
...@@ -886,19 +1102,24 @@ none ...@@ -886,19 +1102,24 @@ none
**Example** **Example**
``` ```
camera.commitConfig((err) => { cameraInput.getFocusMode((err, afMode) => {
if (err) { if (err) {
console.error('Failed to commit the configuration. ${err.message}'); console.error('Failed to get the focus mode ${err.message}');
return; return;
} }
console.log('Callback invoked to indicate the commit config success.'); console.log('Callback returned with current focus mode: ' + afMode);
}); })
``` ```
### getFocusMode(): Promise<FocusMode\>;
### commitConfig\(\): Promise<void\>;<a name="section189141826104616"></a> **System Capabilities:**
Commits the configuration for this CaptureSession instance. This method uses a promise to return the result. SystemCapability.Multimedia.Camera.Core
**Description**
Gets the current focus mode. This method uses a promise to return the result.
**Parameters** **Parameters**
...@@ -906,28 +1127,33 @@ none ...@@ -906,28 +1127,33 @@ none
**Return values** **Return values**
| Type | Description | | Type | Description |
|---------------|---------------------------------------------| |-----------------------|---------------------------------------------------|
| Promise<void\> | Promise used to return the result | | Promise<FocusMode\> | Promise used to return the focus mode |
**Example** **Example**
``` ```
camera.commitConfig().then(() => { cameraInput.getFocusMode().then(afMode) => {
console.log('Promise returned to indicate the commit config success.'); console.log('Promise returned with current focus mode : ' + afMode);
}) })
``` ```
### addInput\(cameraInput: CameraInput, callback: AsyncCallback<void\>\): void; ### getZoomRatioRange\(callback: AsyncCallback<Array<number\>\>\): void;
Add a CameraInput instance to this CaptureSession instance. This method uses an asynchronous callback to return the result. **System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Gets the zoom ratios of all zoom values. This method uses an asynchronous callback to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
|-------------|----------------------|-----------|---------------------------------------------| |----------|--------------------------------|-----------|-------------------------------------------------|
| cameraInput | CameraInput | Yes | CameraInput instance to add | | callback | AsyncCallback<Array<number\>\> | Yes | Callback used to return the zoom ratio range |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result |
**Return values** **Return values**
...@@ -937,50 +1163,59 @@ none ...@@ -937,50 +1163,59 @@ none
**Example** **Example**
``` ```
camera.addInput(cameraInput, (err) => { cameraInput.getZoomRatioRange(err, zoomRatioRange) => {
if (err) { if (err) {
console.error('Failed to add the CameraInput instance. ${err.message}'); console.error('Failed to get the zoom ratio range. ${err.message}');
return; return;
} }
console.log('Callback invoked to indicate that the CameraInput instance is added.'); console.log('Callback returned with zoom ratio range: ' + zoomRatioRange.length);
}); })
``` ```
### addInput\(cameraInput: CameraInput\): Promise<void\>;<a name="section189141826104616"></a> ### getZoomRatioRange\(\): Promise<Array<number\>\>;
Add a CameraInput instance to this CaptureSession instance. This method uses a promise to return the result. **System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Gets the zoom ratios of all zoom values. This method uses a promise to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | none
|-------------|---------------------|-----------|-------------------------------|
| cameraInput | CameraInput | Yes | CameraInput instance to add |
**Return values** **Return values**
| Type | Description | | Type | Description |
|----------------|------------------------------------| |------------------------|---------------------------------------------|
| Promise<void\> | Promise used to return the result | | Promise<Array<number\>\> | Promise used to return the zoom ratio range |
**Example** **Example**
``` ```
camera.addInput(cameraInput).then(() => { cameraInput.getZoomRatioRange().then((zoomRatioRange) => {
console.log('Promise used to indicate that the CameraInput instance is added.'); console.log('Promise returned with zoom ratio range: ' + zoomRatioRange.length);
}) })
``` ```
### addOutput\(previewOutput: PreviewOutput, callback: AsyncCallback<void\>\): void;<a name="section84581011418"></a> ### setZoomRatio(zoomRatio: number, callback: AsyncCallback<void\>): void;
Add a PreviewOutput instance to this CaptureSession instance. This method uses an asynchronous callback to return the result. **System Capabilities:**
**Parameters** SystemCapability.Multimedia.Camera.Core
| Name | Type | Mandatory | Description | **Description**
|---------------|----------------------|-----------|-------------------------------------|
| previewOutput | PreviewOutput | Yes | PreviewOutput instance to add |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result |
Sets a zoom ratio. This method uses an asynchronous callback to return the result.
**Parameters**
| Name | Type | Mandatory | Description |
|-----------|------------------------|-----------|------------------------------------|
| zoomRatio | number | Yes | Zoom ratio |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result |
**Return values** **Return values**
...@@ -989,49 +1224,60 @@ none ...@@ -989,49 +1224,60 @@ none
**Example** **Example**
``` ```
camera.addOutput(previewOutput, (err) => { cameraInput.setZoomRatio(zoomRatio, (err) => {
if (err) { if (err) {
console.error('Failed to add the PreviewOutput instance ${err.message}'); console.error('Failed to set the zoom ratio value ${err.message}');
return; return;
} }
console.log('Callback invoked to indicate that the PreviewOutput instance is added.'); console.log('Callback returned with the successful execution of setZoomRatio.');
}); })
``` ```
### addOutput\(previewOutput: PreviewOutput\): Promise<void\>;<a name="section189141826104616"></a> ### setZoomRatio(zoomRatio: number): Promise<void\>;
Add a PreviewOutput instance to this CaptureSession instance. This method uses a promise to return the result. **System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Sets a zoom ratio. This method uses a promise to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
|---------------|---------------------|-----------|--------------------------------| |-----------|----------|-----------|-------------|
| previewOutput | PreviewOutput | Yes | PreviewOutput instance to add | | zoomRatio | number | Yes | zoom ratio |
**Return values** **Return values**
| Type | Description | | Type | Description |
|----------------|-----------------------------------| |-----------------------|-----------------------------------------|
| Promise<void\> | Promise used to return the result | | Promise<void\> | Promise used to return the result |
**Example** **Example**
``` ```
camera.addOutput(previewOutput).then(() => { cameraInput.setZoomRatio(zoomRatio).then() => {
console.log('Promise used to indicate that the PreviewOutput instance is added.'); console.log('Promise returned with the successful execution of setZoomRatio.');
}) })
``` ```
### addOutput\(photoOutput: PhotoOutput, callback: AsyncCallback<void\>\): void;<a name="section84581011418"></a> ### getZoomRatio(callback: AsyncCallback<number\>): void;
Add a PhotoOutput instance to this CaptureSession instance. This method uses an asynchronous callback to return the result. **System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Gets current zoom ratio value. This method uses an asynchronous callback to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
|---------------|---------------------|-----------|-------------------------------------| |-----------|---------------------------|-----------|------------------------------------------------------|
| photoOutput | PhotoOutput | Yes | PhotoOutput instance to add | | callback | AsyncCallback<number\> | Yes | Callback used to return the current zoom ratio value |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result |
**Return values** **Return values**
...@@ -1040,16 +1286,538 @@ none ...@@ -1040,16 +1286,538 @@ none
**Example** **Example**
``` ```
camera.addOutput(photoOutput, (err) => { cameraInput.getZoomRatio((err, zoomRatio) => {
if (err) { if (err) {
console.error('Failed to add the PhotoOutput instance ${err.message}'); console.error('Failed to get the zoom ratio ${err.message}');
return; return;
} }
console.log('Callback invoked to indicate that the PhotoOutput instance is added.'); console.log('Callback returned with current zoom ratio: ' + zoomRatio);
}); })
``` ```
### addOutput\(photoOutput: PhotoOutput\): Promise<void\>;<a name="section189141826104616"></a> ### getZoomRatio(): Promise<number\>;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Gets current zoom ratio value. This method uses a promise to return the result.
**Parameters**
none
**Return values**
| Type | Description |
|-----------------------|---------------------------------------------------|
| Promise<number\> | Promise used to return the zoom ratio vaule |
**Example**
```
cameraInput.getZoomRatio().then(zoomRatio) => {
console.log('Promise returned with current zoom ratio : ' + zoomRatio);
})
```
### release\(callback: AsyncCallback<void\>\): void;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Releases this **CameraInput** instance. This method uses an asynchronous callback to return the result.
**Parameters**
| Name | Type | Mandatory | Description |
|----------|----------------------|-----------|------------------------------------|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result |
**Return values**
none
**Example**
```
cameraInput.release((err) => {
if (err) {
console.error('Failed to release the CameraInput instance ${err.message}');
return;
}
console.log('Callback invoked to indicate that the CameraInput instance is released successfully.');
});
```
### release(): Promise<void\>;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Releases this **CameraInput** instance. This method uses a promise to return the result.
**Parameters**
none
**Return values**
| Type | Description |
|----------------|---------------------------------------------|
| Promise<void\> | Promise used to return the result |
**Example**
```
cameraInput.release().then(() => {
console.log('Promise returned to indicate that the CameraInput instance is released successfully.');
})
```
### on(type: 'focusStateChange', callback: Callback<FocusState\>): void;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Listens for focus state changes. This method uses a callback to get focus state changes.
**Parameters**
| Name | Type | Mandatory | Description |
| :------- | :--------------------- | :-------- | :-----------------------------------------------|
| type | string | Yes | Name of the event to listen for. |
| callback | Callback<FocusState\> | Yes | Callback used to get the focus state change. |
**Return value**
None
**Example**
```
cameraInput.on('focusStateChange', (focusState) => {
console.log('Focus state : ' + focusState);
})
```
### on(type: 'error', callback: Callback<CameraInputError\>): void;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Listens for **CameraInput** errors. This method uses a callback to get errors.
**Parameters**
| Name | Type | Mandatory | Description |
| :------- | :--------------------- | :-------- | :-----------------------------------------------|
| type | string | Yes | Name of the event to listen for. |
| callback | Callback<CameraInputError\> | Yes | Callback used to get the camera input errors. |
**Return value**
None
**Example**
```
cameraInput.on('error', (cameraInputError) => {
console.log('Camera input error code: ' + cameraInputError.code);
})
```
## FlashMode <a name="sec_FlashMode"></a>
Enumerates the flash modes.
| Name | Default value | Description |
|------------------------|---------------|------------------------|
| FLASH_MODE_CLOSE | 0 | Flash mode close <br/>System Capabilities: SystemCapability.Multimedia.Camera.Core |
| FLASH_MODE_OPEN | 1 | Flash mode open <br/>System Capabilities: SystemCapability.Multimedia.Camera.Core |
| FLASH_MODE_AUTO | 2 | Flash mode auto <br/>System Capabilities: SystemCapability.Multimedia.Camera.Core |
| FLASH_MODE_ALWAYS_OPEN | 3 | Flash mode always open <br/>System Capabilities: SystemCapability.Multimedia.Camera.Core |
## FocusMode <a name="sec_FocusMode"></a>
Enumerates the focus modes.
| Name | Default value | Description |
|----------------------------|---------------|----------------------------|
| FOCUS_MODE_MANUAL | 0 | Focus mode manual <br/>System Capabilities: SystemCapability.Multimedia.Camera.Core |
| FOCUS_MODE_CONTINUOUS_AUTO | 1 | Focus mode continuous auto <br/>System Capabilities: SystemCapability.Multimedia.Camera.Core|
| FOCUS_MODE_AUTO | 2 | Focus mode auto <br/>System Capabilities: SystemCapability.Multimedia.Camera.Core |
| FOCUS_MODE_LOCKED | 3 | Focus mode locked <br/>System Capabilities: SystemCapability.Multimedia.Camera.Core |
## createCaptureSession\(context: Context, callback: AsyncCallback<CaptureSession\>\): void;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Creates a **CaptureSession** instance. This method uses an asynchronous callback to return the instance.
**Parameters**
| Name | Type | Mandatory | Description |
|----------|--------------------------------|-----------|-----------------------------------------------------|
| context | Context | Yes | Application context |
| callback | AsyncCallback<CaptureSession\> | Yes | Callback used to return the CaptureSession instance |
**Return values**
none
**Example**
```
captureSession.createCaptureSession(context), (err, captureSession) => {
if (err) {
console.error('Failed to create the CaptureSession instance. ${err.message}');
return;
}
console.log('Callback returned with the CaptureSession instance.' + captureSession);
});
```
## createCaptureSession(context: Context\): Promise<CaptureSession\>;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Creates a **CaptureSession** instance. This method uses a promise to return the instance.
**Parameters**
| Name | Type | Mandatory | Description |
|----------|-------------------------------|-----------|-----------------------------------------------------|
| context | Context | Yes | Application context |
**Return values**
| Type | Description |
|---------------------------|---------------------------------------------------|
| Promise<CaptureSession\> | Promise used to return the CaptureSession instance. |
**Example**
```
captureSession.createCaptureSession(context).then((captureSession) => {
console.log('Promise returned with the CaptureSession instance');
})
```
## CaptureSession<a name="sec_CaptureSession"></a>
Implements session capture.
### beginConfig\(callback: AsyncCallback<void\>\): void;<a name="section84581011418"></a>
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Starts configuration for this CaptureSession instance. This method uses an asynchronous callback to return the result.
**Parameters**
| Name | Type | Mandatory | Description |
|----------|----------------------|-----------|----------------------------------------------|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result |
**Return values**
none
**Example**
```
captureSession.beginConfig((err) => {
if (err) {
console.error('Failed to start the configuration. ${err.message}');
return;
}
console.log('Callback invoked to indicate the begin config success.');
});
```
### beginConfig\(\): Promise<void\>;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Starts configuration for this CaptureSession instance. This method uses a promise to return the result.
**Parameters**
none
**Return values**
| Type | Description |
|---------------|---------------------------------------------|
| Promise<void\> | Promise used to return the result |
**Example**
```
captureSession.beginConfig().then(() => {
console.log('Promise returned to indicate the begin config success.');
})
```
### commitConfig\(callback: AsyncCallback<void\>\): void;<a name="section84581011418"></a>
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Commits the configuration for this CaptureSession instance. This method uses an asynchronous callback to return the result.
**Parameters**
| Name | Type | Mandatory | Description |
|----------|---------------------|-----------|----------------------------------------------|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result |
**Return values**
none
**Example**
```
captureSession.commitConfig((err) => {
if (err) {
console.error('Failed to commit the configuration. ${err.message}');
return;
}
console.log('Callback invoked to indicate the commit config success.');
});
```
### commitConfig\(\): Promise<void\>;<a name="section189141826104616"></a>
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Commits the configuration for this CaptureSession instance. This method uses a promise to return the result.
**Parameters**
none
**Return values**
| Type | Description |
|---------------|---------------------------------------------|
| Promise<void\> | Promise used to return the result |
**Example**
```
captureSession.commitConfig().then(() => {
console.log('Promise returned to indicate the commit config success.');
})
```
### addInput\(cameraInput: CameraInput, callback: AsyncCallback<void\>\): void;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Add a CameraInput instance to this CaptureSession instance. This method uses an asynchronous callback to return the result.
**Parameters**
| Name | Type | Mandatory | Description |
|-------------|----------------------|-----------|---------------------------------------------|
| cameraInput | CameraInput | Yes | CameraInput instance to add |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result |
**Return values**
none
**Example**
```
captureSession.addInput(cameraInput, (err) => {
if (err) {
console.error('Failed to add the CameraInput instance. ${err.message}');
return;
}
console.log('Callback invoked to indicate that the CameraInput instance is added.');
});
```
### addInput\(cameraInput: CameraInput\): Promise<void\>;<a name="section189141826104616"></a>
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Add a CameraInput instance to this CaptureSession instance. This method uses a promise to return the result.
**Parameters**
| Name | Type | Mandatory | Description |
|-------------|---------------------|-----------|-------------------------------|
| cameraInput | CameraInput | Yes | CameraInput instance to add |
**Return values**
| Type | Description |
|----------------|------------------------------------|
| Promise<void\> | Promise used to return the result |
**Example**
```
captureSession.addInput(cameraInput).then(() => {
console.log('Promise used to indicate that the CameraInput instance is added.');
})
```
### addOutput\(previewOutput: PreviewOutput, callback: AsyncCallback<void\>\): void;<a name="section84581011418"></a>
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Add a PreviewOutput instance to this CaptureSession instance. This method uses an asynchronous callback to return the result.
**Parameters**
| Name | Type | Mandatory | Description |
|---------------|----------------------|-----------|-------------------------------------|
| previewOutput | PreviewOutput | Yes | PreviewOutput instance to add |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result |
**Return values**
none
**Example**
```
captureSession.addOutput(previewOutput, (err) => {
if (err) {
console.error('Failed to add the PreviewOutput instance ${err.message}');
return;
}
console.log('Callback invoked to indicate that the PreviewOutput instance is added.');
});
```
### addOutput\(previewOutput: PreviewOutput\): Promise<void\>;<a name="section189141826104616"></a>
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Add a PreviewOutput instance to this CaptureSession instance. This method uses a promise to return the result.
**Parameters**
| Name | Type | Mandatory | Description |
|---------------|---------------------|-----------|--------------------------------|
| previewOutput | PreviewOutput | Yes | PreviewOutput instance to add |
**Return values**
| Type | Description |
|----------------|-----------------------------------|
| Promise<void\> | Promise used to return the result |
**Example**
```
captureSession.addOutput(previewOutput).then(() => {
console.log('Promise used to indicate that the PreviewOutput instance is added.');
})
```
### addOutput\(photoOutput: PhotoOutput, callback: AsyncCallback<void\>\): void;<a name="section84581011418"></a>
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Add a PhotoOutput instance to this CaptureSession instance. This method uses an asynchronous callback to return the result.
**Parameters**
| Name | Type | Mandatory | Description |
|---------------|---------------------|-----------|-------------------------------------|
| photoOutput | PhotoOutput | Yes | PhotoOutput instance to add |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result |
**Return values**
none
**Example**
```
captureSession.addOutput(photoOutput, (err) => {
if (err) {
console.error('Failed to add the PhotoOutput instance ${err.message}');
return;
}
console.log('Callback invoked to indicate that the PhotoOutput instance is added.');
});
```
### addOutput\(photoOutput: PhotoOutput\): Promise<void\>;<a name="section189141826104616"></a>
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Add a PhotoOutput instance to this CaptureSession instance. This method uses a promise to return the result. Add a PhotoOutput instance to this CaptureSession instance. This method uses a promise to return the result.
...@@ -1068,13 +1836,19 @@ Add a PhotoOutput instance to this CaptureSession instance. This method uses a p ...@@ -1068,13 +1836,19 @@ Add a PhotoOutput instance to this CaptureSession instance. This method uses a p
**Example** **Example**
``` ```
camera.addOutput(photoOutput).then(() => { captureSession.addOutput(photoOutput).then(() => {
console.log('Promise used to indicate that the PhotoOutput instance is added.'); console.log('Promise used to indicate that the PhotoOutput instance is added.');
}) })
``` ```
### addOutput\(videoOutput: VideoOutput, callback: AsyncCallback<void\>\): void; ### addOutput\(videoOutput: VideoOutput, callback: AsyncCallback<void\>\): void;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Add a VideoOutput instance to this CaptureSession instance. This method uses an asynchronous callback to return the result. Add a VideoOutput instance to this CaptureSession instance. This method uses an asynchronous callback to return the result.
**Parameters** **Parameters**
...@@ -1091,7 +1865,7 @@ none ...@@ -1091,7 +1865,7 @@ none
**Example** **Example**
``` ```
camera.addOutput(videoOutput, (err) => { captureSession.addOutput(videoOutput, (err) => {
if (err) { if (err) {
console.error('Failed to add the VideoOutput instance ${err.message}'); console.error('Failed to add the VideoOutput instance ${err.message}');
return; return;
...@@ -1102,6 +1876,12 @@ camera.addOutput(videoOutput, (err) => { ...@@ -1102,6 +1876,12 @@ camera.addOutput(videoOutput, (err) => {
### addOutput\(videoOutput: VideoOutput\): Promise<void\>; ### addOutput\(videoOutput: VideoOutput\): Promise<void\>;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Add a VideoOutput instance to this CaptureSession instance. This method uses a promise to return the result. Add a VideoOutput instance to this CaptureSession instance. This method uses a promise to return the result.
**Parameters** **Parameters**
...@@ -1119,13 +1899,19 @@ Add a VideoOutput instance to this CaptureSession instance. This method uses a p ...@@ -1119,13 +1899,19 @@ Add a VideoOutput instance to this CaptureSession instance. This method uses a p
**Example** **Example**
``` ```
camera.addOutput(videoOutput).then(() => { captureSession.addOutput(videoOutput).then(() => {
console.log('Promise used to indicate that the VideoOutput instance is added.'); console.log('Promise used to indicate that the VideoOutput instance is added.');
}) })
``` ```
### removeInput\(cameraInput: CameraInput, callback: AsyncCallback<void\>\): void;<a name="section84581011418"></a> ### removeInput\(cameraInput: CameraInput, callback: AsyncCallback<void\>\): void;<a name="section84581011418"></a>
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Removes a **CameraInput** instance from this **CaptureSession** instance. This method uses an asynchronous callback to return the result. Removes a **CameraInput** instance from this **CaptureSession** instance. This method uses an asynchronous callback to return the result.
**Parameters** **Parameters**
...@@ -1143,7 +1929,7 @@ none ...@@ -1143,7 +1929,7 @@ none
**Example** **Example**
``` ```
camera.removeInput(cameraInput, (err) => { captureSession.removeInput(cameraInput, (err) => {
if (err) { if (err) {
console.error('Failed to remove the CameraInput instance. ${err.message}'); console.error('Failed to remove the CameraInput instance. ${err.message}');
return; return;
...@@ -1154,6 +1940,12 @@ camera.removeInput(cameraInput, (err) => { ...@@ -1154,6 +1940,12 @@ camera.removeInput(cameraInput, (err) => {
### removeInput\(cameraInput: CameraInput\): Promise<void\>;<a name="section189141826104616"></a> ### removeInput\(cameraInput: CameraInput\): Promise<void\>;<a name="section189141826104616"></a>
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Removes a **CameraInput** instance from this **CaptureSession** instance. This method uses a promise to return the result. Removes a **CameraInput** instance from this **CaptureSession** instance. This method uses a promise to return the result.
**Parameters** **Parameters**
...@@ -1171,13 +1963,19 @@ Removes a **CameraInput** instance from this **CaptureSession** instance. This m ...@@ -1171,13 +1963,19 @@ Removes a **CameraInput** instance from this **CaptureSession** instance. This m
**Example** **Example**
``` ```
camera.removeInput(cameraInput).then(() => { captureSession.removeInput(cameraInput).then(() => {
console.log('Promise returned to indicate that the cameraInput instance is removed.'); console.log('Promise returned to indicate that the cameraInput instance is removed.');
}) })
``` ```
### removeOutput\(previewOutput: PreviewOutput, callback: AsyncCallback<void\>\): void;<a name="section84581011418"></a> ### removeOutput\(previewOutput: PreviewOutput, callback: AsyncCallback<void\>\): void;<a name="section84581011418"></a>
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Removes a **PreviewOutput** instance from this **CaptureSession** instance. This method uses an asynchronous callback to return the result. Removes a **PreviewOutput** instance from this **CaptureSession** instance. This method uses an asynchronous callback to return the result.
**Parameters** **Parameters**
...@@ -1194,7 +1992,7 @@ none ...@@ -1194,7 +1992,7 @@ none
**Example** **Example**
``` ```
camera.removeOutput(previewOutput, (err) => { captureSession.removeOutput(previewOutput, (err) => {
if (err) { if (err) {
console.error('Failed to remove the PreviewOutput instance. ${err.message}'); console.error('Failed to remove the PreviewOutput instance. ${err.message}');
return; return;
...@@ -1205,6 +2003,12 @@ camera.removeOutput(previewOutput, (err) => { ...@@ -1205,6 +2003,12 @@ camera.removeOutput(previewOutput, (err) => {
### removeOutput(previewOutput: PreviewOutput): Promise<void\>; ### removeOutput(previewOutput: PreviewOutput): Promise<void\>;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Removes a **PreviewOutput** instance from this **CaptureSession** instance. This method uses a promise to return the result. Removes a **PreviewOutput** instance from this **CaptureSession** instance. This method uses a promise to return the result.
**Parameters** **Parameters**
...@@ -1224,13 +2028,19 @@ Removes a **PreviewOutput** instance from this **CaptureSession** instance. This ...@@ -1224,13 +2028,19 @@ Removes a **PreviewOutput** instance from this **CaptureSession** instance. This
**Example** **Example**
``` ```
camera.removeOutput(previewOutput).then(() => { captureSession.removeOutput(previewOutput).then(() => {
console.log('Promise returned to indicate that the PreviewOutput instance is removed.'); console.log('Promise returned to indicate that the PreviewOutput instance is removed.');
}) })
``` ```
### removeOutput(photoOutput: PhotoOutput, callback: AsyncCallback<void\>): void; ### removeOutput(photoOutput: PhotoOutput, callback: AsyncCallback<void\>): void;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Removes a **PhotoOutput** instance from this **CaptureSession** instance. This method uses an asynchronous callback to return the result. Removes a **PhotoOutput** instance from this **CaptureSession** instance. This method uses an asynchronous callback to return the result.
**Parameters** **Parameters**
...@@ -1247,7 +2057,7 @@ none ...@@ -1247,7 +2057,7 @@ none
**Example** **Example**
``` ```
camera.removeOutput(photoOutput, (err) => { captureSession.removeOutput(photoOutput, (err) => {
if (err) { if (err) {
console.error('Failed to remove the PhotoOutput instance. ${err.message}'); console.error('Failed to remove the PhotoOutput instance. ${err.message}');
return; return;
...@@ -1258,6 +2068,12 @@ camera.removeOutput(photoOutput, (err) => { ...@@ -1258,6 +2068,12 @@ camera.removeOutput(photoOutput, (err) => {
### removeOutput(photoOutput: PhotoOutput): Promise<void\>; ### removeOutput(photoOutput: PhotoOutput): Promise<void\>;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Removes a **PhotoOutput** instance from this **CaptureSession** instance. This method uses a promise to return the result. Removes a **PhotoOutput** instance from this **CaptureSession** instance. This method uses a promise to return the result.
**Parameters** **Parameters**
...@@ -1277,13 +2093,19 @@ Removes a **PhotoOutput** instance from this **CaptureSession** instance. This m ...@@ -1277,13 +2093,19 @@ Removes a **PhotoOutput** instance from this **CaptureSession** instance. This m
**Example** **Example**
``` ```
camera.removeOutput(photoOutput).then(() => { captureSession.removeOutput(photoOutput).then(() => {
console.log('Promise returned to indicate that the PhotoOutput instance is removed.'); console.log('Promise returned to indicate that the PhotoOutput instance is removed.');
}) })
``` ```
### removeOutput(videoOutput: VideoOutput, callback: AsyncCallback<void\>): void; ### removeOutput(videoOutput: VideoOutput, callback: AsyncCallback<void\>): void;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Removes a **VideoOutput** instance from this **CaptureSession** instance. This method uses an asynchronous callback to return the result. Removes a **VideoOutput** instance from this **CaptureSession** instance. This method uses an asynchronous callback to return the result.
**Parameters** **Parameters**
...@@ -1300,7 +2122,7 @@ none ...@@ -1300,7 +2122,7 @@ none
**Example** **Example**
``` ```
camera.removeOutput(videoOutput, (err) => { captureSession.removeOutput(videoOutput, (err) => {
if (err) { if (err) {
console.error('Failed to remove the VideoOutput instance. ${err.message}'); console.error('Failed to remove the VideoOutput instance. ${err.message}');
return; return;
...@@ -1311,6 +2133,12 @@ camera.removeOutput(videoOutput, (err) => { ...@@ -1311,6 +2133,12 @@ camera.removeOutput(videoOutput, (err) => {
### removeOutput(videoOutput: VideoOutput): Promise<void\>; ### removeOutput(videoOutput: VideoOutput): Promise<void\>;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Removes a **VideoOutput** instance from this **CaptureSession** instance. This method uses a promise to return the result. Removes a **VideoOutput** instance from this **CaptureSession** instance. This method uses a promise to return the result.
**Parameters** **Parameters**
...@@ -1330,13 +2158,19 @@ Removes a **VideoOutput** instance from this **CaptureSession** instance. This m ...@@ -1330,13 +2158,19 @@ Removes a **VideoOutput** instance from this **CaptureSession** instance. This m
**Example** **Example**
``` ```
camera.removeOutput(videoOutput).then(() => { captureSession.removeOutput(videoOutput).then(() => {
console.log('Promise returned to indicate that the VideoOutput instance is removed.'); console.log('Promise returned to indicate that the VideoOutput instance is removed.');
}) })
``` ```
### start\(callback: AsyncCallback<void\>\): void; ### start\(callback: AsyncCallback<void\>\): void;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Starts this **CaptureSession** instance. This method uses an asynchronous callback to return the result. Starts this **CaptureSession** instance. This method uses an asynchronous callback to return the result.
**Parameters** **Parameters**
...@@ -1352,7 +2186,7 @@ none ...@@ -1352,7 +2186,7 @@ none
**Example** **Example**
``` ```
camera.start((err) => { captureSession.start((err) => {
if (err) { if (err) {
console.error('Failed to start the session ${err.message}'); console.error('Failed to start the session ${err.message}');
return; return;
...@@ -1363,6 +2197,12 @@ camera.start((err) => { ...@@ -1363,6 +2197,12 @@ camera.start((err) => {
### start\(\): Promise<void\>;<a name="section189141826104616"></a> ### start\(\): Promise<void\>;<a name="section189141826104616"></a>
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Starts this **CaptureSession** instance. This method uses a promise to return the result. Starts this **CaptureSession** instance. This method uses a promise to return the result.
**Parameters** **Parameters**
...@@ -1378,13 +2218,19 @@ none ...@@ -1378,13 +2218,19 @@ none
**Example** **Example**
``` ```
camera.start().then(() => { captureSession.start().then(() => {
console.log('Promise returned to indicate the session start success.'); console.log('Promise returned to indicate the session start success.');
}) })
``` ```
### stop\(callback: AsyncCallback<void\>\): void;<a name="section84581011418"></a> ### stop\(callback: AsyncCallback<void\>\): void;<a name="section84581011418"></a>
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Stops this **CaptureSession** instance. This method uses an asynchronous callback to return the result. Stops this **CaptureSession** instance. This method uses an asynchronous callback to return the result.
**Parameters** **Parameters**
...@@ -1401,7 +2247,7 @@ none ...@@ -1401,7 +2247,7 @@ none
**Example** **Example**
``` ```
camera.stop((err) => { captureSession.stop((err) => {
if (err) { if (err) {
console.error('Failed to stop the session ${err.message}'); console.error('Failed to stop the session ${err.message}');
return; return;
...@@ -1410,9 +2256,14 @@ camera.stop((err) => { ...@@ -1410,9 +2256,14 @@ camera.stop((err) => {
}); });
``` ```
### stop(): Promise<void\>; ### stop(): Promise<void\>;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Stops this **CaptureSession** instance. This method uses a promise to return the result. Stops this **CaptureSession** instance. This method uses a promise to return the result.
**Parameters** **Parameters**
...@@ -1428,13 +2279,19 @@ none ...@@ -1428,13 +2279,19 @@ none
**Example** **Example**
``` ```
camera.stop().then(() => { captureSession.stop().then(() => {
console.log('Promise returned to indicate the session stop success.'); console.log('Promise returned to indicate the session stop success.');
}) })
``` ```
### release\(callback: AsyncCallback<void\>\): void;<a name="section84581011418"></a> ### release\(callback: AsyncCallback<void\>\): void;<a name="section84581011418"></a>
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Releases this **CaptureSession** instance. This method uses an asynchronous callback to return the result. Releases this **CaptureSession** instance. This method uses an asynchronous callback to return the result.
**Parameters** **Parameters**
...@@ -1450,7 +2307,7 @@ none ...@@ -1450,7 +2307,7 @@ none
**Example** **Example**
``` ```
camera.release((err) => { captureSession.release((err) => {
if (err) { if (err) {
console.error('Failed to release the CaptureSession instance ${err.message}'); console.error('Failed to release the CaptureSession instance ${err.message}');
return; return;
...@@ -1461,6 +2318,12 @@ camera.release((err) => { ...@@ -1461,6 +2318,12 @@ camera.release((err) => {
### release(): Promise<void\>; ### release(): Promise<void\>;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Releases this **CaptureSession** instance. This method uses a promise to return the result. Releases this **CaptureSession** instance. This method uses a promise to return the result.
**Parameters** **Parameters**
...@@ -1476,13 +2339,48 @@ none ...@@ -1476,13 +2339,48 @@ none
**Example** **Example**
``` ```
camera.release().then(() => { captureSession.release().then(() => {
console.log('Promise returned to indicate that the CaptureSession instance is released successfully.'); console.log('Promise returned to indicate that the CaptureSession instance is released successfully.');
}) })
``` ```
### on(type: 'error', callback: Callback<CaptureSessionError\>): void;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Listens for **CaptureSession** errors. This method uses a callback to get errors.
**Parameters**
| Name | Type | Mandatory | Description |
| :------- | :--------------------- | :-------- | :-----------------------------------------------|
| type | string | Yes | Name of the event to listen for. |
| callback | Callback<CaptureSessionError\> | Yes | Callback used to get the capture session errors. |
**Return value**
None
**Example**
```
captureSession.on('error', (captureSessionError) => {
console.log('Capture session error code: ' + captureSessionError.code);
})
```
## createPreviewOutput(surfaceId: string, callback: AsyncCallback<PreviewOutput\>): void; ## createPreviewOutput(surfaceId: string, callback: AsyncCallback<PreviewOutput\>): void;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Creates a **PreviewOutput** instance. This method uses an asynchronous callback to return the instance. Creates a **PreviewOutput** instance. This method uses an asynchronous callback to return the instance.
**Parameters** **Parameters**
...@@ -1510,6 +2408,12 @@ camera.createPreviewOutput(surfaceId), (err, previewOutput) => { ...@@ -1510,6 +2408,12 @@ camera.createPreviewOutput(surfaceId), (err, previewOutput) => {
## createPreviewOutput(surfaceId: string): Promise<PreviewOutput>; ## createPreviewOutput(surfaceId: string): Promise<PreviewOutput>;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Creates a **PreviewOutput** instance. This method uses a promise to return the instance. Creates a **PreviewOutput** instance. This method uses a promise to return the instance.
**Parameters** **Parameters**
...@@ -1538,6 +2442,12 @@ Implements preview output. ...@@ -1538,6 +2442,12 @@ Implements preview output.
### release(callback: AsyncCallback<void\>): void; ### release(callback: AsyncCallback<void\>): void;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Releases this **PreviewOutput** instance. This method uses an asynchronous callback to return the result. Releases this **PreviewOutput** instance. This method uses an asynchronous callback to return the result.
**Parameters** **Parameters**
...@@ -1564,6 +2474,12 @@ previewOutput.release((err) => { ...@@ -1564,6 +2474,12 @@ previewOutput.release((err) => {
### release(): Promise<void\>; ### release(): Promise<void\>;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Releases this **PreviewOutput** instance. This method uses a promise to return the result. Releases this **PreviewOutput** instance. This method uses a promise to return the result.
**Parameters** **Parameters**
...@@ -1584,8 +2500,101 @@ previewOutput.release().then(() => { ...@@ -1584,8 +2500,101 @@ previewOutput.release().then(() => {
}) })
``` ```
### on(type: 'frameStart', callback: Callback<number\>): void;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Listens for preview frame start events. This method uses a callback to get the event information.
**Parameters**
| Name | Type | Mandatory | Description |
| :------- | :---------------- | :-------- | :----------------------------------|
| type | string | Yes | Name of the event to listen for. |
| callback | Callback<void\> | Yes | Callback used to return the result |
**Return value**
None
**Example**
```
previewOutput.on('frameStart', () => {
console.log('Preview frame started');
})
```
### on(type: 'frameEnd', callback: Callback<number\>): void;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Listens for preview frame end event. This method uses a callback to get the event information.
**Parameters**
| Name | Type | Mandatory | Description |
| :------- | :---------------- | :-------- | :----------------------------------|
| type | string | Yes | Name of the event to listen for. |
| callback | Callback<void\> | Yes | Callback used to return the result |
**Return value**
None
**Example**
```
previewOutput.on('frameEnd', () => {
console.log('Preview frame ended');
})
```
### on(type: 'error', callback: Callback<PreviewOutputError\>): void;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Listens for **PreviewOutput** errors. This method uses a callback to get errors.
**Parameters**
| Name | Type | Mandatory | Description |
| :------- | :--------------------- | :-------- | :-----------------------------------------------|
| type | string | Yes | Name of the event to listen for. |
| callback | Callback<PreviewOutputError\> | Yes | Callback used to get the preview output errors. |
**Return value**
None
**Example**
```
previewOutput.on('error', (previewOutputError) => {
console.log('Preview output error code: ' + previewOutputError.code);
})
```
## createPhotoOutput(surfaceId: string, callback: AsyncCallback<PhotoOutput\>): void; ## createPhotoOutput(surfaceId: string, callback: AsyncCallback<PhotoOutput\>): void;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Creates a **PhotoOutput** instance. This method uses an asynchronous callback to return the instance. Creates a **PhotoOutput** instance. This method uses an asynchronous callback to return the instance.
**Parameters** **Parameters**
...@@ -1613,6 +2622,12 @@ camera.createPhotoOutput(surfaceId), (err, photoOutput) => { ...@@ -1613,6 +2622,12 @@ camera.createPhotoOutput(surfaceId), (err, photoOutput) => {
## createPhotoOutput(surfaceId: string): Promise<PhotoOutput\>; ## createPhotoOutput(surfaceId: string): Promise<PhotoOutput\>;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Creates a **PhotoOutput** instance. This method uses a promise to return the PhotoOutput instance. Creates a **PhotoOutput** instance. This method uses a promise to return the PhotoOutput instance.
**Parameters** **Parameters**
...@@ -1640,10 +2655,10 @@ Enumerates the image rotation angles. ...@@ -1640,10 +2655,10 @@ Enumerates the image rotation angles.
| Name | Default Value | Description | | Name | Default Value | Description |
|--------------|---------------|----------------------------------------| |--------------|---------------|----------------------------------------|
| ROTATION_0 | 0 | The capture image rotates 0 degrees. | | ROTATION_0 | 0 | The capture image rotates 0 degrees <br/>System Capabilities: SystemCapability.Multimedia.Camera.Core |
| ROTATION_90 | 90 | The capture image rotates 90 degrees. | | ROTATION_90 | 90 | The capture image rotates 90 degrees <br/>System Capabilities: SystemCapability.Multimedia.Camera.Core |
| ROTATION_180 | 180 | The capture image rotates 180 degrees. | | ROTATION_180 | 180 | The capture image rotates 180 degrees <br/>System Capabilities: SystemCapability.Multimedia.Camera.Core |
| ROTATION_270 | 270 | The capture image rotates 270 degrees. | | ROTATION_270 | 270 | The capture image rotates 270 degrees <br/>System Capabilities: SystemCapability.Multimedia.Camera.Core|
## Location ## Location
...@@ -1652,8 +2667,8 @@ Defines the location of a captured image. ...@@ -1652,8 +2667,8 @@ Defines the location of a captured image.
| Name | Type | Access | Description | | Name | Type | Access | Description |
|-----------|--------|--------------|-------------| |-----------|--------|--------------|-------------|
| latitude | number | read / write | Latitude | | latitude | number | read / write | Latitude <br/>System Capabilities: SystemCapability.Multimedia.Camera.Core |
| longitude | number | read / write | Longitude | | longitude | number | read / write | Longitude <br/>System Capabilities: SystemCapability.Multimedia.Camera.Core |
## QualityLevel ## QualityLevel
...@@ -1661,9 +2676,9 @@ Enumerates the image quality levels. ...@@ -1661,9 +2676,9 @@ Enumerates the image quality levels.
| Name | Default value | Description | | Name | Default value | Description |
|----------------------|---------------|----------------------| |----------------------|---------------|----------------------|
| QUALITY_LEVEL_HIGH | 0 | High image quality | | QUALITY_LEVEL_HIGH | 0 | High image quality <br/>System Capabilities: SystemCapability.Multimedia.Camera.Core |
| QUALITY_LEVEL_MEDIUM | 1 | Medium image quality | | QUALITY_LEVEL_MEDIUM | 1 | Medium image quality <br/>System Capabilities: SystemCapability.Multimedia.Camera.Core |
| QUALITY_LEVEL_LOW | 2 | Low image quality | | QUALITY_LEVEL_LOW | 2 | Low image quality <br/>System Capabilities: SystemCapability.Multimedia.Camera.Core |
## PhotoCaptureSetting ## PhotoCaptureSetting
...@@ -1672,10 +2687,8 @@ Defines the settings for image capture. ...@@ -1672,10 +2687,8 @@ Defines the settings for image capture.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
|----------|---------------|-----------|---------------------| |----------|---------------|-----------|---------------------|
| quality | QualityLevel | Optional | Photo image quality | | quality | QualityLevel | Optional | Photo image quality <br/>System Capabilities: SystemCapability.Multimedia.Camera.Core|
| rotation | ImageRotation | Optional | Photo rotation | | rotation | ImageRotation | Optional | Photo rotation <br/>System Capabilities: SystemCapability.Multimedia.Camera.Core |
| location | Location | Optional | Photo location |
| mirror | boolean | Optional | Mirror mode |
## PhotoOutput ## PhotoOutput
...@@ -1684,6 +2697,12 @@ Implements photo output. ...@@ -1684,6 +2697,12 @@ Implements photo output.
### capture(callback: AsyncCallback<void\>): void; ### capture(callback: AsyncCallback<void\>): void;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Captures a photo. This method uses an asynchronous callback to return the result. Captures a photo. This method uses an asynchronous callback to return the result.
**Parameters** **Parameters**
...@@ -1710,6 +2729,12 @@ photoOutput.capture((err) => { ...@@ -1710,6 +2729,12 @@ photoOutput.capture((err) => {
### capture(setting: PhotoCaptureSetting, callback: AsyncCallback<void\>): void; ### capture(setting: PhotoCaptureSetting, callback: AsyncCallback<void\>): void;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Captures a photo with the specified capture settings. This method uses an asynchronous callback to return the result. Captures a photo with the specified capture settings. This method uses an asynchronous callback to return the result.
**Parameters** **Parameters**
...@@ -1737,6 +2762,12 @@ photoOutput.capture(settings, (err) => { ...@@ -1737,6 +2762,12 @@ photoOutput.capture(settings, (err) => {
### capture(setting?: PhotoCaptureSetting): Promise<void\>; ### capture(setting?: PhotoCaptureSetting): Promise<void\>;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Captures a photo with the specified capture settings. This method uses a promise to return the result. Captures a photo with the specified capture settings. This method uses a promise to return the result.
**Parameters** **Parameters**
...@@ -1762,6 +2793,12 @@ photoOutput.capture().then(() => { ...@@ -1762,6 +2793,12 @@ photoOutput.capture().then(() => {
### release(callback: AsyncCallback<void\>): void; ### release(callback: AsyncCallback<void\>): void;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Releases this **PhotoOutput** instance. This method uses an asynchronous callback to return the result. Releases this **PhotoOutput** instance. This method uses an asynchronous callback to return the result.
**Parameters** **Parameters**
...@@ -1788,6 +2825,12 @@ photoOutput.release((err) => { ...@@ -1788,6 +2825,12 @@ photoOutput.release((err) => {
### release(): Promise<void\>; ### release(): Promise<void\>;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Releases this **PhotoOutput** instance. This method uses a promise to return the result. Releases this **PhotoOutput** instance. This method uses a promise to return the result.
**Parameters** **Parameters**
...@@ -1808,8 +2851,132 @@ photoOutput.release().then(() => { ...@@ -1808,8 +2851,132 @@ photoOutput.release().then(() => {
}) })
``` ```
### on(type: 'captureStart', callback: Callback<number\>): void;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Listens for photo capture start events. This method uses a callback to get the event information.
**Parameters**
| Name | Type | Mandatory | Description |
| :------- | :--------------------- | :-------- | :-----------------------------------------------|
| type | string | Yes | Name of the event to listen for. |
| callback | Callback<number\> | Yes | Callback used to get the capture ID. |
**Return value**
None
**Example**
```
photoOutput.on('captureStart', (captureId) => {
console.log('photo capture stated, captureId : ' + captureId);
})
```
### on(type: 'frameShutter', callback: Callback<FrameShutterInfo\>): void;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Listens for frame shutter events. This method uses a callback to get the event information.
**Parameters**
| Name | Type | Mandatory | Description |
| :------- | :--------------------- | :-------- | :-----------------------------------------------|
| type | string | Yes | Name of the event to listen for. |
| callback | Callback<FrameShutterInfo\> | Yes | Callback used to get the frame shutter information.|
**Return value**
None
**Example**
```
photoOutput.on('frameShutter', (frameShutterInfo) => {
console.log('photo capture end, captureId : ' + frameShutterInfo.captureId);
console.log('Timestamp for frame : ' + frameShutterInfo.timestamp);
})
```
### on(type: 'captureEnd', callback: Callback<CaptureEndInfo\>): void;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Listens for photo capture end events. This method uses a callback to get the event information.
**Parameters**
| Name | Type | Mandatory | Description |
| :------- | :--------------------- | :-------- | :------------------------------------------------|
| type | string | Yes | Name of the event to listen for. |
| callback | Callback<CaptureEndInfo\> | Yes | Callback used to get the capture end information |
**Return value**
None
**Example**
```
photoOutput.on('captureEnd', (captureEndInfo) => {
console.log('photo capture end, captureId : ' + captureEndInfo.captureId);
console.log('frameCount : ' + captureEndInfo.frameCount);
})
```
### on(type: 'error', callback: Callback<PhotoOutputError\>): void;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Listens for **PhotoOutput** errors. This method uses a callback to get errors.
**Parameters**
| Name | Type | Mandatory | Description |
| :------- | :--------------------- | :-------- | :-----------------------------------------------|
| type | string | Yes | Name of the event to listen for. |
| callback | Callback<PhotoOutputError\> | Yes | Callback used to get the photo output errors. |
**Return value**
None
**Example**
```
photoOutput.on('error', (photoOutputError) => {
console.log('Photo output error code: ' + photoOutputError.code);
})
```
## createVideoOutput(surfaceId: string, callback: AsyncCallback<VideoOutput\>): void; ## createVideoOutput(surfaceId: string, callback: AsyncCallback<VideoOutput\>): void;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Creates a **VideoOutput** instance. This method uses an asynchronous callback to return the instance. Creates a **VideoOutput** instance. This method uses an asynchronous callback to return the instance.
**Parameters** **Parameters**
...@@ -1837,6 +3004,12 @@ camera.createVideoOutput(surfaceId), (err, videoOutput) => { ...@@ -1837,6 +3004,12 @@ camera.createVideoOutput(surfaceId), (err, videoOutput) => {
## createVideoOutput(surfaceId: string): Promise<VideoOutput\>; ## createVideoOutput(surfaceId: string): Promise<VideoOutput\>;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Creates a **VideoOutput** instance. This method uses a promise to return the VideoOutput instance. Creates a **VideoOutput** instance. This method uses a promise to return the VideoOutput instance.
**Parameters** **Parameters**
...@@ -1858,9 +3031,18 @@ camera.createVideoOutput(surfaceId).then((videoOutput) => { ...@@ -1858,9 +3031,18 @@ camera.createVideoOutput(surfaceId).then((videoOutput) => {
console.log('Promise returned with the VideoOutput instance'); console.log('Promise returned with the VideoOutput instance');
}) })
``` ```
## VideoOutput
Implements video output.
### start(callback: AsyncCallback<void\>): void; ### start(callback: AsyncCallback<void\>): void;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Starts the video output. This method uses an asynchronous callback to return the result. Starts the video output. This method uses an asynchronous callback to return the result.
**Parameters** **Parameters**
...@@ -1887,6 +3069,12 @@ videoOutput.start((err) => { ...@@ -1887,6 +3069,12 @@ videoOutput.start((err) => {
### start(): Promise<void\>; ### start(): Promise<void\>;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Starts the video output. This method uses a promise to return the result. Starts the video output. This method uses a promise to return the result.
**Parameters** **Parameters**
...@@ -1909,6 +3097,12 @@ videoOutput.start().then(() => { ...@@ -1909,6 +3097,12 @@ videoOutput.start().then(() => {
### stop(callback: AsyncCallback<void\>): void; ### stop(callback: AsyncCallback<void\>): void;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Stops the video output. This method uses an asynchronous callback to return the result. Stops the video output. This method uses an asynchronous callback to return the result.
**Parameters** **Parameters**
...@@ -1935,6 +3129,12 @@ videoOutput.stop((err) => { ...@@ -1935,6 +3129,12 @@ videoOutput.stop((err) => {
### stop(): Promise<void\>; ### stop(): Promise<void\>;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Stops the video output. This method uses a promise to return the result. Stops the video output. This method uses a promise to return the result.
**Parameters** **Parameters**
...@@ -1956,6 +3156,12 @@ videoOutput.start().then(() => { ...@@ -1956,6 +3156,12 @@ videoOutput.start().then(() => {
### release(callback: AsyncCallback<void\>): void; ### release(callback: AsyncCallback<void\>): void;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Releases this VideoOutput instance. This method uses an asynchronous callback to return the result. Releases this VideoOutput instance. This method uses an asynchronous callback to return the result.
**Parameters** **Parameters**
...@@ -1982,6 +3188,12 @@ videoOutput.release((err) => { ...@@ -1982,6 +3188,12 @@ videoOutput.release((err) => {
### release(): Promise<void\>; ### release(): Promise<void\>;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Releases this VideoOutput instance. This method uses a promise to return the result. Releases this VideoOutput instance. This method uses a promise to return the result.
**Parameters** **Parameters**
...@@ -2001,4 +3213,79 @@ none ...@@ -2001,4 +3213,79 @@ none
videoOutput.release().then(() => { videoOutput.release().then(() => {
console.log('Promise returned to indicate that the VideoOutput instance is released successfully.'); console.log('Promise returned to indicate that the VideoOutput instance is released successfully.');
}) })
```
### on(type: 'frameStart', callback: Callback<number\>): void;
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Description**
Listens for video frame start events. This method uses a callback to get the event information.
**Parameters**
| Name | Type | Mandatory | Description |
| :------- | :---------------- | :-------- | :----------------------------------|
| type | string | Yes | Name of the event to listen for. |
| callback | Callback<void\> | Yes | Callback used to return the result |
**Return value**
None
**Example**
```
videoOutput.on('frameStart', () => {
console.log('Video frame started');
})
```
### on(type: 'frameEnd', callback: Callback<number\>): void;
Listens for video frame end events. This method uses a callback to get the event information.
**Parameters**
| Name | Type | Mandatory | Description |
| :------- | :---------------- | :-------- | :----------------------------------|
| type | string | Yes | Name of the event to listen for. |
| callback | Callback<void\> | Yes | Callback used to return the result |
**Return value**
None
**Example**
```
videoOutput.on('frameEnd', () => {
console.log('Video frame ended');
})
```
### on(type: 'error', callback: Callback<VideoOutputError\>): void;
Listens for **VideoOutput** errors. This method uses a callback to get errors.
**Parameters**
| Name | Type | Mandatory | Description |
| :------- | :--------------------- | :-------- | :-----------------------------------------------|
| type | string | Yes | Name of the event to listen for. |
| callback | Callback<VideoOutputError\> | Yes | Callback used to get the video output errors. |
**Return value**
None
**Example**
```
videoOutput.on('error', (VideoOutputError) => {
console.log('Video output error code: ' + VideoOutputError.code);
})
``` ```
\ No newline at end of file
# 相机管理<a name="EN-US_TOPIC_0000001149807881"></a>
## 导入模块
```
import camera from '@ohos.multimedia.camera';
```
## 权限
```
ohos.permission.CAMERA
```
## getCameraManager(context: Context, callback: AsyncCallback<CameraManager\>): void;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
获取**相机管理器**,使用callback方式获取一个异步的实例。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|----------|-------------------------------|-----------|-----------------------------------------------------|
| context | Context | Yes | 应用环境 |
| callback | AsyncCallback<CameraManager\> | Yes | 使用callback方式获取**相机管理器**实例<br/> |
**返回值:**
none
**示例:**
```
camera.getCameraManager(context, (err, cameraManager) => {
if (err) {
console.error('Failed to get the CameraManager instance ${err.message}');
return;
}
console.log('Callback returned with the CameraManager instance');
});
```
## getCameraManager(context: Context): Promise<CameraManager\>;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
获取**相机管理器**,使用promise的方式获取一个实例。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|----------|----------------------|-----------|----------------------------|
| context | Context | Yes | 应用环境 |
**返回值:**
| 类型 | 说明 |
|-------------------------|--------------------------------------------------------|
| Promise<CameraManager\> | 使用Promise的方式获取一个**相机管理器** 实例 |
**示例:**
```
camera.getCameraManager(context).then((cameraManger) => {
console.log('Promise returned with the CameraManager instance.');
})
```
## CameraStatus<a name="section_camera_status"></a>
枚举相机状态类型。
| 名称 | 默认值 | 说明 |
|---------------------------|---------------|--------------------|
| CAMERA_STATUS_APPEAR | 0 | Camera appear<br/>系统能力 : SystemCapability.Multimedia.Camera.Core |
| CAMERA_STATUS_DISAPPEAR | 1 | Camera disappear<br/> 系统能力 : SystemCapability.Multimedia.Camera.Core |
| CAMERA_STATUS_AVAILABLE | 2 | 相机就绪<br/> 系统能力 : SystemCapability.Multimedia.Camera.Core |
| CAMERA_STATUS_UNAVAILABLE | 3 | 相机未就绪<br/> 系统能力 : SystemCapability.Multimedia.Camera.Core |
## CameraPosition<a name="section_camera_position"></a>
枚举相机位置。
| 名称 | 默认值 | 说明 |
|-----------------------------|---------------|-----------------------|
| CAMERA_POSITION_UNSPECIFIED | 0 | 未指定方向相机<br/> 系统能力 : SystemCapability.Multimedia.Camera.Core |
| CAMERA_POSITION_BACK | 1 | 后置相机<br/> 系统能力 : SystemCapability.Multimedia.Camera.Core |
| CAMERA_POSITION_FRONT | 2 | 前置相机<br/> 系统能力 : SystemCapability.Multimedia.Camera.Core |
## CameraType<a name="section_camera_type"></a>
枚举相机类型。
| 名称 | 默认值 | 说明 |
|-------------------------|---------------|-------------------------|
| CAMERA_TYPE_UNSPECIFIED | 0 | 未指定相机类型<br/> 系统能力 : SystemCapability.Multimedia.Camera.Core |
| CAMERA_TYPE_WIDE_ANGLE | 1 | 广角相机<br/> 系统能力 : SystemCapability.Multimedia.Camera.Core |
| CAMERA_TYPE_ULTRA_WIDE | 2 | 超级广角相机<br/> 系统能力 : SystemCapability.Multimedia.Camera.Core |
| CAMERA_TYPE_TELEPHOTO | 3 | 电话相机<br/> 系统能力 : SystemCapability.Multimedia.Camera.Core |
| CAMERA_TYPE_TRUE_DEPTH | 4 | 深度相机<br/> 系统能力 : SystemCapability.Multimedia.Camera.Core |
## ConnectionType<a name="section_ConnectionType"></a>
枚举相机连接类型。
| 名称 | 默认值 | 说明 |
|------------------------------|---------------|----------------------------|
| CAMERA_CONNECTION_BUILT_IN | 0 | 内置相机<br/> 系统能力 : SystemCapability.Multimedia.Camera.Core |
| CAMERA_CONNECTION_USB_PLUGIN | 1 | USB外连相机<br/> 系统能力 : SystemCapability.Multimedia.Camera.Core |
| CAMERA_CONNECTION_REMOTE | 2 | 分布式相机<br/> 系统能力 : SystemCapability.Multimedia.Camera.Core |
## CameraFormat<a name="section_CameraFormat"></a>
枚举相机格式。
| 名称 | 默认值 | 说明 |
|----------------------------|---------------|---------------------|
| CAMERA_FORMAT_YCRCb_420_SP | 1003 | YCRCb格式<br/> 系统能力 : SystemCapability.Multimedia.Camera.Core |
| CAMERA_FORMAT_JPEG | 2000 | JPEG格式<br/> 系统能力 : SystemCapability.Multimedia.Camera.Core |
| CAMERA_FORMAT_AVC | 3000 | AVC 格式<br/> 系统能力 : SystemCapability.Multimedia.Camera.Core |
| CAMERA_FORMAT_HEVC | 3001 | HEVC 格式<br/> 系统能力 : SystemCapability.Multimedia.Camera.Core |
## CameraManager<a name="section_CameraManager"></a>
相机管理器类, 包含获取相机并创建“相机输入”实例。
### getCameras(callback: AsyncCallback<Array<Camera\>\>): void;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
获取设备支持的所有相机,使用callback方式获取异步的支持相机列表。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|----------|--------------------------------|-----------|---------------------------------------------------------|
| callback | AsyncCallback<Array<Camera\>\> | Yes | 使用callback方式获取支持的相机列表 |
**返回值:**
none
**示例:**
```
cameraManager.getCameras((err, cameras) => {
if (err) {
console.error('Failed to get the cameras. ${err.message}');
return;
}
console.log('Callback returned with an array of supported cameras: ' + cameras.length);
})
```
### getCameras(): Promise<Array<Camera\>\>;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
获取设备支持的所有相机,使用promise方式获取支持相机列表。
**参数:**
none
**返回值:**
| 类型 | 说明 |
|------------------------|--------------------------------------------------------|
| Promise<Array<Camera\>\> | 使用promise方获取支持相机列表 |
**示例:**
```
cameraManager.getCameras().then((cameraArray) => {
console.log('Promise returned with an array of supported cameras: ' + cameraArray.length);
})
```
### createCameraInput(cameraId: string, callback: AsyncCallback<CameraInput\>): void;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
使用相机ID创建 **相机输入** 实例,使用callback方式获取一个异步的实例。
**参数:**
| 名称 | 默认值 | 必填 | 说明 |
|----------|------------------------------|-----------|--------------------------------------------------|
| cameraId | string | Yes | 使用 相机ID 来创建一个实例 |
| callback | AsyncCallback<CameraInput\> | Yes | 使用Callback方式来获取一个 CameraInput 实例 |
**返回值:**
none
**示例:**
```
cameraManager.createCameraInput(cameraId, (err, cameraInput) => {
if (err) {
console.error('Failed to create the CameraInput instance. ${err.message}');
return;
}
console.log('Callback returned with the CameraInput instance.');
})
```
### createCameraInput(cameraId: string): Promise<CameraInput\>;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
使用相机ID创建 **相机输入** 实例,使用promise方式获取一个实例。
**参数:**
| 名称 | 默认值 | 必填 | 说明 |
|----------|-----------------------------|-----------|------------------------------------------|
| cameraId | string | Yes | 使用 相机ID 来创建一个实例 |
**返回值:**
| 类型 | 说明 |
|-------------------------|-------------------------------------------------|
| Promise<CameraInput\> | 使用Promise的方式获取一个 CameraInput 的实例 |
**示例:**
```
cameraManager.createCameraInput(cameraId).then((cameraInput) => {
console.log('Promise returned with the CameraInput instance');
})
```
### createCameraInput(position: CameraPosition, type: CameraType, callback: AsyncCallback<CameraInput\>): void;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
使用相机位置和相机类型创建 **相机输入** 实例, 使用callback方式获取一个异步的实例。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|----------------|----------------------------|-----------|---------------------------------------------------|
| cameraPosition | CameraPosition | Yes | 相机位置 |
| cameraType | CameraType | Yes | 相机类型 |
| callback | AsyncCallback<CameraInput\> | Yes | 使用callback方式获取一个异步的实例 |
**返回值:**
none
**实例:**
```
cameraManager.createCameraInput(cameraPosition, cameraType, (err, cameraInput) => {
if (err) {
console.error('Failed to create the CameraInput instance. ${err.message}');
return;
}
console.log('Callback returned with the CameraInput instance');
})
```
### createCameraInput(position: CameraPosition, type: CameraType): Promise<CameraInput\>;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
使用相机位置和相机类型创建 **相机输入** 实例, 使用promise的方式获取一个实例。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|----------------|----------------------------|-----------|----------------------------------------|
| cameraPosition | CameraPosition | Yes | 相机位置 |
| cameraType | CameraType | Yes | 相机类型 |
**返回值:**
| 类型 | 说明 |
|-------------------------|-------------------------------------------------|
| Promise<CameraInput\> | 使用promise的方式获取一个**相机输入**实例 |
**示例:**
```
cameraManager.createCameraInput(cameraPosition, cameraType).then((cameraInput) => {
console.log('Promise returned with the CameraInput instance.');
})
```
### on(type: 'cameraStatus', callback: Callback<CameraStatusInfo\>): void;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
监听相机的状态变化,使用callback的方式获取相机的状态变化
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| :------- | :--------------------- | :-------- | :--------------------------------------------------- |
| type | string | Yes | 监听项的名称 |
| callback | Callback<CameraStatusInfo\> | Yes | 使用callback的方式获取相机状态变化 |
**返回值:**
None
**示例:**
```
cameraManager.on('cameraStatus', (cameraStatusInfo) => {
console.log('camera : ' + cameraStatusInfo.camera.cameraId);
console.log('status: ' + cameraStatusInfo.status);
})
```
## Camera<a name="section_Camera"></a>
**相机**类。
**字段:**
| 名称 | 类型 | 访问权限 | 说明 |
|----------------|----------------|----------|------------------------|
| cameraId | string | readonly | 相机ID<br/> 系统能力 : SystemCapability.Multimedia.Camera.Core |
| cameraPosition | cameraPosition | readonly | 相机位置<br/> 系统能力 : SystemCapability.Multimedia.Camera.Core |
| cameraType | cameraType | readonly | 相机类型<br/> 系统能力 : SystemCapability.Multimedia.Camera.Core |
| connectionType | connectionType | readonly | 相机连接类型<br/> 系统能力 : SystemCapability.Multimedia.Camera.Core |
```
var cameraManager = await camera.getCameraManager();
var cameras = await cameraManager.getCameras();
var cameraObj = cameras[0];
var cameraId = cameraObj.cameraId;
var cameraPosition = cameraObj.cameraPosition;
var cameraType = cameraObj.cameraType;
var cameraId = cameraObj.connectionType;
```
## CameraStatusInfo<a name="section_Camera"></a>
**相机状态信息**类。
**字段:**
| 名称 | 类型 | 说明 |
|----------------|----------------|------------------|
| camera | Camera | 相机类<br/> 系统能力 : SystemCapability.Multimedia.Camera.Core |
| status | CameraStatus | 相机状态<br/> 系统能力 : SystemCapability.Multimedia.Camera.Core |
## CameraInput<a name="section_CameraInput"></a>
**相机输入** 类。
### getCameraId(callback: AsyncCallback<string\>\): void;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
获取该**相机输入** 实例的相机ID, 使用callback的方式获取一个异步的实例。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|----------|------------------------|-----------|---------------------------------------|
| callback | AsyncCallback<string\> | Yes | 使用callback的方式获取 相机ID |
**返回值:**
none
```
cameraInput.getCameraId((err, cameraId) => {
if (err) {
console.error('Failed to get the camera ID. ${err.message}');
return;
}
console.log('Callback returned with the camera ID: ' + cameraId);
})
```
### getCameraId(): Promise<string\>;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
获取该**相机输入** 实例的相机ID, 使用promise的方式获取相机ID。
**参数:**
none
**返回值:**
| 类型 | 说明 |
|------------------------|--------------------------------------|
| Promise<string\> | 使用promise的方式获取相机ID |
**示例:**
```
cameraInput.getCameraId().then((cameraId) => {
console.log('Promise returned with the camera ID:' + cameraId);
})
```
### getSupportedSizes\(format: CameraFormat, callback: AsyncCallback<Array<Size\>\>\): void;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
根据格式查询相机支持的分辨率,使用callback的方式获取一个异步的支持分辨率。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|----------|------------------------------|-----------|---------------------------------------------|
| format | CameraFormat | Yes | 使用CameraFormat来获取支持分辨率 |
| callback | AsyncCallback<Array<Size\>\> | Yes | 使用callback的方式来获取支持分辨率 |
**返回值:**
none
**示例:**
```
cameraInput.getSupportedSizes(format, (err, sizes) => {
if (err) {
console.error('Failed to get the supported sizes. ${err.message}');
return;
}
console.log('Callback returned with the supported sizes:' + sizes);
})
```
### getSupportedSizes\(format: CameraFormat\): Promise<Array<Size\>\>;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
获取CameraFormat的支持分辨率,使用promise的方式获取支持分辨率。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|----------|----------------------------|-----------|-----------------------------------------------|
| format | CameraFormat | Yes | 使用Camera format 获取支持分辨率 |
**返回值:**
| 类型 | 说明 |
|------------------------|---------------------------------------------|
| Promise<Array<Size\>\> | 使用promise的方式获取支持分辨率. |
**示例:**
```
cameraInput.getSupportedSizes(format).then((sizes) => {
console.log('Promise returned with supported sizes: ' + sizes);
})
```
### getSupportedPreviewFormats\(callback: AsyncCallback<Array<CameraFormat\>\>\): void;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
获取预览的支持格式,使用callback的方式获取一个异步的支持格式.
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|----------|--------------------------------------|-----------|---------------------------------------------------|
| callback | AsyncCallback<Array<CameraFormat\>\> | Yes | 使用callback的方式获取支持的预览格式. |
**返回值:**
none
**示例:**
```
cameraInput.getSupportedPreviewFormats((err, previewFormats) => {
if (err) {
console.error('Failed to get the supported preview formats. ${err.message}');
return;
}
console.log('Callback returned with supported preview formats: ' + previewFormats.length);
})
```
### getSupportedPreviewFormats\(\): Promise<Array<CameraFormat\>\>;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
获取预览的 supported formats,使用promise的方式获取supported formats.
**参数:**
none
**返回值:**
| 类型 | 说明 |
|--------------------------------|-------------------------------------------------------|
| Promise<Array<CameraFormat\>\> | 使用promise的方式获取supported preview formats |
**示例:**
```
cameraInput.getSupportedPreviewFormats().then((previewFormats) => {
console.log('Promise returned with supported preview formats.' + previewFormats.length);
})
```
### getSupportedPhotoFormats\(callback: AsyncCallback<Array<CameraFormat\>\>\): void;<a name="section189141826104616"></a>
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
获取 photographing的supported formats,使用callback的方式获取一个异步的supported formats.
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|----------|--------------------------------------|-----------|-------------------------------------------------|
| callback | AsyncCallback<Array<CameraFormat\>\> | Yes | 使用callback的方式获取支持的照片格式 |
**返回值:**
none
**示例:**
```
cameraInput.getSupportedPhotoFormats((err, photoFormats) => {
if (err) {
console.error('Failed to get the supported photo formats. ${err.message}');
return;
}
console.log('Callback returned with supported photo formats');
})
```
### getSupportedPhotoFormats\(\): Promise<Array<CameraFormat\>\>;<a name="section189141826104616"></a>
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
获取 photographing的supported formats,使用promise的方式获取supported formats.
**参数:**
none
**返回值:**
| 类型 | 说明 |
|--------------------------------|---------------------------------------------------|
| Promise<Array<CameraFormat\>\> | 使用promise的方式获取支持的照片格式 |
**示例:**
```
cameraInput.getSupportedPhotoFormats().then((photoFormats) => {
console.log('Promise returned with supported photo formats.' + photoFormats.length);
})
```
### getSupportedVideoFormats\(callback: AsyncCallback<Array<CameraFormat\>\>\): void;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
获取录制视频的supported formats,使用callback的方式获取一个异步的支持的录像格式。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|----------|--------------------------------------|-----------|-------------------------------------------------|
| callback | AsyncCallback<Array<CameraFormat\>\> | Yes | 使用callback的方式获取支持的录像格式 |
**返回值:**
none
**示例:**
```
cameraInput.getSupportedVideoFormats((err, videoFormats) => {
if (err) {
console.error('Failed to get the supported video formats. ${err.message}');
return;
}
console.log('Callback returned with supported video formats : ' + videoFormats.length);
})
```
### getSupportedVideoFormats\(\): Promise<Array<CameraFormat\>\>;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
获取录制视频的supported formats,使用promise的方式获取支持的录像格式。
**参数:**
none
**返回值:**
| 类型 | 说明 |
|--------------------------------|---------------------------------------------------|
| Promise<Array<CameraFormat\>\> | 使用promise的方式获取支持的录像格式 |
**示例:**
```
cameraInput.getSupportedVideoFormats().then((videoFormats) => {
console.log('Promise returned with supported video formats.' + videoFormats.length);
})
```
### hasFlash(callback: AsyncCallback<boolean\>): void; <a name="sec_hasFlash"></a>
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
检查设备是否支持闪光灯,使用callback的方式获取一个异步的结果。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|----------|-------------------------|-----------|----------------------------------------------------|
| callback | AsyncCallback<boolean\> | Yes | 使用callback的方式获取支持闪光灯的状态 |
**返回值:**
none
**示例:**
```
cameraInput.hasFlash((err, status) => {
if (err) {
console.error('Failed to check whether the device has flash light. ${err.message}');
return;
}
console.log('Callback returned with flash light support status: ' + status);
})
```
### hasFlash(): Promise<boolean\>;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
检查设备是否支持闪光灯,使用promise的方式获取结果。
**参数:**
none
**返回值:**
| 类型 | 说明 |
|-----------------------|--------------------------------------------------------|
| Promise<boolean\> | 使用promise的方式获取支持闪光灯的状态。 |
**示例:**
```
cameraInput.hasFlash().then((status) => {
console.log('Promise returned with the flash light support status:' + status);
})
```
### isFlashModeSupported(flashMode: FlashMode, callback: AsyncCallback<boolean\>): void; <a name="sec_isFlashModeSupported"></a>
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
检查设备是否支持闪光灯模式,使用callback的方式获取一个异步的结果。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|-----------|------------------------|-----------|----------------------------------------------------|
| flashMode | <a href="#sec_FlashMode">FlashMode</a> | Yes | 闪光灯模式 |
| callback | AsyncCallback<boolean\> | Yes | 使用callback的方式获取设备支持闪光灯模式 |
**返回值:**
none
**示例:**
```
cameraInput.isFlashModeSupported(flashMode, (err, status) => {
if (err) {
console.error('Failed to check whether the flash mode is supported. ${err.message}');
return;
}
console.log('Callback returned with the flash mode support status: ' + status);
})
```
### isFlashModeSupported(flashMode: FlashMode): Promise<boolean\>;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
检查设备是否支持闪光灯模式,使用promise的方式获取结果。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|-----------|------------------------|-----------|----------------------------------------------------|
| flashMode | <a href="#sec_FlashMode">FlashMode</a> | Yes | 闪光灯模式 |
**返回值:**
| 类型 | 说明 |
|-----------------------|---------------------------------------------------|
| Promise<boolean\> | 使用promise的方式获取支持的闪光灯模式 |
**示例:**
```
cameraInput.isFlashModeSupported(flashMode).then((status) => {
console.log('Promise returned with flash mode support status.' + status);
})
```
### setFlashMode(flashMode: FlashMode, callback: AsyncCallback<void\>): void;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
设置闪光灯模式,使用callback的方式获取一个异步的结果。
说明: 设置闪光灯模式之前, 检查支持的闪光灯 (<a href="#sec_hasFlash">hasFlash</a> method) 以及支持的闪光灯模式 (<a href="#sec_isFlashModeSupported">isFlashModeSupported</a> method);
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|-----------|------------------------|-----------|----------------------------------------------------|
| flashMode | <a href="#sec_FlashMode">FlashMode</a> | Yes | 闪光灯模式 |
| callback | AsyncCallback<void\> | Yes | 使用callback的方式获取结果 |
**返回值:**
none
**示例:**
```
cameraInput.setFlashMode(flashMode, (err) => {
if (err) {
console.error('Failed to set the flash mode ${err.message}');
return;
}
console.log('Callback returned with the successful execution of setFlashMode.');
})
```
### setFlashMode(flashMode: FlashMode): Promise<void\>;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
设置闪光灯模式,使用promise的方式获取结果。
说明: 设置闪光灯模式之前, 检查支持的闪光灯 (<a href="#sec_hasFlash">hasFlash</a> method) 以及支持的闪光灯模式 (<a href="#sec_isFlashModeSupported">isFlashModeSupported</a> method);
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|-----------|------------------------|-----------|----------------------------------------------------|
| flashMode | <a href="#sec_FlashMode">FlashMode</a> | Yes | 闪光灯模式 |
**返回值:**
| 类型 | 说明 |
|-----------------------|-----------------------------------------|
| Promise<void\> | 使用promise的方式获取结果 |
**示例:**
```
cameraInput.setFlashMode(flashMode).then() => {
console.log('Promise returned with the successful execution of setFlashMode.');
})
```
### getFlashMode(callback: AsyncCallback<FlashMode\>): void;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
获取当前闪光灯模式,使用callback的方式获取一个异步的结果。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|-----------|---------------------------|-----------|------------------------------------------------|
| callback | AsyncCallback<FlashMode\> | Yes | 使用callback的方式获取当前闪光灯模式 |
**返回值:**
none
**示例:**
```
cameraInput.getFlashMode((err, flashMode) => {
if (err) {
console.error('Failed to get the flash mode ${err.message}');
return;
}
console.log('Callback returned with current flash mode: ' + flashMode);
})
```
### getFlashMode(): Promise<FlashMode\>;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
获取当前闪光灯模式,使用promise的方式获取结果。
**参数:**
none
**返回值:**
| 类型 | 说明 |
|-----------------------|---------------------------------------------------|
| Promise<FlashMode\> | 使用promise的方式获取当前闪光灯模式 |
**示例:**
```
cameraInput.getFlashMode().then(flashMode) => {
console.log('Promise returned with current flash mode : ' + flashMode);
})
```
### isFocusModeSupported(afMode: FocusMode, callback: AsyncCallback<boolean\>): void; <a name="sec_isFocusModeSupported"></a>
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
检查支持的焦距模式,使用callback的方式获取一个异步的结果。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|-----------|------------------------|-----------|----------------------------------------------------|
| afMode | <a href="#sec_FocusMode">FocusMode</a> | Yes | 焦距模式 |
| callback | AsyncCallback<boolean\> | Yes | 使用callback的方式获取设备支持的焦距模式 |
**返回值:**
none
**示例:**
```
cameraInput.isFocusModeSupported(afMode, (err, status) => {
if (err) {
console.error('Failed to check whether the focus mode is supported. ${err.message}');
return;
}
console.log('Callback returned with the focus mode support status: ' + status);
})
```
### isFocusModeSupported(afMode: FocusMode): Promise<boolean\>;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
检查支持的焦距模式,使用promise的方式获取结果。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|-----------|----------------------------------------|-----------|-------------|
| afMode | <a href="#sec_FocusMode">FocusMode</a> | Yes | 焦距模式 |
**返回值:**
| 类型 | 说明 |
|-----------------------|---------------------------------------------------|
| Promise<boolean\> | 使用promise的方式获取结果 |
**示例:**
```
cameraInput.isFocusModeSupported(afMode).then((status) => {
console.log('Promise returned with focus mode support status.' + status);
})
```
### setFocusMode(afMode: FocusMode, callback: AsyncCallback<void\>): void;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
设置焦距模式,使用callback的方式获取一个异步的结果。
说明:使用设置焦距模式之前,检查设备支持的焦距模式 (<a href="#sec_isFocusModeSupported">isFocusModeSupported</a> method);
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|-----------|------------------------|-----------|------------------------------------|
| afMode | <a href="#sec_FocusMode">FocusMode</a> | Yes | 焦距模式 |
| callback | AsyncCallback<void\> | Yes | 使用callback的方式获取结果 |
**返回值:**
none
**示例:**
```
cameraInput.setFocusMode(afMode, (err) => {
if (err) {
console.error('Failed to set the focus mode ${err.message}');
return;
}
console.log('Callback returned with the successful execution of setFocusMode.');
})
```
### setFocusMode(afMode: FocusMode): Promise<void\>;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
设置焦距模式,使用promise的方式获取结果。
说明:使用设置焦距模式之前,检查设备支持的焦距模式 (<a href="#sec_isFocusModeSupported">isFocusModeSupported</a> method);
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|-----------|-----------------------------------------|-----------|-------------|
| afMode | <a href="#sec_FocusMode">FocusMode</a> | Yes | 焦距模式 |
**返回值:**
| 类型 | 说明 |
|-----------------------|-----------------------------------------|
| Promise<void\> | 使用promise的方式获取结果 |
**示例:**
```
cameraInput.setFocusMode(afMode).then() => {
console.log('Promise returned with the successful execution of setFocusMode.');
})
```
### getFocusMode(callback: AsyncCallback<FocusMode\>): void;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
获取当前的焦距模式,使用callback的方式获取一个异步的结果。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|-----------|---------------------------|-----------|------------------------------------------------|
| callback | AsyncCallback<FocusMode\> | Yes | 使用callback的方式获取结果 |
**返回值:**
none
**示例:**
```
cameraInput.getFocusMode((err, afMode) => {
if (err) {
console.error('Failed to get the focus mode ${err.message}');
return;
}
console.log('Callback returned with current focus mode: ' + afMode);
})
```
### getFocusMode(): Promise<FocusMode\>;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
获取当前的焦距模式,使用promise的方式获取结果。
**参数:**
none
**返回值:**
| 类型 | 说明 |
|-----------------------|---------------------------------------------------|
| Promise<FocusMode\> | 使用promise的方式获取结果 |
**示例:**
```
cameraInput.getFocusMode().then(afMode) => {
console.log('Promise returned with current focus mode : ' + afMode);
})
```
### getZoomRatioRange\(callback: AsyncCallback<Array<number\>\>\): void;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
获取变焦比率的范围,使用callback的方式获取一个异步的结果。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|----------|--------------------------------|-----------|-------------------------------------------------|
| callback | AsyncCallback<Array<number\>\> | Yes | 使用callback的方式获取变焦比率的范围 |
**返回值:**
none
**示例:**
```
cameraInput.getZoomRatioRange(err, zoomRatioRange) => {
if (err) {
console.error('Failed to get the zoom ratio range. ${err.message}');
return;
}
console.log('Callback returned with zoom ratio range: ' + zoomRatioRange.length);
})
```
### getZoomRatioRange\(\): Promise<Array<number\>\>;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
获取变焦比率的范围,使用promise的方式获取结果。
**参数:**
none
**返回值:**
| 类型 | 说明 |
|------------------------|---------------------------------------------|
| Promise<Array<number\>\> | 使用promise的方式获取变焦比率的范围 |
**示例:**
```
cameraInput.getZoomRatioRange().then((zoomRatioRange) => {
console.log('Promise returned with zoom ratio range: ' + zoomRatioRange.length);
})
```
### setZoomRatio(zoomRatio: number, callback: AsyncCallback<void\>): void;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
设置变焦比率,使用callback的方式获取一个异步的结果。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|-----------|------------------------|-----------|------------------------------------|
| zoomRatio | number | Yes | 变焦比率 |
| callback | AsyncCallback<void\> | Yes | 使用callback的方式获取结果 |
**返回值:**
none
**示例:**
```
cameraInput.setZoomRatio(zoomRatio, (err) => {
if (err) {
console.error('Failed to set the zoom ratio value ${err.message}');
return;
}
console.log('Callback returned with the successful execution of setZoomRatio.');
})
```
### setZoomRatio(zoomRatio: number): Promise<void\>;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
设置变焦比率,使用promise的方式获取结果。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|-----------|----------|-----------|-------------|
| zoomRatio | number | Yes | 变焦比率 |
**返回值:**
| 类型 | 说明 |
|-----------------------|-----------------------------------------|
| Promise<void\> | Promise used to return the result |
**示例:**
```
cameraInput.setZoomRatio(zoomRatio).then() => {
console.log('Promise returned with the successful execution of setZoomRatio.');
})
```
### getZoomRatio(callback: AsyncCallback<number\>): void;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
获取当前的变焦比率,使用callback的方式获取一个异步的结果。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|-----------|---------------------------|-----------|------------------------------------------------------|
| callback | AsyncCallback<number\> | Yes | 使用callback的方式获取结果 |
**返回值:**
none
**示例:**
```
cameraInput.getZoomRatio((err, zoomRatio) => {
if (err) {
console.error('Failed to get the zoom ratio ${err.message}');
return;
}
console.log('Callback returned with current zoom ratio: ' + zoomRatio);
})
```
### getZoomRatio(): Promise<number\>;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
Gets current zoom ratio value. This method uses a promise to return the result.
**参数:**
none
**返回值:**
| 类型 | 说明 |
|-----------------------|---------------------------------------------------|
| Promise<number\> | Promise used to return the zoom ratio vaule |
**示例:**
```
cameraInput.getZoomRatio().then(zoomRatio) => {
console.log('Promise returned with current zoom ratio : ' + zoomRatio);
})
```
### release\(callback: AsyncCallback<void\>\): void;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
释放这个 **相机输入** 实例,使用callback的方式获取一个异步的结果。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|----------|----------------------|-----------|------------------------------------|
| callback | AsyncCallback<void\> | Yes | 使用异步的方式获取结果 |
**返回值:**
none
**示例:**
```
camera.release((err) => {
if (err) {
console.error('Failed to release the CameraInput instance ${err.message}');
return;
}
console.log('Callback invoked to indicate that the CameraInput instance is released successfully.');
});
```
### release(): Promise<void\>;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
释放这个 **相机输入** 实例,使用promise的方式获取结果。
**参数:**
none
**返回值:**
| 类型 | 说明 |
|----------------|---------------------------------------------|
| Promise<void\> | 使用promise的方式获取结果 |
**示例:**
```
cameraInput.release().then(() => {
console.log('Promise returned to indicate that the CameraInput instance is released successfully.');
})
```
### on(type: 'focusStateChange', callback: Callback<FocusState\>): void;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
监听焦距的状态变化,使用callback的方式获取焦距的状态变化。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| :------- | :--------------------- | :-------- | :-----------------------------------------------|
| type | string | Yes | 监听项的名称 |
| callback | Callback<FocusState\> | Yes | 使用callback的方式获取结果 |
**返回值:**
None
**示例:**
```
cameraInput.on('focusStateChange', (focusState) => {
console.log('Focus state : ' + focusState);
})
```
### on(type: 'error', callback: Callback<CameraInputError\>): void;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
监听**相机输入**的报错,使用callback的方式获取错误信息。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| :------- | :--------------------- | :-------- | :-----------------------------------------------|
| type | string | Yes | 监听项的名称 |
| callback | Callback<CameraInputError\> | Yes | 使用callback的方式获取**相机输入**的错误信息 |
**返回值:**
None
**示例:**
```
cameraInput.on('error', (cameraInputError) => {
console.log('Camera input error code: ' + cameraInputError.code);
})
```
## FlashMode <a name="sec_FlashMode"></a>
枚举闪光灯模式。
| 名称 | 默认值 | 说明 |
|------------------------|---------------|------------------------|
| FLASH_MODE_CLOSE | 0 | 闪光灯关闭模式<br/> 系统能力 : SystemCapability.Multimedia.Camera.Core |
| FLASH_MODE_OPEN | 1 | 闪光灯开启模式<br/> 系统能力 : SystemCapability.Multimedia.Camera.Core |
| FLASH_MODE_AUTO | 2 | 闪光灯自动模式<br/> 系统能力 : SystemCapability.Multimedia.Camera.Core |
| FLASH_MODE_ALWAYS_OPEN | 3 | 闪光灯常亮模式<br/> 系统能力 : SystemCapability.Multimedia.Camera.Core |
## FocusMode <a name="sec_FocusMode"></a>
枚举焦距模式。
| 名称 | 默认值 | 说明 |
|----------------------------|---------------|----------------------------|
| FOCUS_MODE_MANUAL | 0 | 手动变焦模式<br/> 系统能力 : SystemCapability.Multimedia.Camera.Core |
| FOCUS_MODE_CONTINUOUS_AUTO | 1 | 连续自动变焦模式<br/> 系统能力 : SystemCapability.Multimedia.Camera.Core |
| FOCUS_MODE_AUTO | 2 | 自动变焦模式<br/> 系统能力 : SystemCapability.Multimedia.Camera.Core |
| FOCUS_MODE_LOCKED | 3 | 焦距锁定模式<br/> 系统能力 : SystemCapability.Multimedia.Camera.Core |
## createCaptureSession\(context: Context, callback: AsyncCallback<CaptureSession\>\): void;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
创建 **拍照会话** 实例,使用callback的方式获取一个异步的实例。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|----------|--------------------------------|-----------|-----------------------------------------------------|
| context | Context | Yes | 应用环境 |
| callback | AsyncCallback<CaptureSession\> | Yes | 使用callback的方式获取 **拍照会话** 实例 |
**返回值:**
none
**示例:**
```
camera.createCaptureSession(context), (err, captureSession) => {
if (err) {
console.error('Failed to create the CaptureSession instance. ${err.message}');
return;
}
console.log('Callback returned with the CaptureSession instance.' + captureSession);
});
```
## createCaptureSession(context: Context\): Promise<CaptureSession\>;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
创建 **拍照会话** 实例,使用promise方式获取一个实例。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|----------|-------------------------------|-----------|-----------------------------------------------------|
| context | Context | Yes | 应用环境 |
**返回值:**
| 类型 | 说明 |
|---------------------------|---------------------------------------------------|
| Promise<CaptureSession\> | 使用promise的方式获取**拍照会话**的实例 |
**示例:**
```
camera.createCaptureSession(context).then((captureSession) => {
console.log('Promise returned with the CaptureSession instance');
})
```
## CaptureSession<a name="sec_CaptureSession"></a>
**拍照会话**类。
### beginConfig\(callback: AsyncCallback<void\>\): void;<a name="section84581011418"></a>
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
设置此**拍照会话**实例,使用callback的方式获取一个异步的结果。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|----------|----------------------|-----------|----------------------------------------------|
| callback | AsyncCallback<void\> | Yes | 使用callback的方式获取结果 |
**返回值:**
none
**示例:**
```
captureSession.beginConfig((err) => {
if (err) {
console.error('Failed to start the configuration. ${err.message}');
return;
}
console.log('Callback invoked to indicate the begin config success.');
});
```
### beginConfig\(\): Promise<void\>;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
设置此**拍照会话**实例,使用promise的方式获取结果。
**参数:**
none
**返回值:**
| 类型 | 说明 |
|---------------|---------------------------------------------|
| Promise<void\> | 使用promise的方式获取结果 |
**示例:**
```
captureSession.beginConfig().then(() => {
console.log('Promise returned to indicate the begin config success.');
})
```
### commitConfig\(callback: AsyncCallback<void\>\): void;<a name="section84581011418"></a>
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
提交此**拍照会话**实例的设置,使用callback的方式获取一个异步的结果。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|----------|---------------------|-----------|----------------------------------------------|
| callback | AsyncCallback<void\> | Yes | 使用callback的方式获取一个异步的结果 |
**返回值:**
none
**示例:**
```
captureSession.commitConfig((err) => {
if (err) {
console.error('Failed to commit the configuration. ${err.message}');
return;
}
console.log('Callback invoked to indicate the commit config success.');
});
```
### commitConfig\(\): Promise<void\>;<a name="section189141826104616"></a>
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
提交此**拍照会话**实例的设置,使用promise的方式获取结果。
**参数:**
none
**返回值:**
| 类型 | 说明 |
|---------------|---------------------------------------------|
| Promise<void\> | 使用promise的方式获取结果 |
**示例:**
```
captureSession.commitConfig().then(() => {
console.log('Promise returned to indicate the commit config success.');
})
```
### addInput\(cameraInput: CameraInput, callback: AsyncCallback<void\>\): void;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
为此**拍照会话**实例添加一个**相机输入**,使用callback的方式获取一个异步的结果。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|-------------|----------------------|-----------|---------------------------------------------|
| cameraInput | CameraInput | Yes | 需要添加的**相机输入**实例 |
| callback | AsyncCallback<void\> | Yes | 使用callback的方式获取结果 |
**返回值:**
none
**示例:**
```
captureSession.addInput(cameraInput, (err) => {
if (err) {
console.error('Failed to add the CameraInput instance. ${err.message}');
return;
}
console.log('Callback invoked to indicate that the CameraInput instance is added.');
});
```
### addInput\(cameraInput: CameraInput\): Promise<void\>;<a name="section189141826104616"></a>
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
为此**拍照会话**实例添加一个**相机输入**,使用promise的方式获取结果。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|-------------|---------------------|-----------|-------------------------------|
| cameraInput | CameraInput | Yes | 需要添加的**相机输入**实例 |
**返回值:**
| 类型 | 说明 |
|----------------|------------------------------------|
| Promise<void\> | 使用promise的方式获取结果 |
**示例:**
```
captureSession.addInput(cameraInput).then(() => {
console.log('Promise used to indicate that the CameraInput instance is added.');
})
```
### addOutput\(previewOutput: PreviewOutput, callback: AsyncCallback<void\>\): void;<a name="section84581011418"></a>
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
为此**拍照会话**实例添加一个**预览输出**实例,使用callback的方式获取一个异步的结果。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|---------------|----------------------|-----------|-------------------------------------|
| previewOutput | PreviewOutput | Yes | 需要添加的**预览输出**实例 |
| callback | AsyncCallback<void\> | Yes | 使用callback的方式获取结果 |
**返回值:**
none
**示例:**
```
captureSession.addOutput(previewOutput, (err) => {
if (err) {
console.error('Failed to add the PreviewOutput instance ${err.message}');
return;
}
console.log('Callback invoked to indicate that the PreviewOutput instance is added.');
});
```
### addOutput\(previewOutput: PreviewOutput\): Promise<void\>;<a name="section189141826104616"></a>
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
为此**拍照会话**实例添加一个**预览输出**实例,使用promise的方式获取结果。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|---------------|---------------------|-----------|--------------------------------|
| previewOutput | PreviewOutput | Yes | 需要添加的**预览输出**实例 |
**返回值:**
| 类型 | 说明 |
|----------------|-----------------------------------|
| Promise<void\> | 使用promise的方式获取结果 |
**示例:**
```
captureSession.addOutput(previewOutput).then(() => {
console.log('Promise used to indicate that the PreviewOutput instance is added.');
})
```
### addOutput\(photoOutput: PhotoOutput, callback: AsyncCallback<void\>\): void;<a name="section84581011418"></a>
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
为此**拍照会话**实例添加一个**照片输出**实例, 使用callback的方式获取一个异步的结果。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|---------------|---------------------|-----------|-------------------------------------|
| photoOutput | PhotoOutput | Yes | 需要添加的**照片输出**实例 |
| callback | AsyncCallback<void\> | Yes | 使用callback的方式获取结果 |
**返回值:**
none
**示例:**
```
captureSession.addOutput(photoOutput, (err) => {
if (err) {
console.error('Failed to add the PhotoOutput instance ${err.message}');
return;
}
console.log('Callback invoked to indicate that the PhotoOutput instance is added.');
});
```
### addOutput\(photoOutput: PhotoOutput\): Promise<void\>;<a name="section189141826104616"></a>
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
为此**拍照会话**实例添加一个**照片输出**实例,使用promise的方式获取结果。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|---------------|---------------------|-----------|--------------------------------|
| photoOutput | PhotoOutput | Yes | 需要添加的**照片输出**实例 |
**返回值:**
| 类型 | 说明 |
|---------------|-----------------------------------|
| Promise<void> | 使用promise的方式获取结果 |
**示例:**
```
captureSession.addOutput(photoOutput).then(() => {
console.log('Promise used to indicate that the PhotoOutput instance is added.');
})
```
### addOutput\(videoOutput: VideoOutput, callback: AsyncCallback<void\>\): void;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
为此**拍照会话**实例添加一个**视频输出**实例,使用callback的方式获取一个异步的结果。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|---------------|---------------------|-----------|-------------------------------------|
| videoOutput | VideoOutput | Yes | 需要添加的**视频输出**实例 |
| callback | AsyncCallback<void\> | Yes | 使用callback的方式获取结果 |
**返回值:**
none
**示例:**
```
captureSession.addOutput(videoOutput, (err) => {
if (err) {
console.error('Failed to add the VideoOutput instance ${err.message}');
return;
}
console.log('Callback invoked to indicate that the VideoOutput instance is added.');
});
```
### addOutput\(videoOutput: VideoOutput\): Promise<void\>;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
为此**拍照会话**实例添加一个**视频输出**实例, 使用promise的方式获取结果。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|---------------|---------------------|-----------|--------------------------------|
| videoOutput | VideoOutput | Yes | 需要添加的**视频输出**实例 |
**返回值:**
| 类型 | 说明 |
|----------------|-----------------------------------|
| Promise<void\> | 使用promise的方式获取结果 |
**示例:**
```
captureSession.addOutput(videoOutput).then(() => {
console.log('Promise used to indicate that the VideoOutput instance is added.');
})
```
### removeInput\(cameraInput: CameraInput, callback: AsyncCallback<void\>\): void;<a name="section84581011418"></a>
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
为此**拍照会话**实例移除一个**相机输入**实例,使用callback的方式获取一个异步的结果。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|-------------|----------------------|-----------|------------------------------------|
| cameraInput | CameraInput | Yes | 需要移除的**相机输入**实例 |
| callback | AsyncCallback<void\> | Yes | 使用callback的方式获取结果 |
**返回值:**
none
**示例:**
```
captureSession.removeInput(cameraInput, (err) => {
if (err) {
console.error('Failed to remove the CameraInput instance. ${err.message}');
return;
}
console.log('Callback invoked to indicate that the cameraInput instance is removed.');
});
```
### removeInput\(cameraInput: CameraInput\): Promise<void\>;<a name="section189141826104616"></a>
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
为此**拍照会话**实例移除一个**相机输入**实例,使用promise的方式获取结果。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|-------------|---------------------|-----------|---------------------------------|
| cameraInput | CameraInput | Yes | 需要移除的**相机输入**实例 |
**返回值:**
| 类型 | 说明 |
|----------------|-----------------------------------|
| Promise<void\> | 使用promise的方式获取结果 |
**示例:**
```
captureSession.removeInput(cameraInput).then(() => {
console.log('Promise returned to indicate that the cameraInput instance is removed.');
})
```
### removeOutput\(previewOutput: PreviewOutput, callback: AsyncCallback<void\>\): void;<a name="section84581011418"></a>
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
为此**拍照会话**实例移除一个**预览输出**实例,使用callback的方式获取一个异步的结果。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|---------------|----------------------|-----------|------------------------------------|
| previewOutput | PreviewOutput | Yes | 需要移除的**预览输出**实例 |
| callback | AsyncCallback<void\> | Yes | 使用callback的方式获取结果 |
**返回值:**
none
**示例:**
```
captureSession.removeOutput(previewOutput, (err) => {
if (err) {
console.error('Failed to remove the PreviewOutput instance. ${err.message}');
return;
}
console.log('Callback invoked to indicate that the PreviewOutput instance is removed.');
});
```
### removeOutput(previewOutput: PreviewOutput): Promise<void\>;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
为此**拍照会话**实例移除一个**预览输出**实例,使用promise的方式获取结果。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|---------------|---------------------|-----------|-----------------------------------|
| previewOutput | PreviewOutput | Yes | 需要移除的**预览输出**实例 |
**返回值:**
| 类型 | 说明 |
|---------------|---------------------------------------------|
| Promise<void\> | 使用promise的方式获取结果 |
**示例:**
```
captureSession.removeOutput(previewOutput).then(() => {
console.log('Promise returned to indicate that the PreviewOutput instance is removed.');
})
```
### removeOutput(photoOutput: PhotoOutput, callback: AsyncCallback<void\>): void;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
为此**拍照会话**实例移除一个**照片输出**实例,使用callback的方式获取一个异步的结果。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|---------------|----------------------|-----------|------------------------------------|
| photoOutput | PhotoOutput | Yes | 需要移除的**照片输出**实例 |
| callback | AsyncCallback<void\> | Yes | 使用callback的方式获取结果 |
**返回值:**
none
**示例:**
```
captureSession.removeOutput(photoOutput, (err) => {
if (err) {
console.error('Failed to remove the PhotoOutput instance. ${err.message}');
return;
}
console.log('Callback invoked to indicate that the PhotoOutput instance is removed.');
});
```
### removeOutput(photoOutput: PhotoOutput): Promise<void\>;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
为此**拍照会话**实例移除一个**照片输出**实例,使用promise的方式获取结果。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|---------------|---------------------|-----------|---------------------------------|
| photoOutput | PhotoOutput | Yes | 需要移除的**照片输出**实例 |
**返回值:**
| 类型 | 说明 |
|---------------|------------------------------------|
| Promise<void\> | 使用promise的方式获取结果 |
**示例:**
```
captureSession.removeOutput(photoOutput).then(() => {
console.log('Promise returned to indicate that the PhotoOutput instance is removed.');
})
```
### removeOutput(videoOutput: VideoOutput, callback: AsyncCallback<void\>): void;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
为此**拍照会话**实例移除一个**视频输出**实例,使用callback的方式获取一个异步的结果。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|---------------|----------------------|-----------|------------------------------------|
| videoOutput | VideoOutput | Yes | 需要移除的**视频输出**实例 |
| callback | AsyncCallback<void\> | Yes | 使用callback的方式获取结果 |
**返回值:**
none
**示例:**
```
captureSession.removeOutput(videoOutput, (err) => {
if (err) {
console.error('Failed to remove the VideoOutput instance. ${err.message}');
return;
}
console.log('Callback invoked to indicate that the VideoOutput instance is removed.');
});
```
### removeOutput(videoOutput: VideoOutput): Promise<void\>;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
为此**拍照会话**实例移除一个**视频输出**实例,使用promise的方式获取结果。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|---------------|---------------------|-----------|---------------------------------|
| videoOutput | VideoOutput | Yes | 需要移除的**照片输出**实例 |
**返回值:**
| 类型 | 说明 |
|----------------|---------------------------------------------|
| Promise<void\> | 使用promise的方式获取结果 |
**示例:**
```
captureSession.removeOutput(videoOutput).then(() => {
console.log('Promise returned to indicate that the VideoOutput instance is removed.');
})
```
### start\(callback: AsyncCallback<void\>\): void;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
开启**拍照会话** 实例, 使用callback的方式获取一个异步的结果。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|----------|----------------------|-----------|----------------------------------------------|
| callback | AsyncCallback<void\> | Yes | 使用callback的方式获取结果 |
**返回值:**
none
**示例:**
```
captureSession.start((err) => {
if (err) {
console.error('Failed to start the session ${err.message}');
return;
}
console.log('Callback invoked to indicate the session start success.');
});
```
### start\(\): Promise<void\>;<a name="section189141826104616"></a>
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
开启**拍照会话** 实例,使用promise的方式获取结果。
**参数:**
none
**返回值:**
| 类型 | 说明 |
|----------------|-----------------------------------|
| Promise<void\> | 使用promise的方式获取结果 |
**示例:**
```
captureSession.start().then(() => {
console.log('Promise returned to indicate the session start success.');
})
```
### stop\(callback: AsyncCallback<void\>\): void;<a name="section84581011418"></a>
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
关闭**拍照会话** 实例,使用callback的方式获取一个异步的结果。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|----------|----------------------|-----------|------------------------------------|
| callback | AsyncCallback<void\> | Yes | 使用callback的方式获取结果 |
**返回值:**
none
**示例:**
```
captureSession.stop((err) => {
if (err) {
console.error('Failed to stop the session ${err.message}');
return;
}
console.log('Callback invoked to indicate the session stop success.');
});
```
### stop(): Promise<void\>;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
关闭**拍照会话** 实例,使用promise的方式获取结果。
**参数:**
none
**返回值:**
| 类型 | 说明 |
|----------------|-----------------------------------|
| Promise<void\> | 使用promise的方式获取结果 |
**示例:**
```
captureSession.stop().then(() => {
console.log('Promise returned to indicate the session stop success.');
})
```
### release\(callback: AsyncCallback<void\>\): void;<a name="section84581011418"></a>
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
释放**拍照会话**实例,使用callback的方式获取一个异步的结果。
**参数:**
示例里
| 名称 | 类型 | 必填 | 说明 |
|----------|----------------------|-----------|------------------------------------|
| callback | AsyncCallback<void\> | Yes | 使用callback的方式获取结果 |
**返回值:**
none
**示例:**
```
captureSession.release((err) => {
if (err) {
console.error('Failed to release the CaptureSession instance ${err.message}');
return;
}
console.log('Callback invoked to indicate that the CaptureSession instance is released successfully.');
});
```
### release(): Promise<void\>;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
释放**拍照会话**实例,使用promise的方式获取结果。
**参数:**
none
**返回值:**
| 类型 | 说明 |
|----------------|---------------------------------------------|
| Promise<void\> | 使用promise的方式获取结果 |
**示例:**
```
captureSession.release().then(() => {
console.log('Promise returned to indicate that the CaptureSession instance is released successfully.');
})
```
### on(type: 'error', callback: Callback<CaptureSessionError\>): void;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
监听**拍照会话** 的报错,使用callback的方式获取错误信息。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| :------- | :--------------------- | :-------- | :-----------------------------------------------|
| type | string | Yes | 监听项的名称 |
| callback | Callback<CaptureSessionError\> | Yes | 使用callback的方式获取**拍照会话**的错误信息 |
**返回值:**
None
**示例:**
```
captureSession.on('error', (captureSessionError) => {
console.log('Capture session error code: ' + captureSessionError.code);
})
```
## createPreviewOutput(surfaceId: string, callback: AsyncCallback<PreviewOutput\>): void;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
创建**预览输出**实例,使用callback的方式获取一个异步的实例。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|------------|-------------------------------|-----------|----------------------------------------------------|
| surfaceId | string | Yes | 从XComponent组件获取的Surface ID |
| callback | AsyncCallback<PreviewOutput\> | Yes | 使用callback的方式获取的实例 |
**返回值:**
none
**示例:**
```
camera.createPreviewOutput(surfaceId), (err, previewOutput) => {
if (err) {
console.error('Failed to create the PreviewOutput instance. ${err.message}');
return;
}
console.log('Callback returned with previewOutput instance');
});
```
## createPreviewOutput(surfaceId: string): Promise<PreviewOutput>;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
创建**预览输出**实例, 使用promise方式获取一个实例。.
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|------------|-----------------|-----------|----------------------------------------------------|
| surfaceId | string | Yes | 从XComponent组件获取的Surface ID |
**返回值:**
| 类型 | 说明 |
|-------------------------|---------------------------------------------------|
| Promise<PreviewOutput\> | 使用promise的方式获取结果 |
**示例:**
```
camera.createPreviewOutput(surfaceId).then((previewOutput) => {
console.log('Promise returned with the PreviewOutput instance');
})
```
## PreviewOutput
**预览输出**类。
### release(callback: AsyncCallback<void\>): void;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
释放**预览输出**实例,使用callback的方式获取一个异步的结果。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|----------|----------------------|-----------|----------------------------------------------|
| callback | AsyncCallback<void\> | Yes | 使用callback的方式获取结果 |
**返回值:**
none
**示例:**
```
previewOutput.release((err) => {
if (err) {
console.error('Failed to release the PreviewOutput instance ${err.message}');
return;
}
console.log('Callback invoked to indicate that the PreviewOutput instance is released successfully.');
});
```
### release(): Promise<void\>;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
释放**预览输出**实例,使用promise的方式获取结果。
**参数:**
none
**返回值:**
| 类型 | 说明 |
|----------------|-----------------------------------|
| Promise<void\> | 使用promise的方式获取结果 |
**示例:**
```
previewOutput.release().then(() => {
console.log('Promise returned to indicate that the PreviewOutput instance is released successfully.');
})
```
### on(type: 'frameStart', callback: Callback<number\>): void;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
监听一项预览帧的开启,使用callback的方式获取预览帧开启项。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| :------- | :---------------- | :-------- | :----------------------------------|
| type | string | Yes | 监听项的名称 |
| callback | Callback<void\> | Yes | 使用callback的方式获取结果 |
**返回值:**
None
**示例:**
```
previewOutput.on('frameStart', () => {
console.log('Preview frame started');
})
```
### on(type: 'frameEnd', callback: Callback<number\>): void;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
监听一项预览帧的关闭,使用callback的方式获取预览帧关闭项。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| :------- | :---------------- | :-------- | :----------------------------------|
| type | string | Yes | 监听项的名称 |
| callback | Callback<void\> | Yes | 使用callback的方式获取结果 |
**返回值:**
None
**示例:**
```
previewOutput.on('frameEnd', () => {
console.log('Preview frame ended');
})
```
### on(type: 'error', callback: Callback<PreviewOutputError\>): void;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
监听**预览输出**的报错,使用callback的方式获取错误信息。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| :------- | :--------------------- | :-------- | :-----------------------------------------------|
| type | string | Yes | Name of event to listen for. |
| callback | Callback<PreviewOutputError\> | Yes | 使用callback的方式获取**预览输出**的错误信息 |
**返回值:**
None
**示例:**
```
previewOutput.on('error', (previewOutputError) => {
console.log('Preview output error code: ' + previewOutputError.code);
})
```
## createPhotoOutput(surfaceId: string, callback: AsyncCallback<PhotoOutput\>): void;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
创建**照片输出**实例,使用callback的方式获取一个异步的实例。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|------------|-------------------------------|-----------|----------------------------------------------------|
| surfaceId | string | Yes | 从ImageReceiver获取的Surfack ID |
| callback | AsyncCallback<PhotoOutput\> | Yes | 使用callback的方式获取结果 |
**返回值:**
none
**示例:**
```
camera.createPhotoOutput(surfaceId), (err, photoOutput) => {
if (err) {
console.error('Failed to create the PhotoOutput instance. ${err.message}');
return;
}
console.log('Callback returned with the PhotoOutput instance.');
});
```
## createPhotoOutput(surfaceId: string): Promise<PhotoOutput\>;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
创建**照片输出**实例,使用promise的方式获取实例。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|------------|-----------------|-----------|----------------------------------------------------|
| surfaceId | string | Yes | 从ImageReceiver获取的Surfack ID |
**返回值:**
| 类型 | 说明 |
|-------------------------|--------------------------------------------------|
| Promise<PhotoOutput\> | 使用promise的方式获取结果 |
**示例:**
```
camera.createPhotoOutput(surfaceId).then((photoOutput) => {
console.log('Promise returned with PhotoOutput instance');
})
```
## 图片旋转
枚举图片旋转角度。
| 名称 | 默认值 | 说明 |
|--------------|---------------|----------------------------------------|
| ROTATION_0 | 0 | 图片旋转0度<br/> 系统能力 : SystemCapability.Multimedia.Camera.Core |
| ROTATION_90 | 90 | 图片旋转90度<br/> 系统能力 : SystemCapability.Multimedia.Camera.Core |
| ROTATION_180 | 180 | 图片旋转180度<br/> 系统能力 : SystemCapability.Multimedia.Camera.Core |
| ROTATION_270 | 270 | 图片旋转270度<br/> 系统能力 : SystemCapability.Multimedia.Camera.Core |
## 拍摄地点
拍摄的照片的地点。
| 名称 | 类型 | 权限 | 说明 |
|-----------|--------|--------------|-------------|
| latitude | number | read / write | 纬度<br/> 系统能力 : SystemCapability.Multimedia.Camera.Core |
| longitude | number | read / write | 经度<br/> 系统能力 : SystemCapability.Multimedia.Camera.Core |
## 图片质量
枚举图片质量。
| 名称 | 默认值 | 说明 |
|----------------------|---------------|----------------------|
| QUALITY_LEVEL_HIGH | 0 | 高图片质量<br/> 系统能力 : SystemCapability.Multimedia.Camera.Core |
| QUALITY_LEVEL_MEDIUM | 1 | 中图片质量<br/> 系统能力 : SystemCapability.Multimedia.Camera.Core |
| QUALITY_LEVEL_LOW | 2 | 低图片质量<br/> 系统能力 : SystemCapability.Multimedia.Camera.Core |
## 拍照设置
拍摄的照片的设置。
| 名称 | 类型 | 必填 | 说明 |
|----------|---------------|-----------|---------------------|
| quality | QualityLevel | Optional | 图片质量<br/> 系统能力 : SystemCapability.Multimedia.Camera.Core |
| rotation | ImageRotation | Optional | 图片旋转角度<br/> 系统能力 : SystemCapability.Multimedia.Camera.Core |
## 照片输出
**照片输出**类。
### capture(callback: AsyncCallback<void\>): void;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
拍照,使用callback的方式获取一个异步的结果。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|----------|---------------------|-----------|----------------------------------------------|
| callback | AsyncCallback<void\> | Yes | 使用callback的方式获取结果 |
**返回值:**
none
**示例:**
```
photoOutput.capture((err) => {
if (err) {
console.error('Failed to capture the photo ${err.message}');
return;
}
console.log('Callback invoked to indicate the photo capture request success.');
});
```
### capture(setting: PhotoCaptureSetting, callback: AsyncCallback<void\>): void;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
使用拍照设置拍照, 使用callback的方式获取一个异步的结果。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|----------|----------------------|-----------|----------------------------------------------|
| setting | PhotoCaptureSetting | Yes | 拍照设置 |
| callback | AsyncCallback<void\> | Yes | 使用callback的方式获取结果 |
**返回值:**
none
**示例:**
```
photoOutput.capture(settings, (err) => {
if (err) {
console.error('Failed to capture the photo ${err.message}');
return;
}
console.log('Callback invoked to indicate the photo capture request success.');
});
```
### capture(setting?: PhotoCaptureSetting): Promise<void\>;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
使用拍照设置拍照, 使用promise的方式获取结果。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|----------|---------------------|-----------|----------------------------------------------|
| setting | PhotoCaptureSetting | No | 拍照设置 |
**返回值:**
| 类型 | 说明 |
|----------------|---------------------------------------------|
| Promise<void\> | 使用promise的方式获取结果 |
**示例:**
```
photoOutput.capture().then(() => {
console.log('Promise returned to indicate that photo capture request success.');
})
```
### release(callback: AsyncCallback<void\>): void;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
释放**拍照输出**实例,使用callback的方式获取一个异步的结果。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|----------|----------------------|-----------|----------------------------------------------|
| callback | AsyncCallback<void\> | Yes | 使用callback的方式获取结果 |
**返回值:**
none
**示例:**
```
photoOutput.release((err) => {
if (err) {
console.error('Failed to release the PhotoOutput instance ${err.message}');
return;
}
console.log('Callback invoked to indicate that the PhotoOutput instance is released successfully.');
});
```
### release(): Promise<void\>;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
释放**拍照输出**实例,使用promise的方式获取结果。
**参数:**
none
**返回值:**
| 类型 | 说明 |
|----------------|---------------------------------------------|
| Promise<void\> | 使用promise的方式获取结果 |
**示例:**
```
photoOutput.release().then(() => {
console.log('Promise returned to indicate that the PhotoOutput instance is released successfully.');
})
```
### on(type: 'captureStart', callback: Callback<number\>): void;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
监听拍照项的启动,使用callback的方式获取一个拍照项的启动结果。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| :------- | :--------------------- | :-------- | :-----------------------------------------------|
| type | string | Yes | Name of event to listen for. |
| callback | Callback<number\> | Yes | 使用callback的方式获取captureID |
**返回值:**
None
**示例:**
```
photoOutput.on('captureStart', (captureId) => {
console.log('photo capture stated, captureId : ' + captureId);
})
```
### on(type: 'frameShutter', callback: Callback<FrameShutterInfo\>): void;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
监听一项帧刷新,使用callback的方式获取帧的刷新项。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| :------- | :--------------------- | :-------- | :-----------------------------------------------|
| type | string | Yes | 监听项的名称 |
| callback | Callback<FrameShutterInfo\> | Yes | 使用callback的方式获取结果 |
**返回值:**
None
**示例:**
```
photoOutput.on('frameShutter', (frameShutterInfo) => {
console.log('photo capture end, captureId : ' + frameShutterInfo.captureId);
console.log('Timestamp for frame : ' + frameShutterInfo.timestamp);
})
```
### on(type: 'captureEnd', callback: Callback<CaptureEndInfo\>): void;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
监听拍照项的关闭,使用callback的方式获取一个拍照项的关闭结果。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| :------- | :--------------------- | :-------- | :-----------------------------------------------|
| type | string | Yes | 监听项的名称 |
| callback | Callback<CaptureEndInfo\> | Yes | 使用callback的方式获取拍照结束的信息 |
**返回值:**
None
**示例:**
```
photoOutput.on('captureEnd', (captureEndInfo) => {
console.log('photo capture end, captureId : ' + captureEndInfo.captureId);
console.log('frameCount : ' + captureEndInfo.frameCount);
})
```
### on(type: 'error', callback: Callback<PhotoOutputError\>): void;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
监听**照片输出**的报错,使用callback的方式获取错误信息。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| :------- | :--------------------- | :-------- | :-----------------------------------------------|
| type | string | Yes | Name of event to listen for. |
| callback | Callback<PhotoOutputError\> | Yes | 使用callback的方式获取**照片输出**的错误信息 |
**返回值:**
None
**示例:**
```
photoOutput.on('error', (photoOutputError) => {
console.log('Photo output error code: ' + photoOutputError.code);
})
```
## createVideoOutput(surfaceId: string, callback: AsyncCallback<VideoOutput\>): void;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
创建**视频输出**实例,使用callback的方式获取一个异步的实例。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|------------|-------------------------------|-----------|----------------------------------------------------|
| surfaceId | string | Yes | 从VideoRecorder获取的Surfack ID |
| callback | AsyncCallback<VideoOutput\> | Yes | 用callback的方式获取结果 |
**返回值:**
none
**示例:**
```
camera.createVideoOutput(surfaceId), (err, videoOutput) => {
if (err) {
console.error('Failed to create the VideoOutput instance. ${err.message}');
return;
}
console.log('Callback returned with the VideoOutput instance');
});
```
## createVideoOutput(surfaceId: string): Promise<VideoOutput\>;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
创建**视频输出**实例,使用promise的方式获取结果。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|------------|-----------------|-----------|----------------------------------------------------|
| surfaceId | string | Yes | 从VideoRecorder获取的Surfack ID |
**返回值:**
| 类型 | 说明 |
|-------------------------|-------------------------------------------------|
| Promise<PhotoOutput\> | 使用promise的方式获取结果 |
**示例:**
```
camera.createVideoOutput(surfaceId).then((videoOutput) => {
console.log('Promise returned with the VideoOutput instance');
})
```
## VideoOutput
实现视频输出。
### start(callback: AsyncCallback<void\>): void;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
开启**视频输出**实例, 使用callback的方式获取一个异步的结果。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|----------|----------------------|-----------|----------------------------------------------|
| callback | AsyncCallback<void\> | Yes | 使用callback的方式获取结果 |
**返回值:**
none
**示例:**
```
videoOutput.start((err) => {
if (err) {
console.error('Failed to start the video output ${err.message}');
return;
}
console.log('Callback invoked to indicate the video output start success.');
});
```
### start(): Promise<void\>;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
开启**视频输出**实例, 使用promise的方式获取结果。
**参数:**
none
**返回值:**
| 类型 | 说明 |
|----------------|---------------------------------------------|
| Promise<void\> | 使用promise的方式获取结果 |
**示例:**
```
videoOutput.start().then(() => {
console.log('Promise returned to indicate that start method execution success.');
})
```
### stop(callback: AsyncCallback<void\>): void;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
关闭视频输出,使用callback的方式获取一个异步的结果。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
|----------|----------------------|-----------|----------------------------------------------|
| callback | AsyncCallback<void\> | Yes | 使用callback的方式获取结果 |
**返回值:**
none
**示例:**
```
videoOutput.stop((err) => {
if (err) {
console.error('Failed to stop the video output ${err.message}');
return;
}
console.log('Callback invoked to indicate the video output stop success.');
});
```
### stop(): Promise<void\>;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
关闭视频输出,使用promise的方式获取结果。
**参数:**
none
**返回值:**
| 类型 | 说明 |
|----------------|---------------------------------------------|
| Promise<void\> | 使用promise的方式获取结果 |
**示例:**
```
videoOutput.start().then(() => {
console.log('Promise returned to indicate that stop method execution success.');
})
```
### release(callback: AsyncCallback<void\>): void;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
释放**视频输出**实例, 使用callback的方式获取一个异步的结果。
**参数:**
Camera appear
| 名称 | 类型 | 必填 | 说明 |
|----------|----------------------|-----------|----------------------------------------------|
| callback | AsyncCallback<void\> | Yes | 使用callback的方式获取结果 |
**返回值:**
none
**示例:**
```
videoOutput.release((err) => {
if (err) {
console.error('Failed to release the VideoOutput instance ${err.message}');
return;
}
console.log('Callback invoked to indicate that the VideoOutput instance is released successfully.');
});
```
### release(): Promise<void\>;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
释放**视频输出**实例,使用promise的方式获取结果。
**参数:**
none
**返回值:**
| 类型 | 说明 |
|----------------|---------------------------------------------|
| Promise<void\> | 使用promise的方式获取结果 |
**示例:**
```
videoOutput.release().then(() => {
console.log('Promise returned to indicate that the VideoOutput instance is released successfully.');
})
```
### on(type: 'frameStart', callback: Callback<number\>): void;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
监听一项视频帧的开启,使用callback的方式获取视频帧的开启项。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| :------- | :---------------- | :-------- | :----------------------------------|
| type | string | Yes | 监听项的名称 |
| callback | Callback<void\> | Yes | 使用callback的方式获取结果 |
**返回值:**
None
**示例:**
```
videoOutput.on('frameStart', () => {
console.log('Video frame started');
})
```
### on(type: 'frameEnd', callback: Callback<number\>): void;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
监听一项视频帧的关闭,使用callback的方式获取视频帧的开启项。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| :------- | :---------------- | :-------- | :----------------------------------|
| type | string | Yes | 监听项的名称 |
| callback | Callback<void\> | Yes | 使用callback的方式获取结果 |
**返回值:**
None
**示例:**
```
videoOutput.on('frameEnd', () => {
console.log('Video frame ended');
})
```
### on(type: 'error', callback: Callback<VideoOutputError\>): void;
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**说明:**
监听 **视频输出** 的报错,使用callback的方式获取错误信息。
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| :------- | :--------------------- | :-------- | :-----------------------------------------------|
| type | string | Yes | 监听项的名称 |
| callback | Callback<VideoOutputError\> | Yes | 使用callback的方式获取**视频输出**的错误信息 |
**返回值:**
None
**示例:**
```
videoOutput.on('error', (VideoOutputError) => {
console.log('Video output error code: ' + VideoOutputError.code);
})
```
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册