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

!7363 fixed new apis fo 3.2.

Merge pull request !7363 from 蒋旻洋/master
...@@ -21,7 +21,7 @@ getCameraManager(context: Context, callback: AsyncCallback<CameraManager\>): voi ...@@ -21,7 +21,7 @@ getCameraManager(context: Context, callback: AsyncCallback<CameraManager\>): voi
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------------- | ---- | ---------------------------------- | | -------- | ----------------------------------------------- | ---- | ---------------------------- |
| context | Context | 是 | 应用上下文。 | | context | Context | 是 | 应用上下文。 |
| callback | AsyncCallback<[CameraManager](#cameramanager)\> | 是 | 回调函数,用于获取相机管理器实例。 | | callback | AsyncCallback<[CameraManager](#cameramanager)\> | 是 | 回调函数,用于获取相机管理器实例。 |
...@@ -54,7 +54,7 @@ getCameraManager(context: Context): Promise<CameraManager\> ...@@ -54,7 +54,7 @@ getCameraManager(context: Context): Promise<CameraManager\>
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ----------------------------------------- | ----------------------------------------- | | ----------------------------------------- | ----------------------------------- |
| Promise<[CameraManager](#cameramanager)\> | 使用Promise的方式获取一个相机管理器实例。 | | Promise<[CameraManager](#cameramanager)\> | 使用Promise的方式获取一个相机管理器实例。 |
**示例:** **示例:**
...@@ -73,84 +73,78 @@ camera.getCameraManager(context).then((cameraManager) => { ...@@ -73,84 +73,78 @@ camera.getCameraManager(context).then((cameraManager) => {
| 名称 | 值 | 说明 | | 名称 | 值 | 说明 |
| ------------------------- | ---- | ------------ | | ------------------------- | ---- | ------------ |
| CAMERA_STATUS_APPEAR | 0 | 相机存在。 | | CAMERA_STATUS_APPEAR | 0 | 新的相机出现。 |
| CAMERA_STATUS_DISAPPEAR | 1 | 相机不存在。 | | CAMERA_STATUS_DISAPPEAR | 1 | 相机被移除。 |
| CAMERA_STATUS_AVAILABLE | 2 | 相机就绪。 | | CAMERA_STATUS_AVAILABLE | 2 | 相机可用。 |
| CAMERA_STATUS_UNAVAILABLE | 3 | 相机未就绪。 | | CAMERA_STATUS_UNAVAILABLE | 3 | 相机不可用。 |
## Profile
## CameraPosition 相机配置信息项。
枚举,相机方向。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 值 | 说明 | | 名称 | 类型 | 只读 | 说明 |
| --------------------------- | ---- | ---------------- | | -------- | ----------------------------- |---- | ------------- |
| CAMERA_POSITION_UNSPECIFIED | 0 | 未指定方向相机。 | | format | [CameraFormat](#cameraformat) | 是 | 输出格式。 |
| CAMERA_POSITION_BACK | 1 | 后置相机。 | | size | [Size](#size) | 是 | 分辨率。 |
| CAMERA_POSITION_FRONT | 2 | 前置相机。 |
## CameraType ## FrameRateRange
枚举,相机类型 帧率范围
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 值 | 说明 | | 名称 | 类型 | 只读 | 说明 |
| ----------------------- | ---- | ---------------- | | ------------------------- | ------ | ---- | ------------------- |
| CAMERA_TYPE_UNSPECIFIED | 0 | 未指定相机类型。 | | min | number | 是 | 最小速率,单位fps |
| CAMERA_TYPE_WIDE_ANGLE | 1 | 广角相机。 | | max | number | 是 | 最大速率,单位fps |
| CAMERA_TYPE_ULTRA_WIDE | 2 | 超级广角相机。 |
| CAMERA_TYPE_TELEPHOTO | 3 | 长焦相机。 |
| CAMERA_TYPE_TRUE_DEPTH | 4 | 深度相机。 |
## ConnectionType ## VideoProfile
枚举,相机连接类型。 视频配置信息项。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 值 | 说明 | | 名称 | 类型 | 只读 | 说明 |
| ---------------------------- | ---- | ------------- | | ------------------------- | ----------------------------------------- | --- |------------ |
| CAMERA_CONNECTION_BUILT_IN | 0 | 内置相机。 | | frameRateRanges | [FrameRateRange](#frameraterange) | 是 | 帧率。 |
| CAMERA_CONNECTION_USB_PLUGIN | 1 | 外置USB相机。 |
| CAMERA_CONNECTION_REMOTE | 2 | 分布式相机。 |
## Size ## CameraOutputCapability
用于表示相机预览、照片、视频支持的尺寸大小 相机输出能力项
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 类型 | 可读 | 可写 | 说明 | | 名称 | 类型 | 只读 | 说明 |
| ------ | ------ | ---- | ---- | ------------ | | ----------------------------- | -------------------------------------------------- | --- |------------------- |
| height | string | 是 | 是 | 图像的高度。 | | previewProfiles | Array<[Profile](#profile)\> | 是 | 支持的预览配置信息。 |
| width | number | 是 | 是 | 图像的宽度。 | | photoProfiles | Array<[Profile](#profile)\> | 是 | 支持的拍照配置信息。 |
| videoProfiles | Array<[VideoProfile](#videoprofile)\> | 是 | 支持的录像配置信息。 |
| supportedMetadataObjectTypes | Array<[MetadataObjectType](#metadataobjecttype)\> | 是 | 支持的metadata流类型信息。|
## CameraManager ## CameraManager
相机管理器类,使用前需要通过getCameraManager获取相机管理实例。 相机管理器类,使用前需要通过getCameraManager获取相机管理实例。
### getCameras ### getSupportedCameras
getCameras(callback: AsyncCallback<Array<Camera\>\>): void getSupportedCameras(callback: AsyncCallback<Array<CameraDevice\>\>): void
异步获取设备支持的相机列表,通过注册回调函数获取结果。 获取支持指定的相机设备对象,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------- | ---- | ------------------------------------ | | -------- | ----------------------------------------------------- | ---- | ------------------------------- |
| callback | AsyncCallback<Array<[Camera](#camera)\>\> | 是 | 使用callback方式获取支持的相机列表。 | | callback | AsyncCallback<Array<[CameraDevice](#cameradevice)\>\> | 是 | 使用callback方式获取支持的相机列表。 |
**示例:** **示例:**
```js ```js
cameraManager.getCameras((err, cameras) => { cameraManager.getSupportedCameras((err, cameras) => {
if (err) { if (err) {
console.error('Failed to get the cameras. ${err.message}'); console.error('Failed to get the cameras. ${err.message}');
return; return;
...@@ -159,866 +153,1025 @@ cameraManager.getCameras((err, cameras) => { ...@@ -159,866 +153,1025 @@ cameraManager.getCameras((err, cameras) => {
}) })
``` ```
### getCameras ### getSupportedCameras
getCameras(): Promise<Array<Camera\>\> getSupportedCameras(): Promise<Array<CameraDevice\>\>
异步获取设备支持的相机列表,通过Promise获取结果。 获取支持指定的相机设备对象,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ----------------------------------- | ----------------------------- | | ----------------------------------------------- | ------------------------- |
| Promise<Array<[Camera](#camera)\>\> | 使用promise获取支持相机列表。 | | Promise<Array<[CameraDevice](#cameradevice)\>\> | 使用promise获取支持相机列表。 |
**示例:** **示例:**
```js ```js
cameraManager.getCameras().then((cameraArray) => { cameraManager.getSupportedCameras().then((cameraArray) => {
console.log('Promise returned with an array of supported cameras: ' + cameraArray.length); console.log('Promise returned with an array of supported cameras: ' + cameraArray.length);
}) })
``` ```
### createCameraInput ### getSupportedOutputCapability
createCameraInput(cameraId: string, callback: AsyncCallback<CameraInput\>): void
使用相机ID异步创建CameraInput实例,通过注册回调函数获取结果。 getSupportedOutputCapability(camera:CameraDevice, callback: AsyncCallback<CameraOutputCapability\>): void
**需要权限:** ohos.permission.CAMERA 查询相机设备在模式下支持的输出能力,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------- | ---- | ----------------------------------- | | -------- | ---------------------------------------------------------------- | -- | -------------------------- |
| cameraId | string | 是 | 指定相机ID。 | | camera | [CameraDevice](#cameraDevice) | 是 | CameraDevice对象。 |
| callback | AsyncCallback<[CameraInput](#camerainput)\> | 是 | 回调函数,用于获取CameraInput实例。 | | callback | AsyncCallback<[CameraOutputCapability](#cameraoutputcapability)\> | 是 | 使用callback方式获取相机输出能力。 |
**示例:** **示例:**
```js ```js
cameraManager.createCameraInput(cameraId, (err, cameraInput) => { cameraManager.getSupportedOutputCapability(cameraDevice, (err, cameras) => {
if (err) { if (err) {
console.error('Failed to create the CameraInput instance. ${err.message}'); console.error('Failed to get the cameras. ${err.message}');
return; return;
} }
console.log('Callback returned with the CameraInput instance.'); console.log('Callback returned with an array of supported outputCapability: ' + cameras.length);
}) })
``` ```
### createCameraInput ### getSupportedOutputCapability
createCameraInput(cameraId: string): Promise<CameraInput\>
使用相机ID异步创建CameraInput实例,通过Promise获取结果。 getSupportedOutputCapability(camera:CameraDevice): Promise<CameraOutputCapability\>
**需要权限:** ohos.permission.CAMERA 查询相机设备在模式下支持的输出能力,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| -------- | ------ | ---- | ------------ | | -------- | --------------------------------- | ---- | ---------- |
| cameraId | string | 是 | 指定相机ID。 | | camera | [CameraDevice](#cameraDevice) | 是 | CameraDevice对象。|
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ------------------------------------- | ---------------------------------------- | | -------------------------------------------------------------- | ----------------------------- |
| Promise<[CameraInput](#camerainput)\> | 使用Promise的方式获取CameraInput的实例。 | | Promise<[CameraOutputCapability](#cameraoutputcapability)\> | 使用Promise的方式获取结果,返回相机输出能力。 |
**示例:** **示例:**
```js ```js
cameraManager.createCameraInput(cameraId).then((cameraInput) => { cameraManager.getSupportedOutputCapability(cameraDevice).then((cameraoutputcapability) => {
console.log('Promise returned with the CameraInput instance'); console.log('Promise returned with an array of supported outputCapability: ' + cameraArray.length);
}) })
``` ```
### createCameraInput ### isCameraMuted
createCameraInput(position: CameraPosition, type: CameraType, callback: AsyncCallback<CameraInput\>): void
使用相机位置和相机类型异步创建CameraInput实例,通过注册回调函数获取结果。 isCameraMuted(callback: AsyncCallback<boolean\>): void
**需要权限:** ohos.permission.CAMERA 查询相机是否被禁用,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------- | ---- | ----------------------------------- | | -------- | ---------------------------------------- | ---- | ------------------------------------ |
| position | [CameraPosition](#cameraposition) | 是 | 相机位置。 | | callback | AsyncCallback<boolean\> | 是 | 回调函数,回调返回true即相机被禁用,否则为false。 |
| type | [CameraType](#cameratype) | 是 | 相机类型。 |
| callback | AsyncCallback<[CameraInput](#camerainput)\> | 是 | 回调函数,用于获取CameraInput实例。 |
**示例:** **示例:**
```js ```js
cameraManager.createCameraInput(camera.CameraPosition.CAMERA_POSITION_BACK, camera.CameraType.CAMERA_TYPE_UNSPECIFIED, (err, cameraInput) => { cameraManager.isCameraMuted((err, status) => {
if (err) { if (err) {
console.error('Failed to create the CameraInput instance. ${err.message}'); console.error('Failed to get the cameraMuted status. ${err.message}');
return; return;
} }
console.log('Callback returned with the CameraInput instance'); console.log('Callback returned with cameraMuted status');
}) })
``` ```
### createCameraInput ### isCameraMuted
createCameraInput(position: CameraPosition, type: CameraType): Promise<CameraInput\>
使用相机位置和相机类型异步创建CameraInput实例,通过Promise获取结果。 isCameraMuted(): Promise<boolean\>
**需要权限:** ohos.permission.CAMERA 查询相机是否被禁用,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | --------------------------------- | ---- | ---------- |
| position | [CameraPosition](#cameraposition) | 是 | 相机位置。 |
| type | [CameraType](#cameratype) | 是 | 相机类型。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ------------------------------------- | ---------------------------------------- | | ------------------------------------ | --------------------------------------------- |
| Promise<[CameraInput](#camerainput)\> | 使用Promise的方式获取CameraInput的实例。 | | Promise<boolean\> | 使用Promise的方式获取结果,返回相机是否禁用的结果。 |
**示例:** **示例:**
```js ```js
cameraManager.createCameraInput(camera.CameraPosition.CAMERA_POSITION_BACK, camera.CameraType.CAMERA_TYPE_UNSPECIFIED).then((cameraInput) => { cameraManager.isCameraMuted().then((status) => {
console.log('Promise returned with the CameraInput instance.'); console.log('Promise returned with the status whether camera is muted.');
}) })
``` ```
### on('cameraStatus') ### isCameraMuteSupported
on(type: 'cameraStatus', callback: AsyncCallback<CameraStatusInfo\>): void isCameraMuteSupported(callback: AsyncCallback<boolean\>): void
查询是否支持相机禁用,通过注册回调函数获取结果。
此接口为系统接口。
监听相机的状态变化,通过注册回调函数获取相机的状态变化。 **需要权限:** ohos.permission.CAMERA
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| :------- | :---------------------------------------------------- | :--- | :--------------------------------------------------- | | -------- | --------------------------------------- | ---- | ------------------------------------ |
| type | string | 是 | 监听事件,固定为'cameraStatus',即相机状态变化事件。 | | callback | AsyncCallback<boolean\> | 是 | 使用callback方式获取是否支持相机禁用的结果。 |
| callback | AsyncCallback<[CameraStatusInfo](#camerastatusinfo)\> | 是 | 回调函数,用于获取相机状态变化信息。 |
**示例:** **示例:**
```js ```js
cameraManager.on('cameraStatus', (err, cameraStatusInfo) => { cameraManager.isCameraMuteSupported((err, status) => {
if (err) { if (err) {
console.error('Failed to get cameraStatus callback. ${err.message}'); console.error('Failed to get the cameraMuteSupported. ${err.message}');
return; return;
} }
console.log('camera : ' + cameraStatusInfo.camera.cameraId); console.log('Callback returned with the status whether cameraMuteSupported.');
console.log('status: ' + cameraStatusInfo.status);
}) })
``` ```
## Camera ### isCameraMuteSupported
调用[camera.getCameraManager](#cameragetcameramanager)后,将返回Camera实例,包括相机ID、位置、类型、连接类型等相机相关的元数据。 isCameraMuteSupported(): Promise<boolean\>
**系统能力:** SystemCapability.Multimedia.Camera.Core 查询是否支持相机禁用,通过Promise获取结果
| 名称 | 类型 | 只读 | 说明 | 此接口为系统接口。
| -------------- | --------------------------------- | ---- | -------------- |
| cameraId | string | 是 | 相机ID。 |
| cameraPosition | [CameraPosition](#cameraposition) | 是 | 相机位置。 |
| cameraType | [CameraType](#cameratype) | 是 | 相机类型。 |
| connectionType | [ConnectionType](#connectiontype) | 是 | 相机连接类型。 |
**示例:** **需要权限:** ohos.permission.CAMERA
```js **系统能力:** SystemCapability.Multimedia.Camera.Core
async function getCameraInfo("cameraId") {
var cameraManager = await camera.getCameraManager(context);
var cameras = await cameraManager.getCameras();
var cameraObj = cameras[0];
var cameraId = cameraObj.cameraId;
var cameraPosition = cameraObj.cameraPosition;
var cameraType = cameraObj.cameraType;
var connectionType = cameraObj.connectionType;
}
```
## CameraStatusInfo **返回值:**
相机管理器回调返回的接口实例,表示相机状态信息。 | 类型 | 说明 |
| --------------------- | ----------------------------- |
| Promise<boolean\> | 使用Promise的方式获取结果,返回是否支持相机禁用的结果。 |
**系统能力:** SystemCapability.Multimedia.Camera.Core。
| 名称 | 类型 | 说明 | **示例:**
| ------ | ----------------------------- | ---------- |
| camera | [Camera](#camera) | 相机信息。 |
| status | [CameraStatus](#camerastatus) | 相机状态。 |
```js
cameraManager.isCameraMuteSupported().then((status) => {
console.log('Promise returned with the status whether cameraMuteSupported.');
})
```
## CameraInput ### muteCamera
相机输入类。在使用该类的方法前,需要先构建一个CameraInput实例。 muteCamera(mute:boolean, callback: AsyncCallback<void\>): void
### getCameraId 禁用相机,通过注册回调函数获取结果。
getCameraId(callback: AsyncCallback<string\>\): void 此接口为系统接口。
异步获取该CameraInput实例的相机ID,通过注册回调函数获取结果。 **需要权限:** ohos.permission.CAMERA
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| -------- | ---------------------- | ---- | -------------------------- | | -------- | ----------------------------------------- | ---- | ------------------------------------ |
| callback | AsyncCallback<string\> | 是 | 回调函数,用于获取相机ID。 | | mute | boolean | 是 | 是否禁用相机。 |
| callback | AsyncCallback<void\> | 是 | 使用callback方式获取相机禁用的结果。 |
**示例:** **示例:**
```js ```js
cameraInput.getCameraId((err, cameraId) => { cameraManager.muteCamera(isMuted, (err) => {
if (err) { if (err) {
console.error('Failed to get the camera ID. ${err.message}'); console.error('Failed to mute the camera. ${err.message}');
return; return;
} }
console.log('Callback returned with the camera ID: ' + cameraId); console.log('Callback returned with the muteCamera.');
}) })
``` ```
### getCameraId ### muteCamera
muteCamera(mute:boolean): Promise<void\>
禁用相机,通过Promise获取结果。
getCameraId(): Promise<string\> 此接口为系统接口。
异步获取该CameraInput实例的相机ID,通过Promise获取结果。 **需要权限:** ohos.permission.CAMERA
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------- | ---- | ------------ |
| mute | boolean | 是 | 是否禁用相机。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ---------------- | ----------------------------- | | ----------------------------------- | ----------------------------- |
| Promise<string\> | 使用Promise的方式获取相机ID。 | | Promise<void\> | 使用Promise的方式获取结果,返回是否禁用相机的结果。 |
**示例:** **示例:**
```js ```js
cameraInput.getCameraId().then((cameraId) => { cameraManager.muteCamera(isMuted).then(() => {
console.log('Promise returned with the camera ID:' + cameraId); console.log('Promise returned muteCamera.');
}) })
``` ```
### createCameraInput
createCameraInput(camera: CameraDevice, callback: AsyncCallback<CameraInput\>): void
### hasFlash 使用CameraDevice对象异步创建CameraInput实例,通过注册回调函数获取结果。
hasFlash(callback: AsyncCallback<boolean\>): void 此接口为系统接口。
判断设备是否支持闪光灯,通过注册回调函数获取结果。 **需要权限:** ohos.permission.CAMERA
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- | | -------- | ------------------------------------------- | ---- | --------------------------------- |
| callback | AsyncCallback<boolean\> | 是 | 回调函数,返回true表示设备支持闪光灯。 | | camera | [CameraDevice](#cameraDevice) | 是 | CameraDevice对象。 |
| callback | AsyncCallback<[CameraInput](#camerainput)\> | 是 | 回调函数,用于获取CameraInput实例。 |
**示例:** **示例:**
```js ```js
cameraInput.hasFlash((err, status) => { cameraManager.createCameraInput(camera, (err, cameraInput) => {
if (err) { if (err) {
console.error('Failed to check whether the device has flash light. ${err.message}'); console.error('Failed to create the CameraInput instance. ${err.message}');
return; return;
} }
console.log('Callback returned with flash light support status: ' + status); console.log('Callback returned with the CameraInput instance.');
}) })
``` ```
### hasFlash ### createCameraInput
hasFlash(): Promise<boolean\> createCameraInput(camera: CameraDevice): Promise<CameraInput\>
使用CameraDevice对象异步创建CameraInput实例,通过Promise获取结果。
此接口为系统接口。
判断设备是否支持闪光灯,通过Promise获取结果。 **需要权限:** ohos.permission.CAMERA
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ----------------------------- | ---- | ---------- |
| camera | [CameraDevice](#cameraDevice) | 是 | CameraDevice对象。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ----------------- | ------------------------------------------------------- | | ------------------------------------- | ------------------------------------ |
| Promise<boolean\> | 使用Promise的方式获取结果,返回true表示设备支持闪光灯。 | | Promise<[CameraInput](#camerainput)\> | 使用Promise的方式获取CameraInput的实例。 |
**示例:** **示例:**
```js ```js
cameraInput.hasFlash().then((status) => { cameraManager.createCameraInput(camera).then((cameraInput) => {
console.log('Promise returned with the flash light support status:' + status); console.log('Promise returned with the CameraInput instance');
}) })
``` ```
### isFlashModeSupported ### createCameraInput
isFlashModeSupported(flashMode: FlashMode, callback: AsyncCallback<boolean\>): void createCameraInput(position: CameraPosition, type: CameraType, callback: AsyncCallback<CameraInput\>): void
根据相机位置和类型创建CameraInput实例,通过注册回调函数获取结果。
此接口为系统接口。
判断设备是否支持指定闪光灯模式,通过注册回调函数获取结果。 **需要权限:** ohos.permission.CAMERA
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| --------- | ----------------------- | ---- | ---------------------------------------- | | -------- | ------------------------------------------- | ---- | --------------------------------- |
| flashMode | [FlashMode](#flashmode) | 是 | 指定闪光灯模式。 | | position | [CameraPosition](#cameraposition) | 是 | 相机位置。 |
| callback | AsyncCallback<boolean\> | 是 | 回调函数,返回true表示支持该闪光灯模式。 | | type | [CameraType](#cameratype) | 是 | 相机类型。 |
| callback | AsyncCallback<[CameraInput](#camerainput)\> | 是 | 回调函数,用于获取CameraInput实例。 |
**示例:** **示例:**
```js ```js
cameraInput.isFlashModeSupported(camera.FlashMode.FLASH_MODE_AUTO, (err, status) => { cameraManager.createCameraInput(camera.CameraPosition.CAMERA_POSITION_BACK, camera.CameraType.CAMERA_TYPE_UNSPECIFIED, (err, cameraInput) => {
if (err) { if (err) {
console.error('Failed to check whether the flash mode is supported. ${err.message}'); console.error('Failed to create the CameraInput instance. ${err.message}');
return; return;
} }
console.log('Callback returned with the flash mode support status: ' + status); console.log('Callback returned with the CameraInput instance');
}) })
``` ```
### isFlashModeSupported ### createCameraInput
isFlashModeSupported(flashMode: FlashMode): Promise<boolean\> createCameraInput(position: CameraPosition, type:CameraType ): Promise<CameraInput\>
根据相机位置和类型创建CameraInput实例,通过Promise获取结果。
判断设备是否支持指定闪光灯模式,通过Promise获取结果。 此接口为系统接口。
**需要权限:** ohos.permission.CAMERA
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| --------- | ----------------------- | ---- | ---------------- | | -------- | --------------------------------- | ---- | ------------ |
| flashMode | [FlashMode](#flashmode) | 是 | 指定闪光灯模式。 | | position | [CameraPosition](#cameraposition) | 是 | 相机位置。 |
| type | [CameraType](#cameratype) | 是 | 相机类型。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ----------------- | ------------------------------------------------------------ | | ------------------------------------- | ------------------------------------ |
| Promise<boolean\> | 使用Promise的方式获取结果,返回true表示设备支持该闪光灯模式。 | | Promise<[CameraInput](#camerainput)\> | 使用Promise的方式获取CameraInput的实例。 |
**示例:** **示例:**
```js ```js
cameraInput.isFlashModeSupported(camera.FlashMode.FLASH_MODE_AUTO).then((status) => { cameraManager.createCameraInput(camera.CameraPosition.CAMERA_POSITION_BACK, camera.CameraType.CAMERA_TYPE_UNSPECIFIED).then((cameraInput) => {
console.log('Promise returned with flash mode support status.' + status); console.log('Promise returned with the CameraInput instance');
}) })
``` ```
### setFlashMode ### createPreviewOutput
setFlashMode(flashMode: FlashMode, callback: AsyncCallback<void\>): void
设置闪光灯模式,通过注册回调函数获取结果。
进行设置之前,需要先检查: createPreviewOutput(profile: Profile, surfaceId: string, callback: AsyncCallback<PreviewOutput\>): void
1. 设备是否支持闪光灯,可使用方法[hasFlash](#hasflash) 创建预览输出对象,通过注册回调函数获取结果。
2. 设备是否支持指定的闪光灯模式,可使用方法[isFlashModeSupported](#isflashmodesupported)
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| --------- | ----------------------- | ---- | ------------------------ | | -------- | ----------------------------------------------- | ---- | ------------------------------- |
| flashMode | [FlashMode](#flashmode) | 是 | 指定闪光灯模式。 | | profile | [Profile](#profile) | 是 | 支持的预览配置信息。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 | | surfaceId| string | 是 | 从[XComponent](../arkui-ts/ts-basic-components-xcomponent.md)或者[ImageReceiver](js-apis-image.md#imagereceiver9)组件获取的SurfaceID。|
| callback | AsyncCallback<[PreviewOutput](#previewoutput)\> | 是 | 回调函数,用于获取PreviewOutput实例。|
**示例:** **示例:**
```js ```js
cameraInput.setFlashMode(camera.FlashMode.FLASH_MODE_AUTO, (err) => { cameraManager.createPreviewOutput(profile, surfaceId, (err, previewoutput) => {
if (err) { if (err) {
console.error('Failed to set the flash mode ${err.message}'); console.error('Failed to gcreate previewOutput. ${err.message}');
return; return;
} }
console.log('Callback returned with the successful execution of setFlashMode.'); console.log('Callback returned with previewOutput created.');
}) })
``` ```
### setFlashMode ### createPreviewOutput
setFlashMode(flashMode: FlashMode): Promise<void\>
设置闪光灯模式,通过Promise获取结果。
进行设置之前,需要先检查: createPreviewOutput(profile: Profile, surfaceId: string): Promise<PreviewOutput\>
1. 设备是否支持闪光灯,可使用方法[hasFlash](#hasflash) 创建预览输出对象,通过Promise获取结果。
2. 设备是否支持指定的闪光灯模式,可使用方法[isFlashModeSupported](#isflashmodesupported)
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| --------- | ----------------------- | ---- | ---------------- | | -------- | ---------------------------------| ---- | ----------------- |
| flashMode | [FlashMode](#flashmode) | 是 | 指定闪光灯模式。 | | profile | [Profile](#profile) | 是 | 支持的预览配置信息。 |
| surfaceId| string | 是 | 从[XComponent](../arkui-ts/ts-basic-components-xcomponent.md)或者[ImageReceiver](js-apis-image.md#imagereceiver9)组件获取的SurfaceID。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| -------------- | --------------------------- | | ---------------------------------------- | ---------------------------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 | | Promise<[PreviewOutput](#previewoutput)\> | 使用Promise的方式获取PreviewOutput的实例。 |
**示例:** **示例:**
```js ```js
cameraInput.setFlashMode(camera.FlashMode.FLASH_MODE_AUTO).then(() => { cameraManager.createPreviewOutput(profile, survaceId).then((previewoutput) => {
console.log('Promise returned with the successful execution of setFlashMode.'); console.log('Promise returned with previewOutput created.');
}) })
``` ```
### getFlashMode ### createDeferredPreviewOutput
getFlashMode(callback: AsyncCallback<FlashMode\>): void createDeferredPreviewOutput(profile: Profile, callback: AsyncCallback<PreviewOutput\>): void
获取当前设备的闪光灯模式,通过注册回调函数获取结果。 尚未获取surfaceID时创建预览输出对象,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------------------------------------- | | -------- | ----------------------------------------------- | ---- | --------------------------------- |
| callback | AsyncCallback<[FlashMode](#flashmode)\> | 是 | 回调函数,用于获取当前设备的闪光灯模式。 | | profile | [Profile](#profile) | 是 | 支持的预览配置信息。 |
| callback | AsyncCallback<[PreviewOutput](#previewoutput)\> | 是 | 回调函数,用于获取PreviewOutput实例。 |
**示例:** **示例:**
```js ```js
cameraInput.getFlashMode((err, flashMode) => { cameraManager.createDeferredPreviewOutput(profile, (err, previewoutput) => {
if (err) { if (err) {
console.error('Failed to get the flash mode ${err.message}'); console.error('Failed to create deferredPreviewOutput. ${err.message}');
return; return;
} }
console.log('Callback returned with current flash mode: ' + flashMode); console.log('Callback returned with deferredPreviewOutput created.');
}) })
``` ```
### getFlashMode ### createDeferredPreviewOutput
getFlashMode(): Promise<FlashMode\> createDeferredPreviewOutput(profile: Profile): Promise<PreviewOutput\>
获取当前设备的闪光灯模式,通过Promise获取结果。 尚未获取surfaceID时创建预览输出对象,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------| ---- | ---------- |
| profile | [Profile](#profile) | 是 | 支持的预览配置信息。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| --------------------------------- | --------------------------------------- | | ----------------------------------------- | --------------------------------------- |
| Promise<[FlashMode](#flashmode)\> | 使用Promise的方式获取当前的闪光灯模式。 | | Promise<[PreviewOutput](#previewoutput)\> | 使用Promise的方式获取PreviewOutput的实例。 |
**示例:** **示例:**
```js ```js
cameraInput.getFlashMode().then((flashMode) => { cameraManager.createDeferredPreviewOutput(profile).then((previewoutput) => {
console.log('Promise returned with current flash mode : ' + flashMode); console.log('Promise returned with DefeerredPreviewOutput created.');
}) })
``` ```
### isFocusModeSupported ### createPhotoOutput
isFocusModeSupported(afMode: FocusMode, callback: AsyncCallback<boolean\>): void createPhotoOutput(profile: Profile, surfaceId: string, callback: AsyncCallback<PhotoOutput\>): void
判断设备是否支持指定的焦距模式,通过注册回调函数获取结果。 创建拍照输出对象,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- | | -------- | ------------------------------------------- | ---- | ----------------------------------- |
| afMode | [FocusMode](#focusmode) | 是 | 指定的焦距模式。 | | profile | [Profile](#profile) | 是 | 支持的拍照配置信息。 |
| callback | AsyncCallback<boolean\> | 是 | 回调函数,返回true表示支持该焦距模式。 | | surfaceId| string | 是 | 从[ImageReceiver](js-apis-image.md#imagereceiver9)获取的SurfaceID。|
| callback | AsyncCallback<[PhotoOutput](#photooutput)\> | 是 | 回调函数,用于获取PhotoOutput实例。 |
**示例:** **示例:**
```js ```js
cameraInput.isFocusModeSupported(camera.FocusMode.FOCUS_MODE_AUTO, (err, status) => { cameraManager.createPhotoOutput(profile, surfaceId, (err, photooutput) => {
if (err) { if (err) {
console.error('Failed to check whether the focus mode is supported. ${err.message}'); console.error('Failed to create photoOutput. ${err.message}');
return; return;
} }
console.log('Callback returned with the focus mode support status: ' + status); console.log('Callback returned with photoOutput created.');
}) })
``` ```
### isFocusModeSupported ### createPhotoOutput
isFocusModeSupported(afMode: FocusMode): Promise<boolean\> createPhotoOutput(profile: Profile, surfaceId: string): Promise<PreviewOutput\>
判断设备是否支持指定的焦距模式,通过Promise获取结果。 创建拍照输出对象,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| ------ | ----------------------- | ---- | ---------------- | | -------- | ---------------------------------| ---- | ----------- |
| afMode | [FocusMode](#focusmode) | 是 | 指定的焦距模式。 | | profile | [Profile](#profile) | 是 | 支持的拍照配置信息。 |
| surfaceId| string | 是 | 从[ImageReceiver](js-apis-image.md#imagereceiver9)获取的SurfaceID。|
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ----------------- | ----------------------------------------------------------- | | ------------------------------------- | -------------------------------------- |
| Promise<boolean\> | 使用Promise的方式获取结果,返回true表示设备支持该焦距模式。 | | Promise<[PhotoOutput](#photooutput)\> | 使用Promise的方式获取PhotoOutput的实例。 |
**示例:** **示例:**
```js ```js
cameraInput.isFocusModeSupported(camera.FocusMode.FOCUS_MODE_AUTO).then((status) => { cameraManager.createPhotoOutput(profile, surfaceId).then((photooutput) => {
console.log('Promise returned with focus mode support status.' + status); console.log('Promise returned with photoOutput created.');
}) })
``` ```
### setFocusMode ### createVideoOutput
setFocusMode(afMode: FocusMode, callback: AsyncCallback<void\>): void
设置焦距模式,通过注册回调函数获取结果。 createVideoOutput(profile: VideoProfile, surfaceId: string, callback: AsyncCallback<VideoOutput\>): void
进行设置之前,需要先检查设备是否支持指定的焦距模式,可使用方法[isFocusModeSupported](#isfocusmodesupported) 创建录像输出对象,通过注册回调函数获取结果
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | ------------------------ | | -------- | ------------------------------------------- | ---- | ------------------------------ |
| afMode | [FocusMode](#focusmode) | 是 | 指定的焦距模式。 | | profile | [VideoProfile](#videoprofile) | 是 | 支持的录像配置信息。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 | | surfaceId| string | 是 | 从[VideoRecorder](js-apis-media.md#videorecorder9)获取的SurfaceID。|
| callback | AsyncCallback<[VideoOutput](#videooutput)\> | 是 | 回调函数,用于获取VideoOutput实例。 |
**示例:** **示例:**
```js ```js
cameraInput.setFocusMode(camera.FocusMode.FOCUS_MODE_AUTO, (err) => { cameraManager.createVideoOutput(profile, surfaceId, (err, videooutput) => {
if (err) { if (err) {
console.error('Failed to set the focus mode ${err.message}'); console.error('Failed to create videoOutput. ${err.message}');
return; return;
} }
console.log('Callback returned with the successful execution of setFocusMode.'); console.log('Callback returned with an array of supported outputCapability: ' + cameras.length);
}) })
``` ```
### setFocusMode ### createVideoOutput
setFocusMode(afMode: FocusMode): Promise<void\>
设置焦距模式,通过Promise获取结果。 createVideoOutput(profile: VideoProfile, surfaceId: string): Promise<VideoOutput\>
进行设置之前,需要先检查设备是否支持指定的焦距模式,可使用方法[isFocusModeSupported](#isfocusmodesupported) 创建录像输出对象,通过Promise获取结果
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| ------ | ----------------------- | ---- | ---------------- | | -------- | ---------------------------------| ---- | ---------- |
| afMode | [FocusMode](#focusmode) | 是 | 指定的焦距模式。 | | profile | [VideoProfile](#videoprofile) | 是 | 支持的录像配置信息。 |
| surfaceId| string | 是 | 从[VideoRecorder](js-apis-media.md#videorecorder9)获取的SurfaceID。|
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| -------------- | --------------------------- | | ------------------------------------- | -------------------------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 | | Promise<[VideoOutput](#videooutput)\> | 使用Promise的方式获取videoOutput的实例。 |
**示例:** **示例:**
```js ```js
cameraInput.setFocusMode(camera.FocusMode.FOCUS_MODE_AUTO).then(() => { cameraManager.createVideoOutput(profile, surfaceId).then((videooutput) => {
console.log('Promise returned with the successful execution of setFocusMode.'); console.log('Promise returned with videoOutput created.');
}) })
``` ```
### getFocusMode ### createMetadataOutput
getFocusMode(callback: AsyncCallback<FocusMode\>): void createMetadataOutput(metadataObjectTypes: Array<MetadataObjectType\>, callback: AsyncCallback<MetadataOutput\>): void
获取当前设备的焦距模式,通过注册回调函数获取结果。 创建metadata流输出对象,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | -------------------------------------- | | -------------------- | -------------------------------------------------- | --- | ---------------------------- |
| callback | AsyncCallback<[FocusMode](#focusmode)\> | 是 | 回调函数,用于获取当前设备的焦距模式。 | | metadataObjectTypes | Array<[MetadataObjectType](#metadataobjecttype)\> | 是 | metadata流类型。 |
| callback | AsyncCallback<[MetadataOutput](#metadataoutput)\> | 是 | 回调函数,用于获取MetadataOutput实例。 |
**示例:** **示例:**
```js ```js
cameraInput.getFocusMode((err, afMode) => { cameraManager.createMetadataOutput(metadataObjectTypes, (err, metadataoutput) => {
if (err) { if (err) {
console.error('Failed to get the focus mode ${err.message}'); console.error('Failed to create metadataOutput. ${err.message}');
return; return;
} }
console.log('Callback returned with current focus mode: ' + afMode); console.log('Callback returned with metadataOutput created.');
}) })
``` ```
### getFocusMode ### createMetadataOutput
getFocusMode(): Promise<FocusMode\> createMetadataOutput(metadataObjectTypes: Array<MetadataObjectType\>): Promise<MetadataOutput>
获取当前设备的焦距模式,通过Promise获取结果。 创建metadata流输出对象,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------------------- | -------------------------------------------------- | --- | -------------- |
| metadataObjectTypes | Array<[MetadataObjectType](#metadataobjecttype)\> | 是 | metadata流类型。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ------------------- | ------------------------------------- | | ------------------------------------------ | ----------------------------------------- |
| Promise<FocusMode\> | 使用Promise的方式获取当前的焦距模式。 | | Promise<[MetadataOutput](#metadataoutput)\> | 使用Promise的方式获取MetadataOutput的实例。 |
**示例:** **示例:**
```js ```js
cameraInput.getFocusMode().then((afMode) => { cameraManager.createMetadataOutput(metadataObjectTypes).then((metadataoutput) => {
console.log('Promise returned with current focus mode : ' + afMode); console.log('Promise returned with metadataOutput created.');
}) })
``` ```
### getZoomRatioRange ### createCaptureSession
getZoomRatioRange\(callback: AsyncCallback<Array<number\>\>\): void createCaptureSession(callback: AsyncCallback<CaptureSession\>): void
获取可变焦距比范围,通过注册回调函数获取结果。 创建CaptureSession实例,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| -------- | ------------------------------ | ---- | ------------------------ | | -------------------- | ----------------------------------------- | ----------- | ---------------------------- |
| callback | AsyncCallback<Array<number\>\> | 是 | 回调函数,用于获取结果。 | | callback | AsyncCallback<[CaptureSession](#capturesession)\> | 是 | 回调函数,用于获取拍照会话实例。 |
**示例:** **示例:**
```js ```js
cameraInput.getZoomRatioRange((err, zoomRatioRange) => { cameraManager.createCaptureSession((err, capturesession) => {
if (err) { if (err) {
console.error('Failed to get the zoom ratio range. ${err.message}'); console.error('Failed to create captureSession. ${err.message}');
return; return;
} }
console.log('Callback returned with zoom ratio range: ' + zoomRatioRange.length); console.log('Callback returned with captureSession created.');
}) })
``` ```
### getZoomRatioRange ### createCaptureSession
getZoomRatioRange\(\): Promise<Array<number\>\> createCaptureSession(): Promise<CaptureSession\>
获取可变焦距比范围,通过Promise获取结果。 创建CaptureSession实例,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ------------------------ | ------------------------------------------- | | ------------------------------------------- | ---------------------------------------- |
| Promise<Array<number\>\> | 使用Promise的方式获取当前的可变焦距比范围。 | | Promise<[CaptureSession](#capturesession)\> | 使用Promise的方式获取CaptureSession的实例。 |
**示例:** **示例:**
```js ```js
cameraInput.getZoomRatioRange().then((zoomRatioRange) => { cameraManager.createCaptureSession().then((capturesession) => {
console.log('Promise returned with zoom ratio range: ' + zoomRatioRange.length); console.log('Promise returned with captureSession created.');
}) })
``` ```
### setZoomRatio ### on('cameraStatus')
setZoomRatio(zoomRatio: number, callback: AsyncCallback<void\>): void on(type: 'cameraStatus', callback: AsyncCallback<CameraStatusInfo\>): void
设置可变焦距比,通过注册回调函数获取结果 镜头状态回调,通过注册回调函数获取相机的状态变化
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| --------- | -------------------- | ---- | ------------------------ | | -------- | ----------------------------------------------------- | ---- | --------- |
| zoomRatio | number | 是 | 可变焦距比。 | | type | string | 是 | 监听事件,固定为'cameraStatus',即镜头状态变化事件。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 | | callback | AsyncCallback<[CameraStatusInfo](#camerastatusinfo)\> | 是 | 回调函数,用于获取镜头状态变化信息。 |
**示例:** **示例:**
```js ```js
cameraInput.setZoomRatio(1, (err) => { cameraManager.on('cameraStatus', (err, cameraStatusInfo) => {
if (err) { if (err) {
console.error('Failed to set the zoom ratio value ${err.message}'); console.error('Failed to get cameraStatus callback. ${err.message}');
return; return;
} }
console.log('Callback returned with the successful execution of setZoomRatio.'); console.log('camera : ' + cameraStatusInfo.camera.cameraId);
console.log('status: ' + cameraStatusInfo.status);
}) })
``` ```
### setZoomRatio ### on('cameraMute')
setZoomRatio(zoomRatio: number): Promise<void\> on(type: 'cameraMute', callback: AsyncCallback<boolean\>): void
监听相机禁用的状态变化,通过注册回调函数获取相机的状态变化。
设置可变焦距比,通过Promise获取结果。 此接口为系统接口。
**需要权限:** ohos.permission.CAMERA
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| --------- | ------ | ---- | ------------ | | -------- | --------------------------------------- | ---- | ------------------------------- |
| zoomRatio | number | 是 | 可变焦距比。 | | type | string | 是 | 监听事件,固定为'cameraMute',即相机状禁用态变化事件。 |
| callback | AsyncCallback<boolean\> | 是 | 回调函数,用于获取相机是否禁用。 |
**返回值:** **示例:**
| 类型 | 说明 | ```js
| -------------- | --------------------------- | cameraManager.on('cameraMute', (err, status) => {
| Promise<void\> | 使用Promise的方式获取结果。 | if (err) {
console.error('Failed to get cameraMute callback. ${err.message}');
return;
}
console.log('status: ' + status);
})
```
## CameraStatusInfo
相机管理器回调返回的接口实例,表示相机状态信息。
**系统能力:** SystemCapability.Multimedia.Camera.Core。
| 名称 | 类型 | 说明 |
| ------ | ----------------------------- | ---------- |
| camera | [CameraDevice](#CameraDevice) | 相机信息。 |
| status | [CameraStatus](#camerastatus) | 相机状态。 |
## CameraPosition
枚举,相机位置。
**系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 值 | 说明 |
| --------------------------- | ---- | -------------- |
| CAMERA_POSITION_UNSPECIFIED | 0 | 相机位置未指定。 |
| CAMERA_POSITION_BACK | 1 | 后置相机。 |
| CAMERA_POSITION_FRONT | 2 | 前置相机。 |
## CameraType
枚举,相机类型。
**系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 值 | 说明 |
| ----------------------- | ---- | -------------- |
| CAMERA_TYPE_UNSPECIFIED | 0 | 相机类型未指定。 |
| CAMERA_TYPE_WIDE_ANGLE | 1 | 广角相机。 |
| CAMERA_TYPE_ULTRA_WIDE | 2 | 超广角相机。 |
| CAMERA_TYPE_TELEPHOTO | 3 | 长焦相机。 |
| CAMERA_TYPE_TRUE_DEPTH | 4 | 带景深信息的相机。 |
## ConnectionType
枚举,相机连接类型。
**系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 值 | 说明 |
| ---------------------------- | ---- | ------------- |
| CAMERA_CONNECTION_BUILT_IN | 0 | 内置相机。 |
| CAMERA_CONNECTION_USB_PLUGIN | 1 | USB连接的相机。 |
| CAMERA_CONNECTION_REMOTE | 2 | 远程连接的相机。 |
## CameraDevice
相机设备信息。
**系统能力:** SystemCapability.Multimedia.Camera.Core。
| 名称 | 类型 | 只读 | 说明 |
| -------------- | --------------------------------- | ---- | ---------- |
| cameraId | string | 是 | CameraDevice对象|
| cameraPosition | [CameraPosition](#cameraposition) | 是 | 相机位置。 |
| cameraType | [CameraType](#cameratype) | 是 | 相机类型。 |
| connectionType | [ConnectionType](#connectiontype) | 是 | 相机连接类型。 |
**示例:** **示例:**
```js ```js
cameraInput.setZoomRatio(1).then(() => { async function getCameraInfo("cameraId") {
console.log('Promise returned with the successful execution of setZoomRatio.'); var cameraManager = await camera.getCameraManager(context);
}) var cameras = await cameraManager.getSupportedCameras();
var cameraObj = cameras[0];
var cameraId = cameraObj.cameraId;
var cameraPosition = cameraObj.cameraPosition;
var cameraType = cameraObj.cameraType;
var connectionType = cameraObj.connectionType;
}
``` ```
### getZoomRatio ## Size
getZoomRatio(callback: AsyncCallback<number\>): void 枚举,输出能力查询。
**系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 类型 | 可读 | 可写 | 说明 |
| ------ | ------ | ---- | ---- | ------------ |
| height | number | 是 | 是 | 图像尺寸高(像素)。 |
| width | number | 是 | 是 | 图像尺寸宽(像素)。 |
## Point
枚举,点坐标用于对焦、曝光配置。
**系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | ------------ |
| x | number | 是 | 点的x坐标。 |
| y | number | 是 | 点的y坐标。 |
## CameraFormat
获取当前的可变焦距比,通过注册回调函数获取结果。 枚举,输出格式。
**系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 默认值 | 说明 |
| ----------------------- | --------- | ------------ |
| CAMERA_FORMAT_YUV_420_SP| 1003 | YUV 420 SP格式的图片。 |
| CAMERA_FORMAT_JPEG | 2000 | JPEG格式的图片。 |
## CameraInput
会话中[CaptureSession](#capturesession)使用的相机信息。
### open
open\(callback: AsyncCallback<void\>\): void
打开相机,通过注册回调函数获取状态。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| -------- | ---------------------- | ---- | ------------------------ | | -------- | -------------------- | ---- | ------------------- |
| callback | AsyncCallback<number\> | 是 | 回调函数,用于获取结果。 | | callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:** **示例:**
```js ```js
cameraInput.getZoomRatio((err, zoomRatio) => { cameraInput.open((err) => {
if (err) { if (err) {
console.error('Failed to get the zoom ratio ${err.message}'); console.error('Failed to open the camera. ${err.message}');
return; return;
} }
console.log('Callback returned with current zoom ratio: ' + zoomRatio); console.log('Callback returned with camera opened.');
}) })
``` ```
### getZoomRatio ### open
getZoomRatio(): Promise<number\> open(): Promise<void\>
获取当前的可变焦距比,通过Promise获取结果 打开相机,通过Promise获取相机的状态
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ---------------- | --------------------------- | | -------------- | ----------------------- |
| Promise<number\> | 使用Promise的方式获取结果。 | | Promise<void\> | 使用Promise的方式获取结果。 |
**示例:** **示例:**
```js ```js
cameraInput.getZoomRatio().then((zoomRatio) => { cameraInput.open().then(() => {
console.log('Promise returned with current zoom ratio : ' + zoomRatio); console.log('Promise returned with camera opened.');
}) })
``` ```
### release ### close
release\(callback: AsyncCallback<void\>\): void close\(callback: AsyncCallback<void\>\): void
释放相机实例,通过注册回调函数获取结果 关闭相机,通过注册回调函数获取状态
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------ | | -------- | -------------------- | ---- | -------------------- |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 | | callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:** **示例:**
```js ```js
cameraInput.release((err) => { cameraInput.close((err) => {
if (err) { if (err) {
console.error('Failed to release the CameraInput instance ${err.message}'); console.error('Failed to close the cameras. ${err.message}');
return; return;
} }
console.log('Callback invoked to indicate that the CameraInput instance is released successfully.'); console.log('Callback returned with camera closed.');
}); })
``` ```
### release ### close
release(): Promise<void\> close(): Promise<void\>
释放相机实例,通过Promise获取结果 关闭相机,通过Promise获取状态
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| -------------- | --------------------------- | | -------------- | ----------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 | | Promise<void\> | 使用Promise的方式获取结果。 |
**示例:** **示例:**
```js ```js
cameraInput.release().then(() => { cameraInput.close().then(() => {
console.log('Promise returned to indicate that the CameraInput instance is released successfully.'); console.log('Promise returned with camera closed.');
}) })
``` ```
### on('focusStateChange') ### release
on(type: 'focusStateChange', callback: AsyncCallback<FocusState\>): void release\(callback: AsyncCallback<void\>\): void
监听焦距的状态变化,通过注册回调函数获取结果。 释放资源,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| :------- | :---------------------------------------- | :--- | :------------------------------------------------------- | | -------- | -------------------- | ---- | ------------------- |
| type | string | 是 | 监听事件,固定为'focusStateChange',即焦距状态变化事件。 | | callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
| callback | AsyncCallback<[FocusState](#focusstate)\> | 是 | 回调函数,用于获取焦距状态。 |
**示例:** **示例:**
```js ```js
cameraInput.on('focusStateChange', (focusState) => { cameraInput.release((err) => {
console.log('Focus state : ' + focusState); 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.');
}) })
``` ```
...@@ -1033,7 +1186,7 @@ on(type: 'error', callback: ErrorCallback<CameraInputError\>): void ...@@ -1033,7 +1186,7 @@ on(type: 'error', callback: ErrorCallback<CameraInputError\>): void
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| :------- | :------------------------------- | :--- | :----------------------------------------------- | | -------- | -------------------------------- | ---- | ------------------------------------------- |
| type | string | 是 | 监听事件,固定为'error',即CameraInput错误事件。 | | type | string | 是 | 监听事件,固定为'error',即CameraInput错误事件。 |
| callback | ErrorCallback<[CameraInputError](#camerainputerror)\> | 是 | 回调函数,用于获取结果。 | | callback | ErrorCallback<[CameraInputError](#camerainputerror)\> | 是 | 回调函数,用于获取结果。 |
...@@ -1047,22 +1200,27 @@ cameraInput.on('error', (cameraInputError) => { ...@@ -1047,22 +1200,27 @@ cameraInput.on('error', (cameraInputError) => {
## CameraInputErrorCode ## CameraInputErrorCode
枚举,CameraInput的错误码 枚举,[CameraInput](#camerainput)错误类型
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 值 | 说明 | | 名称 | 值 | 说明 |
| ------------- | ---- | ---------- | | ------------------------- | ---- | ---------- |
| ERROR_UNKNOWN | -1 | 未知错误。 | | 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 ## CameraInputError
CameraInput错误对象 [CameraInput](#camerainput)错误码
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 类型 | 说明 | | 名称 | 类型 | 说明 |
| ---- | ------------------------------------------- | -------------------------- | | ---- | --------------------------------------------- | --------------------- |
| code | [CameraInputErrorCode](#camerainputerrorcode) | CameraInput中的错误码。 | | code | [CameraInputErrorCode](#camerainputerrorcode) | CameraInput中的错误码。 |
...@@ -1073,95 +1231,77 @@ CameraInput错误对象。 ...@@ -1073,95 +1231,77 @@ CameraInput错误对象。
**系统能力:** SystemCapability.Multimedia.Camera.Core。 **系统能力:** SystemCapability.Multimedia.Camera.Core。
| 名称 | 值 | 说明 | | 名称 | 值 | 说明 |
| ---------------------- | ---- | ------------ | | ---------------------- | ---- | ---------- |
| FLASH_MODE_CLOSE | 0 | 闪光灯关闭。 | | FLASH_MODE_CLOSE | 0 | 闪光灯关闭。 |
| FLASH_MODE_OPEN | 1 | 闪光灯开启。 | | FLASH_MODE_OPEN | 1 | 闪光灯打开。 |
| FLASH_MODE_AUTO | 2 | 自动闪光灯。 | | FLASH_MODE_AUTO | 2 | 自动闪光灯。 |
| FLASH_MODE_ALWAYS_OPEN | 3 | 闪光灯常亮。 | | FLASH_MODE_ALWAYS_OPEN | 3 | 闪光灯常亮。 |
## FocusMode ## ExposureMode
枚举,焦距模式。 枚举,曝光模式。
**系统能力:** SystemCapability.Multimedia.Camera.Core。 **系统能力:** SystemCapability.Multimedia.Camera.Core。
| 名称 | 值 | 说明 | | 名称 | 值 | 说明 |
| -------------------------- | ---- | ------------------ | | ----------------------------- | ---- | ----------- |
| FOCUS_MODE_MANUAL | 0 | 手动变焦模式。 | | EXPOSURE_MODE_LOCKED | 0 | 锁定曝光模式。 |
| FOCUS_MODE_CONTINUOUS_AUTO | 1 | 连续自动变焦模式。 | | EXPOSURE_MODE_AUTO | 1 | 自动曝光模式。 |
| FOCUS_MODE_AUTO | 2 | 自动变焦模式。 | | EXPOSURE_MODE_CONTINUOUS_AUTO | 2 | 连续自动曝光。 |
| FOCUS_MODE_LOCKED | 3 | 定焦模式。 |
## FocusState ## FocusMode
枚举,焦距状态 枚举,焦距模式
**系统能力:** SystemCapability.Multimedia.Camera.Core。 **系统能力:** SystemCapability.Multimedia.Camera.Core。
| 名称 | 值 | 说明 | | 名称 | 值 | 说明 |
| --------------------- | ---- | ------------ | | -------------------------- | ---- | ------------ |
| FOCUS_STATE_SCAN | 0 | 扫描状态。 | | FOCUS_MODE_MANUAL | 0 | 手动对焦。 |
| FOCUS_STATE_FOCUSED | 1 | 相机已对焦。 | | FOCUS_MODE_CONTINUOUS_AUTO | 1 | 连续自动对焦。 |
| FOCUS_STATE_UNFOCUSED | 2 | 相机未对焦。 | | FOCUS_MODE_AUTO | 2 | 自动变焦。 |
| FOCUS_MODE_LOCKED | 3 | 对焦锁定。 |
## camera.createCaptureSession
createCaptureSession\(context: Context, callback: AsyncCallback<CaptureSession\>\): void
获取CaptureSession实例,通过注册回调函数获取结果。 ## FocusState
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------- | ---- | -------------------------------------- |
| context | Context | 是 | 应用上下文。 |
| callback | AsyncCallback<[CaptureSession](#capturesession)\> | 是 | 回调函数,用于获取CaptureSession实例。 |
**示例:**
```js 枚举,焦距状态。
camera.createCaptureSession((context), (err, captureSession) => {
if (err) {
console.error('Failed to create the CaptureSession instance. ${err.message}');
return;
}
console.log('Callback returned with the CaptureSession instance.' + captureSession);
});
```
## camera.createCaptureSession **系统能力:** SystemCapability.Multimedia.Camera.Core。
createCaptureSession(context: Context\): Promise<CaptureSession\>; | 名称 | 值 | 说明 |
| --------------------- | ---- | --------- |
| FOCUS_STATE_SCAN | 0 | 触发对焦。 |
| FOCUS_STATE_FOCUSED | 1 | 对焦成功。 |
| FOCUS_STATE_UNFOCUSED | 2 | 未完成对焦。 |
获取CaptureSession实例,通过Promise获取结果。 ## ExposureState
**系统能力:** SystemCapability.Multimedia.Camera.Core 枚举,曝光状态。
**参数:** **系统能力:** SystemCapability.Multimedia.Camera.Core。
| 名称 | 类型 | 必填 | 说明 | | 名称 | 值 | 说明 |
| ------- | ------- | ---- | ------------ | | ------------------------- | ---- | -------- |
| context | Context | 是 | 应用上下文。 | | EXPOSURE_STATE_SCAN | 0 | 曝光中。 |
| EXPOSURE_STATE_CONVERGED | 1 | 曝光收敛。 |
**返回值:** ## VideoStabilizationMode
| 类型 | 说明 | 枚举,视频防抖模式。
| ------------------------------------------- | ----------------------------------------- |
| Promise<[CaptureSession](#capturesession)\> | 使用Promise的方式获取CaptureSession实例。 |
**示例:** **系统能力:** SystemCapability.Multimedia.Camera.Core。
```js | 名称 | 值 | 说明 |
camera.createCaptureSession(context).then((captureSession) => { | --------- | ---- | ------------ |
console.log('Promise returned with the CaptureSession instance'); | OFF | 0 | 关闭视频防抖功能。 |
}) | LOW | 1 | 使用基础防抖算法。 |
``` | MIDDLE | 2 | 使用防抖效果一般的防抖算法,防抖效果优于LOW类型。 |
| HIGH | 3 | 使用防抖效果最好的防抖算法,防抖效果优于MIDDLE类型。 |
| AUTO | 4 | 自动进行选择。 |
## CaptureSession ## CaptureSession
拍照会话类。 拍照会话类,保存一次相机运行所需要的所有资源[CameraInput](#camerainput)[CameraOutput](#cameraoutput),并向相机设备申请完成相机功能(录像,拍照)
### beginConfig ### beginConfig
...@@ -1174,7 +1314,7 @@ beginConfig\(callback: AsyncCallback<void\>\): void ...@@ -1174,7 +1314,7 @@ beginConfig\(callback: AsyncCallback<void\>\): void
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------ | | -------- | -------------------- | ---- | ------------------- |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 | | callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:** **示例:**
...@@ -1200,7 +1340,7 @@ beginConfig\(\): Promise<void\> ...@@ -1200,7 +1340,7 @@ beginConfig\(\): Promise<void\>
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| -------------- | --------------------------- | | -------------- | ------------------------ |
| Promise<void\> | 使用Promise的方式获取结果。 | | Promise<void\> | 使用Promise的方式获取结果。 |
...@@ -1216,14 +1356,14 @@ captureSession.beginConfig().then(() => { ...@@ -1216,14 +1356,14 @@ captureSession.beginConfig().then(() => {
commitConfig\(callback: AsyncCallback<void\>\): void commitConfig\(callback: AsyncCallback<void\>\): void
提交会话配置,通过注册回调函数获取结果。 提交配置信息,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------ | | -------- | -------------------- | ---- | -------------------- |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 | | callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:** **示例:**
...@@ -1242,14 +1382,14 @@ captureSession.commitConfig((err) => { ...@@ -1242,14 +1382,14 @@ captureSession.commitConfig((err) => {
commitConfig\(\): Promise<void\> commitConfig\(\): Promise<void\>
提交会话配置,通过Promise获取结果。 提交配置信息,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| -------------- | --------------------------- | | -------------- | ------------------------ |
| Promise<void\> | 使用Promise的方式获取结果。 | | Promise<void\> | 使用Promise的方式获取结果。 |
**示例:** **示例:**
...@@ -1260,546 +1400,529 @@ captureSession.commitConfig().then(() => { ...@@ -1260,546 +1400,529 @@ captureSession.commitConfig().then(() => {
}) })
``` ```
### addInput ### canAddInput
addInput\(cameraInput: CameraInput, callback: AsyncCallback<void\>\): void canAddInput(cameraInput: CameraInput, callback: AsyncCallback<boolean\>): void
在当前会话中,添加一个CameraInput实例,通过注册回调函数获取结果。 判断是否可以添加[CameraInput](#camerainput)到会话中,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| ----------- | --------------------------- | ---- | --------------------------- | | ----------- | --------------------------- | ---- | ------------------------ |
| cameraInput | [CameraInput](#camerainput) | 是 | 需要添加的CameraInput实例。 | | cameraInput | [CameraInput](#camerainput) | 是 | 需要添加的CameraInput实例。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 | | callback | AsyncCallback<boolean\> | 是 | 回调函数,用于获取结果。 |
**示例:** **示例:**
```js ```js
captureSession.addInput(cameraInput, (err) => { captureSession.canAddInput(cameraInput, (err, status) => {
if (err) { if (err) {
console.error('Failed to add the CameraInput instance. ${err.message}'); console.error('Can not add cameraInput. ${err.message}');
return; return;
} }
console.log('Callback invoked to indicate that the CameraInput instance is added.'); console.log('Callback returned with cameraInput can added.');
}); })
``` ```
### addInput ### canAddInput
addInput\(cameraInput: CameraInput\): Promise<void\> canAddInput(cameraInput: CameraInput): Promise<boolean\>
在当前会话中,添加一个CameraInput实例,通过Promise获取结果。 判断是否可以添加[CameraInput](#camerainput)到会话中,通过注Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| ----------- | --------------------------- | ---- | --------------------------- | | ----------- | --------------------------- | ---- | ------------------------ |
| cameraInput | [CameraInput](#camerainput) | 是 | 需要添加的CameraInput实例。 | | cameraInput | [CameraInput](#camerainput) | 是 | 需要添加的CameraInput实例。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| -------------- | --------------------------- | | -------------- | -------------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 | | Promise<boolean\> | 使用Promise的方式获取结果。 |
**示例:** **示例:**
```js ```js
captureSession.addInput(cameraInput).then(() => { captureSession.canAddInput(cameraInput).then(() => {
console.log('Promise used to indicate that the CameraInput instance is added.'); console.log('Promise returned with cameraInput can added.');
}) })
``` ```
### addOutput ### addInput
addOutput\(previewOutput: PreviewOutput, callback: AsyncCallback<void\>\): void addInput\(cameraInput: CameraInput, callback: AsyncCallback<void\>\): void
在当前会话中,添加一个PreviewOutput实例,通过注册回调函数获取结果。 [CameraInput](#camerainput)加入到会话,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| ------------- | ------------------------------- | ---- | ----------------------------- | | ----------- | --------------------------- | ---- | ------------------------ |
| previewOutput | [PreviewOutput](#previewoutput) | 是 | 需要添加的PreviewOutput实例。 | | cameraInput | [CameraInput](#camerainput) | 是 | 需要添加的CameraInput实例。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 | | callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:** **示例:**
```js ```js
captureSession.addOutput(previewOutput, (err) => { captureSession.addInput(cameraInput, (err) => {
if (err) { if (err) {
console.error('Failed to add the PreviewOutput instance ${err.message}'); console.error('Failed to add the CameraInput instance. ${err.message}');
return; return;
} }
console.log('Callback invoked to indicate that the PreviewOutput instance is added.'); console.log('Callback invoked to indicate that the CameraInput instance is added.');
}); });
``` ```
### addOutput ### addInput
addOutput\(previewOutput: PreviewOutput\): Promise<void\> addInput\(cameraInput: CameraInput\): Promise<void\>
在当前会话中,添加一个PreviewOutput实例,通过Promise获取结果。 [CameraInput](#camerainput)加入到会话,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| ------------- | ------------------------------- | ---- | ----------------------------- | | ----------- | --------------------------- | ---- | ------------------------ |
| previewOutput | [PreviewOutput](#previewoutput) | 是 | 需要添加的PreviewOutput实例。 | | cameraInput | [CameraInput](#camerainput) | 是 | 需要添加的CameraInput实例。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| -------------- | --------------------------- | | -------------- | ------------------------ |
| Promise<void\> | 使用Promise的方式获取结果。 | | Promise<void\> | 使用Promise的方式获取结果。 |
**示例:** **示例:**
```js ```js
captureSession.addOutput(previewOutput).then(() => { captureSession.addInput(cameraInput).then(() => {
console.log('Promise used to indicate that the PreviewOutput instance is added.'); console.log('Promise used to indicate that the CameraInput instance is added.');
}) })
``` ```
### addOutput ### removeInput
addOutput\(photoOutput: PhotoOutput, callback: AsyncCallback<void\>\): void removeInput\(cameraInput: CameraInput, callback: AsyncCallback<void\>\): void
在当前会话中,添加一个PhotoOutput实例,通过注册回调函数获取结果。 移除[CameraInput](#camerainput),通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| ----------- | --------------------------- | ---- | --------------------------- | | ----------- | --------------------------- | ---- | ------------------------ |
| photoOutput | [PhotoOutput](#photooutput) | 是 | 需要添加的PhotoOutput实例。 | | cameraInput | [CameraInput](#camerainput) | 是 | 需要移除的CameraInput实例。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 | | callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:** **示例:**
```js ```js
captureSession.addOutput(photoOutput, (err) => { captureSession.removeInput(cameraInput, (err) => {
if (err) { if (err) {
console.error('Failed to add the PhotoOutput instance ${err.message}'); console.error('Failed to remove the CameraInput instance. ${err.message}');
return; return;
} }
console.log('Callback invoked to indicate that the PhotoOutput instance is added.'); console.log('Callback invoked to indicate that the cameraInput instance is removed.');
}); });
``` ```
### addOutput ### removeInput
addOutput\(photoOutput: PhotoOutput\): Promise<void\> removeInput\(cameraInput: CameraInput\): Promise<void\>
在当前会话中,添加一个PhotoOutput实例,通过Promise获取结果。 移除[CameraInput](#camerainput),通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| ----------- | --------------------------- | ---- | --------------------------- | | ----------- | --------------------------- | ---- | ------------------------ |
| photoOutput | [PhotoOutput](#photooutput) | 是 | 需要添加的PhotoOutput实例。 | | cameraInput | [CameraInput](#camerainput) | 是 | 需要移除的CameraInput实例。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| -------------- | --------------------------- | | -------------- | ------------------------- |
| Promise\<void> | 使用Promise的方式获取结果。 | | Promise\<void\> | 使用Promise的方式获取结果。 |
**示例:** **示例:**
```js ```js
captureSession.addOutput(photoOutput).then(() => { captureSession.removeInput(cameraInput).then(() => {
console.log('Promise used to indicate that the PhotoOutput instance is added.'); console.log('Promise returned to indicate that the cameraInput instance is removed.');
}) })
``` ```
### addOutput ### canAddOutput
addOutput\(videoOutput: VideoOutput, callback: AsyncCallback<void\>\): void canAddOutput(cameraOutput: CameraOutput, callback: AsyncCallback<boolean\>\): void
在当前会话中,添加一个VideoOutput实例,通过注册回调函数获取结果。 查询是否可以添加[CameraOutput](#cameraoutput)到会话中,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| ----------- | --------------------------- | ---- | --------------------------- | | ------------- | ------------------------------- | ---- | ------------------------- |
| videoOutput | [VideoOutput](#videooutput) | 是 | 需要添加的VideoOutput实例。 | | cameraOutput | [CameraOutput](#cameraOutput) | 是 | 需要添加的CameraOutput实例。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 | | callback | AsyncCallback<boolean\> | 是 | 回调函数,用于获取结果。 |
**示例:** **示例:**
```js ```js
captureSession.addOutput(videoOutput, (err) => { captureSession.canAddOutput(cameraOutput, (err, status) => {
if (err) { if (err) {
console.error('Failed to add the VideoOutput instance ${err.message}'); console.error('Can not add cameraOutput. ${err.message}');
return; return;
} }
console.log('Callback invoked to indicate that the VideoOutput instance is added.'); console.log('Callback returned with cameraOutput can added.');
}); })
``` ```
### addOutput ### canAddOutput
addOutput\(videoOutput: VideoOutput\): Promise<void\> canAddOutput(cameraOutput: CameraOutput): Promise<boolean\>
在当前会话中,添加一个VideoOutput实例,通过Promise获取结果。 查询是否可以添加[CameraOutput](#cameraoutput)到会话中,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| ----------- | --------------------------- | ---- | --------------------------- | | ------------- | ------------------------------- | ---- | ------------------------- |
| videoOutput | [VideoOutput](#videooutput) | 是 | 需要添加的VideoOutput实例。 | | cameraOutput | [CameraOutput](#cameraOutput) | 是 | 需要添加的CameraOutput实例。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| -------------- | --------------------------- | | -------------- | --------------------------- |
| Promise\<void> | 使用Promise的方式获取结果。 | | Promise<boolean\> | 使用Promise的方式获取结果。 |
**示例:** **示例:**
```js ```js
captureSession.addOutput(videoOutput).then(() => { captureSession.canAddOutput(cameraOutput).then(() => {
console.log('Promise used to indicate that the VideoOutput instance is added.'); console.log('Promise returned with cameraOutput can added.');
}) })
``` ```
### removeInput ### addOutput
removeInput\(cameraInput: CameraInput, callback: AsyncCallback<void\>\): void addOutput\(cameraOutput: CameraOutput, callback: AsyncCallback<void\>\): void
在当前会话中,移除一个CameraInput实例,通过注册回调函数获取结果。 [CameraOutput](#cameraoutput)加入到会话,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| ----------- | --------------------------- | ---- | --------------------------- | | ------------- | ------------------------------- | ---- | ------------------------ |
| cameraInput | [CameraInput](#camerainput) | 是 | 需要移除的CameraInput实例。 | | cameraOutput | [CameraOutput](#cameraOutput) | 是 | 需要添加的CameraOutput实例。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 | | callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:** **示例:**
```js ```js
captureSession.removeInput(cameraInput, (err) => { captureSession.addOutput(cameraOutput, (err) => {
if (err) { if (err) {
console.error('Failed to remove the CameraInput instance. ${err.message}'); console.error('Failed to add output. ${err.message}');
return; return;
} }
console.log('Callback invoked to indicate that the cameraInput instance is removed.'); console.log('Callback returned with output added.');
}); })
``` ```
### removeInput ### addOutput
removeInput\(cameraInput: CameraInput\): Promise<void\> addOutput\(cameraOutput: CameraOutput\): Promise<void\>
在当前会话中,移除一个CameraInput实例,通过Promise获取结果。 [CameraOutput](#cameraoutput)加入到会话,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| ----------- | --------------------------- | ---- | --------------------------- | | ------------- | ------------------------------- | ---- | ------------------------- |
| cameraInput | [CameraInput](#camerainput) | 是 | 需要移除的CameraInput实例。 | | cameraOutput | [CameraOutput](#cameraOutput) | 是 | 需要添加的CameraOutput实例。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| -------------- | --------------------------- | | -------------- | ----------------------- |
| Promise\<void> | 使用Promise的方式获取结果。 | | Promise<void\> | 使用Promise的方式获取结果。 |
**示例:** **示例:**
```js ```js
captureSession.removeInput(cameraInput).then(() => { captureSession.addOutput(cameraOutput).then(() => {
console.log('Promise returned to indicate that the cameraInput instance is removed.'); console.log('Promise returned with cameraOutput added.');
}) })
``` ```
### removeOutput ### removeOutput
removeOutput\(previewOutput: PreviewOutput, callback: AsyncCallback<void\>\): void removeOutput\(cameraOutput: CameraOutput, callback: AsyncCallback<void\>\): void
在当前会话中,移除一个PreviewOutput实例,通过注册回调函数获取结果。 从会话中移除[CameraOutput](#cameraoutput),通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| ------------- | ------------------------------- | ---- | ----------------------------- | | ------------- | ------------------------------- | ---- | ------------------------ |
| previewOutput | [PreviewOutput](#previewoutput) | 是 | 需要移除的PreviewOutput实例。 | | cameraOutput | [CameraOutput](#cameraOutput) | 是 | 需要移除的CameraOutput实例。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 | | callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:** **示例:**
```js ```js
captureSession.removeOutput(previewOutput, (err) => { captureSession.removeOutput(cameraOutput, (err) => {
if (err) { if (err) {
console.error('Failed to remove the PreviewOutput instance. ${err.message}'); console.error('Failed to remove the CameraOutput instance. ${err.message}');
return; return;
} }
console.log('Callback invoked to indicate that the PreviewOutput instance is removed.'); console.log('Callback invoked to indicate that the CameraOutput instance is removed.');
}); });
``` ```
### removeOutput ### removeOutput
removeOutput(previewOutput: PreviewOutput): Promise<void\> removeOutput(cameraOutput: CameraOutput): Promise<void\>
在当前会话中,移除一个PreviewOutput实例,通过Promise获取结果。 从会话中移除[CameraOutput](#cameraoutput),通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| ------------- | ------------------------------- | ---- | ----------------------------- | | ------------- | ------------------------------- | ---- | ------------------------- |
| previewOutput | [PreviewOutput](#previewoutput) | 是 | 需要移除的PreviewOutput实例。 | | cameraOutput | [CameraOutput](#cameraOutput) | 是 | 需要移除的CameraOutput实例。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| -------------- | --------------------------- | | -------------- | ------------------------ |
| Promise<void\> | 使用Promise的方式获取结果。 | | Promise<void\> | 使用Promise的方式获取结果。 |
**示例:** **示例:**
```js ```js
captureSession.removeOutput(previewOutput).then(() => { captureSession.removeOutput(cameraOutput).then(() => {
console.log('Promise returned to indicate that the PreviewOutput instance is removed.'); console.log('Promise returned to indicate that the CameraOutput instance is removed.');
}) })
``` ```
### removeOutput ### start
removeOutput(photoOutput: PhotoOutput, callback: AsyncCallback<void\>): void start\(callback: AsyncCallback<void\>\): void
在当前会话中,移除一个PhotoOutput实例,通过注册回调函数获取结果。 开始会话工作,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| ----------- | --------------------------- | ---- | --------------------------- | | -------- | -------------------- | ---- | -------------------- |
| photoOutput | [PhotoOutput](#photooutput) | 是 | 需要移除的PhotoOutput实例。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 | | callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:** **示例:**
```js ```js
captureSession.removeOutput(photoOutput, (err) => { captureSession.start((err) => {
if (err) { if (err) {
console.error('Failed to remove the PhotoOutput instance. ${err.message}'); console.error('Failed to start the session ${err.message}');
return; return;
} }
console.log('Callback invoked to indicate that the PhotoOutput instance is removed.'); console.log('Callback invoked to indicate the session start success.');
}); });
``` ```
### removeOutput ### start
removeOutput(photoOutput: PhotoOutput): Promise<void\> start\(\): Promise<void\>
在当前会话中,移除一个PhotoOutput实例,通过Promise获取结果。 开始会话工作,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ----------- | --------------------------- | ---- | --------------------------- |
| photoOutput | [PhotoOutput](#photooutput) | 是 | 需要移除的PhotoOutput实例。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| -------------- | --------------------------- | | -------------- | ------------------------ |
| Promise<void\> | 使用Promise的方式获取结果。 | | Promise<void\> | 使用Promise的方式获取结果。 |
**示例:** **示例:**
```js ```js
captureSession.removeOutput(photoOutput).then(() => { captureSession.start().then(() => {
console.log('Promise returned to indicate that the PhotoOutput instance is removed.'); console.log('Promise returned to indicate the session start success.');
}) })
``` ```
### removeOutput ### stop
removeOutput(videoOutput: VideoOutput, callback: AsyncCallback<void\>): void stop\(callback: AsyncCallback<void\>\): void
在当前会话中,移除一个VideoOutput实例,通过注册回调函数获取结果。 停止会话工作,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| ----------- | --------------------------- | ---- | --------------------------- | | -------- | -------------------- | ---- | ------------------- |
| videoOutput | [VideoOutput](#videooutput) | 是 | 需要移除的VideoOutput实例。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 | | callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:** **示例:**
```js ```js
captureSession.removeOutput(videoOutput, (err) => { captureSession.stop((err) => {
if (err) { if (err) {
console.error('Failed to remove the VideoOutput instance. ${err.message}'); console.error('Failed to stop the session ${err.message}');
return; return;
} }
console.log('Callback invoked to indicate that the VideoOutput instance is removed.'); console.log('Callback invoked to indicate the session stop success.');
}); });
``` ```
### removeOutput ### stop
removeOutput(videoOutput: VideoOutput): Promise<void\> stop(): Promise<void\>
在当前会话中,移除一个VideoOutput实例,通过Promise获取结果。 停止会话工作,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ----------- | --------------------------- | ---- | --------------------------- |
| videoOutput | [VideoOutput](#videooutput) | 是 | 需要移除的VideoOutput实例。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| -------------- | --------------------------- | | -------------- | ----------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 | | Promise<void\> | 使用Promise的方式获取结果。 |
**示例:** **示例:**
```js ```js
captureSession.removeOutput(videoOutput).then(() => { captureSession.stop().then(() => {
console.log('Promise returned to indicate that the VideoOutput instance is removed.'); console.log('Promise returned to indicate the session stop success.');
}) })
``` ```
### start ### lockForControl
start\(callback: AsyncCallback<void\>\): void lockForControl(callback: AsyncCallback<void\>): void
启动拍照会话,通过注册回调函数获取结果。 请求以独占方式控制设备的硬件属性[CameraInput](#camerainput),需要调用[unlockForControl](#unlockforcontrol),通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------ | | -------- | -------------------- | ---- | ------------------- |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 | | callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:** **示例:**
```js ```js
captureSession.start((err) => { captureSession.lockForControl((err) => {
if (err) { if (err) {
console.error('Failed to start the session ${err.message}'); console.error('Failed to lock. ${err.message}');
return; return;
} }
console.log('Callback invoked to indicate the session start success.'); console.log('Locked.');
}); })
``` ```
### start ### lockForControl
start\(\): Promise<void\> lockForControl(): Promise<void\>
启动拍照会话,通过Promise获取结果。 请求以独占方式控制设备的硬件属性[CameraInput](#camerainput),需要调用[unlockForControl](#unlockforcontrol),通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| -------------- | --------------------------- | | -------------- | ------------------------ |
| Promise<void\> | 使用Promise的方式获取结果。 | | Promise<void\> | 使用Promise的方式获取结果。 |
**示例:** **示例:**
```js ```js
captureSession.start().then(() => { captureSession.lockForControl().then(() => {
console.log('Promise returned to indicate the session start success.'); console.log('Locked.');
}) })
``` ```
### stop ### unlockForControl
stop\(callback: AsyncCallback<void\>\): void unlockForControl(callback: AsyncCallback<void\>): void
停止拍照会话,通过注册回调函数获取结果。 控制生效,并放弃对设备配置的排他控制,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------ | | -------- | -------------------- | ---- | -------------------- |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 | | callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:** **示例:**
```js ```js
captureSession.stop((err) => { captureSession.unlockForControl((err) => {
if (err) { if (err) {
console.error('Failed to stop the session ${err.message}'); console.error('Failed to unlock. ${err.message}');
return; return;
} }
console.log('Callback invoked to indicate the session stop success.'); console.log('Unlocked.');
}); })
``` ```
### stop ### unlockForControl
stop(): Promise<void\> unlockForControl(): Promise<void\>
停止拍照会话,通过Promise获取结果。 控制生效,并放弃对设备配置的排他控制,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| -------------- | --------------------------- | | -------------- | ------------------------ |
| Promise<void\> | 使用Promise的方式获取结果。 | | Promise<void\> | 使用Promise的方式获取结果。 |
**示例:** **示例:**
```js ```js
captureSession.stop().then(() => { captureSession.unlockForControl().then(() => {
console.log('Promise returned to indicate the session stop success.'); console.log('Unlocked.');
}) })
``` ```
...@@ -1807,14 +1930,14 @@ captureSession.stop().then(() => { ...@@ -1807,14 +1930,14 @@ captureSession.stop().then(() => {
release\(callback: AsyncCallback<void\>\): void release\(callback: AsyncCallback<void\>\): void
释放CaptureSession实例,通过注册回调函数获取结果。 释放会话资源,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------ | | -------- | -------------------- | ---- | -------------------- |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 | | callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:** **示例:**
...@@ -1833,14 +1956,14 @@ captureSession.release((err) => { ...@@ -1833,14 +1956,14 @@ captureSession.release((err) => {
release(): Promise<void\> release(): Promise<void\>
释放CaptureSession实例,通过Promise获取结果。 释放会话资源,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| -------------- | --------------------------- | | -------------- | ------------------------ |
| Promise<void\> | 使用Promise的方式获取结果。 | | Promise<void\> | 使用Promise的方式获取结果。 |
**示例:** **示例:**
...@@ -1851,239 +1974,1624 @@ captureSession.release().then(() => { ...@@ -1851,239 +1974,1624 @@ captureSession.release().then(() => {
}) })
``` ```
### on('error') ### hasFlash
on(type: 'error', callback: ErrorCallback<CaptureSessionError\>): void hasFlash(callback: AsyncCallback<boolean\>): void
监听拍照会话的错误事件,通过注册回调函数获取结果。 检测是否有闪光灯,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| :------- | :---------------------------------------------------------- | :--- | :-------------------------------------------- | | -------- | ----------------------- | ---- | -------------------------------- |
| type | string | 是 | 监听事件,固定为'error',即拍照会话错误事件。 | | callback | AsyncCallback<boolean\> | 是 | 回调函数,返回true表示设备支持闪光灯。 |
| callback | ErrorCallback<[CaptureSessionError](#capturesessionerror)\> | 是 | 回调函数,用于获取错误信息。 |
**示例:** **示例:**
```js ```js
captureSession.on('error', (captureSessionError) => { cameraInput.hasFlash((err, status) => {
console.log('Capture session error code: ' + captureSessionError.code); 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);
}) })
``` ```
## CaptureSessionErrorCode ### hasFlash
枚举,拍照会话的错误码。 hasFlash(): Promise<boolean\>
**系统能力:** SystemCapability.Multimedia.Camera.Core 检测是否有闪光灯,通过Promise获取结果。
| 名称 | 值 | 说明 | **系统能力:** SystemCapability.Multimedia.Camera.Core
| ------------- | ---- | ---------- |
| ERROR_UNKNOWN | -1 | 未知错误。 |
## CaptureSessionError **返回值:**
拍照会话错误对象。 | 类型 | 说明 |
| ----------------- | ----------------------------------------------- |
| Promise<boolean\> | 使用Promise的方式获取结果,返回true表示设备支持闪光灯。 |
**系统能力:** SystemCapability.Multimedia.Camera.Core **示例:**
| 名称 | 类型 | 说明 | ```js
| ---- | ------------------------------------------- | -------------------------- | cameraInput.hasFlash().then((status) => {
| code | [CaptureSessionError](#capturesessionerror) | CaptureSession中的错误码。 | console.log('Promise returned with the flash light support status:' + status);
})
```
## camera.createPreviewOutput ### isFlashModeSupported
createPreviewOutput(surfaceId: string, callback: AsyncCallback<PreviewOutput\>): void isFlashModeSupported(flashMode: FlashMode, callback: AsyncCallback<boolean\>): void
获取PreviewOutput实例,通过注册回调函数获取结果。 检测闪光灯模式是否支持,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| --------- | ----------------------------------------------- | ---- | ------------------------------------- | | --------- | ----------------------- | ---- | --------------------------------- |
| surfaceId | string | 是 | 从XComponent组件获取的Surface ID。 | | flashMode | [FlashMode](#flashmode) | 是 | 指定闪光灯模式。 |
| callback | AsyncCallback<[PreviewOutput](#previewoutput)\> | 是 | 回调函数,用于获取PreviewOutput实例。 | | callback | AsyncCallback<boolean\> | 是 | 回调函数,返回true表示支持该闪光灯模式。 |
**示例:** **示例:**
```js ```js
camera.createPreviewOutput(("surfaceId"), (err, previewOutput) => { cameraInput.isFlashModeSupported(camera.FlashMode.FLASH_MODE_AUTO, (err, status) => {
if (err) { if (err) {
console.error('Failed to create the PreviewOutput instance. ${err.message}'); console.error('Failed to check whether the flash mode is supported. ${err.message}');
return; return;
} }
console.log('Callback returned with previewOutput instance'); console.log('Callback returned with the flash mode support status: ' + status);
}); })
``` ```
## camera.createPreviewOutput ### isFlashModeSupported
createPreviewOutput(surfaceId: string): Promise\<PreviewOutput> isFlashModeSupported(flashMode: FlashMode): Promise<boolean\>
获取PreviewOutput实例,通过Promise获取结果。 检测闪光灯模式是否支持,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| --------- | ------ | ---- | ---------------------------------- | | --------- | ----------------------- | ---- | ------------- |
| surfaceId | string | 是 | 从XComponent组件获取的Surface ID。 | | flashMode | [FlashMode](#flashmode) | 是 | 指定闪光灯模式。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ----------------------------------------- | --------------------------- | | ----------------- | ---------------------------------------------------- |
| Promise<[PreviewOutput](#previewoutput)\> | 使用Promise的方式获取结果。 | | Promise<boolean\> | 使用Promise的方式获取结果,返回true表示设备支持该闪光灯模式。 |
**示例:** **示例:**
```js ```js
camera.createPreviewOutput("surfaceId").then((previewOutput) => { cameraInput.isFlashModeSupported(camera.FlashMode.FLASH_MODE_AUTO).then((status) => {
console.log('Promise returned with the PreviewOutput instance'); console.log('Promise returned with flash mode support status.' + status);
}) })
``` ```
## PreviewOutput ### setFlashMode
预览输出类。 setFlashMode(flashMode: FlashMode, callback: AsyncCallback<void\>): void
### release 设置闪光灯模式,通过注册回调函数获取结果。
release(callback: AsyncCallback<void\>): void 进行设置之前,需要先检查:
释放PreviewOutput实例,通过注册回调函数获取结果。 1. 设备是否支持闪光灯,可使用方法[hasFlash](#hasflash)
2. 设备是否支持指定的闪光灯模式,可使用方法[isFlashModeSupported](#isflashmodesupported)
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------ | | --------- | ----------------------- | ---- | --------------------- |
| flashMode | [FlashMode](#flashmode) | 是 | 指定闪光灯模式。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 | | callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:** **示例:**
```js ```js
previewOutput.release((err) => { cameraInput.setFlashMode(camera.FlashMode.FLASH_MODE_AUTO, (err) => {
if (err) { if (err) {
console.error('Failed to release the PreviewOutput instance ${err.message}'); console.error('Failed to set the flash mode ${err.message}');
return; return;
} }
console.log('Callback invoked to indicate that the PreviewOutput instance is released successfully.'); console.log('Callback returned with the successful execution of setFlashMode.');
}); })
``` ```
### release ### setFlashMode
release(): Promise<void\> setFlashMode(flashMode: FlashMode): Promise<void\>
设置闪光灯模式,通过Promise获取结果。
释放PreviewOutput实例,通过Promise获取结果。 进行设置之前,需要先检查:
1. 设备是否支持闪光灯,可使用方法[hasFlash](#hasflash)
2. 设备是否支持指定的闪光灯模式,可使用方法[isFlashModeSupported](#isflashmodesupported)
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| --------- | ----------------------- | ---- | ------------- |
| flashMode | [FlashMode](#flashmode) | 是 | 指定闪光灯模式。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| -------------- | --------------------------- | | -------------- | ------------------------ |
| Promise<void\> | 使用Promise的方式获取结果。 | | Promise<void\> | 使用Promise的方式获取结果。 |
**示例:** **示例:**
```js ```js
previewOutput.release().then(() => { cameraInput.setFlashMode(camera.FlashMode.FLASH_MODE_AUTO).then(() => {
console.log('Promise returned to indicate that the PreviewOutput instance is released successfully.'); console.log('Promise returned with the successful execution of setFlashMode.');
}) })
``` ```
### on('frameStart') ### getFlashMode
on(type: 'frameStart', callback: AsyncCallback<void\>): void getFlashMode(callback: AsyncCallback<FlashMode\>): void
监听预览帧启动,通过注册回调函数获取结果。 获取当前设备的闪光灯模式,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| :------- | :------------------- | :--- | :------------------------------------------- | | -------- | --------------------------------------- | ---- | --------------------------------- |
| type | string | 是 | 监听事件,固定为'frameStart',即帧启动事件。 | | callback | AsyncCallback<[FlashMode](#flashmode)\> | 是 | 回调函数,用于获取当前设备的闪光灯模式。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:** **示例:**
```js ```js
previewOutput.on('frameStart', () => { cameraInput.getFlashMode((err, flashMode) => {
console.log('Preview frame started'); if (err) {
console.error('Failed to get the flash mode ${err.message}');
return;
}
console.log('Callback returned with current flash mode: ' + flashMode);
}) })
``` ```
### on('frameEnd') ### getFlashMode
on(type: 'frameEnd', callback: AsyncCallback<void\>): void getFlashMode(): Promise<FlashMode\>
监听预览帧结束,通过注册回调函数获取结果。 获取当前设备的闪光灯模式,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **返回值:**
| 名称 | 类型 | 必填 | 说明 | | 类型 | 说明 |
| :------- | :------------------- | :--- | :----------------------------------------- | | --------------------------------- | --------------------------------- |
| type | string | 是 | 监听事件,固定为'frameEnd',即帧结束事件。 | | Promise<[FlashMode](#flashmode)\> | 使用Promise的方式获取当前的闪光灯模式。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:** **示例:**
```js ```js
previewOutput.on('frameEnd', () => { cameraInput.getFlashMode().then((flashMode) => {
console.log('Preview frame ended'); console.log('Promise returned with current flash mode : ' + flashMode);
}) })
``` ```
### on('error') ### isExposureModeSupported
on(type: 'error', callback: ErrorCallback<PreviewOutputError\>): void isExposureModeSupported(aeMode: ExposureMode, callback: AsyncCallback<boolean\>): void;
监听预览输出的错误事件,通过注册回调函数获取结果。 检测曝光模式是否支持,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| :------- | :----------------------------------------------------------- | :--- | :-------------------------------------------- | | -------- | -------------------------------| ---- | ----------------------------- |
| type | string | 是 | 监听事件,固定为'error',即预览输出错误事件。 | | aeMode | [ExposureMode](#exposuremode) | 是 | 曝光模式。 |
| callback | ErrorCallback<[PreviewOutputErrorCode](#previewoutputerrorcode)\> | 是 | 回调函数,用于获取错误信息。 | | callback | AsyncCallback<boolean\> | 是 | 回调函数,用于获取是否支持曝光模式。 |
**示例:** **示例:**
```js ```js
previewOutput.on('error', (previewOutputError) => { cameraInput.isExposureModeSupported(camera.ExposureMode.EXPOSURE_MODE_LOCKEN,(err) => {
console.log('Preview output error code: ' + previewOutputError.code); if (err) {
}) console.log('Failed to check exposure mode supported ${err.message}');
return ;
}
console.log('Callback returned with the successful excution of isExposureModeSupported');
})
```
### isExposureModeSupported
isExposureModeSupported(aeMode: ExposureMode): Promise<boolean\>
检测曝光模式是否支持,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------------------| ---- | ----------------------------- |
| aeMode | [ExposureMode](#exposuremode) | 是 | 曝光模式。 |
**返回值:**
| 名称 | 说明 |
| ----------------- |--------------------------------- |
| Promise<boolean\> | 使用Promise的方式获取支持的曝光模式。 |
**示例:**
```js
cameraInput.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
cameraInput.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
cameraInput.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
cameraInput.setExposureMode(camera.ExposureMode.EXPOSURE_MODE_LOCKEN,(err) => {
if (err) {
console.log('Failed to set the exposure mode ${err.message}');
return ;
}
console.log('Callback returned with the successful excution of setExposureMode');
})
```
### setExposureMode
setExposureMode(aeMode: ExposureMode): Promise<void\>
设置曝光模式,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 名称 | 说明 |
| ----------------- |---------------------------- |
| Promise<void\> | 使用Promise的方式获取设置结果。 |
**示例:**
```js
cameraInput.setExposureMode(camera.ExposureMode.EXPOSURE_MODE_LOCKED).then(() => {
console.log('Promise returned with the successful execution of setExposureMode.');
})
```
### getMeteringPoint
getMeteringPoint(callback: AsyncCallback<Point\>): void
查询曝光区域中心点,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------------------| ---- | ------------------------ |
| callback | AsyncCallback<[Point](#point)\>| 是 | 回调函数,用于获取当前曝光点。 |
**示例:**
```js
cameraInput.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获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 名称 | 说明 |
| ------------------------- |----------------------------- |
| Promise<[Point](#point)\> | 使用Promise的方式获取当前曝光点。 |
**示例:**
```js
cameraInput.getMeteringPoint().then((exposurePoint) => {
console.log('Promise returned with current exposure point : ' + exposurePoint);
})
```
### setMeteringPoint
setMeteringPoint(point: Point, callback: AsyncCallback<point\>): void
设置曝光区域中心点,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ------------- | -------------------------------| ---- | ------------------- |
| exposurePoint | [Point](#point) | 是 | 曝光点。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```js
var Point1 = {x: 1, y: 1};
cameraInput.setMeteringPoint(Point1,(err) => {
if (err) {
console.log('Failed to set the exposure point ${err.message}');
return ;
}
console.log('Callback returned with the successful excution of setMeteringPoint');
})
```
### setMeteringPoint
setMeteringPoint(point: Point): Promise<void\>
设置曝光区域中心点,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ------------- | -------------------------------| ---- | ------------------- |
| exposurePoint | [Point](#point) | 是 | 曝光点。 |
**返回值:**
| 名称 | 说明 |
| ----------------- |------------------------ |
| Promise<void\> | 使用Promise的方式返回结果。 |
**示例:**
```js
var Point2 = {x: 2, y: 2};
cameraInput.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
cameraInput.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
cameraInput.isExposureModeSupported(camera.ExposureMode.EXPOSURE_MODE_LOCKED).then((isSupported) => {
console.log('Promise returned with exposure mode supported : ' + isSupported);
})
```
### setExposureBias
setExposureBias(exposureBias: number, callback: AsyncCallback<void\>): void
设置曝光补偿,通过注册回调函数获取结果。
进行设置之前,建议先通过方法[getExposureBiasRange](#getexposurebiasrange)查询支持的范围。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------------------| ---- | ------------------- |
| exposureBias | number | 是 | 曝光补偿。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```js
cameraInput.setExposureBias(-4,(err) => {
if (err) {
console.log('Failed to set the exposure bias ${err.message}');
return ;
}
console.log('Callback returned with the successful excution of setExposureBias');
})
```
### setExposureBias
setExposureBias(exposureBias: number): Promise<void\>
设置曝光补偿,通过Promise获取结果。
进行设置之前,建议先通过方法[getExposureBiasRange](#getexposurebiasrange)查询支持的范围。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------------- | --------- | ---- | --------- |
| exposureBias | number | 是 | 曝光补偿。 |
**返回值:**
| 名称 | 说明 |
| ----------------- |------------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 |
**示例:**
```js
cameraInput.setExposureBias(-4).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
cameraInput.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
cameraInput.getExposureValue().then((exposureValue) => {
console.log('Promise returned with exposure value: ' + exposureValue);
})
```
### isFocusModeSupported
isFocusModeSupported(afMode: FocusMode, callback: AsyncCallback<boolean\>): void
检测对焦模式是否支持,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------- |
| afMode | [FocusMode](#focusmode) | 是 | 指定的焦距模式。 |
| callback | AsyncCallback<boolean\> | 是 | 回调函数,返回true表示支持该焦距模式。 |
**示例:**
```js
cameraInput.isFocusModeSupported(camera.FocusMode.FOCUS_MODE_AUTO, (err, status) => {
if (err) {
console.error('Failed to check whether the focus mode is supported. ${err.message}');
return;
}
console.log('Callback returned with the focus mode support status: ' + status);
})
```
### isFocusModeSupported
isFocusModeSupported(afMode: FocusMode): Promise<boolean\>
检测对焦模式是否支持,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ------ | ----------------------- | ---- | ------------- |
| afMode | [FocusMode](#focusmode) | 是 | 指定的焦距模式。 |
**返回值:**
| 类型 | 说明 |
| ----------------- | --------------------------------------------------- |
| Promise<boolean\> | 使用Promise的方式获取结果,返回true表示设备支持该焦距模式。 |
**示例:**
```js
cameraInput.isFocusModeSupported(camera.FocusMode.FOCUS_MODE_AUTO).then((status) => {
console.log('Promise returned with focus mode support status.' + status);
})
```
### setFocusMode
setFocusMode(afMode: FocusMode, callback: AsyncCallback<void\>): void
设置对焦模式,通过注册回调函数获取结果。
进行设置之前,需要先检查设备是否支持指定的焦距模式,可使用方法[isFocusModeSupported](#isfocusmodesupported)
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | ------------------- |
| afMode | [FocusMode](#focusmode) | 是 | 指定的焦距模式。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```js
cameraInput.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.');
})
```
### setFocusMode
setFocusMode(afMode: FocusMode): Promise<void\>
设置对焦模式,通过Promise获取结果。
进行设置之前,需要先检查设备是否支持指定的焦距模式,可使用方法[isFocusModeSupported](#isfocusmodesupported)
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ------ | ----------------------- | ---- | ------------- |
| afMode | [FocusMode](#focusmode) | 是 | 指定的焦距模式。 |
**返回值:**
| 类型 | 说明 |
| -------------- | ------------------------ |
| Promise<void\> | 使用Promise的方式获取结果。 |
**示例:**
```js
cameraInput.setFocusMode(camera.FocusMode.FOCUS_MODE_AUTO).then(() => {
console.log('Promise returned with the successful execution of setFocusMode.');
})
```
### getFocusMode
getFocusMode(callback: AsyncCallback<FocusMode\>): void
获取当前的对焦模式,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ------------------------------- |
| callback | AsyncCallback<[FocusMode](#focusmode)\> | 是 | 回调函数,用于获取当前设备的焦距模式。 |
**示例:**
```js
cameraInput.getFocusMode((err, afMode) => {
if (err) {
console.error('Failed to get the focus mode ${err.message}');
return;
}
console.log('Callback returned with current focus mode: ' + afMode);
})
```
### getFocusMode
getFocusMode(): Promise<FocusMode\>
获取当前的对焦模式,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| ------------------- | -------------------------------- |
| Promise<FocusMode\> | 使用Promise的方式获取当前的焦距模式。 |
**示例:**
```js
cameraInput.getFocusMode().then((afMode) => {
console.log('Promise returned with current focus mode : ' + afMode);
})
```
### setFocusPoint
setFocusPoint(point: Point, callback: AsyncCallback<void\>): void
设置焦点,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | ------------------- |
| point | [Point](#Point) | 是 | 焦点。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```js
var Point1 = {x: 1, y: 1};
cameraInput.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.');
})
```
### setFocusPoint
setFocusPoint(point: Point): Promise<void\>
设置焦点,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| -------------- | ----------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 |
**示例:**
```js
var Point2 = {x: 2, y: 2};
cameraInput.setFocusPoint(Point2).then(() => {
console.log('Promise returned with the successful execution of setFocusPoint.');
})
```
### getFocusPoint
getFocusPoint(callback: AsyncCallback<Point\>): void
查询焦点,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------- | ---- | ----------------------- |
| callback | AsyncCallback<[Point](#point)\> | 是 | 回调函数,用于获取当前焦点。 |
**示例:**
```js
cameraInput.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));
})
```
### getFocusPoint
getFocusPoint(): Promise<Point\>
查询焦点,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| --------------- | --------------------------- |
| Promise<Point\> | 使用Promise的方式获取当前焦点。 |
**示例:**
```js
cameraInput.getFocusPoint().then((point) => {
console.log('Promise returned with the current focus point: ' + JSON.stringify(point));
})
```
### getFocalLength
getFocalLength(callback: AsyncCallback<number\>): void
查询焦距值,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ------------------------- | ---- | ----------------------- |
| callback | AsyncCallback<number\> | 是 | 回调函数,用于获取当前焦距。 |
**示例:**
```js
cameraInput.getFocalLength((err, focalLength) => {
if (err) {
console.error('Failed to get the current focal length ${err.message}');
return;
}
console.log('Callback returned with the current focal length: ' + focalLength);
})
```
### getFocalLength
getFocalLength(): Promise<number\>
查询焦距值,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| ---------------- | ----------------------- |
| Promise<number\> | 使用Promise的方式获取焦距。 |
**示例:**
```js
cameraInput.getFocalLength().then((focalLength) => {
console.log('Promise returned with the current focal length: ' + focalLength);
})
```
### getZoomRatioRange
getZoomRatioRange\(callback: AsyncCallback<Array<number\>\>\): void
获取支持的变焦范围,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ------------------------------ | ---- | ------------------- |
| callback | AsyncCallback<Array<number\>\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```js
cameraInput.getZoomRatioRange((err, zoomRatioRange) => {
if (err) {
console.error('Failed to get the zoom ratio range. ${err.message}');
return;
}
console.log('Callback returned with zoom ratio range: ' + zoomRatioRange.length);
})
```
### getZoomRatioRange
getZoomRatioRange\(\): Promise<Array<number\>\>
获取支持的变焦范围,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| ------------------------ | --------------------------- |
| Promise<Array<number\>\> | 使用Promise的方式获取变焦范围。 |
**示例:**
```js
cameraInput.getZoomRatioRange().then((zoomRatioRange) => {
console.log('Promise returned with zoom ratio range: ' + zoomRatioRange.length);
})
```
### setZoomRatio
setZoomRatio(zoomRatio: number, callback: AsyncCallback<void\>): void
设置变焦比,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| --------- | -------------------- | ---- | ------------------- |
| zoomRatio | number | 是 | 可变焦距比。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```js
cameraInput.setZoomRatio(1, (err) => {
if (err) {
console.error('Failed to set the zoom ratio value ${err.message}');
return;
}
console.log('Callback returned with the successful execution of setZoomRatio.');
})
```
### setZoomRatio
setZoomRatio(zoomRatio: number): Promise<void\>
设置变焦比,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| --------- | ------ | ---- | --------- |
| zoomRatio | number | 是 | 可变焦距比。 |
**返回值:**
| 类型 | 说明 |
| -------------- | ----------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 |
**示例:**
```js
cameraInput.setZoomRatio(1).then(() => {
console.log('Promise returned with the successful execution of setZoomRatio.');
})
```
### getZoomRatio
getZoomRatio(callback: AsyncCallback<number\>): void
获取当前的变焦比,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ---------------------- | ---- | ------------------- |
| callback | AsyncCallback<number\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```js
cameraInput.getZoomRatio((err, zoomRatio) => {
if (err) {
console.error('Failed to get the zoom ratio ${err.message}');
return;
}
console.log('Callback returned with current zoom ratio: ' + zoomRatio);
})
```
### getZoomRatio
getZoomRatio(): Promise<number\>
获取当前的变焦比,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| ---------------- | ----------------------- |
| Promise<number\> | 使用Promise的方式获取结果。 |
**示例:**
```js
cameraInput.getZoomRatio().then((zoomRatio) => {
console.log('Promise returned with current zoom ratio : ' + zoomRatio);
})
```
### isVideoStablizationModeSupported
isVideoStablizationModeSupported(vsMode: VideoStabilizationMode, callback: AsyncCallback<boolean\>): void
查询是否支持指定的视频防抖模式,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------- | ---- | ------------------------------ |
| vsMode | [VideoStabilizationMode](#videostabilizationMode) | 是 | 视频防抖模式。 |
| callback | AsyncCallback<boolean\> | 是 | 回调函数,返回视频防抖模式是否支持。 |
**示例:**
```js
captureSession.isVideoStablizationModeSupported(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: ' + status);
})
```
### isVideoStablizationModeSupported
isVideoStablizationModeSupported(vsMode: VideoStabilizationMode): Promise<boolean\>
查询是否支持指定的视频防抖模式,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| ----------------- | --------------------------------------------- |
| Promise<boolean\> | 使用Promise的方式获取结果,返回视频防抖模式是否支持。 |
**示例:**
```js
captureSession.isVideoStablizationModeSupported(camera.VideoStabilizationMode.OFF).then((isSupported) => {
console.log('Promise returned with video stabilization mode supported: ' + isSupported);
})
```
### getActiveVideoStabilizationMode
getActiveVideoStabilizationMode(callback: AsyncCallback<VideoStabilizationMode\>): void
查询当前正在使用的视频防抖模式,通过注册回调函数获取结果。
**系统能力:** 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
**返回值:**
| 类型 | 说明 |
| -------------------------------- | ------------------------------------------------- |
| Promise<VideoStabilizationMode\> | 使用Promise的方式获取结果,返回视频防抖当前是否正在使用。 |
**示例:**
```js
captureSession.getActiveVideoStabilizationMode().then((vsMode) => {
console.log('Promise returned with the current video stabilization mode: ' + vsMode);
})
```
### setVideoStabilizationMode
setVideoStabilizationMode(mode: VideoStabilizationMode, callback: AsyncCallback<void\>): void
设置视频防抖模式,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------- | ---- | --------------------- |
| mode | [VideoStabilizationMode](#videostabilizationmode) | 是 | 需要设置的视频防抖模式。 |
| callback | AsyncCallback<void\> | 是 | 回调函数。 |
**示例:**
```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.');
})
```
### setVideoStabilizationMode
setVideoStabilizationMode(mode: VideoStabilizationMode): Promise<void\>
设置视频防抖,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| -------------- | ------------------------------------------------- |
| Promise<void\> | 使用Promise的方式获取结果,返回设置的视频防抖模式的结果。 |
**示例:**
```js
captureSession.setVideoStabilizationMode(camera.VideoStabilizationMode.OFF).then(() => {
console.log('Promise returned with the successful execution of setVideoStabilizationMode.');
})
```
### on('focusStateChange')
on(type: 'focusStateChange', callback: AsyncCallback<FocusState\>): void
监听焦距的状态变化,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------- | ---- | ------------------------ |
| type | string | 是 | 监听事件,固定为'focusStateChange',即焦距状态变化事件。 |
| callback | AsyncCallback<[FocusState](#focusstate)\> | 是 | 回调函数,用于获取焦距状态。 |
**示例:**
```js
cameraInput.on('focusStateChange', (focusState) => {
console.log('Focus state : ' + focusState);
})
```
### on('exposureStateChange')
on(type: 'exposureStateChange', callback: AsyncCallback<ExposureState\>): void
监听曝光的状态变化,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------- | ---- | ---------------------------------------------- |
| type | string | 是 | 监听事件,固定为'exposureStateChange',即曝光状态变化事件。|
| callback | AsyncCallback<[ExposureState](#exposureState)\> | 是 | 回调函数,用于获取曝光状态。 |
**示例:**
```js
cameraInput.on('exposureStateChange', (exposureState) => {
console.log('Exposuer state : ' + exposureState);
})
```
### on('error')
on(type: 'error', callback: ErrorCallback<CaptureSessionError\>): void
监听拍照会话的错误事件,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------------------------- | ---- | ------------------------------ |
| type | string | 是 | 监听事件,固定为'error',即拍照会话错误事件。 |
| callback | ErrorCallback<[CaptureSessionError](#capturesessionerror)\> | 是 | 回调函数,用于获取错误信息。 |
**示例:**
```js
captureSession.on('error', (captureSessionError) => {
console.log('Capture session error code: ' + captureSessionError.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的基类。
### release
release(callback: AsyncCallback<void\>): void
释放输出资源,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------- |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```js
previewOutput.release((err) => {
if (err) {
console.error('Failed to release the PreviewOutput instance ${err.message}');
return;
}
console.log('Callback invoked to indicate that the PreviewOutput instance is released successfully.');
});
```
### release
release(): Promise<void\>
释放输出资源,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| -------------- | ----------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 |
**示例:**
```js
previewOutput.release().then(() => {
console.log('Promise returned to indicate that the PreviewOutput instance is released successfully.');
})
```
## PreviewOutput
预览输出类。继承[CameraOutput](#cameraOutput)
### addDeferredSurface
addDeferredSurface(surfaceId: string, callback: AsyncCallback<void\>): void
在previewOutput生成之后添加surface,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | -------------------------------------------------------------------- |
| surfaceId| string | 是 | 从[XComponent](../arkui-ts/ts-basic-components-xcomponent.md)组件获取的SurfaceID。|
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```js
previewOutput.addDeferredSurface('surfaceId', (err) => {
if (err) {
console.error('Failed to add deferredSurface. ${err.message}');
return;
}
console.log('Callback returned with deferredSurface added.');
})
```
### addDeferredSurface
addDeferredSurface(surfaceId: string): Promise<void\>
在previewOutput生成之后添加surface,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | -----------| ---- | ------------------------------------------------------------------------------ |
| surfaceId| string | 是 | 从[XComponent](../arkui-ts/ts-basic-components-xcomponent.md)组件获取的SurfaceID。|
**返回值:**
| 类型 | 说明 |
| -------------- | ----------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 |
**示例:**
```js
previewOutput.addDeferredSurface('surfaceId').then(() => {
console.log('Promise returned with deferredSurface added.');
})
```
### start
start(callback: AsyncCallback<void\>): void
开始输出预览流,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | -------------------- |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```js
previewOutput.start((err) => {
if (err) {
console.error('Failed to start the previewOutput. ${err.message}');
return;
}
console.log('Callback returned with previewOutput started.');
})
```
### start
start(): Promise<void\>
开始输出预览流,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| -------------- | ----------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 |
**示例:**
```js
previewOutput.start().then(() => {
console.log('Promise returned with previewOutput started.');
})
```
### stop
stop(callback: AsyncCallback<void\>): void
停止输出预览流,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | -------------------- |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```js
previewOutput.stop((err) => {
if (err) {
console.error('Failed to stop the previewOutput. ${err.message}');
return;
}
console.log('Callback returned with previewOutput stoped.');
})
```
### stop
stop(): Promise<void\>
停止输出预览流,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| -------------- | ------------------------ |
| Promise<void\> | 使用Promise的方式获取结果。 |
**示例:**
```js
previewOutput.stop().then(() => {
console.log('Callback returned with previewOutput stoped.');
})
```
### on('frameStart')
on(type: 'frameStart', callback: AsyncCallback<void\>): void
监听预览帧启动,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | --------------------------------------- |
| type | string | 是 | 监听事件,固定为'frameStart',即帧启动事件。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```js
previewOutput.on('frameStart', () => {
console.log('Preview frame started');
})
```
### on('frameEnd')
on(type: 'frameEnd', callback: AsyncCallback<void\>): void
监听预览帧结束,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------------------- |
| type | string | 是 | 监听事件,固定为'frameEnd',即帧结束事件。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```js
previewOutput.on('frameEnd', () => {
console.log('Preview frame ended');
})
```
### on('error')
on(type: 'error', callback: ErrorCallback<PreviewOutputError\>): void
监听预览输出的错误事件,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------------------------------- | ---- | ------------------------ |
| type | string | 是 | 监听事件,固定为'error',即预览输出错误事件。|
| callback | ErrorCallback<[PreviewOutputErrorCode](#previewoutputerrorcode)\> | 是 | 回调函数,用于获取错误信息。 |
**示例:**
```js
previewOutput.on('error', (previewOutputError) => {
console.log('Preview output error code: ' + previewOutputError.code);
})
``` ```
## PreviewOutputErrorCode ## PreviewOutputErrorCode
枚举,预览输出的错误码 枚举,预览输出错误类型
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 值 | 说明 | | 名称 | 值 | 说明 |
| ------------- | ---- | ---------- | | ------------- | ---- | -------- |
| ERROR_UNKNOWN | -1 | 未知错误。 | | ERROR_UNKNOWN | -1 | 未知错误。 |
## PreviewOutputError ## PreviewOutputError
预览输出错误对象 预览输出错误
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
...@@ -2091,193 +3599,440 @@ previewOutput.on('error', (previewOutputError) => { ...@@ -2091,193 +3599,440 @@ previewOutput.on('error', (previewOutputError) => {
| ---- | ------------------------------------------------- | ---------------------- | | ---- | ------------------------------------------------- | ---------------------- |
| code | [PreviewOutputErrorCode](#previewoutputerrorcode) | PreviewOutput中的错误码。 | | code | [PreviewOutputErrorCode](#previewoutputerrorcode) | PreviewOutput中的错误码。 |
## camera.createPhotoOutput ## ImageRotation
枚举,图片旋转角度。
**系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 值 | 说明 |
| ------------ | ---- | ------------- |
| ROTATION_0 | 0 | 图片旋转0度。 |
| ROTATION_90 | 90 | 图片旋转90度。 |
| ROTATION_180 | 180 | 图片旋转180度。 |
| ROTATION_270 | 270 | 图片旋转270度。 |
## Location
图片地理位置信息。
**系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 类型 | 必填 |说明 |
| ------------ | ------ | --- |------------ |
| latitude | number | 是 |纬度(度)。 |
| longitude | number | 是 |经度(度)。 |
| altitude | number | 是 |海拔(米)。 |
## QualityLevel
枚举,图片质量。
**系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 值 | 说明 |
| -------------------- | ---- | ------------ |
| QUALITY_LEVEL_HIGH | 0 | 图片质量高。 |
| QUALITY_LEVEL_MEDIUM | 1 | 图片质量中等。 |
| QUALITY_LEVEL_LOW | 2 | 图片质量差。 |
## PhotoCaptureSetting
拍摄照片的设置。
**系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 类型 | 必填 | 默认值 | 说明 |
| -------- | ------------------------------- | ---- | ----------------- | -----------------|
| quality | [QualityLevel](#qualitylevel) | 否 | QUALITY_LEVEL_HIGH| 图片质量。 |
| rotation | [ImageRotation](#imagerotation) | 否 | ROTATION_0 | 图片旋转角度。 |
| location | [Location](#location) | 否 | (0,0,0) | 图片地理位置信息。 |
| mirror | boolean | 否 | false |镜像使能开关(默认关)。 |
## PhotoOutput
createPhotoOutput(surfaceId: string, callback: AsyncCallback<PhotoOutput\>): void 拍照会话中使用的输出信息。
获取PhotoOutput实例,通过注册回调函数获取结果。 ### getDefaultCaptureSetting
getDefaultCaptureSetting(callback: AsyncCallback<PhotoCaptureSetting\>): void
获取默认拍照参数,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| --------- | ------------------------------------------- | ---- | ----------------------------------- | | -------- | ----------------------------------------------------------- | ---- | -------------------- |
| surfaceId | string | 是 | 从[ImageReceiver](js-apis-image.md#imagereceiver9)获取的Surface ID。 | | callback | AsyncCallback<[PhotoCaptureSetting](#photocapturesetting)\> | 是 | 回调函数,用于获取结果。 |
| callback | AsyncCallback<[PhotoOutput](#photooutput)\> | 是 | 回调函数,用于获取PhotoOutput实例。 |
**示例:**
```js
photoOutput.getDefaultCaptureSetting((err, photocapturesetting) => {
if (err) {
console.error('Failed to get the defaultCaptureSetting. ${err.message}');
return;
}
console.log('Callback returned with an array of defaultCaptureSetting.');
})
```
### getDefaultCaptureSetting
getDefaultCaptureSetting(): Promise<PhotoCaptureSetting\>
获取默认拍照参数,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| ----------------------------------------------------- | ----------------------- |
| Promise<[PhotoCaptureSetting](#photocapturesetting)\> | 使用Promise的方式获取结果。 |
**示例:**
```js
photoOutput.getDefaultCaptureSetting().then((photocapturesetting) => {
console.log('Callback returned with an array of defaultCaptureSetting.');
})
```
### capture
capture(callback: AsyncCallback<void\>): void
以默认设置触发一次拍照,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------- |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```js
photoOutput.capture((err) => {
if (err) {
console.error('Failed to capture the photo ${err.message}');
return;
}
console.log('Callback invoked to indicate the photo capture request success.');
});
```
### capture
capture(setting: PhotoCaptureSetting, callback: AsyncCallback<void\>): void
以指定参数触发一次拍照,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------- | ---- | -------------------- |
| setting | [PhotoCaptureSetting](#photocapturesetting) | 是 | 拍照设置。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:** **示例:**
```js ```js
camera.createPhotoOutput(("surfaceId"), (err, photoOutput) => { let settings:PhotoCaptureSetting = {
quality = 1,
rotation = 0
}
photoOutput.capture(settings, (err) => {
if (err) { if (err) {
console.error('Failed to create the PhotoOutput instance. ${err.message}'); console.error('Failed to capture the photo ${err.message}');
return; return;
} }
console.log('Callback returned with the PhotoOutput instance.'); console.log('Callback invoked to indicate the photo capture request success.');
}); });
``` ```
## camera.createPhotoOutput ### capture
createPhotoOutput(surfaceId: string): Promise<PhotoOutput\> capture(setting?: PhotoCaptureSetting): Promise<void\>
获取PhotoOutput实例,通过Promise获取结果。 以指定参数触发一次拍照,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| --------- | ------ | ---- | --------------------------------- | | ------- | ------------------------------------------- | ---- | -------- |
| surfaceId | string | 是 | 从[ImageReceiver](js-apis-image.md#imagereceiver9)获取的Surface ID。 | | setting | [PhotoCaptureSetting](#photocapturesetting) | 否 | 拍照设置。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ------------------------------------- | -------------------------------------- | | -------------- | ------------------------ |
| Promise<[PhotoOutput](#photooutput)\> | 使用Promise的方式获取PhotoOutput实例。 | | Promise<void\> | 使用Promise的方式获取结果。 |
**示例:** **示例:**
```js ```js
camera.createPhotoOutput("surfaceId").then((photoOutput) => { photoOutput.capture().then(() => {
console.log('Promise returned with PhotoOutput instance'); console.log('Promise returned to indicate that photo capture request success.');
}) })
``` ```
## ImageRotation
枚举,图片旋转角度。 ### isMirrorSupported
isMirrorSupported(callback: AsyncCallback<boolean\>): void
查询是否支持镜像拍照,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 值 | 说明 | **参数:**
| ------------ | ---- | --------------- |
| ROTATION_0 | 0 | 图片旋转0度。 |
| ROTATION_90 | 90 | 图片旋转90度。 |
| ROTATION_180 | 180 | 图片旋转180度。 |
| ROTATION_270 | 270 | 图片旋转270度。 |
## QualityLevel | 名称 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------- | ---- | -------------------------- |
| callback | AsyncCallback<boolean\> | 是 | 回调函数,返回是否支持镜像拍照。 |
枚举,图片质量。 **示例:**
```js
captureSession.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.');
})
```
### isMirrorSupported
isMirrorSupported(): Promise<boolean\>
查询是否支持镜像拍照,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 值 | 说明 | **返回值:**
| -------------------- | ---- | -------------- |
| QUALITY_LEVEL_HIGH | 0 | 图片质量高。 | | 类型 | 说明 |
| QUALITY_LEVEL_MEDIUM | 1 | 图片质量中等。 | | ----------------- | ------------------------------------------- |
| QUALITY_LEVEL_LOW | 2 | 图片质量差。 | | Promise<boolean\> | 使用Promise的方式获取结果,返回是否支持自拍结果。 |
**示例:**
```js
captureSession.isMirrorSupported().then((isSupported) => {
console.log('Promise returned with mirror supported: ' + isSupported);
})
```
### on('captureStart')
on(type: 'captureStart', callback: AsyncCallback<number\>): void
监听拍照开始,通过注册回调函数获取Capture ID。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ---------------------- | ---- | ------------------------------------------ |
| type | string | 是 | 监听事件,固定为'captureStart',即拍照启动事件。 |
| callback | AsyncCallback<number\> | 是 | 使用callback的方式获取Capture ID。 |
**示例:**
```js
photoOutput.on('captureStart', (err, captureId) => {
console.log('photo capture stated, captureId : ' + captureId);
})
```
### on('frameShutter')
on(type: 'frameShutter', callback: AsyncCallback<FrameShutterInfo\>): void
监听拍照帧输出捕获,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------------------- | --- | ------------------------------------ |
| type | string | 是 | 监听事件,固定为'frameShutter',即帧刷新事件。 |
| callback | AsyncCallback<[FrameShutterInfo](#frameshutterinfo)\> | 是 | 回调函数,用于获取相关信息。 |
**示例:**
```js
photoOutput.on('frameShutter', (err, frameShutterInfo) => {
console.log('photo capture end, captureId : ' + frameShutterInfo.captureId);
console.log('Timestamp for frame : ' + frameShutterInfo.timestamp);
})
```
### on('captureEnd')
on(type: 'captureEnd', callback: AsyncCallback<CaptureEndInfo\>): void
监听拍照结束,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------- | ---- | ---------------------------------------- |
| type | string | 是 | 监听事件,固定为'captureEnd',即拍照停止事件。 |
| callback | AsyncCallback<[CaptureEndInfo](#captureendinfo)\> | 是 | 回调函数,用于获取相关信息。 |
**示例:**
```js
photoOutput.on('captureEnd', (err, captureEndInfo) => {
console.log('photo capture end, captureId : ' + captureEndInfo.captureId);
console.log('frameCount : ' + captureEndInfo.frameCount);
})
```
### on('error')
on(type: 'error', callback: ErrorCallback<PhotoOutputError\>): void
监听拍照输出发生错误,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------------------- | ---- | ----------------------------------- |
| type | string | 是 | 监听事件,固定为'error',即拍照错误事件。 |
| callback | ErrorCallback<[PhotoOutputError](#photooutputerror)\> | 是 | 回调函数,用于获取错误信息。 |
**示例:**
```js
photoOutput.on('error', (err, photoOutputError) => {
console.log('Photo output error code: ' + photoOutputError.code);
})
```
## FrameShutterInfo
拍照帧输出信息。
## PhotoCaptureSetting **系统能力:** SystemCapability.Multimedia.Camera.Core
拍摄照片的设置。 | 名称 | 类型 | 必填 | 说明 |
| --------- | ------ | ---- | ---------- |
| captureId | number | 是 | 拍照的ID。 |
| timestamp | number | 是 | 快门时间戳。 |
## CaptureEndInfo
拍照停止信息。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| -------- | ------------------------------- | ---- | -------------- | | ---------- | ------ | ---- | ---------|
| quality | [QualityLevel](#qualitylevel) | 否 | 图片质量。 | | captureId | number | 是 | 拍照的ID。 |
| rotation | [ImageRotation](#imagerotation) | 否 | 图片旋转角度。 | | frameCount | number | 是 | 帧数。 |
## PhotoOutputErrorCode
## PhotoOutput 枚举,拍照输出错误类型。
照片输出类。 **系统能力:** SystemCapability.Multimedia.Camera.Core
### capture | 名称 | 值 | 说明 |
| ----------------------------- | ---- | --------------- |
| ERROR_UNKNOWN | -1 | 未知错误。 |
| ERROR_DRIVER_ERROR | 0 | 驱动或者硬件错误。 |
| ERROR_INSUFFICIENT_RESOURCES | 1 | 资源不足。 |
| ERROR_TIMEOUT | 2 | 超时。 |
capture(callback: AsyncCallback<void\>): void ## PhotoOutputError
拍照,通过注册回调函数获取结果 拍照输出错误码
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** | 名称 | 类型 | 说明 |
| ---- | ------------------------------------- | ----------------------- |
| 名称 | 类型 | 必填 | 说明 | | code | [PhotoOutputError](#photooutputerror) | PhotoOutput中的错误码。 |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:** ## VideoOutput
```js 录像会话中使用的输出信息。
photoOutput.capture((err) => {
if (err) {
console.error('Failed to capture the photo ${err.message}');
return;
}
console.log('Callback invoked to indicate the photo capture request success.');
});
```
### capture ### start
capture(setting: PhotoCaptureSetting, callback: AsyncCallback<void\>): void start(callback: AsyncCallback<void\>): void
根据拍照设置拍照,通过注册回调函数获取结果。 启动录制,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------- | ---- | ------------------------ | | -------- | -------------------- | ---- | -------------------- |
| setting | [PhotoCaptureSetting](#photocapturesetting) | 是 | 拍照设置。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 | | callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:** **示例:**
```js ```js
let settings:PhotoCaptureSetting = { videoOutput.start((err) => {
quality = 1,
rotation = 0
}
photoOutput.capture(settings, (err) => {
if (err) { if (err) {
console.error('Failed to capture the photo ${err.message}'); console.error('Failed to start the video output ${err.message}');
return; return;
} }
console.log('Callback invoked to indicate the photo capture request success.'); console.log('Callback invoked to indicate the video output start success.');
}); });
``` ```
### capture ### start
capture(setting?: PhotoCaptureSetting): Promise<void\> start(): Promise<void\>
根据拍照设置拍照,通过Promise获取结果。 启动录制,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ------- | ------------------------------------------- | ---- | ---------- |
| setting | [PhotoCaptureSetting](#photocapturesetting) | 否 | 拍照设置。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| -------------- | --------------------------- | | -------------- | ----------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 | | Promise<void\> | 使用Promise的方式获取结果。 |
**示例:** **示例:**
```js ```js
photoOutput.capture().then(() => { videoOutput.start().then(() => {
console.log('Promise returned to indicate that photo capture request success.'); console.log('Promise returned to indicate that start method execution success.');
}) })
``` ```
### release ### stop
release(callback: AsyncCallback<void\>): void stop(callback: AsyncCallback<void\>): void
释放PhotoOutput实例,通过注册回调函数获取结果。 结束录制,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
...@@ -2290,465 +4045,465 @@ release(callback: AsyncCallback<void\>): void ...@@ -2290,465 +4045,465 @@ release(callback: AsyncCallback<void\>): void
**示例:** **示例:**
```js ```js
photoOutput.release((err) => { videoOutput.stop((err) => {
if (err) { if (err) {
console.error('Failed to release the PhotoOutput instance ${err.message}'); console.error('Failed to stop the video output ${err.message}');
return; return;
} }
console.log('Callback invoked to indicate that the PhotoOutput instance is released successfully.'); console.log('Callback invoked to indicate the video output stop success.');
}); });
``` ```
### release ### stop
release(): Promise<void\> stop(): Promise<void\>
释放PhotoOutput实例,通过Promise获取结果。 结束录制,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| -------------- | --------------------------- | | -------------- | ----------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 | | Promise<void\> | 使用Promise的方式获取结果。 |
**示例:**
```js
photoOutput.release().then(() => {
console.log('Promise returned to indicate that the PhotoOutput instance is released successfully.');
})
```
### on('captureStart')
on(type: 'captureStart', callback: AsyncCallback<number\>): void
监听拍照启动,通过注册回调函数获取Capture ID。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| :------- | :--------------------- | :--- | :----------------------------------------------- |
| type | string | 是 | 监听事件,固定为'captureStart',即拍照启动事件。 |
| callback | AsyncCallback<number\> | 是 | 使用callback的方式获取Capture ID。 |
**示例:** **示例:**
```js ```js
photoOutput.on('captureStart', (err, captureId) => { videoOutput.stop().then(() => {
console.log('photo capture stated, captureId : ' + captureId); console.log('Promise returned to indicate that stop method execution success.');
}) })
``` ```
### on('frameShutter') ### on('frameStart')
on(type: 'frameShutter', callback: AsyncCallback<FrameShutterInfo\>): void on(type: 'frameStart', callback: AsyncCallback<void\>): void
监听快门,通过注册回调函数获取结果。 监听录像开始,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| :------- | :---------------------------------------------------- | :--- | :--------------------------------------------- | | -------- | -------------------- | ---- | ----------------------------------------- |
| type | string | 是 | 监听事件,固定为'frameShutter',即帧刷新事件。 | | type | string | 是 | 监听事件,固定为'frameStart',即视频帧开启事件。 |
| callback | AsyncCallback<[FrameShutterInfo](#frameshutterinfo)\> | 是 | 回调函数,用于获取相关信息。 | | callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:** **示例:**
```js ```js
photoOutput.on('frameShutter', (err, frameShutterInfo) => { videoOutput.on('frameStart', () => {
console.log('photo capture end, captureId : ' + frameShutterInfo.captureId); console.log('Video frame started');
console.log('Timestamp for frame : ' + frameShutterInfo.timestamp);
}) })
``` ```
### on('captureEnd') ### on('frameEnd')
on(type: 'captureEnd', callback: AsyncCallback<CaptureEndInfo\>): void on(type: 'frameEnd', callback: AsyncCallback<void\>): void
监听拍照停止,通过注册回调函数获取结果。 监听录像结束,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| :------- | :------------------------------------------------ | :--- | :--------------------------------------------- | | -------- | -------------------- | ---- | ------------------------------------------ |
| type | string | 是 | 监听事件,固定为'captureEnd',即拍照停止事件。 | | type | string | 是 | 监听事件,固定为'frameEnd',即视频帧结束事件 。 |
| callback | AsyncCallback<[CaptureEndInfo](#captureendinfo)\> | 是 | 回调函数,用于获取相关信息。 | | callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:** **示例:**
```js ```js
photoOutput.on('captureEnd', (err, captureEndInfo) => { videoOutput.on('frameEnd', () => {
console.log('photo capture end, captureId : ' + captureEndInfo.captureId); console.log('Video frame ended');
console.log('frameCount : ' + captureEndInfo.frameCount);
}) })
``` ```
### on('error') ### on('error')
on(type: 'error', callback: ErrorCallback<PhotoOutputError\>): void on(type: 'error', callback: ErrorCallback<VideoOutputError\>): void
监听拍照的错误事件,通过注册回调函数获取结果。 监听录像输出发生错误,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| :------- | :---------------------------------------------------- | :--- | :---------------------------------------- | | -------- | ------------------------------------------------ | ---- | -------------------------------------- |
| type | string | 是 | 监听事件,固定为'error',即拍照错误事件。 | | type | string | 是 | 监听事件,固定为'error',即视频输出错误事件。 |
| callback | ErrorCallback<[PhotoOutputError](#photooutputerror)\> | 是 | 回调函数,用于获取错误信息。 | | callback | Callback<[VideoOutputError](#videooutputerror)\> | 是 | 回调函数,用于获取错误信息。 |
**示例:** **示例:**
```js ```js
photoOutput.on('error', (err, photoOutputError) => { videoOutput.on('error', (VideoOutputError) => {
console.log('Photo output error code: ' + photoOutputError.code); console.log('Video output error code: ' + VideoOutputError.code);
}) })
``` ```
## FrameShutterInfo ## VideoOutputErrorCode
快门事件信息 枚举,录像输出错误类型
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 类型 | 必填 | 说明 | | 名称 | 值 | 说明 |
| --------- | ------ | ---- | ----------------------------- | | --------------------- | ---- | ------------ |
| captureId | number | 是 | CaptureId,本次拍摄动作的ID。 | | ERROR_UNKNOWN | -1 | 未知错误。 |
| timestamp | number | 是 | 时间戳。 | | ERROR_DRIVER_ERROR | 0 | 驱动或者硬件错误。|
## CaptureEndInfo ## VideoOutputError
拍照停止信息 录像输出错误码
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 说明 |
| ---------- | ------ | ---- | ----------------------------- | | ---- | ------------------------------------- | ----------------------- |
| captureId | number | 是 | CaptureId,本次拍摄动作的ID。 | | code | [PhotoOutputError](#photooutputerror) | VideoOutput中的错误码。 |
| frameCount | number | 是 | 帧计数。 |
## PhotoOutputErrorCode ## MetadataObjectType
枚举,拍照输出的错误码 枚举,metadata流
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 值 | 说明 | | 名称 | 值 | 说明 |
| ------------- | ---- | ---------- | | ------------------------- | ---- | ----------------- |
| ERROR_UNKNOWN | -1 | 未知错误。 | | FACE_DETECTION | 0 | metadata对象类型。 |
## PhotoOutputError ## Rect
拍照输出错误对象 矩形定义
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 类型 | 说明 | | 名称 | 类型 | 说明 |
| ---- | ------------------------------------- | ----------------------- | | -------- | ------ | -------------------- |
| code | [PhotoOutputError](#photooutputerror) | PhotoOutput中的错误码。 | | topLeftX | number | 矩形区域左上角x坐标。 |
| topLeftY | number | 矩形区域左上角y坐标。 |
| width | number | 矩形宽。 |
| height | number | 矩形高。 |
## camera.createVideoOutput ## MetadataObject
createVideoOutput(surfaceId: string, callback: AsyncCallback<VideoOutput\>): void 相机元能力信息,[CameraInput](#camerainput)相机信息中的数据来源。
获取VideoOutput实例,通过注册回调函数获取结果。 ### getType
getType(callback: AsyncCallback<MetadataObjectType\>): void
查询metadata对象类型,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| --------- | ------------------------------------------- | ---- | ----------------------------------- | | -------- | --------------------------------------------------------- | --- | -------------------- |
| surfaceId | string | 是 | 从VideoRecorder获取的Surface ID。 | | callback | AsyncCallback<[MetadataObjectType](#metadataObjectType)\> | 是 | 回调函数,用于获取结果。 |
| callback | AsyncCallback<[VideoOutput](#videooutput)\> | 是 | 回调函数,用于获取VideoOutput实例。 |
**示例:** **示例:**
```js ```js
camera.createVideoOutput(("surfaceId"), (err, videoOutput) => { metadataObject.getType((err, metadataObjectType) => {
if (err) { if (err) {
console.error('Failed to create the VideoOutput instance. ${err.message}'); console.error('Failed to get type. ${err.message}');
return; return;
} }
console.log('Callback returned with the VideoOutput instance'); console.log('Callback returned with an array of metadataObjectType.');
}); })
``` ```
## camera.createVideoOutput ### getType
createVideoOutput(surfaceId: string): Promise<VideoOutput\> getType(): Promise<MetadataObjectType\>
获取VideoOutput实例,通过Promise获取结果。 查询metadata对象类型,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| --------- | ------ | ---- | --------------------------------- |
| surfaceId | string | 是 | 从VideoRecorder获取的Surface ID。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ------------------------------------- | -------------------------------------- | | --------------------------------------------------- | --------------------------- |
| Promise<[VideoOutput](#videooutput)\> | 使用Promise的方式获取VideoOutput实例。 | | Promise<[MetadataObjectType](#metadataObjectType)\> | 使用Promise的方式获取结果。 |
**示例:** **示例:**
```js ```js
camera.createVideoOutput("surfaceId" metadataObject.getType().then((metadataObjectType) => {
).then((videoOutput) => { console.log('Callback returned with an array of metadataObjectType.');
console.log('Promise returned with the VideoOutput instance');
}) })
``` ```
## VideoOutput ### getTimestamp
视频输出类。
### start getTimestamp(callback: AsyncCallback<number\>): void
start(callback: AsyncCallback<void\>): void
开始拍摄视频,通过注册回调函数获取结果。 查询metadata时间戳,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------ | | -------- | ----------------------------------------------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 | | callback | AsyncCallback<number\> | 是 | 回调函数,用于获取结果。 |
**示例:** **示例:**
```js ```js
videoOutput.start((err) => { metadataObject.getTimestamp((err) => {
if (err) { if (err) {
console.error('Failed to start the video output ${err.message}'); console.error('Failed to get timestamp. ${err.message}');
return; return;
} }
console.log('Callback invoked to indicate the video output start success.'); console.log('Callback returned with timestamp getted.');
}); })
``` ```
### start ### getTimestamp
start(): Promise<void\> getTimestamp(): Promise<number\>
开始拍摄视频,通过Promise获取结果。 查询metadata时间戳,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| -------------- | --------------------------- | | ---------------- | --------------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 | | Promise<number)\> | 使用Promise的方式获取结果。 |
**示例:** **示例:**
```js ```js
videoOutput.start().then(() => { metadataObject.getTimestamp().then(() => {
console.log('Promise returned to indicate that start method execution success.'); console.log('Callback returned with timestamp getted.');
}) })
``` ```
### stop ### getBoundingBox
stop(callback: AsyncCallback<void\>): void getBoundingBox(callback: AsyncCallback<Rect\>): void
停止拍摄视频,通过注册回调函数获取结果。 查询metadata的边界框,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------ | | -------- | ----------------------------------------------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 | | callback | AsyncCallback<[Rect](#rect)\> | 是 | 回调函数,用于获取结果。 |
**示例:** **示例:**
```js ```js
videoOutput.stop((err) => { metadataObject.getBoundingBox((err, rect) => {
if (err) { if (err) {
console.error('Failed to stop the video output ${err.message}'); console.error('Failed to get boundingBox. ${err.message}');
return; return;
} }
console.log('Callback invoked to indicate the video output stop success.'); console.log('Callback returned with boundingBox getted.');
}); })
``` ```
### stop ### getBoundingBox
stop(): Promise<void\> getBoundingBox(): Promise<Rect\>
停止拍摄视频,通过Promise获取结果。 查询metadata的边界框,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| -------------- | --------------------------- | | ---------------------- | --------------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 | | Promise<[Rect](#rect)\> | 使用Promise的方式获取结果。 |
**示例:** **示例:**
```js ```js
videoOutput.start().then(() => { metadataObject.getBoundingBox().then((rect) => {
console.log('Promise returned to indicate that stop method execution success.'); console.log('Callback returned with boundingBox getted.');
}) })
``` ```
### release ## MetadataFaceObject
release(callback: AsyncCallback<void\>): void metadata的人脸对象。继承[MetadataObject](#metadataObject)
释放VideoOutput实例,通过注册回调函数获取结果。 ## MetadataOutput
metadata流。继承[CameraOutput](#cameraoutput)
### start
start(callback: AsyncCallback<void\>): void
开始输出metadata,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------ | | -------- | ----------------------------------------------------------- | ---- | ------------------- |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 | | callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:** **示例:**
```js ```js
videoOutput.release((err) => { metadataOutput.start((err) => {
if (err) { if (err) {
console.error('Failed to release the VideoOutput instance ${err.message}'); console.error('Failed to start metadataOutput. ${err.message}');
return; return;
} }
console.log('Callback invoked to indicate that the VideoOutput instance is released successfully.'); console.log('Callback returned with metadataOutput started.');
}); })
``` ```
### release ### start
release(): Promise<void\> start(): Promise<void\>
释放VideoOutput实例,通过Promise获取结果。 开始输出metadata,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| -------------- | --------------------------- | | ---------------------- | ------------------------ |
| Promise<void\> | 使用Promise的方式获取结果。 | | Promise<void\> | 使用Promise的方式获取结果。 |
**示例:** **示例:**
```js ```js
videoOutput.release().then(() => { metadataOutput.start().then(() => {
console.log('Promise returned to indicate that the VideoOutput instance is released successfully.'); console.log('Callback returned with metadataOutput started.');
}) })
``` ```
### on('frameStart') ### stop
on(type: 'frameStart', callback: AsyncCallback<void\>): void stop(callback: AsyncCallback<void\>): void
监听视频帧开启,通过注册回调函数获取结果。 停止输出metadata,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| :------- | :------------------- | :--- | :----------------------------------------------- | | -------- | -------------------------- | ---- | ------------------- |
| type | string | 是 | 监听事件,固定为'frameStart',即视频帧开启事件。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 | | callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:** **示例:**
```js ```js
videoOutput.on('frameStart', () => { metadataOutput.stop((err) => {
console.log('Video frame started'); if (err) {
console.error('Failed to stop the metadataOutput. ${err.message}');
return;
}
console.log('Callback returned with metadataOutput stoped.');
}) })
``` ```
### on('frameEnd') ### stop
on(type: 'frameEnd', callback: AsyncCallback<void\>): void stop(): Promise<void\>
停止输出metadata,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| ---------------------- | --------------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 |
**示例:**
```js
metadataOutput.stop().then(() => {
console.log('Callback returned with metadataOutput stoped.');
})
```
### on('metadataObjectsAvailable')
监听视频帧结束,通过注册回调函数获取结果。 on(type: 'metadataObjectsAvailable', callback: AsyncCallback<Array<MetadataObject\>\>): void
监听检测到的metadata对象,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| :------- | :------------------- | :--- | :--------------------------------------------- | | -------- | ----------------------------------------------- - | ---- | ------------------------------------ |
| type | string | 是 | 监听事件,固定为'frameEnd',即视频帧结束事件。 | | type | string | 是 | 监听事件,固定为'metadataObjectsAvailable',即metadata对象。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 | | callback | Callback<Array<[MetadataObject](#metadataObject)\>\> | 是 | 回调函数,用于获取错误信息。 |
**示例:** **示例:**
```js ```js
videoOutput.on('frameEnd', () => { metadataOutput.on('metadataObjectsAvailable', (metadataObject) => {
console.log('Video frame ended'); console.log('metadata output error code: ' + metadataObject.code);
}) })
``` ```
### on('error') ### on('error')
on(type: 'error', callback: ErrorCallback<VideoOutputError\>): void on(tuype: 'error', callback: ErrorCallback<MetadataOutputError\>): void
监听视频输出的错误事件,通过注册回调函数获取结果。 监听metadata流的错误,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:** **参数:**
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| :------- | :----------------------------------------------- | :--- | :-------------------------------------------- | | -------- | ------------------------------------------------ | ---- | --------------------------------------- |
| type | string | 是 | 监听事件,固定为'error',即视频输出错误事件。 | | type | string | 是 | 监听事件,固定为'error',即metadata流的错误。 |
| callback | Callback<[VideoOutputError](#videooutputerror)\> | 是 | 回调函数,用于获取错误信息。 | | callback | Callback<[MetadataOutputError](#metadataOutputError)\> | 是 | 回调函数,用于获取错误信息。 |
**示例:** **示例:**
```js ```js
videoOutput.on('error', (VideoOutputError) => { metadataOutput.on('error', (metadataOutputError) => {
console.log('Video output error code: ' + VideoOutputError.code); console.log('Metadata output error code: ' + metadataOutputError.code);
}) })
``` ```
## VideoOutputErrorCode ## MetadataOutputErrorCode
枚举,视频输出的错误码 枚举,metadata输出错误类型
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 值 | 说明 | | 名称 | 值 | 说明 |
| ------------- | ---- | ---------- | | ------------------------------- | ---- | -------- |
| ERROR_UNKNOWN | -1 | 未知错误。 | | ERROR_UNKNOWN | -1 | 未知错误。 |
| ERROR_INSUFFICIENT_RESOURCES | 0 | 资源不足。 |
## VideoOutputError ## MetadataOutputError
视频输出错误对象 metadata输出错误码
**系统能力:** SystemCapability.Multimedia.Camera.Core **系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 类型 | 说明 | | 名称 | 类型 | 说明 |
| ---- | ------------------------------------- | ----------------------- | | ---- | ------------------------------------- | ----------------------- |
| code | [PhotoOutputError](#photooutputerror) | VideoOutput中的错误码。 | | code | [MetadataOutputErrorCode](#MetadataOutputErrorCode) | MetadataOutput中的错误码。 |
\ No newline at end of file \ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册