提交 5644ab36 编写于 作者: M mali

Camera development and interface document update

Signed-off-by: Nmali <mali81@huawei.com>
上级 b3707f9f
...@@ -8,7 +8,7 @@ OpenHarmony相机模块支持相机业务的开发,开发者可以通过已开 ...@@ -8,7 +8,7 @@ OpenHarmony相机模块支持相机业务的开发,开发者可以通过已开
- **相机静态能力**:用于描述相机的固有能力的一系列参数,比如朝向、支持的分辨率等信息。 - **相机静态能力**:用于描述相机的固有能力的一系列参数,比如朝向、支持的分辨率等信息。
- **物理相机**:物理相机就是独立的实体摄像头设备。物理相机ID是用于标志每个物理摄像头的唯一字串。 - **物理相机**:物理相机就是独立的实体摄像头设备。物理相机ID是用于标志每个物理摄像头的唯一字串。
- **异步操作**:为保证UI线程不被阻塞,大部分Camera调用都是异步的。对于每个API均提供了callback函数和Promise函数。 - **异步操作**:为保证UI线程不被阻塞,部分Camera接口采用异步调用方式。异步方式API均提供了callback函数和Promise函数。
## 开发步骤 ## 开发步骤
...@@ -60,70 +60,99 @@ import media from '@ohos.multimedia.media' ...@@ -60,70 +60,99 @@ import media from '@ohos.multimedia.media'
// 创建CameraManager对象 // 创建CameraManager对象
context: any = getContext(this) context: any = getContext(this)
let cameraManager = await camera.getCameraManager(this.context) let cameraManager = camera.getCameraManager(this.context)
if (!cameraManager) { if (!cameraManager) {
console.error('Failed to get the CameraManager instance'); console.error("camera.getCameraManager error")
return;
} }
// 监听相机状态变化
cameraManager.on('cameraStatus', (cameraStatusInfo) => {
console.log(`camera : ${cameraStatusInfo.camera.cameraId}`);
console.log(`status: ${cameraStatusInfo.status}`);
})
// 获取相机列表 // 获取相机列表
let cameraArray = await cameraManager.getSupportedCameras() let cameraArray = cameraManager.getSupportedCameras();
if (!cameraArray) { if (cameraArray.length <= 0) {
console.error('Failed to get the cameras'); console.error("cameraManager.getSupportedCameras error")
return;
} }
for (let index = 0; index < cameraArray.length; index++) { for (let index = 0; index < cameraArray.length; index++) {
console.log('cameraId : ' + cameraArray[index].cameraId) // 获取相机ID console.log('cameraId : ' + cameraArray[index].cameraId); // 获取相机ID
console.log('cameraPosition : ' + cameraArray[index].cameraPosition) // 获取相机位置 console.log('cameraPosition : ' + cameraArray[index].cameraPosition); // 获取相机位置
console.log('cameraType : ' + cameraArray[index].cameraType) // 获取相机类型 console.log('cameraType : ' + cameraArray[index].cameraType); // 获取相机类型
console.log('connectionType : ' + cameraArray[index].connectionType) // 获取相机连接类型 console.log('connectionType : ' + cameraArray[index].connectionType); // 获取相机连接类型
} }
// 创建相机输入流 // 创建相机输入流
let cameraInput = await cameraManager.createCameraInput(cameraArray[0]) let cameraInput
try {
cameraInput = cameraManager.createCameraInput(cameraArray[0]);
} catch () {
console.error('Failed to createCameraInput errorCode = ' + error.code);
}
// 监听cameraInput错误信息
let cameraDevice = cameraArray[0];
cameraInput.on('error', cameraDevice, (error) => {
console.log(`Camera input error code: ${error.code}`);
})
// 打开相机
await cameraInput.open();
// 获取相机设备支持的输出流能力 // 获取相机设备支持的输出流能力
let cameraOutputCap = await cameraManager.getSupportedOutputCapability(cameraArray[0]); let cameraOutputCap = cameraManager.getSupportedOutputCapability(cameraArray[0]);
if (!cameraOutputCap) { if (!cameraOutputCap) {
console.error("outputCapability outputCapability == null || undefined") console.error("cameraManager.getSupportedOutputCapability error")
} else { return;
console.info("outputCapability: " + JSON.stringify(cameraOutputCap));
} }
console.info("outputCapability: " + JSON.stringify(cameraOutputCap));
let previewProfilesArray = cameraOutputCap.GetPreviewProfiles(); let previewProfilesArray = cameraOutputCap.previewProfiles;
if (!previewProfilesArray) { if (!previewProfilesArray) {
console.error("createOutput previewProfilesArray == null || undefined") console.error("createOutput previewProfilesArray == null || undefined")
} }
let photoProfilesArray = cameraOutputCap.GetPhotoProfiles(); let photoProfilesArray = cameraOutputCap.photoProfiles;
if (!photoProfilesArray) { if (!photoProfilesArray) {
console.error("createOutput photoProfilesArray == null || undefined") console.error("createOutput photoProfilesArray == null || undefined")
} }
let videoProfilesArray = cameraOutputCap.GetVideoProfiles(); let videoProfilesArray = cameraOutputCap.videoProfiles;
if (!videoProfilesArray) { if (!videoProfilesArray) {
console.error("createOutput videoProfilesArray == null || undefined") console.error("createOutput videoProfilesArray == null || undefined")
} }
let metadataObjectTypesArray = cameraOutputCap.GetSupportedMetadataObjectType(); let metadataObjectTypesArray = cameraOutputCap.supportedMetadataObjectTypes;
if (!metadataObjectTypesArray) { if (!metadataObjectTypesArray) {
console.error("createOutput metadataObjectTypesArray == null || undefined") console.error("createOutput metadataObjectTypesArray == null || undefined")
} }
// 创建预览输出流,其中参数 surfaceId 参考下面 XComponent 组件,预览流为XComponent组件提供的surface // 创建预览输出流,其中参数 surfaceId 参考下面 XComponent 组件,预览流为XComponent组件提供的surface
let previewOutput = await cameraManager.createPreviewOutput(previewProfilesArray[0], surfaceId) let previewOutput
if (!previewOutput) { try {
previewOutput = cameraManager.createPreviewOutput(previewProfilesArray[0], surfaceId)
} catch (error) {
console.error("Failed to create the PreviewOutput instance.") console.error("Failed to create the PreviewOutput instance.")
} }
// 监听预览输出错误信息
previewOutput.on('error', (error) => {
console.log(`Preview output error code: ${error.code}`);
})
// 创建ImageReceiver对象,并设置照片参数:分辨率大小是根据前面 photoProfilesArray 获取的当前设备所支持的拍照分辨率大小去设置 // 创建ImageReceiver对象,并设置照片参数:分辨率大小是根据前面 photoProfilesArray 获取的当前设备所支持的拍照分辨率大小去设置
let imageReceiver = await image.createImageReceiver(1920, 1080, 4, 8) let imageReceiver = await image.createImageReceiver(1920, 1080, 4, 8)
// 获取照片显示SurfaceId // 获取照片显示SurfaceId
let photoSurfaceId = await imageReceiver.getReceivingSurfaceId() let photoSurfaceId = await imageReceiver.getReceivingSurfaceId()
// 创建拍照输出流 // 创建拍照输出流
let photoOutput = await cameraManager.createPhotoOutput(photoProfilesArray[0], photoSurfaceId) let photoOutput
if (!photoOutput) { try {
console.error('Failed to create the PhotoOutput instance.'); photoOutput = cameraManager.createPhotoOutput(photoProfilesArray[0], photoSurfaceId)
return; } catch (error) {
console.error('Failed to createPhotoOutput errorCode = ' + error.code);
} }
// 创建视频录制的参数 // 创建视频录制的参数
...@@ -166,11 +195,17 @@ videoRecorder.getInputSurface().then((id) => { ...@@ -166,11 +195,17 @@ videoRecorder.getInputSurface().then((id) => {
}) })
// 创建VideoOutput对象 // 创建VideoOutput对象
let videoOutput = await cameraManager.createVideoOutput(videoProfilesArray[0], videoSurfaceId) let videoOutput
if (!videoOutput) { try {
console.error('Failed to create the videoOutput instance.'); videoOutput = cameraManager.createVideoOutput(videoProfilesArray[0], videoSurfaceId)
return; } catch (error) {
console.error('Failed to create the videoOutput instance. errorCode = ' + error.code);
} }
// 监听视频输出错误信息
videoOutput.on('error', (error) => {
console.log(`Preview output error code: ${error.code}`);
})
``` ```
预览流、拍照流和录像流的输入均需要提前创建surface,其中预览流为XComponent组件提供的surface,拍照流为ImageReceiver提供的surface,录像流为VideoRecorder的surface。 预览流、拍照流和录像流的输入均需要提前创建surface,其中预览流为XComponent组件提供的surface,拍照流为ImageReceiver提供的surface,录像流为VideoRecorder的surface。
...@@ -244,24 +279,45 @@ function getVideoRecorderSurface() { ...@@ -244,24 +279,45 @@ function getVideoRecorderSurface() {
```typescript ```typescript
//创建会话 //创建会话
let captureSession = await camera.createCaptureSession() let captureSession
if (!captureSession) { try {
console.error('Failed to create the CaptureSession instance.'); captureSession = cameraManager.createCaptureSession()
return; } catch (error) {
console.error('Failed to create the CaptureSession instance. errorCode = ' + error.code);
} }
console.log('Callback returned with the CaptureSession instance.' + session);
// 监听session错误信息
captureSession.on('error', (error) => {
console.log(`Capture session error code: ${error.code}`);
})
// 开始配置会话 // 开始配置会话
await captureSession.beginConfig() try {
captureSession.beginConfig()
} catch (error) {
console.error('Failed to beginConfig. errorCode = ' + error.code);
}
// 向会话中添加相机输入流 // 向会话中添加相机输入流
await captureSession.addInput(cameraInput) try {
captureSession.addInput(cameraInput)
} catch (error) {
console.error('Failed to addInput. errorCode = ' + error.code);
}
// 向会话中添加预览输入流 // 向会话中添加预览输入流
await captureSession.addOutput(previewOutput) try {
captureSession.addOutput(previewOutput)
} catch (error) {
console.error('Failed to addOutput(previewOutput). errorCode = ' + error.code);
}
// 向会话中添加拍照输出流 // 向会话中添加拍照输出流
await captureSession.addOutput(photoOutput) try {
captureSession.addOutput(photoOutput)
} catch (error) {
console.error('Failed to addOutput(photoOutput). errorCode = ' + error.code);
}
// 提交会话配置 // 提交会话配置
await captureSession.commitConfig() await captureSession.commitConfig()
...@@ -279,13 +335,25 @@ await captureSession.start().then(() => { ...@@ -279,13 +335,25 @@ await captureSession.start().then(() => {
await captureSession.stop() await captureSession.stop()
// 开始配置会话 // 开始配置会话
await captureSession.beginConfig() try {
captureSession.beginConfig()
} catch (error) {
console.error('Failed to beginConfig. errorCode = ' + error.code);
}
// 从会话中移除拍照输出流 // 从会话中移除拍照输出流
await captureSession.removeOutput(photoOutput) try {
captureSession.removeOutput(photoOutput)
} catch (error) {
console.error('Failed to removeOutput(photoOutput). errorCode = ' + error.code);
}
// 向会话中添加录像输出流 // 向会话中添加录像输出流
await captureSession.addOutput(videoOutput) try {
captureSession.addOutput(videoOutput)
} catch (error) {
console.error('Failed to addOutput(videoOutput). errorCode = ' + error.code);
}
// 提交会话配置 // 提交会话配置
await captureSession.commitConfig() await captureSession.commitConfig()
...@@ -300,71 +368,65 @@ await captureSession.start().then(() => { ...@@ -300,71 +368,65 @@ await captureSession.start().then(() => {
```typescript ```typescript
// 判断设备是否支持闪光灯 // 判断设备是否支持闪光灯
let flashStatus = await captureSession.hasFlash() let flashStatus
if (!flashStatus) { try {
console.error('Failed to check whether the device has the flash mode.'); flashStatus = captureSession.hasFlash()
} catch (error) {
console.error('Failed to hasFlash. errorCode = ' + error.code);
} }
console.log('Promise returned with the flash light support status:' + flashStatus); console.log('Promise returned with the flash light support status:' + flashStatus);
if (flashStatus) { if (flashStatus) {
// 判断是否支持自动闪光灯模式 // 判断是否支持自动闪光灯模式
let flashModeStatus let flashModeStatus
captureSession.isFlashModeSupported(camera.FlashMode.FLASH_MODE_AUTO, async (err, status) => { try {
if (err) { let status = captureSession.isFlashModeSupported(camera.FlashMode.FLASH_MODE_AUTO)
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);
flashModeStatus = status flashModeStatus = status
}) } catch (error) {
console.error('Failed to check whether the flash mode is supported. errorCode = ' + error.code);
}
if(flashModeStatus) { if(flashModeStatus) {
// 设置自动闪光灯模式 // 设置自动闪光灯模式
captureSession.setFlashMode(camera.FlashMode.FLASH_MODE_AUTO, async (err) => { try {
if (err) { captureSession.setFlashMode(camera.FlashMode.FLASH_MODE_AUTO)
console.error('Failed to set the flash mode ${err.message}'); } catch (error) {
return; console.error('Failed to set the flash mode. errorCode = ' + error.code);
} }
console.log('Callback returned with the successful execution of setFlashMode.');
})
} }
} }
// 判断是否支持连续自动变焦模式 // 判断是否支持连续自动变焦模式
let focusModeStatus let focusModeStatus
captureSession.isFocusModeSupported(camera.FocusMode.FOCUS_MODE_CONTINUOUS_AUTO, async (err, status) => { try {
if (err) { let status = captureSession.isFocusModeSupported(camera.FocusMode.FOCUS_MODE_CONTINUOUS_AUTO)
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);
focusModeStatus = status focusModeStatus = status
}) } catch (error) {
console.error('Failed to check whether the focus mode is supported. errorCode = ' + error.code);
}
if (focusModeStatus) { if (focusModeStatus) {
// 设置连续自动变焦模式 // 设置连续自动变焦模式
captureSession.setFocusMode(camera.FocusMode.FOCUS_MODE_CONTINUOUS_AUTO, async (err) => { try {
if (err) { captureSession.setFocusMode(camera.FocusMode.FOCUS_MODE_CONTINUOUS_AUTO)
console.error('Failed to set the focus mode ${err.message}'); } catch (error) {
return; console.error('Failed to set the focus mode. errorCode = ' + error.code);
} }
console.log('Callback returned with the successful execution of setFocusMode.');
})
} }
// 获取相机支持的可变焦距比范围 // 获取相机支持的可变焦距比范围
let zoomRatioRange = await captureSession.getZoomRatioRange() let zoomRatioRange
if (!zoomRatioRange) { try {
console.error('Failed to get the zoom ratio range.'); zoomRatioRange = captureSession.getZoomRatioRange()
return; } catch (error) {
console.error('Failed to get the zoom ratio range. errorCode = ' + error.code);
} }
// 设置可变焦距比 // 设置可变焦距比
captureSession.setZoomRatio(zoomRatioRange[0], async (err) => { try {
if (err) { captureSession.setZoomRatio(zoomRatioRange[0])
console.error('Failed to set the zoom ratio value ${err.message}'); } catch (error) {
return; console.error('Failed to set the zoom ratio value. errorCode = ' + error.code);
} }
console.log('Callback returned with the successful execution of setZoomRatio.');
})
``` ```
#### 拍照 #### 拍照
...@@ -425,7 +487,7 @@ videoOutput.stop((err) => { ...@@ -425,7 +487,7 @@ videoOutput.stop((err) => {
captureSession.stop() captureSession.stop()
// 释放相机输入流 // 释放相机输入流
cameraInput.release() cameraInput.close()
// 释放预览输出流 // 释放预览输出流
previewOutput.release() previewOutput.release()
...@@ -446,4 +508,4 @@ captureSession = null ...@@ -446,4 +508,4 @@ captureSession = null
## 流程图 ## 流程图
应用使用相机的流程示意图如下 应用使用相机的流程示意图如下
![camera_framework process](figures/camera_framework_process.jpg) ![camera_framework process](figures/camera_framework_process.png)
\ No newline at end of file \ No newline at end of file
...@@ -12,9 +12,9 @@ import camera from '@ohos.multimedia.camera'; ...@@ -12,9 +12,9 @@ import camera from '@ohos.multimedia.camera';
## camera.getCameraManager ## camera.getCameraManager
getCameraManager(context: Context, callback: AsyncCallback<CameraManager\>): void getCameraManager(context: Context): CameraManager
获取相机管理器实例,通过注册回调函数获取结果。 获取相机管理器实例,同步返回结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
...@@ -23,46 +23,17 @@ getCameraManager(context: Context, callback: AsyncCallback<CameraManager\>): voi ...@@ -23,46 +23,17 @@ getCameraManager(context: Context, callback: AsyncCallback<CameraManager\>): voi
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------------- | ---- | ---------------------------- | | -------- | ----------------------------------------------- | ---- | ---------------------------- |
| context | [Context](js-apis-inner-app-context.md) | 是 | 应用上下文。 | | context | [Context](js-apis-inner-app-context.md) | 是 | 应用上下文。 |
| callback | AsyncCallback<[CameraManager](#cameramanager)\> | 是 | 回调函数,用于获取相机管理器实例。 |
**示例:**
```js
camera.getCameraManager(context, (err, cameraManager) => {
if (err) {
console.error(`Failed to get the CameraManager instance ${err.message}`);
return;
}
console.log('Callback returned with the CameraManager instance');
});
```
## camera.getCameraManager
getCameraManager(context: Context): Promise<CameraManager\>
获取相机管理器实例,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------- | ------- | ---- | ------------ |
| context | [Context](js-apis-inner-app-context.md) | 是 | 应用上下文。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ----------------------------------------- | ----------------------------------- | | ----------------------------------------------- | ---------------------------- |
| Promise<[CameraManager](#cameramanager)\> | 使用Promise的方式获取一个相机管理器实例。 | | [CameraManager](#cameramanager) | 相机管理器。 |
**示例:** **示例:**
```js ```js
camera.getCameraManager(context).then((cameraManager) => { let cameraManager = camera.getCameraManager(context);
console.log('Promise returned with the CameraManager instance.');
})
``` ```
## CameraStatus ## CameraStatus
...@@ -123,64 +94,54 @@ camera.getCameraManager(context).then((cameraManager) => { ...@@ -123,64 +94,54 @@ camera.getCameraManager(context).then((cameraManager) => {
| videoProfiles | Array<[VideoProfile](#videoprofile)\> | 是 | 支持的录像配置信息。 | | videoProfiles | Array<[VideoProfile](#videoprofile)\> | 是 | 支持的录像配置信息。 |
| supportedMetadataObjectTypes | Array<[MetadataObjectType](#metadataobjecttype)\> | 是 | 支持的metadata流类型信息。| | supportedMetadataObjectTypes | Array<[MetadataObjectType](#metadataobjecttype)\> | 是 | 支持的metadata流类型信息。|
## CameraManager ## CameraErrorCode
相机管理器类,使用前需要通过getCameraManager获取相机管理实例。
### getSupportedCameras
getSupportedCameras(callback: AsyncCallback<Array<CameraDevice\>\>): void
获取支持指定的相机设备对象,通过注册回调函数获取结果 相机错误码。接口使用不正确以及on接口监听error状态返回
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** | 名称 | 值 | 说明 |
| ------------------------- | ---- | ------------ |
| 参数名 | 类型 | 必填 | 说明 | | INVALID_ARGUMENT | 7400101 | 参数缺失或者参数类型不对。 |
| -------- | ----------------------------------------------------- | ---- | ------------------------------- | | OPERATION_NOT_ALLOWED | 7400102 | 操作流程不对,不允许。 |
| callback | AsyncCallback<Array<[CameraDevice](#cameradevice)\>\> | 是 | 使用callback方式获取支持的相机列表。 | | SESSION_NOT_CONFIG | 7400103 | session 未配置返回。 |
| SESSION_NOT_RUNNING | 7400104 | session 未运行返回。 |
| SESSION_CONFIG_LOCKED | 7400105 | session 配置已锁定返回。 |
| DEVICE_SETTING_LOCKED | 7400106 | 设备设置已锁定返回。 |
| CONFILICT_CAMERA | 7400107 | 设备重复打开返回。 |
| DEVICE_DISABLED | 7400108 | 安全原因摄像头被禁用。 |
| SERVICE_FATAL_ERROR | 7400201 | 相机服务错误返回。 |
**示例:** ## CameraManager
```js 相机管理器类,使用前需要通过getCameraManager获取相机管理实例。
cameraManager.getSupportedCameras((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}`);
})
```
### getSupportedCameras ### getSupportedCameras
getSupportedCameras(): Promise<Array<CameraDevice\>\> getSupportedCameras(): Array<CameraDevice\>
获取支持指定的相机设备对象,通过Promise获取结果。 获取支持指定的相机设备对象,同步返回结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ----------------------------------------------- | ------------------------- | | ----------------------------------------------- | ---------------------------- |
| Promise<Array<[CameraDevice](#cameradevice)\>\> | 使用promise获取支持相机列表。 | | Array<[CameraDevice](#cameradevice)> | 相机设备列表。 |
**示例:** **示例:**
```js ```js
cameraManager.getSupportedCameras().then((cameras) => { let cameras = cameraManager.getSupportedCameras();
console.log(`Promise returned with an array of supported cameras: ${cameras.length}`);
})
``` ```
### getSupportedOutputCapability ### getSupportedOutputCapability
getSupportedOutputCapability(camera:CameraDevice, callback: AsyncCallback<CameraOutputCapability\>): void getSupportedOutputCapability(cameraDevice:CameraDevice): CameraOutputCapability
查询相机设备在模式下支持的输出能力,通过注册回调函数获取结果。 查询相机设备在模式下支持的输出能力,同步返回结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
...@@ -189,52 +150,19 @@ getSupportedOutputCapability(camera:CameraDevice, callback: AsyncCallback<Camera ...@@ -189,52 +150,19 @@ getSupportedOutputCapability(camera:CameraDevice, callback: AsyncCallback<Camera
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ------------ |--------------------------------------------------------------- | -- | -------------------------- | | ------------ |--------------------------------------------------------------- | -- | -------------------------- |
| cameraDevice | [CameraDevice](#cameradevice) | 是 | 相机设备,通过 getSupportedCameras 接口获取 | | cameraDevice | [CameraDevice](#cameradevice) | 是 | 相机设备,通过 getSupportedCameras 接口获取 |
| callback | AsyncCallback<[CameraOutputCapability](#cameraoutputcapability)\> | 是 | 使用callback方式获取相机输出能力。 |
**示例:**
```js
cameraManager.getSupportedCameras().then((cameras) => {
let cameraDevice = cameras[0];
cameraManager.getSupportedOutputCapability(cameraDevice, (err, CameraOutputCapability) => {
if (err) {
console.error(`Failed to get the outputCapability. ${err.message}`);
return;
}
console.log('Callback returned with an array of supported outputCapability');
})
})
```
### getSupportedOutputCapability
getSupportedOutputCapability(camera:CameraDevice): Promise<CameraOutputCapability\>
查询相机设备在模式下支持的输出能力,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------- | ---- | ---------- |
| cameradevice | [CameraDevice](#cameradevice) | 是 | 相机设备,通过 getSupportedCameras 接口获取 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| -------------------------------------------------------------- | ----------------------------- | | ----------------------------------------------- | ---------------------------- |
| Promise<[CameraOutputCapability](#cameraoutputcapability)\> | 使用Promise的方式获取结果,返回相机输出能力。 | | [CameraOutputCapability](#cameraoutputcapability) | 相机输出能力。 |
**示例:** **示例:**
```js ```js
cameraManager.getSupportedCameras().then((cameras) => { let cameraDevice = cameras[0];
let cameraDevice = cameras[0]; let cameraOutputCapability = cameraManager.getSupportedOutputCapability(cameraDevice);
cameraManager.getSupportedOutputCapability(cameraDevice).then((cameraoutputcapability) => {
console.log('Promise returned with an array of supported outputCapability');
})
})
``` ```
### isCameraMuted ### isCameraMuted
...@@ -306,9 +234,9 @@ cameraManager.muteCamera(mute); ...@@ -306,9 +234,9 @@ cameraManager.muteCamera(mute);
### createCameraInput ### createCameraInput
createCameraInput(camera: CameraDevice, callback: AsyncCallback<CameraInput\>): void createCameraInput(camera: CameraDevice): CameraInput
使用CameraDevice对象异步创建CameraInput实例,通过注册回调函数获取结果。 使用CameraDevice对象创建CameraInput实例,同步返回结果。
**需要权限:** ohos.permission.CAMERA **需要权限:** ohos.permission.CAMERA
...@@ -319,57 +247,31 @@ createCameraInput(camera: CameraDevice, callback: AsyncCallback<CameraInput\>): ...@@ -319,57 +247,31 @@ createCameraInput(camera: CameraDevice, callback: AsyncCallback<CameraInput\>):
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------- | ---- | --------------------------------- | | -------- | ------------------------------------------- | ---- | --------------------------------- |
| cameraDevice | [CameraDevice](#cameradevice) | 是 | CameraDevice对象,通过 getSupportedCameras 接口获取 | | cameraDevice | [CameraDevice](#cameradevice) | 是 | CameraDevice对象,通过 getSupportedCameras 接口获取 |
| callback | AsyncCallback<[CameraInput](#camerainput)\> | 是 | 回调函数,用于获取CameraInput实例。 |
**示例:**
```js
let cameraDevice = cameras[0];
cameraManager.createCameraInput(cameraDevice, (err, cameraInput) => {
if (err) {
console.error(`Failed to create the CameraInput instance. ${err.message}`);
return;
}
console.log('Callback returned with the CameraInput instance.');
})
```
### createCameraInput
createCameraInput(cameraDevice: CameraDevice): Promise<CameraInput\>
使用CameraDevice对象异步创建CameraInput实例,通过Promise获取结果。
**需要权限:** ohos.permission.CAMERA
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------------- | ---- | ---------- |
| cameraDevice | [CameraDevice](#cameradevice) | 是 | CameraDevice对象,通过 getSupportedCameras 接口获取 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ------------------------------------- | ------------------------------------ | | ---------- | ----------------------------- |
| Promise<[CameraInput](#camerainput)\> | 使用Promise的方式获取CameraInput的实例。 | | [CameraInput](#camerainput) | CameraInput实例。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
```js ```js
let cameraDevice = cameras[0]; let cameraDevice = cameras[0];
cameraManager.createCameraInput(cameraDevice).then((cameraInput) => { let cameraInput;
console.log('Promise returned with the CameraInput instance'); try {
}) cameraInput = cameraManager.createCameraInput(cameraDevice);
} catch (error) {
// 失败返回错误码error.code并处理
console.log(error.code);
}
``` ```
### createCameraInput ### createCameraInput
createCameraInput(position: CameraPosition, type: CameraType, callback: AsyncCallback<CameraInput\>): void createCameraInput(position: CameraPosition, type: CameraType): CameraInput
根据相机位置和类型创建CameraInput实例,通过注册回调函数获取结果。 根据相机位置和类型创建CameraInput实例,同步返回结果。
**需要权限:** ohos.permission.CAMERA **需要权限:** ohos.permission.CAMERA
...@@ -381,45 +283,12 @@ createCameraInput(position: CameraPosition, type: CameraType, callback: AsyncCal ...@@ -381,45 +283,12 @@ createCameraInput(position: CameraPosition, type: CameraType, callback: AsyncCal
| -------- | ------------------------------------------- | ---- | --------------------------------- | | -------- | ------------------------------------------- | ---- | --------------------------------- |
| position | [CameraPosition](#cameraposition) | 是 | 相机位置,通过 getSupportedCameras 接口获取设备,然后获取设备位置信息 | | position | [CameraPosition](#cameraposition) | 是 | 相机位置,通过 getSupportedCameras 接口获取设备,然后获取设备位置信息 |
| type | [CameraType](#cameratype) | 是 | 相机类型,通过 getSupportedCameras 接口获取设备,然后获取设备类型信息 | | type | [CameraType](#cameratype) | 是 | 相机类型,通过 getSupportedCameras 接口获取设备,然后获取设备类型信息 |
| callback | AsyncCallback<[CameraInput](#camerainput)\> | 是 | 回调函数,用于获取CameraInput实例。 |
**示例:**
```js
let cameraDevice = cameras[0];
let position = cameraDevice.cameraPosition;
let type = cameraDevice.cameraType;
cameraManager.createCameraInput(position, type, (err, cameraInput) => {
if (err) {
console.error(`Failed to create the CameraInput instance. ${err.message}`);
return;
}
console.log('Callback returned with the CameraInput instance');
})
```
### createCameraInput
createCameraInput(position: CameraPosition, type:CameraType ): Promise<CameraInput\>
根据相机位置和类型创建CameraInput实例,通过Promise获取结果。
**需要权限:** ohos.permission.CAMERA
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------- | ---- | ------------ |
| position | [CameraPosition](#cameraposition) | 是 | 相机位置,通过 getSupportedCameras 接口获取设备,然后获取设备位置信息 |
| type | [CameraType](#cameratype) | 是 | 相机类型,通过 getSupportedCameras 接口获取设备,然后获取设备类型信息 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ------------------------------------- | ------------------------------------ | | ---------- | ----------------------------- |
| Promise<[CameraInput](#camerainput)\> | 使用Promise的方式获取CameraInput的实例。 | | [CameraInput](#camerainput) | CameraInput实例。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
...@@ -427,16 +296,20 @@ createCameraInput(position: CameraPosition, type:CameraType ): Promise<CameraInp ...@@ -427,16 +296,20 @@ createCameraInput(position: CameraPosition, type:CameraType ): Promise<CameraInp
let cameraDevice = cameras[0]; let cameraDevice = cameras[0];
let position = cameraDevice.cameraPosition; let position = cameraDevice.cameraPosition;
let type = cameraDevice.cameraType; let type = cameraDevice.cameraType;
cameraManager.createCameraInput(position, type).then((cameraInput) => { let cameraInput;
console.log('Promise returned with the CameraInput instance'); try {
}) cameraInput = cameraManager.createCameraInput(position, type);
} catch (error) {
// 失败返回错误码error.code并处理
console.log(error.code);
}
``` ```
### createPreviewOutput ### createPreviewOutput
createPreviewOutput(profile: Profile, surfaceId: string, callback: AsyncCallback<PreviewOutput\>): void createPreviewOutput(profile: Profile, surfaceId: string): PreviewOutput
创建预览输出对象,通过注册回调函数获取结果。 创建预览输出对象,同步返回结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
...@@ -446,56 +319,31 @@ createPreviewOutput(profile: Profile, surfaceId: string, callback: AsyncCallback ...@@ -446,56 +319,31 @@ createPreviewOutput(profile: Profile, surfaceId: string, callback: AsyncCallback
| -------- | ----------------------------------------------- | ---- | ------------------------------- | | -------- | ----------------------------------------------- | ---- | ------------------------------- |
| profile | [Profile](#profile) | 是 | 支持的预览配置信息,通过getSupportedOutputCapability接口获取。| | profile | [Profile](#profile) | 是 | 支持的预览配置信息,通过getSupportedOutputCapability接口获取。|
| surfaceId| string | 是 | 从[XComponent](../arkui-ts/ts-basic-components-xcomponent.md)或者[ImageReceiver](js-apis-image.md#imagereceiver9)组件获取的surfaceId。| | surfaceId| string | 是 | 从[XComponent](../arkui-ts/ts-basic-components-xcomponent.md)或者[ImageReceiver](js-apis-image.md#imagereceiver9)组件获取的surfaceId。|
| callback | AsyncCallback<[PreviewOutput](#previewoutput)\> | 是 | 回调函数,用于获取PreviewOutput实例。|
**示例:**
```js
let profile = cameraoutputcapability.previewProfiles[0];
cameraManager.createPreviewOutput(profile, surfaceId, (err, previewOutput) => {
if (err) {
console.error(`Failed to gcreate previewOutput. ${err.message}`);
return;
}
console.log('Callback returned with previewOutput created.');
})
```
### createPreviewOutput
createPreviewOutput(profile: Profile, surfaceId: string): Promise<PreviewOutput\>
创建预览输出对象,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------| ---- | ----------------- |
| profile | [Profile](#profile) | 是 | 支持的预览配置信息,通过getSupportedOutputCapability接口获取。|
| surfaceId| string | 是 | 从[XComponent](../arkui-ts/ts-basic-components-xcomponent.md)或者[ImageReceiver](js-apis-image.md#imagereceiver9)组件获取的surfaceId。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ---------------------------------------- | ---------------------------------------- | | ---------- | ----------------------------- |
| Promise<[PreviewOutput](#previewoutput)\> | 使用Promise的方式获取PreviewOutput的实例。 | | [PreviewOutput](#previewoutput) | PreviewOutput实例。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
```js ```js
let profile = cameraoutputcapability.previewProfiles[0]; let profile = cameraoutputcapability.previewProfiles[0];
cameraManager.createPreviewOutput(profile, surfaceId).then((previewOutput) => { let previewOutput;
console.log('Promise returned with previewOutput created.'); try {
}) previewOutput = cameraManager.createPreviewOutput(profile, surfaceId);
} catch (error) {
// 失败返回错误码error.code并处理
console.log(error.code);
}
``` ```
### createPhotoOutput ### createPhotoOutput
createPhotoOutput(profile: Profile, surfaceId: string, callback: AsyncCallback<PhotoOutput\>): void createPhotoOutput(profile: Profile, surfaceId: string): PhotoOutput
创建拍照输出对象,通过注册回调函数获取结果。 创建拍照输出对象,同步返回结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
...@@ -505,56 +353,31 @@ createPhotoOutput(profile: Profile, surfaceId: string, callback: AsyncCallback<P ...@@ -505,56 +353,31 @@ createPhotoOutput(profile: Profile, surfaceId: string, callback: AsyncCallback<P
| -------- | ------------------------------------------- | ---- | ----------------------------------- | | -------- | ------------------------------------------- | ---- | ----------------------------------- |
| profile | [Profile](#profile) | 是 | 支持的拍照配置信息,通过getSupportedOutputCapability接口获取。| | profile | [Profile](#profile) | 是 | 支持的拍照配置信息,通过getSupportedOutputCapability接口获取。|
| surfaceId| string | 是 | 从[ImageReceiver](js-apis-image.md#imagereceiver9)获取的surfaceId。| | surfaceId| string | 是 | 从[ImageReceiver](js-apis-image.md#imagereceiver9)获取的surfaceId。|
| callback | AsyncCallback<[PhotoOutput](#photooutput)\> | 是 | 回调函数,用于获取PhotoOutput实例。 |
**示例:**
```js
let profile = cameraoutputcapability.photoProfiles[0];
cameraManager.createPhotoOutput(profile, surfaceId, (err, photoOutput) => {
if (err) {
console.error(`Failed to create photoOutput. ${err.message}`);
return;
}
console.log('Callback returned with photoOutput created.');
})
```
### createPhotoOutput
createPhotoOutput(profile: Profile, surfaceId: string): Promise<PhotoOutput\>
创建拍照输出对象,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------| ---- | ----------- |
| profile | [Profile](#profile) | 是 | 支持的拍照配置信息,通过getSupportedOutputCapability接口获取。 |
| surfaceId| string | 是 | 从[ImageReceiver](js-apis-image.md#imagereceiver9)获取的surfaceId。|
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ------------------------------------- | -------------------------------------- | | ---------- | ----------------------------- |
| Promise<[PhotoOutput](#photooutput)\> | 使用Promise的方式获取PhotoOutput的实例。 | | [PhotoOutput](#photooutput) | PhotoOutput实例。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
```js ```js
let profile = cameraoutputcapability.photoProfiles[0]; let profile = cameraoutputcapability.photoProfiles[0];
cameraManager.createPhotoOutput(profile, surfaceId).then((photoOutput) => { let photoOutput;
console.log('Promise returned with photoOutput created.'); try {
}) photoOutput = cameraManager.createPhotoOutput(profile, surfaceId);
} catch (error) {
// 失败返回错误码error.code并处理
console.log(error.code);
}
``` ```
### createVideoOutput ### createVideoOutput
createVideoOutput(profile: VideoProfile, surfaceId: string, callback: AsyncCallback<VideoOutput\>): void createVideoOutput(profile: VideoProfile, surfaceId: string): VideoOutput
创建录像输出对象,通过注册回调函数获取结果。 创建录像输出对象,同步返回结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
...@@ -564,56 +387,31 @@ createVideoOutput(profile: VideoProfile, surfaceId: string, callback: AsyncCallb ...@@ -564,56 +387,31 @@ createVideoOutput(profile: VideoProfile, surfaceId: string, callback: AsyncCallb
| -------- | ------------------------------------------- | ---- | ------------------------------ | | -------- | ------------------------------------------- | ---- | ------------------------------ |
| profile | [VideoProfile](#videoprofile) | 是 | 支持的录像配置信息,通过getSupportedOutputCapability接口获取。 | | profile | [VideoProfile](#videoprofile) | 是 | 支持的录像配置信息,通过getSupportedOutputCapability接口获取。 |
| surfaceId| string | 是 | 从[VideoRecorder](js-apis-media.md#videorecorder9)获取的surfaceId。| | surfaceId| string | 是 | 从[VideoRecorder](js-apis-media.md#videorecorder9)获取的surfaceId。|
| callback | AsyncCallback<[VideoOutput](#videooutput)\> | 是 | 回调函数,用于获取VideoOutput实例。 |
**示例:**
```js
let profile = cameraoutputcapability.videoProfiles[0];
cameraManager.createVideoOutput(profile, surfaceId, (err, videoOutput) => {
if (err) {
console.error(`Failed to create videoOutput. ${err.message}`);
return;
}
console.log('Callback returned with an array of supported outputCapability' );
})
```
### createVideoOutput
createVideoOutput(profile: VideoProfile, surfaceId: string): Promise<VideoOutput\>
创建录像输出对象,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------| ---- | ---------- |
| profile | [VideoProfile](#videoprofile) | 是 | 支持的录像配置信息,通过getSupportedOutputCapability接口获取。 |
| surfaceId| string | 是 | 从[VideoRecorder](js-apis-media.md#videorecorder9)获取的surfaceId。|
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ------------------------------------- | -------------------------------------- | | ---------- | ----------------------------- |
| Promise<[VideoOutput](#videooutput)\> | 使用Promise的方式获取videoOutput的实例。 | | [VideoOutput](#videooutput) | VideoOutput实例。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
```js ```js
let profile = cameraoutputcapability.videoProfiles[0]; let profile = cameraoutputcapability.videoProfiles[0];
cameraManager.createVideoOutput(profile, surfaceId).then((videoOutput) => { let videoOutput;
console.log('Promise returned with videoOutput created.'); try {
}) videoOutput = cameraManager.createVideoOutput(profile, surfaceId);
} catch (error) {
// 失败返回错误码error.code并处理
console.log(error.code);
}
``` ```
### createMetadataOutput ### createMetadataOutput
createMetadataOutput(metadataObjectTypes:Array<MetadataObjectType\>, callback: AsyncCallback<MetadataOutput\>): void createMetadataOutput(metadataObjectTypes:Array<MetadataObjectType\>): MetadataOutput
创建metadata流输出对象,通过注册回调函数获取结果。 创建metadata流输出对象,同步返回结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
...@@ -622,103 +420,57 @@ createMetadataOutput(metadataObjectTypes:Array<MetadataObjectType\>, callback: A ...@@ -622,103 +420,57 @@ createMetadataOutput(metadataObjectTypes:Array<MetadataObjectType\>, callback: A
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------------------- | -------------------------------------------------- | --- | ---------------------------- | | -------------------- | -------------------------------------------------- | --- | ---------------------------- |
| metadataObjectTypes | Array<[MetadataObjectType](#metadataobjecttype)\> | 是 | metadata流类型信息,通过getSupportedOutputCapability接口获取。 | | metadataObjectTypes | Array<[MetadataObjectType](#metadataobjecttype)\> | 是 | metadata流类型信息,通过getSupportedOutputCapability接口获取。 |
| callback | AsyncCallback<[MetadataOutput](#metadataoutput)\> | 是 | 回调函数,用于获取MetadataOutput实例。 |
**示例:**
```js
let metadataObjectTypes = cameraoutputcapability.supportedMetadataObjectTypes;
cameraManager.createMetadataOutput(metadataObjectTypes, (err, metadataOutput) => {
if (err) {
console.error(`Failed to create metadataOutput. ${err.message}`);
return;
}
console.log('Callback returned with metadataOutput created.');
})
```
### createMetadataOutput
createMetadataOutput(metadataObjectTypes:Array<MetadataObjectType\>): Promise<MetadataOutput\>
创建metadata流输出对象,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------------------- | -------------------------------------------------- | --- | -------------------- |
| metadataObjectTypes | Array<[MetadataObjectType](#metadataobjecttype)\> | 是 | metadata流类型信息,通过getSupportedOutputCapability接口获取。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ------------------------------------------ | ----------------------------------------- | | ---------- | ----------------------------- |
| Promise<[MetadataOutput](#metadataoutput)\> | 使用Promise的方式获取MetadataOutput的实例。 | | [MetadataOutput](#metadataoutput) | MetadataOutput实例。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
```js ```js
let metadataObjectTypes = cameraoutputcapability.supportedMetadataObjectTypes; let metadataObjectTypes = cameraoutputcapability.supportedMetadataObjectTypes;
cameraManager.createMetadataOutput(metadataObjectTypes).then((metadataOutput) => { let metadataOutput;
console.log('Promise returned with metadataOutput created.'); try {
}) metadataOutput = cameraManager.createMetadataOutput(metadataObjectTypes);
} catch (error) {
// 失败返回错误码error.code并处理
console.log(error.code);
}
``` ```
### createCaptureSession ### createCaptureSession
createCaptureSession(callback: AsyncCallback<CaptureSession\>): void createCaptureSession(): CaptureSession
创建CaptureSession实例,通过注册回调函数获取结果。 创建CaptureSession实例,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------------------- | ----------------------------------------- | ----------- | ---------------------------- |
| callback | AsyncCallback<[CaptureSession](#capturesession)\> | 是 | 回调函数,用于获取拍照会话实例。 |
**示例:**
```js
cameraManager.createCaptureSession((err, captureSession) => {
if (err) {
console.error(`Failed to create captureSession. ${err.message}`);
return;
}
console.log('Callback returned with captureSession created.');
})
```
### createCaptureSession
createCaptureSession(): Promise<CaptureSession\>
创建CaptureSession实例,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ------------------------------------------- | ---------------------------------------- | | ---------- | ----------------------------- |
| Promise<[CaptureSession](#capturesession)\> | 使用Promise的方式获取CaptureSession的实例。 | | [CaptureSession](#capturesession) | CaptureSession实例。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
```js ```js
cameraManager.createCaptureSession().then((captureSession) => { let captureSession;
console.log('Promise returned with captureSession created.'); try {
}) captureSession = cameraManager.createCaptureSession();
} catch (error) {
// 失败返回错误码error.code并处理
console.log(error.code);
}
``` ```
### on('cameraStatus') ### on('cameraStatus')
on(type: 'cameraStatus', callback: AsyncCallback<CameraStatusInfo\>): void on(type: 'cameraStatus', callback: AsyncCallback<CameraStatusInfo\>): void
镜头状态回调,通过注册回调函数获取相机的状态变化。 相机设备状态回调,通过注册回调函数获取相机的状态变化。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
...@@ -726,17 +478,13 @@ on(type: 'cameraStatus', callback: AsyncCallback<CameraStatusInfo\>): void ...@@ -726,17 +478,13 @@ on(type: 'cameraStatus', callback: AsyncCallback<CameraStatusInfo\>): void
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------------------- | ---- | --------- | | -------- | ----------------------------------------------------- | ---- | --------- |
| type | string | 是 | 监听事件,固定为'cameraStatus',即镜头状态变化事件。 | | type | string | 是 | 监听事件,固定为'cameraStatus',callback返回相机设备信息,包含设备以及设备对应的状态(可用、不可用等),cameraManager对象获取成功可监听。 |
| callback | AsyncCallback<[CameraStatusInfo](#camerastatusinfo)\> | 是 | 回调函数,用于获取镜头状态变化信息。 | | callback | AsyncCallback<[CameraStatusInfo](#camerastatusinfo)\> | 是 | 回调函数,用于获取镜头状态变化信息。 |
**示例:** **示例:**
```js ```js
cameraManager.on('cameraStatus', (err, cameraStatusInfo) => { cameraManager.on('cameraStatus', (cameraStatusInfo) => {
if (err) {
console.error(`Failed to get cameraStatus callback. ${err.message}`);
return;
}
console.log(`camera : ${cameraStatusInfo.camera.cameraId}`); console.log(`camera : ${cameraStatusInfo.camera.cameraId}`);
console.log(`status: ${cameraStatusInfo.status}`); console.log(`status: ${cameraStatusInfo.status}`);
}) })
...@@ -756,17 +504,14 @@ on(type: 'cameraMute', callback: AsyncCallback<boolean\>): void ...@@ -756,17 +504,14 @@ on(type: 'cameraMute', callback: AsyncCallback<boolean\>): void
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------- | ---- | --------- | | -------- | --------------- | ---- | --------- |
| type | string | 是 | 监听事件,固定为'cameraMute',即禁用状态变化事件。 | | type | string | 是 | 监听事件,固定为'cameraMute',系统相机摄像头开关,callback返回开关状态变化信息,cameraManager对象获取成功可监听。 |
| callback | AsyncCallback<boolean> | 是 | 回调函数,用于获取禁用状态变化信息。 | | callback | AsyncCallback\<boolean> | 是 | 回调函数,用于获取禁用状态变化信息。 |
**示例:** **示例:**
```js ```js
cameraManager.on('cameraMute', (err, curMuetd) => { cameraManager.on('cameraMute', (curMuetd) => {
if (err) { let isMuted = curMuetd;
console.error(`Failed to get cameraMute callback. ${err.message}`);
return;
}
}) })
``` ```
...@@ -801,7 +546,7 @@ cameraManager.on('cameraMute', (err, curMuetd) => { ...@@ -801,7 +546,7 @@ cameraManager.on('cameraMute', (err, curMuetd) => {
| 名称 | 值 | 说明 | | 名称 | 值 | 说明 |
| ----------------------- | ---- | -------------- | | ----------------------- | ---- | -------------- |
| CAMERA_TYPE_UNSPECIFIED | 0 | 相机类型未指定。 | | CAMERA_TYPE_DEFAULT | 0 | 相机类型未指定。 |
| CAMERA_TYPE_WIDE_ANGLE | 1 | 广角相机。 | | CAMERA_TYPE_WIDE_ANGLE | 1 | 广角相机。 |
| CAMERA_TYPE_ULTRA_WIDE | 2 | 超广角相机。 | | CAMERA_TYPE_ULTRA_WIDE | 2 | 超广角相机。 |
| CAMERA_TYPE_TELEPHOTO | 3 | 长焦相机。 | | CAMERA_TYPE_TELEPHOTO | 3 | 长焦相机。 |
...@@ -882,14 +627,14 @@ open\(callback: AsyncCallback<void\>\): void ...@@ -882,14 +627,14 @@ open\(callback: AsyncCallback<void\>\): void
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------- | | -------- | -------------------- | ---- | ------------------- |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 | | callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
```js ```js
cameraInput.open((err) => { cameraInput.open((err) => {
if (err) { if (err) {
console.error(`Failed to open the camera. ${err.message}`); console.error(`Failed to open the camera. ${err.code}`);
return; return;
} }
console.log('Callback returned with camera opened.'); console.log('Callback returned with camera opened.');
...@@ -908,14 +653,16 @@ open(): Promise<void\> ...@@ -908,14 +653,16 @@ open(): Promise<void\>
| 类型 | 说明 | | 类型 | 说明 |
| -------------- | ----------------------- | | -------------- | ----------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 | | Promise<void\> | 使用Promise的方式获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
```js ```js
cameraInput.open().then(() => { cameraInput.open().then(() => {
console.log('Promise returned with camera opened.'); console.log('Promise returned with camera opened.');
}) }).catch((err) => {
console.error(`Failed to open the camera. ${err.code}`);
});
``` ```
### close ### close
...@@ -930,14 +677,14 @@ close\(callback: AsyncCallback<void\>\): void ...@@ -930,14 +677,14 @@ close\(callback: AsyncCallback<void\>\): void
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | -------------------- | | -------- | -------------------- | ---- | -------------------- |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 | | callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
```js ```js
cameraInput.close((err) => { cameraInput.close((err) => {
if (err) { if (err) {
console.error(`Failed to close the cameras. ${err.message}`); console.error(`Failed to close the cameras. ${err.code}`);
return; return;
} }
console.log('Callback returned with camera closed.'); console.log('Callback returned with camera closed.');
...@@ -963,60 +710,14 @@ close(): Promise<void\> ...@@ -963,60 +710,14 @@ close(): Promise<void\>
```js ```js
cameraInput.close().then(() => { cameraInput.close().then(() => {
console.log('Promise returned with camera closed.'); console.log('Promise returned with camera closed.');
}) }).catch((err) => {
console.error(`Failed to close the cameras. ${err.code}`);
});
``` ```
### release ### on('error')
release\(callback: AsyncCallback<void\>\): void on(type: 'error', cameraDevice:CameraDevice, callback: ErrorCallback<BusinessError\>): void
释放资源,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------- |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```js
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
release(): Promise<void\>
释放资源,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| -------------- | ----------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 |
**示例:**
```js
cameraInput.release().then(() => {
console.log('Promise returned to indicate that the CameraInput instance is released successfully.');
})
```
### on('error')
on(type: 'error', cameraDevice:CameraDevice, callback: ErrorCallback<CameraInputError\>): void
监听CameraInput的错误事件,通过注册回调函数获取结果。 监听CameraInput的错误事件,通过注册回调函数获取结果。
...@@ -1026,45 +727,19 @@ on(type: 'error', cameraDevice:CameraDevice, callback: ErrorCallback<CameraInput ...@@ -1026,45 +727,19 @@ on(type: 'error', cameraDevice:CameraDevice, callback: ErrorCallback<CameraInput
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------------------- | --- | ------------------------------------------- | | -------- | -------------------------------- | --- | ------------------------------------------- |
| type | string | 是 | 监听事件,固定为'error',即CameraInput错误事件。 | | type | string | 是 | 监听事件,固定为'error',callback返回错误码,比如(设备不可用或者冲突等返回对应错误码),CameraInput对象创建成功可监听。 |
| cameraDevice | [CameraDevice](#cameradevice) | 是 | CameraDevice对象。 | | cameraDevice | [CameraDevice](#cameradevice) | 是 | CameraDevice对象。 |
| callback | ErrorCallback<[CameraInputError](#camerainputerror)\> | 是 | 回调函数,用于获取结果。 | | callback | ErrorCallback<BusinessError\> | 是 | 回调函数,用于获取结果。返回错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
```js ```js
let cameraDevice = cameras[0]; let cameraDevice = cameras[0];
cameraInput.on('error', cameraDevice, (cameraInputError) => { cameraInput.on('error', cameraDevice, (error) => {
console.log(`Camera input error code: ${cameraInputError.code}`); console.log(`Camera input error code: ${error.code}`);
}) })
``` ```
## CameraInputErrorCode
枚举,[CameraInput](#camerainput)错误类型。
**系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 值 | 说明 |
| ------------------------- | ---- | ---------- |
| ERROR_UNKNOWN | -1 | 未知错误。 |
| ERROR_NO_PERMISSION | 0 | 没有权限。 |
| ERROR_DEVICE_PREEMPTED | 1 | 相机被抢占。 |
| ERROR_DEVICE_DISCONNECTED | 2 | 相机断开连接。 |
| ERROR_DEVICE_IN_USE | 3 | 相机正在使用。 |
| ERROR_DRIVER_ERROR | 4 | 驱动错误。 |
## CameraInputError
[CameraInput](#camerainput)错误码。
**系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 类型 | 必填 | 说明 |
| ---- | --------------------------------------------- | ------------ |--------------------- |
| code | [CameraInputErrorCode](#camerainputerrorcode) | 是 |CameraInput中的错误码。 |
## FlashMode ## FlashMode
枚举,闪光灯模式。 枚举,闪光灯模式。
...@@ -1135,56 +810,32 @@ cameraInput.on('error', cameraDevice, (cameraInputError) => { ...@@ -1135,56 +810,32 @@ cameraInput.on('error', cameraDevice, (cameraInputError) => {
### beginConfig ### beginConfig
beginConfig\(callback: AsyncCallback<void\>\): void beginConfig(): void
开始配置会话,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------- |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```js
captureSession.beginConfig((err) => {
if (err) {
console.error(`Failed to start the configuration. ${err.message}`);
return;
}
console.log('Callback invoked to indicate the begin config success.');
});
```
### beginConfig
beginConfig\(\): Promise<void\>
开始配置会话,通过Promise获取结果 开始配置会话。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| -------------- | ------------------------ | | ---------- | ----------------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 | | [CameraErrorCode](#cameraerrorcode) | 接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
```js ```js
captureSession.beginConfig().then(() => { try {
console.log('Promise returned to indicate the begin config success.'); captureSession.beginConfig();
}) } catch (error) {
// 失败返回错误码error.code并处理
console.log(error.code);
}
``` ```
### commitConfig ### commitConfig
commitConfig\(callback: AsyncCallback<void\>\): void commitConfig(callback: AsyncCallback<void\>): void
提交配置信息,通过注册回调函数获取结果。 提交配置信息,通过注册回调函数获取结果。
...@@ -1194,14 +845,14 @@ commitConfig\(callback: AsyncCallback<void\>\): void ...@@ -1194,14 +845,14 @@ commitConfig\(callback: AsyncCallback<void\>\): void
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | -------------------- | | -------- | -------------------- | ---- | -------------------- |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 | | callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
```js ```js
captureSession.commitConfig((err) => { captureSession.commitConfig((err) => {
if (err) { if (err) {
console.error(`Failed to commit the configuration. ${err.message}`); console.log('Failed to commitConfig '+ err.code);
return; return;
} }
console.log('Callback invoked to indicate the commit config success.'); console.log('Callback invoked to indicate the commit config success.');
...@@ -1210,7 +861,7 @@ captureSession.commitConfig((err) => { ...@@ -1210,7 +861,7 @@ captureSession.commitConfig((err) => {
### commitConfig ### commitConfig
commitConfig\(\): Promise<void\> commitConfig(): Promise<void\>
提交配置信息,通过Promise获取结果。 提交配置信息,通过Promise获取结果。
...@@ -1220,48 +871,24 @@ commitConfig\(\): Promise<void\> ...@@ -1220,48 +871,24 @@ commitConfig\(\): Promise<void\>
| 类型 | 说明 | | 类型 | 说明 |
| -------------- | ------------------------ | | -------------- | ------------------------ |
| Promise<void\> | 使用Promise的方式获取结果。 | | Promise<void\> | 使用Promise的方式获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
```js ```js
captureSession.commitConfig().then(() => { captureSession.commitConfig().then(() => {
console.log('Promise returned to indicate the commit config success.'); console.log('Promise returned to indicate the commit config success.');
}) }).catch((err) => {
``` // 失败返回错误码error.code并处理
console.log('Failed to commitConfig '+ err.code);
### addInput
addInput\(cameraInput: CameraInput, callback: AsyncCallback<void\>\): void
[CameraInput](#camerainput)加入到会话,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ----------- | --------------------------- | ---- | ------------------------ |
| cameraInput | [CameraInput](#camerainput) | 是 | 需要添加的CameraInput实例。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```js
captureSession.addInput(cameraInput, (err) => {
if (err) {
console.error(`Failed to add the CameraInput instance. ${err.message}`);
return;
}
console.log('Callback invoked to indicate that the CameraInput instance is added.');
}); });
``` ```
### addInput ### addInput
addInput\(cameraInput: CameraInput\): Promise<void\> addInput(cameraInput: CameraInput): void
[CameraInput](#camerainput)加入到会话,通过Promise获取结果 [CameraInput](#camerainput)加入到会话。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
...@@ -1274,49 +901,25 @@ addInput\(cameraInput: CameraInput\): Promise<void\> ...@@ -1274,49 +901,25 @@ addInput\(cameraInput: CameraInput\): Promise<void\>
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| -------------- | ------------------------ | | ---------- | ----------------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 | | [CameraErrorCode](#cameraerrorcode) | 接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:**
```js
captureSession.addInput(cameraInput).then(() => {
console.log('Promise used to indicate that the CameraInput instance is added.');
})
```
### removeInput
removeInput\(cameraInput: CameraInput, callback: AsyncCallback<void\>\): void
移除[CameraInput](#camerainput),通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ----------- | --------------------------- | ---- | ------------------------ |
| cameraInput | [CameraInput](#camerainput) | 是 | 需要移除的CameraInput实例。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:** **示例:**
```js ```js
captureSession.removeInput(cameraInput, (err) => { try {
if (err) { captureSession.addInput(cameraInput);
console.error(`Failed to remove the CameraInput instance. ${err.message}`); } catch (error) {
return; // 失败返回错误码error.code并处理
} console.log(error.code);
console.log('Callback invoked to indicate that the cameraInput instance is removed.'); }
});
``` ```
### removeInput ### removeInput
removeInput\(cameraInput: CameraInput\): Promise<void\> removeInput(cameraInput: CameraInput): void
移除[CameraInput](#camerainput),通过Promise获取结果 移除[CameraInput](#camerainput)
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
...@@ -1329,22 +932,25 @@ removeInput\(cameraInput: CameraInput\): Promise<void\> ...@@ -1329,22 +932,25 @@ removeInput\(cameraInput: CameraInput\): Promise<void\>
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| -------------- | ------------------------- | | ---------- | ----------------------------- |
| Promise\<void\> | 使用Promise的方式获取结果。 | | [CameraErrorCode](#cameraerrorcode) | 接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
```js ```js
captureSession.removeInput(cameraInput).then(() => { try {
console.log('Promise returned to indicate that the cameraInput instance is removed.'); captureSession.removeInput(cameraInput);
}) } catch (error) {
// 失败返回错误码error.code并处理
console.log(error.code);
}
``` ```
### addOutput ### addOutput
addOutput\(previewOutput: CameraOutput, callback: AsyncCallback<void\>\): void addOutput(previewOutput: CameraOutput): void
[CameraOutput](#cameraoutput)加入到会话,通过注册回调函数获取结果 [CameraOutput](#cameraoutput)加入到会话。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
...@@ -1353,53 +959,29 @@ addOutput\(previewOutput: CameraOutput, callback: AsyncCallback<void\>\): void ...@@ -1353,53 +959,29 @@ addOutput\(previewOutput: CameraOutput, callback: AsyncCallback<void\>\): void
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ------------- | ------------------------------- | ---- | ------------------------ | | ------------- | ------------------------------- | ---- | ------------------------ |
| previewOutput | [PreviewOutput](#previewoutput) | 是 | 需要添加的previewoutput实例。 | | previewOutput | [PreviewOutput](#previewoutput) | 是 | 需要添加的previewoutput实例。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```js
captureSession.addOutput(previewOutput, (err) => {
if (err) {
console.error(`Failed to add output. ${err.message}`);
return;
}
console.log('Callback returned with output added.');
})
```
### addOutput
addOutput\(previewOutput: CameraOutput\): Promise<void\>
[CameraOutput](#cameraoutput)加入到会话,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------------- | ------------------------------- | ---- | ------------------------- |
| previewOutput | [PreviewOutput](#previewoutput) | 是 | 需要添加的previewOutput实例。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| -------------- | ----------------------- | | ---------- | ----------------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 | | [CameraErrorCode](#cameraerrorcode) | 接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
```js ```js
captureSession.addOutput(previewOutput).then(() => { try {
console.log('Promise returned with cameraOutput added.'); captureSession.addOutput(previewOutput);
}) } catch (error) {
// 失败返回错误码error.code并处理
console.log(error.code);
}
``` ```
### removeOutput ### removeOutput
removeOutput\(previewOutput: CameraOutput, callback: AsyncCallback<void\>\): void removeOutput(previewOutput: CameraOutput): void
从会话中移除[CameraOutput](#cameraoutput),通过注册回调函数获取结果 从会话中移除[CameraOutput](#cameraoutput)
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
...@@ -1408,48 +990,22 @@ removeOutput\(previewOutput: CameraOutput, callback: AsyncCallback<void\>\): voi ...@@ -1408,48 +990,22 @@ removeOutput\(previewOutput: CameraOutput, callback: AsyncCallback<void\>\): voi
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ------------- | ------------------------------- | ---- | ------------------------ | | ------------- | ------------------------------- | ---- | ------------------------ |
| previewOutput | [PreviewOutput](#previewoutput) | 是 | 需要移除的previewoutput实例。 | | previewOutput | [PreviewOutput](#previewoutput) | 是 | 需要移除的previewoutput实例。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```js
captureSession.removeOutput(previewOutput, (err) => {
if (err) {
console.error(`Failed to remove the CameraOutput instance. ${err.message}`);
return;
}
console.log('Callback invoked to indicate that the CameraOutput instance is removed.');
});
```
### removeOutput
removeOutput(previewOutput: CameraOutput): Promise<void\>
从会话中移除[CameraOutput](#cameraoutput),通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------------- | ------------------------------- | ---- | ------------------------- |
| previewOutput | [PreviewOutput](#previewoutput) | 是 | 需要移除的previewoutput实例。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| -------------- | ------------------------ | | ---------- | ----------------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 | | [CameraErrorCode](#cameraerrorcode) | 接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
```js ```js
captureSession.removeOutput(previewOutput).then(() => { try {
console.log('Promise returned to indicate that the CameraOutput instance is removed.'); captureSession.removeOutput(previewOutput);
}) } catch (error) {
// 失败返回错误码error.code并处理
console.log(error.code);
}
``` ```
### start ### start
...@@ -1464,14 +1020,14 @@ start\(callback: AsyncCallback<void\>\): void ...@@ -1464,14 +1020,14 @@ start\(callback: AsyncCallback<void\>\): void
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | -------------------- | | -------- | -------------------- | ---- | -------------------- |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 | | callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
```js ```js
captureSession.start((err) => { captureSession.start((err) => {
if (err) { if (err) {
console.error(`Failed to start the session ${err.message}`); console.error(`Failed to start the session ${err.code}`);
return; return;
} }
console.log('Callback invoked to indicate the session start success.'); console.log('Callback invoked to indicate the session start success.');
...@@ -1497,7 +1053,9 @@ start\(\): Promise<void\> ...@@ -1497,7 +1053,9 @@ start\(\): Promise<void\>
```js ```js
captureSession.start().then(() => { captureSession.start().then(() => {
console.log('Promise returned to indicate the session start success.'); console.log('Promise returned to indicate the session start success.');
}) }).catch((err) => {
console.error(`Failed to start the session ${err.code}`);
});
``` ```
### stop ### stop
...@@ -1512,14 +1070,14 @@ stop\(callback: AsyncCallback<void\>\): void ...@@ -1512,14 +1070,14 @@ stop\(callback: AsyncCallback<void\>\): void
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------- | | -------- | -------------------- | ---- | ------------------- |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 | | callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
```js ```js
captureSession.stop((err) => { captureSession.stop((err) => {
if (err) { if (err) {
console.error(`Failed to stop the session ${err.message}`); console.error(`Failed to stop the session ${err.code}`);
return; return;
} }
console.log('Callback invoked to indicate the session stop success.'); console.log('Callback invoked to indicate the session stop success.');
...@@ -1538,14 +1096,16 @@ stop(): Promise<void\> ...@@ -1538,14 +1096,16 @@ stop(): Promise<void\>
| 类型 | 说明 | | 类型 | 说明 |
| -------------- | ----------------------- | | -------------- | ----------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 | | Promise<void\> | 使用Promise的方式获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
```js ```js
captureSession.stop().then(() => { captureSession.stop().then(() => {
console.log('Promise returned to indicate the session stop success.'); console.log('Promise returned to indicate the session stop success.');
}) }).catch((err) => {
console.error(`Failed to stop the session ${err.code}`);
});
``` ```
### release ### release
...@@ -1560,14 +1120,14 @@ release\(callback: AsyncCallback<void\>\): void ...@@ -1560,14 +1120,14 @@ release\(callback: AsyncCallback<void\>\): void
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | -------------------- | | -------- | -------------------- | ---- | -------------------- |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 | | callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
```js ```js
captureSession.release((err) => { captureSession.release((err) => {
if (err) { if (err) {
console.error(`Failed to release the CaptureSession instance ${err.message}`); console.error(`Failed to release the CaptureSession instance ${err.code}`);
return; return;
} }
console.log('Callback invoked to indicate that the CaptureSession instance is released successfully.'); console.log('Callback invoked to indicate that the CaptureSession instance is released successfully.');
...@@ -1586,1247 +1146,671 @@ release(): Promise<void\> ...@@ -1586,1247 +1146,671 @@ release(): Promise<void\>
| 类型 | 说明 | | 类型 | 说明 |
| -------------- | ------------------------ | | -------------- | ------------------------ |
| Promise<void\> | 使用Promise的方式获取结果。 | | Promise<void\> | 使用Promise的方式获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
```js ```js
captureSession.release().then(() => { captureSession.release().then(() => {
console.log('Promise returned to indicate that the CaptureSession instance is released successfully.'); console.log('Promise returned to indicate that the CaptureSession instance is released successfully.');
}) }).catch((err) => {
console.error(`Failed to release the CaptureSession instance ${err.code}`);
});
``` ```
### hasFlash ### hasFlash
hasFlash(callback: AsyncCallback<boolean\>): void hasFlash(): boolean
检测是否有闪光灯,通过注册回调函数获取结果。 检测是否有闪光灯,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **返回值:**
| 参数名 | 类型 | 必填 | 说明 | | 类型 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------- | | ---------- | ----------------------------- |
| callback | AsyncCallback<boolean\> | 是 | 回调函数,返回true表示设备支持闪光灯。 | | boolean | 返回true表示设备支持闪光灯。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
```js ```js
captureSession.hasFlash((err, status) => { try {
if (err) { let status = captureSession.hasFlash();
console.error(`Failed to check whether the device has flash light. ${err.message}`); } catch (error) {
return; // 失败返回错误码error.code并处理
} console.log(error.code);
console.log(`Callback returned with flash light support status: ${status}`); }
})
``` ```
### hasFlash ### isFlashModeSupported
hasFlash(): Promise<boolean\> isFlashModeSupported(flashMode: FlashMode): boolean
检测是否有闪光灯,通过Promise获取结果 检测闪光灯模式是否支持
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ----------------------- | ---- | --------------------------------- |
| flashMode | [FlashMode](#flashmode) | 是 | 指定闪光灯模式。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ----------------- | ----------------------------------------------- | | ---------- | ----------------------------- |
| Promise<boolean\> | 使用Promise的方式获取结果,返回true表示设备支持闪光灯。 | | boolean | 返回true表示支持该闪光灯模式。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
```js ```js
captureSession.hasFlash().then((status) => { try {
console.log(`Promise returned with the flash light support status: ${status}`); let status = captureSession.isFlashModeSupported(camera.FlashMode.FLASH_MODE_AUTO);
}) } catch (error) {
// 失败返回错误码error.code并处理
console.log(error.code);
}
``` ```
### isFlashModeSupported ### setFlashMode
setFlashMode(flashMode: FlashMode): void
设置闪光灯模式。
isFlashModeSupported(flashMode: FlashMode, callback: AsyncCallback<boolean\>): void 进行设置之前,需要先检查:
检测闪光灯模式是否支持,通过注册回调函数获取结果。 1. 设备是否支持闪光灯,可使用方法[hasFlash](#hasflash)
2. 设备是否支持指定的闪光灯模式,可使用方法[isFlashModeSupported](#isflashmodesupported)
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| --------- | ----------------------- | ---- | --------------------------------- | | --------- | ----------------------- | ---- | --------------------- |
| flashMode | [FlashMode](#flashmode) | 是 | 指定闪光灯模式。 | | flashMode | [FlashMode](#flashmode) | 是 | 指定闪光灯模式。 |
| callback | AsyncCallback<boolean\> | 是 | 回调函数,返回true表示支持该闪光灯模式。 |
**返回值:**
| 类型 | 说明 |
| ---------- | ----------------------------- |
| [CameraErrorCode](#cameraerrorcode) | 接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
```js ```js
captureSession.isFlashModeSupported(camera.FlashMode.FLASH_MODE_AUTO, (err, status) => { try {
if (err) { captureSession.setFlashMode(camera.FlashMode.FLASH_MODE_AUTO);
console.error(`Failed to check whether the flash mode is supported. ${err.message}`); } catch (error) {
return; // 失败返回错误码error.code并处理
} console.log(error.code);
console.log(`Callback returned with the flash mode support status: ${status}`); }
})
``` ```
### isFlashModeSupported ### getFlashMode
isFlashModeSupported(flashMode: FlashMode): Promise<boolean\> getFlashMode(): FlashMode
检测闪光灯模式是否支持,通过Promise获取结果 获取当前设备的闪光灯模式
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ----------------------- | ---- | ------------- |
| flashMode | [FlashMode](#flashmode) | 是 | 指定闪光灯模式。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ----------------- | ---------------------------------------------------- | | ---------- | ----------------------------- |
| Promise<boolean\> | 使用Promise的方式获取结果,返回true表示设备支持该闪光灯模式。 | | [FlashMode](#flashmode) | 获取当前设备的闪光灯模式。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
```js ```js
captureSession.isFlashModeSupported(camera.FlashMode.FLASH_MODE_AUTO).then((status) => { try {
console.log(`Promise returned with flash mode support status.${status}`); let flashMode = captureSession.getFlashMode();
}) } catch (error) {
// 失败返回错误码error.code并处理
console.log(error.code);
}
``` ```
### setFlashMode ### isExposureModeSupported
setFlashMode(flashMode: FlashMode, callback: AsyncCallback<void\>): void
设置闪光灯模式,通过注册回调函数获取结果。
进行设置之前,需要先检查: isExposureModeSupported(aeMode: ExposureMode): boolean;
1. 设备是否支持闪光灯,可使用方法[hasFlash](#hasflash) 检测曝光模式是否支持。
2. 设备是否支持指定的闪光灯模式,可使用方法[isFlashModeSupported](#isflashmodesupported)
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| --------- | ----------------------- | ---- | --------------------- | | -------- | -------------------------------| ---- | ----------------------------- |
| flashMode | [FlashMode](#flashmode) | 是 | 指定闪光灯模式。 | | aeMode | [ExposureMode](#exposuremode) | 是 | 曝光模式。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```js
captureSession.setFlashMode(camera.FlashMode.FLASH_MODE_AUTO, (err) => {
if (err) {
console.error(`Failed to set the flash mode ${err.message}`);
return;
}
console.log('Callback returned with the successful execution of setFlashMode.');
})
```
### setFlashMode
setFlashMode(flashMode: FlashMode): Promise<void\>
设置闪光灯模式,通过Promise获取结果。
进行设置之前,需要先检查:
1. 设备是否支持闪光灯,可使用方法[hasFlash](#hasflash)
2. 设备是否支持指定的闪光灯模式,可使用方法[isFlashModeSupported](#isflashmodesupported)
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ----------------------- | ---- | ------------- |
| flashMode | [FlashMode](#flashmode) | 是 | 指定闪光灯模式。 |
**返回值:**
| 类型 | 说明 |
| -------------- | ------------------------ |
| Promise<void\> | 使用Promise的方式获取结果。 |
**示例:**
```js
captureSession.setFlashMode(camera.FlashMode.FLASH_MODE_AUTO).then(() => {
console.log('Promise returned with the successful execution of setFlashMode.');
})
```
### getFlashMode
getFlashMode(callback: AsyncCallback<FlashMode\>): void
获取当前设备的闪光灯模式,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | --------------------------------- |
| callback | AsyncCallback<[FlashMode](#flashmode)\> | 是 | 回调函数,用于获取当前设备的闪光灯模式。 |
**示例:**
```js
captureSession.getFlashMode((err, flashMode) => {
if (err) {
console.error(`Failed to get the flash mode ${err.message}`);
return;
}
console.log(`Callback returned with current flash mode: ${flashMode}`);
})
```
### getFlashMode
getFlashMode(): Promise<FlashMode\>
获取当前设备的闪光灯模式,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| --------------------------------- | --------------------------------- |
| Promise<[FlashMode](#flashmode)\> | 使用Promise的方式获取当前的闪光灯模式。 |
**示例:**
```js
captureSession.getFlashMode().then((flashMode) => {
console.log(`Promise returned with current flash mode : ${flashMode}`);
})
```
### isExposureModeSupported
isExposureModeSupported(aeMode: ExposureMode, callback: AsyncCallback<boolean\>): void;
检测曝光模式是否支持,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------------------| ---- | ----------------------------- |
| aeMode | [ExposureMode](#exposuremode) | 是 | 曝光模式。 |
| callback | AsyncCallback<boolean\> | 是 | 回调函数,用于获取是否支持曝光模式。 |
**示例:**
```js
captureSession.isExposureModeSupported(camera.ExposureMode.EXPOSURE_MODE_LOCKED,(err) => {
if (err) {
console.log(`Failed to check exposure mode supported ${err.message}`);
return ;
}
console.log('Callback returned with the successful execution of isExposureModeSupported');
})
```
### isExposureModeSupported
isExposureModeSupported(aeMode: ExposureMode): Promise<boolean\>
检测曝光模式是否支持,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------------------| ---- | ----------------------------- |
| aeMode | [ExposureMode](#exposuremode) | 是 | 曝光模式。 |
**返回值:**
| 名称 | 说明 |
| ----------------- |--------------------------------- |
| Promise<boolean\> | 使用Promise的方式获取支持的曝光模式。 |
**示例:**
```js
captureSession.isExposureModeSupported(camera.ExposureMode.EXPOSURE_MODE_LOCKED).then((isSupported) => {
console.log(`Promise returned with exposure mode supported : ${isSupported}`);
})
```
### getExposureMode
getExposureMode(callback: AsyncCallback<ExposureMode\>): void
获取当前曝光模式,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------------------| ---- | ---------------------------------------- |
| callback | AsyncCallback<[ExposureMode](#exposuremode)\> | 是 | 回调函数,用于获取当前曝光模式。 |
**示例:**
```js
captureSession.getExposureMode((err, exposureMode) => {
if (err) {
console.log(`Failed to get the exposure mode ${err.message}`);
return ;
}
console.log(`Callback returned with current exposure mode: ${exposureMode}`);
})
```
### getExposureMode
getExposureMode(): Promise<ExposureMode\>
获取当前曝光模式,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 名称 | 说明 |
| --------------------------------------- |------------------------------- |
| Promise<[ExposureMode](#exposuremode)\> | 使用Promise的方式获取当前曝光模式。 |
**示例:**
```js
captureSession.getExposureMode().then((exposureMode) => {
console.log(`Promise returned with current exposure mode : ${exposureMode}`);
})
```
### setExposureMode
setExposureMode(aeMode: ExposureMode, callback: AsyncCallback<void\>): void
设置曝光模式,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------------------| ---- | ----------------------- |
| aeMode | [ExposureMode](#exposuremode) | 是 | 曝光模式。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取设置结果。 |
**示例:**
```js
captureSession.setExposureMode(camera.ExposureMode.EXPOSURE_MODE_LOCKED,(err) => {
if (err) {
console.log(`Failed to set the exposure mode ${err.message}`);
return ;
}
console.log('Callback returned with the successful execution of setExposureMode');
})
```
### setExposureMode
setExposureMode(aeMode: ExposureMode): Promise<void\>
设置曝光模式,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 名称 | 说明 |
| ----------------- |---------------------------- |
| Promise<void\> | 使用Promise的方式获取设置结果。 |
**示例:**
```js
captureSession.setExposureMode(camera.ExposureMode.EXPOSURE_MODE_LOCKED).then(() => {
console.log('Promise returned with the successful execution of setExposureMode.');
})
```
### getMeteringPoint
getMeteringPoint(callback: AsyncCallback<Point\>): void
查询曝光区域中心点,通过注册回调函数获取结果。(该接口目前为预留,将在3.2版本开放)
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------------------| ---- | ------------------------ |
| callback | AsyncCallback<[Point](#point)\>| 是 | 回调函数,用于获取当前曝光点。 |
**示例:**
```js
captureSession.getMeteringPoint((err, exposurePoint) => {
if (err) {
console.log(`Failed to get the current exposure point ${err.message}`);
return ;
}
console.log(`Callback returned with current exposure point: ${exposurePoint}`);
})
```
### getMeteringPoint
getMeteringPoint(): Promise<Point\>
查询曝光区域中心点,通过Promise获取结果。(该接口目前为预留,将在3.2版本开放)
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 名称 | 说明 |
| ------------------------- |----------------------------- |
| Promise<[Point](#point)\> | 使用Promise的方式获取当前曝光点。 |
**示例:**
```js
captureSession.getMeteringPoint().then((exposurePoint) => {
console.log(`Promise returned with current exposure point : ${exposurePoint}`);
})
```
### setMeteringPoint
setMeteringPoint(point: Point, callback: AsyncCallback<void\>): void
设置曝光区域中心点,通过注册回调函数获取结果。(该接口目前为预留,将在3.2版本开放)
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------------- | -------------------------------| ---- | ------------------- |
| exposurePoint | [Point](#point) | 是 | 曝光点。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```js
const Point1 = {x: 1, y: 1};
captureSession.setMeteringPoint(Point1,(err) => {
if (err) {
console.log(`Failed to set the exposure point ${err.message}`);
return ;
}
console.log('Callback returned with the successful execution of setMeteringPoint');
})
```
### setMeteringPoint
setMeteringPoint(point: Point): Promise<void\>
设置曝光区域中心点,通过Promise获取结果。(该接口目前为预留,将在3.2版本开放)
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------------- | -------------------------------| ---- | ------------------- |
| exposurePoint | [Point](#point) | 是 | 曝光点。 |
**返回值:**
| 名称 | 说明 |
| ----------------- |------------------------ |
| Promise<void\> | 使用Promise的方式返回结果。 |
**示例:**
```js
const Point2 = {x: 2, y: 2};
captureSession.setMeteringPoint(Point2).then(() => {
console.log('Promise returned with the successful execution of setMeteringPoint');
})
```
### getExposureBiasRange
getExposureBiasRange(callback: AsyncCallback<Array<number\>\>): void
查询曝光补偿范围,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------------------| ---- | ----------------------------- |
| callback | AsyncCallback<Array<number\>\> | 是 | 回调函数,用于获取补偿范围的数组。 |
**示例:**
```js
captureSession.getExposureBiasRange((err, biasRangeArray) => {
if (err) {
console.log(`Failed to get the array of compenstation range ${err.message}`);
return ;
}
console.log('Callback returned with the array of compenstation range: ' + JSON.stringify(biasRangeArray));
})
```
### getExposureBiasRange
getExposureBiasRange(): Promise<Array<number\>\>
查询曝光补偿范围,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 名称 | 说明 |
| ----------------- |-------------------------------------- |
| Promise<Array<number\>\> | 使用Promise的方式获取曝光补偿范围。 |
**示例:**
```js
captureSession.getExposureBiasRange().then((biasRangeArray) => {
console.log('Promise returned with the array of compenstation range: ' + JSON.stringify(biasRangeArray));
})
```
### setExposureBias
setExposureBias(exposureBias: number, callback: AsyncCallback<void\>): void
设置曝光补偿,通过注册回调函数获取结果。
进行设置之前,建议先通过方法[getExposureBiasRange](#getexposurebiasrange)查询支持的范围。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------------------| ---- | ------------------- |
| exposureBias | number | 是 | 曝光补偿,getExposureBiasRange查询支持的范围 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```js
let exposureBias = biasRangeArray[0];
captureSession.setExposureBias(exposureBias,(err) => {
if (err) {
console.log(`Failed to set the exposure bias ${err.message}`);
return ;
}
console.log('Callback returned with the successful execution of setExposureBias');
})
```
### setExposureBias
setExposureBias(exposureBias: number): Promise<void\>
设置曝光补偿,通过Promise获取结果。
进行设置之前,建议先通过方法[getExposureBiasRange](#getexposurebiasrange)查询支持的范围。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------------- | --------- | ---- | --------- |
| exposureBias | number | 是 | 曝光补偿,getExposureBiasRange查询支持的范围 |
**返回值:**
| 名称 | 说明 |
| ----------------- |------------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 |
**示例:**
```js
let exposureBias = biasRangeArray[0];
captureSession.setExposureBias(exposureBias).then(() => {
console.log('Promise returned with the successful execution of setExposureBias.');
})
```
### getExposureValue
getExposureValue(callback: AsyncCallback<number\>): void
查询当前曝光值,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------| ---- | --------------------- |
| callback | AsyncCallback<number\> | 是 | 回调函数,用于获取曝光值。 |
**示例:**
```js
captureSession.getExposureValue((err, exposureValue) => {
if (err) {
console.log(`Failed to get the exposure value ${err.message}`);
return ;
}
console.log(`Callback returned with the exposure value: ${exposureValue}`);
})
```
### getExposureValue
getExposureValue(): Promise<number\>
查询当前曝光值,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 名称 | 说明 |
| ----------------- |-------------------------- |
| Promise<number\> | 使用Promise的方式获取曝光值。 |
**示例:**
```js
captureSession.getExposureValue().then((exposureValue) => {
console.log(`Promise returned with exposure value: ${exposureValude}`);
})
```
### isFocusModeSupported
isFocusModeSupported(afMode: FocusMode, callback: AsyncCallback<boolean\>): void
检测对焦模式是否支持,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------- |
| afMode | [FocusMode](#focusmode) | 是 | 指定的焦距模式。 |
| callback | AsyncCallback<boolean\> | 是 | 回调函数,返回true表示支持该焦距模式。 |
**示例:**
```js
captureSession.isFocusModeSupported(camera.FocusMode.FOCUS_MODE_AUTO, (err, status) => {
if (err) {
console.error(`Failed to check whether the focus mode is supported. ${err.message}`);
return;
}
console.log(`Callback returned with the focus mode support status: ${status}`);
})
```
### isFocusModeSupported
isFocusModeSupported(afMode: FocusMode): Promise<boolean\>
检测对焦模式是否支持,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ----------------------- | ---- | ------------- |
| afMode | [FocusMode](#focusmode) | 是 | 指定的焦距模式。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ----------------- | --------------------------------------------------- | | ---------- | ----------------------------- |
| Promise<boolean\> | 使用Promise的方式获取结果,返回true表示设备支持该焦距模式。 | | boolean | 获取是否支持曝光模式。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
```js ```js
captureSession.isFocusModeSupported(camera.FocusMode.FOCUS_MODE_AUTO).then((status) => { try {
console.log(`Promise returned with focus mode support status ${status}.`); let isSupported = captureSession.isExposureModeSupported(camera.ExposureMode.EXPOSURE_MODE_LOCKED);
}) } catch (error) {
// 失败返回错误码error.code并处理
console.log(error.code);
}
``` ```
### setFocusMode ### getExposureMode
setFocusMode(afMode: FocusMode, callback: AsyncCallback<void\>): void
设置对焦模式,通过注册回调函数获取结果。 getExposureMode(): ExposureMode
进行设置之前,需要先检查设备是否支持指定的焦距模式,可使用方法[isFocusModeSupported](#isfocusmodesupported) 获取当前曝光模式
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **返回值:**
| 参数名 | 类型 | 必填 | 说明 | | 类型 | 说明 |
| -------- | ----------------------- | ---- | ------------------- | | ---------- | ----------------------------- |
| afMode | [FocusMode](#focusmode) | 是 | 指定的焦距模式。 | | [ExposureMode](#exposuremode) | 获取当前曝光模式。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:** **示例:**
```js ```js
captureSession.setFocusMode(camera.FocusMode.FOCUS_MODE_AUTO, (err) => { try {
if (err) { let exposureMode = captureSession.getExposureMode();
console.error(`Failed to set the focus mode ${err.message}`); } catch (error) {
return; // 失败返回错误码error.code并处理
} console.log(error.code);
console.log('Callback returned with the successful execution of setFocusMode.'); }
})
``` ```
### setFocusMode ### setExposureMode
setFocusMode(afMode: FocusMode): Promise<void\>
设置对焦模式,通过Promise获取结果。 setExposureMode(aeMode: ExposureMode): void
进行设置之前,需要先检查设备是否支持指定的焦距模式,可使用方法[isFocusModeSupported](#isfocusmodesupported) 设置曝光模式
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ------ | ----------------------- | ---- | ------------- | | -------- | -------------------------------| ---- | ----------------------- |
| afMode | [FocusMode](#focusmode) | 是 | 指定的焦距模式。 | | aeMode | [ExposureMode](#exposuremode) | 是 | 曝光模式。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| -------------- | ------------------------ | | ---------- | ----------------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 | | [CameraErrorCode](#cameraerrorcode) | 接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:**
```js
captureSession.setFocusMode(camera.FocusMode.FOCUS_MODE_AUTO).then(() => {
console.log('Promise returned with the successful execution of setFocusMode.');
})
```
### getFocusMode
getFocusMode(callback: AsyncCallback<FocusMode\>): void
获取当前的对焦模式,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ------------------------------- |
| callback | AsyncCallback<[FocusMode](#focusmode)\> | 是 | 回调函数,用于获取当前设备的焦距模式。 |
**示例:** **示例:**
```js ```js
captureSession.getFocusMode((err, afMode) => { try {
if (err) { captureSession.setExposureMode(camera.ExposureMode.EXPOSURE_MODE_LOCKED);
console.error(`Failed to get the focus mode ${err.message}`); } catch (error) {
return; // 失败返回错误码error.code并处理
} console.log(error.code);
console.log(`Callback returned with current focus mode: ${afMode}`); }
})
``` ```
### getFocusMode ### getMeteringPoint
getFocusMode(): Promise<FocusMode\> getMeteringPoint(): Point
获取当前的对焦模式,通过Promise获取结果。 查询曝光区域中心点。(该接口目前为预留,将在3.2版本开放)
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ------------------- | -------------------------------- | | ---------- | ----------------------------- |
| Promise<FocusMode\> | 使用Promise的方式获取当前的焦距模式。 | | [Point](#point) | 获取当前曝光点。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
```js ```js
captureSession.getFocusMode().then((afMode) => { try {
console.log(`Promise returned with current focus mode : ${afMode}`); let exposurePoint = captureSession.getMeteringPoint();
}) } catch (error) {
// 失败返回错误码error.code并处理
console.log(error.code);
}
``` ```
### setFocusPoint ### setMeteringPoint
setFocusPoint(point: Point, callback: AsyncCallback<void\>): void setMeteringPoint(point: Point): void
设置焦点,通过注册回调函数获取结果。 设置曝光区域中心点。(该接口目前为预留,将在3.2版本开放)
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | ------------------- | | ------------- | -------------------------------| ---- | ------------------- |
| point | [Point](#point) | 是 | 焦点。 | | exposurePoint | [Point](#point) | 是 | 曝光点。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**返回值:**
| 类型 | 说明 |
| ---------- | ----------------------------- |
| [CameraErrorCode](#cameraerrorcode) | 接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
```js ```js
const Point1 = {x: 1, y: 1}; const exposurePoint = {x: 1, y: 1};
try {
captureSession.setFocusPoint(Point1, (err) => { captureSession.setMeteringPoint(exposurePoint);
if (err) { } catch (error) {
console.error(`Failed to set the focus point ${err.message}`); // 失败返回错误码error.code并处理
return; console.log(error.code);
} }
console.log('Callback returned with the successful execution of setFocusPoint.');
})
``` ```
### setFocusPoint ### getExposureBiasRange
setFocusPoint(point: Point): Promise<void\> getExposureBiasRange(): Array<number\>
设置焦点,通过Promise获取结果 查询曝光补偿范围
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | ------------------- |
| point | [Point](#point) | 是 | 焦点。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| -------------- | ----------------------- | | ---------- | ----------------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 | | Array<number\> | 获取补偿范围的数组。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
```js ```js
const Point2 = {x: 2, y: 2}; try {
let biasRangeArray = captureSession.getExposureBiasRange();
captureSession.setFocusPoint(Point2).then(() => { } catch (error) {
console.log('Promise returned with the successful execution of setFocusPoint.'); // 失败返回错误码error.code并处理
}) console.log(error.code);
}
``` ```
### getFocusPoint ### setExposureBias
setExposureBias(exposureBias: number): void
getFocusPoint(callback: AsyncCallback<Point\>): void 设置曝光补偿。
查询焦点,通过注册回调函数获取结果 进行设置之前,建议先通过方法[getExposureBiasRange](#getexposurebiasrange)查询支持的范围
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------- | ---- | ----------------------- | | -------- | -------------------------------| ---- | ------------------- |
| callback | AsyncCallback<[Point](#point)\> | 是 | 回调函数,用于获取当前焦点。 | | exposureBias | number | 是 | 曝光补偿,getExposureBiasRange查询支持的范围,接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
```js ```js
captureSession.getFocusPoint((err, point) => { let exposureBias = biasRangeArray[0];
if (err) { try {
console.error(`Failed to get the current focus point ${err.message}`); captureSession.setExposureBias(exposureBias);
return; } catch (error) {
} // 失败返回错误码error.code并处理
console.log('Callback returned with the current focus point: ' + JSON.stringify(point)); console.log(error.code);
}) }
``` ```
### getFocusPoint ### getExposureValue
getFocusPoint(): Promise<Point\> getExposureValue(): number
查询焦点,通过Promise获取结果 查询当前曝光值
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| --------------- | --------------------------- | | ---------- | ----------------------------- |
| Promise<Point\> | 使用Promise的方式获取当前焦点。 | | number | 获取曝光值。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
```js ```js
captureSession.getFocusPoint().then((point) => { try {
console.log('Promise returned with the current focus point: ' + JSON.stringify(point)); let exposureValue = captureSession.getExposureValue();
}) } catch (error) {
// 失败返回错误码error.code并处理
console.log(error.code);
}
``` ```
### getFocalLength ### isFocusModeSupported
getFocalLength(callback: AsyncCallback<number\>): void isFocusModeSupported(afMode: FocusMode): boolean
查询焦距值,通过注册回调函数获取结果 检测对焦模式是否支持
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------- | ---- | ----------------------- | | -------- | ----------------------- | ---- | -------------------------------- |
| callback | AsyncCallback<number\> | 是 | 回调函数,用于获取当前焦距。 | | afMode | [FocusMode](#focusmode) | 是 | 指定的焦距模式。 |
**示例:**
```js
captureSession.getFocalLength((err, focalLength) => {
if (err) {
console.error(`Failed to get the current focal length ${err.message}`);
return;
}
console.log(`Callback returned with the current focal length: ${focalLength}`);
})
```
### getFocalLength
getFocalLength(): Promise<number\>
查询焦距值,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ---------------- | ----------------------- | | ---------- | ----------------------------- |
| Promise<number\> | 使用Promise的方式获取焦距。 | | boolean | 返回true表示支持该焦距模式。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
```js ```js
captureSession.getFocalLength().then((focalLength) => { try {
console.log(`Promise returned with the current focal length: ${focalLength}`); let status = captureSession.isFocusModeSupported(camera.FocusMode.FOCUS_MODE_AUTO);
}) } catch (error) {
// 失败返回错误码error.code并处理
console.log(error.code);
}
``` ```
### getZoomRatioRange ### setFocusMode
setFocusMode(afMode: FocusMode): void
getZoomRatioRange\(callback: AsyncCallback<Array<number\>\>\): void 设置对焦模式。
获取支持的变焦范围,通过注册回调函数获取结果 进行设置之前,需要先检查设备是否支持指定的焦距模式,可使用方法[isFocusModeSupported](#isfocusmodesupported)
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------ | ---- | ------------------- | | -------- | ----------------------- | ---- | ------------------- |
| callback | AsyncCallback<Array<number\>\> | 是 | 回调函数,用于获取可变焦距比范围,返回的数组包括其最小值和最大值。 | | afMode | [FocusMode](#focusmode) | 是 | 指定的焦距模式。 |
**返回值:**
| 类型 | 说明 |
| ---------- | ----------------------------- |
| [CameraErrorCode](#cameraerrorcode) | 接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
```js ```js
captureSession.getZoomRatioRange((err, zoomRatioRange) => { try {
if (err) { captureSession.setFocusMode(camera.FocusMode.FOCUS_MODE_AUTO);
console.error(`Failed to get the zoom ratio range. ${err.message}`); } catch (error) {
return; // 失败返回错误码error.code并处理
} console.log(error.code);
console.log(`Callback returned with zoom ratio range: ${zoomRatioRange.length}`); }
})
``` ```
### getZoomRatioRange ### getFocusMode
getZoomRatioRange\(\): Promise<Array<number\>\> getFocusMode(): FocusMode
获取支持的变焦范围,通过Promise获取结果 获取当前的对焦模式
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ------------------------ | --------------------------- | | ---------- | ----------------------------- |
| Promise<Array<number\>\> | 使用Promise的方式获取当前的可变焦距比范围,返回的数组包括其最小值和最大值。 | | [FocusMode](#focusmode) | 获取当前设备的焦距模式。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
```js ```js
captureSession.getZoomRatioRange().then((zoomRatioRange) => { try {
console.log(`Promise returned with zoom ratio range: ${zoomRatioRange.length}`); let afMode = captureSession.getFocusMode();
}) } catch (error) {
// 失败返回错误码error.code并处理
console.log(error.code);
}
``` ```
### setZoomRatio ### setFocusPoint
setZoomRatio(zoomRatio: number, callback: AsyncCallback<void\>): void setFocusPoint(point: Point): void
设置变焦比,通过注册回调函数获取结果 设置焦点
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| --------- | -------------------- | ---- | ------------------- | | -------- | ----------------------- | ---- | ------------------- |
| zoomRatio | number | 是 | 可变焦距比,通过getZoomRatioRange获取支持的变焦范围 | | Point1 | [Point](#point) | 是 | 焦点。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**返回值:**
| 类型 | 说明 |
| ---------- | ----------------------------- |
| [CameraErrorCode](#cameraerrorcode) | 接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
```js ```js
let zoomRatio = zoomRatioRange[0]; const Point1 = {x: 1, y: 1};
captureSession.setZoomRatio(zoomRatio, (err) => { try {
if (err) { captureSession.setFocusPoint(Point1);
console.error(`Failed to set the zoom ratio value ${err.message}`); } catch (error) {
return; // 失败返回错误码error.code并处理
} console.log(error.code);
console.log('Callback returned with the successful execution of setZoomRatio.'); }
})
``` ```
### setZoomRatio ### getFocusPoint
setZoomRatio(zoomRatio: number): Promise<void\> getFocusPoint(): Point
设置变焦比,通过Promise获取结果 查询焦点
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ------ | ---- | --------- |
| zoomRatio | number | 是 | 可变焦距比,通过getZoomRatioRange获取支持的变焦范围|
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| -------------- | ----------------------- | | ---------- | ----------------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 | | [Point](#point) | 用于获取当前焦点。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
```js ```js
let zoomRatio = zoomRatioRange[0]; try {
captureSession.setZoomRatio(zoomRatio).then(() => { let point = captureSession.getFocusPoint();
console.log('Promise returned with the successful execution of setZoomRatio.'); } catch (error) {
}) // 失败返回错误码error.code并处理
console.log(error.code);
}
``` ```
### getZoomRatio ### getFocalLength
getZoomRatio(callback: AsyncCallback<number\>): void getFocalLength(): number
获取当前的变焦比,通过注册回调函数获取结果 查询焦距值
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **返回值:**
| 参数名 | 类型 | 必填 | 说明 | | 类型 | 说明 |
| -------- | ---------------------- | ---- | ------------------- | | ---------- | ----------------------------- |
| callback | AsyncCallback<number\> | 是 | 回调函数,用于获取结果。 | | number | 用于获取当前焦距。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
```js ```js
captureSession.getZoomRatio((err, zoomRatio) => { try {
if (err) { let focalLength = captureSession.getFocalLength();
console.error(`Failed to get the zoom ratio ${err.message}`); } catch (error) {
return; // 失败返回错误码error.code并处理
} console.log(error.code);
console.log(`Callback returned with current zoom ratio: ${zoomRatio}`); }
})
``` ```
### getZoomRatio ### getZoomRatioRange
getZoomRatio(): Promise<number\> getZoomRatioRange(): Array<number\>
获取当前的变焦比,通过Promise获取结果 获取支持的变焦范围
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ---------------- | ----------------------- | | ---------- | ----------------------------- |
| Promise<number\> | 使用Promise的方式获取结果。 | | Array<number\> | 用于获取可变焦距比范围,返回的数组包括其最小值和最大值。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
```js ```js
captureSession.getZoomRatio().then((zoomRatio) => { try {
console.log(`Promise returned with current zoom ratio : ${zoomRatio}`); let zoomRatioRange = captureSession.getZoomRatioRange();
}) } catch (error) {
// 失败返回错误码error.code并处理
console.log(error.code);
}
``` ```
### isVideoStabilizationModeSupported ### setZoomRatio
isVideoStabilizationModeSupported(vsMode: VideoStabilizationMode, callback: AsyncCallback<boolean\>): void setZoomRatio(zoomRatio: number): void
查询是否支持指定的视频防抖模式,通过注册回调函数获取结果 设置变焦比
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------- | ---- | ------------------------------ | | --------- | -------------------- | ---- | ------------------- |
| vsMode | [VideoStabilizationMode](#videostabilizationmode) | 是 | 视频防抖模式。 | | zoomRatio | number | 是 | 可变焦距比,通过getZoomRatioRange获取支持的变焦范围 |
| callback | AsyncCallback<boolean\> | 是 | 回调函数,返回视频防抖模式是否支持。 |
**返回值:**
| 类型 | 说明 |
| ---------- | ----------------------------- |
| [CameraErrorCode](#cameraerrorcode) | 接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
```js ```js
captureSession.isVideoStabilizationModeSupported(camera.VideoStabilizationMode.OFF, (err, isSupported) => { let zoomRatio = zoomRatioRange[0];
if (err) { try {
console.error(`Failed to check whether video stabilization mode supported. ${err.message}`); captureSession.setZoomRatio(zoomRatio);
return; } catch (error) {
} // 失败返回错误码error.code并处理
console.log(`Callback returned with the successful execution of isVideoStabilizationModeSupported`); console.log(error.code);
}) }
``` ```
### isVideoStabilizationModeSupported ### getZoomRatio
isVideoStabilizationModeSupported(vsMode: VideoStabilizationMode): Promise<boolean\> getZoomRatio(): number
查询是否支持指定的视频防抖模式,通过Promise获取结果 获取当前的变焦比
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ----------------- | --------------------------------------------- | | ---------- | ----------------------------- |
| Promise<boolean\> | 使用Promise的方式获取结果,返回视频防抖模式是否支持。 | | number | 获取当前的变焦比结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
```js ```js
captureSession.isVideoStabilizationModeSupported(camera.VideoStabilizationMode.OFF).then((isSupported) => { try {
console.log(`Promise returned with video stabilization mode supported: ${isSupported}`); let zoomRatio = captureSession.getZoomRatio();
}) } catch (error) {
// 失败返回错误码error.code并处理
console.log(error.code);
}
``` ```
### getActiveVideoStabilizationMode ### isVideoStabilizationModeSupported
getActiveVideoStabilizationMode(callback: AsyncCallback<VideoStabilizationMode\>): void isVideoStabilizationModeSupported(vsMode: VideoStabilizationMode): boolean
查询当前正在使用的视频防抖模式,通过注册回调函数获取结果 查询是否支持指定的视频防抖模式
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------- | ---- | ------------------------------ | | -------- | ------------------------------------------------- | ---- | ------------------------------ |
| callback | AsyncCallback<VideoStabilizationMode\> | 是 | 回调函数,返回视频防抖是否正在使用。 | | vsMode | [VideoStabilizationMode](#videostabilizationmode) | 是 | 视频防抖模式。 |
**示例:**
```js
captureSession.getActiveVideoStabilizationMode((err, vsMode) => {
if (err) {
console.error(`Failed to get active video stabilization mode ${err.message}`);
return;
}
console.log('Callback returned with the successful execution of getActiveVideoStabilizationMode.');
})
```
### getActiveVideoStabilizationMode
getActiveVideoStabilizationMode(): Promise<VideoStabilizationMode\>
查询当前正在使用的视频防抖模式,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| -------------------------------- | ------------------------------------------------- | | ---------- | ----------------------------- |
| Promise<VideoStabilizationMode\> | 使用Promise的方式获取结果,返回视频防抖当前是否正在使用。 | | boolean | 返回视频防抖模式是否支持。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
```js ```js
captureSession.getActiveVideoStabilizationMode().then((vsMode) => { try {
console.log(`Promise returned with the current video stabilization mode: ${vsMode}`); let isSupported = captureSession.isVideoStabilizationModeSupported(camera.VideoStabilizationMode.OFF);
}) } catch (error) {
// 失败返回错误码error.code并处理
console.log(error.code);
}
``` ```
### setVideoStabilizationMode ### getActiveVideoStabilizationMode
setVideoStabilizationMode(mode: VideoStabilizationMode, callback: AsyncCallback<void\>): void getActiveVideoStabilizationMode(): VideoStabilizationMode
设置视频防抖模式,通过注册回调函数获取结果 查询当前正在使用的视频防抖模式
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **返回值:**
| 参数名 | 类型 | 必填 | 说明 | | 类型 | 说明 |
| -------- | ------------------------------------------------- | ---- | --------------------- | | ---------- | ----------------------------- |
| mode | [VideoStabilizationMode](#videostabilizationmode) | 是 | 需要设置的视频防抖模式。 | | VideoStabilizationMode | 视频防抖是否正在使用。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
| callback | AsyncCallback<void\> | 是 | 回调函数。 |
**示例:** **示例:**
```js ```js
captureSession.setVideoStabilizationMode(camera.VideoStabilizationMode.OFF, (err) => { try {
if (err) { let vsMode = captureSession.getActiveVideoStabilizationMode();
console.error(`Failed to set the video stabilization mode ${err.message}`); } catch (error) {
return; // 失败返回错误码error.code并处理
} console.log(error.code);
console.log('Callback returned with the successful execution of setVideoStabilizationMode.'); }
})
``` ```
### setVideoStabilizationMode ### setVideoStabilizationMode
setVideoStabilizationMode(mode: VideoStabilizationMode): Promise<void\> setVideoStabilizationMode(mode: VideoStabilizationMode): void
设置视频防抖,通过Promise获取结果 设置视频防抖模式
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
...@@ -2839,22 +1823,25 @@ setVideoStabilizationMode(mode: VideoStabilizationMode): Promise<void\> ...@@ -2839,22 +1823,25 @@ setVideoStabilizationMode(mode: VideoStabilizationMode): Promise<void\>
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| -------------- | ------------------------------------------------- | | ---------- | ----------------------------- |
| Promise<void\> | 使用Promise的方式获取结果,返回设置的视频防抖模式的结果。 | | [CameraErrorCode](#cameraerrorcode) | 接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
```js ```js
captureSession.setVideoStabilizationMode(camera.VideoStabilizationMode.OFF).then(() => { try {
console.log('Promise returned with the successful execution of setVideoStabilizationMode.'); captureSession.setVideoStabilizationMode(camera.VideoStabilizationMode.OFF);
}) } catch (error) {
// 失败返回错误码error.code并处理
console.log(error.code);
}
``` ```
### on('focusStateChange') ### on('focusStateChange')
on(type: 'focusStateChange', callback: AsyncCallback<FocusState\>): void on(type: 'focusStateChange', callback: AsyncCallback<FocusState\>): void
监听焦距的状态变化,通过注册回调函数获取结果。 监听相机聚焦的状态变化,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
...@@ -2862,7 +1849,7 @@ on(type: 'focusStateChange', callback: AsyncCallback<FocusState\>): void ...@@ -2862,7 +1849,7 @@ on(type: 'focusStateChange', callback: AsyncCallback<FocusState\>): void
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------- | ---- | ------------------------ | | -------- | ----------------------------------------- | ---- | ------------------------ |
| type | string | 是 | 监听事件,固定为'focusStateChange',即焦距状态变化事件。 | | type | string | 是 | 监听事件,固定为'focusStateChange',callback 返回聚焦状态改变信息,session 创建成功可监听。 |
| callback | AsyncCallback<[FocusState](#focusstate)\> | 是 | 回调函数,用于获取焦距状态。 | | callback | AsyncCallback<[FocusState](#focusstate)\> | 是 | 回调函数,用于获取焦距状态。 |
**示例:** **示例:**
...@@ -2875,7 +1862,7 @@ captureSession.on('focusStateChange', (focusState) => { ...@@ -2875,7 +1862,7 @@ captureSession.on('focusStateChange', (focusState) => {
### on('error') ### on('error')
on(type: 'error', callback: ErrorCallback<CaptureSessionError\>): void on(type: 'error', callback: ErrorCallback<BusinessError\>): void
监听拍照会话的错误事件,通过注册回调函数获取结果。 监听拍照会话的错误事件,通过注册回调函数获取结果。
...@@ -2885,39 +1872,17 @@ on(type: 'error', callback: ErrorCallback<CaptureSessionError\>): void ...@@ -2885,39 +1872,17 @@ on(type: 'error', callback: ErrorCallback<CaptureSessionError\>): void
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------------------------- | ---- | ------------------------------ | | -------- | ----------------------------------------------------------- | ---- | ------------------------------ |
| type | string | 是 | 监听事件,固定为'error',即拍照会话错误事件。 | | type | string | 是 | 监听事件,固定为'error',callback返回session接口使用错误返回对应错误码,比如调用(beginConfig(),commitConfig(),addInput)等接口发生错误时返回对应错误码。 |
| callback | ErrorCallback<[CaptureSessionError](#capturesessionerror)\> | 是 | 回调函数,用于获取错误信息。 | | callback | ErrorCallback<BusinessError\> | 是 | 回调函数,用于获取错误信息。返回错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
```js ```js
captureSession.on('error', (captureSessionError) => { captureSession.on('error', (error) => {
console.log(`Capture session error code: ${captureSessionError.code}`); console.log(`Capture session error code: ${error.code}`);
}) })
``` ```
## CaptureSessionErrorCode
枚举,会话错误类型。
**系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 值 | 说明 |
| ----------------------------- | ---- | -------- |
| ERROR_UNKNOWN | -1 | 未知错误。 |
| ERROR_INSUFFICIENT_RESOURCES | 0 | 资源不足。 |
| ERROR_TIMEOUT | 1 | 超时。 |
## CaptureSessionError
会话错误码。
**系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 类型 | 必填 | 说明 |
| ---- | ------------------------------------------- | -------------------------- |-------------------------- |
| code | [CaptureSessionError](#capturesessionerror) | 是 |CaptureSession中的错误码。 |
## CameraOutput ## CameraOutput
会话中[CaptureSession](#capturesession)使用的输出信息,output的基类。 会话中[CaptureSession](#capturesession)使用的输出信息,output的基类。
...@@ -2938,14 +1903,14 @@ start(callback: AsyncCallback<void\>): void ...@@ -2938,14 +1903,14 @@ start(callback: AsyncCallback<void\>): void
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | -------------------- | | -------- | -------------------- | ---- | -------------------- |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 | | callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
```js ```js
previewOutput.start((err) => { previewOutput.start((err) => {
if (err) { if (err) {
console.error(`Failed to start the previewOutput. ${err.message}`); console.error(`Failed to start the previewOutput. ${err.code}`);
return; return;
} }
console.log('Callback returned with previewOutput started.'); console.log('Callback returned with previewOutput started.');
...@@ -2964,14 +1929,16 @@ start(): Promise<void\> ...@@ -2964,14 +1929,16 @@ start(): Promise<void\>
| 类型 | 说明 | | 类型 | 说明 |
| -------------- | ----------------------- | | -------------- | ----------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 | | Promise<void\> | 使用Promise的方式获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)|
**示例:** **示例:**
```js ```js
previewOutput.start().then(() => { previewOutput.start().then(() => {
console.log('Promise returned with previewOutput started.'); console.log('Promise returned with previewOutput started.');
}) }).catch((err) => {
console.log('Failed to previewOutput start '+ err.code);
});
``` ```
### stop ### stop
...@@ -2993,7 +1960,7 @@ stop(callback: AsyncCallback<void\>): void ...@@ -2993,7 +1960,7 @@ stop(callback: AsyncCallback<void\>): void
```js ```js
previewOutput.stop((err) => { previewOutput.stop((err) => {
if (err) { if (err) {
console.error(`Failed to stop the previewOutput. ${err.message}`); console.error(`Failed to stop the previewOutput. ${err.code}`);
return; return;
} }
console.log('Callback returned with previewOutput stopped.'); console.log('Callback returned with previewOutput stopped.');
...@@ -3019,7 +1986,9 @@ stop(): Promise<void\> ...@@ -3019,7 +1986,9 @@ stop(): Promise<void\>
```js ```js
previewOutput.stop().then(() => { previewOutput.stop().then(() => {
console.log('Callback returned with previewOutput stopped.'); console.log('Callback returned with previewOutput stopped.');
}) }).catch((err) => {
console.log('Failed to previewOutput stop '+ err.code);
});
``` ```
### release ### release
...@@ -3034,14 +2003,14 @@ release(callback: AsyncCallback<void\>): void ...@@ -3034,14 +2003,14 @@ release(callback: AsyncCallback<void\>): void
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------- | | -------- | -------------------- | ---- | ------------------- |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 | | callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
```js ```js
previewOutput.release((err) => { previewOutput.release((err) => {
if (err) { if (err) {
console.error(`Failed to release the PreviewOutput instance ${err.message}`); console.error(`Failed to release the PreviewOutput instance ${err.code}`);
return; return;
} }
console.log('Callback invoked to indicate that the PreviewOutput instance is released successfully.'); console.log('Callback invoked to indicate that the PreviewOutput instance is released successfully.');
...@@ -3060,14 +2029,16 @@ release(): Promise<void\> ...@@ -3060,14 +2029,16 @@ release(): Promise<void\>
| 类型 | 说明 | | 类型 | 说明 |
| -------------- | ----------------------- | | -------------- | ----------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 | | Promise<void\> | 使用Promise的方式获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
```js ```js
previewOutput.release().then(() => { previewOutput.release().then(() => {
console.log('Promise returned to indicate that the PreviewOutput instance is released successfully.'); console.log('Promise returned to indicate that the PreviewOutput instance is released successfully.');
}) }).catch((err) => {
console.log('Failed to previewOutput release '+ err.code);
});
``` ```
### on('frameStart') ### on('frameStart')
...@@ -3082,7 +2053,7 @@ on(type: 'frameStart', callback: AsyncCallback<void\>): void ...@@ -3082,7 +2053,7 @@ on(type: 'frameStart', callback: AsyncCallback<void\>): void
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | --------------------------------------- | | -------- | -------------------- | ---- | --------------------------------------- |
| type | string | 是 | 监听事件,固定为'frameStart',即帧启动事件。 | | type | string | 是 | 监听事件,固定为'frameStart',预览开始第一帧返回,previewOutput创建成功可监听。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 | | callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:** **示例:**
...@@ -3105,7 +2076,7 @@ on(type: 'frameEnd', callback: AsyncCallback<void\>): void ...@@ -3105,7 +2076,7 @@ on(type: 'frameEnd', callback: AsyncCallback<void\>): void
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------------------- | | -------- | -------------------- | ---- | ------------------------------------- |
| type | string | 是 | 监听事件,固定为'frameEnd',即帧结束事件。 | | type | string | 是 | 监听事件,固定为'frameEnd',预览结束最后一帧返回,previewOutput创建成功可监听。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 | | callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:** **示例:**
...@@ -3118,7 +2089,7 @@ previewOutput.on('frameEnd', () => { ...@@ -3118,7 +2089,7 @@ previewOutput.on('frameEnd', () => {
### on('error') ### on('error')
on(type: 'error', callback: ErrorCallback<PreviewOutputError\>): void on(type: 'error', callback: ErrorCallback<BusinessError\>): void
监听预览输出的错误事件,通过注册回调函数获取结果。 监听预览输出的错误事件,通过注册回调函数获取结果。
...@@ -3128,8 +2099,8 @@ on(type: 'error', callback: ErrorCallback<PreviewOutputError\>): void ...@@ -3128,8 +2099,8 @@ on(type: 'error', callback: ErrorCallback<PreviewOutputError\>): void
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------------------------------- | ---- | ------------------------ | | -------- | ----------------------------------------------------------------- | ---- | ------------------------ |
| type | string | 是 | 监听事件,固定为'error',即预览输出错误事件。| | type | string | 是 | 监听事件,固定为'error',callback返回预览接口使用错误时的错误码,比如调用(start(),release())等接口发生错误时返回对应错误码。|
| callback | ErrorCallback<[PreviewOutputErrorCode](#previewoutputerrorcode)\> | 是 | 回调函数,用于获取错误信息。 | | callback | ErrorCallback<BusinessError\> | 是 | 回调函数,用于获取错误信息。返回错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
...@@ -3139,26 +2110,6 @@ previewOutput.on('error', (previewOutputError) => { ...@@ -3139,26 +2110,6 @@ previewOutput.on('error', (previewOutputError) => {
}) })
``` ```
## PreviewOutputErrorCode
枚举,预览输出错误类型。
**系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 值 | 说明 |
| ------------- | ---- | -------- |
| ERROR_UNKNOWN | -1 | 未知错误。 |
## PreviewOutputError
预览输出错误码。
**系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 类型 | 必填 | 说明 |
| ---- | ------------------------------------------------- | ---------------- |---------------------- |
| code | [PreviewOutputErrorCode](#previewoutputerrorcode) | 是 |PreviewOutput中的错误码。 |
## ImageRotation ## ImageRotation
枚举,图片旋转角度。 枚举,图片旋转角度。
...@@ -3226,14 +2177,14 @@ capture(callback: AsyncCallback<void\>): void ...@@ -3226,14 +2177,14 @@ capture(callback: AsyncCallback<void\>): void
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------- | | -------- | -------------------- | ---- | ------------------- |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 | | callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
```js ```js
photoOutput.capture((err) => { photoOutput.capture((err) => {
if (err) { if (err) {
console.error(`Failed to capture the photo ${err.message}`); console.error(`Failed to capture the photo ${err.code}`);
return; return;
} }
console.log('Callback invoked to indicate the photo capture request success.'); console.log('Callback invoked to indicate the photo capture request success.');
...@@ -3242,6 +2193,30 @@ photoOutput.capture((err) => { ...@@ -3242,6 +2193,30 @@ photoOutput.capture((err) => {
### capture ### capture
capture(): Promise<void\>
以默认设置触发一次拍照,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| -------------- | ------------------------ |
| Promise<void\> | 使用Promise的方式获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:**
```js
photoOutput.capture().then(() => {
console.log('Promise returned to indicate that photo capture request success.');
}).catch((err) => {
console.log('Failed to photoOutput capture '+ err.code);
});
```
### capture
capture(setting: PhotoCaptureSetting, callback: AsyncCallback<void\>): void capture(setting: PhotoCaptureSetting, callback: AsyncCallback<void\>): void
以指定参数触发一次拍照,通过注册回调函数获取结果。 以指定参数触发一次拍照,通过注册回调函数获取结果。
...@@ -3253,7 +2228,7 @@ capture(setting: PhotoCaptureSetting, callback: AsyncCallback<void\>): void ...@@ -3253,7 +2228,7 @@ capture(setting: PhotoCaptureSetting, callback: AsyncCallback<void\>): void
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------- | ---- | -------------------- | | -------- | ------------------------------------------- | ---- | -------------------- |
| setting | [PhotoCaptureSetting](#photocapturesetting) | 是 | 拍照设置。 | | setting | [PhotoCaptureSetting](#photocapturesetting) | 是 | 拍照设置。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 | | callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
...@@ -3271,7 +2246,7 @@ let settings = { ...@@ -3271,7 +2246,7 @@ let settings = {
} }
photoOutput.capture(settings, (err) => { photoOutput.capture(settings, (err) => {
if (err) { if (err) {
console.error(`Failed to capture the photo ${err.message}`); console.error(`Failed to capture the photo ${err.code}`);
return; return;
} }
console.log('Callback invoked to indicate the photo capture request success.'); console.log('Callback invoked to indicate the photo capture request success.');
...@@ -3296,41 +2271,37 @@ capture(setting?: PhotoCaptureSetting): Promise<void\> ...@@ -3296,41 +2271,37 @@ capture(setting?: PhotoCaptureSetting): Promise<void\>
| 类型 | 说明 | | 类型 | 说明 |
| -------------- | ------------------------ | | -------------- | ------------------------ |
| Promise<void\> | 使用Promise的方式获取结果。 | | Promise<void\> | 使用Promise的方式获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
```js ```js
photoOutput.capture().then(() => { photoOutput.capture(settings).then(() => {
console.log('Promise returned to indicate that photo capture request success.'); console.log('Promise returned to indicate that photo capture request success.');
}) }).catch((err) => {
console.log('Failed to photoOutput capture '+ err.code);
});
``` ```
### isMirrorSupported ### isMirrorSupported
isMirrorSupported(callback: AsyncCallback<boolean\>): void isMirrorSupported(): boolean
查询是否支持镜像拍照,通过注册回调函数获取结果 查询是否支持镜像拍照。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **返回值:**
| 参数名 | 类型 | 必填 | 说明 | | 类型 | 说明 |
| -------- | ------------------------------------------------- | ---- | -------------------------- | | -------------- | ----------------------- |
| callback | AsyncCallback<boolean\> | 是 | 回调函数,返回是否支持镜像拍照。 | | boolean | 返回是否支持镜像拍照。 |
**示例:** **示例:**
```js ```js
photoOutput.isMirrorSupported((err, isSupported) => { let isSupported = photoOutput.isMirrorSupported();
if (err) {
console.error(`Failed to check mirror is supported ${err.message}`);
return;
}
console.log('Callback returned with the successful execution of isMirrorSupported.');
})
``` ```
### release ### release
...@@ -3345,14 +2316,14 @@ release(callback: AsyncCallback<void\>): void ...@@ -3345,14 +2316,14 @@ release(callback: AsyncCallback<void\>): void
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------- | | -------- | -------------------- | ---- | ------------------- |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 | | callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
```js ```js
photoOutput.release((err) => { photoOutput.release((err) => {
if (err) { if (err) {
console.error(`Failed to release the PreviewOutput instance ${err.message}`); console.error(`Failed to release the PreviewOutput instance ${err.code}`);
return; return;
} }
console.log('Callback invoked to indicate that the PreviewOutput instance is released successfully.'); console.log('Callback invoked to indicate that the PreviewOutput instance is released successfully.');
...@@ -3371,36 +2342,16 @@ release(): Promise<void\> ...@@ -3371,36 +2342,16 @@ release(): Promise<void\>
| 类型 | 说明 | | 类型 | 说明 |
| -------------- | ----------------------- | | -------------- | ----------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 | | Promise<void\> | 使用Promise的方式获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
```js ```js
photoOutput.release().then(() => { photoOutput.release().then(() => {
console.log('Promise returned to indicate that the PreviewOutput instance is released successfully.'); console.log('Promise returned to indicate that the PreviewOutput instance is released successfully.');
}) }).catch((err) => {
``` console.log('Failed to photoOutput release '+ err.code);
});
### isMirrorSupported
isMirrorSupported(): Promise<boolean\>
查询是否支持镜像拍照,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| ----------------- | ------------------------------------------- |
| Promise<boolean\> | 使用Promise的方式获取结果,返回是否支持自拍结果。 |
**示例:**
```js
photoOutput.isMirrorSupported().then((isSupported) => {
console.log(`Promise returned with mirror supported: ${isSupported}`);
})
``` ```
### on('captureStart') ### on('captureStart')
...@@ -3415,13 +2366,13 @@ on(type: 'captureStart', callback: AsyncCallback<number\>): void ...@@ -3415,13 +2366,13 @@ on(type: 'captureStart', callback: AsyncCallback<number\>): void
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------- | ---- | ------------------------------------------ | | -------- | ---------------------- | ---- | ------------------------------------------ |
| type | string | 是 | 监听事件,固定为'captureStart',即拍照启动事件。 | | type | string | 是 | 监听事件,固定为'captureStart',callback返回拍照开始事件。 |
| callback | AsyncCallback<number\> | 是 | 使用callback的方式获取Capture ID。 | | callback | AsyncCallback<number\> | 是 | 使用callback的方式获取Capture ID。 |
**示例:** **示例:**
```js ```js
photoOutput.on('captureStart', (err, captureId) => { photoOutput.on('captureStart', (captureId) => {
console.log(`photo capture stated, captureId : ${captureId}`); console.log(`photo capture stated, captureId : ${captureId}`);
}) })
``` ```
...@@ -3438,13 +2389,13 @@ on(type: 'frameShutter', callback: AsyncCallback<FrameShutterInfo\>): void ...@@ -3438,13 +2389,13 @@ on(type: 'frameShutter', callback: AsyncCallback<FrameShutterInfo\>): void
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------------------- | --- | ------------------------------------ | | -------- | ----------------------------------------------------- | --- | ------------------------------------ |
| type | string | 是 | 监听事件,固定为'frameShutter',即帧刷新事件。 | | type | string | 是 | 监听事件,固定为'frameShutter',callback返回拍照图像获取成功信息(captureId跟获取时间)。 |
| callback | AsyncCallback<[FrameShutterInfo](#frameshutterinfo)\> | 是 | 回调函数,用于获取相关信息。 | | callback | AsyncCallback<[FrameShutterInfo](#frameshutterinfo)\> | 是 | 回调函数,用于获取相关信息。 |
**示例:** **示例:**
```js ```js
photoOutput.on('frameShutter', (err, frameShutterInfo) => { photoOutput.on('frameShutter', (frameShutterInfo) => {
console.log(`photo capture end, captureId : ${frameShutterInfo.captureId}`); console.log(`photo capture end, captureId : ${frameShutterInfo.captureId}`);
console.log(`Timestamp for frame : ${frameShutterInfo.timestamp}`); console.log(`Timestamp for frame : ${frameShutterInfo.timestamp}`);
}) })
...@@ -3462,13 +2413,13 @@ on(type: 'captureEnd', callback: AsyncCallback<CaptureEndInfo\>): void ...@@ -3462,13 +2413,13 @@ on(type: 'captureEnd', callback: AsyncCallback<CaptureEndInfo\>): void
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------- | ---- | ---------------------------------------- | | -------- | ------------------------------------------------- | ---- | ---------------------------------------- |
| type | string | 是 | 监听事件,固定为'captureEnd',即拍照停止事件。 | | type | string | 是 | 监听事件,固定为'captureEnd',callback返回拍照结束事件。 |
| callback | AsyncCallback<[CaptureEndInfo](#captureendinfo)\> | 是 | 回调函数,用于获取相关信息。 | | callback | AsyncCallback<[CaptureEndInfo](#captureendinfo)\> | 是 | 回调函数,用于获取相关信息。 |
**示例:** **示例:**
```js ```js
photoOutput.on('captureEnd', (err, captureEndInfo) => { photoOutput.on('captureEnd', (captureEndInfo) => {
console.log(`photo capture end, captureId : ${captureEndInfo.captureId}`); console.log(`photo capture end, captureId : ${captureEndInfo.captureId}`);
console.log(`frameCount : ${captureEndInfo.frameCount}`); console.log(`frameCount : ${captureEndInfo.frameCount}`);
}) })
...@@ -3476,7 +2427,7 @@ photoOutput.on('captureEnd', (err, captureEndInfo) => { ...@@ -3476,7 +2427,7 @@ photoOutput.on('captureEnd', (err, captureEndInfo) => {
### on('error') ### on('error')
on(type: 'error', callback: ErrorCallback<PhotoOutputError\>): void on(type: 'error', callback: ErrorCallback<BusinessError\>): void
监听拍照输出发生错误,通过注册回调函数获取结果。 监听拍照输出发生错误,通过注册回调函数获取结果。
...@@ -3486,14 +2437,14 @@ on(type: 'error', callback: ErrorCallback<PhotoOutputError\>): void ...@@ -3486,14 +2437,14 @@ on(type: 'error', callback: ErrorCallback<PhotoOutputError\>): void
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------------------- | ---- | ----------------------------------- | | -------- | ----------------------------------------------------- | ---- | ----------------------------------- |
| type | string | 是 | 监听事件,固定为'error',即拍照错误事件。 | | type | string | 是 | 监听事件,固定为'error',callback 返回拍照接口调用时出现错误并返回错误码。 |
| callback | ErrorCallback<[PhotoOutputError](#photooutputerror)\> | 是 | 回调函数,用于获取错误信息。 | | callback | ErrorCallback<BusinessError\> | 是 | 回调函数,用于获取错误信息。返回错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
```js ```js
photoOutput.on('error', (err, photoOutputError) => { photoOutput.on('error', (error) => {
console.log(`Photo output error code: ${photoOutputError.code}`); console.log(`Photo output error code: ${error.code}`);
}) })
``` ```
...@@ -3519,29 +2470,6 @@ photoOutput.on('error', (err, photoOutputError) => { ...@@ -3519,29 +2470,6 @@ photoOutput.on('error', (err, photoOutputError) => {
| captureId | number | 是 | 拍照的ID。 | | captureId | number | 是 | 拍照的ID。 |
| frameCount | number | 是 | 帧数。 | | frameCount | number | 是 | 帧数。 |
## PhotoOutputErrorCode
枚举,拍照输出错误类型。
**系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 值 | 说明 |
| ----------------------------- | ---- | --------------- |
| ERROR_UNKNOWN | -1 | 未知错误。 |
| ERROR_DRIVER_ERROR | 0 | 驱动或者硬件错误。 |
| ERROR_INSUFFICIENT_RESOURCES | 1 | 资源不足。 |
| ERROR_TIMEOUT | 2 | 超时。 |
## PhotoOutputError
拍照输出错误码。
**系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 类型 | 必填 |说明 |
| ---- | ------------------------------------- | --------- | ----------------------- |
| code | [PhotoOutputErrorCode](#photooutputerrorcode) | 是 | PhotoOutput中的错误码。 |
## VideoOutput ## VideoOutput
录像会话中使用的输出信息,继承[CameraOutput](#cameraoutput) 录像会话中使用的输出信息,继承[CameraOutput](#cameraoutput)
...@@ -3558,14 +2486,14 @@ start(callback: AsyncCallback<void\>): void ...@@ -3558,14 +2486,14 @@ start(callback: AsyncCallback<void\>): void
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | -------------------- | | -------- | -------------------- | ---- | -------------------- |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 | | callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
```js ```js
videoOutput.start((err) => { videoOutput.start((err) => {
if (err) { if (err) {
console.error(`Failed to start the video output ${err.message}`); console.error(`Failed to start the video output ${err.code}`);
return; return;
} }
console.log('Callback invoked to indicate the video output start success.'); console.log('Callback invoked to indicate the video output start success.');
...@@ -3584,7 +2512,7 @@ start(): Promise<void\> ...@@ -3584,7 +2512,7 @@ start(): Promise<void\>
| 类型 | 说明 | | 类型 | 说明 |
| -------------- | ----------------------- | | -------------- | ----------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 | | Promise<void\> | 使用Promise的方式获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
...@@ -3592,7 +2520,9 @@ start(): Promise<void\> ...@@ -3592,7 +2520,9 @@ start(): Promise<void\>
```js ```js
videoOutput.start().then(() => { videoOutput.start().then(() => {
console.log('Promise returned to indicate that start method execution success.'); console.log('Promise returned to indicate that start method execution success.');
}) }).catch((err) => {
console.log('Failed to videoOutput start '+ err.code);
});
``` ```
### stop ### stop
...@@ -3614,7 +2544,7 @@ stop(callback: AsyncCallback<void\>): void ...@@ -3614,7 +2544,7 @@ stop(callback: AsyncCallback<void\>): void
```js ```js
videoOutput.stop((err) => { videoOutput.stop((err) => {
if (err) { if (err) {
console.error(`Failed to stop the video output ${err.message}`); console.error(`Failed to stop the video output ${err.code}`);
return; return;
} }
console.log('Callback invoked to indicate the video output stop success.'); console.log('Callback invoked to indicate the video output stop success.');
...@@ -3640,7 +2570,9 @@ stop(): Promise<void\> ...@@ -3640,7 +2570,9 @@ stop(): Promise<void\>
```js ```js
videoOutput.stop().then(() => { videoOutput.stop().then(() => {
console.log('Promise returned to indicate that stop method execution success.'); console.log('Promise returned to indicate that stop method execution success.');
}) }).catch((err) => {
console.log('Failed to videoOutput stop '+ err.code);
});
``` ```
### release ### release
...@@ -3655,14 +2587,14 @@ release(callback: AsyncCallback<void\>): void ...@@ -3655,14 +2587,14 @@ release(callback: AsyncCallback<void\>): void
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------- | | -------- | -------------------- | ---- | ------------------- |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 | | callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
```js ```js
videoOutput.release((err) => { videoOutput.release((err) => {
if (err) { if (err) {
console.error(`Failed to release the PreviewOutput instance ${err.message}`); console.error(`Failed to release the PreviewOutput instance ${err.code}`);
return; return;
} }
console.log('Callback invoked to indicate that the PreviewOutput instance is released successfully.'); console.log('Callback invoked to indicate that the PreviewOutput instance is released successfully.');
...@@ -3681,14 +2613,16 @@ release(): Promise<void\> ...@@ -3681,14 +2613,16 @@ release(): Promise<void\>
| 类型 | 说明 | | 类型 | 说明 |
| -------------- | ----------------------- | | -------------- | ----------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 | | Promise<void\> | 使用Promise的方式获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
```js ```js
videoOutput.release().then(() => { videoOutput.release().then(() => {
console.log('Promise returned to indicate that the PreviewOutput instance is released successfully.'); console.log('Promise returned to indicate that the PreviewOutput instance is released successfully.');
}) }).catch((err) => {
console.log('Failed to videoOutput release '+ err.code);
});
``` ```
### on('frameStart') ### on('frameStart')
...@@ -3703,7 +2637,7 @@ on(type: 'frameStart', callback: AsyncCallback<void\>): void ...@@ -3703,7 +2637,7 @@ on(type: 'frameStart', callback: AsyncCallback<void\>): void
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ----------------------------------------- | | -------- | -------------------- | ---- | ----------------------------------------- |
| type | string | 是 | 监听事件,固定为'frameStart',即视频帧开启事件。 | | type | string | 是 | 监听事件,固定为'frameStart',callback返回录像开始获取第一帧图像时返回。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 | | callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:** **示例:**
...@@ -3726,7 +2660,7 @@ on(type: 'frameEnd', callback: AsyncCallback<void\>): void ...@@ -3726,7 +2660,7 @@ on(type: 'frameEnd', callback: AsyncCallback<void\>): void
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------------------------ | | -------- | -------------------- | ---- | ------------------------------------------ |
| type | string | 是 | 监听事件,固定为'frameEnd',即视频帧结束事件 。 | | type | string | 是 | 监听事件,固定为'frameEnd',callback返回录像结束获取最后一帧图像时返回 。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 | | callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:** **示例:**
...@@ -3739,7 +2673,7 @@ videoOutput.on('frameEnd', () => { ...@@ -3739,7 +2673,7 @@ videoOutput.on('frameEnd', () => {
### on('error') ### on('error')
on(type: 'error', callback: ErrorCallback<VideoOutputError\>): void on(type: 'error', callback: ErrorCallback<BusinessError\>): void
监听录像输出发生错误,通过注册回调函数获取结果。 监听录像输出发生错误,通过注册回调函数获取结果。
...@@ -3749,38 +2683,17 @@ on(type: 'error', callback: ErrorCallback<VideoOutputError\>): void ...@@ -3749,38 +2683,17 @@ on(type: 'error', callback: ErrorCallback<VideoOutputError\>): void
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------ | ---- | -------------------------------------- | | -------- | ------------------------------------------------ | ---- | -------------------------------------- |
| type | string | 是 | 监听事件,固定为'error',即视频输出错误事件。 | | type | string | 是 | 监听事件,固定为'error',callback返回录像接口调用时出现错误时返回对应错误码,比如调用(start(),release())接口时出现错误返回对应错误码。 |
| callback | Callback<[VideoOutputError](#videooutputerror)\> | 是 | 回调函数,用于获取错误信息。 | | callback | Callback<BusinessError\> | 是 | 回调函数,用于获取错误信息。返回错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
```js ```js
videoOutput.on('error', (VideoOutputError) => { videoOutput.on('error', (error) => {
console.log(`Video output error code: ${VideoOutputError.code}`); console.log(`Video output error code: ${error.code}`);
}) })
``` ```
## VideoOutputErrorCode
枚举,录像输出错误类型。
**系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 值 | 说明 |
| --------------------- | ---- | ------------ |
| ERROR_UNKNOWN | -1 | 未知错误。 |
| ERROR_DRIVER_ERROR | 0 | 驱动或者硬件错误。|
## VideoOutputError
录像输出错误码。
**系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 类型 | 必填 | 说明 |
| ---- | ------------------------------------- | ----------------- | ----------------------- |
| code | [PhotoOutputErrorCode](#photooutputerrorcode) | 是 | VideoOutput中的错误码。 |
## MetadataOutput ## MetadataOutput
metadata流。继承[CameraOutput](#cameraoutput) metadata流。继承[CameraOutput](#cameraoutput)
...@@ -3796,15 +2709,15 @@ start(callback: AsyncCallback<void\>): void ...@@ -3796,15 +2709,15 @@ start(callback: AsyncCallback<void\>): void
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------------------------- | ---- | ------------------- | | -------- | -------------------------- | ---- | ------------------- |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 | | callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
```js ```js
metadataOutput.start((err) => { metadataOutput.start((err) => {
if (err) { if (err) {
console.error(`Failed to start metadataOutput. ${err.message}`); console.error(`Failed to start metadataOutput. ${err.code}`);
return; return;
} }
console.log('Callback returned with metadataOutput started.'); console.log('Callback returned with metadataOutput started.');
...@@ -3823,14 +2736,16 @@ start(): Promise<void\> ...@@ -3823,14 +2736,16 @@ start(): Promise<void\>
| 类型 | 说明 | | 类型 | 说明 |
| ---------------------- | ------------------------ | | ---------------------- | ------------------------ |
| Promise<void\> | 使用Promise的方式获取结果。 | | Promise<void\> | 使用Promise的方式获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
```js ```js
metadataOutput.start().then(() => { metadataOutput.start().then(() => {
console.log('Callback returned with metadataOutput started.'); console.log('Callback returned with metadataOutput started.');
}) }).catch((err) => {
console.log('Failed to metadataOutput start '+ err.code);
});
``` ```
### stop ### stop
...@@ -3852,7 +2767,7 @@ stop(callback: AsyncCallback<void\>): void ...@@ -3852,7 +2767,7 @@ stop(callback: AsyncCallback<void\>): void
```js ```js
metadataOutput.stop((err) => { metadataOutput.stop((err) => {
if (err) { if (err) {
console.error(`Failed to stop the metadataOutput. ${err.message}`); console.error(`Failed to stop the metadataOutput. ${err.code}`);
return; return;
} }
console.log('Callback returned with metadataOutput stopped.'); console.log('Callback returned with metadataOutput stopped.');
...@@ -3878,7 +2793,9 @@ stop(): Promise<void\> ...@@ -3878,7 +2793,9 @@ stop(): Promise<void\>
```js ```js
metadataOutput.stop().then(() => { metadataOutput.stop().then(() => {
console.log('Callback returned with metadataOutput stopped.'); console.log('Callback returned with metadataOutput stopped.');
}) }).catch((err) => {
console.log('Failed to metadataOutput stop '+ err.code);
});
``` ```
### on('metadataObjectsAvailable') ### on('metadataObjectsAvailable')
...@@ -3893,8 +2810,8 @@ on(type: 'metadataObjectsAvailable', callback: AsyncCallback<Array<MetadataObjec ...@@ -3893,8 +2810,8 @@ on(type: 'metadataObjectsAvailable', callback: AsyncCallback<Array<MetadataObjec
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------ | ---- | ------------------------------------ | | -------- | ------------------------------------------------ | ---- | ------------------------------------ |
| type | string | 是 | 监听事件,固定为'metadataObjectsAvailable',即metadata对象。 | | type | string | 是 | 监听事件,固定为'metadataObjectsAvailable',检测到有效的metadata数据时callback返回相应的metadata数据,metadataOutput创建成功时可监听。 |
| callback | Callback<Array<[MetadataObject](#metadataobject)\>\> | 是 | 回调函数,用于获取错误信息。 | | callback | Callback<Array<[MetadataObject](#metadataobject)\>\> | 是 | 回调函数,用于获取metadata数据。 |
**示例:** **示例:**
...@@ -3906,7 +2823,7 @@ metadataOutput.on('metadataObjectsAvailable', (metadataObjectArr) => { ...@@ -3906,7 +2823,7 @@ metadataOutput.on('metadataObjectsAvailable', (metadataObjectArr) => {
### on('error') ### on('error')
on(type: 'error', callback: ErrorCallback<MetadataOutputError\>): void on(type: 'error', callback: ErrorCallback<BusinessError\>): void
监听metadata流的错误,通过注册回调函数获取结果。 监听metadata流的错误,通过注册回调函数获取结果。
...@@ -3916,8 +2833,8 @@ on(type: 'error', callback: ErrorCallback<MetadataOutputError\>): void ...@@ -3916,8 +2833,8 @@ on(type: 'error', callback: ErrorCallback<MetadataOutputError\>): void
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------ | ---- | --------------------------------------- | | -------- | ------------------------------------------------ | ---- | --------------------------------------- |
| type | string | 是 | 监听事件,固定为'error',即metadata流的错误。 | | type | string | 是 | 监听事件,固定为'error',callback 返回metadata输出接口使用错误时返回对应错误码,比如调用(start(),release())接口时发生错误返回对应错误码。 |
| callback | Callback<[MetadataOutputError](#metadataoutputerror)\> | 是 | 回调函数,用于获取错误信息。 | | callback | Callback<BusinessError\> | 是 | 回调函数,用于获取错误信息。返回错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
**示例:** **示例:**
...@@ -3927,27 +2844,6 @@ metadataOutput.on('error', (metadataOutputError) => { ...@@ -3927,27 +2844,6 @@ metadataOutput.on('error', (metadataOutputError) => {
}) })
``` ```
## MetadataOutputErrorCode
枚举,metadata输出错误类型。
**系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 值 | 说明 |
| ------------------------------- | ---- | -------- |
| ERROR_UNKNOWN | -1 | 未知错误。 |
| ERROR_INSUFFICIENT_RESOURCES | 0 | 资源不足。 |
## MetadataOutputError
metadata输出错误码。
**系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 类型 | 必填 | 说明 |
| ---- | ------------------------------------- | ----------------- | ----------------------- |
| code | [MetadataOutputErrorCode](#metadataoutputerrorcode) | 是 | MetadataOutput中的错误码。 |
## MetadataObjectType ## MetadataObjectType
枚举,metadata流。 枚举,metadata流。
...@@ -3956,7 +2852,7 @@ metadata输出错误码。 ...@@ -3956,7 +2852,7 @@ metadata输出错误码。
| 名称 | 值 | 说明 | | 名称 | 值 | 说明 |
| ------------------------- | ---- | ----------------- | | ------------------------- | ---- | ----------------- |
| FACE_DETECTION | 0 | metadata对象类型。 | | FACE_DETECTION | 0 | metadata对象类型,人脸检测。 |
## Rect ## Rect
...@@ -3975,156 +2871,8 @@ metadata输出错误码。 ...@@ -3975,156 +2871,8 @@ metadata输出错误码。
相机元能力信息,[CameraInput](#camerainput)相机信息中的数据来源,通过metadataOutput.on('metadataObjectsAvailable')接口获取 相机元能力信息,[CameraInput](#camerainput)相机信息中的数据来源,通过metadataOutput.on('metadataObjectsAvailable')接口获取
### getType | 名称 | 类型 | 必填 | 说明 |
| -------- | ------------------------------- | ---- | -----------------|
getType(callback: AsyncCallback<MetadataObjectType\>): void | type | [MetadataObjectType](#metadataobjecttype) | 否 | metadata 类型,目前只有人脸识别。 |
| timestamp | number | 否 | 当前时间戳(毫秒)。 |
查询metadata对象类型,通过注册回调函数获取结果。 | boundingBox | [Rect](#rect) | 否 | metadata 区域框 |
\ No newline at end of file
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------------------------- | --- | -------------------- |
| callback | AsyncCallback<[MetadataObjectType](#metadataobjecttype)\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```js
let metadataObject = metadataObjectArr[0];
metadataObject.getType((err, metadataObjectType) => {
if (err) {
console.error(`Failed to get type. ${err.message}`);
return;
}
console.log('Callback returned with an array of metadataObjectType.');
})
```
### getType
getType(): Promise<MetadataObjectType\>
查询metadata对象类型,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| --------------------------------------------------- | --------------------------- |
| Promise<[MetadataObjectType](#metadataobjecttype)\> | 使用Promise的方式获取结果。 |
**示例:**
```js
let metadataObject = metadataObjectArr[0];
metadataObject.getType().then((metadataObjectType) => {
console.log('Callback returned with an array of metadataObjectType.');
})
```
### getTimestamp
getTimestamp(callback: AsyncCallback<number\>): void
查询metadata时间戳,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------------------------- | ---- | ------------------------ |
| callback | AsyncCallback<number\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```js
let metadataObject = metadataObjectArr[0];
metadataObject.getTimestamp((err,timestamp) => {
if (err) {
console.error(`Failed to get timestamp. ${err.message}`);
return;
}
console.log('Callback returned with timestamp getted timestamp : ${timestamp}');
})
```
### getTimestamp
getTimestamp(): Promise<number\>
查询metadata时间戳,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| ---------------- | --------------------------- |
| Promise<number)\> | 使用Promise的方式获取结果。 |
**示例:**
```js
let metadataObject = metadataObjectArr[0];
metadataObject.getTimestamp().then((timestamp) => {
console.log('Callback returned with timestamp getted timestamp : ${timestamp}');
})
```
### getBoundingBox
getBoundingBox(callback: AsyncCallback<Rect\>): void
查询metadata的边界框,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------------------------- | ---- | ------------------------ |
| callback | AsyncCallback<[Rect](#rect)\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```js
let metadataObject = metadataObjectArr[0];
metadataObject.getBoundingBox((err, rect) => {
if (err) {
console.error(`Failed to get boundingBox. ${err.message}`);
return;
}
console.log('Callback returned with boundingBox getted.');
})
```
### getBoundingBox
getBoundingBox(): Promise<Rect\>
查询metadata的边界框,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| ---------------------- | --------------------------- |
| Promise<[Rect](#rect)\> | 使用Promise的方式获取结果。 |
**示例:**
```js
let metadataObject = metadataObjectArr[0];
metadataObject.getBoundingBox().then((rect) => {
console.log('Callback returned with boundingBox getted.');
})
```
## MetadataFaceObject
metadata的人脸对象。继承[MetadataObject](#metadataobject)
\ No newline at end of file
# 媒体子系统 JS API 变更 Changelog
OpenHarmony3.2.10.3 相对 OpenHarmony3.2 Beta4 版本,媒体子系统 camera 部件 API 变更如下
## cl.subsystemname.1 camera 接口变更
1. camera 部件在 API9 版本全量改为 SystemAPI
2. 基于以下原因新增部分功能接口以及废弃部分接口:
提升开发者使用相机接口的便利。
帮助开发者快速掌握相机开发接口,快速投入到开发当中。
易于后续版本中框架功能的扩展,降低框架模块之间的耦合度。
具体参考下方变更内容,开发者需要根据以下说明对应用进行适配。
**变更影响**
影响 API9 版本的 JS 接口,应用需要进行适配才可以在新版本 SDK 环境正常实现功能。
**关键的接口/组件变更**
| 模块名 | 类名 | 方法/属性/枚举/常量 | 是否为 SystemApi | 变更类型 |
| ---------------------- | ----------------------- | ------------------------------------------------------------ | --------------- | -------- |
| ohos.multimedia.camera | camera | function getCameraManager(context: Context): CameraManager; | 是 | 新增 |
| ohos.multimedia.camera | camera | function getCameraManager(context: Context, callback: AsyncCallback<CameraManager>): void;<br/>function getCameraManager(context: Context): Promise<CameraManager>; | 是 | 废弃 |
| ohos.multimedia.camera | CameraErrorCode | INVALID_ARGUMENT = 7400101,<br/>OPERATION_NOT_ALLOWED = 7400102,<br/>SESSION_NOT_CONFIG = 7400103,<br/>SESSION_NOT_RUNNING = 7400104,<br/>SESSION_CONFIG_LOCKED = 7400105,<br/>DEVICE_SETTING_LOCKED = 7400106,<br/>CONFILICT_CAMERA = 7400107,<br/>DEVICE_DISABLED = 7400108,<br/>SERVICE_FATAL_ERROR = 7400201 | 是 | 新增 |
| ohos.multimedia.camera | CameraManager | getSupportedCameras(): Array<CameraDevice>;<br/>getSupportedOutputCapability(camera: CameraDevice): CameraOutputCapability;<br/>createCameraInput(camera: CameraDevice): CameraInput;<br/>createCameraInput(position: CameraPosition, type: CameraType): CameraInput;<br/>createPreviewOutput(profile: Profile, surfaceId: string): PreviewOutput;<br/>createPhotoOutput(profile: Profile, surfaceId: string): PhotoOutput;<br/>createVideoOutput(profile: VideoProfile, surfaceId: string): VideoOutput;<br/>createMetadataOutput(metadataObjectTypes: Array<MetadataObjectType>): MetadataOutput;<br/>createCaptureSession(): CaptureSession; | 是 | 新增 |
| ohos.multimedia.camera | CameraManager | getSupportedCameras(callback: AsyncCallback<Array<CameraDevice>>): void;<br/>getSupportedCameras(): Promise<Array<CameraDevice>>;<br/>getSupportedOutputCapability(camera: CameraDevice, callback: AsyncCallback<CameraOutputCapability>): void;<br/>getSupportedOutputCapability(camera: CameraDevice): Promise<CameraOutputCapability>;<br/>createCameraInput(camera: CameraDevice, callback: AsyncCallback<CameraInput>): void;<br/>createCameraInput(camera: CameraDevice): Promise<CameraInput>;<br/>createCameraInput(position: CameraPosition, type: CameraType, callback: AsyncCallback<CameraInput>): void;<br/>createCameraInput(position: CameraPosition, type: CameraType): Promise<CameraInput>;<br/>createPreviewOutput(profile: Profile, surfaceId: string, callback: AsyncCallback<PreviewOutput>): void;<br/>createPreviewOutput(profile: Profile, surfaceId: string): Promise<PreviewOutput>;<br/>createPhotoOutput(profile: Profile, surfaceId: string, callback: AsyncCallback<PhotoOutput>): void;<br/>createPhotoOutput(profile: Profile, surfaceId: string): Promise<PhotoOutput>;<br/>createVideoOutput(profile: VideoProfile, surfaceId: string, callback: AsyncCallback<VideoOutput>): void;<br/>createVideoOutput(profile: VideoProfile, surfaceId: string): Promise<VideoOutput>;<br/>createMetadataOutput(metadataObjectTypes: Array<MetadataObjectType>, callback: AsyncCallback<MetadataOutput>): void;<br/>createMetadataOutput(metadataObjectTypes: Array<MetadataObjectType>): Promise<MetadataOutput>;<br/>createCaptureSession(callback: AsyncCallback<CaptureSession>): void;<br/>createCaptureSession(): Promise<CaptureSession>; | 是 | 废弃 |
| ohos.multimedia.camera | CameraType | CAMERA_TYPE_DEFAULT = 0 | 是 | 新增 |
| ohos.multimedia.camera | CameraType | CAMERA_TYPE_UNSPECIFIED = 0 | 是 | 废弃 |
| ohos.multimedia.camera | CameraInput | on(type: 'error', camera: CameraDevice, callback: ErrorCallback<BusinessError>): void; | 是 | 新增 |
| ohos.multimedia.camera | CameraInput | release(callback: AsyncCallback<void>): void;<br/>release(): Promise<void>;<br/>on(type: 'error', camera: CameraDevice, callback: ErrorCallback<CameraInputError>): void; | 是 | 废弃 |
| ohos.multimedia.camera | CameraInputErrorCode | ERROR_UNKNOWN = -1<br/>ERROR_NO_PERMISSION = 0<br/>ERROR_DEVICE_PREEMPTED = 1<br/>ERROR_DEVICE_DISCONNECTED = 2<br/>ERROR_DEVICE_IN_USE = 3<br/>ERROR_DRIVER_ERROR = 4 | 是 | 废弃 |
| ohos.multimedia.camera | CameraInputError | code: CameraInputErrorCode | 是 | 废弃 |
| ohos.multimedia.camera | CaptureSession | beginConfig(): void;<br/>addInput(cameraInput: CameraInput): void;<br/>removeInput(cameraInput: CameraInput): void;<br/>addOutput(cameraOutput: CameraOutput): void;<br/>removeOutput(cameraOutput: CameraOutput): void;<br/>hasFlash(): boolean;<br/>isFlashModeSupported(flashMode: FlashMode): boolean;<br/>getFlashMode(): FlashMode;<br/>setFlashMode(flashMode: FlashMode): void;<br/>isExposureModeSupported(aeMode: ExposureMode): boolean;<br/>getExposureMode(): ExposureMode;<br/>setExposureMode(aeMode: ExposureMode): void;<br/>getMeteringPoint(): Point;<br/>setMeteringPoint(point: Point): void;<br/>getExposureBiasRange(): Array<number>;<br/>setExposureBias(exposureBias: number): void;<br/>getExposureValue(): number;<br/>isFocusModeSupported(afMode: FocusMode): boolean;<br/>getFocusMode(): FocusMode;<br/>setFocusMode(afMode: FocusMode): void;<br/>setFocusPoint(point: Point): void;<br/>getFocusPoint(): Point;<br/>getFocalLength(): number;<br/>getZoomRatioRange(): Array<number>;<br/>getZoomRatio(): number;<br/>setZoomRatio(zoomRatio: number): void;<br/>isVideoStabilizationModeSupported(vsMode: VideoStabilizationMode): boolean;<br/>getActiveVideoStabilizationMode(): VideoStabilizationMode;<br/>setVideoStabilizationMode(mode: VideoStabilizationMode): void;<br/>on(type: 'error', callback: ErrorCallback<BusinessError>): void; | 是 | 新增 |
| ohos.multimedia.camera | CaptureSession | beginConfig(callback: AsyncCallback<void>): void;<br/>beginConfig(): Promise<void>;<br/>addInput(cameraInput: CameraInput, callback: AsyncCallback<void>): void;<br/>addInput(cameraInput: CameraInput): Promise<void>;<br/>removeInput(cameraInput: CameraInput, callback: AsyncCallback<void>): void;<br/>removeInput(cameraInput: CameraInput): Promise<void>;<br/>addOutput(cameraOutput: CameraOutput, callback: AsyncCallback<void>): void;<br/>addOutput(cameraOutput: CameraOutput): Promise<void>;<br/>removeOutput(cameraOutput: CameraOutput, callback: AsyncCallback<void>): void;<br/>removeOutput(cameraOutput: CameraOutput): Promise<void>;<br/>hasFlash(callback: AsyncCallback<boolean>): void;<br/>hasFlash(): Promise<boolean>;<br/>isFlashModeSupported(flashMode: FlashMode, callback: AsyncCallback<boolean>): void;<br/>isFlashModeSupported(flashMode: FlashMode): Promise<boolean>;<br/>getFlashMode(callback: AsyncCallback<FlashMode>): void;<br/>getFlashMode(): Promise<FlashMode>;<br/>setFlashMode(flashMode: FlashMode, callback: AsyncCallback<void>): void;<br/>setFlashMode(flashMode: FlashMode): Promise<void>;<br/>isExposureModeSupported(aeMode: ExposureMode, callback: AsyncCallback<boolean>): void;<br/>isExposureModeSupported(aeMode: ExposureMode): Promise<boolean>;<br/>getExposureMode(callback: AsyncCallback<ExposureMode>): void;<br/>getExposureMode(): Promise<ExposureMode>;<br/>setExposureMode(aeMode: ExposureMode, callback: AsyncCallback<void>): void;<br/>setExposureMode(aeMode: ExposureMode): Promise<void>;<br/>getMeteringPoint(callback: AsyncCallback<Point>): void;<br/>getMeteringPoint(): Promise<Point>;<br/>setMeteringPoint(point: Point, callback: AsyncCallback<void>): void;<br/>setMeteringPoint(point: Point): Promise<void>;<br/>getExposureBiasRange(callback: AsyncCallback<Array<number>>): void;<br/>getExposureBiasRange(): Promise<Array<number>>;<br/>setExposureBias(exposureBias: number, callback: AsyncCallback<void>): void;<br/>setExposureBias(exposureBias: number): Promise<void>;<br/>getExposureValue(callback: AsyncCallback<number>): void;<br/>getExposureValue(): Promise<number>;<br/>isFocusModeSupported(afMode: FocusMode, callback: AsyncCallback<boolean>): void;<br/>isFocusModeSupported(afMode: FocusMode): Promise<boolean>;<br/>getFocusMode(callback: AsyncCallback<FocusMode>): void;<br/>getFocusMode(): Promise<FocusMode>;<br/>setFocusMode(afMode: FocusMode, callback: AsyncCallback<void>): void;<br/>setFocusMode(afMode: FocusMode): Promise<void>;<br/>setFocusPoint(point: Point, callback: AsyncCallback<void>): void;<br/>setFocusPoint(point: Point): Promise<void>;<br/>getFocusPoint(callback: AsyncCallback<Point>): void;<br/>getFocusPoint(): Promise<Point>;<br/>getFocalLength(callback: AsyncCallback<number>): void;<br/>getFocalLength(): Promise<number>;<br/>getZoomRatioRange(callback: AsyncCallback<Array<number>>): void;<br/>getZoomRatioRange(): Promise<Array<number>>;<br/>getZoomRatio(callback: AsyncCallback<number>): void;<br/>getZoomRatio(): Promise<number>;<br/>setZoomRatio(zoomRatio: number, callback: AsyncCallback<void>): void;<br/>setZoomRatio(zoomRatio: number): Promise<void>;<br/>isVideoStabilizationModeSupported(vsMode: VideoStabilizationMode, callback: AsyncCallback<boolean>): void;<br/>isVideoStabilizationModeSupported(vsMode: VideoStabilizationMode): Promise<boolean>;<br/>getActiveVideoStabilizationMode(callback: AsyncCallback<VideoStabilizationMode>): void;<br/>getActiveVideoStabilizationMode(): Promise<VideoStabilizationMode>;<br/>setVideoStabilizationMode(mode: VideoStabilizationMode, callback: AsyncCallback<void>): void;<br/>setVideoStabilizationMode(mode: VideoStabilizationMode): Promise<void>;<br/>on(type: 'error', callback: ErrorCallback<CaptureSessionError>): void; | 是 | 废弃 |
| ohos.multimedia.camera | CaptureSessionErrorCode | ERROR_UNKNOWN = -1<br/>ERROR_INSUFFICIENT_RESOURCES = 0<br/>ERROR_TIMEOUT = 1 | 是 | 废弃 |
| ohos.multimedia.camera | CaptureSessionError | code: CaptureSessionErrorCode | 是 | 废弃 |
| ohos.multimedia.camera | PreviewOutput | on(type: 'error', callback: ErrorCallback<BusinessError>): void; | 是 | 新增 |
| ohos.multimedia.camera | PreviewOutput | on(type: 'error', callback: ErrorCallback<PreviewOutputError>): void; | 是 | 废弃 |
| ohos.multimedia.camera | PreviewOutputErrorCode | ERROR_UNKNOWN = -1 | 是 | 废弃 |
| ohos.multimedia.camera | PreviewOutputError | code: PreviewOutputErrorCode | 是 | 废弃 |
| ohos.multimedia.camera | PhotoOutput | capture(): Promise<void>;<br/>isMirrorSupported(): boolean;<br/>on(type: 'error', callback: ErrorCallback<BusinessError>): void; | 是 | 新增 |
| ohos.multimedia.camera | PhotoOutput | isMirrorSupported(callback: AsyncCallback<boolean>): void;<br/>isMirrorSupported(): Promise<boolean>;<br/>on(type: 'error', callback: ErrorCallback<PhotoOutputError>): void; | 是 | 废弃 |
| ohos.multimedia.camera | PhotoOutputErrorCode | ERROR_UNKNOWN = -1<br/>ERROR_DRIVER_ERROR = 0<br/>ERROR_INSUFFICIENT_RESOURCES = 1<br/>ERROR_TIMEOUT = 2 | 是 | 废弃 |
| ohos.multimedia.camera | PhotoOutputError | code: PhotoOutputErrorCode | 是 | 废弃 |
| ohos.multimedia.camera | VideoOutput | on(type: 'error', callback: ErrorCallback<BusinessError>): void; | 是 | 新增 |
| ohos.multimedia.camera | VideoOutput | on(type: 'error', callback: ErrorCallback<VideoOutputError>): void; | 是 | 废弃 |
| ohos.multimedia.camera | VideoOutputErrorCode | ERROR_UNKNOWN = -1<br/>ERROR_DRIVER_ERROR = 0 | 是 | 废弃 |
| ohos.multimedia.camera | VideoOutputError | code: VideoOutputErrorCode | 是 | 废弃 |
| ohos.multimedia.camera | MetadataObject | readonly type: MetadataObjectType;<br/>readonly timestamp: number; | 是 | 新增 |
| ohos.multimedia.camera | MetadataObject | getType(callback: AsyncCallback<MetadataObjectType>): void;<br/>getType(): Promise<MetadataObjectType>;<br/>getTimestamp(callback: AsyncCallback<number>): void;<br/>getTimestamp(): Promise<number>;<br/>getBoundingBox(callback: AsyncCallback<Rect>): void;<br/>getBoundingBox(): Promise<Rect>; | 是 | 废弃 |
| ohos.multimedia.camera | MetadataFaceObject | readonly boundingBox: Rect | 是 | 新增 |
| ohos.multimedia.camera | MetadataOutput | on(type: 'error', callback: ErrorCallback<BusinessError>): void; | 是 | 新增 |
| ohos.multimedia.camera | MetadataOutput | on(type: 'error', callback: ErrorCallback<BusinessError>): void; | 是 | 废弃 |
| ohos.multimedia.camera | MetadataOutputErrorCode | ERROR_UNKNOWN = -1<br/>ERROR_INSUFFICIENT_RESOURCES = 0 | 是 | 废弃 |
| ohos.multimedia.camera | MetadataOutputError | code: MetadataOutputErrorCode | 是 | 废弃 |
**适配指导**
除新增接口,和废弃接口之外,开发者需要关注变更的接口的适配:
从 Beta4 版本开始,对以下接口进行调整:
**新增接口**
1. CameraErrorCode 枚举
枚举值名称:INVALID_ARGUMENT, 值:7400101;
枚举值名称:OPERATION_NOT_ALLOWED, 值:7400102;
枚举值名称:SESSION_NOT_CONFIG, 值:7400103;
枚举值名称:SESSION_NOT_RUNNING, 值:7400104;
枚举值名称:SESSION_CONFIG_LOCKED, 值:7400105;
枚举值名称:DEVICE_SETTING_LOCKED, 值:7400106;
枚举值名称:CONFILICT_CAMERA, 值:7400107;
枚举值名称:DEVICE_DISABLED, 值:7400108;
枚举值名称:SERVICE_FATAL_ERROR, 值:7400201;
2. PhotoOutput 接口新增 capture(): Promise<void>;
3. MetadataObject 接口中新增 readonly type: MetadataObjectType;
4. MetadataObject 接口中新增 readonly timestamp: number;
5. MetadataObject 接口中新增 readonly boundingBox: Rect;
**废弃接口**
1. CameraInput 中废弃接口 release(callback: AsyncCallback<void>): void; 以及 release(): Promise<void>;
2. 废弃枚举 CameraInputErrorCode 以及所有它里边的枚举值(ERROR_UNKNOWN = -1,ERROR_NO_PERMISSION = 0,ERROR_DEVICE_PREEMPTED = 1,ERROR_DEVICE_DISCONNECTED = 2,ERROR_DEVICE_IN_USE = 3,ERROR_DRIVER_ERROR = 4);
3. 废弃接口 CameraInputError 以及接口属性 code:CameraInputErrorCode;
4. 废弃枚举 CaptureSessionErrorCode 以及所有它里边的枚举值(ERROR_UNKNOWN = -1,ERROR_INSUFFICIENT_RESOURCES = 0,ERROR_TIMEOUT = 1);
5. 废弃接口 CaptureSessionError 以及接口属性 code: CaptureSessionErrorCode;
6. 废弃枚举 PreviewOutputErrorCode 以及所有它里边的枚举值(ERROR_UNKNOWN = -1);
7. 废弃接口 PreviewOutputError 以及接口属性 code: PreviewOutputErrorCode;
8. 废弃枚举 PhotoOutputErrorCode 以及所有它里边的枚举值(ERROR_UNKNOWN = -1,ERROR_DRIVER_ERROR = 0,ERROR_INSUFFICIENT_RESOURCES = 1,ERROR_TIMEOUT = 2);
9. 废弃接口 PhotoOutputError 以及接口属性 code:PhotoOutputErrorCode;
10. 废弃枚举 VideoOutputErrorCode 以及所有它里边的枚举值(ERROR_UNKNOWN = -1,ERROR_DRIVER_ERROR = 0);
11. 废弃接口 VideoOutputError 以及接口属性 code:VideoOutputErrorCode;
12. 废弃接口 MetadataObject 中 getType(callback: AsyncCallback<MetadataObjectType>): void;
13. 废弃接口 MetadataObject 中 getType(): Promise<MetadataObjectType>;
14. 废弃接口 MetadataObject 中 getTimestamp(callback: AsyncCallback<number>): void;
15. 废弃接口 MetadataObject 中 getTimestamp(): Promise<number>;
16. 废弃接口 MetadataObject 中 getBoundingBox(callback: AsyncCallback<Rect>): void;
17. 废弃接口 MetadataObject 中 getBoundingBox(): Promise<Rect>;
18. 废弃枚举 MetadataOutputErrorCode 以及所有它里边的枚举值(ERROR_UNKNOWN = -1,ERROR_INSUFFICIENT_RESOURCES = 0);
19. 废弃接口 MetadataOutputError 以及接口属性 code:MetadataOutputErrorCode;
**接口变更**
1. camera 模块中接口 getCameraManager 返回方式由异步 callback 跟异步 promise 变更为同步返回,因此旧接口 getCameraManager(context: Context, callback: AsyncCallback<CameraManager>): void; 以及 getCameraManager(context: Context): Promise<CameraManager>; 变更为 getCameraManager(context: Context): CameraManager;
参考代码如下:
```
let cameraManager = camera.getCameraManager(context);
```
2. CameraManager 中接口 getSupportedCameras 返回方式由异步 callback 跟异步 promise 变更为同步返回,因此旧接口 getSupportedCameras(callback: AsyncCallback<Array<CameraDevice>>): void; 以及 getSupportedCameras(): Promise<Array<CameraDevice>>; 变更为 getSupportedCameras(): Array<CameraDevice>;
参考代码如下:
```
let cameras = cameraManager.getSupportedCameras();
```
3. CameraManager 中接口 getSupportedOutputCapability 返回方式由异步 callback 跟异步 promise 变更为同步返回,因此旧接口 getSupportedOutputCapability(camera: CameraDevice, callback: AsyncCallback<CameraOutputCapability>): void; 以及 getSupportedOutputCapability(camera: CameraDevice): Promise<CameraOutputCapability>; 变更为 getSupportedOutputCapability(camera: CameraDevice): CameraOutputCapability;
参考代码如下:
```
let cameraDevice = cameras[0];
let CameraOutputCapability = cameraManager.getSupportedOutputCapability(cameraDevice);
```
4. CameraManager 中接口 createCameraInput(camera: CameraDevice) 返回方式由异步 callback 跟异步 promise 变更为同步返回,因此旧接口 createCameraInput(camera: CameraDevice, callback: AsyncCallback<CameraInput>): void; 以及 createCameraInput(camera: CameraDevice): Promise<CameraInput>; 变更为 createCameraInput(camera: CameraDevice): CameraInput;
参考代码如下:
```
let cameraDevice = cameras[0];
let cameraInput = cameraManager.createCameraInput(cameraDevice);
```
5. CameraManager 中接口 createCameraInput(position: CameraPosition, type: CameraType) 返回方式由异步 callback 跟异步 promise 变更为同步返回,因此旧接口 createCameraInput(position: CameraPosition, type: CameraType, callback: AsyncCallback<CameraInput>): void; 以及 createCameraInput(position: CameraPosition, type: CameraType): Promise<CameraInput>; 变更为 createCameraInput(position: CameraPosition, type: CameraType): CameraInput;
参考代码如下:
```
let cameraDevice = cameras[0];
let position = cameraDevice.cameraPosition;
let type = cameraDevice.cameraType;
let cameraInput = cameraManager.createCameraInput(position, type);
```
6. CameraManager 中接口 createPreviewOutput 返回方式由异步 callback 跟异步 promise 变更为同步返回,因此旧接口 createPreviewOutput(profile: Profile, surfaceId: string, callback: AsyncCallback<PreviewOutput>): void; 以及 createPreviewOutput(profile: Profile, surfaceId: string): Promise<PreviewOutput>; 变更为 createPreviewOutput(profile: Profile, surfaceId: string): PreviewOutput;
参考代码如下:
```
let profile = cameraoutputcapability.previewProfiles[0];
let previewOutput = cameraManager.createPreviewOutput(profile, surfaceId);
```
7. CameraManager 中接口 createPhotoOutput 返回方式由异步 callback 跟异步 promise 变更为同步返回,因此旧接口 createPhotoOutput(profile: Profile, surfaceId: string, callback: AsyncCallback<PhotoOutput>): void; 以及 createPhotoOutput(profile: Profile, surfaceId: string): Promise<PhotoOutput>; 变更为 createPhotoOutput(profile: Profile, surfaceId: string): PhotoOutput;
参考代码如下:
```
let profile = cameraoutputcapability.photoProfiles[0];
let photoOutput = cameraManager.createPhotoOutput(profile, surfaceId);
```
8. CameraManager 中接口 createVideoOutput 返回方式由异步 callback 跟异步 promise 变更为同步返回,因此旧接口 createVideoOutput(profile: VideoProfile, surfaceId: string, callback: AsyncCallback<VideoOutput>): void; 以及 createVideoOutput(profile: VideoProfile, surfaceId: string): Promise<VideoOutput>; 变更为 createVideoOutput(profile: VideoProfile, surfaceId: string): VideoOutput;
参考代码如下:
```
let profile = cameraoutputcapability.videoProfiles[0];
let videoOutput = cameraManager.createVideoOutput(profile, surfaceId);
```
9. CameraManager 中接口 createMetadataOutput 返回方式由异步 callback 跟异步 promise 变更为同步返回,因此旧接口 createMetadataOutput(metadataObjectTypes: Array<MetadataObjectType>, callback: AsyncCallback<MetadataOutput>): void; 以及 createMetadataOutput(metadataObjectTypes: Array<MetadataObjectType>): Promise<MetadataOutput>; 变更为 createMetadataOutput(metadataObjectTypes: Array<MetadataObjectType>): MetadataOutput;
参考代码如下:
```
let metadataObjectTypes = cameraoutputcapability.supportedMetadataObjectTypes;
let metadataOutput = cameraManager.createMetadataOutput(metadataObjectTypes);
```
10. CameraManager 中接口 createCaptureSession 返回方式由异步 callback 跟异步 promise 变更为同步返回,因此旧接口 createCaptureSession(callback: AsyncCallback<CaptureSession>): void; 以及 createCaptureSession(): Promise<CaptureSession>; 变更为 createCaptureSession(): CaptureSession;
参考代码如下:
```
let captureSession = cameraManager.createCaptureSession();
```
11. 枚举 CameraType 中,枚举值名称 CAMERA_TYPE_UNSPECIFIED 变更为 CAMERA_TYPE_DEFAULT。
12. CameraInput 中,on 接口返回值类型由 CameraInputError 变更为 BusinessError,因此旧接口 on(type: 'error', camera: CameraDevice, callback: ErrorCallback<CameraInputError>): void; 变更为 on(type: 'error', camera: CameraDevice, callback: ErrorCallback<BusinessError>): void;
参考代码如下:
```
let cameraDevice = cameras[0];
cameraInput.on('error', cameraDevice, (BusinessError) => {
})
```
13. CaptureSession 中接口 beginConfig 返回方式由异步 callback 跟异步 promise 变更为同步返回,因此旧接口 beginConfig(callback: AsyncCallback<void>): void; 以及 beginConfig(): Promise<void>; 变更为 beginConfig(): void;
参考代码如下:
```
captureSession.beginConfig();
```
14. CaptureSession 中接口 addInput 返回方式由异步 callback 跟异步 promise 变更为同步返回,因此旧接口 addInput(cameraInput: CameraInput, callback: AsyncCallback<void>): void; 以及 addInput(cameraInput: CameraInput): Promise<void>; 变更为 addInput(cameraInput: CameraInput): void;
参考代码如下:
```
captureSession.addInput(cameraInput);
```
15. CaptureSession 中接口 removeInput 返回方式由异步 callback 跟异步 promise 变更为同步返回,因此旧接口 removeInput(cameraInput: CameraInput, callback: AsyncCallback<void>): void; 以及 removeInput(cameraInput: CameraInput): Promise<void>; 变更为 removeInput(cameraInput: CameraInput): void;
参考代码如下:
```
captureSession.removeInput(cameraInput);
```
16. CaptureSession 中接口 addOutput 返回方式由异步 callback 跟异步 promise 变更为同步返回,因此旧接口 addOutput(cameraOutput: CameraOutput, callback: AsyncCallback<void>): void; 以及 addOutput(cameraOutput: CameraOutput): Promise<void>; 变更为 addOutput(cameraOutput: CameraOutput): void;
参考代码如下:
```
captureSession.addOutput(previewOutput);
```
17. CaptureSession 中接口 removeOutput 返回方式由异步 callback 跟异步 promise 变更为同步返回,因此旧接口 removeOutput(cameraOutput: CameraOutput, callback: AsyncCallback<void>): void; 以及 removeOutput(cameraOutput: CameraOutput): Promise<void>; 变更为 removeOutput(cameraOutput: CameraOutput): void;
参考代码如下:
```
captureSession.removeOutput(previewOutput);
```
18. CaptureSession 中接口 hasFlash 返回方式由异步 callback 跟异步 promise 变更为同步返回,因此旧接口 hasFlash(callback: AsyncCallback<boolean>): void; 以及 hasFlash(): Promise<boolean>; 变更为 hasFlash(): boolean;
参考代码如下:
```
let status = captureSession.hasFlash();
```
19. CaptureSession 中接口 isFlashModeSupported 返回方式由异步 callback 跟异步 promise 变更为同步返回,因此旧接口 isFlashModeSupported(flashMode: FlashMode, callback: AsyncCallback<boolean>): void; 以及 isFlashModeSupported(flashMode: FlashMode): Promise<boolean>; 变更为 isFlashModeSupported(flashMode: FlashMode): boolean;
参考代码如下:
```
let status = captureSession.isFlashModeSupported(camera.FlashMode.FLASH_MODE_AUTO);
```
20. CaptureSession 中接口 getFlashMode 返回方式由异步 callback 跟异步 promise 变更为同步返回,因此旧接口 getFlashMode(callback: AsyncCallback<FlashMode>): void; 以及 getFlashMode(): Promise<FlashMode>; 变更为 getFlashMode(): FlashMode;
参考代码如下:
```
let flashMode = captureSession.getFlashMode();
```
21. CaptureSession 中接口 isExposureModeSupported 返回方式由异步 callback 跟异步 promise 变更为同步返回,因此旧接口 isExposureModeSupported(aeMode: ExposureMode, callback: AsyncCallback<boolean>): void; 以及 isExposureModeSupported(aeMode: ExposureMode): Promise<boolean>; 变更为 isExposureModeSupported(aeMode: ExposureMode): boolean;
参考代码如下:
```
let isSupported = captureSession.isExposureModeSupported(camera.ExposureMode.EXPOSURE_MODE_LOCKED);
```
22. CaptureSession 中接口 getExposureMode 返回方式由异步 callback 跟异步 promise 变更为同步返回,因此旧接口 getExposureMode(callback: AsyncCallback<ExposureMode>): void; 以及 getExposureMode(): Promise<ExposureMode>; 变更为 getExposureMode(): ExposureMode;
参考代码如下:
```
let exposureMode = captureSession.getExposureMode();
```
23. CaptureSession 中接口 setExposureMode 返回方式由异步 callback 跟异步 promise 变更为同步返回,因此旧接口 setExposureMode(aeMode: ExposureMode, callback: AsyncCallback<void>): void; 以及 setExposureMode(aeMode: ExposureMode): Promise<void>; 变更为 setExposureMode(aeMode: ExposureMode): void;
参考代码如下:
```
captureSession.setExposureMode(camera.ExposureMode.EXPOSURE_MODE_LOCKED);
```
24. CaptureSession 中接口 getMeteringPoint 返回方式由异步 callback 跟异步 promise 变更为同步返回,因此旧接口 getMeteringPoint(callback: AsyncCallback<Point>): void; 以及 getMeteringPoint(): Promise<Point>; 变更为 getMeteringPoint(): Point;
参考代码如下:
```
let exposurePoint = captureSession.getMeteringPoint();
```
25. CaptureSession 中接口 setMeteringPoint 返回方式由异步 callback 跟异步 promise 变更为同步返回,因此旧接口 setMeteringPoint(point: Point, callback: AsyncCallback<void>): void; 以及 setMeteringPoint(point: Point): Promise<void>; 变更为 setMeteringPoint(point: Point): void;
参考代码如下:
```
let Point2 = {x: 2, y: 2};
captureSession.setMeteringPoint(Point2);
```
26. CaptureSession 中接口 getExposureBiasRange 返回方式由异步 callback 跟异步 promise 变更为同步返回,因此旧接口 getExposureBiasRange(callback: AsyncCallback<Array<number>>): void; 以及 getExposureBiasRange(): Promise<Array<number>>; 变更为 getExposureBiasRange(): Array<number>;
参考代码如下:
```
let biasRangeArray = captureSession.getExposureBiasRange();
```
27. CaptureSession 中接口 setExposureBias 返回方式由异步 callback 跟异步 promise 变更为同步返回,因此旧接口 setExposureBias(exposureBias: number, callback: AsyncCallback<void>): void; 以及 setExposureBias(exposureBias: number): Promise<void>; 变更为 setExposureBias(exposureBias: number): void;
参考代码如下:
```
let exposureBias = biasRangeArray[0];
captureSession.setExposureBias(exposureBias);
```
28. CaptureSession 中接口 getExposureValue 返回方式由异步 callback 跟异步 promise 变更为同步返回,因此旧接口 getExposureValue(callback: AsyncCallback<number>): void; 以及 getExposureValue(): Promise<number>; 变更为 getExposureValue(): number;
参考代码如下:
```
let exposureValue = captureSession.getExposureValue();
```
29. CaptureSession 中接口 isFocusModeSupported 返回方式由异步 callback 跟异步 promise 变更为同步返回,因此旧接口 isFocusModeSupported(afMode: FocusMode, callback: AsyncCallback<boolean>): void; 以及 isFocusModeSupported(afMode: FocusMode): Promise<boolean>; 变更为 isFocusModeSupported(afMode: FocusMode): boolean;
参考代码如下:
```
let status = captureSession.isFocusModeSupported(camera.FocusMode.FOCUS_MODE_AUTO);
```
30. CaptureSession 中接口 getFocusMode 返回方式由异步 callback 跟异步 promise 变更为同步返回,因此旧接口 getFocusMode(callback: AsyncCallback<FocusMode>): void; 以及 getFocusMode(): Promise<FocusMode>; 变更为 getFocusMode(): FocusMode;
参考代码如下:
```
let afMode = captureSession.getFocusMode();
```
31. CaptureSession 中接口 setFocusMode 返回方式由异步 callback 跟异步 promise 变更为同步返回,因此旧接口 setFocusMode(afMode: FocusMode, callback: AsyncCallback<void>): void; 以及 setFocusMode(afMode: FocusMode): Promise<void>; 变更为 setFocusMode(afMode: FocusMode): void;
参考代码如下:
```
captureSession.setFocusMode(camera.FocusMode.FOCUS_MODE_AUTO);
```
32. CaptureSession 中接口 setFocusPoint 返回方式由异步 callback 跟异步 promise 变更为同步返回,因此旧接口 setFocusPoint(point: Point, callback: AsyncCallback<void>): void; 以及 setFocusPoint(point: Point): Promise<void>; 变更为 setFocusPoint(point: Point): void;
参考代码如下:
```
let Point2 = {x: 2, y: 2};
captureSession.setFocusPoint(Point2);
```
33. CaptureSession 中接口 getFocusPoint 返回方式由异步 callback 跟异步 promise 变更为同步返回,因此旧接口 getFocusPoint(callback: AsyncCallback<Point>): void; 以及 getFocusPoint(): Promise<Point>; 变更为 getFocusPoint(): Point;
参考代码如下:
```
let point = captureSession.getFocusPoint();
```
34. CaptureSession 中接口 getFocalLength 返回方式由异步 callback 跟异步 promise 变更为同步返回,因此旧接口 getFocalLength(callback: AsyncCallback<number>): void; 以及 getFocalLength(): Promise<number>; 变更为 getFocalLength(): number;
参考代码如下:
```
let focalLength = captureSession.getFocalLength();
```
35. CaptureSession 中接口 getZoomRatioRange 返回方式由异步 callback 跟异步 promise 变更为同步返回,因此旧接口 getZoomRatioRange(callback: AsyncCallback<Array<number>>): void; 以及 getZoomRatioRange(): Promise<Array<number>>; 变更为 getZoomRatioRange(): Array<number>;
参考代码如下:
```
let zoomRatioRange = captureSession.getZoomRatioRange();
```
36. CaptureSession 中接口 getZoomRatio 返回方式由异步 callback 跟异步 promise 变更为同步返回,因此旧接口 getZoomRatio(callback: AsyncCallback<number>): void; 以及 getZoomRatio(): Promise<number>; 变更为 getZoomRatio(): number;
参考代码如下:
```
let zoomRatio = captureSession.getZoomRatio();
```
37. CaptureSession 中接口 setZoomRatio 返回方式由异步 callback 跟异步 promise 变更为同步返回,因此旧接口 setZoomRatio(zoomRatio: number, callback: AsyncCallback<void>): void; 以及 setZoomRatio(zoomRatio: number): Promise<void>; 变更为 setZoomRatio(zoomRatio: number): void;
参考代码如下:
```
let zoomRatio = zoomRatioRange[0];
captureSession.setZoomRatio(zoomRatio);
```
38. CaptureSession 中接口 isVideoStabilizationModeSupported 返回方式由异步 callback 跟异步 promise 变更为同步返回,因此旧接口 isVideoStabilizationModeSupported(vsMode: VideoStabilizationMode, callback: AsyncCallback<boolean>): void; 以及 isVideoStabilizationModeSupported(vsMode: VideoStabilizationMode): Promise<boolean>; 变更为 isVideoStabilizationModeSupported(vsMode: VideoStabilizationMode): boolean;
参考代码如下:
```
let isSupported = captureSession.isVideoStabilizationModeSupported(camera.VideoStabilizationMode.OFF);
```
39. CaptureSession 中接口 getActiveVideoStabilizationMode 返回方式由异步 callback 跟异步 promise 变更为同步返回,因此旧接口 getActiveVideoStabilizationMode(callback: AsyncCallback<VideoStabilizationMode>): void; 以及 getActiveVideoStabilizationMode(): Promise<VideoStabilizationMode>; 变更为 getActiveVideoStabilizationMode(): VideoStabilizationMode;
参考代码如下:
```
let vsMode = captureSession.getActiveVideoStabilizationMode();
```
40. CaptureSession 中接口 setVideoStabilizationMode 返回方式由异步 callback 跟异步 promise 变更为同步返回,因此旧接口 setVideoStabilizationMode(mode: VideoStabilizationMode, callback: AsyncCallback<void>): void; 以及 setVideoStabilizationMode(mode: VideoStabilizationMode): Promise<void>; 变更为 setVideoStabilizationMode(mode: VideoStabilizationMode): void;
参考代码如下:
```
captureSession.setVideoStabilizationMode(camera.VideoStabilizationMode.OFF);
```
41. CaptureSession 中,on(type: 'error') callback 类型由 ErrorCallback<CaptureSessionError> 变更为 ErrorCallback<BusinessError>,因此旧接口 on(type: 'error', callback: ErrorCallback<CaptureSessionError>): void; 变更为 on(type: 'error', callback: ErrorCallback<BusinessError>): void;
参考代码如下:
```
captureSession.on('error', (BusinessError) => {
})
```
42. PreviewOutput 中,on(type: 'error') callback 类型由 ErrorCallback<PreviewOutputError> 变更为 ErrorCallback<BusinessError>,因此旧接口 on(type: 'error', callback: ErrorCallback<PreviewOutputError>): void; 变更为 on(type: 'error', callback: ErrorCallback<BusinessError>): void;
参考代码如下:
```
previewOutput.on('error', (BusinessError) => {
})
```
43. PhotoOutput 中接口 isMirrorSupported 返回方式由异步 callback 跟异步 promise 变更为同步返回,因此旧接口 isMirrorSupported(callback: AsyncCallback<boolean>): void; 以及 isMirrorSupported(): Promise<boolean>; 变更为 isMirrorSupported(): boolean;
参考代码如下:
```
let isSupported = photoOutput.isMirrorSupported();
```
44. PhotoOutput 中,on(type: 'error') callback 类型由 ErrorCallback<PhotoOutputError> 变更为 ErrorCallback<BusinessError>,因此旧接口 on(type: 'error', callback: ErrorCallback<PhotoOutputError>): void; 变更为 on(type: 'error', callback: ErrorCallback<BusinessError>): void;
参考代码如下:
```
PhotoOutput.on('error', (BusinessError) => {
})
```
45. VideoOutput 中,on(type: 'error') callback 类型由 ErrorCallback<VideoOutputError> 变更为 ErrorCallback<BusinessError>,因此旧接口 on(type: 'error', callback: ErrorCallback<VideoOutputError>): void; 变更为 on(type: 'error', callback: ErrorCallback<BusinessError>): void;
参考代码如下:
```
VideoOutput.on('error', (BusinessError) => {
})
```
46. MetadataOutput 中,on(type: 'error') callback 类型由 ErrorCallback<MetadataOutputError> 变更为 ErrorCallback<BusinessError>,因此旧接口 on(type: 'error', callback: ErrorCallback<MetadataOutputError>): void; 变更为 on(type: 'error', callback: ErrorCallback<BusinessError>): void;
参考代码如下:
```
MetadataOutput.on('error', (BusinessError) => {
})
```
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册