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