提交 497e3b34 编写于 作者: J jiangminyang

fixed for new apis.

Signed-off-by: Njiangminyang <jiangminyang@huawei.com>
上级 25c7525c
......@@ -78,6 +78,50 @@ camera.getCameraManager(context).then((cameraManager) => {
| CAMERA_STATUS_AVAILABLE | 2 | 相机就绪。 |
| CAMERA_STATUS_UNAVAILABLE | 3 | 相机未就绪。 |
## Profile
相机项。
**系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 类型 | 只读 | 说明 |
| -------- | ------------ |---- | ----------- |
| format | CameraFormat | 是 | 相机编码 |
| size | Size | 是 | 尺寸 |
## FrameRateRange
帧速率范围。
**系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 类型 | 只读 | 说明 |
| ------------------------- | ------ | ---- | ----------- |
| min | number | 是 | 最小速率 |
| max | number | 是 | 最大速率 |
## VideoProfile
视频项。
**系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 类型 | 只读 | 说明 |
| ------------------------- | --------------------- | --- |------------ |
| frameRateRanges | Array<FrameRateRange> | 是 | 帧速率范围 |
## CameraOutputCapability
相机输出能力项。
**系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 类型 | 只读 | 说明 |
| ----------------------------- | ------------------------------------------------- | --- |------------------- |
| previewProfiles | Array<[Profile](#profile)> | 是 | 预览项。 |
| photoProfiles | Array<[Profile](#profile)> | 是 | 照片项。 |
| videoProfiles | Array<[VideoProfile](#videoprofile)> | 是 | 视频项。 |
| supportedMetadataObjectTypes | Array<[MetadataObjectType](#metadataobjecttype)> | 是 | 支持的元能力对象类型。 |
## CameraPosition
......@@ -129,13 +173,35 @@ camera.getCameraManager(context).then((cameraManager) => {
| height | string | 是 | 是 | 图像的高度。 |
| 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 |
| CAMERA_FORMAT_JPEG | 2000 | JPEG |
## CameraManager
相机管理器类,使用前需要通过getCameraManager获取相机管理实例。
### getCameras
### getSupportedCameras
getCameras(callback: AsyncCallback<Array<Camera\>\>): void
getSupportedCameras(callback: AsyncCallback<Array<Camera\>\>): void
异步获取设备支持的相机列表,通过注册回调函数获取结果。
......@@ -150,7 +216,7 @@ getCameras(callback: AsyncCallback<Array<Camera\>\>): void
**示例:**
```js
cameraManager.getCameras((err, cameras) => {
cameraManager.getSupportedCameras((err, cameras) => {
if (err) {
console.error('Failed to get the cameras. ${err.message}');
return;
......@@ -159,9 +225,9 @@ cameraManager.getCameras((err, cameras) => {
})
```
### getCameras
### getSupportedCameras
getCameras(): Promise<Array<Camera\>\>
getSupportedCameras(): Promise<Array<Camera\>\>
异步获取设备支持的相机列表,通过Promise获取结果。
......@@ -177,718 +243,775 @@ getCameras(): Promise<Array<Camera\>\>
**示例:**
```js
cameraManager.getCameras().then((cameraArray) => {
cameraManager.getSupportedCameras().then((cameraArray) => {
console.log('Promise returned with an array of supported cameras: ' + cameraArray.length);
})
```
### createCameraInput
createCameraInput(cameraId: string, callback: AsyncCallback<CameraInput\>): void
### getSupportedOutputCapability
使用相机ID异步创建CameraInput实例,通过注册回调函数获取结果。
getSupportedOutputCapability(camera::CameraDevice, callback: AsyncCallback<CameraOutputCapability>): void
**需要权限:** ohos.permission.CAMERA
获取相机支持的输出能力,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------- | ---- | ----------------------------------- |
| cameraId | string | 是 | 指定相机ID。 |
| callback | AsyncCallback<[CameraInput](#camerainput)\> | 是 | 回调函数,用于获取CameraInput实例。 |
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------------------------------------------------------- | -- | ------------------------------------ |
| camera | [CameraDevice](#CameraDevice) | 是 | 指定相机ID。 |
| callback | AsyncCallback<[CameraOutputCapability](#cameraoutputcapability)> | 是 | 使用callback方式获取相机输出能力。 |
**示例:**
```js
cameraManager.createCameraInput(cameraId, (err, cameraInput) => {
cameraManager.getSupportedOutputCapability(cameraDevice, (err, cameras) => {
if (err) {
console.error('Failed to create the CameraInput instance. ${err.message}');
console.error('Failed to get the cameras. ${err.message}');
return;
}
console.log('Callback returned with the CameraInput instance.');
console.log('Callback returned with an array of supported outputCapability: ' + cameras.length);
})
```
### createCameraInput
createCameraInput(cameraId: string): Promise<CameraInput\>
### getSupportedOutputCapability
使用相机ID异步创建CameraInput实例,通过Promise获取结果。
getSupportedOutputCapability(camera:CameraDevice): Promise<CameraOutputCapability>
**需要权限:** ohos.permission.CAMERA
获取相机支持的输出能力,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ------ | ---- | ------------ |
| cameraId | string | 是 | 指定相机ID。 |
| 名称 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------- | --- | ------------------------------------ |
| camera | [CameraDevice](#CameraDevice) | 是 | 指定相机ID。 |
**返回值:**
| 类型 | 说明 |
| ------------------------------------- | ---------------------------------------- |
| Promise<[CameraInput](#camerainput)\> | 使用Promise的方式获取CameraInput的实例。 |
| 类型 | 说明 |
| -------------------------------------------------------------- | ----------------------------- |
| Promise<[CameraOutputCapability](#cameraoutputcapability)> | 使用Promise的方式获取结果,返回相机输出能力。 |
**示例:**
```js
cameraManager.createCameraInput(cameraId).then((cameraInput) => {
console.log('Promise returned with the CameraInput instance');
cameraManager.getSupportedOutputCapability(cameraDevice).then((cameraoutputcapability) => {
console.log('Promise returned with an array of supported outputCapability: ' + cameraArray.length);
})
```
### createCameraInput
createCameraInput(position: CameraPosition, type: CameraType, callback: AsyncCallback<CameraInput\>): void
### isCameraMuted
使用相机位置和相机类型异步创建CameraInput实例,通过注册回调函数获取结果。
isCameraMuted(callback: AsyncCallback<boolean\>): void
**需要权限:** ohos.permission.CAMERA
确认相机是否禁用,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------- | ---- | ----------------------------------- |
| position | [CameraPosition](#cameraposition) | 是 | 相机位置。 |
| type | [CameraType](#cameratype) | 是 | 相机类型。 |
| callback | AsyncCallback<[CameraInput](#camerainput)\> | 是 | 回调函数,用于获取CameraInput实例。 |
| 名称 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------- | ---- | ------------------------------------ |
| callback | AsyncCallback<boolean\> | 是 | 使用callback方式获取相机是否禁用的结果。 |
**示例:**
```js
cameraManager.createCameraInput(camera.CameraPosition.CAMERA_POSITION_BACK, camera.CameraType.CAMERA_TYPE_UNSPECIFIED, (err, cameraInput) => {
cameraManager.isCameraMuted((err, status) => {
if (err) {
console.error('Failed to create the CameraInput instance. ${err.message}');
console.error('Failed to get the cameraMuted status. ${err.message}');
return;
}
console.log('Callback returned with the CameraInput instance');
console.log('Callback returned with cameraMuted status');
})
```
### createCameraInput
createCameraInput(position: CameraPosition, type: CameraType): Promise<CameraInput\>
### isCameraMuted
使用相机位置和相机类型异步创建CameraInput实例,通过Promise获取结果。
isCameraMuted(): Promise<boolean>
**需要权限:** ohos.permission.CAMERA
确认相机是否禁用,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | --------------------------------- | ---- | ---------- |
| position | [CameraPosition](#cameraposition) | 是 | 相机位置。 |
| type | [CameraType](#cameratype) | 是 | 相机类型。 |
**返回值:**
| 类型 | 说明 |
| ------------------------------------- | ---------------------------------------- |
| Promise<[CameraInput](#camerainput)\> | 使用Promise的方式获取CameraInput的实例。 |
| 类型 | 说明 |
| ------------------------------------ | --------------------------------------------- |
| Promise<boolean\> | 使用Promise的方式获取结果,返回相机是否禁用的结果。 |
**示例:**
```js
cameraManager.createCameraInput(camera.CameraPosition.CAMERA_POSITION_BACK, camera.CameraType.CAMERA_TYPE_UNSPECIFIED).then((cameraInput) => {
console.log('Promise returned with the CameraInput instance.');
cameraManager.isCameraMuted().then((status) => {
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
监听相机的状态变化,通过注册回调函数获取相机的状态变化
确认是否支持相机禁用,通过注册回调函数获取结果
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| :------- | :---------------------------------------------------- | :--- | :--------------------------------------------------- |
| type | string | 是 | 监听事件,固定为'cameraStatus',即相机状态变化事件。 |
| callback | AsyncCallback<[CameraStatusInfo](#camerastatusinfo)\> | 是 | 回调函数,用于获取相机状态变化信息。 |
| 名称 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ------------------------------------ |
| callback | AsyncCallback<boolean\> | 是 | 使用callback方式获取是否支持相机禁用的结果。 |
**示例:**
```js
cameraManager.on('cameraStatus', (err, cameraStatusInfo) => {
cameraManager.isCameraMuteSupported((err, status) => {
if (err) {
console.error('Failed to get cameraStatus callback. ${err.message}');
console.error('Failed to get the cameraMuteSupported. ${err.message}');
return;
}
console.log('camera : ' + cameraStatusInfo.camera.cameraId);
console.log('status: ' + cameraStatusInfo.status);
console.log('Callback returned with the status whether cameraMuteSupported.');
})
```
## Camera
调用[camera.getCameraManager](#cameragetcameramanager)后,将返回Camera实例,包括相机ID、位置、类型、连接类型等相机相关的元数据。
**系统能力:** SystemCapability.Multimedia.Camera.Core。
| 名称 | 类型 | 只读 | 说明 |
| -------------- | --------------------------------- | ---- | -------------- |
| cameraId | string | 是 | 相机ID。 |
| cameraPosition | [CameraPosition](#cameraposition) | 是 | 相机位置。 |
| cameraType | [CameraType](#cameratype) | 是 | 相机类型。 |
| connectionType | [ConnectionType](#connectiontype) | 是 | 相机连接类型。 |
**示例:**
### isCameraMuteSupported
```js
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;
}
```
isCameraMuteSupported(): Promise<boolean\>
## CameraStatusInfo
确认是否支持相机禁用,通过Promise获取结果。
相机管理器回调返回的接口实例,表示相机状态信息。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**系统能力:** SystemCapability.Multimedia.Camera.Core。
**返回值:**
| 名称 | 类型 | 说明 |
| ------ | ----------------------------- | ---------- |
| camera | [Camera](#camera) | 相机信息。 |
| status | [CameraStatus](#camerastatus) | 相机状态。 |
| 类型 | 说明 |
| --------------------- | ----------------------------- |
| Promise<boolean\> | 使用Promise的方式获取结果,返回是否支持相机禁用的结果。 |
## CameraInput
**示例:**
相机输入类。在使用该类的方法前,需要先构建一个CameraInput实例。
```js
cameraManager.isCameraMuteSupported().then((status) => {
console.log('Promise returned with the status whether cameraMuteSupported.');
})
```
### getCameraId
### muteCamera
getCameraId(callback: AsyncCallback<string\>\): void
muteCamera(mute:boolean, callback: AsyncCallback<void>): void
异步获取该CameraInput实例的相机ID,通过注册回调函数获取结果。
禁用相机,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ---------------------- | ---- | -------------------------- |
| callback | AsyncCallback<string\> | 是 | 回调函数,用于获取相机ID。 |
| 名称 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------- | ---- | ------------------------------------ |
| mute | boolean | 是 | 是否禁用相机。 |
| callback | AsyncCallback<void> | 是 | 使用callback方式获取相机禁用的结果。 |
**示例:**
```js
cameraInput.getCameraId((err, cameraId) => {
cameraManager.muteCamera(isMuted, (err) => {
if (err) {
console.error('Failed to get the camera ID. ${err.message}');
console.error('Failed to mute the camera. ${err.message}');
return;
}
console.log('Callback returned with the camera ID: ' + cameraId);
console.log('Callback returned with the muteCamera.');
})
```
### getCameraId
### muteCamera
getCameraId(): Promise<string\>
muteCamera(mute:boolean): Promise<void\>
异步获取该CameraInput实例的相机ID,通过Promise获取结果。
禁用相机,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------- | ---- | ------------ |
| mute | boolean | 是 | 是否禁用相机。 |
**返回值:**
| 类型 | 说明 |
| ---------------- | ----------------------------- |
| Promise<string\> | 使用Promise的方式获取相机ID。 |
| 类型 | 说明 |
| ----------------------------------- | ----------------------------- |
| Promise<void> | 使用Promise的方式获取结果,返回是否禁用相机的结果。 |
**示例:**
```js
cameraInput.getCameraId().then((cameraId) => {
console.log('Promise returned with the camera ID:' + cameraId);
cameraManager.muteCamera(isMuted).then(() => {
console.log('Promise returned muteCamera.');
})
```
### createCameraInput
### hasFlash
createCameraInput(camera: CameraDevice, callback: AsyncCallback<CameraInput\>): void
hasFlash(callback: AsyncCallback<boolean\>): void
使用相机ID异步创建CameraInput实例,通过注册回调函数获取结果。
判断设备是否支持闪光灯,通过注册回调函数获取结果。
**需要权限:** ohos.permission.CAMERA
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- |
| callback | AsyncCallback<boolean\> | 是 | 回调函数,返回true表示设备支持闪光灯。 |
| 名称 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------- | ---- | ----------------------------------- |
| camera | [CameraDevice](#CameraDevice) | 是 | 指定相机ID。 |
| callback | AsyncCallback<[CameraInput](#camerainput)\> | 是 | 回调函数,用于获取CameraInput实例。 |
**示例:**
```js
cameraInput.hasFlash((err, status) => {
cameraManager.createCameraInput(camera, (err, cameraInput) => {
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;
}
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\>
判断设备是否支持闪光灯,通过Promise获取结果。
使用相机ID异步创建CameraInput实例,通过Promise获取结果。
**需要权限:** ohos.permission.CAMERA
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ----------------------------- | ---- | ------------ |
| camera | [CameraDevice](#CameraDevice) | 是 | 指定相机ID。 |
**返回值:**
| 类型 | 说明 |
| ----------------- | ------------------------------------------------------- |
| Promise<boolean\> | 使用Promise的方式获取结果,返回true表示设备支持闪光灯。 |
| 类型 | 说明 |
| ------------------------------------- | ---------------------------------------- |
| Promise<[CameraInput](#camerainput)\> | 使用Promise的方式获取CameraInput的实例。 |
**示例:**
```js
cameraInput.hasFlash().then((status) => {
console.log('Promise returned with the flash light support status:' + status);
cameraManager.createCameraInput(camera).then((cameraInput) => {
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
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| --------- | ----------------------- | ---- | ---------------------------------------- |
| flashMode | [FlashMode](#flashmode) | 是 | 指定闪光灯模式。 |
| callback | AsyncCallback<boolean\> | 是 | 回调函数,返回true表示支持该闪光灯模式。 |
| 名称 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------- | ---- | ----------------------------------- |
| position | [CameraPosition](#cameraposition) | 是 | 相机位置。 |
| type | [CameraType](#cameratype) | 是 | 相机类型。 |
| callback | AsyncCallback<[CameraInput](#camerainput)\> | 是 | 回调函数,用于获取CameraInput实例。 |
**示例:**
```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) {
console.error('Failed to check whether the flash mode is supported. ${err.message}');
console.error('Failed to create the CameraInput instance. ${err.message}');
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\>
### createPreviewOutput
判断设备是否支持指定闪光灯模式,通过Promise获取结果。
createPreviewOutput(profile: Profile, surfaceId: string, callback: AsyncCallback<PreviewOutput>): void
创建PreviewOutput实例,通过注册回调函数获取结果。
**需要权限:** ohos.permission.CAMERA
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| --------- | ----------------------- | ---- | ---------------- |
| flashMode | [FlashMode](#flashmode) | 是 | 指定闪光灯模式。 |
| 名称 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------------- | ---- | ------------------------------- |
| profile | [Profile](#profile) | 是 | 相机项。 |
| surfaceId| string | 是 | surface的id。 |
| callback | AsyncCallback<[PreviewOutput](#previewoutput)> | 是 | 回调函数,用于获取PreviewOutput实例。|
**示例:**
```js
cameraManager.createPreviewOutput(profile, surfaceId, (err, previewoutput) => {
if (err) {
console.error('Failed to gcreate previewOutput. ${err.message}');
return;
}
console.log('Callback returned with previewOutput created.');
})
```
### createPreviewOutput
createPreviewOutput(profile: Profile, surfaceId: string): Promise<PreviewOutput>
创建PreviewOutput实例,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------| ---- | ---------- |
| profile | [Profile](#profile) | 是 | 相机项。 |
| surfaceId| string | 是 | surface的id。 |
**返回值:**
| 类型 | 说明 |
| ----------------- | ------------------------------------------------------------ |
| Promise<boolean\> | 使用Promise的方式获取结果,返回true表示设备支持该闪光灯模式。 |
| 类型 | 说明 |
| ---------------------------------------- | ---------------------------------------- |
| Promise<[PreviewOutput](#previewoutput)> | 使用Promise的方式获取PreviewOutput的实例。 |
**示例:**
```js
cameraInput.isFlashModeSupported(camera.FlashMode.FLASH_MODE_AUTO).then((status) => {
console.log('Promise returned with flash mode support status.' + status);
cameraManager.createPreviewOutput(profile, survaceId).then((previewoutput) => {
console.log('Promise returned with previewOutput created.');
})
```
### setFlashMode
setFlashMode(flashMode: FlashMode, callback: AsyncCallback<void\>): void
设置闪光灯模式,通过注册回调函数获取结果。
### createDeferredPreviewOutput
进行设置之前,需要先检查:
createDeferredPreviewOutput(profile: Profile, callback: AsyncCallback<PreviewOutput>): void
1. 设备是否支持闪光灯,可使用方法[hasFlash](#hasflash)
2. 设备是否支持指定的闪光灯模式,可使用方法[isFlashModeSupported](#isflashmodesupported)
创建默认PreviewOutput实例,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| --------- | ----------------------- | ---- | ------------------------ |
| flashMode | [FlashMode](#flashmode) | 是 | 指定闪光灯模式。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
| 名称 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------------- | ---- | ----------------------------------- |
| profile | [Profile](#profile) | 是 | 相机项。 |
| callback | AsyncCallback<[PreviewOutput](#previewoutput)> | 是 | 回调函数,用于获取PreviewOutput实例。 |
**示例:**
```js
cameraInput.setFlashMode(camera.FlashMode.FLASH_MODE_AUTO, (err) => {
cameraManager.createDeferredPreviewOutput(profile, (err, previewoutput) => {
if (err) {
console.error('Failed to set the flash mode ${err.message}');
console.error('Failed to create deferredPreviewOutput. ${err.message}');
return;
}
console.log('Callback returned with the successful execution of setFlashMode.');
console.log('Callback returned with deferredPreviewOutput created.');
})
```
### setFlashMode
setFlashMode(flashMode: FlashMode): Promise<void\>
设置闪光灯模式,通过Promise获取结果。
### createDeferredPreviewOutput
进行设置之前,需要先检查:
createDeferredPreviewOutput(profile: Profile): Promise<PreviewOutput>
1. 设备是否支持闪光灯,可使用方法[hasFlash](#hasflash)
2. 设备是否支持指定的闪光灯模式,可使用方法[isFlashModeSupported](#isflashmodesupported)
创建默认PreviewOutput实例,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| --------- | ----------------------- | ---- | ---------------- |
| flashMode | [FlashMode](#flashmode) | 是 | 指定闪光灯模式。 |
| 名称 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------| ---- | ---------- |
| profile | [Profile](#profile) | 是 | 相机项。 |
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 |
| 类型 | 说明 |
| ----------------------------------------- | ---------------------------------------- |
| Promise<[PreviewOutput](#previewoutput)> | 使用Promise的方式获取PreviewOutput的实例。 |
**示例:**
```js
cameraInput.setFlashMode(camera.FlashMode.FLASH_MODE_AUTO).then(() => {
console.log('Promise returned with the successful execution of setFlashMode.');
cameraManager.createDeferredPreviewOutput(profile).then((previewoutput) => {
console.log('Promise returned with DefeerredPreviewOutput created.');
})
```
### getFlashMode
### createPhotoOutput
getFlashMode(callback: AsyncCallback<FlashMode\>): void
createPhotoOutput(profile: Profile, surfaceId: string, callback: AsyncCallback<PhotoOutput>): void
获取当前设备的闪光灯模式,通过注册回调函数获取结果。
创建PhotoOutput实例,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------------------------------------- |
| callback | AsyncCallback<[FlashMode](#flashmode)\> | 是 | 回调函数,用于获取当前设备的闪光灯模式。 |
| 名称 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------- | ---- | ----------------------------------- |
| profile | [Profile](#profile) | 是 | 相机项。 |
| surfaceId| string | 是 | surface的id。 |
| callback | AsyncCallback<[PhotoOutput](#photooutput)> | 是 | 回调函数,用于获取PhotoOutput实例。 |
**示例:**
```js
cameraInput.getFlashMode((err, flashMode) => {
cameraManager.createPhotoOutput(profile, surfaceId, (err, photooutput) => {
if (err) {
console.error('Failed to get the flash mode ${err.message}');
console.error('Failed to create photoOutput. ${err.message}');
return;
}
console.log('Callback returned with current flash mode: ' + flashMode);
console.log('Callback returned with photoOutput created.');
})
```
### getFlashMode
### createPhotoOutput
getFlashMode(): Promise<FlashMode\>
createPhotoOutput(profile: Profile, surfaceId: string): Promise<PreviewOutput>
获取当前设备的闪光灯模式,通过Promise获取结果。
创建PhotoOutput实例,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------| ---- | ----------- |
| profile | [Profile](#profile) | 是 | 相机项。 |
| surfaceId| string | 是 | surface的id。|
**返回值:**
| 类型 | 说明 |
| --------------------------------- | --------------------------------------- |
| Promise<[FlashMode](#flashmode)\> | 使用Promise的方式获取当前的闪光灯模式。 |
| 类型 | 说明 |
| ------------------------------------- | ---------------------------------------- |
| Promise<[PhotoOutput](#photooutput)> | 使用Promise的方式获取PhotoOutput的实例。 |
**示例:**
```js
cameraInput.getFlashMode().then((flashMode) => {
console.log('Promise returned with current flash mode : ' + flashMode);
cameraManager.createPhotoOutput(profile, surfaceId).then((photooutput) => {
console.log('Promise returned with photoOutput created.');
})
```
### isFocusModeSupported
### createVideoOutput
isFocusModeSupported(afMode: FocusMode, callback: AsyncCallback<boolean\>): void
createVideoOutput(profile: VideoProfile, surfaceId: string, callback: AsyncCallback<VideoOutput>): void
判断设备是否支持指定的焦距模式,通过注册回调函数获取结果。
创建VideoOutput实例,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- |
| afMode | [FocusMode](#focusmode) | 是 | 指定的焦距模式。 |
| callback | AsyncCallback<boolean\> | 是 | 回调函数,返回true表示支持该焦距模式。 |
| 名称 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------- | ---- | ------------------------------ |
| profile | [VideoProfile](#videoprofile) | 是 | 视频项。 |
| surfaceId| string | 是 | surface的id。 |
| callback | AsyncCallback<[VideoOutput](#videooutput)> | 是 | 回调函数,用于获取VideoOutput实例。 |
**示例:**
```js
cameraInput.isFocusModeSupported(camera.FocusMode.FOCUS_MODE_AUTO, (err, status) => {
cameraManager.createVideoOutput(profile, surfaceId, (err, videooutput) => {
if (err) {
console.error('Failed to check whether the focus mode is supported. ${err.message}');
console.error('Failed to create videoOutput. ${err.message}');
return;
}
console.log('Callback returned with the focus mode support status: ' + status);
console.log('Callback returned with an array of supported outputCapability: ' + cameras.length);
})
```
### isFocusModeSupported
### createVideoOutput
isFocusModeSupported(afMode: FocusMode): Promise<boolean\>
createVideoOutput(profile: VideoProfile, surfaceId: string): Promise<VideoOutput>
判断设备是否支持指定的焦距模式,通过Promise获取结果。
创建VideoOutput实例,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ------ | ----------------------- | ---- | ---------------- |
| afMode | [FocusMode](#focusmode) | 是 | 指定的焦距模式。 |
| 名称 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------| ---- | ---------- |
| profile | [VideoProfile](#videoprofile) | 是 | 视频项。 |
| surfaceId| string | 是 | surface的id。|
**返回值:**
| 类型 | 说明 |
| ----------------- | ----------------------------------------------------------- |
| Promise<boolean\> | 使用Promise的方式获取结果,返回true表示设备支持该焦距模式。 |
| 类型 | 说明 |
| ------------------------------------- | ---------------------------------------- |
| Promise<[VideoOutput](#videooutput)> | 使用Promise的方式获取PhotoOutput的实例。 |
**示例:**
```js
cameraInput.isFocusModeSupported(camera.FocusMode.FOCUS_MODE_AUTO).then((status) => {
console.log('Promise returned with focus mode support status.' + status);
cameraManager.createVideoOutput(profile, surfaceId).then((videooutput) => {
console.log('Promise returned with videoOutput created.');
})
```
### setFocusMode
setFocusMode(afMode: FocusMode, callback: AsyncCallback<void\>): void
### createMetadataOutput
设置焦距模式,通过注册回调函数获取结果。
createMetadataOutput(metadataObjectTypes: Array<MetadataObjectType>, callback: AsyncCallback<MetadataOutput>): void
进行设置之前,需要先检查设备是否支持指定的焦距模式,可使用方法[isFocusModeSupported](#isfocusmodesupported)
创建MetadataOutput实例,通过注册回调函数获取结果
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | ------------------------ |
| afMode | [FocusMode](#focusmode) | 是 | 指定的焦距模式。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
| 名称 | 类型 | 必填 | 说明 |
| -------------------- | ------------------------------------------------- | --- | ----------------------------- |
| metadataObjectTypes | Array<[MetadataObjectType](#metadataobjecttype)> | 是 | 元能力类型。 |
| callback | AsyncCallback<[MetadataOutput](#metadataoutput)> | 是 | 回调函数,用于获取元能力实例。 |
**示例:**
```js
cameraInput.setFocusMode(camera.FocusMode.FOCUS_MODE_AUTO, (err) => {
cameraManager.createMetadataOutput(metadataObjectTypes, (err, metadataoutput) => {
if (err) {
console.error('Failed to set the focus mode ${err.message}');
console.error('Failed to create metadataOutput. ${err.message}');
return;
}
console.log('Callback returned with the successful execution of setFocusMode.');
console.log('Callback returned with metadataOutput created.');
})
```
### setFocusMode
setFocusMode(afMode: FocusMode): Promise<void\>
### createMetadataOutput
设置焦距模式,通过Promise获取结果。
createMetadataOutput(metadataObjectTypes: Array<MetadataObjectType>): Promise<MetadataOutput>
进行设置之前,需要先检查设备是否支持指定的焦距模式,可使用方法[isFocusModeSupported](#isfocusmodesupported)
创建MetadataOutput实例,通过Promise获取结果
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ------ | ----------------------- | ---- | ---------------- |
| afMode | [FocusMode](#focusmode) | 是 | 指定的焦距模式。 |
| 名称 | 类型 | 必填 | 说明 |
| -------------------- | ------------------------------------------------- | --- | ---------- |
| metadataObjectTypes | Array<[MetadataObjectType](#metadataobjecttype)> | 是 | 元能力类型。 |
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 |
| 类型 | 说明 |
| ------------------------------------------ | ---------------------------------------- |
| Promise<[MetadataOutput](#metadataoutput)> | 使用Promise的方式获取MetadataOutput的实例。 |
**示例:**
```js
cameraInput.setFocusMode(camera.FocusMode.FOCUS_MODE_AUTO).then(() => {
console.log('Promise returned with the successful execution of setFocusMode.');
cameraManager.createMetadataOutput(metadataObjectTypes).then((metadataoutput) => {
console.log('Promise returned with metadataOutput created.');
})
```
### getFocusMode
### createCaptureSession
getFocusMode(callback: AsyncCallback<FocusMode\>): void
createCaptureSession(callback: AsyncCallback<CaptureSession>): void
获取当前设备的焦距模式,通过注册回调函数获取结果。
创建CaptureSession实例,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | -------------------------------------- |
| callback | AsyncCallback<[FocusMode](#focusmode)\> | 是 | 回调函数,用于获取当前设备的焦距模式。 |
| 名称 | 类型 | 必填 | 说明 |
| -------------------- | ------------------------------------------------- | ---- | ----------------------------------- |
| callback | AsyncCallback<[CaptureSession](#capturesession)> | 是 | 回调函数,用于获取拍照会话实例。 |
**示例:**
```js
cameraInput.getFocusMode((err, afMode) => {
cameraManager.createCaptureSession((err, capturesession) => {
if (err) {
console.error('Failed to get the focus mode ${err.message}');
console.error('Failed to create captureSession. ${err.message}');
return;
}
console.log('Callback returned with current focus mode: ' + afMode);
console.log('Callback returned with captureSession created.');
})
```
### getFocusMode
### createCaptureSession
getFocusMode(): Promise<FocusMode\>
createCaptureSession(): Promise<CaptureSession>
获取当前设备的焦距模式,通过Promise获取结果。
创建CaptureSession实例,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| ------------------- | ------------------------------------- |
| Promise<FocusMode\> | 使用Promise的方式获取当前的焦距模式。 |
| 类型 | 说明 |
| ------------------------------------------- | ---------------------------------------- |
| Promise<[CaptureSession](#capturesession)> | 使用Promise的方式获取CaptureSession的实例。 |
**示例:**
```js
cameraInput.getFocusMode().then((afMode) => {
console.log('Promise returned with current focus mode : ' + afMode);
cameraManager.createCaptureSession().then((capturesession) => {
console.log('Promise returned with captureSession created.');
})
```
### getZoomRatioRange
### on('cameraStatus')
getZoomRatioRange\(callback: AsyncCallback<Array<number\>\>\): void
on(type: 'cameraStatus', callback: AsyncCallback<CameraStatusInfo\>): void
获取可变焦距比范围,通过注册回调函数获取结果
监听相机的状态变化,通过注册回调函数获取相机的状态变化
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ------------------------------ | ---- | ------------------------ |
| callback | AsyncCallback<Array<number\>\> | 是 | 回调函数,用于获取结果。 |
| 名称 | 类型 | 必填 | 说明 |
| :------- | :---------------------------------------------------- | :--- | :--------------------------------------------------- |
| type | string | 是 | 监听事件,固定为'cameraStatus',即相机状态变化事件。 |
| callback | AsyncCallback<[CameraStatusInfo](#camerastatusinfo)\> | 是 | 回调函数,用于获取相机状态变化信息。 |
**示例:**
```js
cameraInput.getZoomRatioRange((err, zoomRatioRange) => {
cameraManager.on('cameraStatus', (err, cameraStatusInfo) => {
if (err) {
console.error('Failed to get the zoom ratio range. ${err.message}');
console.error('Failed to get cameraStatus callback. ${err.message}');
return;
}
console.log('Callback returned with zoom ratio range: ' + zoomRatioRange.length);
console.log('camera : ' + cameraStatusInfo.camera.cameraId);
console.log('status: ' + cameraStatusInfo.status);
})
```
### getZoomRatioRange
### on('cameraMute')
getZoomRatioRange\(\): Promise<Array<number\>\>
on(type: 'cameraMute', callback: AsyncCallback<boolean>): void
获取可变焦距比范围,通过Promise获取结果
监听相机禁用的状态变化,通过注册回调函数获取相机的状态变化
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
**参数:**
| 类型 | 说明 |
| ------------------------ | ------------------------------------------- |
| Promise<Array<number\>\> | 使用Promise的方式获取当前的可变焦距比范围。 |
| 名称 | 类型 | 必填 | 说明 |
| :------- | :---------------------------------------------------- | :--- | :--------------------------------------------------- |
| type | string | 是 | 监听事件,固定为'cameraMute',即相机状态变化事件。 |
| callback | AsyncCallback<boolean> | 是 | 回调函数,用于获取相机状态变化信息。 |
**示例:**
```js
cameraInput.getZoomRatioRange().then((zoomRatioRange) => {
console.log('Promise returned with zoom ratio range: ' + zoomRatioRange.length);
cameraManager.on('cameraMute', (err, status) => {
if (err) {
console.error('Failed to get cameraMute callback. ${err.message}');
return;
}
console.log('status: ' + status);
})
```
### setZoomRatio
## CameraDevice
setZoomRatio(zoomRatio: number, callback: AsyncCallback<void\>): void
调用[camera.getCameraManager](#cameragetcameramanager)后,将返回Camera实例,包括相机ID、位置、类型、连接类型等相机相关的元数据。
设置可变焦距比,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core。
| 名称 | 类型 | 只读 | 说明 |
| -------------- | --------------------------------- | ---- | -------------- |
| cameraId | string | 是 | 相机ID。 |
| cameraPosition | [CameraPosition](#cameraposition) | 是 | 相机位置。 |
| cameraType | [CameraType](#cameratype) | 是 | 相机类型。 |
| connectionType | [ConnectionType](#connectiontype) | 是 | 相机连接类型。 |
**示例:**
```js
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
相机管理器回调返回的接口实例,表示相机状态信息。
**系统能力:** SystemCapability.Multimedia.Camera.Core。
| 名称 | 类型 | 说明 |
| ------ | ----------------------------- | ---------- |
| camera | [CameraDevice](#CameraDevice) | 相机信息。 |
| status | [CameraStatus](#camerastatus) | 相机状态。 |
## CameraInput
相机输入类。在使用该类的方法前,需要先构建一个CameraInput实例。
### open
open\(callback: AsyncCallback<void\>\): void
打开相机,通过注册回调函数获取状态。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| --------- | -------------------- | ---- | ------------------------ |
| zoomRatio | number | 是 | 可变焦距比。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```js
cameraInput.setZoomRatio(1, (err) => {
cameraInput.open((err) => {
if (err) {
console.error('Failed to set the zoom ratio value ${err.message}');
console.error('Failed to open the camera. ${err.message}');
return;
}
console.log('Callback returned with the successful execution of setZoomRatio.');
console.log('Callback returned with camera opened.');
})
```
### setZoomRatio
### open
setZoomRatio(zoomRatio: number): Promise<void\>
open(): Promise<void\>
设置可变焦距比,通过Promise获取结果
打开相机,通过Promise获取相机的状态
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| --------- | ------ | ---- | ------------ |
| zoomRatio | number | 是 | 可变焦距比。 |
**返回值:**
| 类型 | 说明 |
......@@ -898,56 +1021,56 @@ setZoomRatio(zoomRatio: number): Promise<void\>
**示例:**
```js
cameraInput.setZoomRatio(1).then(() => {
console.log('Promise returned with the successful execution of setZoomRatio.');
cameraInput.open().then(() => {
console.log('Promise returned with camera opened.');
})
```
### getZoomRatio
### close
getZoomRatio(callback: AsyncCallback<number\>): void
close\(callback: AsyncCallback<void\>\): void
获取当前的可变焦距比,通过注册回调函数获取结果
关闭相机,通过注册回调函数获取状态
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ---------------------- | ---- | ------------------------ |
| callback | AsyncCallback<number\> | 是 | 回调函数,用于获取结果。 |
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```js
cameraInput.getZoomRatio((err, zoomRatio) => {
cameraInput.close((err) => {
if (err) {
console.error('Failed to get the zoom ratio ${err.message}');
console.error('Failed to close the cameras. ${err.message}');
return;
}
console.log('Callback returned with current zoom ratio: ' + zoomRatio);
console.log('Callback returned with camera closed.');
})
```
### getZoomRatio
### close
getZoomRatio(): Promise<number\>
close(): Promise<void\>
获取当前的可变焦距比,通过Promise获取结果
关闭相机,通过Promise获取状态
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| ---------------- | --------------------------- |
| Promise<number\> | 使用Promise的方式获取结果。 |
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 |
**示例:**
```js
cameraInput.getZoomRatio().then((zoomRatio) => {
console.log('Promise returned with current zoom ratio : ' + zoomRatio);
cameraInput.close().then(() => {
console.log('Promise returned with camera closed.');
})
```
......@@ -999,29 +1122,6 @@ cameraInput.release().then(() => {
})
```
### 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('error')
on(type: 'error', callback: ErrorCallback<CameraInputError\>): void
......@@ -1051,9 +1151,14 @@ cameraInput.on('error', (cameraInputError) => {
**系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 值 | 说明 |
| ------------- | ---- | ---------- |
| ERROR_UNKNOWN | -1 | 未知错误。 |
| 名称 | 值 | 说明 |
| ------------------------- | ---- | ---------- |
| ERROR_UNKNOWN | -1 | 未知错误。 |
| ERROR_NO_PERMISSION | | |
| ERROR_DEVICE_PREEMPTED | | |
| ERROR_DEVICE_DISCONNECTED | | |
| ERROR_DEVICE_IN_USE | | |
| ERROR_DRIVER_ERROR | | |
## CameraInputError
......@@ -1079,6 +1184,18 @@ CameraInput错误对象。
| FLASH_MODE_AUTO | 2 | 自动闪光灯。 |
| FLASH_MODE_ALWAYS_OPEN | 3 | 闪光灯常亮。 |
## ExposuerMode
枚举,曝光模式。
**系统能力:** SystemCapability.Multimedia.Camera.Core。
| 名称 | 值 | 说明 |
| ----------------------------- | ---- | ------------ |
| EXPOSURE_MODE_LOCKED | 0 | 锁定曝光模式。 |
| EXPOSURE_MODE_AUTO | 1 | 自动曝光模式。 |
| EXPOSURE_MODE_CONTINUOUS_AUTO | 2 | 连续自动曝光。 |
## FocusMode
枚举,焦距模式。
......@@ -1104,64 +1221,34 @@ CameraInput错误对象。
| FOCUS_STATE_FOCUSED | 1 | 相机已对焦。 |
| FOCUS_STATE_UNFOCUSED | 2 | 相机未对焦。 |
## camera.createCaptureSession
## ExposureState
createCaptureSession\(context: Context, callback: AsyncCallback<CaptureSession\>\): void
枚举,曝光状态。
获取CaptureSession实例,通过注册回调函数获取结果
**系统能力:** SystemCapability.Multimedia.Camera.Core
**系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 值 | 说明 |
| ------------------------- | ---- | ------------ |
| EXPOSURE_STATE_SCAN | 0 | 扫描状态。 |
| EXPOSURE_STATE_CONVERGED | 1 | 聚焦状态。 |
**参数:**
## VideoStabilizationMode
| 名称 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------- | ---- | -------------------------------------- |
| context | Context | 是 | 应用上下文。 |
| callback | AsyncCallback<[CaptureSession](#capturesession)\> | 是 | 回调函数,用于获取CaptureSession实例。 |
枚举,视频防抖模式。
**示例:**
**系统能力:** SystemCapability.Multimedia.Camera.Core。
```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);
});
```
| 名称 | 值 | 说明 |
| --------- | ---- | ------------ |
| OFF | 0 | 关闭视频防抖。 |
| LOW | 1 | 使用基础防抖运算。 |
| MIDDLE | 2 | 使用常规防抖效果的运算。 |
| HIGH | 3 | 使用最佳防抖效果的运算。 |
| AUTO | 4 | 自动。 |
## camera.createCaptureSession
## CaptureSession
createCaptureSession(context: Context\): Promise<CaptureSession\>;
获取CaptureSession实例,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ------- | ------- | ---- | ------------ |
| context | Context | 是 | 应用上下文。 |
**返回值:**
| 类型 | 说明 |
| ------------------------------------------- | ----------------------------------------- |
| Promise<[CaptureSession](#capturesession)\> | 使用Promise的方式获取CaptureSession实例。 |
**示例:**
```js
camera.createCaptureSession(context).then((captureSession) => {
console.log('Promise returned with the CaptureSession instance');
})
```
## CaptureSession
拍照会话类。
拍照会话类。
### beginConfig
......@@ -1260,11 +1347,11 @@ captureSession.commitConfig().then(() => {
})
```
### addInput
### canAddInput
addInput\(cameraInput: CameraInput, callback: AsyncCallback<void\>\): void
canAddInput(cameraInput: CameraInput, callback: AsyncCallback<boolean>): void
在当前会话中,添加一个CameraInput实例,通过注册回调函数获取结果。
可以加入相机输入,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
......@@ -1273,25 +1360,25 @@ addInput\(cameraInput: CameraInput, callback: AsyncCallback<void\>\): void
| 名称 | 类型 | 必填 | 说明 |
| ----------- | --------------------------- | ---- | --------------------------- |
| cameraInput | [CameraInput](#camerainput) | 是 | 需要添加的CameraInput实例。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
| callback | AsyncCallback<boolean\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```js
captureSession.addInput(cameraInput, (err) => {
CaptureSession.canAddInput(cameraInput, (err, status) => {
if (err) {
console.error('Failed to add the CameraInput instance. ${err.message}');
console.error('Can not add cameraInput. ${err.message}');
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获取结果。
可以加入相机输入,通过注Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
......@@ -1305,56 +1392,56 @@ addInput\(cameraInput: CameraInput\): Promise<void\>
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 |
| Promise<boolean> | 使用Promise的方式获取结果。 |
**示例:**
```js
captureSession.addInput(cameraInput).then(() => {
console.log('Promise used to indicate that the CameraInput instance is added.');
captureSession.canAddInput(cameraInput).then(() => {
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实例,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ------------- | ------------------------------- | ---- | ----------------------------- |
| previewOutput | [PreviewOutput](#previewoutput) | 是 | 需要添加的PreviewOutput实例。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
| 名称 | 类型 | 必填 | 说明 |
| ----------- | --------------------------- | ---- | --------------------------- |
| cameraInput | [CameraInput](#camerainput) | 是 | 需要添加的CameraInput实例。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```js
captureSession.addOutput(previewOutput, (err) => {
captureSession.addInput(cameraInput, (err) => {
if (err) {
console.error('Failed to add the PreviewOutput instance ${err.message}');
console.error('Failed to add the CameraInput instance. ${err.message}');
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实例,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ------------- | ------------------------------- | ---- | ----------------------------- |
| previewOutput | [PreviewOutput](#previewoutput) | 是 | 需要添加的PreviewOutput实例。 |
| 名称 | 类型 | 必填 | 说明 |
| ----------- | --------------------------- | ---- | --------------------------- |
| cameraInput | [CameraInput](#camerainput) | 是 | 需要添加的CameraInput实例。 |
**返回值:**
......@@ -1365,16 +1452,16 @@ addOutput\(previewOutput: PreviewOutput\): Promise<void\>
**示例:**
```js
captureSession.addOutput(previewOutput).then(() => {
console.log('Promise used to indicate that the PreviewOutput instance is added.');
captureSession.addInput(cameraInput).then(() => {
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实例,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
......@@ -1382,26 +1469,26 @@ addOutput\(photoOutput: PhotoOutput, callback: AsyncCallback<void\>\): void
| 名称 | 类型 | 必填 | 说明 |
| ----------- | --------------------------- | ---- | --------------------------- |
| photoOutput | [PhotoOutput](#photooutput) | 是 | 需要添加的PhotoOutput实例。 |
| cameraInput | [CameraInput](#camerainput) | 是 | 需要移除的CameraInput实例。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```js
captureSession.addOutput(photoOutput, (err) => {
captureSession.removeInput(cameraInput, (err) => {
if (err) {
console.error('Failed to add the PhotoOutput instance ${err.message}');
console.error('Failed to remove the CameraInput instance. ${err.message}');
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实例,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
......@@ -1409,7 +1496,7 @@ addOutput\(photoOutput: PhotoOutput\): Promise<void\>
| 名称 | 类型 | 必填 | 说明 |
| ----------- | --------------------------- | ---- | --------------------------- |
| photoOutput | [PhotoOutput](#photooutput) | 是 | 需要添加的PhotoOutput实例。 |
| cameraInput | [CameraInput](#camerainput) | 是 | 需要移除的CameraInput实例。 |
**返回值:**
......@@ -1420,126 +1507,128 @@ addOutput\(photoOutput: PhotoOutput\): Promise<void\>
**示例:**
```js
captureSession.addOutput(photoOutput).then(() => {
console.log('Promise used to indicate that the PhotoOutput instance is added.');
captureSession.removeInput(cameraInput).then(() => {
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实例,通过注册回调函数获取结果。
可以加入相机输出,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ----------- | --------------------------- | ---- | --------------------------- |
| videoOutput | [VideoOutput](#videooutput) | 是 | 需要添加的VideoOutput实例。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
| 名称 | 类型 | 必填 | 说明 |
| ------------- | ------------------------------- | ---- | ----------------------------- |
| cameraOutput | [CameraOutput](#CameraOutput) | 是 | 需要移除的CameraOutput实例。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```js
captureSession.addOutput(videoOutput, (err) => {
captureSession.canAddOutput(cameraOutput, (err, status) => {
if (err) {
console.error('Failed to add the VideoOutput instance ${err.message}');
console.error('Can not add cameraOutput. ${err.message}');
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获取结果。
可以加入相机输出,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ----------- | --------------------------- | ---- | --------------------------- |
| videoOutput | [VideoOutput](#videooutput) | 是 | 需要添加的VideoOutput实例。 |
| 名称 | 类型 | 必填 | 说明 |
| ------------- | ------------------------------- | ---- | ----------------------------- |
| cameraOutput | [CameraOutput](#CameraOutput) | 是 | 需要移除的CameraOutput实例。 |
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise\<void> | 使用Promise的方式获取结果。 |
| Promise<boolean> | 使用Promise的方式获取结果。 |
**示例:**
```js
captureSession.addOutput(videoOutput).then(() => {
console.log('Promise used to indicate that the VideoOutput instance is added.');
captureSession.canAddOutput(cameraOutput).then(() => {
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实例,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ----------- | --------------------------- | ---- | --------------------------- |
| cameraInput | [CameraInput](#camerainput) | 是 | 需要移除的CameraInput实例。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
| 名称 | 类型 | 必填 | 说明 |
| ------------- | ------------------------------- | ---- | ----------------------------- |
| cameraOutput | [CameraOutput](#cameraOutput) | 是 | 需要添加的CameraOutput实例。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```js
captureSession.removeInput(cameraInput, (err) => {
captureSession.addOutput(cameraOutput, (err) => {
if (err) {
console.error('Failed to remove the CameraInput instance. ${err.message}');
console.error('Failed to add output. ${err.message}');
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实例,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ----------- | --------------------------- | ---- | --------------------------- |
| cameraInput | [CameraInput](#camerainput) | 是 | 需要移除的CameraInput实例。 |
| 名称 | 类型 | 必填 | 说明 |
| ------------- | ------------------------------- | ---- | ----------------------------- |
| cameraOutput | [CameraOutput](#cameraOutput) | 是 | 需要添加的CameraOutput实例。 |
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise\<void> | 使用Promise的方式获取结果。 |
| Promise<void\> | 使用Promise的方式获取结果。 |
**示例:**
```js
captureSession.removeInput(cameraInput).then(() => {
console.log('Promise returned to indicate that the cameraInput instance is removed.');
captureSession.addOutput(cameraOutput).then(() => {
console.log('Promise returned with cameraOutput added.');
})
```
### removeOutput
removeOutput\(previewOutput: PreviewOutput, callback: AsyncCallback<void\>\): void
removeOutput\(cameraOutput: CameraOutput, callback: AsyncCallback<void\>\): void
在当前会话中,移除一个PreviewOutput实例,通过注册回调函数获取结果。
在当前会话中,移除一个CameraOutput实例,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
......@@ -1547,26 +1636,26 @@ removeOutput\(previewOutput: PreviewOutput, callback: AsyncCallback<void\>\): vo
| 名称 | 类型 | 必填 | 说明 |
| ------------- | ------------------------------- | ---- | ----------------------------- |
| previewOutput | [PreviewOutput](#previewoutput) | 是 | 需要移除的PreviewOutput实例。 |
| cameraOutput | [CameraOutput](#cameraOutput) | 是 | 需要移除的CameraOutput实例。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```js
captureSession.removeOutput(previewOutput, (err) => {
captureSession.removeOutput(cameraOutput, (err) => {
if (err) {
console.error('Failed to remove the PreviewOutput instance. ${err.message}');
console.error('Failed to remove the CameraOutput instance. ${err.message}');
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(previewOutput: PreviewOutput): Promise<void\>
removeOutput(cameraOutput: CameraOutput): Promise<void\>
在当前会话中,移除一个PreviewOutput实例,通过Promise获取结果。
在当前会话中,移除一个CameraOutput实例,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
......@@ -1574,7 +1663,7 @@ removeOutput(previewOutput: PreviewOutput): Promise<void\>
| 名称 | 类型 | 必填 | 说明 |
| ------------- | ------------------------------- | ---- | ----------------------------- |
| previewOutput | [PreviewOutput](#previewoutput) | 是 | 需要移除的PreviewOutput实例。 |
| cameraOutput | [CameraOutput](#cameraOutput) | 是 | 需要移除的CameraOutput实例。 |
**返回值:**
......@@ -1587,130 +1676,112 @@ removeOutput(previewOutput: PreviewOutput): Promise<void\>
**示例:**
```js
captureSession.removeOutput(previewOutput).then(() => {
console.log('Promise returned to indicate that the PreviewOutput instance is removed.');
captureSession.removeOutput(cameraOutput).then(() => {
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
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ----------- | --------------------------- | ---- | --------------------------- |
| photoOutput | [PhotoOutput](#photooutput) | 是 | 需要移除的PhotoOutput实例。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```js
captureSession.removeOutput(photoOutput, (err) => {
captureSession.start((err) => {
if (err) {
console.error('Failed to remove the PhotoOutput instance. ${err.message}');
console.error('Failed to start the session ${err.message}');
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
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ----------- | --------------------------- | ---- | --------------------------- |
| photoOutput | [PhotoOutput](#photooutput) | 是 | 需要移除的PhotoOutput实例。 |
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 |
**示例:**
```js
captureSession.removeOutput(photoOutput).then(() => {
console.log('Promise returned to indicate that the PhotoOutput instance is removed.');
captureSession.start().then(() => {
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
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ----------- | --------------------------- | ---- | --------------------------- |
| videoOutput | [VideoOutput](#videooutput) | 是 | 需要移除的VideoOutput实例。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```js
captureSession.removeOutput(videoOutput, (err) => {
captureSession.stop((err) => {
if (err) {
console.error('Failed to remove the VideoOutput instance. ${err.message}');
console.error('Failed to stop the session ${err.message}');
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
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ----------- | --------------------------- | ---- | --------------------------- |
| videoOutput | [VideoOutput](#videooutput) | 是 | 需要移除的VideoOutput实例。 |
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 |
**示例:**
```js
captureSession.removeOutput(videoOutput).then(() => {
console.log('Promise returned to indicate that the VideoOutput instance is removed.');
captureSession.stop().then(() => {
console.log('Promise returned to indicate the session stop success.');
})
```
### start
### lockForControl
start\(callback: AsyncCallback<void\>\): void
lockForControl(callback: AsyncCallback<void>): void;
启动拍照会话,通过注册回调函数获取结果。
线程上锁,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
......@@ -1723,20 +1794,20 @@ start\(callback: AsyncCallback<void\>\): void
**示例:**
```js
captureSession.start((err) => {
captureSession.lockForControl((err) => {
if (err) {
console.error('Failed to start the session ${err.message}');
console.error('Failed to lock. ${err.message}');
return;
}
console.log('Callback invoked to indicate the session start success.');
});
console.log('Locked.');
})
```
### start
### lockForControl
start\(\): Promise<void\>
lockForControl(): Promise<void>;
启动拍照会话,通过Promise获取结果。
线程上锁,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
......@@ -1749,22 +1820,21 @@ start\(\): Promise<void\>
**示例:**
```js
captureSession.start().then(() => {
console.log('Promise returned to indicate the session start success.');
captureSession.lockForControl().then(() => {
console.log('Locked.');
})
```
### stop
### unlockForControl
stop\(callback: AsyncCallback<void\>\): void
unlockForControl(callback: AsyncCallback<void>): void;
停止拍照会话,通过注册回调函数获取结果。
线程解锁,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
......@@ -1772,20 +1842,20 @@ stop\(callback: AsyncCallback<void\>\): void
**示例:**
```js
captureSession.stop((err) => {
captureSession.unlockForControl((err) => {
if (err) {
console.error('Failed to stop the session ${err.message}');
console.error('Failed to unlock. ${err.message}');
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
......@@ -1798,8 +1868,8 @@ stop(): Promise<void\>
**示例:**
```js
captureSession.stop().then(() => {
console.log('Promise returned to indicate the session stop success.');
captureSession.unlockForControl().then(() => {
console.log('Unlocked.');
})
```
......@@ -1851,413 +1921,2019 @@ captureSession.release().then(() => {
})
```
### on('error')
### hasFlash
on(type: 'error', callback: ErrorCallback<CaptureSessionError\>): void
hasFlash(callback: AsyncCallback<boolean\>): void
监听拍照会话的错误事件,通过注册回调函数获取结果。
判断设备是否支持闪光灯,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| :------- | :---------------------------------------------------------- | :--- | :-------------------------------------------- |
| type | string | 是 | 监听事件,固定为'error',即拍照会话错误事件。 |
| callback | ErrorCallback<[CaptureSessionError](#capturesessionerror)\> | 是 | 回调函数,用于获取错误信息。 |
| 名称 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- |
| callback | AsyncCallback<boolean\> | 是 | 回调函数,返回true表示设备支持闪光灯。 |
**示例:**
```js
captureSession.on('error', (captureSessionError) => {
console.log('Capture session error code: ' + captureSessionError.code);
cameraInput.hasFlash((err, status) => {
if (err) {
console.error('Failed to check whether the device has flash light. ${err.message}');
return;
}
console.log('Callback returned with flash light support status: ' + status);
})
```
## CaptureSessionErrorCode
### hasFlash
枚举,拍照会话的错误码。
hasFlash(): Promise<boolean\>
**系统能力:** SystemCapability.Multimedia.Camera.Core
判断设备是否支持闪光灯,通过Promise获取结果。
| 名称 | 值 | 说明 |
| ------------- | ---- | ---------- |
| ERROR_UNKNOWN | -1 | 未知错误。 |
**系统能力:** SystemCapability.Multimedia.Camera.Core
## CaptureSessionError
**返回值:**
拍照会话错误对象。
| 类型 | 说明 |
| ----------------- | ------------------------------------------------------- |
| Promise<boolean\> | 使用Promise的方式获取结果,返回true表示设备支持闪光灯。 |
**系统能力:** SystemCapability.Multimedia.Camera.Core
**示例:**
| 名称 | 类型 | 说明 |
| ---- | ------------------------------------------- | -------------------------- |
| code | [CaptureSessionError](#capturesessionerror) | CaptureSession中的错误码。 |
```js
cameraInput.hasFlash().then((status) => {
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
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| --------- | ----------------------------------------------- | ---- | ------------------------------------- |
| surfaceId | string | 是 | 从XComponent组件获取的Surface ID。 |
| callback | AsyncCallback<[PreviewOutput](#previewoutput)\> | 是 | 回调函数,用于获取PreviewOutput实例。 |
| 名称 | 类型 | 必填 | 说明 |
| --------- | ----------------------- | ---- | ---------------------------------------- |
| flashMode | [FlashMode](#flashmode) | 是 | 指定闪光灯模式。 |
| callback | AsyncCallback<boolean\> | 是 | 回调函数,返回true表示支持该闪光灯模式。 |
**示例:**
```js
camera.createPreviewOutput(("surfaceId"), (err, previewOutput) => {
cameraInput.isFlashModeSupported(camera.FlashMode.FLASH_MODE_AUTO, (err, status) => {
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;
}
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
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| --------- | ------ | ---- | ---------------------------------- |
| surfaceId | string | 是 | 从XComponent组件获取的Surface ID。 |
| 名称 | 类型 | 必填 | 说明 |
| --------- | ----------------------- | ---- | ---------------- |
| flashMode | [FlashMode](#flashmode) | 是 | 指定闪光灯模式。 |
**返回值:**
| 类型 | 说明 |
| ----------------------------------------- | --------------------------- |
| Promise<[PreviewOutput](#previewoutput)\> | 使用Promise的方式获取结果。 |
| 类型 | 说明 |
| ----------------- | ------------------------------------------------------------ |
| Promise<boolean\> | 使用Promise的方式获取结果,返回true表示设备支持该闪光灯模式。 |
**示例:**
```js
camera.createPreviewOutput("surfaceId").then((previewOutput) => {
console.log('Promise returned with the PreviewOutput instance');
cameraInput.isFlashModeSupported(camera.FlashMode.FLASH_MODE_AUTO).then((status) => {
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
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
| 名称 | 类型 | 必填 | 说明 |
| --------- | ----------------------- | ---- | ------------------------ |
| flashMode | [FlashMode](#flashmode) | 是 | 指定闪光灯模式。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```js
previewOutput.release((err) => {
cameraInput.setFlashMode(camera.FlashMode.FLASH_MODE_AUTO, (err) => {
if (err) {
console.error('Failed to release the PreviewOutput instance ${err.message}');
console.error('Failed to set the flash mode ${err.message}');
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\>
释放PreviewOutput实例,通过Promise获取结果。
设置闪光灯模式,通过Promise获取结果。
进行设置之前,需要先检查:
1. 设备是否支持闪光灯,可使用方法[hasFlash](#hasflash)
2. 设备是否支持指定的闪光灯模式,可使用方法[isFlashModeSupported](#isflashmodesupported)
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| --------- | ----------------------- | ---- | ---------------- |
| flashMode | [FlashMode](#flashmode) | 是 | 指定闪光灯模式。 |
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 |
**示例:**
```js
previewOutput.release().then(() => {
console.log('Promise returned to indicate that the PreviewOutput instance is released successfully.');
cameraInput.setFlashMode(camera.FlashMode.FLASH_MODE_AUTO).then(() => {
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
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| :------- | :------------------- | :--- | :------------------------------------------- |
| type | string | 是 | 监听事件,固定为'frameStart',即帧启动事件。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
| 名称 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------------------------------------- |
| callback | AsyncCallback<[FlashMode](#flashmode)\> | 是 | 回调函数,用于获取当前设备的闪光灯模式。 |
**示例:**
```js
previewOutput.on('frameStart', () => {
console.log('Preview frame started');
cameraInput.getFlashMode((err, flashMode) => {
if (err) {
console.error('Failed to get the flash mode ${err.message}');
return;
}
console.log('Callback returned with current flash mode: ' + flashMode);
})
```
### on('frameEnd')
### getFlashMode
on(type: 'frameEnd', callback: AsyncCallback<void\>): void
getFlashMode(): Promise<FlashMode\>
监听预览帧结束,通过注册回调函数获取结果。
获取当前设备的闪光灯模式,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
**返回值:**
| 名称 | 类型 | 必填 | 说明 |
| :------- | :------------------- | :--- | :----------------------------------------- |
| type | string | 是 | 监听事件,固定为'frameEnd',即帧结束事件。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
| 类型 | 说明 |
| --------------------------------- | --------------------------------------- |
| Promise<[FlashMode](#flashmode)\> | 使用Promise的方式获取当前的闪光灯模式。 |
**示例:**
```js
previewOutput.on('frameEnd', () => {
console.log('Preview frame ended');
cameraInput.getFlashMode().then((flashMode) => {
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
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| :------- | :----------------------------------------------------------- | :--- | :-------------------------------------------- |
| type | string | 是 | 监听事件,固定为'error',即预览输出错误事件。 |
| callback | ErrorCallback<[PreviewOutputErrorCode](#previewoutputerrorcode)\> | 是 | 回调函数,用于获取错误信息。 |
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------------------| ---- | ---------------------------------------- |
| aeMode | [ExposureMode](#exposuremode) | 是 | 曝光模式。 |
| callback | AsyncCallback<boolean\> | 是 | 回调函数,用于获取是否支持曝光模式。 |
**示例:**
```js
previewOutput.on('error', (previewOutputError) => {
console.log('Preview output error code: ' + previewOutputError.code);
cameraInput.isExposureModeSupported(camera.ExposureMode.EXPOSURE_MODE_LOCKEN,(err) => {
if (err) {
console.log('Failed to check exposure mode supported ${err.message}');
return ;
}
console.log('Callback returned with the successful excution of isExposureModeSupported');
})
```
## PreviewOutputErrorCode
### isExposureModeSupported
枚举,预览输出的错误码。
isExposureModeSupported(aeMode: ExposureMode): Promise<boolean\>;
检查是否支持曝光模式,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 值 | 说明 |
| ------------- | ---- | ---------- |
| ERROR_UNKNOWN | -1 | 未知错误。 |
**返回值:**
## PreviewOutputError
| 名称 | 说明 |
| ----------------- |---------------------------------------- |
| 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
| 名称 | 类型 | 说明 |
| ---- | ------------------------------------------------- | ---------------------- |
| code | [PreviewOutputErrorCode](#previewoutputerrorcode) | PreviewOutput中的错误码。 |
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------------------| ---- | ---------------------------------------- |
| callback | AsyncCallback<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获取结果。
## camera.createPhotoOutput
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 名称 | 说明 |
| ---------------------- |---------------------------------------- |
| Promise<void\> | 使用Promise的方式获取当前曝光模式。 |
**示例:**
```js
cameraInput.getExposureMode().then((exposureMode) => {
console.log('Promise returned with current exposure mode : ' + exposureMode);
})
```
createPhotoOutput(surfaceId: string, callback: AsyncCallback<PhotoOutput\>): void
### setExposureMode
获取PhotoOutput实例,通过注册回调函数获取结果。
setExposureMode(aeMode: ExposureMode, callback: AsyncCallback<void\>): void;
设置曝光模式,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| --------- | ------------------------------------------- | ---- | ----------------------------------- |
| surfaceId | string | 是 | 从[ImageReceiver](js-apis-image.md#imagereceiver9)获取的Surface ID。 |
| callback | AsyncCallback<[PhotoOutput](#photooutput)\> | 是 | 回调函数,用于获取PhotoOutput实例。 |
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------------------| ---- | ---------------------------------------- |
| aeMode | [ExposureMode](#exposuremode) | 是 | 曝光模式。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取设置结果。 |
**示例:**
```js
camera.createPhotoOutput(("surfaceId"), (err, photoOutput) => {
cameraInput.setExposureMode(camera.ExposureMode.EXPOSURE_MODE_LOCKEN,(err) => {
if (err) {
console.error('Failed to create the PhotoOutput instance. ${err.message}');
return;
console.log('Failed to set the exposure mode ${err.message}');
return ;
}
console.log('Callback returned with the PhotoOutput instance.');
});
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.');
})
```
## camera.createPhotoOutput
### getMeteringPoint
createPhotoOutput(surfaceId: string): Promise<PhotoOutput\>
getMeteringPoint(callback: AsyncCallback<point\>): void;
获取PhotoOutput实例,通过Promise获取结果。
获取当前曝光点,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| --------- | ------ | ---- | --------------------------------- |
| surfaceId | string | 是 | 从[ImageReceiver](js-apis-image.md#imagereceiver9)获取的Surface ID。 |
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------------------| ---- | ---------------------------------------- |
| 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<[PhotoOutput](#photooutput)\> | 使用Promise的方式获取PhotoOutput实例。 |
| 名称 | 说明 |
| ------------------------- |---------------------------------------- |
| Promise<[Point](#point)\> | 使用Promise的方式获取当前曝光点。 |
**示例:**
```js
camera.createPhotoOutput("surfaceId").then((photoOutput) => {
console.log('Promise returned with PhotoOutput instance');
cameraInput.getMeteringPoint().then((exposurePoint) => {
console.log('Promise returned with current exposure point : ' + exposurePoint);
})
```
## ImageRotation
枚举,图片旋转角度。
### setMeteringPoint
setMeteringPoint(point: Point, callback: AsyncCallback<point\>): void;
设置曝光中心点,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 值 | 说明 |
| ------------ | ---- | --------------- |
| ROTATION_0 | 0 | 图片旋转0度。 |
| ROTATION_90 | 90 | 图片旋转90度。 |
| ROTATION_180 | 180 | 图片旋转180度。 |
| ROTATION_270 | 270 | 图片旋转270度。 |
**参数:**
## QualityLevel
| 名称 | 类型 | 必填 | 说明 |
| ------------- | -------------------------------| ---- | ---------------------------------------- |
| exposurePoint | [Point](#point) | 是 | 曝光点。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
枚举,图片质量。
**示例:**
**系统能力:** SystemCapability.Multimedia.Camera.Core
```js
var Point1 = {x: 1, y: 1};
| 名称 | 值 | 说明 |
| -------------------- | ---- | -------------- |
| QUALITY_LEVEL_HIGH | 0 | 图片质量高。 |
| QUALITY_LEVEL_MEDIUM | 1 | 图片质量中等。 |
| QUALITY_LEVEL_LOW | 2 | 图片质量差。 |
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
## PhotoCaptureSetting
setMeteringPoint(point: Point): Promise<void\>;
拍摄照片的设置
设置曝光中心点,通过Promise获取结果
**系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 类型 | 必填 | 说明 |
| -------- | ------------------------------- | ---- | -------------- |
| quality | [QualityLevel](#qualitylevel) | 否 | 图片质量。 |
| rotation | [ImageRotation](#imagerotation) | 否 | 图片旋转角度。 |
**返回值:**
| 名称 | 说明 |
| ----------------- |---------------------------------------- |
| Promise<void\> | 使用Promise的方式返回结果。 |
## PhotoOutput
**示例:**
照片输出类。
```js
var Point2 = {x: 2, y: 2};
### capture
cameraInput.setMeteringPoint(Point2).then(() => {
console.log('Promise returned with the successful execution of setMeteringPoint');
})
```
capture(callback: AsyncCallback<void\>): void
### getExposureBiasRange
拍照,通过注册回调函数获取结果。
getExposureBiasRange(callback: AsyncCallback<Array<number\>>): void;
获取曝光补偿范围,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------------------| ---- | ---------------------------------------- |
| callback | AsyncCallback<Array<number\>> | 是 | 回调函数,用于获取补偿范围的数组。 |
**示例:**
```js
photoOutput.capture((err) => {
cameraInput.getExposureBiasRange((err, biasRangeArray) => {
if (err) {
console.error('Failed to capture the photo ${err.message}');
return;
console.log('Failed to get the array of compenstation range ${err.message}');
return ;
}
console.log('Callback invoked to indicate the photo capture request success.');
});
console.log('Callback returned with the array of compenstation range: ' + JSON.stringify(biasRangeArray));
})
```
### capture
### getExposureBiasRange
capture(setting: PhotoCaptureSetting, callback: AsyncCallback<void\>): void
getExposureBiasRange(): Promise<Array<number>>;
根据拍照设置拍照,通过注册回调函数获取结果。
检查是否支持曝光模式,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
**返回值:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------- | ---- | ------------------------ |
| setting | [PhotoCaptureSetting](#photocapturesetting) | 是 | 拍照设置。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
| 名称 | 说明 |
| ----------------- |---------------------------------------- |
| Promise<boolean\> | 使用Promise的方式获取支持的曝光模式。 |
**示例:**
```js
let settings:PhotoCaptureSetting = {
quality = 1,
rotation = 0
}
photoOutput.capture(settings, (err) => {
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;
设置曝光决定,通过注册回调函数获取结果。
**系统能力:** 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获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 名称 | 说明 |
| ----------------- |---------------------------------------- |
| 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((errpoint) => {
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<VideoStabilizationMode\> | 使用Promise的方式获取结果,返回设置的视频防抖模式的结果。 |
**示例:**
```js
captureSession.setVideoStabilizationMode(camera.VideoStabilizationMode.OFF).then((vsMode) => {
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 | | |
| ERROR_TIMEOUT | | |
## CaptureSessionError
拍照会话错误对象。
**系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 类型 | 说明 |
| ---- | ------------------------------------------- | -------------------------- |
| code | [CaptureSessionError](#capturesessionerror) | CaptureSession中的错误码。 |
## CameraOutput
预览输出类。
### release
release(callback: AsyncCallback<void\>): void
释放PreviewOutput实例,通过注册回调函数获取结果。
**系统能力:** 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\>
释放PreviewOutput实例,通过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;
加入延迟surface,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------ |
| surfaceId| string | 是 | surface的id。 |
| 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>;
加入延迟surface,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| 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
枚举,预览输出的错误码。
**系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 值 | 说明 |
| ------------- | ---- | ---------- |
| ERROR_UNKNOWN | -1 | 未知错误。 |
### PreviewOutputError
预览输出错误对象。
**系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 类型 | 说明 |
| ---- | ------------------------------------------------- | ---------------------- |
| code | [PreviewOutputErrorCode](#previewoutputerrorcode) | PreviewOutput中的错误码。 |
## 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) | 否 | 图片质量。 |
| rotation | [ImageRotation](#imagerotation) | 否 | 图片旋转角度。 |
| location | [Location](#location) | 否 | |
| mirror | [boolean] | 否 | |
## PhotoOutput
照片输出类。
### getDefaultCaptureSetting
getDefaultCaptureSetting(callback: AsyncCallback<PhotoCaptureSetting>): void;
获取默认的拍照设置,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------------------------- | ---- | ------------------------ |
| callback | AsyncCallback<[PhotoCaptureSetting](#photocapturesetting)\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```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
let settings:PhotoCaptureSetting = {
quality = 1,
rotation = 0
}
photoOutput.capture(settings, (err) => {
if (err) {
console.error('Failed to capture the photo ${err.message}');
return;
}
console.log('Callback invoked to indicate the photo capture request success.');
});
```
### capture
capture(setting?: PhotoCaptureSetting): Promise<void\>
根据拍照设置拍照,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ------- | ------------------------------------------- | ---- | ---------- |
| setting | [PhotoCaptureSetting](#photocapturesetting) | 否 | 拍照设置。 |
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 |
**示例:**
```js
photoOutput.capture().then(() => {
console.log('Promise returned to indicate that photo capture request success.');
})
```
### isMirrorSupported
isMirrorSupported(callback: AsyncCallback<boolean\>): void;
询问是否支持自拍,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------- | ---- | -------------------------------------- |
| 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
**返回值:**
| 类型 | 说明 |
| ----------------- | ----------------------------------------------------------- |
| 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
快门事件信息。
**系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 类型 | 必填 | 说明 |
| --------- | ------ | ---- | ----------------------------- |
| captureId | number | 是 | CaptureId,本次拍摄动作的ID。 |
| timestamp | number | 是 | 时间戳。 |
## CaptureEndInfo
拍照停止信息。
**系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 类型 | 必填 | 说明 |
| ---------- | ------ | ---- | ----------------------------- |
| captureId | number | 是 | CaptureId,本次拍摄动作的ID。 |
| frameCount | number | 是 | 帧计数。 |
## PhotoOutputErrorCode
枚举,拍照输出的错误码。
**系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 值 | 说明 |
| ----------------------------- | ---- | ---------- |
| ERROR_UNKNOWN | -1 | 未知错误。 |
| ERROR_DRIVER_ERROR | | |
| ERROR_INSUFFICIENT_RESOURCES | | |
| ERROR_TIMEOUT | | |
## PhotoOutputError
拍照输出错误对象。
**系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 类型 | 说明 |
| ---- | ------------------------------------- | ----------------------- |
| code | [PhotoOutputError](#photooutputerror) | PhotoOutput中的错误码。 |
## VideoOutput
视频输出类。
### start
start(callback: AsyncCallback<void\>): void
开始拍摄视频,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```js
videoOutput.start((err) => {
if (err) {
console.error('Failed to capture the photo ${err.message}');
console.error('Failed to start the video output ${err.message}');
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
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ------- | ------------------------------------------- | ---- | ---------- |
| setting | [PhotoCaptureSetting](#photocapturesetting) | 否 | 拍照设置。 |
**返回值:**
| 类型 | 说明 |
......@@ -2268,16 +3944,16 @@ capture(setting?: PhotoCaptureSetting): Promise<void\>
**示例:**
```js
photoOutput.capture().then(() => {
console.log('Promise returned to indicate that photo capture request success.');
videoOutput.start().then(() => {
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
......@@ -2290,20 +3966,20 @@ release(callback: AsyncCallback<void\>): void
**示例:**
```js
photoOutput.release((err) => {
videoOutput.stop((err) => {
if (err) {
console.error('Failed to release the PhotoOutput instance ${err.message}');
console.error('Failed to stop the video output ${err.message}');
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
......@@ -2313,406 +3989,405 @@ release(): Promise<void\>
| -------------- | --------------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 |
**示例:**
```js
photoOutput.release().then(() => {
console.log('Promise returned to indicate that the PhotoOutput instance is released successfully.');
videoOutput.stop().then(() => {
console.log('Promise returned to indicate that stop method execution success.');
})
```
### on('captureStart')
### on('frameStart')
on(type: 'captureStart', callback: AsyncCallback<number\>): void
on(type: 'frameStart', callback: AsyncCallback<void\>): void
监听拍照启动,通过注册回调函数获取Capture ID
监听视频帧开启,通过注册回调函数获取结果
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| :------- | :--------------------- | :--- | :----------------------------------------------- |
| type | string | 是 | 监听事件,固定为'captureStart',即拍照启动事件。 |
| callback | AsyncCallback<number\> | 是 | 使用callback的方式获取Capture ID。 |
| 名称 | 类型 | 必填 | 说明 |
| :------- | :------------------- | :--- | :----------------------------------------------- |
| type | string | 是 | 监听事件,固定为'frameStart',即视频帧开启事件。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```js
photoOutput.on('captureStart', (err, captureId) => {
console.log('photo capture stated, captureId : ' + captureId);
videoOutput.on('frameStart', () => {
console.log('Video frame started');
})
```
### on('frameShutter')
### on('frameEnd')
on(type: 'frameShutter', callback: AsyncCallback<FrameShutterInfo\>): void
on(type: 'frameEnd', callback: AsyncCallback<void\>): void
监听快门,通过注册回调函数获取结果。
监听视频帧结束,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| :------- | :---------------------------------------------------- | :--- | :--------------------------------------------- |
| type | string | 是 | 监听事件,固定为'frameShutter',即帧刷新事件。 |
| callback | AsyncCallback<[FrameShutterInfo](#frameshutterinfo)\> | 是 | 回调函数,用于获取相关信息。 |
| 名称 | 类型 | 必填 | 说明 |
| :------- | :------------------- | :--- | :--------------------------------------------- |
| type | string | 是 | 监听事件,固定为'frameEnd',即视频帧结束事件。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```js
photoOutput.on('frameShutter', (err, frameShutterInfo) => {
console.log('photo capture end, captureId : ' + frameShutterInfo.captureId);
console.log('Timestamp for frame : ' + frameShutterInfo.timestamp);
videoOutput.on('frameEnd', () => {
console.log('Video frame ended');
})
```
### on('captureEnd')
### on('error')
on(type: 'captureEnd', callback: AsyncCallback<CaptureEndInfo\>): void
on(type: 'error', callback: ErrorCallback<VideoOutputError\>): void
监听拍照停止,通过注册回调函数获取结果。
监听视频输出的错误事件,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| :------- | :------------------------------------------------ | :--- | :--------------------------------------------- |
| type | string | 是 | 监听事件,固定为'captureEnd',即拍照停止事件。 |
| callback | AsyncCallback<[CaptureEndInfo](#captureendinfo)\> | 是 | 回调函数,用于获取相关信息。 |
| 名称 | 类型 | 必填 | 说明 |
| :------- | :----------------------------------------------- | :--- | :-------------------------------------------- |
| type | string | 是 | 监听事件,固定为'error',即视频输出错误事件。 |
| callback | Callback<[VideoOutputError](#videooutputerror)\> | 是 | 回调函数,用于获取错误信息。 |
**示例:**
```js
photoOutput.on('captureEnd', (err, captureEndInfo) => {
console.log('photo capture end, captureId : ' + captureEndInfo.captureId);
console.log('frameCount : ' + captureEndInfo.frameCount);
videoOutput.on('error', (VideoOutputError) => {
console.log('Video output error code: ' + VideoOutputError.code);
})
```
### on('error')
on(type: 'error', callback: ErrorCallback<PhotoOutputError\>): void
### VideoOutputErrorCode
监听拍照的错误事件,通过注册回调函数获取结果
枚举,视频输出的错误码
**系统能力:** 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);
})
```
| 名称 | 值 | 说明 |
| --------------------- | ---- | ---------- |
| ERROR_UNKNOWN | -1 | 未知错误。 |
| ERROR_DRIVER_ERROR | | |
## FrameShutterInfo
### VideoOutputError
快门事件信息
视频输出错误对象
**系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 类型 | 必填 | 说明 |
| --------- | ------ | ---- | ----------------------------- |
| captureId | number | 是 | CaptureId,本次拍摄动作的ID。 |
| timestamp | number | 是 | 时间戳。 |
| 名称 | 类型 | 说明 |
| ---- | ------------------------------------- | ----------------------- |
| code | [PhotoOutputError](#photooutputerror) | VideoOutput中的错误码。 |
## CaptureEndInfo
## MetadataObjectType
拍照停止信息
枚举,元能力对象类型
**系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 类型 | 必填 | 说明 |
| ---------- | ------ | ---- | ----------------------------- |
| captureId | number | 是 | CaptureId,本次拍摄动作的ID。 |
| frameCount | number | 是 | 帧计数。 |
| 名称 | 值 | 说明 |
| ------------------------- | ---- | ------------ |
| FACE_DETECTION | 0 | |
## PhotoOutputErrorCode
## Rect
枚举,拍照输出的错误码
长方体对象
**系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 值 | 说明 |
| ------------- | ---- | ---------- |
| ERROR_UNKNOWN | -1 | 未知错误。 |
## PhotoOutputError
拍照输出错误对象。
| 名称 | 类型 | 说明 |
| -------- | ------ | ----------------------- |
| topLeftX | number | |
| topLeftY | number | |
| width | number | |
| height | number | |
**系统能力:** SystemCapability.Multimedia.Camera.Core
## MetadataObject
| 名称 | 类型 | 说明 |
| ---- | ------------------------------------- | ----------------------- |
| code | [PhotoOutputError](#photooutputerror) | PhotoOutput中的错误码。 |
元能力对象。
## camera.createVideoOutput
### getType
createVideoOutput(surfaceId: string, callback: AsyncCallback<VideoOutput\>): void
getType(callback: AsyncCallback<MetadataObjectType>): void;
获取VideoOutput实例,通过注册回调函数获取结果。
获取类型,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| --------- | ------------------------------------------- | ---- | ----------------------------------- |
| surfaceId | string | 是 | 从VideoRecorder获取的Surface ID。 |
| callback | AsyncCallback<[VideoOutput](#videooutput)\> | 是 | 回调函数,用于获取VideoOutput实例。 |
| 名称 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------------------------- | ---- | ------------------------ |
| callback | AsyncCallback<[MetadataObjectType](#metadataObjectType)\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```js
camera.createVideoOutput(("surfaceId"), (err, videoOutput) => {
metadataObject.getType((err, metadataObjectType) => {
if (err) {
console.error('Failed to create the VideoOutput instance. ${err.message}');
console.error('Failed to get type. ${err.message}');
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获取结果。
获取类型,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| --------- | ------ | ---- | --------------------------------- |
| surfaceId | string | 是 | 从VideoRecorder获取的Surface ID。 |
**返回值:**
| 类型 | 说明 |
| ------------------------------------- | -------------------------------------- |
| Promise<[VideoOutput](#videooutput)\> | 使用Promise的方式获取VideoOutput实例。 |
| 类型 | 说明 |
| --------------------------------------------------- | --------------------------- |
| Promise<[MetadataObjectType](#MetadataObjectType)\> | 使用Promise的方式获取结果。 |
**示例:**
```js
camera.createVideoOutput("surfaceId"
).then((videoOutput) => {
console.log('Promise returned with the VideoOutput instance');
metadataObject.getType().then((metadataObjectType) => {
console.log('Callback returned with an array of metadataObjectType.');
})
```
## VideoOutput
视频输出类。
### start
### getTimestamp
start(callback: AsyncCallback<void\>): void
getTimestamp(callback: AsyncCallback<number>): void;
开始拍摄视频,通过注册回调函数获取结果。
获取时间戳,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
| 名称 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------------------------- | ---- | ------------------------ |
| callback | AsyncCallback<number\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```js
videoOutput.start((err) => {
metadataObject.getTimestamp((err) => {
if (err) {
console.error('Failed to start the video output ${err.message}');
console.error('Failed to get timestamp. ${err.message}');
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获取结果。
获取时间戳,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 |
| 类型 | 说明 |
| ---------------- | --------------------------- |
| Promise<number)\> | 使用Promise的方式获取结果。 |
**示例:**
```js
videoOutput.start().then(() => {
console.log('Promise returned to indicate that start method execution success.');
metadataObject.getTimestamp().then(() => {
console.log('Callback returned with timestamp getted.');
})
```
### stop
### getBoundingBox
stop(callback: AsyncCallback<void\>): void
getBoundingBox(callback: AsyncCallback<Rect>): void;
停止拍摄视频,通过注册回调函数获取结果。
获取边界框,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
| 名称 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------------------------- | ---- | ------------------------ |
| callback | AsyncCallback<[Rect](#rect)\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```js
videoOutput.stop((err) => {
metadataObject.getBoundingBox((err, rect) => {
if (err) {
console.error('Failed to stop the video output ${err.message}');
console.error('Failed to get boundingBox. ${err.message}');
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获取结果。
获取边界框,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 |
| 类型 | 说明 |
| ---------------------- | --------------------------- |
| Promise<[Rect](#rect)\> | 使用Promise的方式获取结果。 |
**示例:**
```js
videoOutput.start().then(() => {
console.log('Promise returned to indicate that stop method execution success.');
metadataObject.getBoundingBox().then((rect) => {
console.log('Callback returned with boundingBox getted.');
})
```
### release
## MetadataFaceObject
release(callback: AsyncCallback<void\>): void
元能力的面对象。继承[MetadataObject](#metadataObject)
释放VideoOutput实例,通过注册回调函数获取结果。
## MetadataOutput
元能力输出对象。继承[CameraOutput](#cameraoutput)
### start
start(callback: AsyncCallback<void>): void;
开始输出,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
| 名称 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```js
videoOutput.release((err) => {
metadataOutput.start((err) => {
if (err) {
console.error('Failed to release the VideoOutput instance ${err.message}');
console.error('Failed to start metadataOutput. ${err.message}');
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获取结果。
开始输出,通过Promise获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 |
| 类型 | 说明 |
| ---------------------- | --------------------------- |
| Promise<void\> | 使用Promise的方式获取结果。 |
**示例:**
```js
videoOutput.release().then(() => {
console.log('Promise returned to indicate that the VideoOutput instance is released successfully.');
metadataOutput.start().then(() => {
console.log('Callback returned with metadataOutput started.');
})
```
### on('frameStart')
### stop
on(type: 'frameStart', callback: AsyncCallback<void\>): void
stop(callback: AsyncCallback<void>): void;
监听视频帧开启,通过注册回调函数获取结果。
停止输出,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| :------- | :------------------- | :--- | :----------------------------------------------- |
| type | string | 是 | 监听事件,固定为'frameStart',即视频帧开启事件。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
| 名称 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
**示例:**
```js
videoOutput.on('frameStart', () => {
console.log('Video frame started');
metadataOutput.stop((err) => {
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>;
监听视频帧结束,通过注册回调函数获取结果。
停止输出,通过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;
监听元能力对象是否可用,通过注册回调函数获取结果。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| :------- | :------------------- | :--- | :--------------------------------------------- |
| type | string | 是 | 监听事件,固定为'frameEnd',即视频帧结束事件。 |
| callback | AsyncCallback<void\> | 是 | 回调函数,用于获取结果。 |
| 名称 | 类型 | 必填 | 说明 |
| :------- | :----------------------------------------------- | :--- | :-------------------------------------------- |
| type | string | 是 | 监听事件,固定为'metadataObjectsAvailable',即元能力对象可用事件。 |
| callback | Callback<Array<[MetadataObject](#metadataObject)>\> | 是 | 回调函数,用于获取错误信息。 |
**示例:**
```js
videoOutput.on('frameEnd', () => {
console.log('Video frame ended');
metadataOutput.on('metadataObjectsAvailable', (metadataObject) => {
console.log('metadata output error code: ' + metadataObject.code);
})
```
### on('error')
on(type: 'error', callback: ErrorCallback<VideoOutputError\>): void
on(tuype: 'error', callback: ErrorCallback<MetadataOutputError>): void;
监听视频输出的错误事件,通过注册回调函数获取结果。
......@@ -2723,32 +4398,33 @@ on(type: 'error', callback: ErrorCallback<VideoOutputError\>): void
| 名称 | 类型 | 必填 | 说明 |
| :------- | :----------------------------------------------- | :--- | :-------------------------------------------- |
| type | string | 是 | 监听事件,固定为'error',即视频输出错误事件。 |
| callback | Callback<[VideoOutputError](#videooutputerror)\> | 是 | 回调函数,用于获取错误信息。 |
| callback | Callback<[MetadataOutputError](#metadataOutputError)\> | 是 | 回调函数,用于获取错误信息。 |
**示例:**
```js
videoOutput.on('error', (VideoOutputError) => {
console.log('Video output error code: ' + VideoOutputError.code);
metadataOutput.on('error', (metadataOutputError) => {
console.log('Metadata output error code: ' + metadataOutputError.code);
})
```
## VideoOutputErrorCode
### MetadataOutputErrorCode
枚举,视频输出的错误码。
枚举,元能力输出错误码。
**系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 值 | 说明 |
| ------------- | ---- | ---------- |
| ERROR_UNKNOWN | -1 | 未知错误。 |
| 名称 | 值 | 说明 |
| ------------------------------- | ---- | ---------- |
| ERROR_UNKNOWN | -1 | 未知错误。 |
| ERROR_INSUFFICIENT_RESOURCES | | |
## VideoOutputError
### MetadataOutputError
视频输出错误对象。
元能力输出错误对象。
**系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 类型 | 说明 |
| ---- | ------------------------------------- | ----------------------- |
| code | [PhotoOutputError](#photooutputerror) | VideoOutput中的错误码。 |
\ No newline at end of file
| code | [MetadataOutputErrorCode](#MetadataOutputErrorCode) | MetadataOutput中的错误码。 |
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册