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

!6173 delete camera apis in 3.1 release

Merge pull request !6173 from zengyawen/OpenHarmony-3.1-Release
......@@ -83,7 +83,6 @@
- Media
- [@ohos.multimedia.audio](js-apis-audio.md)
- [@ohos.multimedia.camera](js-apis-camera.md)
- [@ohos.multimedia.image](js-apis-image.md)
- [@ohos.multimedia.media](js-apis-media.md)
- [@ohos.multimedia.medialibrary](js-apis-medialibrary.md)
......
# Camera Management
> **NOTE**
>
> The initial APIs of this module are supported since API version 9. API version 9 is a canary release for trial use. The APIs of this version may be unstable.
## Modules to Import
```
import camera from '@ohos.multimedia.camera';
```
## Required Permissions
ohos.permission.CAMERA
## camera.getCameraManager
getCameraManager(context: Context, callback: AsyncCallback<CameraManager\>): void
Obtains a **CameraManager** instance. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------------------------------- | ---- | ---------------------------------- |
| context | Context | Yes | Application context. |
| callback | AsyncCallback<[CameraManager](#cameramanager)\> | Yes | Callback used to return the **CameraManager** instance.|
**Example**
```
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');
});
```
## camera.getCameraManager
getCameraManager(context: Context): Promise<CameraManager\>
Obtains a **CameraManager** instance. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ------- | ------- | ---- | ------------ |
| context | Context | Yes | Application context.|
**Return value**
| Type | Description |
| ----------------------------------------- | ----------------------------------------- |
| Promise<[CameraManager](#cameramanager)\> | Promise used to return the **CameraManager** instance.|
**Example**
```
camera.getCameraManager(context).then((cameraManager) => {
console.log('Promise returned with the CameraManager instance.');
})
```
## CameraStatus
Enumerates the camera statuses.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Default Value| Description |
| ------------------------- | ------ | ------------ |
| CAMERA_STATUS_APPEAR | 0 | The camera exists. |
| CAMERA_STATUS_DISAPPEAR | 1 | The camera does not exist.|
| CAMERA_STATUS_AVAILABLE | 2 | The camera is ready. |
| CAMERA_STATUS_UNAVAILABLE | 3 | The camera is not ready.|
## CameraPosition
Enumerates the camera positions.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Default Value| Description |
| --------------------------- | ------ | ---------------- |
| CAMERA_POSITION_UNSPECIFIED | 0 | Unspecified position.|
| CAMERA_POSITION_BACK | 1 | Rear camera. |
| CAMERA_POSITION_FRONT | 2 | Front camera. |
## CameraType
Enumerates the camera types.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Default Value| Description |
| ----------------------- | ------ | ---------------- |
| CAMERA_TYPE_UNSPECIFIED | 0 | Unspecified camera type.|
| CAMERA_TYPE_WIDE_ANGLE | 1 | Wide camera. |
| CAMERA_TYPE_ULTRA_WIDE | 2 | Ultra wide camera. |
| CAMERA_TYPE_TELEPHOTO | 3 | Telephoto camera. |
| CAMERA_TYPE_TRUE_DEPTH | 4 | True depth camera. |
## ConnectionType
Enumerates the camera connection types.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Default Value| Description |
| ---------------------------- | ------ | ------------- |
| CAMERA_CONNECTION_BUILT_IN | 0 | Built-in camera. |
| CAMERA_CONNECTION_USB_PLUGIN | 1 | Camera connected using USB.|
| CAMERA_CONNECTION_REMOTE | 2 | Remote camera. |
## CameraManager
Implements camera management. Before calling any API in **CameraManager**, you must use **getCameraManager** to obtain a **CameraManager** instance.
### getCameras
getCameras(callback: AsyncCallback<Array<Camera\>\>): void
Obtains all cameras supported by the device. This API uses an asynchronous callback to return the array of supported cameras.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------------------------- | ---- | ------------------------------------ |
| callback | AsyncCallback<Array<[Camera](#camera)\>\> | Yes | Callback used to return the array of supported cameras.|
**Example**
```
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
getCameras(): Promise<Array<Camera\>\>
Obtains all cameras supported by the device. This API uses a promise to return the array of supported cameras.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| ----------------------------------- | ----------------------------- |
| Promise<Array<[Camera](#camera)\>\> | Promise used to return the array of supported cameras.|
**Example**
```
cameraManager.getCameras().then((cameraArray) => {
console.log('Promise returned with an array of supported cameras: ' + cameraArray.length);
})
```
### createCameraInput
createCameraInput(cameraId: string, callback: AsyncCallback<CameraInput\>): void
Creates a **CameraInput** instance with the specified camera ID. This API uses an asynchronous callback to return the instance.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Default Value | Mandatory| Description |
| -------- | ------------------------------------------- | ---- | ----------------------------------- |
| cameraId | string | Yes | Camera ID used to create the instance. |
| callback | AsyncCallback<[CameraInput](#camerainput)\> | Yes | Callback used to return the **CameraInput** instance.|
**Example**
```
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
createCameraInput(cameraId: string): Promise<CameraInput\>
Creates a **CameraInput** instance with the specified camera ID. This API uses a promise to return the instance.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Default Value| Mandatory| Description |
| -------- | ------ | ---- | ------------ |
| cameraId | string | Yes | Camera ID used to create the instance.|
**Return value**
| Type | Description |
| ------------------------------------- | ---------------------------------------- |
| Promise<[CameraInput](#camerainput)\> | Promise used to return the **CameraInput** instance.|
**Example**
```
cameraManager.createCameraInput(cameraId).then((cameraInput) => {
console.log('Promise returned with the CameraInput instance');
})
```
### createCameraInput
createCameraInput(position: CameraPosition, type: CameraType, callback: AsyncCallback<CameraInput\>): void
Creates a **CameraInput** instance with the specified camera position and camera type. This API uses an asynchronous callback to return the instance.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------- | ---- | ----------------------------------- |
| position | [CameraPosition](#cameraposition) | Yes | Camera position. |
| type | [CameraType](#cameratype) | Yes | Camera type. |
| callback | AsyncCallback<[CameraInput](#camerainput)\> | Yes | Callback used to return the **CameraInput** instance.|
**Example**
```
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
createCameraInput(position: CameraPosition, type: CameraType): Promise<CameraInput\>
Creates a **CameraInput** instance with the specified camera position and camera type. This API uses a promise to return the instance.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------- | ---- | ---------- |
| position | [CameraPosition](#cameraposition) | Yes | Camera position.|
| type | [CameraType](#cameratype) | Yes | Camera type.|
**Return value**
| Type | Description |
| ------------------------------------- | ---------------------------------------- |
| Promise<[CameraInput](#camerainput)\> | Promise used to return the **CameraInput** instance.|
**Example**
```
cameraManager.createCameraInput(cameraPosition, cameraType).then((cameraInput) => {
console.log('Promise returned with the CameraInput instance.');
})
```
### on('cameraStatus')
on(type: 'cameraStatus', callback: AsyncCallback<CameraStatusInfo\>): void
Listens for camera status changes. This API uses a callback to return the camera status changes.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| :------- | :---------------------------------------------------- | :--- | :--------------------------------------------------- |
| type | string | Yes | Type of event to listen for. The value is fixed at **cameraStatus**, indicating the camera status change event.|
| callback | AsyncCallback<[CameraStatusInfo](#camerastatusinfo)\> | Yes | Callback used to return the camera status change. |
**Example**
```
cameraManager.on('cameraStatus', (cameraStatusInfo) => {
console.log('camera : ' + cameraStatusInfo.camera.cameraId);
console.log('status: ' + cameraStatusInfo.status);
})
```
## Camera
After **[camera.getCameraManager](#cameragetcameramanager)** is called, a camera instance is returned, including camera-related metadata such as **cameraId**, **cameraPosition**, **cameraType**, and **connectionType**.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Type | Read only| Description |
| -------------- | --------------------------------- | ---- | -------------- |
| cameraId | string | Yes | Camera ID. |
| cameraPosition | [CameraPosition](#cameraposition) | Yes | Camera position. |
| cameraType | [CameraType](#cameratype) | Yes | Camera type. |
| connectionType | [ConnectionType](#connectiontype) | Yes | Camera connection type.|
**Example**
```
async function getCameraInfo() {
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
Describes the camera status information.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Type | Description |
| ------ | ----------------------------- | ---------- |
| camera | [Camera](#camera) | Camera object. |
| status | [CameraStatus](#camerastatus) | Camera status. |
## CameraInput
Implements a **CameraInput** instance. Before calling any API in **CameraInput**, you must create a **CameraInput** instance.
### getCameraId
getCameraId(callback: AsyncCallback<string\>\): void
Obtains the camera ID based on which this **CameraInput** instance is created. This API uses an asynchronous callback to return the camera ID.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------- | ---- | -------------------------- |
| callback | AsyncCallback<string\> | Yes | Callback used to return the camera ID. |
**Example**
```
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
getCameraId(): Promise<string\>
Obtains the camera ID based on which this **CameraInput** instance is created. This API uses a promise to return the camera ID.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| ---------------- | ----------------------------- |
| Promise<string\> | Promise used to return the camera ID.|
**Example**
```
cameraInput.getCameraId().then((cameraId) => {
console.log('Promise returned with the camera ID:' + cameraId);
})
```
### hasFlash
hasFlash(callback: AsyncCallback<boolean\>): void
Checks whether the device has flash light. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | -------------------------------------- |
| callback | AsyncCallback<boolean\> | Yes | Callback used to return the flash light support status. The value **true** means that the device has flash light.|
**Example**
```
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
hasFlash(): Promise<boolean\>
Checks whether the device has flash light. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| ----------------- | ------------------------------------------------------- |
| Promise<boolean\> | Promise used to return the flash light support status. The value **true** means that the device has flash light.|
**Example**
```
cameraInput.hasFlash().then((status) => {
console.log('Promise returned with the flash light support status:' + status);
})
```
### isFlashModeSupported
isFlashModeSupported(flashMode: FlashMode, callback: AsyncCallback<boolean\>): void
Checks whether a specified flash mode is supported. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ----------------------- | ---- | ---------------------------------------- |
| flashMode | [FlashMode](#flashmode) | Yes | Flash mode. |
| callback | AsyncCallback<boolean\> | Yes | Callback used to return the flash mode support status. The value **true** means that the specified flash mode is supported.|
**Example**
```
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
isFlashModeSupported(flashMode: FlashMode): Promise<boolean\>
Checks whether a specified flash mode is supported. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ----------------------- | ---- | ---------------- |
| flashMode | [FlashMode](#flashmode) | Yes | Flash mode.|
**Return value**
| Type | Description |
| ----------------- | ------------------------------------------------------------ |
| Promise<boolean\> | Promise used to return the flash mode support status. The value **true** means that the specified flash mode is supported.|
**Example**
```
cameraInput.isFlashModeSupported(flashMode).then((status) => {
console.log('Promise returned with flash mode support status.' + status);
})
```
### setFlashMode
setFlashMode(flashMode: FlashMode, callback: AsyncCallback<void\>): void
Sets the flash mode. This API uses an asynchronous callback to return the result.
Before setting the parameters, do the following checks:
1. Use [hasFlash](#hasflash) to check whether the device has flash light.
2. Use [isFlashModeSupported](#isflashmodesupported) to check whether the device supports a specified flash mode.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ----------------------- | ---- | ------------------------ |
| flashMode | [FlashMode](#flashmode) | Yes | Flash mode. |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example**
```
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
setFlashMode(flashMode: FlashMode): Promise<void\>
Sets the flash mode. This API uses a promise to return the result.
Before setting the parameters, do the following checks:
1. Use [hasFlash](#hasflash) to check whether the device has flash light.
2. Use [isFlashModeSupported](#isflashmodesupported) to check whether the device supports a specified flash mode.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ----------------------- | ---- | ---------------- |
| flashMode | [FlashMode](#flashmode) | Yes | Flash mode.|
**Return value**
| Type | Description |
| -------------- | --------------------------- |
| Promise<void\> | Promise used to return the result.|
**Example**
```
cameraInput.setFlashMode(flashMode).then(() => {
console.log('Promise returned with the successful execution of setFlashMode.');
})
```
### getFlashMode
getFlashMode(callback: AsyncCallback<FlashMode\>): void
Obtains the current flash mode. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------------------------------------- |
| callback | AsyncCallback<[FlashMode](#flashmode)\> | Yes | Callback used to return the current flash mode.|
**Example**
```
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
getFlashMode(): Promise<FlashMode\>
Obtains the current flash mode. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| --------------------------------- | --------------------------------------- |
| Promise<[FlashMode](#flashmode)\> | Promise used to return the current flash mode.|
**Example**
```
cameraInput.getFlashMode().then((flashMode) => {
console.log('Promise returned with current flash mode : ' + flashMode);
})
```
### isFocusModeSupported
isFocusModeSupported(afMode: FocusMode, callback: AsyncCallback<boolean\>): void
Checks whether a specified focus mode is supported. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | -------------------------------------- |
| afMode | [FocusMode](#focusmode) | Yes | Focus mode. |
| callback | AsyncCallback<boolean\> | Yes | Callback used to return the focus mode support status. The value **true** means that the specified focus mode is supported.|
**Example**
```
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
isFocusModeSupported(afMode: FocusMode): Promise<boolean\>
Checks whether a specified focus mode is supported. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ------ | ----------------------- | ---- | ---------------- |
| afMode | [FocusMode](#focusmode) | Yes | Focus mode.|
**Return value**
| Type | Description |
| ----------------- | ----------------------------------------------------------- |
| Promise<boolean\> | Promise used to return the flash mode support status. The value **true** means that the specified focus mode is supported.|
**Example**
```
cameraInput.isFocusModeSupported(afMode).then((status) => {
console.log('Promise returned with focus mode support status.' + status);
})
```
### setFocusMode
setFocusMode(afMode: FocusMode, callback: AsyncCallback<void\>): void
Sets the focus mode. This API uses an asynchronous callback to return the result.
Before setting the focus mode, use **[isFocusModeSupported](#isfocusmodesupported)** to check whether the focus mode is supported.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | ------------------------ |
| afMode | [FocusMode](#focusmode) | Yes | Focus mode. |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example**
```
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
setFocusMode(afMode: FocusMode): Promise<void\>
Sets the focus mode. This API uses a promise to return the result.
Before setting the focus mode, use **[isFocusModeSupported](#isfocusmodesupported)** to check whether the focus mode is supported.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ------ | ----------------------- | ---- | ---------------- |
| afMode | [FocusMode](#focusmode) | Yes | Focus mode.|
**Return value**
| Type | Description |
| -------------- | --------------------------- |
| Promise<void\> | Promise used to return the result.|
**Example**
```
cameraInput.setFocusMode(afMode).then(() => {
console.log('Promise returned with the successful execution of setFocusMode.');
})
```
### getFocusMode
getFocusMode(callback: AsyncCallback<FocusMode\>): void
Obtains the current focus mode. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | -------------------------------------- |
| callback | AsyncCallback<[FocusMode](#focusmode)\> | Yes | Callback used to return the current focus mode.|
**Example**
```
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
getFocusMode(): Promise<FocusMode\>
Obtains the current focus mode. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| ------------------- | ------------------------------------- |
| Promise<FocusMode\> | Promise used to return the current focus mode.|
**Example**
```
cameraInput.getFocusMode().then((afMode) => {
console.log('Promise returned with current focus mode : ' + afMode);
})
```
### getZoomRatioRange
getZoomRatioRange\(callback: AsyncCallback<Array<number\>\>\): void
Obtains the zoom ratio range. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------ | ---- | ------------------------ |
| callback | AsyncCallback<Array<number\>\> | Yes | Callback used to return the zoom ratio range.|
**Example**
```
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
getZoomRatioRange\(\): Promise<Array<number\>\>
Obtains the zoom ratio range. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| ------------------------ | ------------------------------------------- |
| Promise<Array<number\>\> | Promise used to return the zoom ratio range.|
**Example**
```
cameraInput.getZoomRatioRange().then((zoomRatioRange) => {
console.log('Promise returned with zoom ratio range: ' + zoomRatioRange.length);
})
```
### setZoomRatio
setZoomRatio(zoomRatio: number, callback: AsyncCallback<void\>): void
Sets a zoom ratio. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | -------------------- | ---- | ------------------------ |
| zoomRatio | number | Yes | Zoom ratio to set. |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example**
```
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
setZoomRatio(zoomRatio: number): Promise<void\>
Sets a zoom ratio. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ------ | ---- | ------------ |
| zoomRatio | number | Yes | Zoom ratio to set.|
**Return value**
| Type | Description |
| -------------- | --------------------------- |
| Promise<void\> | Promise used to return the result.|
**Example**
```
cameraInput.setZoomRatio(zoomRatio).then(() => {
console.log('Promise returned with the successful execution of setZoomRatio.');
})
```
### getZoomRatio
getZoomRatio(callback: AsyncCallback<number\>): void
Obtains the current zoom ratio. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | ------------------------ |
| callback | AsyncCallback<number\> | Yes | Callback used to return the current zoom ratio.|
**Example**
```
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
getZoomRatio(): Promise<number\>
Obtains the current zoom ratio. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| ---------------- | --------------------------- |
| Promise<number\> | Promise used to return the current zoom ratio.|
**Example**
```
cameraInput.getZoomRatio().then((zoomRatio) => {
console.log('Promise returned with current zoom ratio : ' + zoomRatio);
})
```
### release
release\(callback: AsyncCallback<void\>\): void
Releases this **CameraInput** instance. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example**
```
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
release(): Promise<void\>
Releases this **CameraInput** instance. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| 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('focusStateChange')
on(type: 'focusStateChange', callback: AsyncCallback<FocusState\>): void
Listens for focus state changes. This API uses a callback to return the focus state changes.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| :------- | :---------------------------------------- | :--- | :------------------------------------------------------- |
| type | string | Yes | Type of event to listen for. The value is fixed at **focusStateChange**, indicating the focus state change event.|
| callback | AsyncCallback<[FocusState](#focusstate)\> | Yes | Callback used to return the focus state change. |
**Example**
```
cameraInput.on('focusStateChange', (focusState) => {
console.log('Focus state : ' + focusState);
})
```
### on('error')
on(type: 'error', callback: ErrorCallback<CameraInputError\>): void
Listens for **CameraInput** errors. This API uses a callback to return the errors.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| :------- | :------------------------------- | :--- | :---------------------------------------------- |
| type | string | Yes | Type of event to listen for. The value is fixed at **error**, indicating the camera input error event.|
| callback | ErrorCallback<CameraInputError\> | Yes | Callback used to return the result. |
**Example**
```
cameraInput.on('error', (cameraInputError) => {
console.log('Camera input error code: ' + cameraInputError.code);
})
```
## FlashMode
Enumerates the flash modes.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Default Value| Description |
| ---------------------- | ------ | ------------ |
| FLASH_MODE_CLOSE | 0 | The flash is off.|
| FLASH_MODE_OPEN | 1 | The flash is on.|
| FLASH_MODE_AUTO | 2 | The flash mode is auto, indicating that the flash fires automatically depending on the shooting conditions.|
| FLASH_MODE_ALWAYS_OPEN | 3 | The flash is steady on.|
## FocusMode
Enumerates the focus modes.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Default Value| Description |
| -------------------------- | ------ | ------------------ |
| FOCUS_MODE_MANUAL | 0 | Manual focus. |
| FOCUS_MODE_CONTINUOUS_AUTO | 1 | Continuous auto focus.|
| FOCUS_MODE_AUTO | 2 | Auto focus. |
| FOCUS_MODE_LOCKED | 3 | Locked focus. |
## FocusState
Enumerates the focus states.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Default Value| Description |
| --------------------- | ------ | ------------ |
| FOCUS_STATE_SCAN | 0 | Scanning. |
| FOCUS_STATE_FOCUSED | 1 | Focused.|
| FOCUS_STATE_UNFOCUSED | 2 | Unfocused.|
## camera.createCaptureSession
createCaptureSession\(context: Context, callback: AsyncCallback<CaptureSession\>\): void
Creates a **CaptureSession** instance. This API uses an asynchronous callback to return the instance.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------- | ---- | -------------------------------------- |
| context | Context | Yes | Application context. |
| callback | AsyncCallback<[CaptureSession](#capturesession)\> | Yes | Callback used to return the **CaptureSession** instance.|
**Example**
```
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);
});
```
## camera.createCaptureSession
createCaptureSession(context: Context\): Promise<CaptureSession\>;
Creates a **CaptureSession** instance. This API uses a promise to return the instance.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ------- | ------- | ---- | ------------ |
| context | Context | Yes | Application context.|
**Return value**
| Type | Description |
| ------------------------------------------- | ----------------------------------------- |
| Promise<[CaptureSession](#capturesession)\> | Promise used to return the **CaptureSession** instance.|
**Example**
```
camera.createCaptureSession(context).then((captureSession) => {
console.log('Promise returned with the CaptureSession instance');
})
```
## CaptureSession
Implements session capture.
### beginConfig
beginConfig\(callback: AsyncCallback<void\>\): void
Starts configuration for this **CaptureSession** instance. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**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
beginConfig\(\): Promise<void\>
Starts configuration for this **CaptureSession** instance. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| 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
commitConfig\(callback: AsyncCallback<void\>\): void
Commits the configuration for this **CaptureSession** instance. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**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
commitConfig\(\): Promise<void\>
Commits the configuration for this **CaptureSession** instance. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| 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
addInput\(cameraInput: CameraInput, callback: AsyncCallback<void\>\): void
Adds a **CameraInput** instance to this **CaptureSession** instance. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | --------------------------- | ---- | --------------------------- |
| cameraInput | [CameraInput](#camerainput) | Yes | **CameraInput** instance to add.|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
**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
addInput\(cameraInput: CameraInput\): Promise<void\>
Adds a **CameraInput** instance to this **CaptureSession** instance. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | --------------------------- | ---- | --------------------------- |
| cameraInput | [CameraInput](#camerainput) | Yes | **CameraInput** instance to add.|
**Return value**
| 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
addOutput\(previewOutput: PreviewOutput, callback: AsyncCallback<void\>\): void
Adds a **PreviewOutput** instance to this **CaptureSession** instance. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ------------- | ------------------------------- | ---- | ----------------------------- |
| previewOutput | [PreviewOutput](#previewoutput) | Yes | **PreviewOutput** instance to add.|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
**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
addOutput\(previewOutput: PreviewOutput\): Promise<void\>
Adds a **PreviewOutput** instance to this **CaptureSession** instance. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ------------- | ------------------------------- | ---- | ----------------------------- |
| previewOutput | [PreviewOutput](#previewoutput) | Yes | **PreviewOutput** instance to add.|
**Return value**
| 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
addOutput\(photoOutput: PhotoOutput, callback: AsyncCallback<void\>\): void
Adds a **PhotoOutput** instance to this **CaptureSession** instance. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | --------------------------- | ---- | --------------------------- |
| photoOutput | [PhotoOutput](#photooutput) | Yes | **PhotoOutput** instance to add.|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
**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
addOutput\(photoOutput: PhotoOutput\): Promise<void\>
Adds a **PhotoOutput** instance to this **CaptureSession** instance. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | --------------------------- | ---- | --------------------------- |
| photoOutput | [PhotoOutput](#photooutput) | Yes | **PhotoOutput** instance to add.|
**Return value**
| Type | Description |
| -------------- | --------------------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```
captureSession.addOutput(photoOutput).then(() => {
console.log('Promise used to indicate that the PhotoOutput instance is added.');
})
```
### addOutput
addOutput\(videoOutput: VideoOutput, callback: AsyncCallback<void\>\): void
Adds a **VideoOutput** instance to this **CaptureSession** instance. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | --------------------------- | ---- | --------------------------- |
| videoOutput | [VideoOutput](#videooutput) | Yes | **VideoOutput** instance to add.|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
**Example**
```
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
addOutput\(videoOutput: VideoOutput\): Promise<void\>
Adds a **VideoOutput** instance to this **CaptureSession** instance. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | --------------------------- | ---- | --------------------------- |
| videoOutput | [VideoOutput](#videooutput) | Yes | **VideoOutput** instance to add.|
**Return value**
| Type | Description |
| -------------- | --------------------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```
captureSession.addOutput(videoOutput).then(() => {
console.log('Promise used to indicate that the VideoOutput instance is added.');
})
```
### removeInput
removeInput\(cameraInput: CameraInput, callback: AsyncCallback<void\>\): void
Removes a **CameraInput** instance from this **CaptureSession** instance. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | --------------------------- | ---- | --------------------------- |
| cameraInput | [CameraInput](#camerainput) | Yes | **CameraInput** instance to remove.|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
**Example**
```
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
removeInput\(cameraInput: CameraInput\): Promise<void\>
Removes a **CameraInput** instance from this **CaptureSession** instance. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | --------------------------- | ---- | --------------------------- |
| cameraInput | [CameraInput](#camerainput) | Yes | **CameraInput** instance to remove.|
**Return value**
| Type | Description |
| -------------- | --------------------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```
captureSession.removeInput(cameraInput).then(() => {
console.log('Promise returned to indicate that the cameraInput instance is removed.');
})
```
### removeOutput
removeOutput\(previewOutput: PreviewOutput, callback: AsyncCallback<void\>\): void
Removes a **PreviewOutput** instance from this **CaptureSession** instance. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ------------- | ------------------------------- | ---- | ----------------------------- |
| previewOutput | [PreviewOutput](#previewoutput) | Yes | **PreviewOutput** instance to remove.|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
**Example**
```
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
removeOutput(previewOutput: PreviewOutput): Promise<void\>
Removes a **PreviewOutput** instance from this **CaptureSession** instance. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ------------- | ------------------------------- | ---- | ----------------------------- |
| previewOutput | [PreviewOutput](#previewoutput) | Yes | **PreviewOutput** instance to remove.|
**Return value**
| Type | Description |
| -------------- | --------------------------- |
| Promise<void\> | Promise used to return the result.|
**Example**
```
captureSession.removeOutput(previewOutput).then(() => {
console.log('Promise returned to indicate that the PreviewOutput instance is removed.');
})
```
### removeOutput
removeOutput(photoOutput: PhotoOutput, callback: AsyncCallback<void\>): void
Removes a **PhotoOutput** instance from this **CaptureSession** instance. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | --------------------------- | ---- | --------------------------- |
| photoOutput | [PhotoOutput](#photooutput) | Yes | **PhotoOutput** instance to remove.|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
**Example**
```
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
removeOutput(photoOutput: PhotoOutput): Promise<void\>
Removes a **PhotoOutput** instance from this **CaptureSession** instance. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | --------------------------- | ---- | --------------------------- |
| photoOutput | [PhotoOutput](#photooutput) | Yes | **PhotoOutput** instance to remove.|
**Return value**
| Type | Description |
| -------------- | --------------------------- |
| Promise<void\> | Promise used to return the result.|
**Example**
```
captureSession.removeOutput(photoOutput).then(() => {
console.log('Promise returned to indicate that the PhotoOutput instance is removed.');
})
```
### removeOutput
removeOutput(videoOutput: VideoOutput, callback: AsyncCallback<void\>): void
Removes a **VideoOutput** instance from this **CaptureSession** instance. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | --------------------------- | ---- | --------------------------- |
| videoOutput | [VideoOutput](#videooutput) | Yes | **VideoOutput** instance to remove.|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
**Example**
```
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
removeOutput(videoOutput: VideoOutput): Promise<void\>
Removes a **VideoOutput** instance from this **CaptureSession** instance. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | --------------------------- | ---- | --------------------------- |
| videoOutput | [VideoOutput](#videooutput) | Yes | **VideoOutput** instance to remove.|
**Return value**
| Type | Description |
| -------------- | --------------------------- |
| Promise<void\> | Promise used to return the result.|
**Example**
```
captureSession.removeOutput(videoOutput).then(() => {
console.log('Promise returned to indicate that the VideoOutput instance is removed.');
})
```
### start
start\(callback: AsyncCallback<void\>\): void
Starts this **CaptureSession** instance. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example**
```
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
start\(\): Promise<void\>
Starts this **CaptureSession** instance. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| -------------- | --------------------------- |
| Promise<void\> | Promise used to return the result.|
**Example**
```
captureSession.start().then(() => {
console.log('Promise returned to indicate the session start success.');
})
```
### stop
stop\(callback: AsyncCallback<void\>\): void
Stops this **CaptureSession** instance. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example**
```
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
stop(): Promise<void\>
Stops this **CaptureSession** instance. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| -------------- | --------------------------- |
| Promise<void\> | Promise used to return the result.|
**Example**
```
captureSession.stop().then(() => {
console.log('Promise returned to indicate the session stop success.');
})
```
### release
release\(callback: AsyncCallback<void\>\): void
Releases this **CaptureSession** instance. This API uses an asynchronous callback to return the instance.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example**
```
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
release(): Promise<void\>
Releases this **CaptureSession** instance. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| -------------- | --------------------------- |
| Promise<void\> | Promise used to return the result.|
**Example**
```
captureSession.release().then(() => {
console.log('Promise returned to indicate that the CaptureSession instance is released successfully.');
})
```
### on('error')
on(type: 'error', callback: ErrorCallback<CaptureSessionError\>): void
Listens for **CaptureSession** errors. This API uses a callback to return the errors.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| :------- | :---------------------------------- | :--- | :-------------------------------------------- |
| type | string | Yes | Type of event to listen for. The value is fixed at **error**, indicating the capture session error event.|
| callback | ErrorCallback<CaptureSessionError\> | Yes | Callback used to return the capture session errors. |
**Example**
```
captureSession.on('error', (captureSessionError) => {
console.log('Capture session error code: ' + captureSessionError.code);
})
```
## camera.createPreviewOutput
createPreviewOutput(surfaceId: string, callback: AsyncCallback<PreviewOutput\>): void
Creates a **PreviewOutput** instance. This API uses an asynchronous callback to return the instance.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ----------------------------------------------- | ---- | ------------------------------------- |
| surfaceId | string | Yes | Surface ID received from **XComponent**. |
| callback | AsyncCallback<[PreviewOutput](#previewoutput)\> | Yes | Callback used to return the **PreviewOutput** instance.|
**Example**
```
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');
});
```
## camera.createPreviewOutput
createPreviewOutput(surfaceId: string): Promise\<PreviewOutput>
Creates a **PreviewOutput** instance. This API uses a promise to return the instance.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ------ | ---- | ---------------------------------- |
| surfaceId | string | Yes | Surface ID received from **XComponent**.|
**Return value**
| Type | Description |
| ----------------------------------------- | --------------------------- |
| Promise<[PreviewOutput](#previewoutput)\> | Promise used to return the **PreviewOutput** instance.|
**Example**
```
camera.createPreviewOutput(surfaceId).then((previewOutput) => {
console.log('Promise returned with the PreviewOutput instance');
})
```
## PreviewOutput
Implements preview output.
### release
release(callback: AsyncCallback<void\>): void
Releases this **PreviewOutput** instance. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example**
```
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
release(): Promise<void\>
Releases this **PreviewOutput** instance. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| -------------- | --------------------------- |
| Promise<void\> | Promise used to return the result.|
**Example**
```
previewOutput.release().then(() => {
console.log('Promise returned to indicate that the PreviewOutput instance is released successfully.');
})
```
### on('frameStart')
on(type: 'frameStart', callback: AsyncCallback<void\>): void
Listens for preview frame start events. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| :------- | :------------------- | :--- | :------------------------------------------- |
| type | string | Yes | Type of event to listen for. The value is fixed at **frameStart**, indicating the preview frame start event.|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
**Example**
```
previewOutput.on('frameStart', () => {
console.log('Preview frame started');
})
```
### on('frameEnd')
on(type: 'frameEnd', callback: AsyncCallback<void\>): void
Listens for preview frame end events. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| :------- | :------------------- | :--- | :----------------------------------------- |
| type | string | Yes | Type of event to listen for. The value is fixed at **frameEnd**, indicating the preview frame end event.|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
**Example**
```
previewOutput.on('frameEnd', () => {
console.log('Preview frame ended');
})
```
### on('error')
on(type: 'error', callback: ErrorCallback<PreviewOutputError\>): void
Listens for **PreviewOutput** errors. This API uses a callback to return the errors.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| :------- | :--------------------------------- | :--- | :-------------------------------------------- |
| type | string | Yes | Type of event to listen for. The value is fixed at **error**, indicating the preview output error event.|
| callback | ErrorCallback<PreviewOutputError\> | Yes | Callback used to return the preview output errors. |
**Example**
```
previewOutput.on('error', (previewOutputError) => {
console.log('Preview output error code: ' + previewOutputError.code);
})
```
## camera.createPhotoOutput
createPhotoOutput(surfaceId: string, callback: AsyncCallback<PhotoOutput\>): void
Creates a **PhotoOutput** instance. This API uses an asynchronous callback to return the instance.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ------------------------------------------- | ---- | ----------------------------------- |
| surfaceId | string | Yes | Surface ID received from **ImageReceiver**. |
| callback | AsyncCallback<[PhotoOutput](#photooutput)\> | Yes | Callback used to return the **PhotoOutput** instance.|
**Example**
```
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.');
});
```
## camera.createPhotoOutput
createPhotoOutput(surfaceId: string): Promise<PhotoOutput\>
Creates a **PhotoOutput** instance. This API uses a promise to return the instance.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ------ | ---- | --------------------------------- |
| surfaceId | string | Yes | Surface ID received from **ImageReceiver**.|
**Return value**
| Type | Description |
| ------------------------------------- | -------------------------------------- |
| Promise<[PhotoOutput](#photooutput)\> | Promise used to return the **PhotoOutput** instance.|
**Example**
```
camera.createPhotoOutput(surfaceId).then((photoOutput) => {
console.log('Promise returned with PhotoOutput instance');
})
```
## ImageRotation
Enumerates the image rotation angles.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Default Value| Description |
| ------------ | ------ | --------------- |
| ROTATION_0 | 0 | The image rotates 0 degrees. |
| ROTATION_90 | 90 | The image rotates 90 degrees. |
| ROTATION_180 | 180 | The image rotates 180 degrees.|
| ROTATION_270 | 270 | The image rotates 270 degrees.|
## QualityLevel
Enumerates the image quality levels.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Default Value| Description |
| -------------------- | ------ | -------------- |
| QUALITY_LEVEL_HIGH | 0 | High image quality. |
| QUALITY_LEVEL_MEDIUM | 1 | Medium image quality.|
| QUALITY_LEVEL_LOW | 2 | Low image quality. |
## PhotoCaptureSetting
Defines the settings for image capture.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Type | Mandatory| Description |
| -------- | ------------------------------- | ---- | -------------- |
| quality | [QualityLevel](#qualitylevel) | No | Photo image quality. |
| rotation | [ImageRotation](#imagerotation) | No | Photo rotation.|
## PhotoOutput
Implements photo output.
### capture
capture(callback: AsyncCallback<void\>): void
Captures a photo. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example**
```
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
capture(setting: PhotoCaptureSetting, callback: AsyncCallback<void\>): void
Captures a photo with the specified capture settings. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------- | ---- | ------------------------ |
| setting | [PhotoCaptureSetting](#photocapturesetting) | Yes | Photo capture settings. |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example**
```
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
capture(setting?: PhotoCaptureSetting): Promise<void\>
Captures a photo with the specified capture settings. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ------- | ------------------------------------------- | ---- | ---------- |
| setting | [PhotoCaptureSetting](#photocapturesetting) | No | Photo capture settings.|
**Return value**
| Type | Description |
| -------------- | --------------------------- |
| Promise<void\> | Promise used to return the result.|
**Example**
```
photoOutput.capture().then(() => {
console.log('Promise returned to indicate that photo capture request success.');
})
```
### release
release(callback: AsyncCallback<void\>): void
Releases this **PhotoOutput** instance. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example**
```
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
release(): Promise<void\>
Releases this **PhotoOutput** instance. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| -------------- | --------------------------- |
| Promise<void\> | Promise used to return the result.|
**Example**
```
photoOutput.release().then(() => {
console.log('Promise returned to indicate that the PhotoOutput instance is released successfully.');
})
```
### on('captureStart')
on(type: 'captureStart', callback: AsyncCallback<number\>): void
Listens for photo capture start events. This API uses a callback to return the event information.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| :------- | :--------------------- | :--- | :----------------------------------------------- |
| type | string | Yes | Type of event to listen for. The value is fixed at **captureStart**, indicating the photo capture start event.|
| callback | AsyncCallback<number\> | Yes | Callback used to return the capture ID. |
**Example**
```
photoOutput.on('captureStart', (captureId) => {
console.log('photo capture stated, captureId : ' + captureId);
})
```
### on('frameShutter')
on(type: 'frameShutter', callback: AsyncCallback<FrameShutterInfo\>): void
Listens for frame shutter events. This API uses a callback to return the event information.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| :------- | :------------------------------- | :--- | :--------------------------------------------- |
| type | string | Yes | Type of event to listen for. The value is fixed at **frameShutter**, indicating the frame shutter event.|
| callback | AsyncCallback<FrameShutterInfo\> | Yes | Callback used to return the frame shutter information. |
**Example**
```
photoOutput.on('frameShutter', (frameShutterInfo) => {
console.log('photo capture end, captureId : ' + frameShutterInfo.captureId);
console.log('Timestamp for frame : ' + frameShutterInfo.timestamp);
})
```
### on('captureEnd')
on(type: 'captureEnd', callback: AsyncCallback<CaptureEndInfo\>): void
Listens for photo capture end events. This API uses a callback to return the event information.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| :------- | :----------------------------- | :--- | :--------------------------------------------- |
| type | string | Yes | Type of event to listen for. The value is fixed at **captureEnd**, indicating the photo capture end event.|
| callback | AsyncCallback<CaptureEndInfo\> | Yes | Callback used to return the capture end information. |
**Example**
```
photoOutput.on('captureEnd', (captureEndInfo) => {
console.log('photo capture end, captureId : ' + captureEndInfo.captureId);
console.log('frameCount : ' + captureEndInfo.frameCount);
})
```
### on('error')
on(type: 'error', callback: ErrorCallback<PhotoOutputError\>): void
Listens for **PhotoOutput** errors. This API uses a callback to return the errors.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| :------- | :------------------------------- | :--- | :---------------------------------------- |
| type | string | Yes | Type of event to listen for. The value is fixed at **error**, indicating the photo output error event.|
| callback | ErrorCallback<PhotoOutputError\> | Yes | Callback used to return the photo output errors. |
**Example**
```
photoOutput.on('error', (photoOutputError) => {
console.log('Photo output error code: ' + photoOutputError.code);
})
```
## camera.createVideoOutput
createVideoOutput(surfaceId: string, callback: AsyncCallback<VideoOutput\>): void
Creates a **VideoOutput** instance. This API uses an asynchronous callback to return the instance.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ------------------------------------------- | ---- | ----------------------------------- |
| surfaceId | string | Yes | Surface ID received from **VideoRecorder**. |
| callback | AsyncCallback<[VideoOutput](#videooutput)\> | Yes | Callback used to return the **VideoOutput** instance.|
**Example**
```
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');
});
```
## camera.createVideoOutput
createVideoOutput(surfaceId: string): Promise<VideoOutput\>
Creates a **VideoOutput** instance. This API uses a promise to return the instance.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ------ | ---- | --------------------------------- |
| surfaceId | string | Yes | Surface ID received from **VideoRecorder**.|
**Return value**
| Type | Description |
| ------------------------------------- | -------------------------------------- |
| Promise<[VideoOutput](#videooutput)\> | Promise used to return the **VideoOutput** instance.|
**Example**
```
camera.createVideoOutput(surfaceId).then((videoOutput) => {
console.log('Promise returned with the VideoOutput instance');
})
```
## VideoOutput
Implements video output.
### start
start(callback: AsyncCallback<void\>): void
Starts the video output. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example**
```
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
start(): Promise<void\>
Starts the video output. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| -------------- | --------------------------- |
| Promise<void\> | Promise used to return the result.|
**Example**
```
videoOutput.start().then(() => {
console.log('Promise returned to indicate that start method execution success.');
})
```
### stop
stop(callback: AsyncCallback<void\>): void
Stops the video output. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example**
```
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
stop(): Promise<void\>
Stops the video output. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| -------------- | --------------------------- |
| Promise<void\> | Promise used to return the result.|
**Example**
```
videoOutput.start().then(() => {
console.log('Promise returned to indicate that stop method execution success.');
})
```
### release
release(callback: AsyncCallback<void\>): void
Releases this **VideoOutput** instance. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example**
```
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
release(): Promise<void\>
Releases this **VideoOutput** instance. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| -------------- | --------------------------- |
| Promise<void\> | Promise used to return the result.|
**Example**
```
videoOutput.release().then(() => {
console.log('Promise returned to indicate that the VideoOutput instance is released successfully.');
})
```
### on('frameStart')
on(type: 'frameStart', callback: AsyncCallback<void\>): void
Listens for video frame start events. This API uses a callback to return the event information.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| :------- | :------------------- | :--- | :----------------------------------------------- |
| type | string | Yes | Type of event to listen for. The value is fixed at **frameStart**, indicating the video frame start event.|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
**Example**
```
videoOutput.on('frameStart', () => {
console.log('Video frame started');
})
```
### on('frameEnd')
on(type: 'frameEnd', callback: AsyncCallback<void\>): void
Listens for video frame end events. This API uses a callback to return the event information.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| :------- | :------------------- | :--- | :--------------------------------------------- |
| type | string | Yes | Type of event to listen for. The value is fixed at **frameEnd**, indicating the video frame end event.|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
**Example**
```
videoOutput.on('frameEnd', () => {
console.log('Video frame ended');
})
```
### on('error')
on(type: 'error', callback: ErrorCallback<VideoOutputError\>): void
Listens for **VideoOutput** errors. This API uses a callback to return the errors.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| :------- | :-------------------------- | :--- | :-------------------------------------------- |
| type | string | Yes | Type of event to listen for. The value is fixed at **error**, indicating the video output error event.|
| callback | Callback<VideoOutputError\> | Yes | Callback used to return the video output errors. |
**Example**
```
videoOutput.on('error', (VideoOutputError) => {
console.log('Video output error code: ' + VideoOutputError.code);
})
```
......@@ -48,7 +48,6 @@
- application/[ExtensionAbilityContext (ExtensionAbilityContext)](js-apis-extension-ability-context.md)
- application/[ExtensionAbilityInfo (ExtensionAbilityInfo)](js-apis-extensionAbilityInfo.md)
- application/[ServiceExtAbilityContext (ServiceExtAbilityContext)](js-apis-serviceExtAbilityContext.md)
- 公共事件与通知
- [@ohos.commonEvent (公共事件模块)](js-apis-commonEvent.md)
......@@ -85,7 +84,6 @@
- 媒体
- [@ohos.multimedia.audio (音频管理)](js-apis-audio.md)
- [@ohos.multimedia.camera (相机管理)](js-apis-camera.md)
- [@ohos.multimedia.image (图片处理)](js-apis-image.md)
- [@ohos.multimedia.media (媒体服务)](js-apis-media.md)
- [@ohos.multimedia.medialibrary (媒体库管理)](js-apis-medialibrary.md)
......
# 相机管理
> **说明:**
> 本模块首批接口从API version 9开始支持。API Version 9当前为Canary版本,仅供试用,不保证接口可稳定调用。
## 导入模块
```
import camera from '@ohos.multimedia.camera';
```
## 权限
ohos.permission.CAMERA
## camera.getCameraManager
getCameraManager(context: Context, callback: AsyncCallback<CameraManager\>): void
获取相机管理器实例,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------------- | ---- | ---------------------------------- |
| context | Context | 是 | 应用上下文。 |
| callback | AsyncCallback<[CameraManager](#cameramanager)\> | 是 | 回调函数,用于获取相机管理器实例。 |
**示例:**
```
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');
});
```
## camera.getCameraManager
getCameraManager(context: Context): Promise<CameraManager\>
获取相机管理器实例,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ------- | ------- | ---- | ------------ |
| context | Context | 是 | 应用上下文。 |
**返回值:**
| 类型 | 说明 |
| ----------------------------------------- | ----------------------------------------- |
| Promise<[CameraManager](#cameramanager)\> | 使用Promise的方式获取一个相机管理器实例。 |
**示例:**
```
camera.getCameraManager(context).then((cameraManager) => {
console.log('Promise returned with the CameraManager instance.');
})
```
## CameraStatus
枚举,相机状态。
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Camera.Core。
| 名称 | 默认值 | 说明 |
| ------------------------- | ------ | ------------ |
| CAMERA_STATUS_APPEAR | 0 | 相机存在。 |
| CAMERA_STATUS_DISAPPEAR | 1 | 相机不存在。 |
| CAMERA_STATUS_AVAILABLE | 2 | 相机就绪。 |
| CAMERA_STATUS_UNAVAILABLE | 3 | 相机未就绪。 |
## CameraPosition
枚举,相机方向。
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Camera.Core。
| 名称 | 默认值 | 说明 |
| --------------------------- | ------ | ---------------- |
| CAMERA_POSITION_UNSPECIFIED | 0 | 未指定方向相机。 |
| CAMERA_POSITION_BACK | 1 | 后置相机。 |
| CAMERA_POSITION_FRONT | 2 | 前置相机。 |
## CameraType
枚举,相机类型。
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Camera.Core。
| 名称 | 默认值 | 说明 |
| ----------------------- | ------ | ---------------- |
| CAMERA_TYPE_UNSPECIFIED | 0 | 未指定相机类型。 |
| CAMERA_TYPE_WIDE_ANGLE | 1 | 广角相机。 |
| CAMERA_TYPE_ULTRA_WIDE | 2 | 超级广角相机。 |
| CAMERA_TYPE_TELEPHOTO | 3 | 长焦相机。 |
| CAMERA_TYPE_TRUE_DEPTH | 4 | 深度相机。 |
## ConnectionType
枚举,相机连接类型。
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Camera.Core。
| 名称 | 默认值 | 说明 |
| ---------------------------- | ------ | ------------- |
| CAMERA_CONNECTION_BUILT_IN | 0 | 内置相机。 |
| CAMERA_CONNECTION_USB_PLUGIN | 1 | 外置USB相机。 |
| CAMERA_CONNECTION_REMOTE | 2 | 分布式相机。 |
## CameraManager
相机管理器类,使用前需要通过getCameraManager获取相机管理实例。
### getCameras
getCameras(callback: AsyncCallback<Array<Camera\>\>): void
异步获取设备支持的相机列表,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------- | ---- | ------------------------------------ |
| callback | AsyncCallback<Array<[Camera](#camera)\>\> | 是 | 使用callback方式获取支持的相机列表。 |
**示例:**
```
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
getCameras(): Promise<Array<Camera\>\>
异步获取设备支持的相机列表,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| ----------------------------------- | ----------------------------- |
| Promise<Array<[Camera](#camera)\>\> | 使用promise获取支持相机列表。 |
**示例:**
```
cameraManager.getCameras().then((cameraArray) => {
console.log('Promise returned with an array of supported cameras: ' + cameraArray.length);
})
```
### createCameraInput
createCameraInput(cameraId: string, callback: AsyncCallback<CameraInput\>): void
使用相机ID异步创建CameraInput实例,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 默认值 | 必填 | 说明 |
| -------- | ------------------------------------------- | ---- | ----------------------------------- |
| cameraId | string | 是 | 指定相机ID。 |
| callback | AsyncCallback<[CameraInput](#camerainput)\> | 是 | 回调函数,用于获取CameraInput实例。 |
**示例:**
```
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
createCameraInput(cameraId: string): Promise<CameraInput\>
使用相机ID异步创建CameraInput实例,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 默认值 | 必填 | 说明 |
| -------- | ------ | ---- | ------------ |
| cameraId | string | 是 | 指定相机ID。 |
**返回值:**
| 类型 | 说明 |
| ------------------------------------- | ---------------------------------------- |
| Promise<[CameraInput](#camerainput)\> | 使用Promise的方式获取CameraInput的实例。 |
**示例:**
```
cameraManager.createCameraInput(cameraId).then((cameraInput) => {
console.log('Promise returned with the CameraInput instance');
})
```
### createCameraInput
createCameraInput(position: CameraPosition, type: CameraType, callback: AsyncCallback<CameraInput\>): void
使用相机位置和相机类型异步创建CameraInput实例,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------- | ---- | ----------------------------------- |
| position | [CameraPosition](#cameraposition) | 是 | 相机位置。 |
| type | [CameraType](#cameratype) | 是 | 相机类型。 |
| callback | AsyncCallback<[CameraInput](#camerainput)\> | 是 | 回调函数,用于获取CameraInput实例。 |
**示例:**
```
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
createCameraInput(position: CameraPosition, type: CameraType): Promise<CameraInput\>
使用相机位置和相机类型异步创建CameraInput实例,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | --------------------------------- | ---- | ---------- |
| position | [CameraPosition](#cameraposition) | 是 | 相机位置。 |
| type | [CameraType](#cameratype) | 是 | 相机类型。 |
**返回值:**
| 类型 | 说明 |
| ------------------------------------- | ---------------------------------------- |
| Promise<[CameraInput](#camerainput)\> | 使用Promise的方式获取CameraInput的实例。 |
**示例:**
```
cameraManager.createCameraInput(cameraPosition, cameraType).then((cameraInput) => {
console.log('Promise returned with the CameraInput instance.');
})
```
### on('cameraStatus')
on(type: 'cameraStatus', callback: AsyncCallback<CameraStatusInfo\>): void
监听相机的状态变化,通过注册回调函数获取相机的状态变化。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| :------- | :---------------------------------------------------- | :--- | :--------------------------------------------------- |
| type | string | 是 | 监听事件,固定为'cameraStatus',即相机状态变化事件。 |
| callback | AsyncCallback<[CameraStatusInfo](#camerastatusinfo)\> | 是 | 回调函数,用于获取相机状态变化信息。 |
**示例:**
```
cameraManager.on('cameraStatus', (cameraStatusInfo) => {
console.log('camera : ' + cameraStatusInfo.camera.cameraId);
console.log('status: ' + cameraStatusInfo.status);
})
```
## Camera
调用[camera.getCameraManager](#cameragetcameramanager)后,将返回Camera实例,包括相机ID、位置、类型、连接类型等相机相关的元数据。
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Camera.Core。
| 名称 | 类型 | 只读 | 说明 |
| -------------- | --------------------------------- | ---- | -------------- |
| cameraId | string | 是 | 相机ID。 |
| cameraPosition | [CameraPosition](#cameraposition) | 是 | 相机位置。 |
| cameraType | [CameraType](#cameratype) | 是 | 相机类型。 |
| connectionType | [ConnectionType](#connectiontype) | 是 | 相机连接类型。 |
**示例:**
```
async function getCameraInfo() {
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
相机管理器回调返回的接口实例,表示相机状态信息。
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Camera.Core。
| 名称 | 类型 | 说明 |
| ------ | ----------------------------- | ---------- |
| camera | [Camera](#camera) | 相机信息。 |
| status | [CameraStatus](#camerastatus) | 相机状态。 |
## CameraInput
相机输入类。在使用该类的方法前,需要先构建一个CameraInput实例。
### getCameraId
getCameraId(callback: AsyncCallback<string\>\): void
异步获取该CameraInput实例的相机ID,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ---------------------- | ---- | -------------------------- |
| callback | AsyncCallback<string\> | 是 | 回调函数,用于获取相机ID。 |
**示例:**
```
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
getCameraId(): Promise<string\>
异步获取该CameraInput实例的相机ID,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| ---------------- | ----------------------------- |
| Promise<string\> | 使用Promise的方式获取相机ID。 |
**示例:**
```
cameraInput.getCameraId().then((cameraId) => {
console.log('Promise returned with the camera ID:' + cameraId);
})
```
### hasFlash
hasFlash(callback: AsyncCallback<boolean\>): void
判断设备是否支持闪光灯,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- |
| callback | AsyncCallback<boolean\> | 是 | 回调函数,返回true表示设备支持闪光灯。 |
**示例:**
```
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
hasFlash(): Promise<boolean\>
判断设备是否支持闪光灯,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| ----------------- | ------------------------------------------------------- |
| Promise<boolean\> | 使用Promise的方式获取结果,返回true表示设备支持闪光灯。 |
**示例:**
```
cameraInput.hasFlash().then((status) => {
console.log('Promise returned with the flash light support status:' + status);
})
```
### isFlashModeSupported
isFlashModeSupported(flashMode: FlashMode, callback: AsyncCallback<boolean\>): void
判断设备是否支持指定闪光灯模式,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| --------- | ----------------------- | ---- | ---------------------------------------- |
| flashMode | [FlashMode](#flashmode) | 是 | 指定闪光灯模式。 |
| callback | AsyncCallback<boolean\> | 是 | 回调函数,返回true表示支持该闪光灯模式。 |
**示例:**
```
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
isFlashModeSupported(flashMode: FlashMode): Promise<boolean\>
判断设备是否支持指定闪光灯模式,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| --------- | ----------------------- | ---- | ---------------- |
| flashMode | [FlashMode](#flashmode) | 是 | 指定闪光灯模式。 |
**返回值:**
| 类型 | 说明 |
| ----------------- | ------------------------------------------------------------ |
| Promise<boolean\> | 使用Promise的方式获取结果,返回true表示设备支持该闪光灯模式。 |
**示例:**
```
cameraInput.isFlashModeSupported(flashMode).then((status) => {
console.log('Promise returned with flash mode support status.' + status);
})
```
### setFlashMode
setFlashMode(flashMode: FlashMode, callback: AsyncCallback<void\>): void
设置闪光灯模式,通过注册回调函数获取结果。
进行设置之前,需要先检查:
1. 设备是否支持闪光灯,可使用方法[hasFlash](#hasflash)
2. 设备是否支持指定的闪光灯模式,可使用方法[isFlashModeSupported](#isflashmodesupported)
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| --------- | ----------------------- | ---- | ------------------------ |
| flashMode | [FlashMode](#flashmode) | 是 | 指定闪光灯模式。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```
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
setFlashMode(flashMode: FlashMode): Promise<void\>
设置闪光灯模式,通过Promise获取结果。
进行设置之前,需要先检查:
1. 设备是否支持闪光灯,可使用方法[hasFlash](#hasflash)
2. 设备是否支持指定的闪光灯模式,可使用方法[isFlashModeSupported](#isflashmodesupported)
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| --------- | ----------------------- | ---- | ---------------- |
| flashMode | [FlashMode](#flashmode) | 是 | 指定闪光灯模式。 |
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 |
**示例:**
```
cameraInput.setFlashMode(flashMode).then(() => {
console.log('Promise returned with the successful execution of setFlashMode.');
})
```
### getFlashMode
getFlashMode(callback: AsyncCallback<FlashMode\>): void
获取当前设备的闪光灯模式,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------------------------------------- |
| callback | AsyncCallback<[FlashMode](#flashmode)\> | 是 | 回调函数,用于获取当前设备的闪光灯模式。 |
**示例:**
```
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
getFlashMode(): Promise<FlashMode\>
获取当前设备的闪光灯模式,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| --------------------------------- | --------------------------------------- |
| Promise<[FlashMode](#flashmode)\> | 使用Promise的方式获取当前的闪光灯模式。 |
**示例:**
```
cameraInput.getFlashMode().then((flashMode) => {
console.log('Promise returned with current flash mode : ' + flashMode);
})
```
### isFocusModeSupported
isFocusModeSupported(afMode: FocusMode, callback: AsyncCallback<boolean\>): void
判断设备是否支持指定的焦距模式,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- |
| afMode | [FocusMode](#focusmode) | 是 | 指定的焦距模式。 |
| callback | AsyncCallback<boolean\> | 是 | 回调函数,返回true表示支持该焦距模式。 |
**示例:**
```
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
isFocusModeSupported(afMode: FocusMode): Promise<boolean\>
判断设备是否支持指定的焦距模式,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ------ | ----------------------- | ---- | ---------------- |
| afMode | [FocusMode](#focusmode) | 是 | 指定的焦距模式。 |
**返回值:**
| 类型 | 说明 |
| ----------------- | ----------------------------------------------------------- |
| Promise<boolean\> | 使用Promise的方式获取结果,返回true表示设备支持该焦距模式。 |
**示例:**
```
cameraInput.isFocusModeSupported(afMode).then((status) => {
console.log('Promise returned with focus mode support status.' + status);
})
```
### setFocusMode
setFocusMode(afMode: FocusMode, callback: AsyncCallback<void\>): void
设置焦距模式,通过注册回调函数获取结果。
进行设置之前,需要先检查设备是否支持指定的焦距模式,可使用方法[isFocusModeSupported](#isfocusmodesupported)
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | ------------------------ |
| afMode | [FocusMode](#focusmode) | 是 | 指定的焦距模式。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```
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
setFocusMode(afMode: FocusMode): Promise<void\>
设置焦距模式,通过Promise获取结果。
进行设置之前,需要先检查设备是否支持指定的焦距模式,可使用方法[isFocusModeSupported](#isfocusmodesupported)
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ------ | ----------------------- | ---- | ---------------- |
| afMode | [FocusMode](#focusmode) | 是 | 指定的焦距模式。 |
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 |
**示例:**
```
cameraInput.setFocusMode(afMode).then(() => {
console.log('Promise returned with the successful execution of setFocusMode.');
})
```
### getFocusMode
getFocusMode(callback: AsyncCallback<FocusMode\>): void
获取当前设备的焦距模式,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | -------------------------------------- |
| callback | AsyncCallback<[FocusMode](#focusmode)\> | 是 | 回调函数,用于获取当前设备的焦距模式。 |
**示例:**
```
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
getFocusMode(): Promise<FocusMode\>
获取当前设备的焦距模式,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| ------------------- | ------------------------------------- |
| Promise<FocusMode\> | 使用Promise的方式获取当前的焦距模式。 |
**示例:**
```
cameraInput.getFocusMode().then((afMode) => {
console.log('Promise returned with current focus mode : ' + afMode);
})
```
### getZoomRatioRange
getZoomRatioRange\(callback: AsyncCallback<Array<number\>\>\): void
获取可变焦距比范围,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ------------------------------ | ---- | ------------------------ |
| callback | AsyncCallback<Array<number\>\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```
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
getZoomRatioRange\(\): Promise<Array<number\>\>
获取可变焦距比范围,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| ------------------------ | ------------------------------------------- |
| Promise<Array<number\>\> | 使用Promise的方式获取当前的可变焦距比范围。 |
**示例:**
```
cameraInput.getZoomRatioRange().then((zoomRatioRange) => {
console.log('Promise returned with zoom ratio range: ' + zoomRatioRange.length);
})
```
### setZoomRatio
setZoomRatio(zoomRatio: number, callback: AsyncCallback<void\>): void
设置可变焦距比,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| --------- | -------------------- | ---- | ------------------------ |
| zoomRatio | number | 是 | 可变焦距比。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```
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
setZoomRatio(zoomRatio: number): Promise<void\>
设置可变焦距比,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| --------- | ------ | ---- | ------------ |
| zoomRatio | number | 是 | 可变焦距比。 |
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 |
**示例:**
```
cameraInput.setZoomRatio(zoomRatio).then(() => {
console.log('Promise returned with the successful execution of setZoomRatio.');
})
```
### getZoomRatio
getZoomRatio(callback: AsyncCallback<number\>): void
获取当前的可变焦距比,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ---------------------- | ---- | ------------------------ |
| callback | AsyncCallback<number\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```
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
getZoomRatio(): Promise<number\>
获取当前的可变焦距比,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| ---------------- | --------------------------- |
| Promise<number\> | 使用Promise的方式获取结果。 |
**示例:**
```
cameraInput.getZoomRatio().then((zoomRatio) => {
console.log('Promise returned with current zoom ratio : ' + zoomRatio);
})
```
### release
release\(callback: AsyncCallback<void\>\): void
释放相机实例,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```
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
release(): Promise<void\>
释放相机实例,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 |
**示例:**
```
cameraInput.release().then(() => {
console.log('Promise returned to indicate that the CameraInput instance is released successfully.');
})
```
### on('focusStateChange')
on(type: 'focusStateChange', callback: AsyncCallback<FocusState\>): void
监听焦距的状态变化,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| :------- | :---------------------------------------- | :--- | :------------------------------------------------------- |
| type | string | 是 | 监听事件,固定为'focusStateChange',即焦距状态变化事件。 |
| callback | AsyncCallback<[FocusState](#focusstate)\> | 是 | 回调函数,用于获取焦距状态。 |
**示例:**
```
cameraInput.on('focusStateChange', (focusState) => {
console.log('Focus state : ' + focusState);
})
```
### on('error')
on(type: 'error', callback: ErrorCallback<CameraInputError\>): void
监听CameraInput的错误事件,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| :------- | :------------------------------- | :--- | :---------------------------------------------- |
| type | string | 是 | 监听事件,固定为'error',即CameraInput错误事件。 |
| callback | ErrorCallback<CameraInputError\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```
cameraInput.on('error', (cameraInputError) => {
console.log('Camera input error code: ' + cameraInputError.code);
})
```
## FlashMode
枚举,闪光灯模式。
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Camera.Core。
| 名称 | 默认值 | 说明 |
| ---------------------- | ------ | ------------ |
| FLASH_MODE_CLOSE | 0 | 闪光灯关闭。 |
| FLASH_MODE_OPEN | 1 | 闪光灯开启。 |
| FLASH_MODE_AUTO | 2 | 自动闪光灯。 |
| FLASH_MODE_ALWAYS_OPEN | 3 | 闪光灯常亮。 |
## FocusMode
枚举,焦距模式。
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Camera.Core。
| 名称 | 默认值 | 说明 |
| -------------------------- | ------ | ------------------ |
| FOCUS_MODE_MANUAL | 0 | 手动变焦模式。 |
| FOCUS_MODE_CONTINUOUS_AUTO | 1 | 连续自动变焦模式。 |
| FOCUS_MODE_AUTO | 2 | 自动变焦模式。 |
| FOCUS_MODE_LOCKED | 3 | 定焦模式。 |
## FocusState
枚举,焦距状态。
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Camera.Core。
| 名称 | 默认值 | 说明 |
| --------------------- | ------ | ------------ |
| FOCUS_STATE_SCAN | 0 | 扫描状态。 |
| FOCUS_STATE_FOCUSED | 1 | 相机已对焦。 |
| FOCUS_STATE_UNFOCUSED | 2 | 相机未对焦。 |
## camera.createCaptureSession
createCaptureSession\(context: Context, callback: AsyncCallback<CaptureSession\>\): void
获取CaptureSession实例,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------- | ---- | -------------------------------------- |
| context | Context | 是 | 应用上下文。 |
| callback | AsyncCallback<[CaptureSession](#capturesession)\> | 是 | 回调函数,用于获取CaptureSession实例。 |
**示例:**
```
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);
});
```
## camera.createCaptureSession
createCaptureSession(context: Context\): Promise<CaptureSession\>;
获取CaptureSession实例,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ------- | ------- | ---- | ------------ |
| context | Context | 是 | 应用上下文。 |
**返回值:**
| 类型 | 说明 |
| ------------------------------------------- | ----------------------------------------- |
| Promise<[CaptureSession](#capturesession)\> | 使用Promise的方式获取CaptureSession实例。 |
**示例:**
```
camera.createCaptureSession(context).then((captureSession) => {
console.log('Promise returned with the CaptureSession instance');
})
```
## CaptureSession
拍照会话类。
### beginConfig
beginConfig\(callback: AsyncCallback<void\>\): void
开始配置会话,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```
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
beginConfig\(\): Promise<void\>
开始配置会话,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 |
**示例:**
```
captureSession.beginConfig().then(() => {
console.log('Promise returned to indicate the begin config success.');
})
```
### commitConfig
commitConfig\(callback: AsyncCallback<void\>\): void
提交会话配置,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```
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
commitConfig\(\): Promise<void\>
提交会话配置,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 |
**示例:**
```
captureSession.commitConfig().then(() => {
console.log('Promise returned to indicate the commit config success.');
})
```
### addInput
addInput\(cameraInput: CameraInput, callback: AsyncCallback<void\>\): void
在当前会话中,添加一个CameraInput实例,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ----------- | --------------------------- | ---- | --------------------------- |
| cameraInput | [CameraInput](#camerainput) | 是 | 需要添加的CameraInput实例。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```
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
addInput\(cameraInput: CameraInput\): Promise<void\>
在当前会话中,添加一个CameraInput实例,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ----------- | --------------------------- | ---- | --------------------------- |
| cameraInput | [CameraInput](#camerainput) | 是 | 需要添加的CameraInput实例。 |
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 |
**示例:**
```
captureSession.addInput(cameraInput).then(() => {
console.log('Promise used to indicate that the CameraInput instance is added.');
})
```
### addOutput
addOutput\(previewOutput: PreviewOutput, callback: AsyncCallback<void\>\): void
在当前会话中,添加一个PreviewOutput实例,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ------------- | ------------------------------- | ---- | ----------------------------- |
| previewOutput | [PreviewOutput](#previewoutput) | 是 | 需要添加的PreviewOutput实例。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```
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
addOutput\(previewOutput: PreviewOutput\): Promise<void\>
在当前会话中,添加一个PreviewOutput实例,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ------------- | ------------------------------- | ---- | ----------------------------- |
| previewOutput | [PreviewOutput](#previewoutput) | 是 | 需要添加的PreviewOutput实例。 |
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 |
**示例:**
```
captureSession.addOutput(previewOutput).then(() => {
console.log('Promise used to indicate that the PreviewOutput instance is added.');
})
```
### addOutput
addOutput\(photoOutput: PhotoOutput, callback: AsyncCallback<void\>\): void
在当前会话中,添加一个PhotoOutput实例,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ----------- | --------------------------- | ---- | --------------------------- |
| photoOutput | [PhotoOutput](#photooutput) | 是 | 需要添加的PhotoOutput实例。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```
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
addOutput\(photoOutput: PhotoOutput\): Promise<void\>
在当前会话中,添加一个PhotoOutput实例,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ----------- | --------------------------- | ---- | --------------------------- |
| photoOutput | [PhotoOutput](#photooutput) | 是 | 需要添加的PhotoOutput实例。 |
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise\<void> | 使用Promise的方式获取结果。 |
**示例:**
```
captureSession.addOutput(photoOutput).then(() => {
console.log('Promise used to indicate that the PhotoOutput instance is added.');
})
```
### addOutput
addOutput\(videoOutput: VideoOutput, callback: AsyncCallback<void\>\): void
在当前会话中,添加一个VideoOutput实例,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ----------- | --------------------------- | ---- | --------------------------- |
| videoOutput | [VideoOutput](#videooutput) | 是 | 需要添加的VideoOutput实例。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```
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
addOutput\(videoOutput: VideoOutput\): Promise<void\>
在当前会话中,添加一个VideoOutput实例,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ----------- | --------------------------- | ---- | --------------------------- |
| videoOutput | [VideoOutput](#videooutput) | 是 | 需要添加的VideoOutput实例。 |
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise\<void> | 使用Promise的方式获取结果。 |
**示例:**
```
captureSession.addOutput(videoOutput).then(() => {
console.log('Promise used to indicate that the VideoOutput instance is added.');
})
```
### removeInput
removeInput\(cameraInput: CameraInput, callback: AsyncCallback<void\>\): void
在当前会话中,移除一个CameraInput实例,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ----------- | --------------------------- | ---- | --------------------------- |
| cameraInput | [CameraInput](#camerainput) | 是 | 需要移除的CameraInput实例。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```
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
removeInput\(cameraInput: CameraInput\): Promise<void\>
在当前会话中,移除一个CameraInput实例,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ----------- | --------------------------- | ---- | --------------------------- |
| cameraInput | [CameraInput](#camerainput) | 是 | 需要移除的CameraInput实例。 |
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise\<void> | 使用Promise的方式获取结果。 |
**示例:**
```
captureSession.removeInput(cameraInput).then(() => {
console.log('Promise returned to indicate that the cameraInput instance is removed.');
})
```
### removeOutput
removeOutput\(previewOutput: PreviewOutput, callback: AsyncCallback<void\>\): void
在当前会话中,移除一个PreviewOutput实例,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ------------- | ------------------------------- | ---- | ----------------------------- |
| previewOutput | [PreviewOutput](#previewoutput) | 是 | 需要移除的PreviewOutput实例。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```
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
removeOutput(previewOutput: PreviewOutput): Promise<void\>
在当前会话中,移除一个PreviewOutput实例,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ------------- | ------------------------------- | ---- | ----------------------------- |
| previewOutput | [PreviewOutput](#previewoutput) | 是 | 需要移除的PreviewOutput实例。 |
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 |
**示例:**
```
captureSession.removeOutput(previewOutput).then(() => {
console.log('Promise returned to indicate that the PreviewOutput instance is removed.');
})
```
### removeOutput
removeOutput(photoOutput: PhotoOutput, callback: AsyncCallback<void\>): void
在当前会话中,移除一个PhotoOutput实例,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ----------- | --------------------------- | ---- | --------------------------- |
| photoOutput | [PhotoOutput](#photooutput) | 是 | 需要移除的PhotoOutput实例。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```
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
removeOutput(photoOutput: PhotoOutput): Promise<void\>
在当前会话中,移除一个PhotoOutput实例,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ----------- | --------------------------- | ---- | --------------------------- |
| photoOutput | [PhotoOutput](#photooutput) | 是 | 需要移除的PhotoOutput实例。 |
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 |
**示例:**
```
captureSession.removeOutput(photoOutput).then(() => {
console.log('Promise returned to indicate that the PhotoOutput instance is removed.');
})
```
### removeOutput
removeOutput(videoOutput: VideoOutput, callback: AsyncCallback<void\>): void
在当前会话中,移除一个VideoOutput实例,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ----------- | --------------------------- | ---- | --------------------------- |
| videoOutput | [VideoOutput](#videooutput) | 是 | 需要移除的VideoOutput实例。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```
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
removeOutput(videoOutput: VideoOutput): Promise<void\>
在当前会话中,移除一个VideoOutput实例,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ----------- | --------------------------- | ---- | --------------------------- |
| videoOutput | [VideoOutput](#videooutput) | 是 | 需要移除的VideoOutput实例。 |
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 |
**示例:**
```
captureSession.removeOutput(videoOutput).then(() => {
console.log('Promise returned to indicate that the VideoOutput instance is removed.');
})
```
### start
start\(callback: AsyncCallback<void\>\): void
启动拍照会话,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```
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
start\(\): Promise<void\>
启动拍照会话,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 |
**示例:**
```
captureSession.start().then(() => {
console.log('Promise returned to indicate the session start success.');
})
```
### stop
stop\(callback: AsyncCallback<void\>\): void
停止拍照会话,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```
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
stop(): Promise<void\>
停止拍照会话,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 |
**示例:**
```
captureSession.stop().then(() => {
console.log('Promise returned to indicate the session stop success.');
})
```
### release
release\(callback: AsyncCallback<void\>\): void
释放CaptureSession实例,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```
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
release(): Promise<void\>
释放CaptureSession实例,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 |
**示例:**
```
captureSession.release().then(() => {
console.log('Promise returned to indicate that the CaptureSession instance is released successfully.');
})
```
### on('error')
on(type: 'error', callback: ErrorCallback<CaptureSessionError\>): void
监听拍照会话的错误事件,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| :------- | :---------------------------------- | :--- | :-------------------------------------------- |
| type | string | 是 | 监听事件,固定为'error',即拍照会话错误事件。 |
| callback | ErrorCallback<CaptureSessionError\> | 是 | 回调函数,用于获取错误信息。 |
**示例:**
```
captureSession.on('error', (captureSessionError) => {
console.log('Capture session error code: ' + captureSessionError.code);
})
```
## camera.createPreviewOutput
createPreviewOutput(surfaceId: string, callback: AsyncCallback<PreviewOutput\>): void
获取PreviewOutput实例,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| --------- | ----------------------------------------------- | ---- | ------------------------------------- |
| surfaceId | string | 是 | 从XComponent组件获取的Surface ID。 |
| callback | AsyncCallback<[PreviewOutput](#previewoutput)\> | 是 | 回调函数,用于获取PreviewOutput实例。 |
**示例:**
```
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');
});
```
## camera.createPreviewOutput
createPreviewOutput(surfaceId: string): Promise\<PreviewOutput>
获取PreviewOutput实例,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| --------- | ------ | ---- | ---------------------------------- |
| surfaceId | string | 是 | 从XComponent组件获取的Surface ID。 |
**返回值:**
| 类型 | 说明 |
| ----------------------------------------- | --------------------------- |
| Promise<[PreviewOutput](#previewoutput)\> | 使用Promise的方式获取结果。 |
**示例:**
```
camera.createPreviewOutput(surfaceId).then((previewOutput) => {
console.log('Promise returned with the PreviewOutput instance');
})
```
## PreviewOutput
预览输出类。
### release
release(callback: AsyncCallback<void\>): void
释放PreviewOutput实例,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```
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
release(): Promise<void\>
释放PreviewOutput实例,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 |
**示例:**
```
previewOutput.release().then(() => {
console.log('Promise returned to indicate that the PreviewOutput instance is released successfully.');
})
```
### on('frameStart')
on(type: 'frameStart', callback: AsyncCallback<void\>): void
监听预览帧启动,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| :------- | :------------------- | :--- | :------------------------------------------- |
| type | string | 是 | 监听事件,固定为'frameStart',即帧启动事件。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```
previewOutput.on('frameStart', () => {
console.log('Preview frame started');
})
```
### on('frameEnd')
on(type: 'frameEnd', callback: AsyncCallback<void\>): void
监听预览帧结束,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| :------- | :------------------- | :--- | :----------------------------------------- |
| type | string | 是 | 监听事件,固定为'frameEnd',即帧结束事件。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```
previewOutput.on('frameEnd', () => {
console.log('Preview frame ended');
})
```
### on('error')
on(type: 'error', callback: ErrorCallback<PreviewOutputError\>): void
监听预览输出的错误事件,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| :------- | :--------------------------------- | :--- | :-------------------------------------------- |
| type | string | 是 | 监听事件,固定为'error',即预览输出错误事件。 |
| callback | ErrorCallback<PreviewOutputError\> | 是 | 回调函数,用于获取错误信息。 |
**示例:**
```
previewOutput.on('error', (previewOutputError) => {
console.log('Preview output error code: ' + previewOutputError.code);
})
```
## camera.createPhotoOutput
createPhotoOutput(surfaceId: string, callback: AsyncCallback<PhotoOutput\>): void
获取PhotoOutput实例,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| --------- | ------------------------------------------- | ---- | ----------------------------------- |
| surfaceId | string | 是 | 从ImageReceiver获取的Surface ID。 |
| callback | AsyncCallback<[PhotoOutput](#photooutput)\> | 是 | 回调函数,用于获取PhotoOutput实例。 |
**示例:**
```
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.');
});
```
## camera.createPhotoOutput
createPhotoOutput(surfaceId: string): Promise<PhotoOutput\>
获取PhotoOutput实例,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| --------- | ------ | ---- | --------------------------------- |
| surfaceId | string | 是 | 从ImageReceiver获取的Surface ID。 |
**返回值:**
| 类型 | 说明 |
| ------------------------------------- | -------------------------------------- |
| Promise<[PhotoOutput](#photooutput)\> | 使用Promise的方式获取PhotoOutput实例。 |
**示例:**
```
camera.createPhotoOutput(surfaceId).then((photoOutput) => {
console.log('Promise returned with PhotoOutput instance');
})
```
## ImageRotation
枚举,图片旋转角度。
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Camera.Core。
| 名称 | 默认值 | 说明 |
| ------------ | ------ | --------------- |
| ROTATION_0 | 0 | 图片旋转0度。 |
| ROTATION_90 | 90 | 图片旋转90度。 |
| ROTATION_180 | 180 | 图片旋转180度。 |
| ROTATION_270 | 270 | 图片旋转270度。 |
## QualityLevel
枚举,图片质量。
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Camera.Core。
| 名称 | 默认值 | 说明 |
| -------------------- | ------ | -------------- |
| QUALITY_LEVEL_HIGH | 0 | 图片质量高。 |
| QUALITY_LEVEL_MEDIUM | 1 | 图片质量中等。 |
| QUALITY_LEVEL_LOW | 2 | 图片质量差。 |
## PhotoCaptureSetting
拍摄照片的设置。
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Camera.Core。
| 名称 | 类型 | 必填 | 说明 |
| -------- | ------------------------------- | ---- | -------------- |
| quality | [QualityLevel](#qualitylevel) | 否 | 图片质量。 |
| rotation | [ImageRotation](#imagerotation) | 否 | 图片旋转角度。 |
## PhotoOutput
照片输出类。
### capture
capture(callback: AsyncCallback<void\>): void
拍照,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```
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
capture(setting: PhotoCaptureSetting, callback: AsyncCallback<void\>): void
根据拍照设置拍照,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------- | ---- | ------------------------ |
| setting | [PhotoCaptureSetting](#photocapturesetting) | 是 | 拍照设置。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```
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
capture(setting?: PhotoCaptureSetting): Promise<void\>
根据拍照设置拍照,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ------- | ------------------------------------------- | ---- | ---------- |
| setting | [PhotoCaptureSetting](#photocapturesetting) | 否 | 拍照设置。 |
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 |
**示例:**
```
photoOutput.capture().then(() => {
console.log('Promise returned to indicate that photo capture request success.');
})
```
### release
release(callback: AsyncCallback<void\>): void
释放PhotoOutput实例,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```
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
release(): Promise<void\>
释放PhotoOutput实例,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 |
**示例:**
```
photoOutput.release().then(() => {
console.log('Promise returned to indicate that the PhotoOutput instance is released successfully.');
})
```
### on('captureStart')
on(type: 'captureStart', callback: AsyncCallback<number\>): void
监听拍照启动,通过注册回调函数获取Capture ID。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| :------- | :--------------------- | :--- | :----------------------------------------------- |
| type | string | 是 | 监听事件,固定为'captureStart',即拍照启动事件。 |
| callback | AsyncCallback<number\> | 是 | 使用callback的方式获取Capture ID。 |
**示例:**
```
photoOutput.on('captureStart', (captureId) => {
console.log('photo capture stated, captureId : ' + captureId);
})
```
### on('frameShutter')
on(type: 'frameShutter', callback: AsyncCallback<FrameShutterInfo\>): void
监听帧刷新,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| :------- | :------------------------------- | :--- | :--------------------------------------------- |
| type | string | 是 | 监听事件,固定为'frameShutter',即帧刷新事件。 |
| callback | AsyncCallback<FrameShutterInfo\> | 是 | 回调函数,用于获取相关信息。 |
**示例:**
```
photoOutput.on('frameShutter', (frameShutterInfo) => {
console.log('photo capture end, captureId : ' + frameShutterInfo.captureId);
console.log('Timestamp for frame : ' + frameShutterInfo.timestamp);
})
```
### on('captureEnd')
on(type: 'captureEnd', callback: AsyncCallback<CaptureEndInfo\>): void
监听拍照停止,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| :------- | :----------------------------- | :--- | :--------------------------------------------- |
| type | string | 是 | 监听事件,固定为'captureEnd',即拍照停止事件。 |
| callback | AsyncCallback<CaptureEndInfo\> | 是 | 回调函数,用于获取相关信息。 |
**示例:**
```
photoOutput.on('captureEnd', (captureEndInfo) => {
console.log('photo capture end, captureId : ' + captureEndInfo.captureId);
console.log('frameCount : ' + captureEndInfo.frameCount);
})
```
### on('error')
on(type: 'error', callback: ErrorCallback<PhotoOutputError\>): void
监听拍照的错误事件,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| :------- | :------------------------------- | :--- | :---------------------------------------- |
| type | string | 是 | 监听事件,固定为'error',即拍照错误事件。 |
| callback | ErrorCallback<PhotoOutputError\> | 是 | 回调函数,用于获取错误信息。 |
**示例:**
```
photoOutput.on('error', (photoOutputError) => {
console.log('Photo output error code: ' + photoOutputError.code);
})
```
## camera.createVideoOutput
createVideoOutput(surfaceId: string, callback: AsyncCallback<VideoOutput\>): void
获取VideoOutput实例,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| --------- | ------------------------------------------- | ---- | ----------------------------------- |
| surfaceId | string | 是 | 从VideoRecorder获取的Surface ID。 |
| callback | AsyncCallback<[VideoOutput](#videooutput)\> | 是 | 回调函数,用于获取VideoOutput实例。 |
**示例:**
```
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');
});
```
## camera.createVideoOutput
createVideoOutput(surfaceId: string): Promise<VideoOutput\>
获取VideoOutput实例,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| --------- | ------ | ---- | --------------------------------- |
| surfaceId | string | 是 | 从VideoRecorder获取的Surface ID。 |
**返回值:**
| 类型 | 说明 |
| ------------------------------------- | -------------------------------------- |
| Promise<[VideoOutput](#videooutput)\> | 使用Promise的方式获取VideoOutput实例。 |
**示例:**
```
camera.createVideoOutput(surfaceId).then((videoOutput) => {
console.log('Promise returned with the VideoOutput instance');
})
```
## VideoOutput
视频输出类。
### start
start(callback: AsyncCallback<void\>): void
开始拍摄视频,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```
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
start(): Promise<void\>
开始拍摄视频,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 |
**示例:**
```
videoOutput.start().then(() => {
console.log('Promise returned to indicate that start method execution success.');
})
```
### stop
stop(callback: AsyncCallback<void\>): void
停止拍摄视频,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```
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
stop(): Promise<void\>
停止拍摄视频,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 |
**示例:**
```
videoOutput.start().then(() => {
console.log('Promise returned to indicate that stop method execution success.');
})
```
### release
release(callback: AsyncCallback<void\>): void
释放VideoOutput实例,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```
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
release(): Promise<void\>
释放VideoOutput实例,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 |
**示例:**
```
videoOutput.release().then(() => {
console.log('Promise returned to indicate that the VideoOutput instance is released successfully.');
})
```
### on('frameStart')
on(type: 'frameStart', callback: AsyncCallback<void\>): void
监听视频帧开启,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| :------- | :------------------- | :--- | :----------------------------------------------- |
| type | string | 是 | 监听事件,固定为'frameStart',即视频帧开启事件。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```
videoOutput.on('frameStart', () => {
console.log('Video frame started');
})
```
### on('frameEnd')
on(type: 'frameEnd', callback: AsyncCallback<void\>): void
监听视频帧结束,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| :------- | :------------------- | :--- | :--------------------------------------------- |
| type | string | 是 | 监听事件,固定为'frameEnd',即视频帧结束事件。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```
videoOutput.on('frameEnd', () => {
console.log('Video frame ended');
})
```
### on('error')
on(type: 'error', callback: ErrorCallback<VideoOutputError\>): void
监听视频输出的错误事件,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| :------- | :-------------------------- | :--- | :-------------------------------------------- |
| type | string | 是 | 监听事件,固定为'error',即视频输出错误事件。 |
| callback | Callback<VideoOutputError\> | 是 | 回调函数,用于获取错误信息。 |
**示例:**
```
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.
先完成此消息的编辑!
想要评论请 注册