“a55dd22649ce99b3aa6e1b3d17904277d2550331”上不存在“paddle/math/git@gitcode.net:s920243400/PaddleDetection.git”
提交 5644ab36 编写于 作者: M mali

Camera development and interface document update

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