From b8fda9b365af36d4f5d99c1c79bab8797bd8c76f Mon Sep 17 00:00:00 2001 From: zengyawen Date: Thu, 30 Jun 2022 15:52:46 +0800 Subject: [PATCH] update docs Signed-off-by: zengyawen --- .../reference/apis/js-apis-camera.md | 556 +++++++++++------- 1 file changed, 337 insertions(+), 219 deletions(-) diff --git a/zh-cn/application-dev/reference/apis/js-apis-camera.md b/zh-cn/application-dev/reference/apis/js-apis-camera.md index f39c4c3632..7df6d6bb7f 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-camera.md +++ b/zh-cn/application-dev/reference/apis/js-apis-camera.md @@ -5,14 +5,10 @@ ## 导入模块 -``` +```js import camera from '@ohos.multimedia.camera'; ``` -## 权限 - -ohos.permission.CAMERA - ## camera.getCameraManager getCameraManager(context: Context, callback: AsyncCallback): void @@ -30,7 +26,7 @@ getCameraManager(context: Context, callback: AsyncCallback): voi **示例:** -``` +```js camera.getCameraManager(context, (err, cameraManager) => { if (err) { console.error('Failed to get the CameraManager instance ${err.message}'); @@ -62,7 +58,7 @@ getCameraManager(context: Context): Promise **示例:** -``` +```js camera.getCameraManager(context).then((cameraManager) => { console.log('Promise returned with the CameraManager instance.'); }) @@ -72,55 +68,65 @@ camera.getCameraManager(context).then((cameraManager) => { 枚举,相机状态。 -**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Camera.Core。 +**系统能力:** SystemCapability.Multimedia.Camera.Core -| 名称 | 默认值 | 说明 | -| ------------------------- | ------ | ------------ | -| CAMERA_STATUS_APPEAR | 0 | 相机存在。 | -| CAMERA_STATUS_DISAPPEAR | 1 | 相机不存在。 | -| CAMERA_STATUS_AVAILABLE | 2 | 相机就绪。 | -| CAMERA_STATUS_UNAVAILABLE | 3 | 相机未就绪。 | +| 名称 | 值 | 说明 | +| ------------------------- | ---- | ------------ | +| CAMERA_STATUS_APPEAR | 0 | 相机存在。 | +| CAMERA_STATUS_DISAPPEAR | 1 | 相机不存在。 | +| CAMERA_STATUS_AVAILABLE | 2 | 相机就绪。 | +| CAMERA_STATUS_UNAVAILABLE | 3 | 相机未就绪。 | ## CameraPosition 枚举,相机方向。 -**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Camera.Core。 +**系统能力:** SystemCapability.Multimedia.Camera.Core -| 名称 | 默认值 | 说明 | -| --------------------------- | ------ | ---------------- | -| CAMERA_POSITION_UNSPECIFIED | 0 | 未指定方向相机。 | -| CAMERA_POSITION_BACK | 1 | 后置相机。 | -| CAMERA_POSITION_FRONT | 2 | 前置相机。 | +| 名称 | 值 | 说明 | +| --------------------------- | ---- | ---------------- | +| CAMERA_POSITION_UNSPECIFIED | 0 | 未指定方向相机。 | +| CAMERA_POSITION_BACK | 1 | 后置相机。 | +| CAMERA_POSITION_FRONT | 2 | 前置相机。 | ## CameraType 枚举,相机类型。 -**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Camera.Core。 +**系统能力:** SystemCapability.Multimedia.Camera.Core -| 名称 | 默认值 | 说明 | -| ----------------------- | ------ | ---------------- | -| CAMERA_TYPE_UNSPECIFIED | 0 | 未指定相机类型。 | -| CAMERA_TYPE_WIDE_ANGLE | 1 | 广角相机。 | -| CAMERA_TYPE_ULTRA_WIDE | 2 | 超级广角相机。 | -| CAMERA_TYPE_TELEPHOTO | 3 | 长焦相机。 | -| CAMERA_TYPE_TRUE_DEPTH | 4 | 深度相机。 | +| 名称 | 值 | 说明 | +| ----------------------- | ---- | ---------------- | +| CAMERA_TYPE_UNSPECIFIED | 0 | 未指定相机类型。 | +| CAMERA_TYPE_WIDE_ANGLE | 1 | 广角相机。 | +| CAMERA_TYPE_ULTRA_WIDE | 2 | 超级广角相机。 | +| CAMERA_TYPE_TELEPHOTO | 3 | 长焦相机。 | +| CAMERA_TYPE_TRUE_DEPTH | 4 | 深度相机。 | ## ConnectionType 枚举,相机连接类型。 -**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Camera.Core。 +**系统能力:** SystemCapability.Multimedia.Camera.Core + +| 名称 | 值 | 说明 | +| ---------------------------- | ---- | ------------- | +| CAMERA_CONNECTION_BUILT_IN | 0 | 内置相机。 | +| CAMERA_CONNECTION_USB_PLUGIN | 1 | 外置USB相机。 | +| CAMERA_CONNECTION_REMOTE | 2 | 分布式相机。 | + +## Size -| 名称 | 默认值 | 说明 | -| ---------------------------- | ------ | ------------- | -| CAMERA_CONNECTION_BUILT_IN | 0 | 内置相机。 | -| CAMERA_CONNECTION_USB_PLUGIN | 1 | 外置USB相机。 | -| CAMERA_CONNECTION_REMOTE | 2 | 分布式相机。 | +用于表示相机预览、照片、视频支持的尺寸大小。 +**系统能力:** SystemCapability.Multimedia.Camera.Core + +| 名称 | 类型 | 可读 | 可写 | 说明 | +| ------ | ------ | ---- | ---- | ------------ | +| height | string | 是 | 是 | 图像的高度。 | +| width | number | 是 | 是 | 图像的宽度。 | ## CameraManager @@ -142,7 +148,7 @@ getCameras(callback: AsyncCallback\>): void **示例:** -``` +```js cameraManager.getCameras((err, cameras) => { if (err) { console.error('Failed to get the cameras. ${err.message}'); @@ -169,7 +175,7 @@ getCameras(): Promise\> **示例:** -``` +```js cameraManager.getCameras().then((cameraArray) => { console.log('Promise returned with an array of supported cameras: ' + cameraArray.length); }) @@ -181,18 +187,20 @@ createCameraInput(cameraId: string, callback: AsyncCallback): void 使用相机ID异步创建CameraInput实例,通过注册回调函数获取结果。 +**需要权限:** ohos.permission.CAMERA + **系统能力:** SystemCapability.Multimedia.Camera.Core **参数:** -| 名称 | 默认值 | 必填 | 说明 | +| 名称 | 类型 | 必填 | 说明 | | -------- | ------------------------------------------- | ---- | ----------------------------------- | | cameraId | string | 是 | 指定相机ID。 | | callback | AsyncCallback<[CameraInput](#camerainput)\> | 是 | 回调函数,用于获取CameraInput实例。 | **示例:** -``` +```js cameraManager.createCameraInput(cameraId, (err, cameraInput) => { if (err) { console.error('Failed to create the CameraInput instance. ${err.message}'); @@ -208,11 +216,13 @@ createCameraInput(cameraId: string): Promise 使用相机ID异步创建CameraInput实例,通过Promise获取结果。 +**需要权限:** ohos.permission.CAMERA + **系统能力:** SystemCapability.Multimedia.Camera.Core **参数:** -| 名称 | 默认值 | 必填 | 说明 | +| 名称 | 类型 | 必填 | 说明 | | -------- | ------ | ---- | ------------ | | cameraId | string | 是 | 指定相机ID。 | @@ -224,7 +234,7 @@ createCameraInput(cameraId: string): Promise **示例:** -``` +```js cameraManager.createCameraInput(cameraId).then((cameraInput) => { console.log('Promise returned with the CameraInput instance'); }) @@ -236,6 +246,8 @@ createCameraInput(position: CameraPosition, type: CameraType, callback: AsyncCal 使用相机位置和相机类型异步创建CameraInput实例,通过注册回调函数获取结果。 +**需要权限:** ohos.permission.CAMERA + **系统能力:** SystemCapability.Multimedia.Camera.Core **参数:** @@ -248,8 +260,8 @@ createCameraInput(position: CameraPosition, type: CameraType, callback: AsyncCal **示例:** -``` -cameraManager.createCameraInput(cameraPosition, cameraType, (err, cameraInput) => { +```js +cameraManager.createCameraInput(camera.CameraPosition.CAMERA_POSITION_BACK, camera.CameraType.CAMERA_TYPE_UNSPECIFIED, (err, cameraInput) => { if (err) { console.error('Failed to create the CameraInput instance. ${err.message}'); return; @@ -264,6 +276,8 @@ createCameraInput(position: CameraPosition, type: CameraType): Promise { +```js +cameraManager.createCameraInput(camera.CameraPosition.CAMERA_POSITION_BACK, camera.CameraType.CAMERA_TYPE_UNSPECIFIED).then((cameraInput) => { console.log('Promise returned with the CameraInput instance.'); }) ``` @@ -304,8 +318,12 @@ on(type: 'cameraStatus', callback: AsyncCallback): void **示例:** -``` -cameraManager.on('cameraStatus', (cameraStatusInfo) => { +```js +cameraManager.on('cameraStatus', (err, cameraStatusInfo) => { + if (err) { + console.error('Failed to get cameraStatus callback. ${err.message}'); + return; + } console.log('camera : ' + cameraStatusInfo.camera.cameraId); console.log('status: ' + cameraStatusInfo.status); }) @@ -315,7 +333,7 @@ cameraManager.on('cameraStatus', (cameraStatusInfo) => { 调用[camera.getCameraManager](#cameragetcameramanager)后,将返回Camera实例,包括相机ID、位置、类型、连接类型等相机相关的元数据。 -**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Camera.Core。 +**系统能力:** SystemCapability.Multimedia.Camera.Core。 | 名称 | 类型 | 只读 | 说明 | | -------------- | --------------------------------- | ---- | -------------- | @@ -326,24 +344,23 @@ cameraManager.on('cameraStatus', (cameraStatusInfo) => { **示例:** -``` -async function getCameraInfo() { +```js +async function getCameraInfo("cameraId") { var cameraManager = await camera.getCameraManager(); var cameras = await cameraManager.getCameras(); var cameraObj = cameras[0]; var cameraId = cameraObj.cameraId; var cameraPosition = cameraObj.cameraPosition; var cameraType = cameraObj.cameraType; - var cameraId = cameraObj.connectionType; + var connectionType = cameraObj.connectionType; } - ``` ## CameraStatusInfo 相机管理器回调返回的接口实例,表示相机状态信息。 -**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Camera.Core。 +**系统能力:** SystemCapability.Multimedia.Camera.Core。 | 名称 | 类型 | 说明 | | ------ | ----------------------------- | ---------- | @@ -371,7 +388,7 @@ getCameraId(callback: AsyncCallback\): void **示例:** -``` +```js cameraInput.getCameraId((err, cameraId) => { if (err) { console.error('Failed to get the camera ID. ${err.message}'); @@ -397,7 +414,7 @@ getCameraId(): Promise **示例:** -``` +```js cameraInput.getCameraId().then((cameraId) => { console.log('Promise returned with the camera ID:' + cameraId); }) @@ -420,7 +437,7 @@ hasFlash(callback: AsyncCallback): void **示例:** -``` +```js cameraInput.hasFlash((err, status) => { if (err) { console.error('Failed to check whether the device has flash light. ${err.message}'); @@ -446,7 +463,7 @@ hasFlash(): Promise **示例:** -``` +```js cameraInput.hasFlash().then((status) => { console.log('Promise returned with the flash light support status:' + status); }) @@ -469,8 +486,8 @@ isFlashModeSupported(flashMode: FlashMode, callback: AsyncCallback): v **示例:** -``` -cameraInput.isFlashModeSupported(flashMode, (err, status) => { +```js +cameraInput.isFlashModeSupported(camera.FlashMode.FLASH_MODE_AUTO, (err, status) => { if (err) { console.error('Failed to check whether the flash mode is supported. ${err.message}'); return; @@ -501,8 +518,8 @@ isFlashModeSupported(flashMode: FlashMode): Promise **示例:** -``` -cameraInput.isFlashModeSupported(flashMode).then((status) => { +```js +cameraInput.isFlashModeSupported(camera.FlashMode.FLASH_MODE_AUTO).then((status) => { console.log('Promise returned with flash mode support status.' + status); }) ``` @@ -529,8 +546,8 @@ setFlashMode(flashMode: FlashMode, callback: AsyncCallback): void **示例:** -``` -cameraInput.setFlashMode(flashMode, (err) => { +```js +cameraInput.setFlashMode(camera.FlashMode.FLASH_MODE_AUTO, (err) => { if (err) { console.error('Failed to set the flash mode ${err.message}'); return; @@ -566,8 +583,8 @@ setFlashMode(flashMode: FlashMode): Promise **示例:** -``` -cameraInput.setFlashMode(flashMode).then(() => { +```js +cameraInput.setFlashMode(camera.FlashMode.FLASH_MODE_AUTO).then(() => { console.log('Promise returned with the successful execution of setFlashMode.'); }) ``` @@ -588,7 +605,7 @@ getFlashMode(callback: AsyncCallback): void **示例:** -``` +```js cameraInput.getFlashMode((err, flashMode) => { if (err) { console.error('Failed to get the flash mode ${err.message}'); @@ -614,7 +631,7 @@ getFlashMode(): Promise **示例:** -``` +```js cameraInput.getFlashMode().then((flashMode) => { console.log('Promise returned with current flash mode : ' + flashMode); }) @@ -637,8 +654,8 @@ isFocusModeSupported(afMode: FocusMode, callback: AsyncCallback): void **示例:** -``` -cameraInput.isFocusModeSupported(afMode, (err, status) => { +```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; @@ -669,8 +686,8 @@ isFocusModeSupported(afMode: FocusMode): Promise **示例:** -``` -cameraInput.isFocusModeSupported(afMode).then((status) => { +```js +cameraInput.isFocusModeSupported(camera.FocusMode.FOCUS_MODE_AUTO).then((status) => { console.log('Promise returned with focus mode support status.' + status); }) ``` @@ -694,8 +711,8 @@ setFocusMode(afMode: FocusMode, callback: AsyncCallback): void **示例:** -``` -cameraInput.setFocusMode(afMode, (err) => { +```js +cameraInput.setFocusMode(camera.FocusMode.FOCUS_MODE_AUTO, (err) => { if (err) { console.error('Failed to set the focus mode ${err.message}'); return; @@ -728,8 +745,8 @@ setFocusMode(afMode: FocusMode): Promise **示例:** -``` -cameraInput.setFocusMode(afMode).then(() => { +```js +cameraInput.setFocusMode(camera.FocusMode.FOCUS_MODE_AUTO).then(() => { console.log('Promise returned with the successful execution of setFocusMode.'); }) ``` @@ -750,7 +767,7 @@ getFocusMode(callback: AsyncCallback): void **示例:** -``` +```js cameraInput.getFocusMode((err, afMode) => { if (err) { console.error('Failed to get the focus mode ${err.message}'); @@ -776,7 +793,7 @@ getFocusMode(): Promise **示例:** -``` +```js cameraInput.getFocusMode().then((afMode) => { console.log('Promise returned with current focus mode : ' + afMode); }) @@ -798,7 +815,7 @@ getZoomRatioRange\(callback: AsyncCallback\>\): void **示例:** -``` +```js cameraInput.getZoomRatioRange((err, zoomRatioRange) => { if (err) { console.error('Failed to get the zoom ratio range. ${err.message}'); @@ -824,7 +841,7 @@ getZoomRatioRange\(\): Promise\> **示例:** -``` +```js cameraInput.getZoomRatioRange().then((zoomRatioRange) => { console.log('Promise returned with zoom ratio range: ' + zoomRatioRange.length); }) @@ -847,8 +864,8 @@ setZoomRatio(zoomRatio: number, callback: AsyncCallback): void **示例:** -``` -cameraInput.setZoomRatio(zoomRatio, (err) => { +```js +cameraInput.setZoomRatio(1, (err) => { if (err) { console.error('Failed to set the zoom ratio value ${err.message}'); return; @@ -879,8 +896,8 @@ setZoomRatio(zoomRatio: number): Promise **示例:** -``` -cameraInput.setZoomRatio(zoomRatio).then(() => { +```js +cameraInput.setZoomRatio(1).then(() => { console.log('Promise returned with the successful execution of setZoomRatio.'); }) ``` @@ -901,7 +918,7 @@ getZoomRatio(callback: AsyncCallback): void **示例:** -``` +```js cameraInput.getZoomRatio((err, zoomRatio) => { if (err) { console.error('Failed to get the zoom ratio ${err.message}'); @@ -927,7 +944,7 @@ getZoomRatio(): Promise **示例:** -``` +```js cameraInput.getZoomRatio().then((zoomRatio) => { console.log('Promise returned with current zoom ratio : ' + zoomRatio); }) @@ -949,8 +966,8 @@ release\(callback: AsyncCallback\): void **示例:** -``` -camera.release((err) => { +```js +cameraInput.release((err) => { if (err) { console.error('Failed to release the CameraInput instance ${err.message}'); return; @@ -975,7 +992,7 @@ release(): Promise **示例:** -``` +```js cameraInput.release().then(() => { console.log('Promise returned to indicate that the CameraInput instance is released successfully.'); }) @@ -998,7 +1015,7 @@ on(type: 'focusStateChange', callback: AsyncCallback): void **示例:** -``` +```js cameraInput.on('focusStateChange', (focusState) => { console.log('Focus state : ' + focusState); }) @@ -1014,14 +1031,14 @@ on(type: 'error', callback: ErrorCallback): void **参数:** -| 名称 | 类型 | 必填 | 说明 | -| :------- | :------------------------------- | :--- | :---------------------------------------------- | +| 名称 | 类型 | 必填 | 说明 | +| :------- | :------------------------------- | :--- | :----------------------------------------------- | | type | string | 是 | 监听事件,固定为'error',即CameraInput错误事件。 | -| callback | ErrorCallback | 是 | 回调函数,用于获取结果。 | +| callback | ErrorCallback | 是 | 回调函数,用于获取结果。 | **示例:** -``` +```js cameraInput.on('error', (cameraInputError) => { console.log('Camera input error code: ' + cameraInputError.code); }) @@ -1032,39 +1049,39 @@ cameraInput.on('error', (cameraInputError) => { 枚举,闪光灯模式。 -**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Camera.Core。 +**系统能力:** SystemCapability.Multimedia.Camera.Core。 -| 名称 | 默认值 | 说明 | -| ---------------------- | ------ | ------------ | -| FLASH_MODE_CLOSE | 0 | 闪光灯关闭。 | -| FLASH_MODE_OPEN | 1 | 闪光灯开启。 | -| FLASH_MODE_AUTO | 2 | 自动闪光灯。 | -| FLASH_MODE_ALWAYS_OPEN | 3 | 闪光灯常亮。 | +| 名称 | 值 | 说明 | +| ---------------------- | ---- | ------------ | +| FLASH_MODE_CLOSE | 0 | 闪光灯关闭。 | +| FLASH_MODE_OPEN | 1 | 闪光灯开启。 | +| FLASH_MODE_AUTO | 2 | 自动闪光灯。 | +| FLASH_MODE_ALWAYS_OPEN | 3 | 闪光灯常亮。 | ## FocusMode 枚举,焦距模式。 -**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Camera.Core。 +**系统能力:** SystemCapability.Multimedia.Camera.Core。 -| 名称 | 默认值 | 说明 | -| -------------------------- | ------ | ------------------ | -| FOCUS_MODE_MANUAL | 0 | 手动变焦模式。 | -| FOCUS_MODE_CONTINUOUS_AUTO | 1 | 连续自动变焦模式。 | -| FOCUS_MODE_AUTO | 2 | 自动变焦模式。 | -| FOCUS_MODE_LOCKED | 3 | 定焦模式。 | +| 名称 | 值 | 说明 | +| -------------------------- | ---- | ------------------ | +| FOCUS_MODE_MANUAL | 0 | 手动变焦模式。 | +| FOCUS_MODE_CONTINUOUS_AUTO | 1 | 连续自动变焦模式。 | +| FOCUS_MODE_AUTO | 2 | 自动变焦模式。 | +| FOCUS_MODE_LOCKED | 3 | 定焦模式。 | ## FocusState 枚举,焦距状态。 -**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Camera.Core。 +**系统能力:** SystemCapability.Multimedia.Camera.Core。 -| 名称 | 默认值 | 说明 | -| --------------------- | ------ | ------------ | -| FOCUS_STATE_SCAN | 0 | 扫描状态。 | -| FOCUS_STATE_FOCUSED | 1 | 相机已对焦。 | -| FOCUS_STATE_UNFOCUSED | 2 | 相机未对焦。 | +| 名称 | 值 | 说明 | +| --------------------- | ---- | ------------ | +| FOCUS_STATE_SCAN | 0 | 扫描状态。 | +| FOCUS_STATE_FOCUSED | 1 | 相机已对焦。 | +| FOCUS_STATE_UNFOCUSED | 2 | 相机未对焦。 | ## camera.createCaptureSession @@ -1083,7 +1100,7 @@ createCaptureSession\(context: Context, callback: AsyncCallback **示例:** -``` +```js camera.createCaptureSession((context), (err, captureSession) => { if (err) { console.error('Failed to create the CaptureSession instance. ${err.message}'); @@ -1115,7 +1132,7 @@ createCaptureSession(context: Context\): Promise; **示例:** -``` +```js camera.createCaptureSession(context).then((captureSession) => { console.log('Promise returned with the CaptureSession instance'); }) @@ -1141,7 +1158,7 @@ beginConfig\(callback: AsyncCallback\): void **示例:** -``` +```js captureSession.beginConfig((err) => { if (err) { console.error('Failed to start the configuration. ${err.message}'); @@ -1168,7 +1185,7 @@ beginConfig\(\): Promise **示例:** -``` +```js captureSession.beginConfig().then(() => { console.log('Promise returned to indicate the begin config success.'); }) @@ -1190,7 +1207,7 @@ commitConfig\(callback: AsyncCallback\): void **示例:** -``` +```js captureSession.commitConfig((err) => { if (err) { console.error('Failed to commit the configuration. ${err.message}'); @@ -1216,7 +1233,7 @@ commitConfig\(\): Promise **示例:** -``` +```js captureSession.commitConfig().then(() => { console.log('Promise returned to indicate the commit config success.'); }) @@ -1239,7 +1256,7 @@ addInput\(cameraInput: CameraInput, callback: AsyncCallback\): void **示例:** -``` +```js captureSession.addInput(cameraInput, (err) => { if (err) { console.error('Failed to add the CameraInput instance. ${err.message}'); @@ -1271,7 +1288,7 @@ addInput\(cameraInput: CameraInput\): Promise **示例:** -``` +```js captureSession.addInput(cameraInput).then(() => { console.log('Promise used to indicate that the CameraInput instance is added.'); }) @@ -1294,7 +1311,7 @@ addOutput\(previewOutput: PreviewOutput, callback: AsyncCallback\): void **示例:** -``` +```js captureSession.addOutput(previewOutput, (err) => { if (err) { console.error('Failed to add the PreviewOutput instance ${err.message}'); @@ -1326,7 +1343,7 @@ addOutput\(previewOutput: PreviewOutput\): Promise **示例:** -``` +```js captureSession.addOutput(previewOutput).then(() => { console.log('Promise used to indicate that the PreviewOutput instance is added.'); }) @@ -1349,7 +1366,7 @@ addOutput\(photoOutput: PhotoOutput, callback: AsyncCallback\): void **示例:** -``` +```js captureSession.addOutput(photoOutput, (err) => { if (err) { console.error('Failed to add the PhotoOutput instance ${err.message}'); @@ -1381,7 +1398,7 @@ addOutput\(photoOutput: PhotoOutput\): Promise **示例:** -``` +```js captureSession.addOutput(photoOutput).then(() => { console.log('Promise used to indicate that the PhotoOutput instance is added.'); }) @@ -1404,7 +1421,7 @@ addOutput\(videoOutput: VideoOutput, callback: AsyncCallback\): void **示例:** -``` +```js captureSession.addOutput(videoOutput, (err) => { if (err) { console.error('Failed to add the VideoOutput instance ${err.message}'); @@ -1436,7 +1453,7 @@ addOutput\(videoOutput: VideoOutput\): Promise **示例:** -``` +```js captureSession.addOutput(videoOutput).then(() => { console.log('Promise used to indicate that the VideoOutput instance is added.'); }) @@ -1459,7 +1476,7 @@ removeInput\(cameraInput: CameraInput, callback: AsyncCallback\): void **示例:** -``` +```js captureSession.removeInput(cameraInput, (err) => { if (err) { console.error('Failed to remove the CameraInput instance. ${err.message}'); @@ -1491,7 +1508,7 @@ removeInput\(cameraInput: CameraInput\): Promise **示例:** -``` +```js captureSession.removeInput(cameraInput).then(() => { console.log('Promise returned to indicate that the cameraInput instance is removed.'); }) @@ -1514,7 +1531,7 @@ removeOutput\(previewOutput: PreviewOutput, callback: AsyncCallback\): vo **示例:** -``` +```js captureSession.removeOutput(previewOutput, (err) => { if (err) { console.error('Failed to remove the PreviewOutput instance. ${err.message}'); @@ -1548,7 +1565,7 @@ removeOutput(previewOutput: PreviewOutput): Promise **示例:** -``` +```js captureSession.removeOutput(previewOutput).then(() => { console.log('Promise returned to indicate that the PreviewOutput instance is removed.'); }) @@ -1571,7 +1588,7 @@ removeOutput(photoOutput: PhotoOutput, callback: AsyncCallback): void **示例:** -``` +```js captureSession.removeOutput(photoOutput, (err) => { if (err) { console.error('Failed to remove the PhotoOutput instance. ${err.message}'); @@ -1605,7 +1622,7 @@ removeOutput(photoOutput: PhotoOutput): Promise **示例:** -``` +```js captureSession.removeOutput(photoOutput).then(() => { console.log('Promise returned to indicate that the PhotoOutput instance is removed.'); }) @@ -1628,7 +1645,7 @@ removeOutput(videoOutput: VideoOutput, callback: AsyncCallback): void **示例:** -``` +```js captureSession.removeOutput(videoOutput, (err) => { if (err) { console.error('Failed to remove the VideoOutput instance. ${err.message}'); @@ -1662,7 +1679,7 @@ removeOutput(videoOutput: VideoOutput): Promise **示例:** -``` +```js captureSession.removeOutput(videoOutput).then(() => { console.log('Promise returned to indicate that the VideoOutput instance is removed.'); }) @@ -1684,7 +1701,7 @@ start\(callback: AsyncCallback\): void **示例:** -``` +```js captureSession.start((err) => { if (err) { console.error('Failed to start the session ${err.message}'); @@ -1710,7 +1727,7 @@ start\(\): Promise **示例:** -``` +```js captureSession.start().then(() => { console.log('Promise returned to indicate the session start success.'); }) @@ -1733,7 +1750,7 @@ stop\(callback: AsyncCallback\): void **示例:** -``` +```js captureSession.stop((err) => { if (err) { console.error('Failed to stop the session ${err.message}'); @@ -1759,7 +1776,7 @@ stop(): Promise **示例:** -``` +```js captureSession.stop().then(() => { console.log('Promise returned to indicate the session stop success.'); }) @@ -1781,7 +1798,7 @@ release\(callback: AsyncCallback\): void **示例:** -``` +```js captureSession.release((err) => { if (err) { console.error('Failed to release the CaptureSession instance ${err.message}'); @@ -1807,7 +1824,7 @@ release(): Promise **示例:** -``` +```js captureSession.release().then(() => { console.log('Promise returned to indicate that the CaptureSession instance is released successfully.'); }) @@ -1823,19 +1840,39 @@ on(type: 'error', callback: ErrorCallback): void **参数:** -| 名称 | 类型 | 必填 | 说明 | -| :------- | :---------------------------------- | :--- | :-------------------------------------------- | -| type | string | 是 | 监听事件,固定为'error',即拍照会话错误事件。 | -| callback | ErrorCallback | 是 | 回调函数,用于获取错误信息。 | +| 名称 | 类型 | 必填 | 说明 | +| :------- | :---------------------------------------------------------- | :--- | :-------------------------------------------- | +| 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 | 未知错误。 | + +## CaptureSessionError + +拍照会话错误对象。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +| 名称 | 类型 | 说明 | +| ---- | ------------------------------------------- | -------------------------- | +| code | [CaptureSessionError](#capturesessionerror) | CaptureSession中的错误码。 | + ## camera.createPreviewOutput createPreviewOutput(surfaceId: string, callback: AsyncCallback): void @@ -1853,8 +1890,8 @@ createPreviewOutput(surfaceId: string, callback: AsyncCallback): **示例:** -``` -camera.createPreviewOutput((surfaceId), (err, previewOutput) => { +```js +camera.createPreviewOutput(("surfaceId"), (err, previewOutput) => { if (err) { console.error('Failed to create the PreviewOutput instance. ${err.message}'); return; @@ -1885,8 +1922,8 @@ createPreviewOutput(surfaceId: string): Promise\ **示例:** -``` -camera.createPreviewOutput(surfaceId).then((previewOutput) => { +```js +camera.createPreviewOutput("surfaceId").then((previewOutput) => { console.log('Promise returned with the PreviewOutput instance'); }) ``` @@ -1911,7 +1948,7 @@ release(callback: AsyncCallback): void **示例:** -``` +```js previewOutput.release((err) => { if (err) { console.error('Failed to release the PreviewOutput instance ${err.message}'); @@ -1938,7 +1975,7 @@ release(): Promise **示例:** -``` +```js previewOutput.release().then(() => { console.log('Promise returned to indicate that the PreviewOutput instance is released successfully.'); }) @@ -1961,7 +1998,7 @@ on(type: 'frameStart', callback: AsyncCallback): void **示例:** -``` +```js previewOutput.on('frameStart', () => { console.log('Preview frame started'); }) @@ -1984,7 +2021,7 @@ on(type: 'frameEnd', callback: AsyncCallback): void **示例:** -``` +```js previewOutput.on('frameEnd', () => { console.log('Preview frame ended'); }) @@ -2000,19 +2037,39 @@ on(type: 'error', callback: ErrorCallback): void **参数:** -| 名称 | 类型 | 必填 | 说明 | -| :------- | :--------------------------------- | :--- | :-------------------------------------------- | -| type | string | 是 | 监听事件,固定为'error',即预览输出错误事件。 | -| callback | ErrorCallback | 是 | 回调函数,用于获取错误信息。 | +| 名称 | 类型 | 必填 | 说明 | +| :------- | :----------------------------------------------------------- | :--- | :-------------------------------------------- | +| 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) | PreviewOut中的错误码。 | + ## camera.createPhotoOutput createPhotoOutput(surfaceId: string, callback: AsyncCallback): void @@ -2030,8 +2087,8 @@ createPhotoOutput(surfaceId: string, callback: AsyncCallback): voi **示例:** -``` -camera.createPhotoOutput((surfaceId), (err, photoOutput) => { +```js +camera.createPhotoOutput(("surfaceId"), (err, photoOutput) => { if (err) { console.error('Failed to create the PhotoOutput instance. ${err.message}'); return; @@ -2062,8 +2119,8 @@ createPhotoOutput(surfaceId: string): Promise **示例:** -``` -camera.createPhotoOutput(surfaceId).then((photoOutput) => { +```js +camera.createPhotoOutput("surfaceId").then((photoOutput) => { console.log('Promise returned with PhotoOutput instance'); }) ``` @@ -2071,35 +2128,33 @@ camera.createPhotoOutput(surfaceId).then((photoOutput) => { 枚举,图片旋转角度。 -**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Camera.Core。 - -| 名称 | 默认值 | 说明 | -| ------------ | ------ | --------------- | -| ROTATION_0 | 0 | 图片旋转0度。 | -| ROTATION_90 | 90 | 图片旋转90度。 | -| ROTATION_180 | 180 | 图片旋转180度。 | -| ROTATION_270 | 270 | 图片旋转270度。 | - +**系统能力:** SystemCapability.Multimedia.Camera.Core +| 名称 | 值 | 说明 | +| ------------ | ---- | --------------- | +| ROTATION_0 | 0 | 图片旋转0度。 | +| ROTATION_90 | 90 | 图片旋转90度。 | +| ROTATION_180 | 180 | 图片旋转180度。 | +| ROTATION_270 | 270 | 图片旋转270度。 | ## QualityLevel 枚举,图片质量。 -**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Camera.Core。 +**系统能力:** SystemCapability.Multimedia.Camera.Core -| 名称 | 默认值 | 说明 | -| -------------------- | ------ | -------------- | -| QUALITY_LEVEL_HIGH | 0 | 图片质量高。 | -| QUALITY_LEVEL_MEDIUM | 1 | 图片质量中等。 | -| QUALITY_LEVEL_LOW | 2 | 图片质量差。 | +| 名称 | 值 | 说明 | +| -------------------- | ---- | -------------- | +| QUALITY_LEVEL_HIGH | 0 | 图片质量高。 | +| QUALITY_LEVEL_MEDIUM | 1 | 图片质量中等。 | +| QUALITY_LEVEL_LOW | 2 | 图片质量差。 | ## PhotoCaptureSetting 拍摄照片的设置。 -**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Camera.Core。 +**系统能力:** SystemCapability.Multimedia.Camera.Core | 名称 | 类型 | 必填 | 说明 | | -------- | ------------------------------- | ---- | -------------- | @@ -2127,7 +2182,7 @@ capture(callback: AsyncCallback): void **示例:** -``` +```js photoOutput.capture((err) => { if (err) { console.error('Failed to capture the photo ${err.message}'); @@ -2154,7 +2209,7 @@ capture(setting: PhotoCaptureSetting, callback: AsyncCallback): void **示例:** -``` +```js photoOutput.capture(settings, (err) => { if (err) { console.error('Failed to capture the photo ${err.message}'); @@ -2187,7 +2242,7 @@ capture(setting?: PhotoCaptureSetting): Promise **示例:** -``` +```js photoOutput.capture().then(() => { console.log('Promise returned to indicate that photo capture request success.'); }) @@ -2209,7 +2264,7 @@ release(callback: AsyncCallback): void **示例:** -``` +```js photoOutput.release((err) => { if (err) { console.error('Failed to release the PhotoOutput instance ${err.message}'); @@ -2236,7 +2291,7 @@ release(): Promise **示例:** -``` +```js photoOutput.release().then(() => { console.log('Promise returned to indicate that the PhotoOutput instance is released successfully.'); }) @@ -2259,8 +2314,8 @@ on(type: 'captureStart', callback: AsyncCallback): void **示例:** -``` -photoOutput.on('captureStart', (captureId) => { +```js +photoOutput.on('captureStart', (err, captureId) => { console.log('photo capture stated, captureId : ' + captureId); }) ``` @@ -2269,20 +2324,20 @@ photoOutput.on('captureStart', (captureId) => { on(type: 'frameShutter', callback: AsyncCallback): void -监听帧刷新,通过注册回调函数获取结果。 +监听快门,通过注册回调函数获取结果。 **系统能力:** SystemCapability.Multimedia.Camera.Core **参数:** -| 名称 | 类型 | 必填 | 说明 | -| :------- | :------------------------------- | :--- | :--------------------------------------------- | -| type | string | 是 | 监听事件,固定为'frameShutter',即帧刷新事件。 | -| callback | AsyncCallback | 是 | 回调函数,用于获取相关信息。 | +| 名称 | 类型 | 必填 | 说明 | +| :------- | :---------------------------------------------------- | :--- | :--------------------------------------------- | +| type | string | 是 | 监听事件,固定为'frameShutter',即帧刷新事件。 | +| callback | AsyncCallback<[FrameShutterInfo](#frameshutterinfo)\> | 是 | 回调函数,用于获取相关信息。 | **示例:** -``` +```js photoOutput.on('frameShutter', (frameShutterInfo) => { console.log('photo capture end, captureId : ' + frameShutterInfo.captureId); console.log('Timestamp for frame : ' + frameShutterInfo.timestamp); @@ -2299,14 +2354,14 @@ on(type: 'captureEnd', callback: AsyncCallback): void **参数:** -| 名称 | 类型 | 必填 | 说明 | -| :------- | :----------------------------- | :--- | :--------------------------------------------- | -| type | string | 是 | 监听事件,固定为'captureEnd',即拍照停止事件。 | -| callback | AsyncCallback | 是 | 回调函数,用于获取相关信息。 | +| 名称 | 类型 | 必填 | 说明 | +| :------- | :------------------------------------------------ | :--- | :--------------------------------------------- | +| type | string | 是 | 监听事件,固定为'captureEnd',即拍照停止事件。 | +| callback | AsyncCallback<[CaptureEndInfo](#captureendinfo)\> | 是 | 回调函数,用于获取相关信息。 | **示例:** -``` +```js photoOutput.on('captureEnd', (captureEndInfo) => { console.log('photo capture end, captureId : ' + captureEndInfo.captureId); console.log('frameCount : ' + captureEndInfo.frameCount); @@ -2323,19 +2378,61 @@ on(type: 'error', callback: ErrorCallback): void **参数:** -| 名称 | 类型 | 必填 | 说明 | -| :------- | :------------------------------- | :--- | :---------------------------------------- | -| type | string | 是 | 监听事件,固定为'error',即拍照错误事件。 | -| callback | ErrorCallback | 是 | 回调函数,用于获取错误信息。 | +| 名称 | 类型 | 必填 | 说明 | +| :------- | :---------------------------------------------------- | :--- | :---------------------------------------- | +| type | string | 是 | 监听事件,固定为'error',即拍照错误事件。 | +| callback | ErrorCallback<[PhotoOutputError](#photooutputerror)\> | 是 | 回调函数,用于获取错误信息。 | **示例:** -``` +```js photoOutput.on('error', (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 | 未知错误。 | + +## PhotoOutputError + +拍照输出错误对象。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +| 名称 | 类型 | 说明 | +| ---- | ------------------------------------- | ----------------------- | +| code | [PhotoOutputError](#photooutputerror) | PhotoOutput中的错误码。 | + ## camera.createVideoOutput createVideoOutput(surfaceId: string, callback: AsyncCallback): void @@ -2353,8 +2450,8 @@ createVideoOutput(surfaceId: string, callback: AsyncCallback): voi **示例:** -``` -camera.createVideoOutput((surfaceId), (err, videoOutput) => { +```js +camera.createVideoOutput(("surfaceId"), (err, videoOutput) => { if (err) { console.error('Failed to create the VideoOutput instance. ${err.message}'); return; @@ -2385,8 +2482,9 @@ createVideoOutput(surfaceId: string): Promise **示例:** -``` -camera.createVideoOutput(surfaceId).then((videoOutput) => { +```js +camera.createVideoOutput("surfaceId" +).then((videoOutput) => { console.log('Promise returned with the VideoOutput instance'); }) ``` @@ -2411,7 +2509,7 @@ start(callback: AsyncCallback): void **示例:** -``` +```js videoOutput.start((err) => { if (err) { console.error('Failed to start the video output ${err.message}'); @@ -2438,7 +2536,7 @@ start(): Promise **示例:** -``` +```js videoOutput.start().then(() => { console.log('Promise returned to indicate that start method execution success.'); }) @@ -2460,7 +2558,7 @@ stop(callback: AsyncCallback): void **示例:** -``` +```js videoOutput.stop((err) => { if (err) { console.error('Failed to stop the video output ${err.message}'); @@ -2486,7 +2584,7 @@ stop(): Promise **示例:** -``` +```js videoOutput.start().then(() => { console.log('Promise returned to indicate that stop method execution success.'); }) @@ -2508,7 +2606,7 @@ release(callback: AsyncCallback): void **示例:** -``` +```js videoOutput.release((err) => { if (err) { console.error('Failed to release the VideoOutput instance ${err.message}'); @@ -2535,7 +2633,7 @@ release(): Promise **示例:** -``` +```js videoOutput.release().then(() => { console.log('Promise returned to indicate that the VideoOutput instance is released successfully.'); }) @@ -2558,7 +2656,7 @@ on(type: 'frameStart', callback: AsyncCallback): void **示例:** -``` +```js videoOutput.on('frameStart', () => { console.log('Video frame started'); }) @@ -2581,7 +2679,7 @@ on(type: 'frameEnd', callback: AsyncCallback): void **示例:** -``` +```js videoOutput.on('frameEnd', () => { console.log('Video frame ended'); }) @@ -2597,15 +2695,35 @@ on(type: 'error', callback: ErrorCallback): void **参数:** -| 名称 | 类型 | 必填 | 说明 | -| :------- | :-------------------------- | :--- | :-------------------------------------------- | -| type | string | 是 | 监听事件,固定为'error',即视频输出错误事件。 | -| callback | Callback | 是 | 回调函数,用于获取错误信息。 | +| 名称 | 类型 | 必填 | 说明 | +| :------- | :----------------------------------------------- | :--- | :-------------------------------------------- | +| type | string | 是 | 监听事件,固定为'error',即视频输出错误事件。 | +| callback | Callback<[VideoOutputError](#videooutputerror)\> | 是 | 回调函数,用于获取错误信息。 | **示例:** -``` +```js videoOutput.on('error', (VideoOutputError) => { console.log('Video output error code: ' + VideoOutputError.code); }) -``` \ No newline at end of file +``` + +## VideoOutputErrorCode + +枚举,视频输出的错误码。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +| 名称 | 值 | 说明 | +| ------------- | ---- | ---------- | +| ERROR_UNKNOWN | -1 | 未知错误。 | + +## VideoOutputError + +视频输出错误对象。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +| 名称 | 类型 | 说明 | +| ---- | ------------------------------------- | ----------------------- | +| code | [PhotoOutputError](#photooutputerror) | VideoOutput中的错误码。 | \ No newline at end of file -- GitLab