未验证 提交 4848b5b5 编写于 作者: O openharmony_ci 提交者: Gitee

!23759 【cameraFramework】js改ts

Merge pull request !23759 from 章超123/master
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
[各类Context的获取方式](../application-models/application-context-stage.md) [各类Context的获取方式](../application-models/application-context-stage.md)
```js ```ts
import camera from '@ohos.multimedia.camera'; import camera from '@ohos.multimedia.camera';
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
...@@ -83,7 +83,7 @@ async function preview(context: featureAbility.Context, cameraInfo: camera.Camer ...@@ -83,7 +83,7 @@ async function preview(context: featureAbility.Context, cameraInfo: camera.Camer
![](figures/quick-thumbnail-sequence-diagram.png) ![](figures/quick-thumbnail-sequence-diagram.png)
[各类Context的获取方式](../application-models/application-context-stage.md) [各类Context的获取方式](../application-models/application-context-stage.md)
```js ```ts
import camera from '@ohos.multimedia.camera'; import camera from '@ohos.multimedia.camera';
import { BusinessError } from '@ohos.base'; import { BusinessError } from '@ohos.base';
import image from '@ohos.multimedia.image'; import image from '@ohos.multimedia.image';
...@@ -152,7 +152,7 @@ function showOrSavePicture(pixelMap: image.PixelMap): void { ...@@ -152,7 +152,7 @@ function showOrSavePicture(pixelMap: image.PixelMap): void {
- **桌面应用** - **桌面应用**
```js ```ts
import camera from '@ohos.multimedia.camera'; import camera from '@ohos.multimedia.camera';
import { BusinessError } from '@ohos.base'; import { BusinessError } from '@ohos.base';
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
...@@ -174,7 +174,7 @@ function showOrSavePicture(pixelMap: image.PixelMap): void { ...@@ -174,7 +174,7 @@ function showOrSavePicture(pixelMap: image.PixelMap): void {
具体申请方式及校验方式,请参考[访问控制授权申请指导](../security/accesstoken-guidelines.md) 具体申请方式及校验方式,请参考[访问控制授权申请指导](../security/accesstoken-guidelines.md)
```js ```ts
import camera from '@ohos.multimedia.camera'; import camera from '@ohos.multimedia.camera';
import { BusinessError } from '@ohos.base'; import { BusinessError } from '@ohos.base';
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
......
...@@ -6,13 +6,13 @@ ...@@ -6,13 +6,13 @@
## 导入模块 ## 导入模块
```js ```ts
import camera from '@ohos.multimedia.camera'; import camera from '@ohos.multimedia.camera';
``` ```
## camera.getCameraManager ## camera.getCameraManager
getCameraManager(context: Context): CameraManager getCameraManager(context: featureAbility.Context): CameraManager
获取相机管理器实例,同步返回结果。 获取相机管理器实例,同步返回结果。
...@@ -41,12 +41,24 @@ getCameraManager(context: Context): CameraManager ...@@ -41,12 +41,24 @@ getCameraManager(context: Context): CameraManager
**示例:** **示例:**
```js ```ts
let cameraManager = camera.getCameraManager(context); import featureAbility from '@ohos.ability.featureAbility';
import { BusinessError } from '@ohos.base';
function getCameraManager(context: featureAbility.Context): camera.CameraManager {
let cameraManager: camera.CameraManager;
try {
cameraManager = camera.getCameraManager(context);
} catch (error) {
let err = error as BusinessError;
console.error(`The getCameraManager call failed. error code: ${err.code}`);
}
return cameraManager;
}
``` ```
## camera.getModeManager ## camera.getModeManager
getModeManager(context: Context): ModeManager getModeManager(context: featureAbility.Context): ModeManager
获取模式化管理器实例,同步返回结果。 获取模式化管理器实例,同步返回结果。
...@@ -79,8 +91,20 @@ getModeManager(context: Context): ModeManager ...@@ -79,8 +91,20 @@ getModeManager(context: Context): ModeManager
**示例:** **示例:**
```js ```ts
let modeManager = camera.getModeManager(context); import featureAbility from '@ohos.ability.featureAbility';
import { BusinessError } from '@ohos.base';
function getModeManager(context: featureAbility.Context): camera.ModeManager {
let modeManager: camera.ModeManager;
try {
modeManager = camera.getModeManager(context);
} catch (error) {
let err = error as BusinessError;
console.error(`The getModeManager call failed. error code: ${err.code}`);
}
return modeManager;
}
``` ```
## CameraStatus ## CameraStatus
...@@ -241,9 +265,19 @@ getSupportedCameras(): Array\<CameraDevice\> ...@@ -241,9 +265,19 @@ getSupportedCameras(): Array\<CameraDevice\>
**示例:** **示例:**
```js ```ts
let cameras = cameraManager.getSupportedCameras(); import { BusinessError } from '@ohos.base';
function getSupportedCameras(cameraManager: camera.CameraManager): Array<camera.CameraDevice> {
let cameras: Array<camera.CameraDevice>;
try {
cameras = cameraManager.getSupportedCameras();
} catch (error) {
let err = error as BusinessError;
console.error(`The getSupportedCameras call failed. error code: ${err.code}`);
}
return cameras;
}
``` ```
### getSupportedOutputCapability ### getSupportedOutputCapability
...@@ -268,11 +302,11 @@ getSupportedOutputCapability(camera:CameraDevice): CameraOutputCapability ...@@ -268,11 +302,11 @@ getSupportedOutputCapability(camera:CameraDevice): CameraOutputCapability
**示例:** **示例:**
```js ```ts
let cameras = cameraManager.getSupportedCameras(); function getSupportedOutputCapability(cameraDevice: camera.CameraDevice, cameraManager: camera.CameraManager): camera.CameraOutputCapability {
let cameraDevice = cameras[0]; let cameraOutputCapability: camera.CameraOutputCapability = cameraManager.getSupportedOutputCapability(cameraDevice);
let cameraOutputCapability = cameraManager.getSupportedOutputCapability(cameraDevice); return cameraOutputCapability;
}
``` ```
### isCameraMuted ### isCameraMuted
...@@ -293,8 +327,11 @@ isCameraMuted(): boolean ...@@ -293,8 +327,11 @@ isCameraMuted(): boolean
**示例:** **示例:**
```js ```ts
let ismuted = cameraManager.isCameraMuted(); function isCameraMuted(cameraManager: camera.CameraManager): boolean {
let isMuted: boolean = cameraManager.isCameraMuted();
return isMuted;
}
``` ```
### isCameraMuteSupported ### isCameraMuteSupported
...@@ -315,8 +352,11 @@ isCameraMuteSupported(): boolean ...@@ -315,8 +352,11 @@ isCameraMuteSupported(): boolean
**示例:** **示例:**
```js ```ts
let ismutesuppotred = cameraManager.isCameraMuteSupported(); function isCameraMuteSupported(cameraManager: camera.CameraManager): boolean {
let isMuteSupported: boolean = cameraManager.isCameraMuteSupported();
return isMuteSupported;
}
``` ```
### muteCamera ### muteCamera
...@@ -337,9 +377,11 @@ muteCamera(mute: boolean): void ...@@ -337,9 +377,11 @@ muteCamera(mute: boolean): void
**示例:** **示例:**
```js ```ts
let mute = true; function muteCamera(cameraManager: camera.CameraManager): void {
cameraManager.muteCamera(mute); let mute: boolean = true;
cameraManager.muteCamera(mute);
}
``` ```
### createCameraInput ### createCameraInput
...@@ -374,14 +416,19 @@ createCameraInput(camera: CameraDevice): CameraInput ...@@ -374,14 +416,19 @@ createCameraInput(camera: CameraDevice): CameraInput
**示例:** **示例:**
```js ```ts
let cameraDevice = cameras[0]; import { BusinessError } from '@ohos.base';
let cameraInput;
try { function createCameraInput(cameraDevice: camera.CameraDevice, cameraManager: camera.CameraManager): camera.CameraInput {
cameraInput = cameraManager.createCameraInput(cameraDevice); let cameraInput: camera.CameraInput;
} catch (error) { try {
cameraInput = cameraManager.createCameraInput(cameraDevice);
} catch (error) {
// 失败返回错误码error.code并处理 // 失败返回错误码error.code并处理
console.log(error.code); let err = error as BusinessError;
console.error(`The createCameraInput call failed. error code: ${err.code}`);
}
return cameraInput;
} }
``` ```
...@@ -418,16 +465,21 @@ createCameraInput(position: CameraPosition, type: CameraType): CameraInput ...@@ -418,16 +465,21 @@ createCameraInput(position: CameraPosition, type: CameraType): CameraInput
**示例:** **示例:**
```js ```ts
let cameraDevice = cameras[0]; import { BusinessError } from '@ohos.base';
let position = cameraDevice.cameraPosition;
let type = cameraDevice.cameraType; function createCameraInput(cameraDevice: camera.CameraDevice, cameraManager: camera.CameraManager): camera.CameraInput {
let cameraInput; let position: camera.CameraPosition = cameraDevice.cameraPosition;
try { let type: camera.CameraType = cameraDevice.cameraType;
let cameraInput: camera.CameraInput;
try {
cameraInput = cameraManager.createCameraInput(position, type); cameraInput = cameraManager.createCameraInput(position, type);
} catch (error) { } catch (error) {
// 失败返回错误码error.code并处理 // 失败返回错误码error.code并处理
console.log(error.code); let err = error as BusinessError;
console.log(`The createCameraInput call failed. error code: ${err.code}`);
}
return cameraInput;
} }
``` ```
...@@ -462,14 +514,20 @@ createPreviewOutput(profile: Profile, surfaceId: string): PreviewOutput ...@@ -462,14 +514,20 @@ createPreviewOutput(profile: Profile, surfaceId: string): PreviewOutput
**示例:** **示例:**
```js ```ts
let profile = cameraOutputCapability.previewProfiles[0]; import { BusinessError } from '@ohos.base';
let previewOutput;
try { function createPreviewOutput(cameraOutputCapability: camera.CameraOutputCapability, cameraManager: camera.CameraManager, surfaceId: string): camera.PreviewOutput {
let profile: camera.Profile = cameraOutputCapability.previewProfiles[0];
let previewOutput: camera.PreviewOutput;
try {
previewOutput = cameraManager.createPreviewOutput(profile, surfaceId); previewOutput = cameraManager.createPreviewOutput(profile, surfaceId);
} catch (error) { } catch (error) {
// 失败返回错误码error.code并处理 // 失败返回错误码error.code并处理
console.log(error.code); let err = error as BusinessError;
console.log(`The createPreviewOutput call failed. error code: ${err.code}`);
}
return previewOutput;
} }
``` ```
...@@ -504,14 +562,20 @@ createPhotoOutput(profile: Profile, surfaceId: string): PhotoOutput ...@@ -504,14 +562,20 @@ createPhotoOutput(profile: Profile, surfaceId: string): PhotoOutput
**示例:** **示例:**
```js ```ts
let profile = cameraOutputCapability.photoProfiles[0]; import { BusinessError } from '@ohos.base';
let photoOutput;
try { function createPhotoOutput(cameraOutputCapability: camera.CameraOutputCapability, cameraManager: camera.CameraManager, surfaceId: string): camera.PhotoOutput {
let profile: camera.Profile = cameraOutputCapability.photoProfiles[0];
let photoOutput: camera.PhotoOutput;
try {
photoOutput = cameraManager.createPhotoOutput(profile, surfaceId); photoOutput = cameraManager.createPhotoOutput(profile, surfaceId);
} catch (error) { } catch (error) {
// 失败返回错误码error.code并处理 // 失败返回错误码error.code并处理
console.log(error.code); let err = error as BusinessError;
console.log(`The createPhotoOutput call failed. error code: ${err.code}`);
}
return photoOutput;
} }
``` ```
...@@ -546,14 +610,20 @@ createVideoOutput(profile: VideoProfile, surfaceId: string): VideoOutput ...@@ -546,14 +610,20 @@ createVideoOutput(profile: VideoProfile, surfaceId: string): VideoOutput
**示例:** **示例:**
```js ```ts
let profile = cameraOutputCapability.videoProfiles[0]; import { BusinessError } from '@ohos.base';
let videoOutput;
try { function createVideoOutput(cameraOutputCapability: camera.CameraOutputCapability, cameraManager: camera.CameraManager, surfaceId: string): camera.VideoOutput {
let profile: camera.VideoProfile = cameraOutputCapability.videoProfiles[0];
let videoOutput: camera.VideoOutput;
try {
videoOutput = cameraManager.createVideoOutput(profile, surfaceId); videoOutput = cameraManager.createVideoOutput(profile, surfaceId);
} catch (error) { } catch (error) {
// 失败返回错误码error.code并处理 // 失败返回错误码error.code并处理
console.log(error.code); let err = error as BusinessError;
console.log(`The createPhotoOutput call failed. error code: ${err.code}`);
}
return videoOutput;
} }
``` ```
...@@ -587,14 +657,19 @@ createMetadataOutput(metadataObjectTypes:Array\<MetadataObjectType\>): MetadataO ...@@ -587,14 +657,19 @@ createMetadataOutput(metadataObjectTypes:Array\<MetadataObjectType\>): MetadataO
**示例:** **示例:**
```js ```ts
let metadataObjectTypes = cameraOutputCapability.supportedMetadataObjectTypes; import { BusinessError } from '@ohos.base';
let metadataOutput;
try { function createMetadataOutput(cameraManager: camera.CameraManager, cameraOutputCapability: camera.CameraOutputCapability): void {
let metadataObjectTypes: Array<camera.MetadataObjectType> = cameraOutputCapability.supportedMetadataObjectTypes;
let metadataOutput: camera.MetadataOutput;
try {
metadataOutput = cameraManager.createMetadataOutput(metadataObjectTypes); metadataOutput = cameraManager.createMetadataOutput(metadataObjectTypes);
} catch (error) { } catch (error) {
// 失败返回错误码error.code并处理 // 失败返回错误码error.code并处理
console.log(error.code); let err = error as BusinessError;
console.log(`createMetadataOutput error. error code: ${err.code}`);
}
} }
``` ```
...@@ -622,13 +697,19 @@ createCaptureSession(): CaptureSession ...@@ -622,13 +697,19 @@ createCaptureSession(): CaptureSession
**示例:** **示例:**
```js ```ts
let captureSession; import { BusinessError } from '@ohos.base';
try {
function createCaptureSession(cameraManager: camera.CameraManager): camera.CaptureSession {
let captureSession: camera.CaptureSession;
try {
captureSession = cameraManager.createCaptureSession(); captureSession = cameraManager.createCaptureSession();
} catch (error) { } catch (error) {
// 失败返回错误码error.code并处理 // 失败返回错误码error.code并处理
console.log(error.code); let err = error as BusinessError;
console.log(`createCaptureSession error. error code: ${err.code}`);
}
return captureSession;
} }
``` ```
...@@ -649,11 +730,15 @@ on(type: 'cameraStatus', callback: AsyncCallback\<CameraStatusInfo\>): void ...@@ -649,11 +730,15 @@ on(type: 'cameraStatus', callback: AsyncCallback\<CameraStatusInfo\>): void
**示例:** **示例:**
```js ```ts
cameraManager.on('cameraStatus', (err, cameraStatusInfo) => { import { BusinessError } from '@ohos.base';
function registerCameraStatus(cameraManager: camera.CameraManager): void {
cameraManager.on('cameraStatus', (err: BusinessError, cameraStatusInfo: camera.CameraStatusInfo) => {
console.log(`camera : ${cameraStatusInfo.camera.cameraId}`); console.log(`camera : ${cameraStatusInfo.camera.cameraId}`);
console.log(`status: ${cameraStatusInfo.status}`); console.log(`status: ${cameraStatusInfo.status}`);
}) });
}
``` ```
### off('cameraStatus') ### off('cameraStatus')
...@@ -673,8 +758,10 @@ off(type: 'cameraStatus', callback?: AsyncCallback\<CameraStatusInfo\>): void ...@@ -673,8 +758,10 @@ off(type: 'cameraStatus', callback?: AsyncCallback\<CameraStatusInfo\>): void
**示例:** **示例:**
```js ```ts
cameraManager.off('cameraStatus') function unregisterCameraStatus(cameraManager: camera.CameraManager): void {
cameraManager.off('cameraStatus');
}
``` ```
### on('cameraMute') ### on('cameraMute')
...@@ -696,10 +783,15 @@ on(type: 'cameraMute', callback: AsyncCallback\<boolean\>): void ...@@ -696,10 +783,15 @@ on(type: 'cameraMute', callback: AsyncCallback\<boolean\>): void
**示例:** **示例:**
```js ```ts
cameraManager.on('cameraMute', (err, curMuetd) => { import { BusinessError } from '@ohos.base';
let isMuted = curMuetd;
}) function registerCameraMute(cameraManager: camera.CameraManager): void {
cameraManager.on('cameraMute', (err: BusinessError, curMuted: boolean) => {
let isMuted: boolean = curMuted;
console.log(`cameraMute status: ${isMuted}`);
})
}
``` ```
### off('cameraMute') ### off('cameraMute')
...@@ -721,12 +813,17 @@ off(type: 'cameraMute', callback?: AsyncCallback\<boolean\>): void ...@@ -721,12 +813,17 @@ off(type: 'cameraMute', callback?: AsyncCallback\<boolean\>): void
**示例:** **示例:**
```js ```ts
func(err, curMuetd) { import { BusinessError } from '@ohos.base';
let isMuted = curMuetd;
function callback(err: BusinessError, curMuetd: boolean): void {
let isMuted: boolean = curMuetd;
}
function unregisterCameraMute(cameraManager: camera.CameraManager): void {
cameraManager.on('cameraMute', callback);
cameraManager.off('cameraMute', callback);
} }
cameraManager.on('cameraMute', func)
cameraManager.off('cameraMute', func)
``` ```
### isPrelaunchSupported ### isPrelaunchSupported
...@@ -761,11 +858,15 @@ isPrelaunchSupported(camera: CameraDevice): boolean ...@@ -761,11 +858,15 @@ isPrelaunchSupported(camera: CameraDevice): boolean
**示例:** **示例:**
```js ```ts
this.cameraManager = camera.getCameraManager(globalThis.abilityContext); import featureAbility from '@ohos.ability.featureAbility';
let cameras = this.cameraManager.getSupportedCameras()
if(this.cameraManager.isPrelaunchSupported(cameras[0])) { function isPreLaunchSupported(context: featureAbility.Context): boolean {
this.cameraManager.setPrelaunchConfig({cameraDevice: cameras[0]}); let cameraManager: camera.CameraManager = camera.getCameraManager(context);
let cameras: Array<camera.CameraDevice> = cameraManager.getSupportedCameras();
let isSupported: boolean = cameraManager.isPrelaunchSupported(cameras[0]);
console.log(`PreLaunch supported states: ${isSupported}`);
return isSupported;
} }
``` ```
...@@ -796,15 +897,21 @@ setPrelaunchConfig(prelaunchConfig: PrelaunchConfig): void ...@@ -796,15 +897,21 @@ setPrelaunchConfig(prelaunchConfig: PrelaunchConfig): void
**示例:** **示例:**
```js ```ts
this.cameraManager = camera.getCameraManager(globalThis.abilityContext); import featureAbility from '@ohos.ability.featureAbility';
let cameras = this.cameraManager.getSupportedCameras() import { BusinessError } from '@ohos.base';
if(this.cameraManager.isPrelaunchSupported(cameras[0])) {
function setPrelaunchConfig(context: featureAbility.Context): void {
let cameraManager: camera.CameraManager = camera.getCameraManager(context);
let cameras: Array<camera.CameraDevice> = cameraManager.getSupportedCameras();
if(cameraManager.isPrelaunchSupported(cameras[0])) {
try { try {
this.cameraManager.setPrelaunchConfig({cameraDevice: cameras[0]}); cameraManager.setPrelaunchConfig({cameraDevice: cameras[0]});
} catch (error) { } catch (error) {
console.error(`catch error: Code: ${error.code}, message: ${error.message}`); let err = error as BusinessError;
console.error(`setPrelaunchConfig error. Code: ${err.code}, message: ${err.message}`);
} }
}
} }
``` ```
...@@ -820,12 +927,18 @@ prelaunch(): void ...@@ -820,12 +927,18 @@ prelaunch(): void
**示例:** **示例:**
```js ```ts
this.cameraManager = camera.getCameraManager(globalThis.abilityContext); import featureAbility from '@ohos.ability.featureAbility';
try { import { BusinessError } from '@ohos.base';
this.cameraManager.prelaunch();
} catch (error) { function preLaunch(context: featureAbility.Context): void {
console.error(`catch error: Code: ${error.code}, message: ${error.message}`); let cameraManager: camera.CameraManager = camera.getCameraManager(context);
try {
cameraManager.prelaunch();
} catch (error) {
let err = error as BusinessError;
console.error(`prelaunch error. Code: ${error.code}, message: ${error.message}`);
}
} }
``` ```
...@@ -861,10 +974,10 @@ createDeferredPreviewOutput(profile: Profile): PreviewOutput ...@@ -861,10 +974,10 @@ createDeferredPreviewOutput(profile: Profile): PreviewOutput
**示例:** **示例:**
```js ```ts
function getDeferredPreviewOutput(context: Context, previewProfile: camera.Profile): Promise<PreviewOutput> { function getDeferredPreviewOutput(context: Context, previewProfile: camera.Profile): camera.PreviewOutput {
const cameraManager = camera.getCameraManager(context); const cameraManager: camera.CameraManager = camera.getCameraManager(context);
const output: Promise<PreviewOutput> = cameraManager.createDeferredPreviewOutput(previewProfile); const output: camera.PreviewOutput = cameraManager.createDeferredPreviewOutput(previewProfile);
return output; return output;
} }
``` ```
...@@ -896,9 +1009,11 @@ getSupportedModes(device: CameraDevice): Array\<CameraMode\> ...@@ -896,9 +1009,11 @@ getSupportedModes(device: CameraDevice): Array\<CameraMode\>
**示例:** **示例:**
```js ```ts
let cameraModes = cameraManager.getSupportedModes(cameraDevices[0]); function getSupportedModes(cameraManager: camera.CameraManager, cameraDevice: camera.CameraDevice): Array<camera.CameraMode> {
let cameraModes: Array<camera.CameraMode> = cameraManager.getSupportedModes(cameraDevice);
return cameraModes;
}
``` ```
### getSupportedOutputCapability ### getSupportedOutputCapability
...@@ -926,13 +1041,21 @@ getSupportedOutputCapability(device:CameraDevice, mode: CameraMode): CameraOutpu ...@@ -926,13 +1041,21 @@ getSupportedOutputCapability(device:CameraDevice, mode: CameraMode): CameraOutpu
**示例:** **示例:**
```js ```ts
let cameras = cameraManager.getSupportedCameras(); function getSupportedOutputCapability(cameraManager: camera.CameraManager, modeManager: camera.ModeManager): camera.CameraOutputCapability {
let cameraDevice = cameras[0]; let cameras: Array<camera.CameraDevice> = cameraManager.getSupportedCameras();
let cameraModes = modeManager.getSupportedModes(cameraDevice); if (cameras == undefined || cameras.length <= 0) {
let mode = cameraModes[0] return;
let cameraOutputCapability = modeManager.getSupportedOutputCapability(cameraDevice, mode); }
let cameraDevice: camera.CameraDevice = cameras[0];
let cameraModes: Array<camera.CameraMode> = modeManager.getSupportedModes(cameraDevice);
if (cameraModes === undefined || cameraModes.length <= 0) {
return;
}
let mode: camera.CameraMode = cameraModes[0];
let cameraOutputCapability: camera.CameraOutputCapability = modeManager.getSupportedOutputCapability(cameraDevice, mode);
return cameraOutputCapability;
}
``` ```
### createCaptureSession ### createCaptureSession
...@@ -958,13 +1081,29 @@ createCaptureSession(mode: CameraMode): CaptureSession ...@@ -958,13 +1081,29 @@ createCaptureSession(mode: CameraMode): CaptureSession
**示例:** **示例:**
```js ```ts
let cameras = cameraManager.getSupportedCameras(); import { BusinessError } from '@ohos.base';
let cameraDevice = cameras[0];
let cameraModes = modeManager.getSupportedModes(cameraDevice); function createCaptureSession(cameraManager: camera.CameraManager, modeManager: camera.ModeManager): camera.CaptureSession {
let mode = cameraModes[0] let cameras: Array<camera.CameraDevice> = cameraManager.getSupportedCameras();
let captureSession = modeManager.createCaptureSession(mode); if (cameras == undefined || cameras.length <= 0) {
return;
}
let cameraDevice: camera.CameraDevice = cameras[0];
let cameraModes: Array<camera.CameraMode> = modeManager.getSupportedModes(cameraDevice);
if (cameraModes === undefined || cameraModes.length <= 0) {
return;
}
let mode: camera.CameraMode = cameraModes[0];
let captureSession: camera.CaptureSession
try {
captureSession = modeManager.createCaptureSession(mode);
} catch (error) {
let err = error as BusinessError;
console.error(`The createCaptureSession call failed. error code: ${err.code}`);
}
return captureSession;
}
``` ```
## PrelaunchConfig ## PrelaunchConfig
...@@ -1123,14 +1262,18 @@ open\(callback: AsyncCallback\<void\>\): void ...@@ -1123,14 +1262,18 @@ open\(callback: AsyncCallback\<void\>\): void
**示例:** **示例:**
```js ```ts
cameraInput.open((err) => { import { BusinessError } from '@ohos.base';
function openCameraInput(cameraInput: camera.CameraInput): void {
cameraInput.open((err: BusinessError) => {
if (err) { if (err) {
console.error(`Failed to open the camera. ${err.code}`); console.error(`Failed to open the camera. ${err.code}`);
return; return;
} }
console.log('Callback returned with camera opened.'); console.log('Callback returned with camera opened.');
}) });
}
``` ```
### open ### open
...@@ -1159,12 +1302,16 @@ open(): Promise\<void\> ...@@ -1159,12 +1302,16 @@ open(): Promise\<void\>
**示例:** **示例:**
```js ```ts
cameraInput.open().then(() => { import { BusinessError } from '@ohos.base';
function openCameraInput(cameraInput: camera.CameraInput): void {
cameraInput.open().then(() => {
console.log('Promise returned with camera opened.'); console.log('Promise returned with camera opened.');
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`Failed to open the camera. ${err.code}`); console.error(`Failed to open the camera. ${err.code}`);
}); });
}
``` ```
### close ### close
...@@ -1191,14 +1338,18 @@ close\(callback: AsyncCallback\<void\>\): void ...@@ -1191,14 +1338,18 @@ close\(callback: AsyncCallback\<void\>\): void
**示例:** **示例:**
```js ```ts
cameraInput.close((err) => { import { BusinessError } from '@ohos.base';
function closeCameraInput(cameraInput: camera.CameraInput): void {
cameraInput.close((err: BusinessError) => {
if (err) { if (err) {
console.error(`Failed to close the cameras. ${err.code}`); console.error(`Failed to close the cameras. ${err.code}`);
return; return;
} }
console.log('Callback returned with camera closed.'); console.log('Callback returned with camera closed.');
}) });
}
``` ```
### close ### close
...@@ -1225,12 +1376,16 @@ close(): Promise\<void\> ...@@ -1225,12 +1376,16 @@ close(): Promise\<void\>
**示例:** **示例:**
```js ```ts
cameraInput.close().then(() => { import { BusinessError } from '@ohos.base';
function closeCameraInput(cameraInput: camera.CameraInput): void {
cameraInput.close().then(() => {
console.log('Promise returned with camera closed.'); console.log('Promise returned with camera closed.');
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`Failed to close the cameras. ${err.code}`); console.error(`Failed to close the cameras. ${err.code}`);
}); });
}
``` ```
### on('error') ### on('error')
...@@ -1251,10 +1406,14 @@ on(type: 'error', camera:CameraDevice, callback: ErrorCallback): void ...@@ -1251,10 +1406,14 @@ on(type: 'error', camera:CameraDevice, callback: ErrorCallback): void
**示例:** **示例:**
```js ```ts
cameraInput.on('error', cameraDevice, (error) => { import { BusinessError } from '@ohos.base';
function registerCameraInputError(cameraInput: camera.CameraInput, cameraDevice: camera.CameraDevice): void {
cameraInput.on('error', cameraDevice, (error: BusinessError) => {
console.log(`Camera input error code: ${error.code}`); console.log(`Camera input error code: ${error.code}`);
}) });
}
``` ```
### off('error') ### off('error')
...@@ -1275,8 +1434,11 @@ off(type: 'error', camera:CameraDevice, callback?: ErrorCallback): void ...@@ -1275,8 +1434,11 @@ off(type: 'error', camera:CameraDevice, callback?: ErrorCallback): void
**示例:** **示例:**
```js ```ts
cameraInput.off('error', cameraDevice)
function unregisterCameraInputError(cameraInput: camera.CameraInput, cameraDevice: camera.CameraDevice): void {
cameraInput.off('error', cameraDevice);
}
``` ```
## FlashMode ## FlashMode
...@@ -1371,12 +1533,17 @@ beginConfig(): void ...@@ -1371,12 +1533,17 @@ beginConfig(): void
**示例:** **示例:**
```js ```ts
try { import { BusinessError } from '@ohos.base';
function beginConfig(captureSession: camera.CaptureSession): void {
try {
captureSession.beginConfig(); captureSession.beginConfig();
} catch (error) { } catch (error) {
// 失败返回错误码error.code并处理 // 失败返回错误码error.code并处理
console.log(error.code); let err = error as BusinessError;
console.error(`The beginConfig call failed. error code: ${err.code}`);
}
} }
``` ```
...@@ -1405,14 +1572,18 @@ commitConfig(callback: AsyncCallback\<void\>): void ...@@ -1405,14 +1572,18 @@ commitConfig(callback: AsyncCallback\<void\>): void
**示例:** **示例:**
```js ```ts
captureSession.commitConfig((err) => { import { BusinessError } from '@ohos.base';
function commitConfig(captureSession: camera.CaptureSession): void {
captureSession.commitConfig((err: BusinessError) => {
if (err) { if (err) {
console.log('Failed to commitConfig '+ err.code); console.error(`The commitConfig call failed. error code: ${err.code}`);
return; return;
} }
console.log('Callback invoked to indicate the commit config success.'); console.log('Callback invoked to indicate the commit config success.');
}); });
}
``` ```
### commitConfig ### commitConfig
...@@ -1440,13 +1611,17 @@ commitConfig(): Promise\<void\> ...@@ -1440,13 +1611,17 @@ commitConfig(): Promise\<void\>
**示例:** **示例:**
```js ```ts
captureSession.commitConfig().then(() => { import { BusinessError } from '@ohos.base';
function commitConfig(captureSession: camera.CaptureSession): void {
captureSession.commitConfig().then(() => {
console.log('Promise returned to indicate the commit config success.'); console.log('Promise returned to indicate the commit config success.');
}).catch((err) => { }).catch((err: BusinessError) => {
// 失败返回错误码error.code并处理 // 失败返回错误码error.code并处理
console.log('Failed to commitConfig '+ err.code); console.error(`The commitConfig call failed. error code: ${err.code}`);
}); });
}
``` ```
### addInput ### addInput
...@@ -1480,12 +1655,17 @@ addInput(cameraInput: CameraInput): void ...@@ -1480,12 +1655,17 @@ addInput(cameraInput: CameraInput): void
**示例:** **示例:**
```js ```ts
try { import { BusinessError } from '@ohos.base';
function addInput(captureSession: camera.CaptureSession, cameraInput: camera.CameraInput): void {
try {
captureSession.addInput(cameraInput); captureSession.addInput(cameraInput);
} catch (error) { } catch (error) {
// 失败返回错误码error.code并处理 // 失败返回错误码error.code并处理
console.log(error.code); let err = error as BusinessError;
console.log(`The addInput call failed. error code: ${err.code}`);
}
} }
``` ```
...@@ -1520,12 +1700,17 @@ removeInput(cameraInput: CameraInput): void ...@@ -1520,12 +1700,17 @@ removeInput(cameraInput: CameraInput): void
**示例:** **示例:**
```js ```ts
try { import { BusinessError } from '@ohos.base';
function removeInput(captureSession: camera.CaptureSession, cameraInput: camera.CameraInput): void {
try {
captureSession.removeInput(cameraInput); captureSession.removeInput(cameraInput);
} catch (error) { } catch (error) {
// 失败返回错误码error.code并处理 // 失败返回错误码error.code并处理
console.log(error.code); let err = error as BusinessError;
console.log(`The removeInput call failed. error code: ${err.code}`);
}
} }
``` ```
...@@ -1560,12 +1745,17 @@ addOutput(cameraOutput: CameraOutput): void ...@@ -1560,12 +1745,17 @@ addOutput(cameraOutput: CameraOutput): void
**示例:** **示例:**
```js ```ts
try { import { BusinessError } from '@ohos.base';
function addOutput(captureSession: camera.CaptureSession, cameraOutput: camera.CameraOutput): void {
try {
captureSession.addOutput(cameraOutput); captureSession.addOutput(cameraOutput);
} catch (error) { } catch (error) {
// 失败返回错误码error.code并处理 // 失败返回错误码error.code并处理
console.log(error.code); let err = error as BusinessError;
console.log(`The addOutput call failed. error code: ${err.code}`);
}
} }
``` ```
...@@ -1600,12 +1790,17 @@ removeOutput(cameraOutput: CameraOutput): void ...@@ -1600,12 +1790,17 @@ removeOutput(cameraOutput: CameraOutput): void
**示例:** **示例:**
```js ```ts
try { import { BusinessError } from '@ohos.base';
function removeOutput(captureSession: camera.CaptureSession, previewOutput: camera.PreviewOutput): void {
try {
captureSession.removeOutput(previewOutput); captureSession.removeOutput(previewOutput);
} catch (error) { } catch (error) {
// 失败返回错误码error.code并处理 // 失败返回错误码error.code并处理
console.log(error.code); let err = error as BusinessError;
console.log(`The removeOutput call failed. error code: ${err.code}`);
}
} }
``` ```
...@@ -1634,14 +1829,18 @@ start\(callback: AsyncCallback\<void\>\): void ...@@ -1634,14 +1829,18 @@ start\(callback: AsyncCallback\<void\>\): void
**示例:** **示例:**
```js ```ts
captureSession.start((err) => { import { BusinessError } from '@ohos.base';
function startCaptureSession(captureSession: camera.CaptureSession): void {
captureSession.start((err: BusinessError) => {
if (err) { if (err) {
console.error(`Failed to start the session ${err.code}`); console.error(`Failed to start the session ${err.code}`);
return; return;
} }
console.log('Callback invoked to indicate the session start success.'); console.log('Callback invoked to indicate the session start success.');
}); });
}
``` ```
### start ### start
...@@ -1669,12 +1868,16 @@ start\(\): Promise\<void\> ...@@ -1669,12 +1868,16 @@ start\(\): Promise\<void\>
**示例:** **示例:**
```js ```ts
captureSession.start().then(() => { import { BusinessError } from '@ohos.base';
function startCaptureSession(captureSession: camera.CaptureSession): void {
captureSession.start().then(() => {
console.log('Promise returned to indicate the session start success.'); console.log('Promise returned to indicate the session start success.');
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`Failed to start the session ${err.code}`); console.error(`Failed to start the session ${err.code}`);
}); });
}
``` ```
### stop ### stop
...@@ -1701,14 +1904,18 @@ stop\(callback: AsyncCallback\<void\>\): void ...@@ -1701,14 +1904,18 @@ stop\(callback: AsyncCallback\<void\>\): void
**示例:** **示例:**
```js ```ts
captureSession.stop((err) => { import { BusinessError } from '@ohos.base';
function stopCaptureSession(captureSession: camera.CaptureSession): void {
captureSession.stop((err: BusinessError) => {
if (err) { if (err) {
console.error(`Failed to stop the session ${err.code}`); console.error(`Failed to stop the session ${err.code}`);
return; return;
} }
console.log('Callback invoked to indicate the session stop success.'); console.log('Callback invoked to indicate the session stop success.');
}); });
}
``` ```
### stop ### stop
...@@ -1735,12 +1942,16 @@ stop(): Promise\<void\> ...@@ -1735,12 +1942,16 @@ stop(): Promise\<void\>
**示例:** **示例:**
```js ```ts
captureSession.stop().then(() => { import { BusinessError } from '@ohos.base';
function stopCaptureSession(captureSession: camera.CaptureSession): void {
captureSession.stop().then(() => {
console.log('Promise returned to indicate the session stop success.'); console.log('Promise returned to indicate the session stop success.');
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`Failed to stop the session ${err.code}`); console.error(`Failed to stop the session ${err.code}`);
}); });
}
``` ```
### release ### release
...@@ -1767,14 +1978,18 @@ release\(callback: AsyncCallback\<void\>\): void ...@@ -1767,14 +1978,18 @@ release\(callback: AsyncCallback\<void\>\): void
**示例:** **示例:**
```js ```ts
captureSession.release((err) => { import { BusinessError } from '@ohos.base';
function releaseCaptureSession(captureSession: camera.CaptureSession): void {
captureSession.release((err: BusinessError) => {
if (err) { if (err) {
console.error(`Failed to release the CaptureSession instance ${err.code}`); console.error(`Failed to release the CaptureSession instance ${err.code}`);
return; return;
} }
console.log('Callback invoked to indicate that the CaptureSession instance is released successfully.'); console.log('Callback invoked to indicate that the CaptureSession instance is released successfully.');
}); });
}
``` ```
### release ### release
...@@ -1801,12 +2016,16 @@ release(): Promise\<void\> ...@@ -1801,12 +2016,16 @@ release(): Promise\<void\>
**示例:** **示例:**
```js ```ts
captureSession.release().then(() => { import { BusinessError } from '@ohos.base';
function releaseCaptureSession(captureSession: camera.CaptureSession): void {
captureSession.release().then(() => {
console.log('Promise returned to indicate that the CaptureSession instance is released successfully.'); console.log('Promise returned to indicate that the CaptureSession instance is released successfully.');
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`Failed to release the CaptureSession instance ${err.code}`); console.error(`Failed to release the CaptureSession instance ${err.code}`);
}); });
}
``` ```
### hasFlash ### hasFlash
...@@ -1833,12 +2052,19 @@ hasFlash(): boolean ...@@ -1833,12 +2052,19 @@ hasFlash(): boolean
**示例:** **示例:**
```js ```ts
try { import { BusinessError } from '@ohos.base';
let status = captureSession.hasFlash();
} catch (error) { function hasFlash(captureSession: camera.CaptureSession): boolean {
let status: boolean = false;
try {
status = captureSession.hasFlash();
} catch (error) {
// 失败返回错误码error.code并处理 // 失败返回错误码error.code并处理
console.log(error.code); let err = error as BusinessError;
console.error(`The hasFlash call failed. error code: ${err.code}`);
}
return status;
} }
``` ```
...@@ -1872,12 +2098,19 @@ isFlashModeSupported(flashMode: FlashMode): boolean ...@@ -1872,12 +2098,19 @@ isFlashModeSupported(flashMode: FlashMode): boolean
**示例:** **示例:**
```js ```ts
try { import { BusinessError } from '@ohos.base';
let status = captureSession.isFlashModeSupported(camera.FlashMode.FLASH_MODE_AUTO);
} catch (error) { function isFlashModeSupported(captureSession: camera.CaptureSession): boolean {
let status: boolean = false;
try {
status = captureSession.isFlashModeSupported(camera.FlashMode.FLASH_MODE_AUTO);
} catch (error) {
// 失败返回错误码error.code并处理 // 失败返回错误码error.code并处理
console.log(error.code); let err = error as BusinessError;
console.error(`The isFlashModeSupported call failed. error code: ${err.code}`);
}
return status;
} }
``` ```
...@@ -1916,12 +2149,17 @@ setFlashMode(flashMode: FlashMode): void ...@@ -1916,12 +2149,17 @@ setFlashMode(flashMode: FlashMode): void
**示例:** **示例:**
```js ```ts
try { import { BusinessError } from '@ohos.base';
function setFlashMode(captureSession: camera.CaptureSession): void {
try {
captureSession.setFlashMode(camera.FlashMode.FLASH_MODE_AUTO); captureSession.setFlashMode(camera.FlashMode.FLASH_MODE_AUTO);
} catch (error) { } catch (error) {
// 失败返回错误码error.code并处理 // 失败返回错误码error.code并处理
console.log(error.code); let err = error as BusinessError;
console.error(`The setFlashMode call failed. error code: ${err.code}`);
}
} }
``` ```
...@@ -1949,12 +2187,19 @@ getFlashMode(): FlashMode ...@@ -1949,12 +2187,19 @@ getFlashMode(): FlashMode
**示例:** **示例:**
```js ```ts
try { import { BusinessError } from '@ohos.base';
let flashMode = captureSession.getFlashMode();
} catch (error) { function getFlashMode(captureSession: camera.CaptureSession): camera.FlashMode {
let flashMode: camera.FlashMode;
try {
flashMode = captureSession.getFlashMode();
} catch (error) {
// 失败返回错误码error.code并处理 // 失败返回错误码error.code并处理
console.log(error.code); let err = error as BusinessError;
console.error(`The getFlashMode call failed.error code: ${err.code}`);
}
return flashMode;
} }
``` ```
...@@ -1988,12 +2233,19 @@ isExposureModeSupported(aeMode: ExposureMode): boolean; ...@@ -1988,12 +2233,19 @@ isExposureModeSupported(aeMode: ExposureMode): boolean;
**示例:** **示例:**
```js ```ts
try { import { BusinessError } from '@ohos.base';
let isSupported = captureSession.isExposureModeSupported(camera.ExposureMode.EXPOSURE_MODE_LOCKED);
} catch (error) { function isExposureModeSupported(captureSession: camera.CaptureSession): boolean {
let isSupported: boolean;
try {
isSupported = captureSession.isExposureModeSupported(camera.ExposureMode.EXPOSURE_MODE_LOCKED);
} catch (error) {
// 失败返回错误码error.code并处理 // 失败返回错误码error.code并处理
console.log(error.code); let err = error as BusinessError;
console.error(`The isExposureModeSupported call failed. error code: ${err.code}`);
}
return isSupported;
} }
``` ```
...@@ -2021,12 +2273,19 @@ getExposureMode(): ExposureMode ...@@ -2021,12 +2273,19 @@ getExposureMode(): ExposureMode
**示例:** **示例:**
```js ```ts
try { import { BusinessError } from '@ohos.base';
let exposureMode = captureSession.getExposureMode();
} catch (error) { function getExposureMode(captureSession: camera.CaptureSession): camera.ExposureMode {
let exposureMode: camera.ExposureMode;
try {
exposureMode = captureSession.getExposureMode();
} catch (error) {
// 失败返回错误码error.code并处理 // 失败返回错误码error.code并处理
console.log(error.code); let err = error as BusinessError;
console.error(`The getExposureMode call failed. error code: ${err.code}`);
}
return exposureMode;
} }
``` ```
...@@ -2060,12 +2319,17 @@ setExposureMode(aeMode: ExposureMode): void ...@@ -2060,12 +2319,17 @@ setExposureMode(aeMode: ExposureMode): void
**示例:** **示例:**
```js ```ts
try { import { BusinessError } from '@ohos.base';
function setExposureMode(captureSession: camera.CaptureSession): void {
try {
captureSession.setExposureMode(camera.ExposureMode.EXPOSURE_MODE_LOCKED); captureSession.setExposureMode(camera.ExposureMode.EXPOSURE_MODE_LOCKED);
} catch (error) { } catch (error) {
// 失败返回错误码error.code并处理 // 失败返回错误码error.code并处理
console.log(error.code); let err = error as BusinessError;
console.error(`The setExposureMode call failed. error code: ${err.code}`);
}
} }
``` ```
...@@ -2093,12 +2357,19 @@ getMeteringPoint(): Point ...@@ -2093,12 +2357,19 @@ getMeteringPoint(): Point
**示例:** **示例:**
```js ```ts
try { import { BusinessError } from '@ohos.base';
let exposurePoint = captureSession.getMeteringPoint();
} catch (error) { function getMeteringPoint(captureSession: camera.CaptureSession): camera.Point {
let exposurePoint: camera.Point;
try {
exposurePoint = captureSession.getMeteringPoint();
} catch (error) {
// 失败返回错误码error.code并处理 // 失败返回错误码error.code并处理
console.log(error.code); let err = error as BusinessError;
console.error(`The getMeteringPoint call failed. error code: ${err.code}`);
}
return exposurePoint;
} }
``` ```
...@@ -2135,13 +2406,18 @@ setMeteringPoint(point: Point): void ...@@ -2135,13 +2406,18 @@ setMeteringPoint(point: Point): void
**示例:** **示例:**
```js ```ts
const exposurePoint = {x: 1, y: 1}; import { BusinessError } from '@ohos.base';
try {
function setMeteringPoint(captureSession: camera.CaptureSession): void {
const exposurePoint: camera.Point = {x: 1, y: 1};
try {
captureSession.setMeteringPoint(exposurePoint); captureSession.setMeteringPoint(exposurePoint);
} catch (error) { } catch (error) {
// 失败返回错误码error.code并处理 // 失败返回错误码error.code并处理
console.log(error.code); let err = error as BusinessError;
console.error(`The setMeteringPoint call failed. error code: ${err.code}`);
}
} }
``` ```
...@@ -2169,12 +2445,19 @@ getExposureBiasRange(): Array\<number\> ...@@ -2169,12 +2445,19 @@ getExposureBiasRange(): Array\<number\>
**示例:** **示例:**
```js ```ts
try { import { BusinessError } from '@ohos.base';
let biasRangeArray = captureSession.getExposureBiasRange();
} catch (error) { function getExposureBiasRange(captureSession: camera.CaptureSession): Array<number> {
let biasRangeArray: Array<number>;
try {
biasRangeArray = captureSession.getExposureBiasRange();
} catch (error) {
// 失败返回错误码error.code并处理 // 失败返回错误码error.code并处理
console.log(error.code); let err = error as BusinessError;
console.error(`The getExposureBiasRange call failed. error code: ${err.code}`);
}
return biasRangeArray;
} }
``` ```
...@@ -2204,13 +2487,18 @@ setExposureBias(exposureBias: number): void ...@@ -2204,13 +2487,18 @@ setExposureBias(exposureBias: number): void
**示例:** **示例:**
```js ```ts
let exposureBias = biasRangeArray[0]; import { BusinessError } from '@ohos.base';
try {
function setExposureBias(captureSession: camera.CaptureSession, biasRangeArray: Array<number>): void {
let exposureBias = biasRangeArray[0];
try {
captureSession.setExposureBias(exposureBias); captureSession.setExposureBias(exposureBias);
} catch (error) { } catch (error) {
// 失败返回错误码error.code并处理 // 失败返回错误码error.code并处理
console.log(error.code); let err = error as BusinessError;
console.error(`The setExposureBias call failed. error code: ${err.code}`);
}
} }
``` ```
...@@ -2238,12 +2526,19 @@ getExposureValue(): number ...@@ -2238,12 +2526,19 @@ getExposureValue(): number
**示例:** **示例:**
```js ```ts
try { import { BusinessError } from '@ohos.base';
let exposureValue = captureSession.getExposureValue();
} catch (error) { function getExposureValue(captureSession: camera.CaptureSession): number {
let exposureValue: number;
try {
exposureValue = captureSession.getExposureValue();
} catch (error) {
// 失败返回错误码error.code并处理 // 失败返回错误码error.code并处理
console.log(error.code); let err = error as BusinessError;
console.error(`The getExposureValue call failed. error code: ${err.code}`);
}
return exposureValue;
} }
``` ```
...@@ -2277,12 +2572,19 @@ isFocusModeSupported(afMode: FocusMode): boolean ...@@ -2277,12 +2572,19 @@ isFocusModeSupported(afMode: FocusMode): boolean
**示例:** **示例:**
```js ```ts
try { import { BusinessError } from '@ohos.base';
let status = captureSession.isFocusModeSupported(camera.FocusMode.FOCUS_MODE_AUTO);
} catch (error) { function isFocusModeSupported(captureSession: camera.CaptureSession): boolean {
let status: boolean = false;
try {
status = captureSession.isFocusModeSupported(camera.FocusMode.FOCUS_MODE_AUTO);
} catch (error) {
// 失败返回错误码error.code并处理 // 失败返回错误码error.code并处理
console.log(error.code); let err = error as BusinessError;
console.error(`The isFocusModeSupported call failed. error code: ${err.code}`);
}
return status;
} }
``` ```
...@@ -2318,12 +2620,17 @@ setFocusMode(afMode: FocusMode): void ...@@ -2318,12 +2620,17 @@ setFocusMode(afMode: FocusMode): void
**示例:** **示例:**
```js ```ts
try { import { BusinessError } from '@ohos.base';
function setFocusMode(captureSession: camera.CaptureSession): void {
try {
captureSession.setFocusMode(camera.FocusMode.FOCUS_MODE_AUTO); captureSession.setFocusMode(camera.FocusMode.FOCUS_MODE_AUTO);
} catch (error) { } catch (error) {
// 失败返回错误码error.code并处理 // 失败返回错误码error.code并处理
console.log(error.code); let err = error as BusinessError;
console.error(`The setFocusMode call failed. error code: ${err.code}`);
}
} }
``` ```
...@@ -2351,12 +2658,19 @@ getFocusMode(): FocusMode ...@@ -2351,12 +2658,19 @@ getFocusMode(): FocusMode
**示例:** **示例:**
```js ```ts
try { import { BusinessError } from '@ohos.base';
let afMode = captureSession.getFocusMode();
} catch (error) { function getFocusMode(captureSession: camera.CaptureSession): camera.FocusMode {
let afMode: camera.FocusMode;
try {
afMode = captureSession.getFocusMode();
} catch (error) {
// 失败返回错误码error.code并处理 // 失败返回错误码error.code并处理
console.log(error.code); let err = error as BusinessError;
console.error(`The getFocusMode call failed. error code: ${err.code}`);
}
return afMode;
} }
``` ```
...@@ -2393,13 +2707,18 @@ setFocusPoint(point: Point): void ...@@ -2393,13 +2707,18 @@ setFocusPoint(point: Point): void
**示例:** **示例:**
```js ```ts
const Point1 = {x: 1, y: 1}; import { BusinessError } from '@ohos.base';
try {
function setFocusPoint(captureSession: camera.CaptureSession): void {
const Point1: camera.Point = {x: 1, y: 1};
try {
captureSession.setFocusPoint(Point1); captureSession.setFocusPoint(Point1);
} catch (error) { } catch (error) {
// 失败返回错误码error.code并处理 // 失败返回错误码error.code并处理
console.log(error.code); let err = error as BusinessError;
console.error(`The setFocusPoint call failed. error code: ${err.code}`);
}
} }
``` ```
...@@ -2427,12 +2746,19 @@ getFocusPoint(): Point ...@@ -2427,12 +2746,19 @@ getFocusPoint(): Point
**示例:** **示例:**
```js ```ts
try { import { BusinessError } from '@ohos.base';
let point = captureSession.getFocusPoint();
} catch (error) { function getFocusPoint(captureSession: camera.CaptureSession): camera.Point {
let point: camera.Point;
try {
point = captureSession.getFocusPoint();
} catch (error) {
// 失败返回错误码error.code并处理 // 失败返回错误码error.code并处理
console.log(error.code); let err = error as BusinessError;
console.error(`The getFocusPoint call failed. error code: ${err.code}`);
}
return point;
} }
``` ```
...@@ -2460,12 +2786,19 @@ getFocalLength(): number ...@@ -2460,12 +2786,19 @@ getFocalLength(): number
**示例:** **示例:**
```js ```ts
try { import { BusinessError } from '@ohos.base';
let focalLength = captureSession.getFocalLength();
} catch (error) { function getFocalLength(captureSession: camera.CaptureSession): number {
let focalLength: number;
try {
focalLength = captureSession.getFocalLength();
} catch (error) {
// 失败返回错误码error.code并处理 // 失败返回错误码error.code并处理
console.log(error.code); let err = error as BusinessError;
console.error(`The getFocalLength call failed. error code: ${err.code}`);
}
return focalLength;
} }
``` ```
...@@ -2493,12 +2826,19 @@ getZoomRatioRange(): Array\<number\> ...@@ -2493,12 +2826,19 @@ getZoomRatioRange(): Array\<number\>
**示例:** **示例:**
```js ```ts
try { import { BusinessError } from '@ohos.base';
let zoomRatioRange = captureSession.getZoomRatioRange();
} catch (error) { function getZoomRatioRange(captureSession: camera.CaptureSession): Array<number> {
let zoomRatioRange: Array<number>;
try {
zoomRatioRange = captureSession.getZoomRatioRange();
} catch (error) {
// 失败返回错误码error.code并处理 // 失败返回错误码error.code并处理
console.log(error.code); let err = error as BusinessError;
console.error(`The getZoomRatioRange call failed. error code: ${err.code}`);
}
return zoomRatioRange;
} }
``` ```
...@@ -2532,13 +2872,21 @@ setZoomRatio(zoomRatio: number): void ...@@ -2532,13 +2872,21 @@ setZoomRatio(zoomRatio: number): void
**示例:** **示例:**
```js ```ts
let zoomRatio = zoomRatioRange[0]; import { BusinessError } from '@ohos.base';
try {
function setZoomRatio(captureSession: camera.CaptureSession, zoomRatioRange: Array<number>): void {
if (zoomRatioRange === undefined || zoomRatioRange.length <= 0) {
return;
}
let zoomRatio = zoomRatioRange[0];
try {
captureSession.setZoomRatio(zoomRatio); captureSession.setZoomRatio(zoomRatio);
} catch (error) { } catch (error) {
// 失败返回错误码error.code并处理 // 失败返回错误码error.code并处理
console.log(error.code); let err = error as BusinessError;
console.error(`The setZoomRatio call failed. error code: ${err.code}`);
}
} }
``` ```
...@@ -2566,12 +2914,19 @@ getZoomRatio(): number ...@@ -2566,12 +2914,19 @@ getZoomRatio(): number
**示例:** **示例:**
```js ```ts
try { import { BusinessError } from '@ohos.base';
let zoomRatio = captureSession.getZoomRatio();
} catch (error) { function getZoomRatio(captureSession: camera.CaptureSession): number {
let zoomRatio: number;
try {
zoomRatio = captureSession.getZoomRatio();
} catch (error) {
// 失败返回错误码error.code并处理 // 失败返回错误码error.code并处理
console.log(error.code); let err = error as BusinessError;
console.error(`The getZoomRatio call failed. error code: ${err.code}`);
}
return zoomRatio;
} }
``` ```
...@@ -2605,12 +2960,19 @@ isVideoStabilizationModeSupported(vsMode: VideoStabilizationMode): boolean ...@@ -2605,12 +2960,19 @@ isVideoStabilizationModeSupported(vsMode: VideoStabilizationMode): boolean
**示例:** **示例:**
```js ```ts
try { import { BusinessError } from '@ohos.base';
let isSupported = captureSession.isVideoStabilizationModeSupported(camera.VideoStabilizationMode.OFF);
} catch (error) { function isVideoStabilizationModeSupported(captureSession: camera.CaptureSession): boolean {
let isSupported: boolean = false;
try {
isSupported = captureSession.isVideoStabilizationModeSupported(camera.VideoStabilizationMode.OFF);
} catch (error) {
// 失败返回错误码error.code并处理 // 失败返回错误码error.code并处理
console.log(error.code); let err = error as BusinessError;
console.error(`The isVideoStabilizationModeSupported call failed. error code: ${err.code}`);
}
return isSupported;
} }
``` ```
...@@ -2638,12 +3000,19 @@ getActiveVideoStabilizationMode(): VideoStabilizationMode ...@@ -2638,12 +3000,19 @@ getActiveVideoStabilizationMode(): VideoStabilizationMode
**示例:** **示例:**
```js ```ts
try { import { BusinessError } from '@ohos.base';
let vsMode = captureSession.getActiveVideoStabilizationMode();
} catch (error) { function getActiveVideoStabilizationMode(captureSession: camera.CaptureSession): camera.VideoStabilizationMode {
let vsMode: camera.VideoStabilizationMode;
try {
vsMode = captureSession.getActiveVideoStabilizationMode();
} catch (error) {
// 失败返回错误码error.code并处理 // 失败返回错误码error.code并处理
console.log(error.code); let err = error as BusinessError;
console.error(`The getActiveVideoStabilizationMode call failed. error code: ${err.code}`);
}
return vsMode;
} }
``` ```
...@@ -2677,12 +3046,17 @@ setVideoStabilizationMode(mode: VideoStabilizationMode): void ...@@ -2677,12 +3046,17 @@ setVideoStabilizationMode(mode: VideoStabilizationMode): void
**示例:** **示例:**
```js ```ts
try { import { BusinessError } from '@ohos.base';
function setVideoStabilizationMode(captureSession: camera.CaptureSession): void {
try {
captureSession.setVideoStabilizationMode(camera.VideoStabilizationMode.OFF); captureSession.setVideoStabilizationMode(camera.VideoStabilizationMode.OFF);
} catch (error) { } catch (error) {
// 失败返回错误码error.code并处理 // 失败返回错误码error.code并处理
console.log(error.code); let err = error as BusinessError;
console.error(`The setVideoStabilizationMode call failed. error code: ${err.code}`);
}
} }
``` ```
### getSupportedFilters ### getSupportedFilters
...@@ -2711,8 +3085,11 @@ getSupportedFilters(): Array\<number> ...@@ -2711,8 +3085,11 @@ getSupportedFilters(): Array\<number>
**示例:** **示例:**
```js ```ts
let FilterTypes = captureSession.getSupportedFilters(); function getSupportedFilters(captureSession: camera.CaptureSession): Array<camera.FilterType> {
let filterTypes: Array<camera.FilterType> = captureSession.getSupportedFilters();
return filterTypes;
}
``` ```
### setFilter ### setFilter
...@@ -2741,10 +3118,12 @@ setFilter(filter: number): void ...@@ -2741,10 +3118,12 @@ setFilter(filter: number): void
**示例:** **示例:**
```js ```ts
let FilterTypes = captureSession.getSupportedFilters(); function setFilter(captureSession: camera.CaptureSession, filterTypes: Array<camera.FilterType>): void {
if (!FilterTypes.empty()) { if (filterTypes === undefined || filterTypes.length <= 0) {
captureSession.setFilter(FilterTypes[0]); return;
}
captureSession.setFilter(filterTypes[0]);
} }
``` ```
...@@ -2774,8 +3153,11 @@ if (!FilterTypes.empty()) { ...@@ -2774,8 +3153,11 @@ if (!FilterTypes.empty()) {
**示例:** **示例:**
```js ```ts
let FilterType = captureSession.getFilter(); function getFilter(captureSession: camera.CaptureSession): number {
let filterType: number = captureSession.getFilter();
return filterType;
}
``` ```
### getSupportedBeautyTypes ### getSupportedBeautyTypes
...@@ -2803,8 +3185,11 @@ getSupportedBeautyTypes(): Array<[BeautyType](#beautytype)> ...@@ -2803,8 +3185,11 @@ getSupportedBeautyTypes(): Array<[BeautyType](#beautytype)>
**示例:** **示例:**
```js ```ts
let FilterTypes = captureSession.getSupportedBeautyTypes(); function getSupportedBeautyTypes(captureSession: camera.CaptureSession): Array<camera.BeautyType> {
let beautyTypes: Array<camera.BeautyType> = captureSession.getSupportedBeautyTypes();
return beautyTypes;
}
``` ```
### getSupportedBeautyRange ### getSupportedBeautyRange
...@@ -2838,10 +3223,14 @@ getSupportedBeautyRange(type: BeautyType): Array\<number\> ...@@ -2838,10 +3223,14 @@ getSupportedBeautyRange(type: BeautyType): Array\<number\>
**示例:** **示例:**
```js ```ts
let beautyTypes = captureSession.getSupportedBeautyTypes(); function getSupportedBeautyRange(captureSession: camera.CaptureSession): Array<number> {
if (!beautyTypes.empty()) { let beautyTypes: Array<camera.BeautyType> = captureSession.getSupportedBeautyTypes();
let nums = captureSession.getSupportedBeautyRange(beautyTypes[0]); if (beautyTypes === undefined || beautyTypes.length <= 0) {
return null;
}
let beautyLevels: Array<number> = captureSession.getSupportedBeautyRange(beautyTypes[0]);
return beautyLevels;
} }
``` ```
...@@ -2872,14 +3261,17 @@ setBeauty(type: BeautyType, value: number): void ...@@ -2872,14 +3261,17 @@ setBeauty(type: BeautyType, value: number): void
**示例:** **示例:**
```js ```ts
let beautyTypes = captureSession.getSupportedBeautyTypes(); function setBeauty(captureSession: camera.CaptureSession): void {
let beautyLevels; let beautyTypes: Array<camera.BeautyType> = captureSession.getSupportedBeautyTypes();
if (!beautyTypes.empty()) { if (beautyTypes === undefined || beautyTypes.length <= 0) {
beautyLevels = captureSession.getSupportedBeautyRange(beautyTypes[0]); return null;
} }
if (!beautyTypes.empty() && beautyLevels.empty()) { let beautyLevels: Array<number> = captureSession.getSupportedBeautyRange(beautyTypes[0]);
captureSession.setBeauty(beautyTypes[0], beautyLevels[0]); if (beautyLevels === undefined || beautyLevels.length <= 0) {
return null;
}
captureSession.setBeauty(beautyTypes[0], beautyLevels[0]);
} }
``` ```
...@@ -2914,16 +3306,20 @@ getBeauty(type: BeautyType): number ...@@ -2914,16 +3306,20 @@ getBeauty(type: BeautyType): number
**示例:** **示例:**
```js ```ts
let BeautyTypes = captureSession.getSupportedBeautyTypes(); function getBeauty(captureSession: camera.CaptureSession): number {
let beautyLevels; let beautyTypes = captureSession.getSupportedBeautyTypes();
if (!BeautyTypes.empty()) { if (beautyTypes === undefined || beautyTypes.length <= 0) {
beautyLevels = captureSession.getSupportedBeautyRange(BeautyTypes[0]); return null;
} }
if (!BeautyTypes.empty() && beautyLevels.empty()) { let beautyLevels: Array<number> = captureSession.getSupportedBeautyRange(BeautyTypes[0]);
captureSession.setBeauty(BeautyTypes[0], beautyLevels[0]); if (beautyLevels === undefined || beautyLevels.length <= 0) {
return null;
}
captureSession.setBeauty(beautyTypes[0], beautyLevels[0]);
let beautyLevel: number = captureSession.getBeauty(beautyTypes[0]);
return beautyLevel;
} }
let beautyLevel = captureSession.getBeauty(BeautyTypes[0]);
``` ```
### on('focusStateChange') ### on('focusStateChange')
...@@ -2943,10 +3339,14 @@ on(type: 'focusStateChange', callback: AsyncCallback\<FocusState\>): void ...@@ -2943,10 +3339,14 @@ on(type: 'focusStateChange', callback: AsyncCallback\<FocusState\>): void
**示例:** **示例:**
```js ```ts
captureSession.on('focusStateChange', (err, focusState) => { import { BusinessError } from '@ohos.base';
console.log(`Focus state : ${focusState}`);
}) function registerFocusStateChange(captureSession: camera.CaptureSession): void {
captureSession.on('focusStateChange', (err: BusinessError, focusState: camera.FocusState) => {
console.log(`Focus state: ${focusState}`);
});
}
``` ```
### off('focusStateChange') ### off('focusStateChange')
...@@ -2966,8 +3366,10 @@ off(type: 'focusStateChange', callback?: AsyncCallback\<FocusState\>): void ...@@ -2966,8 +3366,10 @@ off(type: 'focusStateChange', callback?: AsyncCallback\<FocusState\>): void
**示例:** **示例:**
```js ```ts
captureSession.off('focusStateChange') function unregisterFocusStateChange(captureSession: camera.CaptureSession): void {
captureSession.off('focusStateChange');
}
``` ```
### on('error') ### on('error')
...@@ -2987,10 +3389,14 @@ on(type: 'error', callback: ErrorCallback): void ...@@ -2987,10 +3389,14 @@ on(type: 'error', callback: ErrorCallback): void
**示例:** **示例:**
```js ```ts
captureSession.on('error', (error) => { import { BusinessError } from '@ohos.base';
function registerCaptureSessionError(captureSession: camera.CaptureSession): void {
captureSession.on('error', (error: BusinessError) => {
console.log(`Capture session error code: ${error.code}`); console.log(`Capture session error code: ${error.code}`);
}) });
}
``` ```
### off('error') ### off('error')
...@@ -3010,8 +3416,10 @@ off(type: 'error', callback?: ErrorCallback): void ...@@ -3010,8 +3416,10 @@ off(type: 'error', callback?: ErrorCallback): void
**示例:** **示例:**
```js ```ts
captureSession.off('error') function unregisterCaptureSessionError(captureSession: camera.CaptureSession): void {
captureSession.off('error');
}
``` ```
## PortraitSession ## PortraitSession
...@@ -3043,8 +3451,11 @@ getSupportedPortraitEffects(): Array<[PortraitEffect](#portraiteffect)> ...@@ -3043,8 +3451,11 @@ getSupportedPortraitEffects(): Array<[PortraitEffect](#portraiteffect)>
**示例:** **示例:**
```js ```ts
let portraitEffect = PortraitSession.getSupportedPortraitEffects(); function getSupportedPortraitEffects(portraitSession: camera.PortraitSession): Array<camera.PortraitEffect> {
let portraitEffect: Array<camera.PortraitEffect> = portraitSession.getSupportedPortraitEffects();
return portraitEffect;
}
``` ```
### setPortraitEffect ### setPortraitEffect
...@@ -3072,10 +3483,19 @@ setPortraitEffect(effect: PortraitEffect): void ...@@ -3072,10 +3483,19 @@ setPortraitEffect(effect: PortraitEffect): void
**示例:** **示例:**
```js ```ts
let portraitEffects = PortraitSession.getSupportedPortraitEffects(); import { BusinessError } from '@ohos.base';
if (!portraitEffects.empty()) {
PortraitSession.setPortraitEffect(portraitEffects[0]); function setPortraitEffect(portraitSession: camera.PortraitSession, portraitEffects: Array<camera.PortraitEffect>): void {
if (portraitEffects === undefined || portraitEffects.length <= 0) {
return;
}
try {
portraitSession.setPortraitEffect(portraitEffects[0]);
} catch (error) {
let err = error as BusinessError;
console.error(`The setPortraitEffect call failed. error code: ${err.code}`);
}
} }
``` ```
### getPortraitEffect ### getPortraitEffect
...@@ -3104,10 +3524,10 @@ getPortraitEffect(): PortraitEffect ...@@ -3104,10 +3524,10 @@ getPortraitEffect(): PortraitEffect
**示例:** **示例:**
```js ```ts
let portraitEffects = PortraitSession.getSupportedPortraitEffects(); function getSupportedPortraitEffects(portraitSession: camera.PortraitSession): Array<camera.PortraitEffect> {
if (!portraitEffects.empty()) { let portraitEffects: Array<camera.PortraitEffect> = portraitSession.getSupportedPortraitEffects();
PortraitSession.setPortraitEffect(portraitEffects[0]); return portraitEffects;
} }
``` ```
...@@ -3143,14 +3563,18 @@ start(callback: AsyncCallback\<void\>): void ...@@ -3143,14 +3563,18 @@ start(callback: AsyncCallback\<void\>): void
**示例:** **示例:**
```js ```ts
previewOutput.start((err) => { import { BusinessError } from '@ohos.base';
function startPreviewOutput(previewOutput: camera.PreviewOutput): void {
previewOutput.start((err: BusinessError) => {
if (err) { if (err) {
console.error(`Failed to start the previewOutput. ${err.code}`); console.error(`Failed to start the previewOutput. ${err.code}`);
return; return;
} }
console.log('Callback returned with previewOutput started.'); console.log('Callback returned with previewOutput started.');
}) });
}
``` ```
### start ### start
...@@ -3177,12 +3601,16 @@ start(): Promise\<void\> ...@@ -3177,12 +3601,16 @@ start(): Promise\<void\>
**示例:** **示例:**
```js ```ts
previewOutput.start().then(() => { import { BusinessError } from '@ohos.base';
function startPreviewOutput(previewOutput: camera.PreviewOutput): void {
previewOutput.start().then(() => {
console.log('Promise returned with previewOutput started.'); console.log('Promise returned with previewOutput started.');
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('Failed to previewOutput start '+ err.code); console.log('Failed to previewOutput start '+ err.code);
}); });
}
``` ```
### stop ### stop
...@@ -3201,14 +3629,18 @@ stop(callback: AsyncCallback\<void\>): void ...@@ -3201,14 +3629,18 @@ stop(callback: AsyncCallback\<void\>): void
**示例:** **示例:**
```js ```ts
previewOutput.stop((err) => { import { BusinessError } from '@ohos.base';
function stopPreviewOutput(previewOutput: camera.PreviewOutput): void {
previewOutput.stop((err: BusinessError) => {
if (err) { if (err) {
console.error(`Failed to stop the previewOutput. ${err.code}`); console.error(`Failed to stop the previewOutput. ${err.code}`);
return; return;
} }
console.log('Callback returned with previewOutput stopped.'); console.log('Callback returned with previewOutput stopped.');
}) })
}
``` ```
### stop ### stop
...@@ -3227,12 +3659,16 @@ stop(): Promise\<void\> ...@@ -3227,12 +3659,16 @@ stop(): Promise\<void\>
**示例:** **示例:**
```js ```ts
previewOutput.stop().then(() => { import { BusinessError } from '@ohos.base';
function stopPreviewOutput(previewOutput: camera.PreviewOutput): void {
previewOutput.stop().then(() => {
console.log('Callback returned with previewOutput stopped.'); console.log('Callback returned with previewOutput stopped.');
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('Failed to previewOutput stop '+ err.code); console.log('Failed to previewOutput stop '+ err.code);
}); });
}
``` ```
### release ### release
...@@ -3259,14 +3695,18 @@ release(callback: AsyncCallback\<void\>): void ...@@ -3259,14 +3695,18 @@ release(callback: AsyncCallback\<void\>): void
**示例:** **示例:**
```js ```ts
previewOutput.release((err) => { import { BusinessError } from '@ohos.base';
function releasePreviewOutput(previewOutput: camera.PreviewOutput): void {
previewOutput.release((err: BusinessError) => {
if (err) { if (err) {
console.error(`Failed to release the PreviewOutput instance ${err.code}`); console.error(`Failed to release the PreviewOutput instance ${err.code}`);
return; return;
} }
console.log('Callback invoked to indicate that the PreviewOutput instance is released successfully.'); console.log('Callback invoked to indicate that the PreviewOutput instance is released successfully.');
}); });
}
``` ```
### release ### release
...@@ -3293,12 +3733,16 @@ release(): Promise\<void\> ...@@ -3293,12 +3733,16 @@ release(): Promise\<void\>
**示例:** **示例:**
```js ```ts
previewOutput.release().then(() => { import { BusinessError } from '@ohos.base';
function releasePreviewOutput(previewOutput: camera.PreviewOutput): void {
previewOutput.release().then(() => {
console.log('Promise returned to indicate that the PreviewOutput instance is released successfully.'); console.log('Promise returned to indicate that the PreviewOutput instance is released successfully.');
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('Failed to previewOutput release '+ err.code); console.log('Failed to previewOutput release '+ err.code);
}); });
}
``` ```
### on('frameStart') ### on('frameStart')
...@@ -3318,10 +3762,12 @@ on(type: 'frameStart', callback: AsyncCallback\<void\>): void ...@@ -3318,10 +3762,12 @@ on(type: 'frameStart', callback: AsyncCallback\<void\>): void
**示例:** **示例:**
```js ```ts
previewOutput.on('frameStart', () => { function registerPreviewOutputFrameStart(previewOutput: camera.PreviewOutput): void {
previewOutput.on('frameStart', () => {
console.log('Preview frame started'); console.log('Preview frame started');
}) });
}
``` ```
### off('frameStart') ### off('frameStart')
...@@ -3341,8 +3787,10 @@ off(type: 'frameStart', callback?: AsyncCallback\<void\>): void ...@@ -3341,8 +3787,10 @@ off(type: 'frameStart', callback?: AsyncCallback\<void\>): void
**示例:** **示例:**
```js ```ts
previewOutput.off('frameStart') function unregisterPreviewOutputFrameStart(previewOutput: camera.PreviewOutput): void {
previewOutput.off('frameStart');
}
``` ```
### on('frameEnd') ### on('frameEnd')
...@@ -3362,10 +3810,12 @@ on(type: 'frameEnd', callback: AsyncCallback\<void\>): void ...@@ -3362,10 +3810,12 @@ on(type: 'frameEnd', callback: AsyncCallback\<void\>): void
**示例:** **示例:**
```js ```ts
previewOutput.on('frameEnd', () => { function registerPreviewOutputFrameEnd(previewOutput: camera.PreviewOutput): void {
previewOutput.on('frameEnd', () => {
console.log('Preview frame ended'); console.log('Preview frame ended');
}) });
}
``` ```
### off('frameEnd') ### off('frameEnd')
...@@ -3385,8 +3835,10 @@ off(type: 'frameEnd', callback?: AsyncCallback\<void\>): void ...@@ -3385,8 +3835,10 @@ off(type: 'frameEnd', callback?: AsyncCallback\<void\>): void
**示例:** **示例:**
```js ```ts
previewOutput.off('frameEnd') function unregisterPreviewOutputFrameEnd(previewOutput: camera.PreviewOutput): void {
previewOutput.off('frameEnd');
}
``` ```
### on('error') ### on('error')
...@@ -3406,10 +3858,14 @@ on(type: 'error', callback: ErrorCallback): void ...@@ -3406,10 +3858,14 @@ on(type: 'error', callback: ErrorCallback): void
**示例:** **示例:**
```js ```ts
previewOutput.on('error', (previewOutputError) => { import { BusinessError } from '@ohos.base';
function registerPreviewOutputError(previewOutput: camera.PreviewOutput): void {
previewOutput.on('error', (previewOutputError: BusinessError) => {
console.log(`Preview output error code: ${previewOutputError.code}`); console.log(`Preview output error code: ${previewOutputError.code}`);
}) })
}
``` ```
### off('error') ### off('error')
...@@ -3429,8 +3885,10 @@ off(type: 'error', callback?: ErrorCallback): void ...@@ -3429,8 +3885,10 @@ off(type: 'error', callback?: ErrorCallback): void
**示例:** **示例:**
```js ```ts
previewOutput.off('error') function unregisterPreviewOutputError(previewOutput: camera.PreviewOutput): void {
previewOutput.off('error');
}
``` ```
### addDeferredSurface ### addDeferredSurface
...@@ -3459,17 +3917,19 @@ addDeferredSurface(surfaceId: string): void ...@@ -3459,17 +3917,19 @@ addDeferredSurface(surfaceId: string): void
**示例:** **示例:**
```js ```ts
function async preview(context: Context, cameraInfo: camera.Device, previewProfile: camera.Profile, photoProfile: camera.Profile, surfaceId: string): Promise<void> { import featureAbility from '@ohos.ability.featureAbility';
async function preview(context: featureAbility.Context, cameraInfo: camera.CameraDevice, previewProfile: camera.Profile, photoProfile: camera.Profile, surfaceId: string): Promise<void> {
const cameraManager: camera.CameraManager = camera.getCameraManager(context); const cameraManager: camera.CameraManager = camera.getCameraManager(context);
const cameraInput camera.CameraInput = await cameraManager.createCameraInput(cameraInfo) const cameraInput: camera.CameraInput = cameraManager.createCameraInput(cameraInfo)
const previewOutput: camera.PreviewOutput = await cameraManager.createDeferredPreviewOutput(previewProfile); const previewOutput: camera.PreviewOutput = await cameraManager.createDeferredPreviewOutput(previewProfile);
const photoOutput: camera.PhotoOutput = await cameraManager.createPhotoOutput(photoProfile); const photoOutput: camera.PhotoOutput = cameraManager.createPhotoOutput(photoProfile);
const session: camera.CaptureSession = await this.mCameraManager.createCaptureSession(); const session: camera.CaptureSession = await this.mCameraManager.createCaptureSession();
await session.beginConfig(); session.beginConfig();
await session.addInput(cameraInput); session.addInput(cameraInput);
await session.addOutput(previewOutput); session.addOutput(previewOutput);
await session.addOutput(photoOutput); session.addOutput(photoOutput);
await session.commitConfig(); await session.commitConfig();
await session.start(); await session.start();
await previewOutput.addDeferredSurface(surfaceId); await previewOutput.addDeferredSurface(surfaceId);
...@@ -3556,14 +4016,18 @@ capture(callback: AsyncCallback\<void\>): void ...@@ -3556,14 +4016,18 @@ capture(callback: AsyncCallback\<void\>): void
**示例:** **示例:**
```js ```ts
photoOutput.capture((err) => { import { BusinessError } from '@ohos.base';
function capture(photoOutput: camera.PhotoOutput): void {
photoOutput.capture((err: BusinessError) => {
if (err) { if (err) {
console.error(`Failed to capture the photo ${err.code}`); console.error(`Failed to capture the photo ${err.code}`);
return; return;
} }
console.log('Callback invoked to indicate the photo capture request success.'); console.log('Callback invoked to indicate the photo capture request success.');
}); });
}
``` ```
### capture ### capture
...@@ -3591,12 +4055,16 @@ capture(): Promise\<void\> ...@@ -3591,12 +4055,16 @@ capture(): Promise\<void\>
**示例:** **示例:**
```js ```ts
photoOutput.capture().then(() => { import { BusinessError } from '@ohos.base';
function capture(photoOutput: camera.PhotoOutput): void {
photoOutput.capture().then(() => {
console.log('Promise returned to indicate that photo capture request success.'); console.log('Promise returned to indicate that photo capture request success.');
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('Failed to photoOutput capture '+ err.code); console.log('Failed to photoOutput capture '+ err.code);
}); });
}
``` ```
### capture ### capture
...@@ -3626,25 +4094,29 @@ capture(setting: PhotoCaptureSetting, callback: AsyncCallback\<void\>): void ...@@ -3626,25 +4094,29 @@ capture(setting: PhotoCaptureSetting, callback: AsyncCallback\<void\>): void
**示例:** **示例:**
```js ```ts
let captureLocation = { import { BusinessError } from '@ohos.base';
latitude: 0,
longitude: 0, function capture(photoOutput: camera.PhotoOutput): void {
altitude: 0, let captureLocation: camera.Location = {
} latitude: 0,
let settings = { longitude: 0,
quality: camera.QualityLevel.QUALITY_LEVEL_LOW, altitude: 0,
rotation: camera.ImageRotation.ROTATION_0, }
location: captureLocation, let settings: camera.PhotoCaptureSetting = {
mirror: false quality: camera.QualityLevel.QUALITY_LEVEL_LOW,
} rotation: camera.ImageRotation.ROTATION_0,
photoOutput.capture(settings, (err) => { location: captureLocation,
mirror: false
}
photoOutput.capture(settings, (err: BusinessError) => {
if (err) { if (err) {
console.error(`Failed to capture the photo ${err.code}`); console.error(`Failed to capture the photo ${err.code}`);
return; return;
} }
console.log('Callback invoked to indicate the photo capture request success.'); console.log('Callback invoked to indicate the photo capture request success.');
}); });
}
``` ```
### capture ### capture
...@@ -3679,23 +4151,27 @@ capture(setting?: PhotoCaptureSetting): Promise\<void\> ...@@ -3679,23 +4151,27 @@ capture(setting?: PhotoCaptureSetting): Promise\<void\>
**示例:** **示例:**
```js ```ts
let captureLocation = { import { BusinessError } from '@ohos.base';
latitude: 0,
longitude: 0, function capture(photoOutput: camera.PhotoOutput): void {
altitude: 0, let captureLocation: camera.Location = {
} latitude: 0,
let settings = { longitude: 0,
quality: camera.QualityLevel.QUALITY_LEVEL_LOW, altitude: 0,
rotation: camera.ImageRotation.ROTATION_0, }
location: captureLocation, let settings: camera.PhotoCaptureSetting = {
mirror: false quality: camera.QualityLevel.QUALITY_LEVEL_LOW,
} rotation: camera.ImageRotation.ROTATION_0,
photoOutput.capture(settings).then(() => { location: captureLocation,
mirror: false
}
photoOutput.capture(settings).then(() => {
console.log('Promise returned to indicate that photo capture request success.'); console.log('Promise returned to indicate that photo capture request success.');
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('Failed to photoOutput capture '+ err.code); console.log('Failed to photoOutput capture '+ err.code);
}); });
}
``` ```
### isMirrorSupported ### isMirrorSupported
...@@ -3714,8 +4190,11 @@ isMirrorSupported(): boolean ...@@ -3714,8 +4190,11 @@ isMirrorSupported(): boolean
**示例:** **示例:**
```js ```ts
let isSupported = photoOutput.isMirrorSupported(); function isMirrorSupported(photoOutput: camera.PhotoOutput): boolean {
let isSupported: boolean = photoOutput.isMirrorSupported();
return isSupported;
}
``` ```
### release ### release
...@@ -3742,14 +4221,18 @@ release(callback: AsyncCallback\<void\>): void ...@@ -3742,14 +4221,18 @@ release(callback: AsyncCallback\<void\>): void
**示例:** **示例:**
```js ```ts
photoOutput.release((err) => { import { BusinessError } from '@ohos.base';
function releasePhotoOutput(photoOutput: camera.PhotoOutput): void {
photoOutput.release((err: BusinessError) => {
if (err) { if (err) {
console.error(`Failed to release the PreviewOutput instance ${err.code}`); console.error(`Failed to release the PreviewOutput instance ${err.code}`);
return; return;
} }
console.log('Callback invoked to indicate that the PreviewOutput instance is released successfully.'); console.log('Callback invoked to indicate that the PreviewOutput instance is released successfully.');
}); });
}
``` ```
### release ### release
...@@ -3776,12 +4259,16 @@ release(): Promise\<void\> ...@@ -3776,12 +4259,16 @@ release(): Promise\<void\>
**示例:** **示例:**
```js ```ts
photoOutput.release().then(() => { import { BusinessError } from '@ohos.base';
function releasePhotoOutput(photoOutput: camera.PhotoOutput): void {
photoOutput.release().then(() => {
console.log('Promise returned to indicate that the PreviewOutput instance is released successfully.'); console.log('Promise returned to indicate that the PreviewOutput instance is released successfully.');
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('Failed to photoOutput release '+ err.code); console.log('Failed to photoOutput release '+ err.code);
}); });
}
``` ```
### on('captureStart') ### on('captureStart')
...@@ -3801,10 +4288,14 @@ on(type: 'captureStart', callback: AsyncCallback\<number\>): void ...@@ -3801,10 +4288,14 @@ on(type: 'captureStart', callback: AsyncCallback\<number\>): void
**示例:** **示例:**
```js ```ts
photoOutput.on('captureStart', (err, captureId) => { import { BusinessError } from '@ohos.base';
function registerPhotoOutputCaptureStart(photoOutput: camera.PhotoOutput): void {
photoOutput.on('captureStart', (err: BusinessError, captureId: number) => {
console.log(`photo capture stated, captureId : ${captureId}`); console.log(`photo capture stated, captureId : ${captureId}`);
}) });
}
``` ```
### off('captureStart') ### off('captureStart')
...@@ -3824,8 +4315,10 @@ off(type: 'captureStart', callback?: AsyncCallback\<number\>): void ...@@ -3824,8 +4315,10 @@ off(type: 'captureStart', callback?: AsyncCallback\<number\>): void
**示例:** **示例:**
```js ```ts
photoOutput.off('captureStart') function unregisterPhotoOutputCaptureStart(photoOutput: camera.PhotoOutput): void {
photoOutput.off('captureStart');
}
``` ```
### on('frameShutter') ### on('frameShutter')
...@@ -3845,11 +4338,15 @@ on(type: 'frameShutter', callback: AsyncCallback\<FrameShutterInfo\>): void ...@@ -3845,11 +4338,15 @@ on(type: 'frameShutter', callback: AsyncCallback\<FrameShutterInfo\>): void
**示例:** **示例:**
```js ```ts
photoOutput.on('frameShutter', (err, frameShutterInfo) => { import { BusinessError } from '@ohos.base';
function registerPhotoOutputFrameShutter(photoOutput: camera.PhotoOutput): void {
photoOutput.on('frameShutter', (err: BusinessError, frameShutterInfo: camera.FrameShutterInfo) => {
console.log(`photo capture end, captureId : ${frameShutterInfo.captureId}`); console.log(`photo capture end, captureId : ${frameShutterInfo.captureId}`);
console.log(`Timestamp for frame : ${frameShutterInfo.timestamp}`); console.log(`Timestamp for frame : ${frameShutterInfo.timestamp}`);
}) });
}
``` ```
### off('frameShutter') ### off('frameShutter')
...@@ -3869,8 +4366,10 @@ off(type: 'frameShutter', callback?: AsyncCallback\<FrameShutterInfo\>): void ...@@ -3869,8 +4366,10 @@ off(type: 'frameShutter', callback?: AsyncCallback\<FrameShutterInfo\>): void
**示例:** **示例:**
```js ```ts
photoOutput.off('frameShutter') function unregisterPhotoOutputFrameShutter(photoOutput: camera.PhotoOutput): void {
photoOutput.off('frameShutter');
}
``` ```
### on('captureEnd') ### on('captureEnd')
...@@ -3890,11 +4389,15 @@ on(type: 'captureEnd', callback: AsyncCallback\<CaptureEndInfo\>): void ...@@ -3890,11 +4389,15 @@ on(type: 'captureEnd', callback: AsyncCallback\<CaptureEndInfo\>): void
**示例:** **示例:**
```js ```ts
photoOutput.on('captureEnd', (err, captureEndInfo) => { import { BusinessError } from '@ohos.base';
function registerPhotoOutputCaptureEnd(photoOutput: camera.PhotoOutput): void {
photoOutput.on('captureEnd', (err: BusinessError, captureEndInfo: camera.CaptureEndInfo) => {
console.log(`photo capture end, captureId : ${captureEndInfo.captureId}`); console.log(`photo capture end, captureId : ${captureEndInfo.captureId}`);
console.log(`frameCount : ${captureEndInfo.frameCount}`); console.log(`frameCount : ${captureEndInfo.frameCount}`);
}) });
}
``` ```
### off('captureEnd') ### off('captureEnd')
...@@ -3914,8 +4417,10 @@ off(type: 'captureEnd', callback?: AsyncCallback\<CaptureEndInfo\>): void ...@@ -3914,8 +4417,10 @@ off(type: 'captureEnd', callback?: AsyncCallback\<CaptureEndInfo\>): void
**示例:** **示例:**
```js ```ts
photoOutput.off('captureEnd') function unregisterPhotoOutputCaptureEnd(photoOutput: camera.PhotoOutput): void {
photoOutput.off('captureEnd');
}
``` ```
### on('error') ### on('error')
...@@ -3935,10 +4440,14 @@ on(type: 'error', callback: ErrorCallback): void ...@@ -3935,10 +4440,14 @@ on(type: 'error', callback: ErrorCallback): void
**示例:** **示例:**
```js ```ts
photoOutput.on('error', (error) => { import { BusinessError } from '@ohos.base';
function registerPhotoOutputError(photoOutput: camera.PhotoOutput): void {
photoOutput.on('error', (error: BusinessError) => {
console.log(`Photo output error code: ${error.code}`); console.log(`Photo output error code: ${error.code}`);
}) });
}
``` ```
### off('error') ### off('error')
...@@ -3958,8 +4467,10 @@ off(type: 'error', callback?: ErrorCallback): void ...@@ -3958,8 +4467,10 @@ off(type: 'error', callback?: ErrorCallback): void
**示例:** **示例:**
```js ```ts
photoOutput.off('error') function unregisterPhotoOutputError(photoOutput: camera.PhotoOutput): void {
photoOutput.off('error');
}
``` ```
### isQuickThumbnailSupported ### isQuickThumbnailSupported
...@@ -3990,22 +4501,26 @@ isQuickThumbnailSupported(): boolean ...@@ -3990,22 +4501,26 @@ isQuickThumbnailSupported(): boolean
**示例:** **示例:**
```js ```ts
this.cameraManager = camera.getCameraManager(globalThis.abilityContext); import featureAbility from '@ohos.ability.featureAbility';
let cameras = this.cameraManager.getSupportedCameras()
// 创建CaptureSession实例 async function isQuickThumbnailSupported(context: featureAbility.Context, photoProfile: camera.Profile, surfaceId: string): Promise<boolean> {
this.captureSession = await this.cameraManager.createCaptureSession() let cameraManager: camera.CameraManager = camera.getCameraManager(context);
// 开始配置会话 let cameras: Array<camera.CameraDevice> = cameraManager.getSupportedCameras();
await this.captureSession.beginConfig() // 创建CaptureSession实例
// 把CameraInput加入到会话 let captureSession: camera.CaptureSession = cameraManager.createCaptureSession();
this.mCameraInput = await this.cameraManager.createCameraInput(cameras[0]) // 开始配置会话
await this.cameraInput.open() captureSession.beginConfig();
await this.captureSession.addInput(this.cameraInput) // 把CameraInput加入到会话
// 把PhotoOutPut加入到会话 let cameraInput: camera.CameraInput = cameraManager.createCameraInput(cameras[0]);
this.photoOutPut = await this.cameraManager.createPhotoOutput(photoProfile, surfaceId) await cameraInput.open();
await this.captureSession.addOutput(this.photoOutPut) captureSession.addInput(cameraInput);
// 把photoOutput加入到会话
boolean isSupported = this.photoOutPut.isQuickThumbnailSupported() let photoOutput: camera.PhotoOutput = cameraManager.createPhotoOutput(photoProfile, surfaceId);
captureSession.addOutput(photoOutput);
let isSupported: boolean = photoOutput.isQuickThumbnailSupported();
return isSupported;
}
``` ```
### enableQuickThumbnail ### enableQuickThumbnail
...@@ -4036,24 +4551,35 @@ enableQuickThumbnail(enabled: boolean): void ...@@ -4036,24 +4551,35 @@ enableQuickThumbnail(enabled: boolean): void
**示例:** **示例:**
```js ```ts
this.cameraManager = camera.getCameraManager(globalThis.abilityContext); import featureAbility from '@ohos.ability.featureAbility';
let cameras = this.cameraManager.getSupportedCameras() import { BusinessError } from '@ohos.base';
// 创建CaptureSession实例
this.captureSession = await this.cameraManager.createCaptureSession() async function enableQuickThumbnail(context: featureAbility.Context, photoProfile: camera.Profile, surfaceId: string): Promise<void> {
// 开始配置会话 let cameraManager: camera.CameraManager = camera.getCameraManager(context);
await this.captureSession.beginConfig() let cameras: Array<camera.CameraDevice> = cameraManager.getSupportedCameras();
// 把CameraInput加入到会话 // 创建CaptureSession实例
this.cameraInput = await this.cameraManager.createCameraInput(cameras[0]) let captureSession: camera.CaptureSession = cameraManager.createCaptureSession();
await this.cameraInput.open() // 开始配置会话
await this.captureSession.addInput(this.cameraInput) captureSession.beginConfig();
// 把PhotoOutPut加入到会话 // 把CameraInput加入到会话
this.photoOutPut = await this.cameraManager.createPhotoOutput(photoProfile, surfaceId) let cameraInput: camera.CameraInput = cameraManager.createCameraInput(cameras[0]);
await this.captureSession.addOutput(this.photoOutPut) await cameraInput.open();
boolean isSupported = this.photoOutPut.isQuickThumbnailSupported() captureSession.addInput(cameraInput);
if (isSupported) { // 把PhotoOutPut加入到会话
// 使能快速缩略图 let photoOutput: camera.PhotoOutput = cameraManager.createPhotoOutput(photoProfile, surfaceId);
this.photoOutPut.enableQuickThumbnail(true) captureSession.addOutput(photoOutput);
let isSupported: boolean = photoOutput.isQuickThumbnailSupported();
if (!isSupported) {
console.log('Quick Thumbnail is not supported to be turned on.');
return;
}
try {
photoOutput.enableQuickThumbnail(true);
} catch (error) {
let err = error as BusinessError;
console.error(`The enableQuickThumbnail call failed. error code: ${err.code}`);
}
} }
``` ```
...@@ -4078,35 +4604,45 @@ on(type: 'quickThumbnail', callback: AsyncCallback\<image.PixelMap>): void ...@@ -4078,35 +4604,45 @@ on(type: 'quickThumbnail', callback: AsyncCallback\<image.PixelMap>): void
**示例:** **示例:**
```js ```ts
import camera from '@ohos.multimedia.camera' import featureAbility from '@ohos.ability.featureAbility';
import { BusinessError } from '@ohos.base';
this.cameraManager = camera.getCameraManager(globalThis.abilityContext);
let cameras = this.cameraManager.getSupportedCameras() async function registerQuickThumbnail(context: featureAbility.Context, photoProfile: camera.Profile, surfaceId: string): Promise<void> {
// 创建CaptureSession实例 let cameraManager: camera.CameraManager = camera.getCameraManager(context);
this.captureSession = await this.cameraManager.createCaptureSession() let cameras: Array<camera.CameraDevice> = cameraManager.getSupportedCameras();
// 开始配置会话 // 创建CaptureSession实例
await this.captureSession.beginConfig() let captureSession: camera.CaptureSession = cameraManager.createCaptureSession();
// 把CameraInput加入到会话 // 开始配置会话
this.cameraInput = await this.cameraManager.createCameraInput(cameras[0]) captureSession.beginConfig();
await this.cameraInput.open() // 把CameraInput加入到会话
await this.captureSession.addInput(this.cameraInput) let cameraInput: camera.CameraInput = cameraManager.createCameraInput(cameras[0]);
// 把PhotoOutPut加入到会话 await cameraInput.open();
this.photoOutPut = await this.cameraManager.createPhotoOutput(photoProfile, surfaceId) captureSession.addInput(cameraInput);
await this.captureSession.addOutput(this.photoOutPut) // 把PhotoOutPut加入到会话
boolean isSupported = this.photoOutPut.isQuickThumbnailSupported() let photoOutput: camera.PhotoOutput = cameraManager.createPhotoOutput(photoProfile, surfaceId);
if (isSupported) { captureSession.addOutput(photoOutput);
// 使能快速缩略图 let isSupported: boolean = photoOutput.isQuickThumbnailSupported();
this.photoOutPut.enableQuickThumbnail(true) if (!isSupported) {
} console.log('Quick Thumbnail is not supported to be turned on.');
this.photoOutPut.on('quickThumbnail', (err, pixelmap) => { return;
if (err || pixelmap === undefined) { }
Logger.error(this.tag, 'photoOutPut on thumbnail failed ') try {
return photoOutput.enableQuickThumbnail(true);
} catch (error) {
let err = error as BusinessError;
console.error(`The enableQuickThumbnail call failed. error code: ${err.code}`);
}
photoOutput.on('quickThumbnail', (err: BusinessError, pixelMap: image.PixelMap) => {
if (err || pixelMap === undefined) {
console.error('photoOutput on thumbnail failed');
return;
} }
// 显示或保存pixelmap // 显示或保存pixelMap
this.showOrSavePicture(pixelmap) // do something
}) })
}
``` ```
### off('quickThumbnail') ### off('quickThumbnail')
...@@ -4128,36 +4664,10 @@ off(type: 'quickThumbnail', callback?: AsyncCallback\<image.PixelMap>): void ...@@ -4128,36 +4664,10 @@ off(type: 'quickThumbnail', callback?: AsyncCallback\<image.PixelMap>): void
**示例:** **示例:**
```js ```ts
import camera from '@ohos.multimedia.camera' function unregisterQuickThumbnail(photoOutput: camera.PhotoOutput): void {
this.photoOutput.off('quickThumbnail');
this.cameraManager = camera.getCameraManager(globalThis.abilityContext); }
let cameras = this.cameraManager.getSupportedCameras()
// 创建CaptureSession实例
this.captureSession = await this.cameraManager.createCaptureSession()
// 开始配置会话
await this.captureSession.beginConfig()
// 把CameraInput加入到会话
this.cameraInput = await this.cameraManager.createCameraInput(cameras[0])
await this.cameraInput.open()
await this.captureSession.addInput(this.cameraInput)
// 把PhotoOutPut加入到会话
this.photoOutPut = await this.cameraManager.createPhotoOutput(photoProfile, surfaceId)
await this.captureSession.addOutput(this.photoOutPut)
boolean isSupported = this.photoOutPut.isQuickThumbnailSupported()
if (isSupported) {
// 使能快速缩略图
this.photoOutPut.enableQuickThumbnail(true)
}
this.photoOutPut.on('quickThumbnail', (err, pixelmap) => {
if (err || pixelmap === undefined) {
Logger.error(this.tag, 'photoOutPut on thumbnail failed ')
return
}
// 显示或保存pixelmap
this.showOrSavePicture(pixelmap)
})
this.photoOutPut.off('quickThumbnail')
``` ```
## FrameShutterInfo ## FrameShutterInfo
...@@ -4211,14 +4721,18 @@ start(callback: AsyncCallback\<void\>): void ...@@ -4211,14 +4721,18 @@ start(callback: AsyncCallback\<void\>): void
**示例:** **示例:**
```js ```ts
videoOutput.start((err) => { import { BusinessError } from '@ohos.base';
function startVideoOutput(videoOutput: camera.VideoOutput): void {
videoOutput.start((err: BusinessError) => {
if (err) { if (err) {
console.error(`Failed to start the video output ${err.code}`); console.error(`Failed to start the video output ${err.code}`);
return; return;
} }
console.log('Callback invoked to indicate the video output start success.'); console.log('Callback invoked to indicate the video output start success.');
}); });
}
``` ```
### start ### start
...@@ -4246,12 +4760,16 @@ start(): Promise\<void\> ...@@ -4246,12 +4760,16 @@ start(): Promise\<void\>
**示例:** **示例:**
```js ```ts
videoOutput.start().then(() => { import { BusinessError } from '@ohos.base';
function startVideoOutput(videoOutput: camera.VideoOutput): void {
videoOutput.start().then(() => {
console.log('Promise returned to indicate that start method execution success.'); console.log('Promise returned to indicate that start method execution success.');
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('Failed to videoOutput start '+ err.code); console.log('Failed to videoOutput start '+ err.code);
}); });
}
``` ```
### stop ### stop
...@@ -4270,14 +4788,18 @@ stop(callback: AsyncCallback\<void\>): void ...@@ -4270,14 +4788,18 @@ stop(callback: AsyncCallback\<void\>): void
**示例:** **示例:**
```js ```ts
videoOutput.stop((err) => { import { BusinessError } from '@ohos.base';
function stopVideoOutput(videoOutput: camera.VideoOutput): void {
videoOutput.stop((err: BusinessError) => {
if (err) { if (err) {
console.error(`Failed to stop the video output ${err.code}`); console.error(`Failed to stop the video output ${err.code}`);
return; return;
} }
console.log('Callback invoked to indicate the video output stop success.'); console.log('Callback invoked to indicate the video output stop success.');
}); });
}
``` ```
### stop ### stop
...@@ -4296,12 +4818,16 @@ stop(): Promise\<void\> ...@@ -4296,12 +4818,16 @@ stop(): Promise\<void\>
**示例:** **示例:**
```js ```ts
videoOutput.stop().then(() => { import { BusinessError } from '@ohos.base';
function stopVideoOutput(videoOutput: camera.VideoOutput): void {
videoOutput.stop().then(() => {
console.log('Promise returned to indicate that stop method execution success.'); console.log('Promise returned to indicate that stop method execution success.');
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('Failed to videoOutput stop '+ err.code); console.log('Failed to videoOutput stop '+ err.code);
}); });
}
``` ```
### release ### release
...@@ -4328,14 +4854,18 @@ release(callback: AsyncCallback\<void\>): void ...@@ -4328,14 +4854,18 @@ release(callback: AsyncCallback\<void\>): void
**示例:** **示例:**
```js ```ts
videoOutput.release((err) => { import { BusinessError } from '@ohos.base';
function releaseVideoOutput(videoOutput: camera.VideoOutput): void {
videoOutput.release((err: BusinessError) => {
if (err) { if (err) {
console.error(`Failed to release the PreviewOutput instance ${err.code}`); console.error(`Failed to release the PreviewOutput instance ${err.code}`);
return; return;
} }
console.log('Callback invoked to indicate that the PreviewOutput instance is released successfully.'); console.log('Callback invoked to indicate that the videoOutput instance is released successfully.');
}); });
}
``` ```
### release ### release
...@@ -4362,12 +4892,16 @@ release(): Promise\<void\> ...@@ -4362,12 +4892,16 @@ release(): Promise\<void\>
**示例:** **示例:**
```js ```ts
videoOutput.release().then(() => { import { BusinessError } from '@ohos.base';
console.log('Promise returned to indicate that the PreviewOutput instance is released successfully.');
}).catch((err) => { function releaseVideoOutput(videoOutput: camera.VideoOutput): void {
videoOutput.release().then(() => {
console.log('Promise returned to indicate that the videoOutput instance is released successfully.');
}).catch((err: BusinessError) => {
console.log('Failed to videoOutput release '+ err.code); console.log('Failed to videoOutput release '+ err.code);
}); });
}
``` ```
### on('frameStart') ### on('frameStart')
...@@ -4387,10 +4921,12 @@ on(type: 'frameStart', callback: AsyncCallback\<void\>): void ...@@ -4387,10 +4921,12 @@ on(type: 'frameStart', callback: AsyncCallback\<void\>): void
**示例:** **示例:**
```js ```ts
videoOutput.on('frameStart', () => { function registerVideoOutputFrameStart(videoOutput: camera.VideoOutput): void {
videoOutput.on('frameStart', () => {
console.log('Video frame started'); console.log('Video frame started');
}) });
}
``` ```
### off('frameStart') ### off('frameStart')
...@@ -4410,8 +4946,11 @@ off(type: 'frameStart', callback?: AsyncCallback\<void\>): void ...@@ -4410,8 +4946,11 @@ off(type: 'frameStart', callback?: AsyncCallback\<void\>): void
**示例:** **示例:**
```js ```ts
videoOutput.off('frameStart') function unregisterVideoOutputFrameStart(videoOutput: camera.VideoOutput): void {
videoOutput.off('frameStart');
}
``` ```
### on('frameEnd') ### on('frameEnd')
...@@ -4431,10 +4970,12 @@ on(type: 'frameEnd', callback: AsyncCallback\<void\>): void ...@@ -4431,10 +4970,12 @@ on(type: 'frameEnd', callback: AsyncCallback\<void\>): void
**示例:** **示例:**
```js ```ts
videoOutput.on('frameEnd', () => { function registerVideoOutputFrameEnd(videoOutput: camera.VideoOutput): void {
videoOutput.on('frameEnd', () => {
console.log('Video frame ended'); console.log('Video frame ended');
}) });
}
``` ```
### off('frameEnd') ### off('frameEnd')
...@@ -4454,8 +4995,10 @@ off(type: 'frameEnd', callback?: AsyncCallback\<void\>): void ...@@ -4454,8 +4995,10 @@ off(type: 'frameEnd', callback?: AsyncCallback\<void\>): void
**示例:** **示例:**
```js ```ts
videoOutput.off('frameEnd') function unregisterVideoOutputFrameEnd(videoOutput: camera.VideoOutput): void {
videoOutput.off('frameEnd');
}
``` ```
### on('error') ### on('error')
...@@ -4475,10 +5018,14 @@ on(type: 'error', callback: ErrorCallback): void ...@@ -4475,10 +5018,14 @@ on(type: 'error', callback: ErrorCallback): void
**示例:** **示例:**
```js ```ts
videoOutput.on('error', (error) => { import { BusinessError } from '@ohos.base';
function registerVideoOutputError(videoOutput: camera.VideoOutput): void {
videoOutput.on('error', (error: BusinessError) => {
console.log(`Video output error code: ${error.code}`); console.log(`Video output error code: ${error.code}`);
}) });
}
``` ```
### off('error') ### off('error')
...@@ -4498,8 +5045,10 @@ off(type: 'error', callback?: ErrorCallback): void ...@@ -4498,8 +5045,10 @@ off(type: 'error', callback?: ErrorCallback): void
**示例:** **示例:**
```js ```ts
videoOutput.off('error') function unregisterVideoOutputError(videoOutput: camera.VideoOutput): void {
videoOutput.off('error');
}
``` ```
## MetadataOutput ## MetadataOutput
...@@ -4531,14 +5080,18 @@ start(callback: AsyncCallback\<void\>): void ...@@ -4531,14 +5080,18 @@ start(callback: AsyncCallback\<void\>): void
**示例:** **示例:**
```js ```ts
metadataOutput.start((err) => { import { BusinessError } from '@ohos.base';
function startMetadataOutput(metadataOutput: camera.MetadataOutput): void {
metadataOutput.start((err: BusinessError) => {
if (err) { if (err) {
console.error(`Failed to start metadataOutput. ${err.code}`); console.error(`Failed to start metadataOutput. ${err.code}`);
return; return;
} }
console.log('Callback returned with metadataOutput started.'); console.log('Callback returned with metadataOutput started.');
}) });
}
``` ```
### start ### start
...@@ -4566,12 +5119,16 @@ start(): Promise\<void\> ...@@ -4566,12 +5119,16 @@ start(): Promise\<void\>
**示例:** **示例:**
```js ```ts
metadataOutput.start().then(() => { import { BusinessError } from '@ohos.base';
function startMetadataOutput(metadataOutput: camera.MetadataOutput): void {
metadataOutput.start().then(() => {
console.log('Callback returned with metadataOutput started.'); console.log('Callback returned with metadataOutput started.');
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('Failed to metadataOutput start '+ err.code); console.log('Failed to metadataOutput start '+ err.code);
}); });
}
``` ```
### stop ### stop
...@@ -4590,14 +5147,18 @@ stop(callback: AsyncCallback\<void\>): void ...@@ -4590,14 +5147,18 @@ stop(callback: AsyncCallback\<void\>): void
**示例:** **示例:**
```js ```ts
metadataOutput.stop((err) => { import { BusinessError } from '@ohos.base';
function stopMetadataOutput(metadataOutput: camera.MetadataOutput): void {
metadataOutput.stop((err: BusinessError) => {
if (err) { if (err) {
console.error(`Failed to stop the metadataOutput. ${err.code}`); console.error(`Failed to stop the metadataOutput. ${err.code}`);
return; return;
} }
console.log('Callback returned with metadataOutput stopped.'); console.log('Callback returned with metadataOutput stopped.');
}) })
}
``` ```
### stop ### stop
...@@ -4616,12 +5177,16 @@ stop(): Promise\<void\> ...@@ -4616,12 +5177,16 @@ stop(): Promise\<void\>
**示例:** **示例:**
```js ```ts
metadataOutput.stop().then(() => { import { BusinessError } from '@ohos.base';
function stopMetadataOutput(metadataOutput: camera.MetadataOutput): void {
metadataOutput.stop().then(() => {
console.log('Callback returned with metadataOutput stopped.'); console.log('Callback returned with metadataOutput stopped.');
}).catch((err) => { }).catch((err: BusinessError) => {
console.log('Failed to metadataOutput stop '+ err.code); console.log('Failed to metadataOutput stop '+ err.code);
}); });
}
``` ```
### on('metadataObjectsAvailable') ### on('metadataObjectsAvailable')
...@@ -4641,10 +5206,14 @@ on(type: 'metadataObjectsAvailable', callback: AsyncCallback\<Array\<MetadataObj ...@@ -4641,10 +5206,14 @@ on(type: 'metadataObjectsAvailable', callback: AsyncCallback\<Array\<MetadataObj
**示例:** **示例:**
```js ```ts
metadataOutput.on('metadataObjectsAvailable', (err, metadataObjectArr) => { import { BusinessError } from '@ohos.base';
function registerMetadataObjectsAvailable(metadataOutput: camera.MetadataOutput): void {
metadataOutput.on('metadataObjectsAvailable', (err: BusinessError, metadataObjectArr: Array<camera.MetadataObject>) => {
console.log(`metadata output metadataObjectsAvailable`); console.log(`metadata output metadataObjectsAvailable`);
}) });
}
``` ```
### off('metadataObjectsAvailable') ### off('metadataObjectsAvailable')
...@@ -4664,8 +5233,10 @@ off(type: 'metadataObjectsAvailable', callback?: AsyncCallback\<Array\<MetadataO ...@@ -4664,8 +5233,10 @@ off(type: 'metadataObjectsAvailable', callback?: AsyncCallback\<Array\<MetadataO
**示例:** **示例:**
```js ```ts
metadataOutput.off('metadataObjectsAvailable') function unregisterMetadataObjectsAvailable(metadataOutput: camera.MetadataOutput): void {
metadataOutput.off('metadataObjectsAvailable');
}
``` ```
### on('error') ### on('error')
...@@ -4685,10 +5256,14 @@ on(type: 'error', callback: ErrorCallback): void ...@@ -4685,10 +5256,14 @@ on(type: 'error', callback: ErrorCallback): void
**示例:** **示例:**
```js ```ts
metadataOutput.on('error', (metadataOutputError) => { import { BusinessError } from '@ohos.base';
function registerMetadataOutputError(metadataOutput: camera.MetadataOutput): void {
metadataOutput.on('error', (metadataOutputError: BusinessError) => {
console.log(`Metadata output error code: ${metadataOutputError.code}`); console.log(`Metadata output error code: ${metadataOutputError.code}`);
}) });
}
``` ```
### off('error') ### off('error')
...@@ -4708,8 +5283,10 @@ off(type: 'error', callback?: ErrorCallback): void ...@@ -4708,8 +5283,10 @@ off(type: 'error', callback?: ErrorCallback): void
**示例:** **示例:**
```js ```ts
metadataOutput.off('error') function unregisterMetadataOutputError(metadataOutput: camera.MetadataOutput): void {
metadataOutput.off('error');
}
``` ```
## MetadataObjectType ## MetadataObjectType
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册