1# @ohos.multimedia.camera (Camera Management) 2 3The camera module provides a set of camera service APIs for you to easily develop a camera application. The application can access and operate the camera hardware to implement basic operations, such as preview, taking photos, and recording videos. It can also perform more operations, for example, controlling the flash and exposure time, and focusing or adjusting the focus. 4 5> **NOTE** 6> 7> The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8 9## Modules to Import 10 11```ts 12import camera from '@ohos.multimedia.camera'; 13``` 14 15## camera.getCameraManager 16 17getCameraManager(context: Context): CameraManager 18 19Obtains a **CameraManager** instance. This API returns the result synchronously. 20 21**System capability**: SystemCapability.Multimedia.Camera.Core 22 23**Parameters** 24 25| Name | Type | Mandatory| Description | 26| -------- | ----------------------------------------------- | ---- | ---------------------------- | 27| context | [Context](js-apis-inner-application-baseContext.md) | Yes | Application context. | 28 29**Return value** 30 31| Type | Description | 32| ----------------------------------------------- | ---------------------------- | 33| [CameraManager](#cameramanager) | **CameraManager** instance obtained. | 34 35**Error codes** 36 37For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 38 39| ID | Error Message | 40| --------------- | --------------- | 41| 7400101 | Parameter missing or parameter type incorrect | 42| 7400201 | Camera service fatal error. | 43 44**Example** 45 46```ts 47import common from '@ohos.app.ability.common'; 48import { BusinessError } from '@ohos.base'; 49 50function getCameraManager(context: common.BaseContext): camera.CameraManager | undefined { 51 let cameraManager: camera.CameraManager | undefined = undefined; 52 try { 53 cameraManager = camera.getCameraManager(context); 54 } catch (error) { 55 let err = error as BusinessError; 56 console.error(`The getCameraManager call failed. error code: ${err.code}`); 57 } 58 return cameraManager; 59} 60``` 61 62## CameraDevice 63 64Defines the camera device information. 65 66**System capability**: SystemCapability.Multimedia.Camera.Core 67 68| Name | Type | Mandatory| Read-only| Description | 69| -------------- | --------------------------------- | ---- | ---- |---------- | 70| cameraId | string | Yes | Yes | Camera ID.| 71| cameraPosition | [CameraPosition](#cameraposition) | Yes | Yes | Camera position. | 72| cameraType | [CameraType](#cameratype) | Yes | Yes | Camera type. | 73| connectionType | [ConnectionType](#connectiontype) | Yes | Yes | Camera connection type.| 74| hostDeviceName | string | Yes | Yes | Name of the remote device. **System API**: This is a system API.| 75| hostDeviceType | [HostDeviceType](#hostdevicetype) | Yes | Yes | Type of the remote device. **System API**: This is a system API.| 76 77## CameraPosition 78 79Enumerates the camera positions. 80 81**System capability**: SystemCapability.Multimedia.Camera.Core 82 83| Name | Value | Description | 84| --------------------------- | ---- | -------------- | 85| CAMERA_POSITION_UNSPECIFIED | 0 | Unspecified position. | 86| CAMERA_POSITION_BACK | 1 | Rear camera. | 87| CAMERA_POSITION_FRONT | 2 | Front camera. | 88| CAMERA_POSITION_FOLD_INNER<sup>11+</sup> | 3 | Folded camera. | 89 90## CameraType 91 92Enumerates the camera types. 93 94**System capability**: SystemCapability.Multimedia.Camera.Core 95 96| Name | Value | Description | 97| ----------------------- | ---- | -------------- | 98| CAMERA_TYPE_DEFAULT | 0 | Unspecified camera type. | 99| CAMERA_TYPE_WIDE_ANGLE | 1 | Wide camera. | 100| CAMERA_TYPE_ULTRA_WIDE | 2 | Ultra wide camera. | 101| CAMERA_TYPE_TELEPHOTO | 3 | Telephoto camera. | 102| CAMERA_TYPE_TRUE_DEPTH | 4 | Camera with depth of field information.| 103 104## ConnectionType 105 106Enumerates the camera connection types. 107 108**System capability**: SystemCapability.Multimedia.Camera.Core 109 110| Name | Value | Description | 111| ---------------------------- | ---- | ------------- | 112| CAMERA_CONNECTION_BUILT_IN | 0 | Built-in camera. | 113| CAMERA_CONNECTION_USB_PLUGIN | 1 | Camera connected using USB.| 114| CAMERA_CONNECTION_REMOTE | 2 | Remote camera.| 115 116## HostDeviceType 117 118Enumerates the remote camera types. 119 120**System API**: This is a system API. 121 122**System capability**: SystemCapability.Multimedia.Camera.Core 123 124| Name | Value | Description | 125| ---------------------------- | ---- | ------------- | 126| UNKNOWN_TYPE | 0 | Unknown type. | 127| PHONE | 0x0E | Phone camera.| 128| TABLET | 0x11 | Tablet camera.| 129 130## CameraStatus 131 132Enumerates the camera statuses. 133 134**System capability**: SystemCapability.Multimedia.Camera.Core 135 136| Name | Value | Description | 137| ------------------------- | ---- | ------------ | 138| CAMERA_STATUS_APPEAR | 0 | A camera appears. | 139| CAMERA_STATUS_DISAPPEAR | 1 | The camera disappears. | 140| CAMERA_STATUS_AVAILABLE | 2 | The camera is available. | 141| CAMERA_STATUS_UNAVAILABLE | 3 | The camera is unavailable. | 142 143## CameraStatusInfo 144 145Defines the camera status information. 146 147**System capability**: SystemCapability.Multimedia.Camera.Core 148 149| Name | Type | Mandatory | Description | 150| ------ | ----------------------------- | -------------- | ---------- | 151| camera | [CameraDevice](#cameradevice) | Yes | Camera device.| 152| status | [CameraStatus](#camerastatus) | Yes | Camera status.| 153 154## Profile 155 156Defines the camera profile. 157 158**System capability**: SystemCapability.Multimedia.Camera.Core 159 160| Name | Type | Mandatory| Read-only| Description | 161| -------- | ----------------------------- |---- | ---- | ------------- | 162| format | [CameraFormat](#cameraformat) | Yes | Yes | Output format. | 163| size | [Size](#size) | Yes | Yes | Resolution. | 164 165## FrameRateRange 166 167Defines the frame rate range. 168 169**System capability**: SystemCapability.Multimedia.Camera.Core 170 171| Name | Type | Mandatory| Read-only| Description | 172| -------- | ----------------------------- |---- | ---- | ------------- | 173| min | number | Yes | Yes | Minimum frame rate. | 174| max | number | Yes | Yes | Maximum frame rate. | 175 176## VideoProfile 177 178Defines the video configuration information. It inherits from [Profile](#profile). 179 180**System capability**: SystemCapability.Multimedia.Camera.Core 181 182| Name | Type | Mandatory| Read-only| Description | 183| ------------------------- | ----------------------------------------- | --- | ---- |----------- | 184| frameRateRange | [FrameRateRange](#frameraterange) | Yes | Yes | Frame rate range, in units of frames per second (FPS).| 185 186## CameraOutputCapability 187 188Defines the camera output capability. 189 190**System capability**: SystemCapability.Multimedia.Camera.Core 191 192| Name | Type | Mandatory| Read-only| Description | 193| ----------------------------- | -------------------------------------------------- | --- | ---- | ------------------- | 194| previewProfiles | Array\<[Profile](#profile)\> | Yes | Yes | Supported preview profiles. | 195| photoProfiles | Array\<[Profile](#profile)\> | Yes | Yes | Supported photo profiles. | 196| videoProfiles | Array\<[VideoProfile](#videoprofile)\> | Yes | Yes | Supported video profiles. | 197| supportedMetadataObjectTypes | Array\<[MetadataObjectType](#metadataobjecttype)\> | Yes | Yes | Supported metadata object types.| 198 199## SceneMode<sup>11+</sup> 200 201Enumerates the camera scene modes. 202 203**System capability**: SystemCapability.Multimedia.Camera.Core 204 205| Name | Value | Description | 206| ----------------------- | --------- | ------------ | 207| NORMAL_PHOTO | 1 | Normal photo mode. | 208| NORMAL_VIDEO | 2 | Normal record mode. | 209| PORTRAIT_PHOTO | 3 | Portrait photo mode. **System API**: This is a system API. | 210| NIGHT_PHOTO | 4 | Night photo mode. **System API**: This is a system API. | 211 212## CameraErrorCode 213 214Enumerates the camera error codes, 215 216which are returned when an API call is incorrect or the **on()** API is used to listen for the error status. 217 218**System capability**: SystemCapability.Multimedia.Camera.Core 219 220| Name | Value | Description | 221| ------------------------- | ---- | ------------ | 222| INVALID_ARGUMENT | 7400101 | A parameter is missing or the parameter type is incorrect. | 223| OPERATION_NOT_ALLOWED | 7400102 | The operation is not allowed. | 224| SESSION_NOT_CONFIG | 7400103 | The session is not configured. | 225| SESSION_NOT_RUNNING | 7400104 | The session is not running. | 226| SESSION_CONFIG_LOCKED | 7400105 | The session configuration is locked. | 227| DEVICE_SETTING_LOCKED | 7400106 | The device setting is locked. | 228| CONFLICT_CAMERA | 7400107 | The device is already started. | 229| DEVICE_DISABLED | 7400108 | The camera is disabled for security reasons. | 230| DEVICE_PREEMPTED | 7400109 | The camera is preempted. | 231| SERVICE_FATAL_ERROR | 7400201 | An error occurs in the camera service. | 232 233## CameraManager 234 235Implements camera management. Before calling any API in **CameraManager**, you must use [getCameraManager](#cameragetcameramanager) to obtain a **CameraManager** instance. 236 237### getSupportedCameras 238 239getSupportedCameras(): Array\<CameraDevice\> 240 241Obtains the supported camera devices. This API returns the result synchronously. 242 243**System capability**: SystemCapability.Multimedia.Camera.Core 244 245**Return value** 246 247| Type | Description | 248| ----------------------------------------------- | ---------------------------- | 249| Array\<[CameraDevice](#cameradevice)> | Array of camera devices supported. | 250 251**Example** 252 253```ts 254import { BusinessError } from '@ohos.base'; 255 256function getSupportedCameras(cameraManager: camera.CameraManager): Array<camera.CameraDevice> { 257 let cameras: Array<camera.CameraDevice> = []; 258 try { 259 cameras = cameraManager.getSupportedCameras(); 260 } catch (error) { 261 let err = error as BusinessError; 262 console.error(`The getSupportedCameras call failed. error code: ${err.code}`); 263 } 264 return cameras; 265} 266``` 267### getSupportedSceneModes<sup>11+</sup> 268 269getSupportedSceneModes(camera: CameraDevice): Array\<SceneMode\> 270 271Obtains the scene modes supported by a camera device. This API returns the result synchronously. 272 273**System capability**: SystemCapability.Multimedia.Camera.Core 274 275**Parameters** 276 277| Name | Type | Mandatory| Description | 278| ------------ |--------------------------------------------------------------- | -- | -------------------------- | 279| cameraDevice | [CameraDevice](#cameradevice) | Yes| **CameraDevice** instance, which is obtained through [getSupportedCameras](#getsupportedcameras). | 280 281**Return value** 282 283| Type | Description | 284| ----------------------------------------------- | ---------------------------- | 285| Array\<[SceneMode](#scenemode11)> | Array of scene modes supported. | 286 287**Example** 288 289```ts 290import { BusinessError } from '@ohos.base'; 291 292function getSupportedSceneModes(cameraManager: camera.CameraManager): Array<camera.SceneMode> { 293 let modes: Array<camera.SceneMode> = []; 294 try { 295 modes = cameraManager.getSupportedSceneModes(camera); 296 } catch (error) { 297 let err = error as BusinessError; 298 console.error(`The getSupportedSceneModes call failed. error code: ${err.code}`); 299 } 300 return modes; 301} 302``` 303 304### getSupportedOutputCapability<sup>(deprecated)</sup> 305 306getSupportedOutputCapability(camera: CameraDevice): CameraOutputCapability 307 308Obtains the output capability supported by a camera device. This API returns the result synchronously. 309 310> **NOTE** 311> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [getSupportedOutputCapability<sup>11+</sup>](#getsupportedoutputcapability11) instead. 312 313**System capability**: SystemCapability.Multimedia.Camera.Core 314 315**Parameters** 316 317| Name | Type | Mandatory| Description | 318| ------------ |--------------------------------------------------------------- | -- | -------------------------- | 319| cameraDevice | [CameraDevice](#cameradevice) | Yes| **CameraDevice** instance, which is obtained through [getSupportedCameras](#getsupportedcameras). | 320 321**Return value** 322 323| Type | Description | 324| ----------------------------------------------- | ---------------------------- | 325| [CameraOutputCapability](#cameraoutputcapability) | Camera output capability obtained. | 326 327**Example** 328 329```ts 330function getSupportedOutputCapability(cameraDevice: camera.CameraDevice, cameraManager: camera.CameraManager): camera.CameraOutputCapability { 331 let cameraOutputCapability: camera.CameraOutputCapability = cameraManager.getSupportedOutputCapability(cameraDevice); 332 return cameraOutputCapability; 333} 334``` 335 336### getSupportedOutputCapability<sup>11+</sup> 337 338getSupportedOutputCapability(camera: CameraDevice, mode: SceneMode): CameraOutputCapability 339 340Obtains the output capability supported by a camera device in a given scene mode. This API returns the result synchronously. 341 342**System capability**: SystemCapability.Multimedia.Camera.Core 343 344**Parameters** 345 346| Name | Type | Mandatory| Description | 347| ------------ |--------------------------------------------------------------- | -- | -------------------------- | 348| cameraDevice | [CameraDevice](#cameradevice) | Yes| **CameraDevice** instance, which is obtained through [getSupportedCameras](#getsupportedcameras). | 349| mode | [SceneMode](#scenemode11) | Yes| Scene mode, which is obtained through [getSupportedSceneModes](#getsupportedscenemodes11). | 350 351**Return value** 352 353| Type | Description | 354| ----------------------------------------------- | ---------------------------- | 355| [CameraOutputCapability](#cameraoutputcapability) | Camera output capability obtained. | 356 357**Example** 358 359```ts 360function getSupportedOutputCapability(cameraDevice: camera.CameraDevice, cameraManager: camera.CameraManager, sceneMode: camera.SceneMode): camera.CameraOutputCapability { 361 let cameraOutputCapability: camera.CameraOutputCapability = cameraManager.getSupportedOutputCapability(cameraDevice, sceneMode); 362 return cameraOutputCapability; 363} 364``` 365 366### isCameraMuted 367 368isCameraMuted(): boolean 369 370Checks whether the camera device is muted. 371 372Before calling the API, ensure that the camera device can be muted. You can use [isCameraMuteSupported](#iscameramutesupported) to check whether the camera device can be muted. 373 374**System capability**: SystemCapability.Multimedia.Camera.Core 375 376**Return value** 377 378| Type | Description | 379| ---------- | -------------------------------------------- | 380| boolean | **true**: The camera device is muted.<br>**false**: The camera device is not muted.| 381 382**Example** 383 384```ts 385function isCameraMuted(cameraManager: camera.CameraManager): boolean { 386 let isMuted: boolean = cameraManager.isCameraMuted(); 387 return isMuted; 388} 389``` 390 391### isCameraMuteSupported 392 393isCameraMuteSupported(): boolean 394 395Checks whether the camera device can be muted. 396 397**System API**: This is a system API. 398 399**System capability**: SystemCapability.Multimedia.Camera.Core 400 401**Return value** 402 403| Type | Description | 404| ---------- | ----------------------------- | 405| boolean | **true**: The camera device can be muted.<br>**false**: The camera device cannot be muted.| 406 407**Example** 408 409```ts 410function isCameraMuteSupported(cameraManager: camera.CameraManager): boolean { 411 let isMuteSupported: boolean = cameraManager.isCameraMuteSupported(); 412 return isMuteSupported; 413} 414``` 415 416### muteCamera 417 418muteCamera(mute: boolean): void 419 420Mutes or unmutes the camera device. 421 422**System API**: This is a system API. 423 424**System capability**: SystemCapability.Multimedia.Camera.Core 425 426**Parameters** 427 428| Name | Type | Mandatory | Description | 429| -------- | --------------------------------- | ---- | ---------- | 430| mute | boolean | Yes | Whether to mute the camera device. The value **true** means to mute the camera device, and **false** means the opposite. | 431 432**Example** 433 434```ts 435function muteCamera(cameraManager: camera.CameraManager): void { 436 let mute: boolean = true; 437 cameraManager.muteCamera(mute); 438} 439``` 440 441### createCameraInput 442 443createCameraInput(camera: CameraDevice): CameraInput 444 445Creates a **CameraInput** instance with the specified **CameraDevice** instance. This API returns the result synchronously. 446 447**Required permissions**: ohos.permission.CAMERA 448 449**System capability**: SystemCapability.Multimedia.Camera.Core 450 451**Parameters** 452 453| Name | Type | Mandatory| Description | 454| -------- | ------------------------------------------- | ---- |--------------------------------------------------| 455| cameraDevice | [CameraDevice](#cameradevice) | Yes | **CameraDevice** instance, which is obtained through [getSupportedCameras](#getsupportedcameras).| 456 457**Return value** 458 459| Type | Description | 460| ---------- | ----------------------------- | 461| [CameraInput](#camerainput) | **CameraInput** instance created. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 462 463**Error codes** 464 465For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 466 467| ID | Error Message | 468| --------------- | --------------- | 469| 7400101 | Parameter missing or parameter type incorrect. | 470 471**Example** 472 473```ts 474import { BusinessError } from '@ohos.base'; 475 476function createCameraInput(cameraDevice: camera.CameraDevice, cameraManager: camera.CameraManager): camera.CameraInput | undefined { 477 let cameraInput: camera.CameraInput | undefined = undefined; 478 try { 479 cameraInput = cameraManager.createCameraInput(cameraDevice); 480 } catch (error) { 481 // If the operation fails, error.code is returned and processed. 482 let err = error as BusinessError; 483 console.error(`The createCameraInput call failed. error code: ${err.code}`); 484 } 485 return cameraInput; 486} 487``` 488 489### createCameraInput 490 491createCameraInput(position: CameraPosition, type: CameraType): CameraInput 492 493Creates a **CameraInput** instance with the specified camera position and type. This API returns the result synchronously. 494 495**Required permissions**: ohos.permission.CAMERA 496 497**System capability**: SystemCapability.Multimedia.Camera.Core 498 499**Parameters** 500 501| Name | Type | Mandatory| Description | 502| -------- | ------------------------------------------- | ---- | --------------------------------- | 503| position | [CameraPosition](#cameraposition) | Yes | Camera position. You can call [getSupportedCameras](#getsupportedcameras) to obtain a **CameraDevice** instance, which contains the camera position information. | 504| type | [CameraType](#cameratype) | Yes | Camera type. You can call [getSupportedCameras](#getsupportedcameras) to obtain a **CameraDevice** instance, which contains the camera type information.| 505 506**Return value** 507 508| Type | Description | 509| ---------- | ----------------------------- | 510| [CameraInput](#camerainput) | **CameraInput** instance created. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 511 512**Error codes** 513 514For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 515 516| ID | Error Message | 517| --------------- | --------------- | 518| 7400101 | Parameter missing or parameter type incorrect. | 519 520**Example** 521 522```ts 523import { BusinessError } from '@ohos.base'; 524 525function createCameraInput(cameraDevice: camera.CameraDevice, cameraManager: camera.CameraManager): camera.CameraInput | undefined { 526 let position: camera.CameraPosition = cameraDevice.cameraPosition; 527 let type: camera.CameraType = cameraDevice.cameraType; 528 let cameraInput: camera.CameraInput | undefined = undefined; 529 try { 530 cameraInput = cameraManager.createCameraInput(position, type); 531 } catch (error) { 532 // If the operation fails, error.code is returned and processed. 533 let err = error as BusinessError; 534 console.error(`The createCameraInput call failed. error code: ${err.code}`); 535 } 536 return cameraInput; 537} 538``` 539 540### createPreviewOutput 541 542createPreviewOutput(profile: Profile, surfaceId: string): PreviewOutput 543 544Creates a **PreviewOutput** instance. This API returns the result synchronously. 545 546**System capability**: SystemCapability.Multimedia.Camera.Core 547 548**Parameters** 549 550| Name | Type | Mandatory| Description | 551| -------- | ----------------------------------------------- | ---- | ------------------------------- | 552| profile | [Profile](#profile) | Yes | Supported preview profiles, which are obtained through [getSupportedOutputCapability](#getsupportedoutputcapability11).| 553| surfaceId| string | Yes | Surface ID, which is obtained from [XComponent](../arkui-ts/ts-basic-components-xcomponent.md) or [ImageReceiver](js-apis-image.md#imagereceiver9).| 554 555**Return value** 556 557| Type | Description | 558| ---------- | ----------------------------- | 559| [PreviewOutput](#previewoutput) | **PreviewOutput** instance created. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 560 561**Error codes** 562 563For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 564 565| ID | Error Message | 566| --------------- | --------------- | 567| 7400101 | Parameter missing or parameter type incorrect. | 568 569**Example** 570 571```ts 572import { BusinessError } from '@ohos.base'; 573 574function createPreviewOutput(cameraOutputCapability: camera.CameraOutputCapability, cameraManager: camera.CameraManager, surfaceId: string): camera.PreviewOutput | undefined { 575 let profile: camera.Profile = cameraOutputCapability.previewProfiles[0]; 576 let previewOutput: camera.PreviewOutput | undefined = undefined; 577 try { 578 previewOutput = cameraManager.createPreviewOutput(profile, surfaceId); 579 } catch (error) { 580 // If the operation fails, error.code is returned and processed. 581 let err = error as BusinessError; 582 console.error(`The createPreviewOutput call failed. error code: ${err.code}`); 583 } 584 return previewOutput; 585} 586``` 587 588### createPhotoOutput<sup>(deprecated)</sup> 589 590createPhotoOutput(profile: Profile, surfaceId: string): PhotoOutput 591 592Creates a **PhotoOutput** instance. This API returns the result synchronously. 593 594> **NOTE** 595> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [createPhotoOutput<sup>11+</sup>](#createphotooutput11) instead. 596 597**System capability**: SystemCapability.Multimedia.Camera.Core 598 599**Parameters** 600 601| Name | Type | Mandatory| Description | 602| -------- | ------------------------------------------- | ---- | ----------------------------------- | 603| profile | [Profile](#profile) | Yes | Supported photo profiles, which are obtained through [getSupportedOutputCapability](#getsupportedoutputcapability11).| 604| surfaceId| string | Yes | Surface ID, which is obtained from [ImageReceiver](js-apis-image.md#imagereceiver9).| 605 606**Return value** 607 608| Type | Description | 609| ---------- | ----------------------------- | 610| [PhotoOutput](#photooutput) | **PhotoOutput** instance created. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 611 612**Error codes** 613 614For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 615 616| ID | Error Message | 617| --------------- | --------------- | 618| 7400101 | Parameter missing or parameter type incorrect. | 619 620```ts 621import { BusinessError } from '@ohos.base'; 622 623function createPhotoOutput(cameraOutputCapability: camera.CameraOutputCapability, cameraManager: camera.CameraManager, surfaceId: string): camera.PhotoOutput | undefined { 624 let profile: camera.Profile = cameraOutputCapability.photoProfiles[0]; 625 let photoOutput: camera.PhotoOutput | undefined = undefined; 626 try { 627 photoOutput = cameraManager.createPhotoOutput(profile, surfaceId); 628 } catch (error) { 629 // If the operation fails, error.code is returned and processed. 630 let err = error as BusinessError; 631 console.error(`The createPhotoOutput call failed. error code: ${err.code}`); 632 } 633 return photoOutput; 634} 635``` 636 637### createPhotoOutput<sup>11+</sup> 638 639createPhotoOutput(profile: Profile): PhotoOutput 640 641Creates a **PhotoOutput** instance. This API returns the result synchronously. 642 643**System capability**: SystemCapability.Multimedia.Camera.Core 644 645**Parameters** 646 647| Name | Type | Mandatory| Description | 648| -------- | ------------------------------------------- | ---- | ----------------------------------- | 649| profile | [Profile](#profile) | Yes | Supported photo profiles, which are obtained through [getSupportedOutputCapability](#getsupportedoutputcapability11).| 650 651**Return value** 652 653| Type | Description | 654| ---------- | ----------------------------- | 655| [PhotoOutput](#photooutput) | **PhotoOutput** instance created. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 656 657**Error codes** 658 659For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 660 661| ID | Error Message | 662| --------------- | --------------- | 663| 7400101 | Parameter missing or parameter type incorrect. | 664 665**Example** 666 667```ts 668import { BusinessError } from '@ohos.base'; 669 670function createPhotoOutput(cameraOutputCapability: camera.CameraOutputCapability, cameraManager: camera.CameraManager): camera.PhotoOutput | undefined { 671 let profile: camera.Profile = cameraOutputCapability.photoProfiles[0]; 672 let photoOutput: camera.PhotoOutput | undefined = undefined; 673 try { 674 photoOutput = cameraManager.createPhotoOutput(profile); 675 } catch (error) { 676 // If the operation fails, error.code is returned and processed. 677 let err = error as BusinessError; 678 console.error(`The createPhotoOutput call failed. error code: ${err.code}`); 679 } 680 return photoOutput; 681} 682``` 683 684### createVideoOutput 685 686createVideoOutput(profile: VideoProfile, surfaceId: string): VideoOutput 687 688Creates a **VideoOutput** instance. This API returns the result synchronously. 689 690**System capability**: SystemCapability.Multimedia.Camera.Core 691 692**Parameters** 693 694| Name | Type | Mandatory| Description | 695| -------- | ------------------------------------------- | ---- | ------------------------------ | 696| profile | [VideoProfile](#videoprofile) | Yes | Supported video profiles, which are obtained through [getSupportedOutputCapability](#getsupportedoutputcapability11).| 697| surfaceId| string | Yes | Surface ID, which is obtained from [AVRecorder](js-apis-media.md#avrecorder9).| 698 699**Return value** 700 701| Type | Description | 702| ---------- | ----------------------------- | 703| [VideoOutput](#videooutput) | **VideoOutput** instance created. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 704 705**Error codes** 706 707For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 708 709| ID | Error Message | 710| --------------- | --------------- | 711| 7400101 | Parameter missing or parameter type incorrect. | 712 713**Example** 714 715```ts 716import { BusinessError } from '@ohos.base'; 717 718function createVideoOutput(cameraOutputCapability: camera.CameraOutputCapability, cameraManager: camera.CameraManager, surfaceId: string): camera.VideoOutput | undefined { 719 let profile: camera.VideoProfile = cameraOutputCapability.videoProfiles[0]; 720 let videoOutput: camera.VideoOutput | undefined = undefined; 721 try { 722 videoOutput = cameraManager.createVideoOutput(profile, surfaceId); 723 } catch (error) { 724 // If the operation fails, error.code is returned and processed. 725 let err = error as BusinessError; 726 console.error(`The createVideoOutput call failed. error code: ${err.code}`); 727 } 728 return videoOutput; 729} 730``` 731 732### createMetadataOutput 733 734createMetadataOutput(metadataObjectTypes: Array\<MetadataObjectType\>): MetadataOutput 735 736Creates a **MetadataOutput** instance. This API returns the result synchronously. 737 738**System capability**: SystemCapability.Multimedia.Camera.Core 739 740**Parameters** 741 742| Name | Type | Mandatory| Description | 743| -------------------- | -------------------------------------------------- | --- | ---------------------------- | 744| metadataObjectTypes | Array\<[MetadataObjectType](#metadataobjecttype)\> | Yes | Metadata object types, which are obtained through [getSupportedOutputCapability](#getsupportedoutputcapability11).| 745 746**Return value** 747 748| Type | Description | 749| ---------- | ----------------------------- | 750| [MetadataOutput](#metadataoutput) | **MetadataOutput** instance created. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 751 752**Error codes** 753 754For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 755 756| ID | Error Message | 757| --------------- | --------------- | 758| 7400101 | Parameter missing or parameter type incorrect. | 759 760**Example** 761 762```ts 763import { BusinessError } from '@ohos.base'; 764 765function createMetadataOutput(cameraManager: camera.CameraManager, cameraOutputCapability: camera.CameraOutputCapability): void { 766 let metadataObjectTypes: Array<camera.MetadataObjectType> = cameraOutputCapability.supportedMetadataObjectTypes; 767 let metadataOutput: camera.MetadataOutput | undefined = undefined; 768 try { 769 metadataOutput = cameraManager.createMetadataOutput(metadataObjectTypes); 770 } catch (error) { 771 // If the operation fails, error.code is returned and processed. 772 let err = error as BusinessError; 773 console.error(`createMetadataOutput error. error code: ${err.code}`); 774 } 775} 776``` 777 778### createCaptureSession<sup>(deprecated)</sup> 779 780createCaptureSession(): CaptureSession 781 782Creates a **CaptureSession** instance. This API returns the result synchronously. 783 784> **NOTE** 785>This API is supported since API version 10 and deprecated since API version 11. You are advised to use [createSession](#createsession11) instead. 786 787**System capability**: SystemCapability.Multimedia.Camera.Core 788 789**Return value** 790 791| Type | Description | 792| ---------- | ----------------------------- | 793| [CaptureSession](#capturesession) | **CaptureSession** instance created. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 794 795**Error codes** 796 797For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 798 799| ID | Error Message | 800| --------------- | --------------- | 801| 7400201 | Camera service fatal error. | 802 803**Example** 804 805```ts 806import { BusinessError } from '@ohos.base'; 807 808function createCaptureSession(cameraManager: camera.CameraManager): camera.CaptureSession | undefined { 809 let captureSession: camera.CaptureSession | undefined = undefined; 810 try { 811 captureSession = cameraManager.createCaptureSession(); 812 } catch (error) { 813 // If the operation fails, error.code is returned and processed. 814 let err = error as BusinessError; 815 console.error(`createCaptureSession error. error code: ${err.code}`); 816 } 817 return captureSession; 818} 819``` 820 821### createSession<sup>11+</sup> 822 823createSession\<T extends Session\>(mode: SceneMode): T 824 825Creates a **Session** instance with a given scene mode. This API returns the result synchronously. 826 827**System capability**: SystemCapability.Multimedia.Camera.Core 828 829**Parameters** 830 831| Name | Type | Mandatory| Description | 832| -------- | -----------------| ---- | --------- | 833| mode | SceneMode | Yes | Scene mode.| 834 835**Return value** 836 837| Type | Description | 838| ---------- | ----------------------------- | 839| [T extends Session](#session) | **Session** instance created. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 840 841**Error codes** 842 843For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 844 845| ID | Error Message | 846| --------------- | --------------- | 847| 7400201 | Camera service fatal error. | 848 849**Example** 850 851```ts 852import { BusinessError } from '@ohos.base'; 853 854function createSession(cameraManager: camera.CameraManager, mode: camera.SceneMode): camera.Session | undefined { 855 let photoSession: camera.PhotoSession | undefined = undefined; 856 try { 857 photoSession = cameraManager.createSession(mode.NORMAL_PHOTO); 858 } catch (error) { 859 // If the operation fails, error.code is returned and processed. 860 let err = error as BusinessError; 861 console.error(`createCaptureSession error. error code: ${err.code}`); 862 } 863 return photoSession; 864} 865``` 866 867### on('cameraStatus') 868 869on(type: 'cameraStatus', callback: AsyncCallback\<CameraStatusInfo\>): void 870 871Subscribes to camera status events. This API uses an asynchronous callback to return the result. 872 873**System capability**: SystemCapability.Multimedia.Camera.Core 874 875**Parameters** 876 877| Name | Type | Mandatory| Description | 878| -------- | -----------------| ---- | --------- | 879| type | string | Yes | Event type. The value is fixed at **'cameraStatus'**. The event can be listened for when a **CameraManager** instance is obtained. This event is triggered and the corresponding information is returned only when the camera device is enabled or disabled.| 880| callback | AsyncCallback\<[CameraStatusInfo](#camerastatusinfo)\> | Yes | Callback used to return the camera status change.| | 881 882**Example** 883 884```ts 885import { BusinessError } from '@ohos.base'; 886 887function callback(err: BusinessError, cameraStatusInfo: camera.CameraStatusInfo): void { 888 console.info(`camera : ${cameraStatusInfo.camera.cameraId}`); 889 console.info(`status: ${cameraStatusInfo.status}`); 890} 891 892function registerCameraStatus(cameraManager: camera.CameraManager): void { 893 cameraManager.on('cameraStatus', callback); 894} 895``` 896 897### off('cameraStatus') 898 899off(type: 'cameraStatus', callback?: AsyncCallback\<CameraStatusInfo\>): void 900 901Unsubscribes from camera status events. This API uses an asynchronous callback to return the result. 902 903**System capability**: SystemCapability.Multimedia.Camera.Core 904 905**Parameters** 906 907| Name | Type | Mandatory| Description | 908| -------- | -----------------| ---- | --------- | 909| type | string | Yes | Event type. The value is fixed at **'cameraStatus'**. The event can be listened for when a **CameraManager** instance is obtained.| 910| callback | AsyncCallback\<[CameraStatusInfo](#camerastatusinfo)\> | No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('error') with the specified callback is canceled. (The callback object cannot be an anonymous function.)| 911 912**Example** 913 914```ts 915function unregisterCameraStatus(cameraManager: camera.CameraManager): void { 916 cameraManager.off('cameraStatus'); 917} 918``` 919 920### on('cameraMute') 921 922on(type: 'cameraMute', callback: AsyncCallback\<boolean\>): void 923 924Subscribes to camera mute status events. This API uses an asynchronous callback to return the result. 925 926**System API**: This is a system API. 927 928**System capability**: SystemCapability.Multimedia.Camera.Core 929 930**Parameters** 931 932| Name | Type | Mandatory| Description | 933| -------- | --------------- | ---- | --------- | 934| type | string | Yes | Event type. The value is fixed at **'cameraMute'**, indicating the camera mute status. The event can be listened for when a **CameraManager** instance is obtained. This event is triggered and the status is returned when the camera device is muted or unmuted.| 935| callback | AsyncCallback\<boolean> | Yes | Callback used to return the mute status. The value **true** means that the camera is enabled, and **false** means that the camera is disabled. | 936 937**Example** 938 939```ts 940import { BusinessError } from '@ohos.base'; 941 942function callback(err: BusinessError, curMuetd: boolean): void { 943 let isMuted: boolean = curMuetd; 944 console.info(`cameraMute status: ${isMuted}`); 945} 946 947function registerCameraMute(cameraManager: camera.CameraManager): void { 948 cameraManager.on('cameraMute', callback); 949} 950``` 951 952### off('cameraMute') 953 954off(type: 'cameraMute', callback?: AsyncCallback\<boolean\>): void 955 956Unsubscribes from camera mute status events. This API uses an asynchronous callback to return the result. 957 958**System API**: This is a system API. 959 960**System capability**: SystemCapability.Multimedia.Camera.Core 961 962**Parameters** 963 964| Name | Type | Mandatory| Description | 965| -------- | --------------- | ---- |---------------------------------------------------------| 966| type | string | Yes | Event type. The value is fixed at **'cameraMute'**, indicating the camera mute status. The event can be listened for when a **CameraManager** instance is obtained.| 967| callback | AsyncCallback\<boolean> | No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('error') with the specified callback is canceled. (The callback object cannot be an anonymous function.) | 968 969**Example** 970 971```ts 972import { BusinessError } from '@ohos.base'; 973 974function callback(err: BusinessError, curMuetd: boolean): void { 975 let isMuted: boolean = curMuetd; 976} 977 978function unregisterCameraMute(cameraManager: camera.CameraManager): void { 979 cameraManager.on('cameraMute', callback); 980 cameraManager.off('cameraMute', callback); 981} 982``` 983 984### isPrelaunchSupported 985 986isPrelaunchSupported(camera: CameraDevice): boolean 987 988Checks whether a camera device supports prelaunch. 989 990**System API**: This is a system API. 991 992**System capability**: SystemCapability.Multimedia.Camera.Core 993 994**Parameters** 995 996| Name | Type | Mandatory| Description | 997| -------- | --------------- | ---- | --------- | 998| camera | [CameraDevice](#cameradevice) | Yes| Camera device.| 999 1000**Return value** 1001 1002| Type| Description| 1003| -------- | --------------- | 1004| boolean | **true**: The camera device supports prelaunch.<br>**false**: The camera device does not support prelaunch.| 1005 1006**Error codes** 1007 1008For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 1009 1010| ID | Error Message | 1011| --------------- | --------------- | 1012| 7400101 | Parameter missing or parameter type incorrect. | 1013 1014**Example** 1015 1016```ts 1017import common from '@ohos.app.ability.common'; 1018 1019function isPreLaunchSupported(context: common.BaseContext): boolean { 1020 let cameraManager: camera.CameraManager = camera.getCameraManager(context); 1021 let cameras: Array<camera.CameraDevice> = cameraManager.getSupportedCameras(); 1022 let isSupported: boolean = false; 1023 if (cameras && cameras.length >= 1) { 1024 isSupported = cameraManager.isPrelaunchSupported(cameras[0]); 1025 console.info(`PreLaunch supported states: ${isSupported}`); 1026 return isSupported; 1027 } 1028 return isSupported; 1029} 1030``` 1031 1032### setPrelaunchConfig 1033 1034setPrelaunchConfig(prelaunchConfig: PrelaunchConfig): void 1035 1036Sets prelaunch configuration. 1037 1038Before the setting, use [isPrelaunchSupported](#isprelaunchsupported) to check whether the camera device supports prelaunch. 1039 1040**System API**: This is a system API. 1041 1042**Required permissions**: ohos.permission.CAMERA 1043 1044**System capability**: SystemCapability.Multimedia.Camera.Core 1045 1046**Parameters** 1047 1048| Name | Type | Mandatory| Description | 1049| -------- | --------------- | ---- | --------- | 1050| prelaunchConfig | [PrelaunchConfig](#prelaunchconfig) | Yes| Prelaunch configuration.| 1051 1052**Error codes** 1053 1054For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 1055 1056| ID | Error Message | 1057| --------------- | --------------- | 1058| 7400101 | Parameter missing or parameter type incorrect. | 1059| 7400102 | Operation not allow. | 1060 1061**Example** 1062 1063```ts 1064import common from '@ohos.app.ability.common'; 1065import { BusinessError } from '@ohos.base'; 1066 1067function setPrelaunchConfig(context: common.BaseContext): void { 1068 let cameraManager: camera.CameraManager = camera.getCameraManager(context); 1069 let cameras: Array<camera.CameraDevice> = cameraManager.getSupportedCameras(); 1070 if (cameras && cameras.length >= 1) { 1071 let cameraDevice: camera.CameraDevice = cameras[0]; 1072 if(cameraManager.isPrelaunchSupported(cameraDevice)) { 1073 try { 1074 cameraManager.setPrelaunchConfig({cameraDevice: cameraDevice}); 1075 } catch (error) { 1076 let err = error as BusinessError; 1077 console.error(`setPrelaunchConfig error. Code: ${err.code}, message: ${err.message}`); 1078 } 1079 } 1080 } 1081} 1082``` 1083 1084### prelaunch 1085 1086prelaunch(): void 1087 1088Prelaunches the camera device. This API is called when a user clicks the system camera icon to start the camera application. 1089 1090**System API**: This is a system API. 1091 1092**System capability**: SystemCapability.Multimedia.Camera.Core 1093 1094**Example** 1095 1096```ts 1097import common from '@ohos.app.ability.common'; 1098import { BusinessError } from '@ohos.base'; 1099 1100function preLaunch(context: common.BaseContext): void { 1101 let cameraManager: camera.CameraManager = camera.getCameraManager(context); 1102 try { 1103 cameraManager.prelaunch(); 1104 } catch (error) { 1105 let err = error as BusinessError; 1106 console.error(`prelaunch error. Code: ${err.code}, message: ${err.message}`); 1107 } 1108} 1109``` 1110 1111### createDeferredPreviewOutput 1112 1113createDeferredPreviewOutput(profile: Profile): PreviewOutput 1114 1115Creates a deferred **PreviewOutput** instance and adds it, instead of a common **PreviewOutput** instance, to the data stream during stream configuration. 1116 1117**System API**: This is a system API. 1118 1119**System capability**: SystemCapability.Multimedia.Camera.Core 1120 1121**Parameters** 1122 1123| Name | Type | Mandatory| Description | 1124| -------- | --------------- | ---- | --------- | 1125| profile | [Profile](#profile) | Yes| Configuration file of the camera preview stream.| 1126 1127**Return value** 1128 1129| Type| Description| 1130| -------- | --------------- | 1131| [PreviewOutput](#previewoutput) | **PreviewOutput** instance obtained.| 1132 1133**Error codes** 1134 1135For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 1136 1137| ID | Error Message | 1138| --------------- | --------------- | 1139| 7400101 | Parameter missing or parameter type incorrect. | 1140 1141**Example** 1142 1143```ts 1144import common from '@ohos.app.ability.common'; 1145 1146function getDeferredPreviewOutput(context: common.BaseContext, previewProfile: camera.Profile): camera.PreviewOutput { 1147 const cameraManager: camera.CameraManager = camera.getCameraManager(context); 1148 const output: camera.PreviewOutput = cameraManager.createDeferredPreviewOutput(previewProfile); 1149 return output; 1150} 1151``` 1152 1153### preSwitchCamera<sup>11+</sup> 1154 1155preSwitchCamera(cameraId: string): void 1156 1157Pre-switches a camera device to speed up its startup. 1158 1159**System API**: This is a system API. 1160 1161**System capability**: SystemCapability.Multimedia.Camera.Core 1162 1163**Parameters** 1164 1165| Name | Type | Mandatory| Description | 1166| -------- | --------------- | ---- | --------- | 1167| cameraId | string | Yes| Camera device.| 1168 1169**Error codes** 1170 1171For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 1172 1173| ID | Error Message | 1174| --------------- | --------------- | 1175| 7400101 | Parameter missing or parameter type incorrect. | 1176 1177**Example** 1178 1179```ts 1180import common from '@ohos.app.ability.common'; 1181import { BusinessError } from '@ohos.base'; 1182 1183function preSwitch(cameraDevice: camera.CameraDevice, context: common.BaseContext): void { 1184 let cameraManager: camera.CameraManager = camera.getCameraManager(context); 1185 try { 1186 cameraManager.preSwitchCamera(cameraDevice.cameraId); 1187 } catch (error) { 1188 let err = error as BusinessError; 1189 console.error(`prelaunch error. Code: ${err.code}, message: ${err.message}`); 1190 } 1191} 1192``` 1193 1194### isTorchSupported<sup>11+</sup> 1195 1196isTorchSupported(): boolean 1197 1198Checks whether the camera device supports the flashlight. 1199 1200**System capability**: SystemCapability.Multimedia.Camera.Core 1201 1202**Return value** 1203 1204| Type | Description | 1205| ---------- | ----------------------------- | 1206| boolean | **true**: The camera device supports the flashlight.<br>**false**: The camera device does not support the flashlight.| 1207 1208**Example** 1209 1210```ts 1211function isTorchSupported(cameraManager: camera.CameraManager): boolean { 1212 let isSupported = cameraManager.isTorchSupported(); 1213 return isSupported; 1214} 1215``` 1216 1217### isTorchModeSupported<sup>11+</sup> 1218 1219isTorchModeSupported(mode: TorchMode): boolean 1220 1221Checks whether a flashlight mode is supported. 1222 1223**System capability**: SystemCapability.Multimedia.Camera.Core 1224 1225**Parameters** 1226 1227| Name | Type | Mandatory| Description | 1228| -------- | --------------- | ---- | --------- | 1229| mode | [TorchMode](#torchmode) | Yes| Flashlight mode.| 1230 1231**Return value** 1232 1233| Type | Description | 1234| ---------- | ----------------------------- | 1235| boolean | **true**: The flashlight mode is supported.<br>**false**: The flashlight mode is not supported.| 1236 1237**Example** 1238 1239```ts 1240function isTorchModeSupported(cameraManager: camera.CameraManager, torchMode: camera.TorchMode): boolean { 1241 let isSupported = cameraManager.isTorchModeSupported(torchMode); 1242 return isSupported; 1243} 1244``` 1245 1246### getTorchMode<sup>11+</sup> 1247 1248getTorchMode(): TorchMode 1249 1250Obtains the flashlight mode of this camera device. 1251 1252**System capability**: SystemCapability.Multimedia.Camera.Core 1253 1254**Return value** 1255 1256| Type | Description | 1257| ---------- | ----------------------------- | 1258| [TorchMode](#torchmode) | Flashlight mode.| 1259 1260**Example** 1261 1262```ts 1263function getTorchMode(cameraManager: camera.CameraManager): camera.TorchMode | undefined { 1264 let torchMode: camera.TorchMode | undefined = undefined; 1265 torchMode = cameraManager.getTorchMode(); 1266 return torchMode; 1267} 1268``` 1269 1270### setTorchMode<sup>11+</sup> 1271 1272setTorchMode(mode: TorchMode): void 1273 1274Sets the flashlight mode. 1275 1276**System capability**: SystemCapability.Multimedia.Camera.Core 1277 1278**Parameters** 1279 1280| Name | Type | Mandatory| Description | 1281| -------- | --------------- | ---- | --------- | 1282| mode | [TorchMode](#torchmode) | Yes| Flashlight mode.| 1283 1284**Error codes** 1285 1286For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 1287 1288| ID | Error Message | 1289| --------------- | --------------- | 1290| 7400101 | Parameter missing or parameter type incorrect. | 1291 1292**Example** 1293 1294```ts 1295import { BusinessError } from '@ohos.base'; 1296 1297function setTorchMode(cameraManager: camera.CameraManager, torchMode: camera.TorchMode): void { 1298 try { 1299 cameraManager.setTorchMode(torchMode); 1300 } catch (error) { 1301 // If the operation fails, error.code is returned and processed. 1302 let err = error as BusinessError; 1303 console.error(`The setTorchMode call failed. error code: ${err.code}`); 1304 } 1305} 1306``` 1307 1308### on('torchStatusChange')<sup>11+</sup> 1309 1310on(type: 'torchStatusChange', callback: AsyncCallback\<TorchStatusInfo\>): void 1311 1312Subscribes to flashlight status change events. This API uses an asynchronous callback to return the result. 1313 1314**System capability**: SystemCapability.Multimedia.Camera.Core 1315 1316**Parameters** 1317 1318| Name | Type | Mandatory| Description | 1319| -------- | --------------- | ---- | --------- | 1320| type | string | Yes | Event type. The value is fixed at **'torchStatusChange'**. The event can be listened for when a **CameraManager** instance is obtained. Currently, this event is triggered only in the following scenarios: The flashlight is turned on or turned off, or becomes unavailable or available.| 1321| callback | AsyncCallback\<TorchStatusInfo> | Yes | Callback used to return the flashlight status. | 1322 1323**Example** 1324 1325```ts 1326import { BusinessError } from '@ohos.base'; 1327 1328function callback(err: BusinessError, torchStatusInfo: camera.TorchStatusInfo): void { 1329 console.info(`onTorchStatusChange, isTorchAvailable: ${torchStatusInfo.isTorchAvailable}, isTorchActive: ${torchStatusInfo.isTorchActive}, level: ${torchStatusInfo.torchLevel}`); 1330} 1331 1332function registerTorchStatusChange(cameraManager: camera.CameraManager): void { 1333 cameraManager.on('torchStatusChange', callback); 1334} 1335``` 1336 1337### off('torchStatusChange')<sup>11+</sup> 1338 1339off(type: 'torchStatusChange', callback?: AsyncCallback\<TorchStatusInfo\>): void 1340 1341Unsubscribes from flashlight status change events. This API uses an asynchronous callback to return the result. 1342 1343**System capability**: SystemCapability.Multimedia.Camera.Core 1344 1345**Parameters** 1346 1347| Name | Type | Mandatory| Description | 1348| -------- | --------------- | ---- | --------- | 1349| type | string | Yes | Event type. The value is fixed at **'torchStatusChange'**. The event can be listened for when a **CameraManager** instance is obtained.| 1350| callback | AsyncCallback\<TorchStatusInfo> | No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('error') with the specified callback is canceled. (The callback object cannot be an anonymous function.) | 1351 1352**Example** 1353 1354```ts 1355function unregisterTorchStatusChange(cameraManager: camera.CameraManager): void { 1356 cameraManager.off('torchStatusChange'); 1357} 1358``` 1359 1360## PrelaunchConfig 1361 1362Defines the camera prelaunch configuration. 1363 1364Currently, the configuration is used for sensor-level prelaunch. It will be used for stream-level prelaunch in a later version. 1365 1366**System API**: This is a system API. 1367 1368**System capability**: SystemCapability.Multimedia.Camera.Core 1369 1370| Name | Type | Mandatory | Description | 1371| ------ | ----------------------------- | -------------- | ---------- | 1372| cameraDevice | [CameraDevice](#cameradevice) | Yes | Camera device.| 1373| restoreParamType<sup>11+</sup> | [RestoreParamType](#restoreparamtype11) | No | Type of the parameter used for prelaunch.| 1374| activeTime<sup>11+</sup> | number | No | Activation time, in minutes.| 1375| settingParam<sup>11+</sup> | [SettingParam](#settingparam11) | No | Setting parameter.| 1376 1377## RestoreParamType<sup>11+</sup> 1378 1379Enumerates the types of the parameters used for prelaunch. 1380 1381**System API**: This is a system API. 1382 1383**System capability**: SystemCapability.Multimedia.Camera.Core 1384 1385| Name | Value | Description | 1386| ----------------| ---- | ---------| 1387| NO_NEED_RESTORE_PARAM | 0 | The parameter used for prelaunch is not required. | 1388| PRESISTENT_DEFAULT_PARAM | 1 | Persistent parameter type. This parameter is used to restore stream information with the specified time point. | 1389| TRANSIENT_ACTIVE_PARAM | 2 | Temporary parameter type. This parameter is used to restore stream information only within a period of time after the camera application is closed. Its priority is higher than that of the persistent parameter. | 1390 1391## SettingParam<sup>11+</sup> 1392 1393Defines the effect parameters used to preheat an image. 1394 1395**System API**: This is a system API. 1396 1397**System capability**: SystemCapability.Multimedia.Camera.Core 1398 1399| Name | Type | Mandatory | Description | 1400| ------ | ----------------------------- | -------------- | ---------- | 1401| skinSmoothLevel | number | Yes | Skin smoothing level, which is obtained through [getSupportedBeautyRange](#getsupportedbeautyrange). For example, the value **1** indicates level-1 smoothing.| 1402| faceSlender | number | Yes | Face slimming level, which is obtained through [getSupportedBeautyRange](#getsupportedbeautyrange). For example, the value **1** indicates level-1 slimming.| 1403| skinTone | number | Yes | Skin tone perfection level, which is obtained through [getSupportedBeautyRange](#getsupportedbeautyrange). For example, the value **0xBF986C** indicates a specific color.| 1404 1405## TorchMode<sup>11+</sup> 1406 1407Enumerates the flashlight modes. 1408 1409**System capability**: SystemCapability.Multimedia.Camera.Core 1410 1411| Name | Value | Description | 1412| ---------------------------- | ---- | ------------- | 1413| OFF | 0 | The flashlight is off. | 1414| ON | 1 | The flashlight is on.| 1415| AUTO | 2 | The flashlight mode is auto.| 1416 1417## TorchStatusInfo<sup>11+</sup> 1418 1419Defines the flashlight status information. 1420 1421**System capability**: SystemCapability.Multimedia.Camera.Core 1422 1423| Name | Type | Read-only| Description | 1424| -------------- | --------------------------------- | ---- | ---------- | 1425| isTorchAvailable | boolean | Yes | Whether the flashlight is available.| 1426| isTorchActive | boolean | Yes | Whether the flashlight is activated. | 1427| torchLevel | number | Yes | Flashlight level. The value range is [0, 1]. A larger value indicates a greater luminance. | 1428 1429## Size 1430 1431Defines the output capability. 1432 1433**System capability**: SystemCapability.Multimedia.Camera.Core 1434 1435| Name | Type | Readable| Writable| Description | 1436| ------ | ------ | ---- | ---- | ------------ | 1437| height | number | Yes | Yes | Image height, in pixels.| 1438| width | number | Yes | Yes | Image width, in pixels.| 1439 1440## Point 1441 1442Defines the point coordinates, which are used for focus and exposure configuration. 1443 1444**System capability**: SystemCapability.Multimedia.Camera.Core 1445 1446| Name | Type | Mandatory | Description | 1447| ------ | ------ | ---- | ------------ | 1448| x | number | Yes | X coordinate of a point. | 1449| y | number | Yes | Y coordinate of a point. | 1450 1451## CameraFormat 1452 1453Enumerates the camera output formats. 1454 1455**System capability**: SystemCapability.Multimedia.Camera.Core 1456 1457| Name | Value | Description | 1458| ----------------------- | --------- | ------------ | 1459| CAMERA_FORMAT_RGBA_8888 | 3 | RGB image. | 1460| CAMERA_FORMAT_YUV_420_SP| 1003 | YUV 420 SP image. | 1461| CAMERA_FORMAT_JPEG | 2000 | JPEG image. | 1462| CAMERA_FORMAT_YCBCR_P010<sup>11+</sup> | 2001 | YCBCR_P010 image. | 1463| CAMERA_FORMAT_YCRCB_P010<sup>11+</sup> | 2002 | YCRCB_P010 image. | 1464 1465## CameraInput 1466 1467Defines the camera input object. 1468 1469Provides camera device information used in [CaptureSession](#capturesession). 1470 1471### open 1472 1473open(callback: AsyncCallback\<void\>): void 1474 1475Opens this camera device. This API uses an asynchronous callback to return the result. 1476 1477**System capability**: SystemCapability.Multimedia.Camera.Core 1478 1479**Parameters** 1480 1481| Name | Type | Mandatory| Description | 1482| -------- | -------------------- | ---- | ------------------- | 1483| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 1484 1485**Error codes** 1486 1487For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 1488 1489| ID | Error Message | 1490| --------------- | --------------- | 1491| 7400107 | Can not use camera cause of conflict. | 1492| 7400108 | Camera disabled cause of security reason. | 1493| 7400201 | Camera service fatal error. | 1494 1495**Example** 1496 1497```ts 1498import { BusinessError } from '@ohos.base'; 1499 1500function openCameraInput(cameraInput: camera.CameraInput): void { 1501 cameraInput.open((err: BusinessError) => { 1502 if (err) { 1503 console.error(`Failed to open the camera, error code: ${err.code}.`); 1504 return; 1505 } 1506 console.info('Callback returned with camera opened.'); 1507 }); 1508} 1509``` 1510 1511### open 1512 1513open(): Promise\<void\> 1514 1515Opens this camera device. This API uses a promise to return the result. 1516 1517**System capability**: SystemCapability.Multimedia.Camera.Core 1518 1519**Return value** 1520 1521| Type | Description | 1522| -------------- | ----------------------- | 1523| Promise\<void\> | Promise used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 1524 1525**Error codes** 1526 1527For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 1528 1529| ID | Error Message | 1530| --------------- | --------------- | 1531| 7400107 | Can not use camera cause of conflict. | 1532| 7400108 | Camera disabled cause of security reason. | 1533| 7400201 | Camera service fatal error. | 1534 1535**Example** 1536 1537```ts 1538import { BusinessError } from '@ohos.base'; 1539 1540function openCameraInput(cameraInput: camera.CameraInput): void { 1541 cameraInput.open().then(() => { 1542 console.info('Promise returned with camera opened.'); 1543 }).catch((err: BusinessError) => { 1544 let err = error as BusinessError; 1545 console.error(`Failed to open the camera, error code: ${err.code}.`); 1546 }); 1547} 1548``` 1549 1550### close 1551 1552close(callback: AsyncCallback\<void\>\): void 1553 1554Closes this camera device. This API uses an asynchronous callback to return the result. 1555 1556**System capability**: SystemCapability.Multimedia.Camera.Core 1557 1558**Parameters** 1559 1560| Name | Type | Mandatory| Description | 1561| -------- | -------------------- | ---- | -------------------- | 1562| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 1563 1564**Error codes** 1565 1566For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 1567 1568| ID | Error Message | 1569| --------------- | --------------- | 1570| 7400201 | Camera service fatal error. | 1571 1572**Example** 1573 1574```ts 1575import { BusinessError } from '@ohos.base'; 1576 1577function closeCameraInput(cameraInput: camera.CameraInput): void { 1578 cameraInput.close((err: BusinessError) => { 1579 if (err) { 1580 console.error(`Failed to close the cameras, error code: ${err.code}.`); 1581 return; 1582 } 1583 console.info('Callback returned with camera closed.'); 1584 }); 1585} 1586``` 1587 1588### close 1589 1590close(): Promise\<void\> 1591 1592Closes this camera device. This API uses a promise to return the result. 1593 1594**System capability**: SystemCapability.Multimedia.Camera.Core 1595 1596**Return value** 1597 1598| Type | Description | 1599| -------------- | ----------------------- | 1600| Promise\<void\> | Promise used to return the result.| 1601 1602**Error codes** 1603 1604For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 1605 1606| ID | Error Message | 1607| --------------- | --------------- | 1608| 7400201 | Camera service fatal error. | 1609 1610**Example** 1611 1612```ts 1613import { BusinessError } from '@ohos.base'; 1614 1615function closeCameraInput(cameraInput: camera.CameraInput): void { 1616 cameraInput.close().then(() => { 1617 console.info('Promise returned with camera closed.'); 1618 }).catch((err: BusinessError) => { 1619 let err = error as BusinessError; 1620 console.error(`Failed to close the cameras, error code: ${err.code}.`); 1621 }); 1622} 1623``` 1624 1625### on('error') 1626 1627on(type: 'error', camera: CameraDevice, callback: ErrorCallback): void 1628 1629Subscribes to **CameraInput** error events. This API uses a callback to return the result. 1630 1631**System capability**: SystemCapability.Multimedia.Camera.Core 1632 1633**Parameters** 1634 1635| Name | Type | Mandatory| Description | 1636| -------- | -------------------------------- | --- | ------------------------------------------- | 1637| type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a **CameraInput** instance is created. This event is triggered and the result is returned when an error occurs on the camera device. For example, if the camera device is unavailable or a conflict occurs, the error information is returned.| 1638| cameraDevice | [CameraDevice](#cameradevice) | Yes | Camera device.| 1639| callback | ErrorCallback | Yes | Callback used to return an error code defined in [CameraErrorCode](#cameraerrorcode). | 1640 1641**Example** 1642 1643```ts 1644import { BusinessError } from '@ohos.base'; 1645 1646function callback(err: BusinessError): void { 1647 console.error(`Camera input error code: ${err.code}`); 1648} 1649 1650function registerCameraInputError(cameraInput: camera.CameraInput, cameraDevice: camera.CameraDevice): void { 1651 cameraInput.on('error', cameraDevice, callback); 1652} 1653``` 1654 1655### off('error') 1656 1657off(type: 'error', camera: CameraDevice, callback?: ErrorCallback): void 1658 1659Unsubscribes from **CameraInput** error events. 1660 1661**System capability**: SystemCapability.Multimedia.Camera.Core 1662 1663**Parameters** 1664 1665| Name | Type | Mandatory| Description | 1666| -------- | -------------------------------- | --- | ------------------------------------------- | 1667| type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a **CameraInput** instance is created. This event is triggered and the result is returned when an error occurs on the camera device. For example, if the camera device is unavailable or a conflict occurs, the error information is returned.| 1668| cameraDevice | [CameraDevice](#cameradevice) | Yes | Camera device.| 1669| callback | ErrorCallback | No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('error') with the specified callback is canceled. (The callback object cannot be an anonymous function.) | 1670 1671**Example** 1672 1673```ts 1674function unregisterCameraInputError(cameraInput: camera.CameraInput, cameraDevice: camera.CameraDevice): void { 1675 cameraInput.off('error', cameraDevice); 1676} 1677``` 1678 1679## CameraOutput 1680 1681Implements output information used in [CaptureSession](#capturesession). It is the base class of **output**. 1682 1683### release 1684 1685release(callback: AsyncCallback\<void\>): void 1686 1687Releases output resources. This API uses an asynchronous callback to return the result. 1688 1689**System capability**: SystemCapability.Multimedia.Camera.Core 1690 1691**Parameters** 1692 1693| Name | Type | Mandatory| Description | 1694| -------- | -------------------- | ---- | ------------------- | 1695| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 1696 1697**Error codes** 1698 1699For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 1700 1701| ID | Error Message | 1702| --------------- | --------------- | 1703| 7400201 | Camera service fatal error. | 1704 1705**Example** 1706 1707```ts 1708import { BusinessError } from '@ohos.base'; 1709 1710function releasePreviewOutput(previewOutput: camera.PreviewOutput): void { 1711 previewOutput.release((err: BusinessError) => { 1712 if (err) { 1713 console.error(`Failed to release the PreviewOutput instance ${err.code}`); 1714 return; 1715 } 1716 console.info('Callback invoked to indicate that the previewOutput instance is released successfully.'); 1717 }); 1718} 1719 1720function releaseVideoOutput(videoOutput: camera.VideoOutput): void { 1721 videoOutput.release((err: BusinessError) => { 1722 if (err) { 1723 console.error(`Failed to release the VideoOutput instance ${err.code}`); 1724 return; 1725 } 1726 console.info('Callback invoked to indicate that the videoOutput instance is released successfully.'); 1727 }); 1728} 1729``` 1730 1731### release 1732 1733release(): Promise\<void\> 1734 1735Releases output resources. This API uses a promise to return the result. 1736 1737**System capability**: SystemCapability.Multimedia.Camera.Core 1738 1739**Return value** 1740 1741| Type | Description | 1742| -------------- | ----------------------- | 1743| Promise\<void\> | Promise used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 1744 1745**Error codes** 1746 1747For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 1748 1749| ID | Error Message | 1750| --------------- | --------------- | 1751| 7400201 | Camera service fatal error. | 1752 1753**Example** 1754 1755```ts 1756import { BusinessError } from '@ohos.base'; 1757 1758function releasePreviewOutput(previewOutput: camera.PreviewOutput): void { 1759 previewOutput.release().then(() => { 1760 console.info('Promise returned to indicate that the PreviewOutput instance is released successfully.'); 1761 }).catch((err: BusinessError) => { 1762 let err = error as BusinessError; 1763 console.error(`Failed to previewOutput release, error code: ${err.code}`); 1764 }); 1765} 1766 1767function releaseVideoOutput(videoOutput: camera.VideoOutput): void { 1768 videoOutput.release().then(() => { 1769 console.info('Promise returned to indicate that the VideoOutput instance is released successfully.'); 1770 }).catch((err: BusinessError) => { 1771 let err = error as BusinessError; 1772 console.error(`Failed to videoOutput release, error code: ${err.code}`); 1773 }); 1774} 1775``` 1776 1777## PreviewOutput 1778 1779Implements preview output. It inherits from [CameraOutput](#cameraoutput). 1780 1781### start<sup>(deprecated)</sup> 1782 1783start(callback: AsyncCallback\<void\>): void 1784 1785Starts to output preview streams. This API uses an asynchronous callback to return the result. 1786 1787> **NOTE** 1788>This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Session.start](#start-4) instead. 1789 1790**System capability**: SystemCapability.Multimedia.Camera.Core 1791 1792**Parameters** 1793 1794| Name | Type | Mandatory| Description | 1795| -------- | -------------------- | ---- | -------------------- | 1796| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 1797 1798**Error codes** 1799 1800For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 1801 1802| ID | Error Message | 1803| --------------- | --------------- | 1804| 7400103 | Session not config. | 1805 1806**Example** 1807 1808```ts 1809import { BusinessError } from '@ohos.base'; 1810 1811function startPreviewOutput(previewOutput: camera.PreviewOutput): void { 1812 previewOutput.start((err: BusinessError) => { 1813 if (err) { 1814 console.error(`Failed to start the previewOutput, error code: ${err.code}.`); 1815 return; 1816 } 1817 console.info('Callback returned with previewOutput started.'); 1818 }); 1819} 1820``` 1821 1822### start<sup>(deprecated)</sup> 1823 1824start(): Promise\<void\> 1825 1826Starts to output preview streams. This API uses a promise to return the result. 1827 1828> **NOTE** 1829>This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Session.start](#start-5) instead. 1830 1831**System capability**: SystemCapability.Multimedia.Camera.Core 1832 1833**Return value** 1834 1835| Type | Description | 1836| -------------- | ----------------------- | 1837| Promise\<void\> | Promise used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 1838 1839**Error codes** 1840 1841For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 1842 1843| ID | Error Message | 1844| --------------- | --------------- | 1845| 7400103 | Session not config. | 1846 1847**Example** 1848 1849```ts 1850import { BusinessError } from '@ohos.base'; 1851 1852function startPreviewOutput(previewOutput: camera.PreviewOutput): void { 1853 previewOutput.start().then(() => { 1854 console.info('Promise returned with previewOutput started.'); 1855 }).catch((err: BusinessError) => { 1856 let err = error as BusinessError; 1857 console.error(`Failed to previewOutput start, error code: ${err.code}.`); 1858 }); 1859} 1860``` 1861 1862### stop<sup>(deprecated)</sup> 1863 1864stop(callback: AsyncCallback\<void\>): void 1865 1866Stops outputting preview streams. This API uses an asynchronous callback to return the result. 1867 1868> **NOTE** 1869>This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Session.stop](#stop-4) instead. 1870 1871**System capability**: SystemCapability.Multimedia.Camera.Core 1872 1873**Parameters** 1874 1875| Name | Type | Mandatory| Description | 1876| -------- | -------------------- | ---- | -------------------- | 1877| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| 1878 1879**Example** 1880 1881```ts 1882import { BusinessError } from '@ohos.base'; 1883 1884function stopPreviewOutput(previewOutput: camera.PreviewOutput): void { 1885 previewOutput.stop((err: BusinessError) => { 1886 if (err) { 1887 console.error(`Failed to stop the previewOutput, error code: ${err.code}.`); 1888 return; 1889 } 1890 console.info('Returned with previewOutput stopped.'); 1891 }) 1892} 1893``` 1894 1895### stop<sup>(deprecated)</sup> 1896 1897stop(): Promise\<void\> 1898 1899Stops outputting preview streams. This API uses a promise to return the result. 1900 1901> **NOTE** 1902>This API is supported since API version 10 and deprecated since API version 11. You are advised to use [Session.stop](#stop-5) instead. 1903 1904**System capability**: SystemCapability.Multimedia.Camera.Core 1905 1906**Return value** 1907 1908| Type | Description | 1909| -------------- | ------------------------ | 1910| Promise\<void\> | Promise used to return the result.| 1911 1912**Example** 1913 1914```ts 1915import { BusinessError } from '@ohos.base'; 1916 1917function stopPreviewOutput(previewOutput: camera.PreviewOutput): void { 1918 previewOutput.stop().then(() => { 1919 console.info('Callback returned with previewOutput stopped.'); 1920 }).catch((err: BusinessError) => { 1921 let err = error as BusinessError; 1922 console.error(`Failed to previewOutput stop, error code: ${err.code}.`); 1923 }); 1924} 1925``` 1926 1927### on('frameStart') 1928 1929on(type: 'frameStart', callback: AsyncCallback\<void\>): void 1930 1931Subscribes to preview frame start events. This API uses an asynchronous callback to return the result. 1932 1933**System capability**: SystemCapability.Multimedia.Camera.Core 1934 1935**Parameters** 1936 1937| Name | Type | Mandatory| Description | 1938| -------- | -------------------- | ---- | --------------------------------------- | 1939| type | string | Yes | Event type. The value is fixed at **'frameStart'**. The event can be listened for when a **previewOutput** instance is created. This event is triggered and returned when the bottom layer starts exposure for the first time.| 1940| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. The preview starts as long as this event is returned. | 1941 1942**Example** 1943 1944```ts 1945function callback(): void { 1946 console.info('Preview frame started'); 1947} 1948 1949function registerPreviewOutputFrameStart(previewOutput: camera.PreviewOutput): void { 1950 previewOutput.on('frameStart', callback); 1951} 1952``` 1953 1954### off('frameStart') 1955 1956off(type: 'frameStart', callback?: AsyncCallback\<void\>): void 1957 1958Unsubscribes from preview frame start events. 1959 1960**System capability**: SystemCapability.Multimedia.Camera.Core 1961 1962**Parameters** 1963 1964| Name | Type | Mandatory| Description | 1965| -------- | -------------------- | ---- | --------------------------------------- | 1966| type | string | Yes | Event type. The value is fixed at **'frameStart'**. The event can be listened for when a **previewOutput** instance is created.| 1967| callback | AsyncCallback\<void\> | No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('error') with the specified callback is canceled. (The callback object cannot be an anonymous function.) | 1968 1969**Example** 1970 1971```ts 1972function unregisterPreviewOutputFrameStart(previewOutput: camera.PreviewOutput): void { 1973 previewOutput.off('frameStart'); 1974} 1975``` 1976 1977### on('frameEnd') 1978 1979on(type: 'frameEnd', callback: AsyncCallback\<void\>): void 1980 1981Subscribes to preview frame end events. This API uses an asynchronous callback to return the result. 1982 1983**System capability**: SystemCapability.Multimedia.Camera.Core 1984 1985**Parameters** 1986 1987| Name | Type | Mandatory| Description | 1988| -------- | -------------------- | ---- | ------------------------------------- | 1989| type | string | Yes | Event type. The value is fixed at **'frameEnd'**. The event can be listened for when a **previewOutput** instance is created. This event is triggered and returned when the last frame of preview ends.| 1990| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. The preview ends as long as this event is returned. | 1991 1992**Example** 1993 1994```ts 1995function callback(): void { 1996 console.info('Preview frame ended'); 1997} 1998 1999function registerPreviewOutputFrameEnd(previewOutput: camera.PreviewOutput): void { 2000 previewOutput.on('frameEnd', callback); 2001} 2002``` 2003 2004### off('frameEnd') 2005 2006off(type: 'frameEnd', callback?: AsyncCallback\<void\>): void 2007 2008Unsubscribes from preview frame end events. 2009 2010**System capability**: SystemCapability.Multimedia.Camera.Core 2011 2012**Parameters** 2013 2014| Name | Type | Mandatory| Description | 2015| -------- | -------------------- | ---- | ------------------------------------- | 2016| type | string | Yes | Event type. The value is fixed at **'frameEnd'**. The event can be listened for when a **previewOutput** instance is created.| 2017| callback | AsyncCallback\<void\> | No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('error') with the specified callback is canceled. (The callback object cannot be an anonymous function.) | 2018 2019**Example** 2020 2021```ts 2022function unregisterPreviewOutputFrameEnd(previewOutput: camera.PreviewOutput): void { 2023 previewOutput.off('frameEnd'); 2024} 2025``` 2026 2027### on('error') 2028 2029on(type: 'error', callback: ErrorCallback): void 2030 2031Subscribes to **PreviewOutput** error events. This API uses a callback to return the result. 2032 2033**System capability**: SystemCapability.Multimedia.Camera.Core 2034 2035**Parameters** 2036 2037| Name | Type | Mandatory| Description | 2038| -------- | --------------| ---- | ------------------------ | 2039| type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a **previewOutput** instance is created. This event is triggered and the corresponding error message is returned when an error occurs during the use of a preview-related API such as [Session.start](#start-5) or [CameraOutput.release](#release-1).| 2040| callback | ErrorCallback | Yes | Callback used to return an error code defined in [CameraErrorCode](#cameraerrorcode). | 2041 2042**Example** 2043 2044```ts 2045import { BusinessError } from '@ohos.base'; 2046 2047function callback(previewOutputError: BusinessError): void { 2048 console.error(`Preview output error code: ${previewOutputError.code}`); 2049} 2050 2051function registerPreviewOutputError(previewOutput: camera.PreviewOutput): void { 2052 previewOutput.on('error', callback) 2053} 2054``` 2055 2056### off('error') 2057 2058off(type: 'error', callback?: ErrorCallback): void 2059 2060Unsubscribes from **PreviewOutput** error events. 2061 2062**System capability**: SystemCapability.Multimedia.Camera.Core 2063 2064**Parameters** 2065 2066| Name | Type | Mandatory| Description | 2067| -------- | --------------| ---- | ------------------------ | 2068| type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a **previewOutput** instance is created.| 2069| callback | ErrorCallback | No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('error') with the specified callback is canceled. (The callback object cannot be an anonymous function.) | 2070 2071**Example** 2072 2073```ts 2074function unregisterPreviewOutputError(previewOutput: camera.PreviewOutput): void { 2075 previewOutput.off('error'); 2076} 2077``` 2078 2079### addDeferredSurface 2080 2081addDeferredSurface(surfaceId: string): void 2082 2083Adds a surface for delayed preview. This API can run after [commitConfig](#commitconfig) or [Session.start](#start-4) is called. 2084 2085**System API**: This is a system API. 2086 2087**System capability**: SystemCapability.Multimedia.Camera.Core 2088 2089**Parameters** 2090 2091| Name | Type | Mandatory| Description | 2092| -------- | --------------| ---- | ------------------------ | 2093| surfaceId | string | Yes| Surface ID, which is obtained from [XComponent](../arkui-ts/ts-basic-components-xcomponent.md).| 2094 2095**Error codes** 2096 2097For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 2098 2099| ID | Error Message | 2100| --------------- | --------------- | 2101| 7400101 | Parameter missing or parameter type incorrect. | 2102 2103**Example** 2104 2105```ts 2106import common from '@ohos.app.ability.common'; 2107 2108async function preview(context: common.BaseContext, cameraInfo: camera.CameraDevice, previewProfile: camera.Profile, photoProfile: camera.Profile, photoSurfaceId: string, previewSurfaceId: string): Promise<void> { 2109 const cameraManager: camera.CameraManager = camera.getCameraManager(context); 2110 const cameraInput: camera.CameraInput = cameraManager.createCameraInput(cameraInfo) 2111 const previewOutput: camera.PreviewOutput = cameraManager.createDeferredPreviewOutput(previewProfile); 2112 const photoOutput: camera.PhotoOutput = cameraManager.createPhotoOutput(photoProfile, photoSurfaceId); 2113 const session: camera.CaptureSession = cameraManager.createCaptureSession(); 2114 session.beginConfig(); 2115 session.addInput(cameraInput); 2116 session.addOutput(previewOutput); 2117 session.addOutput(photoOutput); 2118 await session.commitConfig(); 2119 await session.start(); 2120 previewOutput.addDeferredSurface(previewSurfaceId); 2121} 2122``` 2123 2124### isSketchSupported<sup>11+</sup> 2125 2126isSketchSupported(): boolean 2127 2128Checks whether Picture-in-Picture (PiP) preview is supported. 2129 2130**System API**: This is a system API. 2131 2132**System capability**: SystemCapability.Multimedia.Camera.Core 2133 2134**Return value** 2135 2136| Type | Description | 2137| -------------- | ----------------------- | 2138| boolean | **true**: PiP preview is supported.<br>**false**: PiP preview is not supported.| 2139 2140**Example** 2141 2142```ts 2143function isSketchSupported(previewOutput: camera.PreviewOutput): boolean { 2144 let isSupported: boolean = previewOutput.isSketchSupported(); 2145 return isSupported; 2146} 2147``` 2148 2149### getSketchRatio<sup>11+</sup> 2150 2151getSketchRatio(): number 2152 2153Obtains the zoom ratio when PiP preview is enabled. 2154 2155**System API**: This is a system API. 2156 2157**System capability**: SystemCapability.Multimedia.Camera.Core 2158 2159**Return value** 2160 2161| Type | Description | 2162| -------------- | ----------------------- | 2163| number | Zoom ratio obtained. If PiP preview is not supported, the value **-1** is returned.| 2164 2165**Error codes** 2166 2167For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 2168 2169| ID | Error Message | 2170| --------------- | --------------- | 2171| 7400103 | Session not config. | 2172| 202 | Not System Application. | 2173 2174**Example** 2175 2176```ts 2177function getSketchRatio(previewOutput: camera.PreviewOutput): number { 2178 let sketchRatio: number = previewOutput.getSketchRatio(); 2179 return sketchRatio; 2180} 2181``` 2182 2183### enableSketch<sup>11+</sup> 2184 2185enableSketch(enabled: boolean): void 2186 2187Enables or disables PiP preview. 2188 2189**System API**: This is a system API. 2190 2191**System capability**: SystemCapability.Multimedia.Camera.Core 2192 2193**Parameters** 2194 2195| Name | Type | Mandatory| Description | 2196| -------- | --------------| ---- | ------------------------ | 2197| enabled | boolean | Yes| Whether to enable PiP preview. The value **true** means to enable PiP preview, and **false** means to disable it.| 2198 2199**Error codes** 2200 2201For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 2202 2203| ID | Error Message | 2204| --------------- | --------------- | 2205| 7400103 | Session not config. | 2206| 202 | Not System Application. | 2207 2208**Example** 2209 2210```ts 2211import { BusinessError } from '@ohos.base'; 2212 2213function enableSketch(previewOutput: camera.PreviewOutput, captureSession: camera.CaptureSession, cameraInput: camera.CameraInput): void { 2214 try { 2215 captureSession.beginConfig(); 2216 captureSession.addInput(cameraInput); 2217 captureSession.addOutput(previewOutput); 2218 previewOutput.enableSketch(true); 2219 captureSession.commitConfig(); 2220 } catch (error) { 2221 // If the operation fails, error.code is returned and processed. 2222 let err = error as BusinessError; 2223 console.error(`The enableSketch call failed. error code: ${err.code}`); 2224 } 2225} 2226``` 2227 2228### attachSketchSurface<sup>11+</sup> 2229 2230attachSketchSurface(surfaceId: string): void 2231 2232Attaches a surface for PiP preview. 2233 2234**System API**: This is a system API. 2235 2236**System capability**: SystemCapability.Multimedia.Camera.Core 2237 2238**Parameters** 2239 2240| Name | Type | Mandatory| Description | 2241| -------- | --------------| ---- | ------------------------ | 2242| surfaceId | string | Yes| Surface ID, which is obtained from [XComponent](../arkui-ts/ts-basic-components-xcomponent.md).| 2243 2244**Error codes** 2245 2246For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 2247 2248| ID | Error Message | 2249| --------------- | --------------- | 2250| 7400103 | Session not config. | 2251| 202 | Not System Application. | 2252 2253**Example** 2254 2255```ts 2256import { BusinessError } from '@ohos.base'; 2257 2258function attachSketchSurface(previewOutput: camera.PreviewOutput, captureSession: camera.CaptureSession, cameraInput: camera.CameraInput, sketchSurfaceId: string): void { 2259 try { 2260 captureSession.beginConfig(); 2261 captureSession.addInput(cameraInput); 2262 captureSession.addOutput(previewOutput); 2263 previewOutput.enableSketch(true); 2264 captureSession.commitConfig(); 2265 previewOutput.attachSketchSurface(sketchSurfaceId); 2266 } catch (error) { 2267 // If the operation fails, error.code is returned and processed. 2268 let err = error as BusinessError; 2269 console.error(`The attachSketchSurface call failed. error code: ${err.code}`); 2270 } 2271} 2272``` 2273 2274### on('sketchStatusChanged')<sup>11+</sup> 2275 2276on(type: 'sketchStatusChanged', callback: AsyncCallback\<SketchStatusData\>): void 2277 2278Subscribes to PiP status change events. This API uses an asynchronous callback to return the PiP status data. 2279 2280**System API**: This is a system API. 2281 2282**System capability**: SystemCapability.Multimedia.Camera.Core 2283 2284**Parameters** 2285 2286| Name | Type | Mandatory| Description | 2287| -------- | ---------------------- | ---- | ------------------------------------------ | 2288| type | string | Yes | Event type. The value is fixed at **'sketchStatusChanged'**. The event can be listened for when a PiP preview stream is created. This event is triggered when PiP preview is enabled or disabled or the zoom ratio changes while PiP preview is enabled.| 2289| callback | AsyncCallback\<SketchStatusData\> | Yes | Callback used to return the PiP status data. | 2290 2291**Example** 2292 2293```ts 2294function callback(errorCode: number, data: camera.SketchStatusData): void { 2295 console.info(`sketch errorCode is ${errorCode}, data is ${JSON.stringify(data)}`); 2296} 2297 2298function registerSketchStatusChanged(previewOutput: camera.PreviewOutput): void { 2299 previewOutput.on('sketchStatusChanged', callback); 2300} 2301``` 2302 2303### off('sketchStatusChanged')<sup>11+</sup> 2304 2305off(type: 'sketchStatusChanged', callback?: AsyncCallback\<SketchStatusData\>): void 2306 2307Unsubscribes from PiP status change events. This API uses an asynchronous callback to return the PiP status data. 2308 2309**System API**: This is a system API. 2310 2311**System capability**: SystemCapability.Multimedia.Camera.Core 2312 2313**Parameters** 2314 2315| Name | Type | Mandatory| Description | 2316| -------- | ---------------------- | ---- | ------------------------------------------ | 2317| type | string | Yes | Event type. The value is fixed at **'sketchStatusChanged'**. The event can be listened for when a PiP preview stream is created.| 2318| callback | AsyncCallback\<SketchStatusData\> | No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('error') with the specified callback is canceled. (The callback object cannot be an anonymous function.) | 2319 2320**Example** 2321 2322```ts 2323function unregisterSketchStatusChanged(previewOutput: camera.PreviewOutput): void { 2324 previewOutput.off('sketchStatusChanged'); 2325} 2326``` 2327 2328## ImageRotation 2329 2330Enumerates the image rotation angles. 2331 2332**System capability**: SystemCapability.Multimedia.Camera.Core 2333 2334| Name | Value | Description | 2335| ------------ | ---- | ------------- | 2336| ROTATION_0 | 0 | The image rotates 0 degrees. | 2337| ROTATION_90 | 90 | The image rotates 90 degrees. | 2338| ROTATION_180 | 180 | The image rotates 180 degrees.| 2339| ROTATION_270 | 270 | The image rotates 270 degrees.| 2340 2341## Location 2342 2343Defines the geolocation information. 2344 2345**System capability**: SystemCapability.Multimedia.Camera.Core 2346 2347| Name | Type | Mandatory|Description | 2348| ------------ | ------ | --- |------------ | 2349| latitude | number | Yes |Latitude, in degrees. | 2350| longitude | number | Yes |Longitude, in degrees. | 2351| altitude | number | Yes |Altitude, in meters. | 2352 2353## QualityLevel 2354 2355Enumerates the image quality levels. 2356 2357**System capability**: SystemCapability.Multimedia.Camera.Core 2358 2359| Name | Value | Description | 2360| -------------------- | ---- | ------------ | 2361| QUALITY_LEVEL_HIGH | 0 | High image quality. | 2362| QUALITY_LEVEL_MEDIUM | 1 | Medium image quality.| 2363| QUALITY_LEVEL_LOW | 2 | Low image quality. | 2364 2365 2366## PhotoCaptureSetting 2367 2368Defines the settings for taking an image. 2369 2370**System capability**: SystemCapability.Multimedia.Camera.Core 2371 2372| Name | Type | Mandatory | Description | 2373| -------- | ------------------------------- | ---- |----------------------------------------------------------------------| 2374| quality | [QualityLevel](#qualitylevel) | No | Image quality (low by default). | 2375| rotation | [ImageRotation](#imagerotation) | No | Rotation angle of the image. The default value is **0**, indicating clockwise rotation. | 2376| location | [Location](#location) | No | Geolocation information of the image (depending on the device hardware information by default). | 2377| mirror | boolean | No | Whether mirror photography is enabled (disabled by default). Before using this enumerated value, call [isMirrorSupported](#ismirrorsupported) to check whether mirror photography is supported.| 2378 2379## DeferredDeliveryImageType<sup>11+</sup> 2380 2381Enumerates the deferred delivery image types. In deferred delivery, photo and video capture are divided into two phases. In the first phase, an image or video is output to users at a relatively fast speed. In the second phase, a higher-resolution image or video is output again after optimization processing. 2382 2383**System API**: This is a system API. 2384 2385**System capability**: SystemCapability.Multimedia.Camera.Core 2386 2387| Name | Value | Description | 2388| ------- | ---- | ------------ | 2389| NONE | 0 | Deferred delivery is not supported.| 2390| PHOTO | 1 | Deferred delivery for photo capture.| 2391| VIDEO | 2 | Deferred delivery for video capture.| 2392 2393## DeferredPhotoProxy<sup>11+</sup> 2394 2395A class object that functions as a thumbnail proxy. 2396 2397### getThumbnail 2398 2399getThumbnail(): Promise<image.PixelMap> 2400 2401Obtains the pixel map of a thumbnail. 2402 2403**System API**: This is a system API. 2404 2405**System capability**: SystemCapability.Multimedia.Camera.Core 2406 2407**Return value** 2408 2409| Type | Description | 2410| -------------- | ----------------------- | 2411| Promise\<image.PixelMap\> | Pixel map of the thumbnail.| 2412 2413**Example** 2414 2415```ts 2416import image from '@ohos.multimedia.image'; 2417 2418function getThumbnail(proxyObj: camera.DeferredPhotoProxy): void { 2419 proxyObj.getThumbnail().then((thumbnail: image.PixelMap) => { 2420 AppStorage.setOrCreate('proxyThumbnail', thumbnail); 2421 }); 2422} 2423``` 2424 2425### release 2426 2427release(): Promise\<void\> 2428 2429Releases output resources. This API uses a promise to return the result. 2430 2431**System API**: This is a system API. 2432 2433**System capability**: SystemCapability.Multimedia.Camera.Core 2434 2435**Return value** 2436 2437| Type | Description | 2438| -------------- | ----------------------- | 2439| Promise\<void\> | Promise used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 2440 2441**Example** 2442 2443```ts 2444async function releaseDeferredPhotoProxy(proxyObj: camera.DeferredPhotoProxy): Promise<void> { 2445 await proxyObj.release(); 2446} 2447``` 2448 2449## Photo 2450 2451Defines a higher-resolution image object. 2452 2453### Attributes 2454 2455**System capability**: SystemCapability.Multimedia.Camera.Core 2456 2457| Name | Type | Mandatory | Description | 2458| ------ | ----------------------------- | -------------- | ---------- | 2459| main | [image.Image](js-apis-image.md#image9) | Yes | Higher-resolution image.| 2460 2461### release 2462 2463release(): Promise\<void\> 2464 2465Releases output resources. This API uses a promise to return the result. 2466 2467**System capability**: SystemCapability.Multimedia.Camera.Core 2468 2469**Return value** 2470 2471| Type | Description | 2472| -------------- | ----------------------- | 2473| Promise\<void\> | Promise used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 2474 2475**Example** 2476 2477```ts 2478async function releaseDeferredPhotoProxy(photo: camera.Photo): Promise<void> { 2479 await photo.release(); 2480} 2481``` 2482 2483## PhotoOutput 2484 2485Implements output information used in a photo session. It inherits from [CameraOutput](#cameraoutput). 2486 2487### capture 2488 2489capture(callback: AsyncCallback\<void\>): void 2490 2491Captures a photo with the default photo capture parameters. This API uses an asynchronous callback to return the result. 2492 2493**System capability**: SystemCapability.Multimedia.Camera.Core 2494 2495**Parameters** 2496 2497| Name | Type | Mandatory| Description | 2498| -------- | -------------------- | ---- | ------------------- | 2499| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 2500 2501**Error codes** 2502 2503For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 2504 2505| ID | Error Message | 2506| --------------- | --------------- | 2507| 7400104 | Session not running. | 2508| 7400201 | Camera service fatal error. | 2509 2510**Example** 2511 2512```ts 2513import { BusinessError } from '@ohos.base'; 2514 2515function capture(photoOutput: camera.PhotoOutput): void { 2516 photoOutput.capture((err: BusinessError) => { 2517 if (err) { 2518 console.error(`Failed to capture the photo, error code: ${err.code}.`); 2519 return; 2520 } 2521 console.info('Callback invoked to indicate the photo capture request success.'); 2522 }); 2523} 2524``` 2525 2526### capture 2527 2528capture(): Promise\<void\> 2529 2530Captures a photo with the default photo capture parameters. This API uses a promise to return the result. 2531 2532**System capability**: SystemCapability.Multimedia.Camera.Core 2533 2534**Return value** 2535 2536| Type | Description | 2537| -------------- | ------------------------ | 2538| Promise\<void\> | Promise used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 2539 2540**Error codes** 2541 2542For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 2543 2544| ID | Error Message | 2545| --------------- | --------------- | 2546| 7400104 | Session not running. | 2547| 7400201 | Camera service fatal error. | 2548 2549**Example** 2550 2551```ts 2552import { BusinessError } from '@ohos.base'; 2553 2554function capture(photoOutput: camera.PhotoOutput): void { 2555 photoOutput.capture().then(() => { 2556 console.info('Promise returned to indicate that photo capture request success.'); 2557 }).catch((err: BusinessError) => { 2558 let err = error as BusinessError; 2559 console.error(`Failed to photoOutput capture, error code: ${err.code}.`); 2560 }); 2561} 2562``` 2563 2564### capture 2565 2566capture(setting: PhotoCaptureSetting, callback: AsyncCallback\<void\>): void 2567 2568Captures a photo with the specified photo capture parameters. This API uses an asynchronous callback to return the result. 2569 2570**System capability**: SystemCapability.Multimedia.Camera.Core 2571 2572**Parameters** 2573 2574| Name | Type | Mandatory| Description | 2575| -------- | ------------------------------------------- | ---- | -------------------- | 2576| setting | [PhotoCaptureSetting](#photocapturesetting) | Yes | Photo capture settings. | 2577| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned. | 2578 2579**Error codes** 2580 2581For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 2582 2583| ID | Error Message | 2584| --------------- | --------------- | 2585| 7400101 | Parameter missing or parameter type incorrect. | 2586| 7400104 | Session not running. | 2587| 7400201 | Camera service fatal error. | 2588 2589**Example** 2590 2591```ts 2592import { BusinessError } from '@ohos.base'; 2593 2594function capture(photoOutput: camera.PhotoOutput): void { 2595 let captureLocation: camera.Location = { 2596 latitude: 0, 2597 longitude: 0, 2598 altitude: 0 2599 } 2600 let settings: camera.PhotoCaptureSetting = { 2601 quality: camera.QualityLevel.QUALITY_LEVEL_LOW, 2602 rotation: camera.ImageRotation.ROTATION_0, 2603 location: captureLocation, 2604 mirror: false 2605 } 2606 photoOutput.capture(settings, (err: BusinessError) => { 2607 if (err) { 2608 console.error(`Failed to capture the photo, error code: ${err.code}.`); 2609 return; 2610 } 2611 console.info('Callback invoked to indicate the photo capture request success.'); 2612 }); 2613} 2614``` 2615 2616### capture 2617 2618capture(setting: PhotoCaptureSetting): Promise\<void\> 2619 2620Captures a photo with the specified photo capture parameters. This API uses a promise to return the result. 2621 2622**System capability**: SystemCapability.Multimedia.Camera.Core 2623 2624**Parameters** 2625 2626| Name | Type | Mandatory| Description | 2627| ------- | ------------------------------------------- | ---- | -------- | 2628| setting | [PhotoCaptureSetting](#photocapturesetting) | Yes | Photo capture parameters. The input of **undefined** is processed as if no parameters were passed.| 2629 2630**Return value** 2631 2632| Type | Description | 2633| -------------- | ------------------------ | 2634| Promise\<void\> | Promise used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 2635 2636**Error codes** 2637 2638For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 2639 2640| ID | Error Message | 2641| --------------- | --------------- | 2642| 7400101 | Parameter missing or parameter type incorrect. | 2643| 7400104 | Session not running. | 2644| 7400201 | Camera service fatal error. | 2645 2646**Example** 2647 2648```ts 2649import { BusinessError } from '@ohos.base'; 2650 2651function capture(photoOutput: camera.PhotoOutput): void { 2652 let captureLocation: camera.Location = { 2653 latitude: 0, 2654 longitude: 0, 2655 altitude: 0 2656 } 2657 let settings: camera.PhotoCaptureSetting = { 2658 quality: camera.QualityLevel.QUALITY_LEVEL_LOW, 2659 rotation: camera.ImageRotation.ROTATION_0, 2660 location: captureLocation, 2661 mirror: false 2662 } 2663 photoOutput.capture(settings).then(() => { 2664 console.info('Promise returned to indicate that photo capture request success.'); 2665 }).catch((err: BusinessError) => { 2666 let err = error as BusinessError; 2667 console.error(`Failed to photoOutput capture, error code: ${err.code}.`); 2668 }); 2669} 2670``` 2671 2672### confirmCapture<sup>11+</sup> 2673 2674confirmCapture(): void 2675 2676Confirms photo capture. This API is generally used in night photo mode when users need to stop the exposure countdown and take a photo in advance. 2677 2678**System API**: This is a system API. 2679 2680**System capability**: SystemCapability.Multimedia.Camera.Core 2681 2682**Error codes** 2683 2684For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 2685 2686| ID | Error Message | 2687| --------------- | --------------- | 2688| 7400104 | Session not running. | 2689| 7400201 | Camera service fatal error. | 2690 2691**Example** 2692 2693```ts 2694import { BusinessError } from '@ohos.base'; 2695 2696function confirmCapture(photoOutput: camera.PhotoOutput): void { 2697 try { 2698 photoOutput.confirmCapture(); 2699 } catch (error) { 2700 let err = error as BusinessError; 2701 console.error(`The confirmCapture call failed. error code: ${err.code}`); 2702 } 2703} 2704``` 2705 2706### isDeferredImageDeliverySupported<sup>11+</sup> 2707 2708isDeferredImageDeliverySupported(type: DeferredDeliveryImageType): boolean 2709 2710Checks whether deferred delivery of a certain type is supported. 2711 2712**System API**: This is a system API. 2713 2714**System capability**: SystemCapability.Multimedia.Camera.Core 2715 2716**Parameters** 2717 2718| Name | Type | Mandatory| Description | 2719| -------- | -------------------- | ---- | ------------------- | 2720| type | [DeferredDeliveryImageType](#deferreddeliveryimagetype11) | Yes | Deferred delivery image type. | 2721 2722**Return value** 2723 2724| Type | Description | 2725| -------------- | ----------------------- | 2726| boolean | **true**: Deferred delivery is supported.<br>**false**: Deferred delivery is not supported.| 2727 2728**Error codes** 2729 2730For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 2731 2732| ID | Error Message | 2733| --------------- | --------------- | 2734| 7400101 | Parameter missing or parameter type incorrect. | 2735| 7400104 | Session not running. | 2736| 7400201 | Camera service fatal error. | 2737| 202 | Not System Application. | 2738 2739**Example** 2740 2741```ts 2742function isDeferredImageDeliverySupported(photoOutput: camera.PhotoOutput, type: camera.DeferredDeliveryImageType): boolean { 2743 let res: boolean = false; 2744 res = photoOutPut.isDeferredImageDeliverySupported(type); 2745 return res; 2746} 2747``` 2748 2749### isDeferredImageDeliveryEnabled<sup>11+</sup> 2750 2751isDeferredImageDeliveryEnabled(type: DeferredDeliveryImageType): boolean 2752 2753Checks whether deferred delivery of a certain type is enabled. 2754 2755**System API**: This is a system API. 2756 2757**System capability**: SystemCapability.Multimedia.Camera.Core 2758 2759**Parameters** 2760 2761| Name | Type | Mandatory| Description | 2762| -------- | -------------------- | ---- | ------------------- | 2763| type | [DeferredDeliveryImageType](#deferreddeliveryimagetype11) | Yes | Deferred delivery image type. | 2764 2765**Return value** 2766 2767| Type | Description | 2768| -------------- | ----------------------- | 2769| boolean | **true**: Deferred delivery is enabled. **false**: Deferred delivery is disabled.| 2770 2771**Error codes** 2772 2773For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 2774 2775| ID | Error Message | 2776| --------------- | --------------- | 2777| 7400101 | Parameter missing or parameter type incorrect. | 2778| 7400104 | Session not running. | 2779| 7400201 | Camera service fatal error. | 2780| 202 | Not System Application. | 2781 2782**Example** 2783 2784```ts 2785function isDeferredImageDeliveryEnabled(photoOutput: camera.PhotoOutput, type: camera.DeferredDeliveryImageType): boolean { 2786 let res: boolean = false; 2787 res = photoOutPut.isDeferredImageDeliveryEnabled(type); 2788 return res; 2789} 2790``` 2791 2792### deferImageDelivery<sup>11+</sup> 2793 2794deferImageDelivery(type: DeferredDeliveryImageType): void 2795 2796Enables deferred delivery of a certain type. 2797 2798**System API**: This is a system API. 2799 2800**System capability**: SystemCapability.Multimedia.Camera.Core 2801 2802**Parameters** 2803 2804| Name | Type | Mandatory| Description | 2805| -------- | -------------------- | ---- | ------------------- | 2806| type | [DeferredDeliveryImageType](#deferreddeliveryimagetype11) | Yes | Deferred delivery image type. | 2807 2808**Error codes** 2809 2810For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 2811 2812| ID | Error Message | 2813| --------------- | --------------- | 2814| 7400101 | Parameter missing or parameter type incorrect. | 2815| 7400104 | Session not running. | 2816| 7400201 | Camera service fatal error. | 2817| 202 | Not System Application. | 2818 2819**Example** 2820 2821```ts 2822function deferImageDelivery(photoOutput: camera.PhotoOutput, type: camera.DeferredDeliveryImageType): void { 2823 photoOutPut.deferImageDelivery(type); 2824} 2825``` 2826 2827### on('photoAvailable')<sup>11+</sup> 2828 2829on(type: 'photoAvailable', callback: AsyncCallback\<Photo\>): void 2830 2831Subscribes to events indicating available high-resolution images. 2832 2833**System capability**: SystemCapability.Multimedia.Camera.Core 2834 2835**Parameters** 2836 2837| Name | Type | Mandatory| Description | 2838| -------- | ---------- | --- | ------------------------------------ | 2839| type | string | Yes | Event type. The value is fixed at **'photoAvailable'**. The event can be listened for when a **photoOutput** instance is created.| 2840| callback | AsyncCallback\<[Photo](#photo)\> | Yes | Callback used to return the high-resolution image.| 2841 2842**Example** 2843 2844```ts 2845import { BusinessError } from '@ohos.base'; 2846 2847function callback(err: BusinessError, photo: camera.Photo): void { 2848 let mainImage: image.Image = photo.main; 2849} 2850 2851function registerPhotoOutputPhotoAvailable(photoOutput: camera.PhotoOutput): void { 2852 photoOutput.on('photoAvailable', callback); 2853} 2854``` 2855 2856### off('photoAvailable')<sup>11+</sup> 2857 2858off(type: 'photoAvailable', callback?: AsyncCallback\<Photo\>): void 2859 2860Unsubscribes from events indicating available high-resolution images. 2861 2862**System capability**: SystemCapability.Multimedia.Camera.Core 2863 2864**Parameters** 2865 2866| Name | Type | Mandatory| Description | 2867| -------- | ---------------------- | ---- | ------------------------------------------ | 2868| type | string | Yes | Event type. The value is fixed at **'photoAvailable'**. The event can be listened for when a **photoOutput** instance is created.| 2869| callback | AsyncCallback\<[Photo](#photo)\> | No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('error') with the specified callback is canceled. (The callback object cannot be an anonymous function.) | 2870 2871**Example** 2872 2873```ts 2874import { BusinessError } from '@ohos.base'; 2875 2876function callback(err: BusinessError, photo: camera.Photo): void { 2877 let mainImage: image.Image = photo.main; 2878} 2879 2880function unRegisterPhotoOutputPhotoAvailable(photoOutput: camera.PhotoOutput): void { 2881 photoOutput.off('photoAvailable', callback); 2882} 2883``` 2884 2885### on('deferredPhotoProxyAvailable')<sup>11+</sup> 2886 2887on(type: 'deferredPhotoProxyAvailable', callback: AsyncCallback\<DeferredPhotoProxy\>): void 2888 2889Subscribes to events indicating available thumbnail proxies. 2890 2891**System API**: This is a system API. 2892 2893**System capability**: SystemCapability.Multimedia.Camera.Core 2894 2895**Parameters** 2896 2897| Name | Type | Mandatory| Description | 2898| -------- | ---------- | --- | ------------------------------------ | 2899| type | string | Yes | Event type. The value is fixed at **'deferredPhotoProxyAvailable'**. The event can be listened for when a **photoOutput** instance is created.| 2900| callback | AsyncCallback\<[DeferredPhotoProxy](#deferredphotoproxy11)\> | Yes | Callback used to return the thumbnail proxy.| 2901 2902**Example** 2903 2904```ts 2905import { BusinessError } from '@ohos.base'; 2906import image from '@ohos.multimedia.image'; 2907 2908function callback(err: BusinessError, proxyObj: camera.DeferredPhotoProxy): void { 2909 proxyObj.getThumbnail().then((thumbnail: image.PixelMap) => { 2910 AppStorage.setOrCreate('proxyThumbnail', thumbnail); 2911 }); 2912} 2913 2914function registerPhotoOutputDeferredPhotoProxyAvailable(photoOutput: camera.PhotoOutput): void { 2915 photoOutput.on('deferredPhotoProxyAvailable', callback); 2916} 2917``` 2918 2919### off('deferredPhotoProxyAvailable')<sup>11+</sup> 2920 2921off(type: 'deferredPhotoProxyAvailable', callback?: AsyncCallback\<DeferredPhotoProxy\>): void 2922 2923Unsubscribes from events indicating available thumbnail proxies. 2924 2925**System API**: This is a system API. 2926 2927**System capability**: SystemCapability.Multimedia.Camera.Core 2928 2929**Parameters** 2930 2931| Name | Type | Mandatory| Description | 2932| -------- | ---------------------- | ---- | ------------------------------------------ | 2933| type | string | Yes | Event type. The value is fixed at **'deferredPhotoProxyAvailable'**. The event can be listened for when a **photoOutput** instance is created.| 2934| callback | AsyncCallback\<[DeferredPhotoProxy](#deferredphotoproxy11)\> | No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('error') with the specified callback is canceled. (The callback object cannot be an anonymous function.) | 2935 2936**Example** 2937 2938```ts 2939import { BusinessError } from '@ohos.base'; 2940import image from '@ohos.multimedia.image'; 2941 2942function callback(err: BusinessError, proxyObj: camera.DeferredPhotoProxy): void { 2943 proxyObj.getThumbnail().then((thumbnail: image.PixelMap) => { 2944 AppStorage.setOrCreate('proxyThumbnail', thumbnail); 2945 }); 2946} 2947 2948function unRegisterPhotoOutputDeferredPhotoProxyAvailable(photoOutput: camera.PhotoOutput): void { 2949 photoOutput.off('deferredPhotoProxyAvailable', callback); 2950} 2951``` 2952 2953### on('captureStartWithInfo')<sup>11+</sup> 2954 2955on(type: 'captureStartWithInfo', callback: AsyncCallback\<CaptureStartInfo\>): void 2956 2957Subscribes to capture start events. This API uses an asynchronous callback to return the capture start ID. 2958 2959**System capability**: SystemCapability.Multimedia.Camera.Core 2960 2961**Parameters** 2962 2963| Name | Type | Mandatory| Description | 2964| -------- | ---------- | --- | ------------------------------------ | 2965| type | string | Yes | Event type. The value is fixed at **'captureStartWithInfo'**. The event can be listened for when a **photoOutput** instance is created.| 2966| callback | AsyncCallback\<[CaptureStartInfo](#capturestartinfo)\> | Yes | Callback used to return the capture ID.| 2967 2968**Example** 2969 2970```ts 2971import { BusinessError } from '@ohos.base'; 2972 2973function callback(err: BusinessError, captureStartInfo: camera.CaptureStartInfo): void { 2974 console.info(`photo capture started, captureStartInfo : ${captureStartInfo}`); 2975} 2976 2977function registerCaptureStartWithInfo(photoOutput: camera.PhotoOutput): void { 2978 photoOutput.on('captureStartWithInfo', callback); 2979} 2980``` 2981 2982### off('captureStartWithInfo')<sup>11+</sup> 2983 2984off(type: 'captureStartWithInfo', callback?: AsyncCallback\<CaptureStartInfo\>): void 2985 2986Unsubscribes from capture start events. 2987 2988**System capability**: SystemCapability.Multimedia.Camera.Core 2989 2990**Parameters** 2991 2992| Name | Type | Mandatory| Description | 2993| -------- | ---------------------- | ---- | ------------------------------------------ | 2994| type | string | Yes | Event type. The value is fixed at **'captureStartWithInfo'**. The event can be listened for when a **photoOutput** instance is created.| 2995| callback | AsyncCallback\<[CaptureStartInfo](#capturestartinfo11)\> | No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('error') with the specified callback is canceled. (The callback object cannot be an anonymous function.) | 2996 2997**Example** 2998 2999```ts 3000import { BusinessError } from '@ohos.base'; 3001 3002function unRegisterCaptureStartWithInfo(photoOutput: camera.PhotoOutput): void { 3003 photoOutput.off('captureStartWithInfo'); 3004} 3005``` 3006 3007### isMirrorSupported 3008 3009isMirrorSupported(): boolean 3010 3011Checks whether mirror photography is supported. 3012 3013**System capability**: SystemCapability.Multimedia.Camera.Core 3014 3015**Return value** 3016 3017| Type | Description | 3018| -------------- | ----------------------- | 3019| boolean | **true**: Mirror photography is supported.<br>**false**: Mirror photography is not supported.| 3020 3021**Example** 3022 3023```ts 3024function isMirrorSupported(photoOutput: camera.PhotoOutput): boolean { 3025 let isSupported: boolean = photoOutput.isMirrorSupported(); 3026 return isSupported; 3027} 3028``` 3029 3030### on('captureStart')<sup>(deprecated)</sup> 3031 3032on(type: 'captureStart', callback: AsyncCallback\<number\>): void 3033 3034Subscribes to capture start events. This API uses an asynchronous callback to return the capture ID. 3035 3036> **NOTE** 3037>This API is supported since API version 10 and deprecated since API version 11. You are advised to use [on('captureStartWithInfo')](#oncapturestartwithinfo11) instead. 3038 3039**System capability**: SystemCapability.Multimedia.Camera.Core 3040 3041**Parameters** 3042 3043| Name | Type | Mandatory| Description | 3044| -------- | ---------------------- | ---- | ------------------------------------------ | 3045| type | string | Yes | Event type. The value is fixed at **'captureStart'**. The event can be listened for when a **photoOutput** instance is created. This event is triggered and returned when the bottom layer starts exposure each time a photo is taken.| 3046| callback | AsyncCallback\<number\> | Yes | Callback used to return the capture ID. | 3047 3048**Example** 3049 3050```ts 3051import { BusinessError } from '@ohos.base'; 3052 3053function callback(err: BusinessError, captureId: number): void { 3054 console.info(`photo capture started, captureId : ${captureId}`); 3055} 3056 3057function registerPhotoOutputCaptureStart(photoOutput: camera.PhotoOutput): void { 3058 photoOutput.on('captureStart', callback); 3059} 3060``` 3061 3062### off('captureStart')<sup>(deprecated)</sup> 3063 3064off(type: 'captureStart', callback?: AsyncCallback\<number\>): void 3065 3066Unsubscribes from capture start events. 3067 3068> **NOTE** 3069>This API is supported since API version 10 and deprecated since API version 11. You are advised to use [off('captureStartWithInfo')](#offcapturestartwithinfo11) instead. 3070 3071**System capability**: SystemCapability.Multimedia.Camera.Core 3072 3073**Parameters** 3074 3075| Name | Type | Mandatory| Description | 3076| -------- | ---------------------- | ---- | ------------------------------------------ | 3077| type | string | Yes | Event type. The value is fixed at **'captureStart'**. The event can be listened for when a **photoOutput** instance is created.| 3078| callback | AsyncCallback\<number\> | No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('error') with the specified callback is canceled. (The callback object cannot be an anonymous function.) | 3079 3080**Example** 3081 3082```ts 3083function unregisterPhotoOutputCaptureStart(photoOutput: camera.PhotoOutput): void { 3084 photoOutput.off('captureStart'); 3085} 3086``` 3087 3088### on('frameShutter') 3089 3090on(type: 'frameShutter', callback: AsyncCallback\<FrameShutterInfo\>): void 3091 3092Subscribes to frame shutter events. This API uses an asynchronous callback to return the result. 3093 3094**System capability**: SystemCapability.Multimedia.Camera.Core 3095 3096**Parameters** 3097 3098| Name | Type | Mandatory| Description | 3099| -------- | ---------- | --- | ------------------------------------ | 3100| type | string | Yes | Event type. The value is fixed at **'frameShutter'**. The event can be listened for when a **photoOutput** instance is created.| 3101| callback | AsyncCallback\<[FrameShutterInfo](#frameshutterinfo)\> | Yes | Callback used to return the result. A new photographing request can be delivered as long as this event is returned. | 3102 3103**Example** 3104 3105```ts 3106import { BusinessError } from '@ohos.base'; 3107 3108function callback(err: BusinessError, frameShutterInfo: camera.FrameShutterInfo): void { 3109 console.info(`CaptureId for frame : ${frameShutterInfo.captureId}`); 3110 console.info(`Timestamp for frame : ${frameShutterInfo.timestamp}`); 3111} 3112 3113function registerPhotoOutputFrameShutter(photoOutput: camera.PhotoOutput): void { 3114 photoOutput.on('frameShutter', callback); 3115} 3116``` 3117 3118### off('frameShutter') 3119 3120off(type: 'frameShutter', callback?: AsyncCallback\<FrameShutterInfo\>): void 3121 3122Unsubscribes from frame shutter events. 3123 3124**System capability**: SystemCapability.Multimedia.Camera.Core 3125 3126**Parameters** 3127 3128| Name | Type | Mandatory| Description | 3129| -------- | ---------- | --- | ------------------------------------ | 3130| type | string | Yes | Event type. The value is fixed at **'frameShutter'**. The event can be listened for when a **photoOutput** instance is created.| 3131| callback | AsyncCallback\<[FrameShutterInfo](#frameshutterinfo)\> | No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('error') with the specified callback is canceled. (The callback object cannot be an anonymous function.) | 3132 3133**Example** 3134 3135```ts 3136function unregisterPhotoOutputFrameShutter(photoOutput: camera.PhotoOutput): void { 3137 photoOutput.off('frameShutter'); 3138} 3139``` 3140 3141### on('captureEnd') 3142 3143on(type: 'captureEnd', callback: AsyncCallback\<CaptureEndInfo\>): void 3144 3145Subscribes to capture end events. This API uses an asynchronous callback to return the result. 3146 3147**System capability**: SystemCapability.Multimedia.Camera.Core 3148 3149**Parameters** 3150 3151| Name | Type | Mandatory| Description | 3152| -------- | --------------- | ---- | ---------------------------------------- | 3153| type | string | Yes | Event type. The value is fixed at **'captureEnd'**. The event can be listened for when a **photoOutput** instance is created. This event is triggered and the corresponding information is returned when the photographing is complete.| 3154| callback | AsyncCallback\<[CaptureEndInfo](#captureendinfo)\> | Yes | Callback used to return the result. | 3155 3156**Example** 3157 3158```ts 3159import { BusinessError } from '@ohos.base'; 3160 3161function callback(err: BusinessError, captureEndInfo: camera.CaptureEndInfo): void { 3162 console.info(`photo capture end, captureId : ${captureEndInfo.captureId}`); 3163 console.info(`frameCount : ${captureEndInfo.frameCount}`); 3164} 3165 3166function registerPhotoOutputCaptureEnd(photoOutput: camera.PhotoOutput): void { 3167 photoOutput.on('captureEnd', callback); 3168} 3169``` 3170 3171### off('captureEnd') 3172 3173off(type: 'captureEnd', callback?: AsyncCallback\<CaptureEndInfo\>): void 3174 3175Unsubscribes from capture end events. 3176 3177**System capability**: SystemCapability.Multimedia.Camera.Core 3178 3179**Parameters** 3180 3181| Name | Type | Mandatory| Description | 3182| -------- | --------------- | ---- | ---------------------------------------- | 3183| type | string | Yes | Event type. The value is fixed at **'captureEnd'**. The event can be listened for when a **photoOutput** instance is created.| 3184| callback | AsyncCallback\<[CaptureEndInfo](#captureendinfo)\> | No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('error') with the specified callback is canceled. (The callback object cannot be an anonymous function.) | 3185 3186**Example** 3187 3188```ts 3189function unregisterPhotoOutputCaptureEnd(photoOutput: camera.PhotoOutput): void { 3190 photoOutput.off('captureEnd'); 3191} 3192``` 3193 3194### on('error') 3195 3196on(type: 'error', callback: ErrorCallback): void 3197 3198Subscribes to **PhotoOutput** error events. This API uses a callback to return the result. 3199 3200**System capability**: SystemCapability.Multimedia.Camera.Core 3201 3202**Parameters** 3203 3204| Name | Type | Mandatory| Description | 3205| -------- | ------------- | ---- | ----------------------------------- | 3206| type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a **photoOutput** instance is created. This event is triggered and the corresponding error message is returned when an error occurs during the calling of a photo-related API.| 3207| callback | ErrorCallback | Yes | Callback used to return an error code defined in [CameraErrorCode](#cameraerrorcode). | 3208 3209**Example** 3210 3211```ts 3212import { BusinessError } from '@ohos.base'; 3213 3214function callback(err: BusinessError): void { 3215 console.error(`Photo output error code: ${err.code}`); 3216} 3217 3218function registerPhotoOutputError(photoOutput: camera.PhotoOutput): void { 3219 photoOutput.on('error', callback); 3220} 3221``` 3222 3223### off('error') 3224 3225off(type: 'error', callback?: ErrorCallback): void 3226 3227Unsubscribes from **PhotoOutput** error events. 3228 3229**System capability**: SystemCapability.Multimedia.Camera.Core 3230 3231**Parameters** 3232 3233| Name | Type | Mandatory| Description | 3234| -------- | ------------- | ---- | ----------------------------------- | 3235| type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a **photoOutput** instance is created.| 3236| callback | ErrorCallback | No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('error') with the specified callback is canceled. (The callback object cannot be an anonymous function.) | 3237 3238**Example** 3239 3240```ts 3241function unregisterPhotoOutputError(photoOutput: camera.PhotoOutput): void { 3242 photoOutput.off('error'); 3243} 3244``` 3245 3246### isQuickThumbnailSupported 3247 3248isQuickThumbnailSupported(): boolean 3249 3250Checks whether the quick thumbnail feature is supported. 3251 3252This API takes effect after [addOutput](#addoutput) and [addInput](#addinput) and before [commitConfig](#commitconfig). 3253 3254**System API**: This is a system API. 3255 3256**System capability**: SystemCapability.Multimedia.Camera.Core 3257 3258**Return value** 3259 3260| Type| Description| 3261| --------- | ------ | 3262| boolean | **true**: The quick thumbnail feature is supported.<br>**false**: The quick thumbnail feature is not supported.| 3263 3264**Error codes** 3265 3266For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 3267 3268| ID | Error Message | 3269| --------------- | --------------- | 3270| 7400104 | session is not running. | 3271 3272**Example** 3273 3274```ts 3275import common from '@ohos.app.ability.common'; 3276 3277async function isQuickThumbnailSupported(context: common.BaseContext, photoProfile: camera.Profile, surfaceId: string): Promise<boolean> { 3278 let cameraManager: camera.CameraManager = camera.getCameraManager(context); 3279 let cameras: Array<camera.CameraDevice> = cameraManager.getSupportedCameras(); 3280 // Create a CaptureSession instance. 3281 let captureSession: camera.CaptureSession = cameraManager.createCaptureSession(); 3282 // Start configuration for the session. 3283 captureSession.beginConfig(); 3284 // Add a CameraInput instance to the session. 3285 let cameraInput: camera.CameraInput = cameraManager.createCameraInput(cameras[0]); 3286 await cameraInput.open(); 3287 captureSession.addInput(cameraInput); 3288 // Add a PhotoOutput instance to the session. 3289 let photoOutput: camera.PhotoOutput = cameraManager.createPhotoOutput(photoProfile, surfaceId); 3290 captureSession.addOutput(photoOutput); 3291 let isSupported: boolean = photoOutput.isQuickThumbnailSupported(); 3292 return isSupported; 3293} 3294``` 3295 3296### enableQuickThumbnail 3297 3298enableQuickThumbnail(enabled: boolean): void 3299 3300Enables or disables the quick thumbnail feature. 3301 3302This API takes effect after [addOutput](#addoutput) and [addInput](#addinput) and before [commitConfig](#commitconfig). 3303 3304**System API**: This is a system API. 3305 3306**System capability**: SystemCapability.Multimedia.Camera.Core 3307 3308**Parameters** 3309 3310| Name | Type | Mandatory| Description | 3311| -------- | ------------- | ---- | ----------------------------------- | 3312| enabled | boolean | Yes | Whether to enable the quick thumbnail feature. The value **true** means to enable the quick thumbnail feature, and **false** means to disable it.| 3313 3314**Error codes** 3315 3316For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 3317 3318| ID | Error Message | 3319| --------------- | --------------- | 3320| 7400104 | session is not running. | 3321 3322**Example** 3323 3324```ts 3325import common from '@ohos.app.ability.common'; 3326import { BusinessError } from '@ohos.base'; 3327 3328async function enableQuickThumbnail(context: common.BaseContext, photoProfile: camera.Profile, surfaceId: string): Promise<void> { 3329 let cameraManager: camera.CameraManager = camera.getCameraManager(context); 3330 let cameras: Array<camera.CameraDevice> = cameraManager.getSupportedCameras(); 3331 // Create a CaptureSession instance. 3332 let captureSession: camera.CaptureSession = cameraManager.createCaptureSession(); 3333 // Start configuration for the session. 3334 captureSession.beginConfig(); 3335 // Add a CameraInput instance to the session. 3336 let cameraInput: camera.CameraInput = cameraManager.createCameraInput(cameras[0]); 3337 await cameraInput.open(); 3338 captureSession.addInput(cameraInput); 3339 // Add a PhotoOutput instance to the session. 3340 let photoOutput: camera.PhotoOutput = cameraManager.createPhotoOutput(photoProfile, surfaceId); 3341 captureSession.addOutput(photoOutput); 3342 let isSupported: boolean = photoOutput.isQuickThumbnailSupported(); 3343 if (!isSupported) { 3344 console.info('Quick Thumbnail is not supported to be turned on.'); 3345 return; 3346 } 3347 try { 3348 photoOutput.enableQuickThumbnail(true); 3349 } catch (error) { 3350 let err = error as BusinessError; 3351 console.error(`The enableQuickThumbnail call failed. error code: ${err.code}`); 3352 } 3353} 3354``` 3355 3356### on('quickThumbnail') 3357 3358on(type: 'quickThumbnail', callback: AsyncCallback\<image.PixelMap>): void 3359 3360Subscribes to quick thumbnail output events. 3361 3362The listening takes effect after **enableQuickThumbnail(true)** is called. 3363 3364**System API**: This is a system API. 3365 3366**System capability**: SystemCapability.Multimedia.Camera.Core 3367 3368**Parameters** 3369 3370| Name | Type | Mandatory| Description | 3371| -------- | ------------- | ---- | ----------------------------------- | 3372| type | string | Yes | Event type. The value is fixed at **'quickThumbnail'**.| 3373| callback | AsyncCallback\<[image.PixelMap](js-apis-image.md#pixelmap7)> | Yes| Callback that returns a **PixelMap** instance.| 3374 3375**Example** 3376 3377```ts 3378import common from '@ohos.app.ability.common'; 3379import { BusinessError } from '@ohos.base'; 3380import image from '@ohos.multimedia.image'; 3381 3382function callback(err: BusinessError, pixelMap: image.PixelMap): void { 3383 if (err || pixelMap === undefined) { 3384 console.error('photoOutput on thumbnail failed'); 3385 return; 3386 } 3387 // Display or save the PixelMap instance. 3388 // do something 3389} 3390 3391async function registerQuickThumbnail(context: common.BaseContext, photoProfile: camera.Profile, surfaceId: string): Promise<void> { 3392 let cameraManager: camera.CameraManager = camera.getCameraManager(context); 3393 let cameras: Array<camera.CameraDevice> = cameraManager.getSupportedCameras(); 3394 // Create a CaptureSession instance. 3395 let captureSession: camera.CaptureSession = cameraManager.createCaptureSession(); 3396 // Start configuration for the session. 3397 captureSession.beginConfig(); 3398 // Add a CameraInput instance to the session. 3399 let cameraInput: camera.CameraInput = cameraManager.createCameraInput(cameras[0]); 3400 await cameraInput.open(); 3401 captureSession.addInput(cameraInput); 3402 // Add a PhotoOutput instance to the session. 3403 let photoOutput: camera.PhotoOutput = cameraManager.createPhotoOutput(photoProfile, surfaceId); 3404 captureSession.addOutput(photoOutput); 3405 let isSupported: boolean = photoOutput.isQuickThumbnailSupported(); 3406 if (!isSupported) { 3407 console.info('Quick Thumbnail is not supported to be turned on.'); 3408 return; 3409 } 3410 try { 3411 photoOutput.enableQuickThumbnail(true); 3412 } catch (error) { 3413 let err = error as BusinessError; 3414 console.error(`The enableQuickThumbnail call failed. error code: ${err.code}`); 3415 } 3416 3417 photoOutput.on('quickThumbnail', callback); 3418} 3419``` 3420 3421### off('quickThumbnail') 3422 3423off(type: 'quickThumbnail', callback?: AsyncCallback\<image.PixelMap>): void 3424 3425Unsubscribes from quick thumbnail output events. 3426 3427**System API**: This is a system API. 3428 3429**System capability**: SystemCapability.Multimedia.Camera.Core 3430 3431**Parameters** 3432 3433| Name | Type | Mandatory| Description | 3434| -------- | ------------- | ---- | ----------------------------------- | 3435| type | string | Yes | Event type. The value is fixed at **'quickThumbnail'**.| 3436| callback | AsyncCallback\<[image.PixelMap](js-apis-image.md#pixelmap7)> | No| Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('error') with the specified callback is canceled. (The callback object cannot be an anonymous function.)| 3437 3438**Example** 3439 3440```ts 3441function unregisterQuickThumbnail(photoOutput: camera.PhotoOutput): void { 3442 photoOutput.off('quickThumbnail'); 3443} 3444``` 3445 3446## FrameShutterInfo 3447 3448Defines the frame shutter information. 3449 3450**System capability**: SystemCapability.Multimedia.Camera.Core 3451 3452| Name | Type | Mandatory| Description | 3453| --------- | ------ | ---- | ---------- | 3454| captureId | number | Yes | ID of this capture action. | 3455| timestamp | number | Yes | Timestamp when the frame shutter event is triggered.| 3456 3457## CaptureStartInfo<sup>11+</sup> 3458 3459Defines the capture start information. 3460 3461**System capability**: SystemCapability.Multimedia.Camera.Core 3462 3463| Name | Type | Mandatory| Description | 3464| ---------- | ------ | ---- | ---------| 3465| captureId | number | Yes | ID of this capture action.| 3466| time | number | Yes | Capture timestamp. | 3467 3468## CaptureEndInfo 3469 3470Defines the capture end information. 3471 3472**System capability**: SystemCapability.Multimedia.Camera.Core 3473 3474| Name | Type | Mandatory| Description | 3475| ---------- | ------ | ---- | ---------| 3476| captureId | number | Yes | ID of this capture action.| 3477| frameCount | number | Yes | Number of frames captured. | 3478 3479## VideoOutput 3480 3481Implements output information used in a video session. It inherits from [CameraOutput](#cameraoutput). 3482 3483### start 3484 3485start(callback: AsyncCallback\<void\>): void 3486 3487Starts video recording. This API uses an asynchronous callback to return the result. 3488 3489**System capability**: SystemCapability.Multimedia.Camera.Core 3490 3491**Parameters** 3492 3493| Name | Type | Mandatory| Description | 3494| -------- | -------------------- | ---- | -------------------- | 3495| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 3496 3497**Error codes** 3498 3499For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 3500 3501| ID | Error Message | 3502| --------------- | --------------- | 3503| 7400103 | Session not config. | 3504| 7400201 | Camera service fatal error. | 3505 3506**Example** 3507 3508```ts 3509import { BusinessError } from '@ohos.base'; 3510 3511function startVideoOutput(videoOutput: camera.VideoOutput): void { 3512 videoOutput.start((err: BusinessError) => { 3513 if (err) { 3514 console.error(`Failed to start the video output, error code: ${err.code}.`); 3515 return; 3516 } 3517 console.info('Callback invoked to indicate the video output start success.'); 3518 }); 3519} 3520``` 3521 3522### start 3523 3524start(): Promise\<void\> 3525 3526Starts video recording. This API uses a promise to return the result. 3527 3528**System capability**: SystemCapability.Multimedia.Camera.Core 3529 3530**Return value** 3531 3532| Type | Description | 3533| -------------- | ----------------------- | 3534| Promise\<void\> | Promise used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 3535 3536**Error codes** 3537 3538For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 3539 3540| ID | Error Message | 3541| --------------- | --------------- | 3542| 7400103 | Session not config. | 3543| 7400201 | Camera service fatal error. | 3544 3545**Example** 3546 3547```ts 3548import { BusinessError } from '@ohos.base'; 3549 3550function startVideoOutput(videoOutput: camera.VideoOutput): void { 3551 videoOutput.start().then(() => { 3552 console.info('Promise returned to indicate that start method execution success.'); 3553 }).catch((err: BusinessError) => { 3554 let err = error as BusinessError; 3555 console.error(`Failed to videoOutput start, error code: ${err.code}.`); 3556 }); 3557} 3558``` 3559 3560### stop 3561 3562stop(callback: AsyncCallback\<void\>): void 3563 3564Stops video recording. This API uses an asynchronous callback to return the result. 3565 3566**System capability**: SystemCapability.Multimedia.Camera.Core 3567 3568**Parameters** 3569 3570| Name | Type | Mandatory| Description | 3571| -------- | -------------------- | ---- | ------------------------ | 3572| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| 3573 3574**Example** 3575 3576```ts 3577import { BusinessError } from '@ohos.base'; 3578 3579function stopVideoOutput(videoOutput: camera.VideoOutput): void { 3580 videoOutput.stop((err: BusinessError) => { 3581 if (err) { 3582 console.error(`Failed to stop the video output, error code: ${err.code}.`); 3583 return; 3584 } 3585 console.info('Callback invoked to indicate the video output stop success.'); 3586 }); 3587} 3588``` 3589 3590### stop 3591 3592stop(): Promise\<void\> 3593 3594Stops video recording. This API uses a promise to return the result. 3595 3596**System capability**: SystemCapability.Multimedia.Camera.Core 3597 3598**Return value** 3599 3600| Type | Description | 3601| -------------- | ----------------------- | 3602| Promise\<void\> | Promise used to return the result.| 3603 3604**Example** 3605 3606```ts 3607import { BusinessError } from '@ohos.base'; 3608 3609function stopVideoOutput(videoOutput: camera.VideoOutput): void { 3610 videoOutput.stop().then(() => { 3611 console.info('Promise returned to indicate that stop method execution success.'); 3612 }).catch((err: BusinessError) => { 3613 let err = error as BusinessError; 3614 console.error(`Failed to videoOutput stop, error code: ${err.code}.`); 3615 }); 3616} 3617``` 3618 3619### on('frameStart') 3620 3621on(type: 'frameStart', callback: AsyncCallback\<void\>): void 3622 3623Subscribes to video recording start events. This API uses an asynchronous callback to return the result. 3624 3625**System capability**: SystemCapability.Multimedia.Camera.Core 3626 3627**Parameters** 3628 3629| Name | Type | Mandatory| Description | 3630| -------- | -------------------- | ---- | ----------------------------------------- | 3631| type | string | Yes | Event type. The value is fixed at **'frameStart'**. The event can be listened for when a **videoOutput** instance is created. The event is triggered and the corresponding information is returned when the bottom layer starts exposure for the first time.| 3632| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. The recording starts as long as this event is returned. | 3633 3634**Example** 3635 3636```ts 3637function callback(): void { 3638 console.info('Video frame started'); 3639} 3640 3641function registerVideoOutputFrameStart(videoOutput: camera.VideoOutput): void { 3642 videoOutput.on('frameStart', callback); 3643} 3644``` 3645 3646### off('frameStart') 3647 3648off(type: 'frameStart', callback?: AsyncCallback\<void\>): void 3649 3650Unsubscribes from video recording start events. 3651 3652**System capability**: SystemCapability.Multimedia.Camera.Core 3653 3654**Parameters** 3655 3656| Name | Type | Mandatory| Description | 3657| -------- | -------------------- | ---- | ----------------------------------------- | 3658| type | string | Yes | Event type. The value is fixed at **'frameStart'**. The event can be listened for when a **videoOutput** instance is created.| 3659| callback | AsyncCallback\<void\> | No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('error') with the specified callback is canceled. (The callback object cannot be an anonymous function.) | 3660 3661**Example** 3662 3663```ts 3664function unregisterVideoOutputFrameStart(videoOutput: camera.VideoOutput): void { 3665 videoOutput.off('frameStart'); 3666} 3667 3668``` 3669 3670### on('frameEnd') 3671 3672on(type: 'frameEnd', callback: AsyncCallback\<void\>): void 3673 3674Subscribes to video recording stop events. This API uses an asynchronous callback to return the result. 3675 3676**System capability**: SystemCapability.Multimedia.Camera.Core 3677 3678**Parameters** 3679 3680| Name | Type | Mandatory| Description | 3681| -------- | -------------------- | ---- | ------------------------------------------ | 3682| type | string | Yes | Event type. The value is fixed at **'frameEnd'**. The event can be listened for when a **videoOutput** instance is created. This event is triggered and returned when the last frame of recording is complete.| 3683| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. The recording ends as long as this event is returned. | 3684 3685**Example** 3686 3687```ts 3688function callback(): void { 3689 console.info('Video frame ended'); 3690} 3691 3692function registerVideoOutputFrameEnd(videoOutput: camera.VideoOutput): void { 3693 videoOutput.on('frameEnd', callback); 3694} 3695``` 3696 3697### off('frameEnd') 3698 3699off(type: 'frameEnd', callback?: AsyncCallback\<void\>): void 3700 3701Unsubscribes from video recording stop events. 3702 3703**System capability**: SystemCapability.Multimedia.Camera.Core 3704 3705**Parameters** 3706 3707| Name | Type | Mandatory| Description | 3708| -------- | -------------------- | ---- | ------------------------------------------ | 3709| type | string | Yes | Event type. The value is fixed at **'frameEnd'**. The event can be listened for when a **videoOutput** instance is created.| 3710| callback | AsyncCallback\<void\> | No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('error') with the specified callback is canceled. (The callback object cannot be an anonymous function.) | 3711 3712**Example** 3713 3714```ts 3715function unregisterVideoOutputFrameEnd(videoOutput: camera.VideoOutput): void { 3716 videoOutput.off('frameEnd'); 3717} 3718``` 3719 3720### on('error') 3721 3722on(type: 'error', callback: ErrorCallback): void 3723 3724Subscribes to **VideoOutput** error events. This API uses a callback to return the result. 3725 3726**System capability**: SystemCapability.Multimedia.Camera.Core 3727 3728**Parameters** 3729 3730| Name | Type | Mandatory| Description | 3731| -------- | ----------- | ---- | -------------------------------------- | 3732| type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a **videoOutput** instance is created. This event is triggered and the corresponding error message is returned when an error occurs during the use of a recording-related API such as [start](#start-1) or [CameraOutput.release](#release-1).| 3733| callback | ErrorCallback | Yes | Callback used to return an error code defined in [CameraErrorCode](#cameraerrorcode). | 3734 3735**Example** 3736 3737```ts 3738import { BusinessError } from '@ohos.base'; 3739 3740function callback(err: BusinessError): void { 3741 console.error(`Video output error code: ${err.code}`); 3742} 3743 3744function registerVideoOutputError(videoOutput: camera.VideoOutput): void { 3745 videoOutput.on('error', callback); 3746} 3747``` 3748 3749### off('error') 3750 3751off(type: 'error', callback?: ErrorCallback): void 3752 3753Unsubscribes from **VideoOutput** error events. 3754 3755**System capability**: SystemCapability.Multimedia.Camera.Core 3756 3757**Parameters** 3758 3759| Name | Type | Mandatory| Description | 3760| -------- | ------------- | ---- | ----------------------------------- | 3761| type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a **photoOutput** instance is created.| 3762| callback | ErrorCallback | No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('error') with the specified callback is canceled. (The callback object cannot be an anonymous function.) | 3763 3764**Example** 3765 3766```ts 3767function unregisterVideoOutputError(videoOutput: camera.VideoOutput): void { 3768 videoOutput.off('error'); 3769} 3770``` 3771 3772## MetadataOutput 3773 3774Implements metadata streams. It inherits from [CameraOutput](#cameraoutput). 3775 3776### start 3777 3778start(callback: AsyncCallback\<void\>): void 3779 3780Starts to output metadata. This API uses an asynchronous callback to return the result. 3781 3782**System capability**: SystemCapability.Multimedia.Camera.Core 3783 3784**Parameters** 3785 3786| Name | Type | Mandatory| Description | 3787| -------- | -------------------------- | ---- | ------------------- | 3788| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 3789 3790**Error codes** 3791 3792For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 3793 3794| ID | Error Message | 3795| --------------- | --------------- | 3796| 7400103 | Session not config. | 3797| 7400201 | Camera service fatal error. | 3798 3799**Example** 3800 3801```ts 3802import { BusinessError } from '@ohos.base'; 3803 3804function startMetadataOutput(metadataOutput: camera.MetadataOutput): void { 3805 metadataOutput.start((err: BusinessError) => { 3806 if (err) { 3807 console.error(`Failed to start metadataOutput, error code: ${err.code}.`); 3808 return; 3809 } 3810 console.info('Callback returned with metadataOutput started.'); 3811 }); 3812} 3813``` 3814 3815### start 3816 3817start(): Promise\<void\> 3818 3819Starts to output metadata. This API uses a promise to return the result. 3820 3821**System capability**: SystemCapability.Multimedia.Camera.Core 3822 3823**Return value** 3824 3825| Type | Description | 3826| ---------------------- | ------------------------ | 3827| Promise\<void\> | Promise used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 3828 3829**Error codes** 3830 3831For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 3832 3833| ID | Error Message | 3834| --------------- | --------------- | 3835| 7400103 | Session not config. | 3836| 7400201 | Camera service fatal error. | 3837 3838**Example** 3839 3840```ts 3841import { BusinessError } from '@ohos.base'; 3842 3843function startMetadataOutput(metadataOutput: camera.MetadataOutput): void { 3844 metadataOutput.start().then(() => { 3845 console.info('Callback returned with metadataOutput started.'); 3846 }).catch((err: BusinessError) => { 3847 let err = error as BusinessError; 3848 console.error(`Failed to metadataOutput stop, error code: ${err.code}`); 3849 }); 3850} 3851``` 3852 3853### stop 3854 3855stop(callback: AsyncCallback\<void\>): void 3856 3857Stops outputting metadata. This API uses an asynchronous callback to return the result. 3858 3859**System capability**: SystemCapability.Multimedia.Camera.Core 3860 3861**Parameters** 3862 3863| Name | Type | Mandatory| Description | 3864| -------- | -------------------------- | ---- | ------------------- | 3865| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| 3866 3867**Example** 3868 3869```ts 3870import { BusinessError } from '@ohos.base'; 3871 3872function stopMetadataOutput(metadataOutput: camera.MetadataOutput): void { 3873 metadataOutput.stop((err: BusinessError) => { 3874 if (err) { 3875 console.error(`Failed to stop the metadataOutput, error code: ${err.code}.`); 3876 return; 3877 } 3878 console.info('Callback returned with metadataOutput stopped.'); 3879 }) 3880} 3881``` 3882 3883### stop 3884 3885stop(): Promise\<void\> 3886 3887Stops outputting metadata. This API uses a promise to return the result. 3888 3889**System capability**: SystemCapability.Multimedia.Camera.Core 3890 3891**Return value** 3892 3893| Type | Description | 3894| ---------------------- | --------------------------- | 3895| Promise\<void\> | Promise used to return the result.| 3896 3897**Example** 3898 3899```ts 3900import { BusinessError } from '@ohos.base'; 3901 3902function stopMetadataOutput(metadataOutput: camera.MetadataOutput): void { 3903 metadataOutput.stop().then(() => { 3904 console.info('Callback returned with metadataOutput stopped.'); 3905 }).catch((err: BusinessError) => { 3906 let err = error as BusinessError; 3907 console.error(`Failed to metadataOutput stop, error code: ${err.code}`); 3908 }); 3909} 3910``` 3911 3912### on('metadataObjectsAvailable') 3913 3914on(type: 'metadataObjectsAvailable', callback: AsyncCallback\<Array\<MetadataObject\>\>): void 3915 3916Subscribes to events indicating available metadata objects. This API uses an asynchronous callback to return the result. 3917 3918**System capability**: SystemCapability.Multimedia.Camera.Core 3919 3920**Parameters** 3921 3922| Name | Type | Mandatory| Description | 3923| -------- | -------------- | ---- | ------------------------------------ | 3924| type | string | Yes | Event type. The value is fixed at **'metadataObjectsAvailable'**. The event can be listened for when a **metadataOutput** instance is created. This event is triggered and the corresponding metadata is returned when valid metadata is detected.| 3925| callback | Callback\<Array\<[MetadataObject](#metadataobject)\>\> | Yes | Callback used to return the metadata.| 3926 3927**Example** 3928 3929```ts 3930import { BusinessError } from '@ohos.base'; 3931 3932function callback(err: BusinessError, metadataObjectArr: Array<camera.MetadataObject>): void { 3933 console.info('metadata output metadataObjectsAvailable'); 3934} 3935 3936function registerMetadataObjectsAvailable(metadataOutput: camera.MetadataOutput): void { 3937 metadataOutput.on('metadataObjectsAvailable', callback); 3938} 3939``` 3940 3941### off('metadataObjectsAvailable') 3942 3943off(type: 'metadataObjectsAvailable', callback?: AsyncCallback\<Array\<MetadataObject\>\>): void 3944 3945Unsubscribes from events indicating available metadata objects. 3946 3947**System capability**: SystemCapability.Multimedia.Camera.Core 3948 3949**Parameters** 3950 3951| Name | Type | Mandatory| Description | 3952| -------- | -------------- | ---- | ------------------------------------ | 3953| type | string | Yes | Event type. The value is fixed at **'metadataObjectsAvailable'**. The event can be listened for when a **metadataOutput** instance is created.| 3954| callback | Callback\<Array\<[MetadataObject](#metadataobject)\>\> | No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('error') with the specified callback is canceled. (The callback object cannot be an anonymous function.)| 3955 3956**Example** 3957 3958```ts 3959function unregisterMetadataObjectsAvailable(metadataOutput: camera.MetadataOutput): void { 3960 metadataOutput.off('metadataObjectsAvailable'); 3961} 3962``` 3963 3964### on('error') 3965 3966on(type: 'error', callback: ErrorCallback): void 3967 3968Subscribes to metadata error events. This API uses an asynchronous callback to return the result. 3969 3970**System capability**: SystemCapability.Multimedia.Camera.Core 3971 3972**Parameters** 3973 3974| Name | Type | Mandatory| Description | 3975| -------- | ------------- | ---- | --------------------------------------- | 3976| type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a **metadataOutput** instance is created. This event is triggered and the corresponding error message is returned when an error occurs during the use of a metadata-related API such as [start](#start-3) or [CameraOutput.release](#release-1).| 3977| callback | ErrorCallback | Yes | Callback used to return an error code defined in [CameraErrorCode](#cameraerrorcode). | 3978 3979**Example** 3980 3981```ts 3982import { BusinessError } from '@ohos.base'; 3983 3984function callback(metadataOutputError: BusinessError): void { 3985 console.error(`Metadata output error code: ${metadataOutputError.code}`); 3986} 3987 3988function registerMetadataOutputError(metadataOutput: camera.MetadataOutput): void { 3989 metadataOutput.on('error', callback); 3990} 3991``` 3992 3993### off('error') 3994 3995off(type: 'error', callback?: ErrorCallback): void 3996 3997Unsubscribes from metadata error events. 3998 3999**System capability**: SystemCapability.Multimedia.Camera.Core 4000 4001**Parameters** 4002 4003| Name | Type | Mandatory| Description | 4004| -------- | ------------- | ---- | --------------------------------------- | 4005| type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a **metadataOutput** instance is created.| 4006| callback | ErrorCallback | No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('error') with the specified callback is canceled. (The callback object cannot be an anonymous function.) | 4007 4008**Example** 4009 4010```ts 4011function unregisterMetadataOutputError(metadataOutput: camera.MetadataOutput): void { 4012 metadataOutput.off('error'); 4013} 4014``` 4015 4016## MetadataObjectType 4017 4018Enumerates the metadata object types. 4019 4020**System capability**: SystemCapability.Multimedia.Camera.Core 4021 4022| Name | Value | Description | 4023| ------------------------- | ---- | ----------------- | 4024| FACE_DETECTION | 0 | Metadata object used for face detection.<br> The detection point must be in the coordinate system (0-1), where the upper left corner is (0, 0) and the lower right corner is (1, 1).<br> The coordinate system is based on the horizontal device direction with the device's charging port on the right.<br>If the layout of a preview screen of an application is based on the vertical direction with the charging port on the lower side,<br>the layout width and height are (w, h) and the return point is (x, y), then the coordinate point after conversion is (1-y, x).| 4025 4026## Rect 4027 4028Defines a rectangle. 4029 4030**System capability**: SystemCapability.Multimedia.Camera.Core 4031 4032| Name | Type | Mandatory | Description | 4033| -------- | ------ | --------------- | -------------------- | 4034| topLeftX | number | Yes | X-axis coordinate of the upper left corner of the rectangle. | 4035| topLeftY | number | Yes | Y-axis coordinate of the upper left corner of the rectangle. | 4036| width | number | Yes | Width of the rectangle, which is a relative value. The value range is [0, 1]. | 4037| height | number | Yes | Height of the rectangle, which is a relative value. The value range is [0, 1]. | 4038 4039## MetadataObject 4040 4041Implements camera metadata, which is the data source of [CameraInput](#camerainput). The metadata is obtained through metadataOutput.on('metadataObjectsAvailable'). 4042 4043**System capability**: SystemCapability.Multimedia.Camera.Core 4044 4045| Name | Type | Mandatory | Read-only|Description | 4046| -------- | ------------------------------- | ---- | ---- |-----------------| 4047| type | [MetadataObjectType](#metadataobjecttype) | No | Yes | Metadata object type.| 4048| timestamp | number | No | Yes | Current timestamp, in milliseconds.| 4049| boundingBox | [Rect](#rect) | No | Yes | Metadata rectangle.| 4050 4051## PortraitEffect 4052 4053Enumerates the portrait effects. 4054 4055**System API**: This is a system API. 4056 4057**System capability**: SystemCapability.Multimedia.Camera.Core 4058 4059| Name | Value | Description | 4060| ----------------| ---- | ---------| 4061| OFF | 0 | Disabled. | 4062| CIRCLES | 1 | Circles. | 4063| HEART<sup>11+</sup> | 2 | Heart-shaped. | 4064| ROTATED<sup>11+</sup> | 3 | Rotated. | 4065| STUDIO<sup>11+</sup> | 4 | Studio light. | 4066| THEATER<sup>11+</sup> | 5 | Theater light. | 4067 4068## BeautyType 4069 4070Enumerates the beauty types. 4071 4072**System API**: This is a system API. 4073 4074**System capability**: SystemCapability.Multimedia.Camera.Core 4075 4076| Name | Value | Description | 4077| ----------------| ---- | ---------| 4078| AUTO | 0 | Automatic. | 4079| SKIN_SMOOTH | 1 | Skin smoothing. | 4080| FACE_SLENDER | 2 | Face slimming. | 4081| SKIN_TONE | 3 | Skin tone perfection. | 4082 4083## FlashMode 4084 4085Enumerates the flash modes. 4086 4087**System capability**: SystemCapability.Multimedia.Camera.Core 4088 4089| Name | Value | Description | 4090| ---------------------- | ---- | ---------- | 4091| FLASH_MODE_CLOSE | 0 | The flash is off.| 4092| FLASH_MODE_OPEN | 1 | The flash is on.| 4093| FLASH_MODE_AUTO | 2 | The flash mode is auto, indicating that the flash fires automatically depending on the photo capture conditions.| 4094| FLASH_MODE_ALWAYS_OPEN | 3 | The flash is steady on.| 4095 4096## ManualExposure<sup>11+</sup> 4097 4098Provides APIs related to manual exposure. 4099 4100### getSupportedExposureRange 4101 4102getSupportedExposureRange(): Array\<number\> 4103 4104Obtains the supported manual exposure durations. 4105 4106**System API**: This is a system API. 4107 4108**System capability**: SystemCapability.Multimedia.Camera.Core 4109 4110**Return value** 4111 4112| Type | Description | 4113| ---------- | ----------------------------- | 4114| Array\<number\>| Array of manual exposure durations supported, in ms. | 4115 4116**Error codes** 4117 4118For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 4119 4120| ID | Error Message | 4121| --------------- | --------------- | 4122| 7400103 | Session not config. | 4123 4124 **Example** 4125 4126```ts 4127function getSupportedExposureRange(nightPhotoSession: camera.NightPhotoSession): Array<number> { 4128 let exposureRange: Array<number> = nightPhotoSession.getSupportedExposureRange(); 4129 return exposureRange; 4130} 4131``` 4132 4133### getExposure 4134 4135getExposure(): number 4136 4137Obtains the manual exposure duration in use. 4138 4139**System API**: This is a system API. 4140 4141**System capability**: SystemCapability.Multimedia.Camera.Core 4142 4143**Return value** 4144| Name | Type | Mandatory| Description | 4145| -------- | ------------------------------------------------- | ---- | --------------------- | 4146| value | number | Yes | Manual exposure duration, in ms. | 4147 4148**Error codes** 4149 4150For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 4151 4152| ID | Error Message | 4153| --------------- | --------------- | 4154| 7400103 | Session not config. | 4155 4156**Example** 4157 4158```ts 4159function getExposure(portraitSession: camera.PortraitPhotoSession): number { 4160 let exposureRange: Array<number> = nightPhotoSession.getSupportedExposureRange(); 4161 if (exposureRange === undefined || exposureRange.length <= 0) { 4162 return; 4163 } 4164 let exposure: number = nightPhotoSession.getExposure(); 4165 return exposure; 4166} 4167``` 4168 4169### setExposure 4170 4171setExposure(exposure: number): void 4172 4173Sets the manual exposure duration, in ms. 4174 4175**System API**: This is a system API. 4176 4177**System capability**: SystemCapability.Multimedia.Camera.Core 4178 4179**Parameters** 4180 4181| Name | Type | Mandatory| Description | 4182| -------- | --------------------------| ---- | --------------------- | 4183| value | number | Yes | Manual exposure duration, which must be one of the supported durations obtained by running [getSupportedExposureRange](#getsupportedexposurerange).| 4184 4185 **Error codes** 4186 4187| ID | Error Message | 4188| --------------- | --------------- | 4189| 7400103 | Session not config. | 4190 4191```ts 4192function setExposure(nightPhotoSession: camera.NightPhotoSession): void { 4193 let exposureRange: Array<number> = nightPhotoSession.getSupportedExposureRange(); 4194 if (exposureRange === undefined || exposureRange.length <= 0) { 4195 return; 4196 } 4197 nightPhotoSession.setExposure(exposureRange[0]); 4198} 4199``` 4200 4201## ExposureMode 4202 4203Enumerates the exposure modes. 4204 4205**System capability**: SystemCapability.Multimedia.Camera.Core 4206 4207| Name | Value | Description | 4208| ----------------------------- | ---- | ----------- | 4209| EXPOSURE_MODE_LOCKED | 0 | Exposure locked. The metering point cannot be set.| 4210| EXPOSURE_MODE_AUTO | 1 | Auto exposure. The metering point can be set by calling [setMeteringPoint](#setmeteringpoint).| 4211| EXPOSURE_MODE_CONTINUOUS_AUTO | 2 | Continuous auto exposure. The metering point cannot be set.| 4212 4213## FocusMode 4214 4215Enumerates the focus modes. 4216 4217**System capability**: SystemCapability.Multimedia.Camera.Core 4218 4219| Name | Value | Description | 4220| -------------------------- | ---- | ------------ | 4221| FOCUS_MODE_MANUAL | 0 | Manual focus. The focal length of the camera can be manually set to change the focus position. However, the focal point cannot be set. | 4222| FOCUS_MODE_CONTINUOUS_AUTO | 1 | Continuous auto focus. The focal point cannot be set.| 4223| FOCUS_MODE_AUTO | 2 | Auto focus. The focal point can be set by calling [setFocusPoint](#setfocuspoint), and auto focus is performed once based on the focal point. | 4224| FOCUS_MODE_LOCKED | 3 | Focus locked. The focal point cannot be set. | 4225 4226## FocusState 4227 4228Enumerates the focus states. 4229 4230**System capability**: SystemCapability.Multimedia.Camera.Core 4231 4232| Name | Value | Description | 4233| --------------------- | ---- | --------- | 4234| FOCUS_STATE_SCAN | 0 | Focusing. | 4235| FOCUS_STATE_FOCUSED | 1 | Focused. | 4236| FOCUS_STATE_UNFOCUSED | 2 | Unfocused.| 4237 4238## VideoStabilizationMode 4239 4240Enumerates the video stabilization modes. 4241 4242**System capability**: SystemCapability.Multimedia.Camera.Core 4243 4244| Name | Value | Description | 4245| --------- | ---- | ------------ | 4246| OFF | 0 | Video stabilization is disabled. | 4247| LOW | 1 | The basic video stabilization algorithm is used. | 4248| MIDDLE | 2 | A video stabilization algorithm with a stabilization effect better than that of the **LOW** type is used. | 4249| HIGH | 3 | A video stabilization algorithm with a stabilization effect better than that of the **MIDDLE** type is used. | 4250| AUTO | 4 | Automatic video stabilization is used. | 4251 4252## Macro 4253 4254Provides APIs related to macro photography. 4255 4256### isMacroSupported 4257 4258isMacroSupported(): boolean 4259 4260Checks whether macro photography is supported in the current state. This API must be called after **commitConfig**. 4261 4262**System API**: This is a system API. 4263 4264**System capability**: SystemCapability.Multimedia.Camera.Core 4265 4266**Return value** 4267 4268| Type | Description | 4269| ---------- | ----------------------------- | 4270| boolean | **true**: Macro photography is supported.<br>**false**: Macro photography is not supported.| 4271 4272**Error codes** 4273 4274For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 4275 4276| ID | Error Message | 4277| --------------- | --------------- | 4278| 7400103 | Session not config. | 4279| 202 | Not System Application. | 4280 4281**Example** 4282 4283```ts 4284function isMacroSupported(captureSession: camera.CaptureSession): boolean { 4285 let isSupported: boolean = captureSession.isMacroSupported(); 4286 return isSupported; 4287} 4288``` 4289 4290### enableMacro 4291 4292enableMacro(enabled: boolean): void 4293 4294Enables or disables macro photography. This API can be called only when macro photography is supported. 4295 4296**System API**: This is a system API. 4297 4298**System capability**: SystemCapability.Multimedia.Camera.Core 4299 4300**Parameters** 4301 4302| Name | Type | Mandatory| Description | 4303| -------- | -------------------- | ---- | -------------------- | 4304| enabled | boolean | Yes | Whether to enable macro photography. The value **true** means to enable macro photography, and **false** means to disable it.| 4305 4306**Example** 4307 4308```ts 4309function enableMacro(captureSession: camera.CaptureSession): boolean { 4310 let isSupported: boolean = captureSession.isMacroSupported(); 4311 if (isSupported) { 4312 captureSession.enableMacro(true); 4313 } 4314} 4315``` 4316 4317## Session<sup>11+</sup> 4318 4319Implements a session, which saves all [CameraInput](#camerainput) and [CameraOutput](#cameraoutput) instances required to run the camera and requests the camera to take a photo or record a video. 4320 4321### beginConfig 4322 4323beginConfig(): void 4324 4325Starts configuration for the session. 4326 4327**System capability**: SystemCapability.Multimedia.Camera.Core 4328 4329**Error codes** 4330 4331For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 4332 4333| ID | Error Message | 4334| --------------- | --------------- | 4335| 7400105 | Session config locked. | 4336 4337**Example** 4338 4339```ts 4340import { BusinessError } from '@ohos.base'; 4341 4342function beginConfig(captureSession: camera.CaptureSession): void { 4343 try { 4344 captureSession.beginConfig(); 4345 } catch (error) { 4346 // If the operation fails, error.code is returned and processed. 4347 let err = error as BusinessError; 4348 console.error(`The beginConfig call failed. error code: ${err.code}`); 4349 } 4350} 4351``` 4352 4353### commitConfig 4354 4355commitConfig(callback: AsyncCallback\<void\>): void 4356 4357Commits the configuration for this session. This API uses an asynchronous callback to return the result. 4358 4359**System capability**: SystemCapability.Multimedia.Camera.Core 4360 4361**Parameters** 4362 4363| Name | Type | Mandatory| Description | 4364| -------- | -------------------- | ---- | -------------------- | 4365| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 4366 4367**Error codes** 4368 4369For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 4370 4371| ID | Error Message | 4372| --------------- | --------------- | 4373| 7400102 | Operation not allow. | 4374| 7400201 | Camera service fatal error. | 4375 4376**Example** 4377 4378```ts 4379import { BusinessError } from '@ohos.base'; 4380 4381function commitConfig(captureSession: camera.CaptureSession): void { 4382 captureSession.commitConfig((err: BusinessError) => { 4383 if (err) { 4384 console.error(`The commitConfig call failed. error code: ${err.code}`); 4385 return; 4386 } 4387 console.info('Callback invoked to indicate the commit config success.'); 4388 }); 4389} 4390``` 4391 4392### commitConfig 4393 4394commitConfig(): Promise\<void\> 4395 4396Commits the configuration for this session. This API uses a promise to return the result. 4397 4398**System capability**: SystemCapability.Multimedia.Camera.Core 4399 4400**Return value** 4401 4402| Type | Description | 4403| -------------- | ------------------------ | 4404| Promise\<void\> | Promise used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 4405 4406**Error codes** 4407 4408For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 4409 4410| ID | Error Message | 4411| --------------- | --------------- | 4412| 7400102 | Operation not allow. | 4413| 7400201 | Camera service fatal error. | 4414 4415**Example** 4416 4417```ts 4418import { BusinessError } from '@ohos.base'; 4419 4420function commitConfig(captureSession: camera.CaptureSession): void { 4421 captureSession.commitConfig().then(() => { 4422 console.info('Promise returned to indicate the commit config success.'); 4423 }).catch((err: BusinessError) => { 4424 // If the operation fails, error.code is returned and processed. 4425 let err = error as BusinessError; 4426 console.error(`The commitConfig call failed. error code: ${err.code}`); 4427 }); 4428} 4429``` 4430 4431### canAddInput<sup>11+</sup> 4432 4433canAddInput(cameraInput: CameraInput): boolean 4434 4435Determines whether a **CameraInput** instance can be added to this session. This API must be called after [beginConfig](#beginconfig) and before [commitConfig](#commitconfig). 4436 4437**System capability**: SystemCapability.Multimedia.Camera.Core 4438 4439**Parameters** 4440 4441| Name | Type | Mandatory| Description | 4442| ----------- | --------------------------- | ---- | ------------------------ | 4443| cameraInput | [CameraInput](#camerainput) | Yes | **CameraInput** instance to add.| 4444 4445**Return value** 4446 4447| Type | Description | 4448| -------------- | ------------------------ | 4449| boolean | **true**: The **CameraInput** instance can be added.<br>**false**: The **CameraInput** instance cannot be added.| 4450 4451**Example** 4452 4453```ts 4454import { BusinessError } from '@ohos.base'; 4455 4456function canAddInput(captureSession: camera.CaptureSession, cameraInput: camera.CameraInput): void { 4457 let canAdd: boolean = captureSession.canAddInput(cameraInput); 4458 console.info(`The input canAddInput: ${canAdd}`); 4459} 4460``` 4461 4462### addInput 4463 4464addInput(cameraInput: CameraInput): void 4465 4466Adds a [CameraInput](#camerainput) instance to this session. 4467 4468**System capability**: SystemCapability.Multimedia.Camera.Core 4469 4470**Parameters** 4471 4472| Name | Type | Mandatory| Description | 4473| ----------- | --------------------------- | ---- | ------------------------ | 4474| cameraInput | [CameraInput](#camerainput) | Yes | **CameraInput** instance to add.| 4475 4476**Error codes** 4477 4478For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 4479 4480| ID | Error Message | 4481| --------------- | --------------- | 4482| 7400101 | Parameter missing or parameter type incorrect. | 4483| 7400102 | Operation not allow. | 4484| 7400103 | Session not config. | 4485 4486**Example** 4487 4488```ts 4489import { BusinessError } from '@ohos.base'; 4490 4491function addInput(captureSession: camera.CaptureSession, cameraInput: camera.CameraInput): void { 4492 try { 4493 captureSession.addInput(cameraInput); 4494 } catch (error) { 4495 // If the operation fails, error.code is returned and processed. 4496 let err = error as BusinessError; 4497 console.error(`The addInput call failed. error code: ${err.code}`); 4498 } 4499} 4500``` 4501 4502### removeInput 4503 4504removeInput(cameraInput: CameraInput): void 4505 4506Removes a [CameraInput](#camerainput) instance from this session. This API must be called after [beginConfig](#beginconfig) and before [commitConfig](#commitconfig). 4507 4508**System capability**: SystemCapability.Multimedia.Camera.Core 4509 4510**Parameters** 4511 4512| Name | Type | Mandatory| Description | 4513| ----------- | --------------------------- | ---- | ------------------------ | 4514| cameraInput | [CameraInput](#camerainput) | Yes | **CameraInput** instance to remove.| 4515 4516**Error codes** 4517 4518For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 4519 4520| ID | Error Message | 4521| --------------- | --------------- | 4522| 7400101 | Parameter missing or parameter type incorrect. | 4523| 7400102 | Operation not allow. | 4524| 7400103 | Session not config. | 4525 4526**Example** 4527 4528```ts 4529import { BusinessError } from '@ohos.base'; 4530 4531function removeInput(captureSession: camera.CaptureSession, cameraInput: camera.CameraInput): void { 4532 try { 4533 captureSession.removeInput(cameraInput); 4534 } catch (error) { 4535 // If the operation fails, error.code is returned and processed. 4536 let err = error as BusinessError; 4537 console.error(`The removeInput call failed. error code: ${err.code}`); 4538 } 4539} 4540``` 4541 4542### canAddOutput<sup>11+</sup> 4543 4544canAddOutput(cameraOutput: CameraOutput): boolean 4545 4546Determines whether a **CameraOutput** instance can be added to this session. This API must be called after [addInput](#addinput) and before [commitConfig](#commitconfig). 4547 4548**System capability**: SystemCapability.Multimedia.Camera.Core 4549 4550**Parameters** 4551 4552| Name | Type | Mandatory| Description | 4553| ----------- | --------------------------- | ---- | ------------------------ | 4554| cameraOutput | [CameraOutput](#cameraoutput) | Yes | **CameraOutput** instance to add.| 4555 4556**Return value** 4557 4558| Type | Description | 4559| -------------- | ------------------------ | 4560| boolean | **true**: The **CameraOutput** instance can be added.<br>**false**: The **CameraOutput** instance cannot be added.| 4561 4562**Example** 4563 4564```ts 4565import { BusinessError } from '@ohos.base'; 4566 4567function canAddOutput(captureSession: camera.CaptureSession, cameraOutput: camera.CameraOutput): void { 4568 let canAdd: boolean = captureSession.canAddOutput(cameraOutput); 4569 console.info(`This addOutput can add: ${canAdd}`); 4570} 4571``` 4572 4573### addOutput 4574 4575addOutput(cameraOutput: CameraOutput): void 4576 4577Adds a [CameraOutput](#cameraoutput) instance to this session. 4578 4579**System capability**: SystemCapability.Multimedia.Camera.Core 4580 4581**Parameters** 4582 4583| Name | Type | Mandatory| Description | 4584| ------------- | ------------------------------- | ---- | ------------------------ | 4585| cameraOutput | [CameraOutput](#cameraoutput) | Yes | **CameraOutput** instance to add.| 4586 4587**Error codes** 4588 4589For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 4590 4591| ID | Error Message | 4592| --------------- | --------------- | 4593| 7400101 | Parameter missing or parameter type incorrect. | 4594| 7400102 | Operation not allow. | 4595| 7400103 | Session not config. | 4596 4597**Example** 4598 4599```ts 4600import { BusinessError } from '@ohos.base'; 4601 4602function addOutput(captureSession: camera.CaptureSession, cameraOutput: camera.CameraOutput): void { 4603 try { 4604 captureSession.addOutput(cameraOutput); 4605 } catch (error) { 4606 // If the operation fails, error.code is returned and processed. 4607 let err = error as BusinessError; 4608 console.error(`The addOutput call failed. error code: ${err.code}`); 4609 } 4610} 4611``` 4612 4613### removeOutput 4614 4615removeOutput(cameraOutput: CameraOutput): void 4616 4617Removes a [CameraOutput](#cameraoutput) instance from this session. 4618 4619**System capability**: SystemCapability.Multimedia.Camera.Core 4620 4621**Parameters** 4622 4623| Name | Type | Mandatory| Description | 4624| ------------- | ------------------------------- | ---- | ------------------------ | 4625| cameraOutput | [CameraOutput](#cameraoutput) | Yes | **CameraOutput** instance to remove.| 4626 4627**Error codes** 4628 4629For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 4630 4631| ID | Error Message | 4632| --------------- | --------------- | 4633| 7400101 | Parameter missing or parameter type incorrect. | 4634| 7400102 | Operation not allow. | 4635| 7400103 | Session not config. | 4636 4637**Example** 4638 4639```ts 4640import { BusinessError } from '@ohos.base'; 4641 4642function removeOutput(captureSession: camera.CaptureSession, previewOutput: camera.PreviewOutput): void { 4643 try { 4644 captureSession.removeOutput(previewOutput); 4645 } catch (error) { 4646 // If the operation fails, error.code is returned and processed. 4647 let err = error as BusinessError; 4648 console.error(`The removeOutput call failed. error code: ${err.code}`); 4649 } 4650} 4651``` 4652 4653### start 4654 4655start(callback: AsyncCallback\<void\>): void 4656 4657Starts this session. This API uses an asynchronous callback to return the result. 4658 4659**System capability**: SystemCapability.Multimedia.Camera.Core 4660 4661**Parameters** 4662 4663| Name | Type | Mandatory| Description | 4664| -------- | -------------------- | ---- | -------------------- | 4665| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 4666 4667**Error codes** 4668 4669For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 4670 4671| ID | Error Message | 4672| --------------- | --------------- | 4673| 7400103 | Session not config. | 4674| 7400201 | Camera service fatal error. | 4675 4676**Example** 4677 4678```ts 4679import { BusinessError } from '@ohos.base'; 4680 4681function startCaptureSession(captureSession: camera.CaptureSession): void { 4682 captureSession.start((err: BusinessError) => { 4683 if (err) { 4684 console.error(`Failed to start the session, error code: ${err.code}.`); 4685 return; 4686 } 4687 console.info('Callback invoked to indicate the session start success.'); 4688 }); 4689} 4690``` 4691 4692### start 4693 4694start(): Promise\<void\> 4695 4696Starts this session. This API uses a promise to return the result. 4697 4698**System capability**: SystemCapability.Multimedia.Camera.Core 4699 4700**Return value** 4701 4702| Type | Description | 4703| -------------- | ------------------------ | 4704| Promise\<void\> | Promise used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 4705 4706**Error codes** 4707 4708For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 4709 4710| ID | Error Message | 4711| --------------- | --------------- | 4712| 7400103 | Session not config. | 4713| 7400201 | Camera service fatal error. | 4714 4715**Example** 4716 4717```ts 4718import { BusinessError } from '@ohos.base'; 4719 4720function startCaptureSession(captureSession: camera.CaptureSession): void { 4721 captureSession.start().then(() => { 4722 console.info('Promise returned to indicate the session start success.'); 4723 }).catch((err: BusinessError) => { 4724 let err = error as BusinessError; 4725 console.error(`Failed to start the session, error code: ${err.code}.`); 4726 }); 4727} 4728``` 4729 4730### stop 4731 4732stop(callback: AsyncCallback\<void\>): void 4733 4734Stops this session. This API uses an asynchronous callback to return the result. 4735 4736**System capability**: SystemCapability.Multimedia.Camera.Core 4737 4738**Parameters** 4739 4740| Name | Type | Mandatory| Description | 4741| -------- | -------------------- | ---- | ------------------- | 4742| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 4743 4744**Error codes** 4745 4746For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 4747 4748| ID | Error Message | 4749| --------------- | --------------- | 4750| 7400201 | Camera service fatal error. | 4751 4752**Example** 4753 4754```ts 4755import { BusinessError } from '@ohos.base'; 4756 4757function stopCaptureSession(captureSession: camera.CaptureSession): void { 4758 captureSession.stop((err: BusinessError) => { 4759 if (err) { 4760 console.error(`Failed to stop the session, error code: ${err.code}.`); 4761 return; 4762 } 4763 console.info('Callback invoked to indicate the session stop success.'); 4764 }); 4765} 4766``` 4767 4768### stop 4769 4770stop(): Promise\<void\> 4771 4772Stops this session. This API uses a promise to return the result. 4773 4774**System capability**: SystemCapability.Multimedia.Camera.Core 4775 4776**Return value** 4777 4778| Type | Description | 4779| -------------- | ----------------------- | 4780| Promise\<void\> | Promise used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 4781 4782**Error codes** 4783 4784For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 4785 4786| ID | Error Message | 4787| --------------- | --------------- | 4788| 7400201 | Camera service fatal error. | 4789 4790**Example** 4791 4792```ts 4793import { BusinessError } from '@ohos.base'; 4794 4795function stopCaptureSession(captureSession: camera.CaptureSession): void { 4796 captureSession.stop().then(() => { 4797 console.info('Promise returned to indicate the session stop success.'); 4798 }).catch((err: BusinessError) => { 4799 let err = error as BusinessError; 4800 console.error(`Failed to stop the session, error code: ${err.code}.`); 4801 }); 4802} 4803``` 4804 4805### release 4806 4807release(callback: AsyncCallback\<void\>): void 4808 4809Releases this session. This API uses an asynchronous callback to return the result. 4810 4811**System capability**: SystemCapability.Multimedia.Camera.Core 4812 4813**Parameters** 4814 4815| Name | Type | Mandatory| Description | 4816| -------- | -------------------- | ---- | -------------------- | 4817| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 4818 4819**Error codes** 4820 4821For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 4822 4823| ID | Error Message | 4824| --------------- | --------------- | 4825| 7400201 | Camera service fatal error. | 4826 4827**Example** 4828 4829```ts 4830import { BusinessError } from '@ohos.base'; 4831 4832function releaseCaptureSession(captureSession: camera.CaptureSession): void { 4833 captureSession.release((err: BusinessError) => { 4834 if (err) { 4835 console.error(`Failed to release the CaptureSession instance, error code: ${err.code}.`); 4836 return; 4837 } 4838 console.info('Callback invoked to indicate that the CaptureSession instance is released successfully.'); 4839 }); 4840} 4841``` 4842 4843### release 4844 4845release(): Promise\<void\> 4846 4847Releases this session. This API uses a promise to return the result. 4848 4849**System capability**: SystemCapability.Multimedia.Camera.Core 4850 4851**Return value** 4852 4853| Type | Description | 4854| -------------- | ------------------------ | 4855| Promise\<void\> | Promise used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 4856 4857**Error codes** 4858 4859For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 4860 4861| ID | Error Message | 4862| --------------- | --------------- | 4863| 7400201 | Camera service fatal error. | 4864 4865**Example** 4866 4867```ts 4868import { BusinessError } from '@ohos.base'; 4869 4870function releaseCaptureSession(captureSession: camera.CaptureSession): void { 4871 captureSession.release().then(() => { 4872 console.info('Promise returned to indicate that the CaptureSession instance is released successfully.'); 4873 }).catch((err: BusinessError) => { 4874 let err = error as BusinessError; 4875 console.error(`Failed to release the CaptureSession instance, error code: ${err.code}.`); 4876 }); 4877} 4878``` 4879 4880## Flash<sup>11+</sup> 4881 4882Provides APIs related to the flash. 4883 4884### hasFlash 4885 4886hasFlash(): boolean 4887 4888Checks whether the camera device has flash. This API uses an asynchronous callback to return the result. 4889 4890**System capability**: SystemCapability.Multimedia.Camera.Core 4891 4892**Return value** 4893 4894| Type | Description | 4895| ---------- | ----------------------------- | 4896| boolean | **true**: The camera device has flash.<br>**false**: The camera device does not have flash. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 4897 4898**Error codes** 4899 4900For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 4901 4902| ID | Error Message | 4903| --------------- | --------------- | 4904| 7400103 | Session not config. | 4905 4906**Example** 4907 4908```ts 4909import { BusinessError } from '@ohos.base'; 4910 4911function hasFlash(captureSession: camera.CaptureSession): boolean { 4912 let status: boolean = false; 4913 try { 4914 status = captureSession.hasFlash(); 4915 } catch (error) { 4916 // If the operation fails, error.code is returned and processed. 4917 let err = error as BusinessError; 4918 console.error(`The hasFlash call failed. error code: ${err.code}`); 4919 } 4920 return status; 4921} 4922``` 4923 4924### isFlashModeSupported 4925 4926isFlashModeSupported(flashMode: FlashMode): boolean 4927 4928Checks whether a flash mode is supported. 4929 4930**System capability**: SystemCapability.Multimedia.Camera.Core 4931 4932**Parameters** 4933 4934| Name | Type | Mandatory| Description | 4935| --------- | ----------------------- | ---- | --------------------------------- | 4936| flashMode | [FlashMode](#flashmode) | Yes | Flash mode. | 4937 4938**Return value** 4939 4940| Type | Description | 4941| ---------- | ----------------------------- | 4942| boolean | **true**: The flash mode is supported.<br>**false**: The flash mode is not supported. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 4943 4944**Error codes** 4945 4946For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 4947 4948| ID | Error Message | 4949| --------------- | --------------- | 4950| 7400103 | Session not config. | 4951 4952**Example** 4953 4954```ts 4955import { BusinessError } from '@ohos.base'; 4956 4957function isFlashModeSupported(captureSession: camera.CaptureSession): boolean { 4958 let status: boolean = false; 4959 try { 4960 status = captureSession.isFlashModeSupported(camera.FlashMode.FLASH_MODE_AUTO); 4961 } catch (error) { 4962 // If the operation fails, error.code is returned and processed. 4963 let err = error as BusinessError; 4964 console.error(`The isFlashModeSupported call failed. error code: ${err.code}`); 4965 } 4966 return status; 4967} 4968``` 4969 4970### setFlashMode 4971 4972setFlashMode(flashMode: FlashMode): void 4973 4974Sets a flash mode. 4975 4976Before the setting, do the following checks: 4977 49781. Use [hasFlash](#hasflash) to check whether the camera device has flash. 49792. Use [isFlashModeSupported](#isflashmodesupported) to check whether the camera device supports the flash mode. 4980 4981**System capability**: SystemCapability.Multimedia.Camera.Core 4982 4983**Parameters** 4984 4985| Name | Type | Mandatory| Description | 4986| --------- | ----------------------- | ---- | --------------------- | 4987| flashMode | [FlashMode](#flashmode) | Yes | Flash mode. | 4988 4989**Error codes** 4990 4991For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 4992 4993| ID | Error Message | 4994| --------------- | --------------- | 4995| 7400103 | Session not config. | 4996 4997**Example** 4998 4999```ts 5000import { BusinessError } from '@ohos.base'; 5001 5002function setFlashMode(captureSession: camera.CaptureSession): void { 5003 try { 5004 captureSession.setFlashMode(camera.FlashMode.FLASH_MODE_AUTO); 5005 } catch (error) { 5006 // If the operation fails, error.code is returned and processed. 5007 let err = error as BusinessError; 5008 console.error(`The setFlashMode call failed. error code: ${err.code}`); 5009 } 5010} 5011``` 5012 5013### getFlashMode 5014 5015getFlashMode(): FlashMode 5016 5017Obtains the flash mode in use. 5018 5019**System capability**: SystemCapability.Multimedia.Camera.Core 5020 5021**Return value** 5022 5023| Type | Description | 5024| ---------- | ----------------------------- | 5025| [FlashMode](#flashmode) | Flash mode obtained. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 5026 5027**Error codes** 5028 5029For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 5030 5031| ID | Error Message | 5032| --------------- | --------------- | 5033| 7400103 | Session not config. | 5034 5035**Example** 5036 5037```ts 5038import { BusinessError } from '@ohos.base'; 5039 5040function getFlashMode(captureSession: camera.CaptureSession): camera.FlashMode | undefined { 5041 let flashMode: camera.FlashMode | undefined = undefined; 5042 try { 5043 flashMode = captureSession.getFlashMode(); 5044 } catch (error) { 5045 // If the operation fails, error.code is returned and processed. 5046 let err = error as BusinessError; 5047 console.error(`The getFlashMode call failed.error code: ${err.code}`); 5048 } 5049 return flashMode; 5050} 5051``` 5052 5053## AutoExposure<sup>11+</sup> 5054 5055Provides APIs related to auto exposure. 5056 5057### isExposureModeSupported 5058 5059isExposureModeSupported(aeMode: ExposureMode): boolean 5060 5061Checks whether an exposure mode is supported. 5062 5063**System capability**: SystemCapability.Multimedia.Camera.Core 5064 5065**Parameters** 5066 5067| Name | Type | Mandatory | Description | 5068| -------- | -------------------------------| ---- | ----------------------------- | 5069| aeMode | [ExposureMode](#exposuremode) | Yes | Exposure mode. | 5070 5071**Return value** 5072 5073| Type | Description | 5074| ---------- | ----------------------------- | 5075| boolean | **true**: The exposure mode is supported.<br>**false**: The exposure mode is not supported. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 5076 5077**Error codes** 5078 5079For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 5080 5081| ID | Error Message | 5082| --------------- | --------------- | 5083| 7400103 | Session not config. | 5084 5085**Example** 5086 5087```ts 5088import { BusinessError } from '@ohos.base'; 5089 5090function isExposureModeSupported(captureSession: camera.CaptureSession): boolean { 5091 let isSupported: boolean = false; 5092 try { 5093 isSupported = captureSession.isExposureModeSupported(camera.ExposureMode.EXPOSURE_MODE_LOCKED); 5094 } catch (error) { 5095 // If the operation fails, error.code is returned and processed. 5096 let err = error as BusinessError; 5097 console.error(`The isExposureModeSupported call failed. error code: ${err.code}`); 5098 } 5099 return isSupported; 5100} 5101``` 5102 5103### getExposureMode 5104 5105getExposureMode(): ExposureMode 5106 5107Obtains the exposure mode in use. 5108 5109**System capability**: SystemCapability.Multimedia.Camera.Core 5110 5111**Return value** 5112 5113| Type | Description | 5114| ---------- | ----------------------------- | 5115| [ExposureMode](#exposuremode) | Exposure mode obtained. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 5116 5117**Error codes** 5118 5119For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 5120 5121| ID | Error Message | 5122| --------------- | --------------- | 5123| 7400103 | Session not config. | 5124 5125**Example** 5126 5127```ts 5128import { BusinessError } from '@ohos.base'; 5129 5130function getExposureMode(captureSession: camera.CaptureSession): camera.ExposureMode | undefined { 5131 let exposureMode: camera.ExposureMode | undefined = undefined; 5132 try { 5133 exposureMode = captureSession.getExposureMode(); 5134 } catch (error) { 5135 // If the operation fails, error.code is returned and processed. 5136 let err = error as BusinessError; 5137 console.error(`The getExposureMode call failed. error code: ${err.code}`); 5138 } 5139 return exposureMode; 5140} 5141``` 5142 5143### setExposureMode 5144 5145setExposureMode(aeMode: ExposureMode): void 5146 5147Sets an exposure mode. Before the setting, use [isExposureModeSupported](#isexposuremodesupported) to check whether the target exposure mode is supported. 5148 5149**System capability**: SystemCapability.Multimedia.Camera.Core 5150 5151**Parameters** 5152 5153| Name | Type | Mandatory| Description | 5154| -------- | -------------------------------| ---- | ----------------------- | 5155| aeMode | [ExposureMode](#exposuremode) | Yes | Exposure mode. | 5156 5157**Error codes** 5158 5159For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 5160 5161| ID | Error Message | 5162| --------------- | --------------- | 5163| 7400103 | Session not config. | 5164 5165**Example** 5166 5167```ts 5168import { BusinessError } from '@ohos.base'; 5169 5170function setExposureMode(captureSession: camera.CaptureSession): void { 5171 try { 5172 captureSession.setExposureMode(camera.ExposureMode.EXPOSURE_MODE_LOCKED); 5173 } catch (error) { 5174 // If the operation fails, error.code is returned and processed. 5175 let err = error as BusinessError; 5176 console.error(`The setExposureMode call failed. error code: ${err.code}`); 5177 } 5178} 5179``` 5180 5181### getMeteringPoint 5182 5183getMeteringPoint(): Point 5184 5185Obtains the metering point of the camera device. 5186 5187**System capability**: SystemCapability.Multimedia.Camera.Core 5188 5189**Return value** 5190 5191| Type | Description | 5192| ---------- | ----------------------------- | 5193| [Point](#point) | Metering point obtained. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 5194 5195**Error codes** 5196 5197For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 5198 5199| ID | Error Message | 5200| --------------- | --------------- | 5201| 7400103 | Session not config. | 5202 5203**Example** 5204 5205```ts 5206import { BusinessError } from '@ohos.base'; 5207 5208function getMeteringPoint(captureSession: camera.CaptureSession): camera.Point | undefined { 5209 let exposurePoint: camera.Point | undefined = undefined; 5210 try { 5211 exposurePoint = captureSession.getMeteringPoint(); 5212 } catch (error) { 5213 // If the operation fails, error.code is returned and processed. 5214 let err = error as BusinessError; 5215 console.error(`The getMeteringPoint call failed. error code: ${err.code}`); 5216 } 5217 return exposurePoint; 5218} 5219``` 5220 5221### setMeteringPoint 5222 5223setMeteringPoint(point: Point): void 5224 5225Sets the metering point, which is the center point of the metering rectangle. The metering point must be in the coordinate system (0-1), where the upper left corner is {0, 0} and the lower right corner is {1, 1}.<br>The coordinate system is based on the horizontal device direction with the device's charging port on the right. If the layout of the preview screen of an application is<br>based on the vertical direction with the charging port on the lower side, the layout width and height are {w, h}, and the touch point is {x, y},<br>then the coordinate point after conversion is {y/h, 1-x/w}. 5226 5227**System capability**: SystemCapability.Multimedia.Camera.Core 5228 5229**Parameters** 5230 5231| Name | Type | Mandatory| Description | 5232| ------------- | -------------------------------| ---- | ------------------- | 5233| exposurePoint | [Point](#point) | Yes | Metering point. The value range of x and y must be within [0, 1]. If a value less than 0 is passed, the value **0** is used. If a value greater than **1** is passed, the value **1** is used. | 5234 5235**Error codes** 5236 5237For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 5238 5239| ID | Error Message | 5240| --------------- | --------------- | 5241| 7400103 | Session not config. | 5242 5243**Example** 5244 5245```ts 5246import { BusinessError } from '@ohos.base'; 5247 5248function setMeteringPoint(captureSession: camera.CaptureSession): void { 5249 const exposurePoint: camera.Point = {x: 1, y: 1}; 5250 try { 5251 captureSession.setMeteringPoint(exposurePoint); 5252 } catch (error) { 5253 // If the operation fails, error.code is returned and processed. 5254 let err = error as BusinessError; 5255 console.error(`The setMeteringPoint call failed. error code: ${err.code}`); 5256 } 5257} 5258``` 5259 5260### getExposureBiasRange 5261 5262getExposureBiasRange(): Array\<number\> 5263 5264Obtains the exposure compensation values of the camera device. 5265 5266**System capability**: SystemCapability.Multimedia.Camera.Core 5267 5268**Return value** 5269 5270| Type | Description | 5271| ---------- | ----------------------------- | 5272| Array\<number\> | Array of compensation values. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 5273 5274**Error codes** 5275 5276For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 5277 5278| ID | Error Message | 5279| --------------- | --------------- | 5280| 7400103 | Session not config. | 5281 5282**Example** 5283 5284```ts 5285import { BusinessError } from '@ohos.base'; 5286 5287function getExposureBiasRange(captureSession: camera.CaptureSession): Array<number> { 5288 let biasRangeArray: Array<number> = []; 5289 try { 5290 biasRangeArray = captureSession.getExposureBiasRange(); 5291 } catch (error) { 5292 // If the operation fails, error.code is returned and processed. 5293 let err = error as BusinessError; 5294 console.error(`The getExposureBiasRange call failed. error code: ${err.code}`); 5295 } 5296 return biasRangeArray; 5297} 5298``` 5299 5300### setExposureBias 5301 5302setExposureBias(exposureBias: number): void 5303 5304Sets an exposure compensation value (EV). 5305 5306Before the setting, you are advised to use [getExposureBiasRange](#getexposurebiasrange) to obtain the supported values. 5307 5308**System capability**: SystemCapability.Multimedia.Camera.Core 5309 5310**Parameters** 5311 5312| Name | Type | Mandatory| Description | 5313| -------- | -------------------------------| ---- | ------------------- | 5314| exposureBias | number | Yes | EV. The supported EV range can be obtained by calling [getExposureBiasRange](#getexposurebiasrange). If the value passed is not within the supported range, the nearest critical point is used.<br>There is a step for EV. For example, if the step is 0.5 and this parameter is set to 1.2, the EV that takes effect is 1.0.<br>If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 5315 5316**Error codes** 5317 5318For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 5319 5320| ID | Error Message | 5321| --------------- | --------------- | 5322| 7400103 | Session not config. | 5323 5324**Example** 5325 5326```ts 5327import { BusinessError } from '@ohos.base'; 5328 5329function setExposureBias(captureSession: camera.CaptureSession, biasRangeArray: Array<number>): void { 5330 if (biasRangeArray && biasRangeArray.length > 0) { 5331 let exposureBias = biasRangeArray[0]; 5332 try { 5333 captureSession.setExposureBias(exposureBias); 5334 } catch (error) { 5335 // If the operation fails, error.code is returned and processed. 5336 let err = error as BusinessError; 5337 console.error(`The setExposureBias call failed. error code: ${err.code}`); 5338 } 5339 } 5340} 5341``` 5342 5343### getExposureValue 5344 5345getExposureValue(): number 5346 5347Obtains the exposure value in use. 5348 5349**System capability**: SystemCapability.Multimedia.Camera.Core 5350 5351**Return value** 5352 5353| Type | Description | 5354| ---------- | ----------------------------- | 5355| number | Exposure value obtained. There is a step for EV. For example, if the step is 0.5 and this parameter is set to 1.2, the EV that takes effect is 1.0.<br>If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 5356 5357**Error codes** 5358 5359For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 5360 5361| ID | Error Message | 5362| --------------- | --------------- | 5363| 7400103 | Session not config. | 5364 5365**Example** 5366 5367```ts 5368import { BusinessError } from '@ohos.base'; 5369 5370function getExposureValue(captureSession: camera.CaptureSession): number { 5371 const invalidValue: number = -1; 5372 let exposureValue: number = invalidValue; 5373 try { 5374 exposureValue = captureSession.getExposureValue(); 5375 } catch (error) { 5376 // If the operation fails, error.code is returned and processed. 5377 let err = error as BusinessError; 5378 console.error(`The getExposureValue call failed. error code: ${err.code}`); 5379 } 5380 return exposureValue; 5381} 5382``` 5383 5384## Focus<sup>11+</sup> 5385 5386Provides APIs related to focus operations. 5387 5388### isFocusModeSupported 5389 5390isFocusModeSupported(afMode: FocusMode): boolean 5391 5392Checks whether a focus mode is supported. 5393 5394**System capability**: SystemCapability.Multimedia.Camera.Core 5395 5396**Parameters** 5397 5398| Name | Type | Mandatory| Description | 5399| -------- | ----------------------- | ---- | -------------------------------- | 5400| afMode | [FocusMode](#focusmode) | Yes | Focus mode. | 5401 5402**Return value** 5403 5404| Type | Description | 5405| ---------- | ----------------------------- | 5406| boolean | **true**: The focus mode is supported.<br>**false**: The focus mode is not supported. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 5407 5408**Error codes** 5409 5410For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 5411 5412| ID | Error Message | 5413| --------------- | --------------- | 5414| 7400103 | Session not config. | 5415 5416**Example** 5417 5418```ts 5419import { BusinessError } from '@ohos.base'; 5420 5421function isFocusModeSupported(captureSession: camera.CaptureSession): boolean { 5422 let status: boolean = false; 5423 try { 5424 status = captureSession.isFocusModeSupported(camera.FocusMode.FOCUS_MODE_AUTO); 5425 } catch (error) { 5426 // If the operation fails, error.code is returned and processed. 5427 let err = error as BusinessError; 5428 console.error(`The isFocusModeSupported call failed. error code: ${err.code}`); 5429 } 5430 return status; 5431} 5432``` 5433 5434### setFocusMode 5435 5436setFocusMode(afMode: FocusMode): void 5437 5438Sets a focus mode. 5439 5440Before the setting, use [isFocusModeSupported](#isfocusmodesupported) to check whether the focus mode is supported. 5441 5442**System capability**: SystemCapability.Multimedia.Camera.Core 5443 5444**Parameters** 5445 5446| Name | Type | Mandatory| Description | 5447| -------- | ----------------------- | ---- | ------------------- | 5448| afMode | [FocusMode](#focusmode) | Yes | Focus mode. | 5449 5450**Error codes** 5451 5452For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 5453 5454| ID | Error Message | 5455| --------------- | --------------- | 5456| 7400103 | Session not config. | 5457 5458**Example** 5459 5460```ts 5461import { BusinessError } from '@ohos.base'; 5462 5463function setFocusMode(captureSession: camera.CaptureSession): void { 5464 try { 5465 captureSession.setFocusMode(camera.FocusMode.FOCUS_MODE_AUTO); 5466 } catch (error) { 5467 // If the operation fails, error.code is returned and processed. 5468 let err = error as BusinessError; 5469 console.error(`The setFocusMode call failed. error code: ${err.code}`); 5470 } 5471} 5472``` 5473 5474### getFocusMode 5475 5476getFocusMode(): FocusMode 5477 5478Obtains the focus mode in use. 5479 5480**System capability**: SystemCapability.Multimedia.Camera.Core 5481 5482**Return value** 5483 5484| Type | Description | 5485| ---------- | ----------------------------- | 5486| [FocusMode](#focusmode) | Focus mode obtained. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 5487 5488**Error codes** 5489 5490For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 5491 5492| ID | Error Message | 5493| --------------- | --------------- | 5494| 7400103 | Session not config. | 5495 5496**Example** 5497 5498```ts 5499import { BusinessError } from '@ohos.base'; 5500 5501function getFocusMode(captureSession: camera.CaptureSession): camera.FocusMode | undefined { 5502 let afMode: camera.FocusMode | undefined = undefined; 5503 try { 5504 afMode = captureSession.getFocusMode(); 5505 } catch (error) { 5506 // If the operation fails, error.code is returned and processed. 5507 let err = error as BusinessError; 5508 console.error(`The getFocusMode call failed. error code: ${err.code}`); 5509 } 5510 return afMode; 5511} 5512``` 5513 5514### setFocusPoint 5515 5516setFocusPoint(point: Point): void 5517 5518Sets the focal point. The focal point must be in the coordinate system (0-1), where the upper left corner is {0, 0} and the lower right corner is {1, 1}.<br>The coordinate system is based on the horizontal device direction with the device's charging port on the right. If the layout of the preview screen of an application is<br>based on the vertical direction with the charging port on the lower side, the layout width and height are {w, h}, and the touch point is {x, y},<br>then the coordinate point after conversion is {y/h, 1-x/w}. 5519 5520**System capability**: SystemCapability.Multimedia.Camera.Core 5521 5522**Parameters** 5523 5524| Name | Type | Mandatory| Description | 5525| -------- | ----------------------- | ---- | ------------------- | 5526| point | [Point](#point) | Yes | Focal point. The value range of x and y must be within [0, 1]. If a value less than 0 is passed, the value **0** is used. If a value greater than **1** is passed, the value **1** is used. | 5527 5528**Error codes** 5529 5530For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 5531 5532| ID | Error Message | 5533| --------------- | --------------- | 5534| 7400103 | Session not config. | 5535 5536**Example** 5537 5538```ts 5539import { BusinessError } from '@ohos.base'; 5540 5541function setFocusPoint(captureSession: camera.CaptureSession): void { 5542 const focusPoint: camera.Point = {x: 1, y: 1}; 5543 try { 5544 captureSession.setFocusPoint(focusPoint); 5545 } catch (error) { 5546 // If the operation fails, error.code is returned and processed. 5547 let err = error as BusinessError; 5548 console.error(`The setFocusPoint call failed. error code: ${err.code}`); 5549 } 5550} 5551``` 5552 5553### getFocusPoint 5554 5555getFocusPoint(): Point 5556 5557Obtains the focal point of the camera device. 5558 5559**System capability**: SystemCapability.Multimedia.Camera.Core 5560 5561**Return value** 5562 5563| Type | Description | 5564| ---------- | ----------------------------- | 5565| [Point](#point) | Focal point obtained. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 5566 5567**Error codes** 5568 5569For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 5570 5571| ID | Error Message | 5572| --------------- | --------------- | 5573| 7400103 | Session not config. | 5574 5575**Example** 5576 5577```ts 5578import { BusinessError } from '@ohos.base'; 5579 5580function getFocusPoint(captureSession: camera.CaptureSession): camera.Point | undefined { 5581 let point: camera.Point | undefined = undefined; 5582 try { 5583 point = captureSession.getFocusPoint(); 5584 } catch (error) { 5585 // If the operation fails, error.code is returned and processed. 5586 let err = error as BusinessError; 5587 console.error(`The getFocusPoint call failed. error code: ${err.code}`); 5588 } 5589 return point; 5590} 5591``` 5592 5593### getFocalLength 5594 5595getFocalLength(): number 5596 5597Obtains the focal length of the camera device. 5598 5599**System capability**: SystemCapability.Multimedia.Camera.Core 5600 5601**Return value** 5602 5603| Type | Description | 5604| ---------- | ----------------------------- | 5605| number | Focal length, in mm. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 5606 5607**Error codes** 5608 5609For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 5610 5611| ID | Error Message | 5612| --------------- | --------------- | 5613| 7400103 | Session not config. | 5614 5615**Example** 5616 5617```ts 5618import { BusinessError } from '@ohos.base'; 5619 5620function getFocalLength(captureSession: camera.CaptureSession): number { 5621 const invalidValue: number = -1; 5622 let focalLength: number = invalidValue; 5623 try { 5624 focalLength = captureSession.getFocalLength(); 5625 } catch (error) { 5626 // If the operation fails, error.code is returned and processed. 5627 let err = error as BusinessError; 5628 console.error(`The getFocalLength call failed. error code: ${err.code}`); 5629 } 5630 return focalLength; 5631} 5632``` 5633 5634## SmoothZoomMode<sup>11+</sup> 5635 5636Enumerates the smooth zoom modes. 5637 5638**System capability**: SystemCapability.Multimedia.Camera.Core 5639 5640| Name | Value | Description | 5641| ------------ | ---- | -------------- | 5642| NORMAL | 0 | Bessel curve mode. | 5643 5644## SmoothZoomInfo<sup>11+</sup> 5645 5646Defines the smooth zoom information. 5647 5648**System capability**: SystemCapability.Multimedia.Camera.Core 5649 5650| Name| Type | Mandatory | Description | 5651| -------- | ---------- | -------- | ---------- | 5652| duration | number | Yes | Total duration of smooth zoom, in ms.| 5653 5654## Zoom<sup>11+</sup> 5655 5656Provides APIs related to zoom operations. 5657 5658### getZoomRatioRange 5659 5660getZoomRatioRange(): Array\<number\> 5661 5662Obtains the supported zoom ratio range. 5663 5664**System capability**: SystemCapability.Multimedia.Camera.Core 5665 5666**Return value** 5667 5668| Type | Description | 5669| ---------- | ----------------------------- | 5670| Array\<number\> | Callback used to return an array containing the minimum and maximum zoom ratios. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 5671 5672**Error codes** 5673 5674For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 5675 5676| ID | Error Message | 5677| --------------- | --------------- | 5678| 7400103 | Session not config. | 5679 5680**Example** 5681 5682```ts 5683import { BusinessError } from '@ohos.base'; 5684 5685function getZoomRatioRange(captureSession: camera.CaptureSession): Array<number> { 5686 let zoomRatioRange: Array<number> = []; 5687 try { 5688 zoomRatioRange = captureSession.getZoomRatioRange(); 5689 } catch (error) { 5690 // If the operation fails, error.code is returned and processed. 5691 let err = error as BusinessError; 5692 console.error(`The getZoomRatioRange call failed. error code: ${err.code}`); 5693 } 5694 return zoomRatioRange; 5695} 5696``` 5697 5698### setZoomRatio 5699 5700setZoomRatio(zoomRatio: number): void 5701 5702Sets a zoom ratio, with a maximum precision of two decimal places. 5703 5704**System capability**: SystemCapability.Multimedia.Camera.Core 5705 5706**Parameters** 5707 5708| Name | Type | Mandatory| Description | 5709| --------- | -------------------- | ---- | ------------------- | 5710| zoomRatio | number | Yes | Zoom ratio. The supported zoom ratio range can be obtained by calling [getZoomRatioRange](#getzoomratiorange). If the value passed in is not within the supported range, the value within the precision range is retained.| 5711 5712**Error codes** 5713 5714For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 5715 5716| ID | Error Message | 5717| --------------- | --------------- | 5718| 7400103 | Session not config. | 5719 5720**Example** 5721 5722```ts 5723import { BusinessError } from '@ohos.base'; 5724 5725function setZoomRatio(captureSession: camera.CaptureSession, zoomRatioRange: Array<number>): void { 5726 if (zoomRatioRange === undefined || zoomRatioRange.length <= 0) { 5727 return; 5728 } 5729 let zoomRatio = zoomRatioRange[0]; 5730 try { 5731 captureSession.setZoomRatio(zoomRatio); 5732 } catch (error) { 5733 // If the operation fails, error.code is returned and processed. 5734 let err = error as BusinessError; 5735 console.error(`The setZoomRatio call failed. error code: ${err.code}`); 5736 } 5737} 5738``` 5739 5740### getZoomRatio 5741 5742getZoomRatio(): number 5743 5744Obtains the zoom ratio in use. 5745 5746**System capability**: SystemCapability.Multimedia.Camera.Core 5747 5748**Return value** 5749 5750| Type | Description | 5751| ---------- | ----------------------------- | 5752| number | Zoom ratio obtained. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 5753 5754**Error codes** 5755 5756For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 5757 5758| ID | Error Message | 5759| --------------- | --------------- | 5760| 7400103 | Session not config. | 5761 5762**Example** 5763 5764```ts 5765import { BusinessError } from '@ohos.base'; 5766 5767function getZoomRatio(captureSession: camera.CaptureSession): number { 5768 const invalidValue: number = -1; 5769 let zoomRatio: number = invalidValue; 5770 try { 5771 zoomRatio = captureSession.getZoomRatio(); 5772 } catch (error) { 5773 // If the operation fails, error.code is returned and processed. 5774 let err = error as BusinessError; 5775 console.error(`The getZoomRatio call failed. error code: ${err.code}`); 5776 } 5777 return zoomRatio; 5778} 5779``` 5780 5781### setSmoothZoom 5782 5783setSmoothZoom(targetRatio: number, mode?: SmoothZoomMode): void 5784 5785Sets smooth zoom. 5786 5787**System capability**: SystemCapability.Multimedia.Camera.Core 5788 5789**Parameters** 5790 5791| Name | Type | Mandatory| Description | 5792| ------------ | -------------- | ---- | ----------------- | 5793| targetRatio | number | Yes | Target zoom ratio. | 5794| mode | SmoothZoomMode | No | Smooth zoom mode. | 5795 5796**Example** 5797 5798```ts 5799import { BusinessError } from '@ohos.base'; 5800 5801function setSmoothZoom(sessionExtendsZoom: camera.Zoom, targetZoomRatio: number, mode: camera.SmoothZoomMode): void { 5802 try { 5803 sessionExtendsZoom.setSmoothZoom(targetZoomRatio, mode); 5804 } catch (error) { 5805 // If the operation fails, error.code is returned and processed. 5806 let err = error as BusinessError; 5807 console.error(`The setSmoothZoom call failed. error code: ${err.code}`); 5808 } 5809} 5810``` 5811 5812### prepareZoom 5813 5814prepareZoom(): void 5815 5816Instructs the bottom layer to prepare for zooming, for example, powering on the sensor. 5817 5818**System API**: This is a system API. 5819 5820**System capability**: SystemCapability.Multimedia.Camera.Core 5821 5822**Example** 5823 5824```ts 5825import { BusinessError } from '@ohos.base'; 5826 5827function prepareZoom(sessionExtendsZoom: camera.Zoom): void { 5828 try { 5829 sessionExtendsZoom.prepareZoom(); 5830 } catch (error) { 5831 // If the operation fails, error.code is returned and processed. 5832 let err = error as BusinessError; 5833 console.error(`The prepareZoom call failed. error code: ${err.code}`); 5834 } 5835} 5836``` 5837 5838### unprepareZoom 5839 5840unprepareZoom(): void 5841 5842Instructs the bottom layer to unprepare for zooming. 5843 5844**System API**: This is a system API. 5845 5846**System capability**: SystemCapability.Multimedia.Camera.Core 5847 5848**Example** 5849 5850```ts 5851import { BusinessError } from '@ohos.base'; 5852 5853function unprepareZoom(sessionExtendsZoom: camera.Zoom): void { 5854 try { 5855 sessionExtendsZoom.unprepareZoom(); 5856 } catch (error) { 5857 // If the operation fails, error.code is returned and processed. 5858 let err = error as BusinessError; 5859 console.error(`The unprepareZoom call failed. error code: ${err.code}`); 5860 } 5861} 5862``` 5863 5864## ZoomRange<sup>11+</sup> 5865 5866Obtains the supported zoom ratio range. The range is [min, max), which includes the minimum value but excludes the maximum value. 5867 5868**System API**: This is a system API. 5869 5870**System capability**: SystemCapability.Multimedia.Camera.Core 5871 5872| Name | Type | Mandatory| Read-only| Description | 5873| -------- | ------------- |---- | ---- | -------------| 5874| min | number | Yes | Yes | Minimum value of the zoom ratio range. | 5875| max | number | Yes | Yes | Maximum value of the zoom ratio range.| 5876 5877 5878## Stabilization<sup>11+</sup> 5879 5880Provides APIs for stabilization-related operations. 5881 5882### isVideoStabilizationModeSupported 5883 5884isVideoStabilizationModeSupported(vsMode: VideoStabilizationMode): boolean 5885 5886Checks whether a video stabilization mode is supported. 5887 5888**System capability**: SystemCapability.Multimedia.Camera.Core 5889 5890**Parameters** 5891 5892| Name | Type | Mandatory| Description | 5893| -------- | ------------------------------------------------- | ---- | ------------------------------ | 5894| vsMode | [VideoStabilizationMode](#videostabilizationmode) | Yes | Video stabilization mode. | 5895 5896**Return value** 5897 5898| Type | Description | 5899| ---------- | ----------------------------- | 5900| boolean | **true**: The video stabilization mode is supported.<br>**false**: The video stabilization mode is not supported. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 5901 5902**Error codes** 5903 5904For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 5905 5906| ID | Error Message | 5907| --------------- | --------------- | 5908| 7400103 | Session not config. | 5909 5910**Example** 5911 5912```ts 5913import { BusinessError } from '@ohos.base'; 5914 5915function isVideoStabilizationModeSupported(captureSession: camera.CaptureSession): boolean { 5916 let isSupported: boolean = false; 5917 try { 5918 isSupported = captureSession.isVideoStabilizationModeSupported(camera.VideoStabilizationMode.OFF); 5919 } catch (error) { 5920 // If the operation fails, error.code is returned and processed. 5921 let err = error as BusinessError; 5922 console.error(`The isVideoStabilizationModeSupported call failed. error code: ${err.code}`); 5923 } 5924 return isSupported; 5925} 5926``` 5927 5928### getActiveVideoStabilizationMode 5929 5930getActiveVideoStabilizationMode(): VideoStabilizationMode 5931 5932Obtains the video stabilization mode in use. 5933 5934**System capability**: SystemCapability.Multimedia.Camera.Core 5935 5936**Return value** 5937 5938| Type | Description | 5939| ---------- | ----------------------------- | 5940| [VideoStabilizationMode](#videostabilizationmode) | Video stabilization mode obtained. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.| 5941 5942**Error codes** 5943 5944For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 5945 5946| ID | Error Message | 5947| --------------- | --------------- | 5948| 7400103 | Session not config. | 5949 5950**Example** 5951 5952```ts 5953import { BusinessError } from '@ohos.base'; 5954 5955function getActiveVideoStabilizationMode(captureSession: camera.CaptureSession): camera.VideoStabilizationMode | undefined { 5956 let vsMode: camera.VideoStabilizationMode | undefined = undefined; 5957 try { 5958 vsMode = captureSession.getActiveVideoStabilizationMode(); 5959 } catch (error) { 5960 // If the operation fails, error.code is returned and processed. 5961 let err = error as BusinessError; 5962 console.error(`The getActiveVideoStabilizationMode call failed. error code: ${err.code}`); 5963 } 5964 return vsMode; 5965} 5966``` 5967 5968### setVideoStabilizationMode 5969 5970setVideoStabilizationMode(mode: VideoStabilizationMode): void 5971 5972Sets a video stabilization mode. Before the setting, use [isVideoStabilizationModeSupported](#isvideostabilizationmodesupported) to check whether the target video stabilization mode is supported. 5973 5974**System capability**: SystemCapability.Multimedia.Camera.Core 5975 5976**Parameters** 5977 5978| Name | Type | Mandatory| Description | 5979| -------- | ------------------------------------------------- | ---- | --------------------- | 5980| mode | [VideoStabilizationMode](#videostabilizationmode) | Yes | Video stabilization mode. | 5981 5982**Error codes** 5983 5984For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 5985 5986| ID | Error Message | 5987| --------------- | --------------- | 5988| 7400103 | Session not config. | 5989 5990**Example** 5991 5992```ts 5993import { BusinessError } from '@ohos.base'; 5994 5995function setVideoStabilizationMode(captureSession: camera.CaptureSession): void { 5996 try { 5997 captureSession.setVideoStabilizationMode(camera.VideoStabilizationMode.OFF); 5998 } catch (error) { 5999 // If the operation fails, error.code is returned and processed. 6000 let err = error as BusinessError; 6001 console.error(`The setVideoStabilizationMode call failed. error code: ${err.code}`); 6002 } 6003} 6004``` 6005 6006## Beauty<sup>11+</sup> 6007 6008Provides APIs related to beauty settings. 6009 6010### getSupportedBeautyTypes 6011 6012getSupportedBeautyTypes(): Array\<BeautyType\> 6013 6014Obtains the supported beauty types. 6015 6016**System API**: This is a system API. 6017 6018**System capability**: SystemCapability.Multimedia.Camera.Core 6019 6020**Return value** 6021 6022| Type | Description | 6023| ---------- | ----------------------------- | 6024| Array\<[BeautyType](#beautytype)\>| Array of beauty types supported. | 6025 6026**Error codes** 6027 6028For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 6029 6030| ID | Error Message | 6031| --------------- | --------------- | 6032| 7400103 | Session not config. | 6033 6034**Example** 6035 6036```ts 6037function getSupportedBeautyTypes(portraitSession: camera.PortraitSession): Array<camera.BeautyType> { 6038 let beautyTypes: Array<camera.BeautyType> = portraitSession.getSupportedBeautyTypes(); 6039 return beautyTypes; 6040} 6041``` 6042### getSupportedBeautyRange 6043 6044getSupportedBeautyRange(type: BeautyType): Array\<number\> 6045 6046Obtains the levels that can be set a beauty type. The beauty levels vary according to the device type. The following table is only an example. 6047 6048| Input Parameter | Example Return Value | Return Value Description | 6049| ----------------| ---- | ---------| 6050| AUTO | [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] |Beauty levels supported when **type** is set to **AUTO**. The value **0** means that beauty mode is disabled, and other positive values mean the corresponding automatic beauty levels. | 6051| SKIN_SMOOTH | [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] | Beauty levels supported when **type** is set to **SKIN_SMOOTH**. The value **0** means that the skin smoothing feature is disabled, and other positive values mean the corresponding skin smoothing levels. | 6052| FACE_SLENDER | [0, 1, 2, 3, 4, 5] | Beauty levels supported when **type** is set to **FACE_SLENDER**. The value **0** means that the face slimming feature is disabled, and other positive values mean the corresponding face slimming levels. | 6053| SKIN_TONE | [-1, 16242611] | Beauty levels supported when **type** is set to **SKIN_TONE**. The value **-1** means that the skin tone perfection feature is disabled. Other non-negative values mean the skin tone perfection levels represented by RGB,<br> for example, 16242611, which is 0xF7D7B3 in hexadecimal format, where F7, D7, and B3 represent the values of the R channel, G channel, and B channel, respectively. | 6054 6055**System API**: This is a system API. 6056 6057**System capability**: SystemCapability.Multimedia.Camera.Core 6058 6059**Parameters** 6060 6061| Name | Type | Mandatory| Description | 6062| -------- | --------------------------| ---- | ----------| 6063| type | [BeautyType](#beautytype) | Yes | Beauty type. | 6064 6065**Return value** 6066 6067| Type | Description | 6068| ---------- | ----------------------------- | 6069| Array\<number\> | Array of levels supported.| 6070 6071**Error codes** 6072 6073For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 6074 6075| ID | Error Message | 6076| --------------- | --------------- | 6077| 7400103 | Session not config. | 6078 6079**Example** 6080 6081```ts 6082function getSupportedBeautyRange(portraitSession: camera.PortraitSession): Array<number> { 6083 let beautyTypes: Array<camera.BeautyType> = portraitSession.getSupportedBeautyTypes(); 6084 if (beautyTypes === undefined || beautyTypes.length <= 0) { 6085 return []; 6086 } 6087 let beautyLevels: Array<number> = portraitSession.getSupportedBeautyRange(beautyTypes[0]); 6088 return beautyLevels; 6089} 6090``` 6091 6092### setBeauty 6093 6094setBeauty(type: BeautyType, value: number): void 6095 6096Sets a beauty type and its level. Beauty mode is turned off only when all the [beauty types](#beautytype) obtained through [getSupportedBeautyTypes](#getsupportedbeautytypes) are disabled. 6097 6098**System API**: This is a system API. 6099 6100**System capability**: SystemCapability.Multimedia.Camera.Core 6101 6102**Parameters** 6103 6104| Name | Type | Mandatory| Description | 6105| -------- | --------------------------| ---- | --------------------- | 6106| type | [BeautyType](#beautytype) | Yes | Beauty type. | 6107| value | number | Yes | Beauty level, which is obtained through [getSupportedBeautyRange](#getsupportedbeautyrange).| 6108 6109**Error codes** 6110 6111For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 6112 6113| ID | Error Message | 6114| --------------- | --------------- | 6115| 7400103 | Session not config. | 6116 6117**Example** 6118 6119```ts 6120function setBeauty(portraitSession: camera.PortraitSession): void { 6121 let beautyTypes: Array<camera.BeautyType> = portraitSession.getSupportedBeautyTypes(); 6122 if (beautyTypes === undefined || beautyTypes.length <= 0) { 6123 return; 6124 } 6125 let beautyLevels: Array<number> = portraitSession.getSupportedBeautyRange(beautyTypes[0]); 6126 if (beautyLevels === undefined || beautyLevels.length <= 0) { 6127 return; 6128 } 6129 portraitSession.setBeauty(beautyTypes[0], beautyLevels[0]); 6130} 6131``` 6132 6133### getBeauty 6134 6135getBeauty(type: BeautyType): number 6136 6137Obtains the level of the beauty type in use. 6138 6139**System API**: This is a system API. 6140 6141**System capability**: SystemCapability.Multimedia.Camera.Core 6142 6143**Parameters** 6144 6145| Name | Type | Mandatory| Description | 6146| -------- | ------------------------------------------------- | ---- | --------------------- | 6147| type | [BeautyType](#beautytype) | Yes | Beauty type. | 6148 6149**Return value** 6150| Name | Type | Mandatory| Description | 6151| -------- | ------------------------------------------------- | ---- | --------------------- | 6152| value | number | Yes | Beauty level. | 6153 6154**Error codes** 6155 6156For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 6157 6158| ID | Error Message | 6159| --------------- | --------------- | 6160| 7400103 | Session not config. | 6161 6162**Example** 6163 6164```ts 6165function getBeauty(portraitSession: camera.PortraitSession): number { 6166 const invalidValue: number = -1; 6167 let beautyTypes = portraitSession.getSupportedBeautyTypes(); 6168 if (beautyTypes === undefined || beautyTypes.length <= 0) { 6169 return invalidValue; 6170 } 6171 let beautyLevels: Array<number> = portraitSession.getSupportedBeautyRange(beautyTypes[0]); 6172 if (beautyLevels === undefined || beautyLevels.length <= 0) { 6173 return invalidValue; 6174 } 6175 portraitSession.setBeauty(beautyTypes[0], beautyLevels[0]); 6176 let beautyLevel: number = portraitSession.getBeauty(beautyTypes[0]); 6177 return beautyLevel; 6178} 6179``` 6180 6181## ColorEffect<sup>11+</sup> 6182 6183Provides the APIs for color effect settings. 6184 6185### getSupportedColorEffects 6186 6187getSupportedColorEffects(): Array\<ColorEffectType\> 6188 6189Obtains the supported color effects. 6190 6191**System API**: This is a system API. 6192 6193**System capability**: SystemCapability.Multimedia.Camera.Core 6194 6195**Return value** 6196 6197| Type | Description | 6198| ----------------------------------------------- | ---------------------------- | 6199| Array<[ColorEffectType](#coloreffecttype11)> | Array of color effects supported. | 6200 6201**Error codes** 6202 6203For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 6204 6205| ID | Error Message | 6206| --------------- | --------------- | 6207| 7400103 | Session not config. | 6208| 202 | Not System Application. | 6209 6210**Example** 6211 6212```ts 6213function getSupportedColorEffects(session: camera.PhotoSession): Array<camera.ColorEffectType> { 6214 let colorEffects: Array<camera.ColorEffectType> = session.getSupportedColorEffects(); 6215 return colorEffects; 6216} 6217``` 6218 6219### setColorEffect 6220 6221setColorEffect(type: ColorEffectType): void 6222 6223Sets a color effect. Before the setting, use [getSupportedColorEffects](#getsupportedcoloreffects) to obtain the supported color effects. 6224 6225**System API**: This is a system API. 6226 6227**System capability**: SystemCapability.Multimedia.Camera.Core 6228 6229**Parameters** 6230 6231| Name | Type | Mandatory| Description | 6232| ------------ |--------------------------------------------------------------- | -- | -------------------------- | 6233| type | [ColorEffectType](#coloreffecttype11) | Yes| Color effect, which can be obtained through [getSupportedColorEffects](#getsupportedcoloreffects). | 6234 6235**Error codes** 6236 6237For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 6238 6239| ID | Error Message | 6240| --------------- | --------------- | 6241| 7400103 | Session not config. | 6242| 202 | Not System Application. | 6243 6244**Example** 6245 6246```ts 6247function setColorEffect(session: camera.PhotoSession, colorEffect: camera.ColorEffectType): void { 6248 session.setColorEffect(colorEffect); 6249} 6250``` 6251 6252### getColorEffect 6253 6254getColorEffect(): ColorEffectType 6255 6256Obtains the color effect in use. 6257 6258**System API**: This is a system API. 6259 6260**System capability**: SystemCapability.Multimedia.Camera.Core 6261 6262**Return value** 6263 6264| Type | Description | 6265| ----------------------------------------------- | ---------------------------- | 6266| [ColorEffectType](#coloreffecttype11) | Color effect. | 6267 6268**Error codes** 6269 6270For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 6271 6272| ID | Error Message | 6273| --------------- | --------------- | 6274| 7400103 | Session not config. | 6275| 202 | Not System Application. | 6276 6277**Example** 6278 6279```ts 6280function getColorEffect(session: camera.PhotoSession): camera.ColorEffectType { 6281 let colorEffect: camera.ColorEffectType = session.getColorEffect(); 6282 return colorEffect; 6283} 6284``` 6285 6286## ColorEffectType<sup>11+</sup> 6287 6288Enumerates the color effect types. 6289 6290**System API**: This is a system API. 6291 6292**System capability**: SystemCapability.Multimedia.Camera.Core 6293 6294| Name | Value | Description | 6295| --------------------- | ---- | --------- | 6296| NORMAL | 0 | Regular color effect. | 6297| BRIGHT | 1 | Bright color effect. | 6298| SOFT | 2 | Soft color effect. | 6299 6300## ColorManagement<sup>11+</sup> 6301 6302Provides the APIs for color space settings. 6303 6304### getSupportedColorSpaces 6305 6306getSupportedColorSpaces(): Array\<colorSpaceManager.ColorSpace\> 6307 6308Obtains the supported color spaces. 6309 6310**System API**: This is a system API. 6311 6312**System capability**: SystemCapability.Multimedia.Camera.Core 6313 6314**Return value** 6315 6316| Type | Description | 6317| ----------------------------------------------- | ---------------------------- | 6318| Array<[colorSpaceManager.ColorSpace](js-apis-colorSpaceManager.md#colorspace)>| Array of color spaces supported. | 6319 6320**Error codes** 6321 6322For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 6323 6324| ID | Error Message | 6325| --------------- | --------------- | 6326| 7400103 | Session not config. | 6327| 202 | Not System Application. | 6328 6329**Example** 6330 6331```ts 6332function getSupportedColorSpaces(session: camera.PhotoSession): Array<colorSpaceManager.ColorSpace> { 6333 let colorSpaces: Array<colorSpaceManager.ColorSpace> = session.getSupportedColorSpaces(); 6334 return colorSpaces; 6335} 6336``` 6337### setColorSpace 6338 6339setColorSpace(colorSpace: colorSpaceManager.ColorSpace): void 6340 6341Sets a color space. Before the setting, use [getSupportedColorSpaces](#getsupportedcolorspaces) to obtain the supported color spaces. 6342 6343**System API**: This is a system API. 6344 6345**System capability**: SystemCapability.Multimedia.Camera.Core 6346 6347**Parameters** 6348 6349| Name | Type | Mandatory| Description | 6350| ------------ |---------------------- | -- | -------------------------- | 6351| colorSpace | [colorSpaceManager.ColorSpace](js-apis-colorSpaceManager.md#colorspace) | Yes| Color space, which can be obtained through [getSupportedColorSpaces](#getsupportedcolorspaces). | 6352 6353**Error codes** 6354 6355For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 6356 6357| ID | Error Message | 6358| --------------- | --------------- | 6359| 202 | Not System Application. | 6360| 7400102 | The colorSpace does not match the format. | 6361| 7400103 | Session not config. | 6362 6363**Example** 6364 6365```ts 6366import { BusinessError } from '@ohos.base'; 6367 6368function setColorSpace(session: camera.PhotoSession, colorSpaces: Array<colorSpaceManager.ColorSpace>): void { 6369 if (colorSpaces === undefined || colorSpaces.length <= 0) { 6370 return; 6371 } 6372 try { 6373 session.setColorSpace(colorSpaces[0]); 6374 } catch (error) { 6375 let err = error as BusinessError; 6376 console.error(`The setColorSpace call failed, error code: ${err.code}`); 6377 } 6378} 6379``` 6380### getActiveColorSpace 6381 6382getActiveColorSpace(): colorSpaceManager.ColorSpace 6383 6384Obtains the color space in use. 6385 6386**System API**: This is a system API. 6387 6388**System capability**: SystemCapability.Multimedia.Camera.Core 6389 6390**Return value** 6391 6392| Type | Description | 6393| ----------------------------------------------- | ---------------------------- | 6394| [colorSpaceManager.ColorSpace](js-apis-colorSpaceManager.md#colorspace) | Color space. | 6395 6396**Error codes** 6397 6398For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 6399 6400| ID | Error Message | 6401| --------------- | --------------- | 6402| 7400103 | Session not config. | 6403| 202 | Not System Application. | 6404 6405**Example** 6406 6407```ts 6408function getActiveColorSpace(session: camera.PhotoSession): colorSpaceManager.ColorSpace { 6409 let colorSpace: colorSpaceManager.ColorSpace = session.getActiveColorSpace(); 6410 return colorSpace; 6411} 6412``` 6413 6414## Portrait<sup>11+</sup> 6415 6416Provides the APIs for portrait photo settings. 6417 6418### getSupportedPortraitEffects 6419 6420getSupportedPortraitEffects(): Array\<PortraitEffect\> 6421 6422Obtains the supported portrait effects. 6423 6424**System API**: This is a system API. 6425 6426**System capability**: SystemCapability.Multimedia.Camera.Core 6427 6428**Return value** 6429 6430| Type | Description | 6431| ----------------------------------------------- | ---------------------------- | 6432| Array<[PortraitEffect](#portraiteffect)> | Array of portrait effects supported. | 6433 6434**Error codes** 6435 6436For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 6437 6438| ID | Error Message | 6439| --------------- | --------------- | 6440| 7400103 | Session not config. | 6441| 202 | Not System Application. | 6442 6443**Example** 6444 6445```ts 6446function getSupportedPortraitEffects(portraitSession: camera.PortraitSession): Array<camera.PortraitEffect> { 6447 let portraitEffects: Array<camera.PortraitEffect> = portraitSession.getSupportedPortraitEffects(); 6448 return portraitEffects; 6449} 6450``` 6451### setPortraitEffect 6452 6453setPortraitEffect(effect: PortraitEffect): void 6454 6455Sets a portrait effect. Before the setting, use [getSupportedPortraitEffects](#getsupportedportraiteffects) to obtain the supported portrait effects and check whether the target portrait effect is supported. 6456 6457**System API**: This is a system API. 6458 6459**System capability**: SystemCapability.Multimedia.Camera.Core 6460 6461**Parameters** 6462 6463| Name | Type | Mandatory| Description | 6464| ------------ |----------------------------- | -- | -------------------------- | 6465| effect | [PortraitEffect](#portraiteffect) | Yes| Portrait effect, which can be obtained through [getSupportedPortraitEffects](#getsupportedportraiteffects). | 6466 6467**Error codes** 6468 6469For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 6470 6471| ID | Error Message | 6472| --------------- | --------------- | 6473| 7400103 | Session not config. | 6474| 202 | Not System Application. | 6475 6476**Example** 6477 6478```ts 6479import { BusinessError } from '@ohos.base'; 6480 6481function setPortraitEffect(portraitSession: camera.PortraitSession, portraitEffects: Array<camera.PortraitEffect>): void { 6482 if (portraitEffects === undefined || portraitEffects.length <= 0) { 6483 return; 6484 } 6485 try { 6486 portraitSession.setPortraitEffect(portraitEffects[0]); 6487 } catch (error) { 6488 let err = error as BusinessError; 6489 console.error(`The setPortraitEffect call failed. error code: ${err.code}`); 6490 } 6491} 6492``` 6493### getPortraitEffect 6494 6495getPortraitEffect(): PortraitEffect 6496 6497Obtains the portrait effect in use. 6498 6499**System API**: This is a system API. 6500 6501**System capability**: SystemCapability.Multimedia.Camera.Core 6502 6503**Return value** 6504 6505| Type | Description | 6506| ----------------------------------------------- | ---------------------------- | 6507| [PortraitEffect](#portraiteffect) | Portrait effect. | 6508 6509**Error codes** 6510 6511For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 6512 6513| ID | Error Message | 6514| --------------- | --------------- | 6515| 7400103 | Session not config. | 6516| 202 | Not System Application. | 6517 6518**Example** 6519 6520```ts 6521function getPortraitEffect(portraitSession: camera.PortraitSession): camera.PortraitEffect { 6522 let portraitEffect: camera.PortraitEffect = portraitSession.getPortraitEffect(); 6523 return portraitEffect; 6524} 6525``` 6526 6527## PhysicalAperture<sup>11+</sup> 6528 6529Defines the physical aperture information. 6530 6531**System API**: This is a system API. 6532 6533**System capability**: SystemCapability.Multimedia.Camera.Core 6534 6535| Name | Type | Mandatory| Description | 6536| ---------- | ------------------------- | ---- | -----------------| 6537| zoomRange | [ZoomRange](#zoomrange11) | Yes | Zoom range of a given physical aperture. | 6538| apertures | Array\<number\> | Yes | Array of physical apertures supported. | 6539 6540## Aperture<sup>11+</sup> 6541 6542Provides the APIs for aperture settings. 6543 6544### getSupportedVirtualApertures 6545 6546getSupportedVirtualApertures(): Array\<number\> 6547 6548Obtains the supported virtual apertures. 6549 6550**System API**: This is a system API. 6551 6552**System capability**: SystemCapability.Multimedia.Camera.Core 6553 6554**Return value** 6555 6556| Type | Description | 6557| ----------------------------------------------- | ---------------------------- | 6558| Array\<number\> | Array of virtual apertures supported. | 6559 6560**Error codes** 6561 6562For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 6563 6564| ID | Error Message | 6565| --------------- | --------------- | 6566| 7400103 | Session not config. | 6567| 202 | Not System Application. | 6568 6569**Example** 6570 6571```ts 6572function getSupportedVirtualApertures(session: camera.PortraitPhotoSession): Array<number> { 6573 let virtualApertures: Array<number> = session.getSupportedVirtualApertures(); 6574 return virtualApertures; 6575} 6576``` 6577 6578### getVirtualAperture 6579 6580getVirtualAperture(): number 6581 6582Obtains the virtual aperture in use. 6583 6584**System API**: This is a system API. 6585 6586**System capability**: SystemCapability.Multimedia.Camera.Core 6587 6588**Return value** 6589 6590| Type | Description | 6591| ----------------------------------------------- | ---------------------------- | 6592| number | Virtual aperture. | 6593 6594**Error codes** 6595 6596For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 6597 6598| ID | Error Message | 6599| --------------- | --------------- | 6600| 7400103 | Session not config. | 6601| 202 | Not System Application. | 6602 6603**Example** 6604 6605```ts 6606function getVirtualAperture(session: camera.PortraitPhotoSession): number { 6607 let virtualAperture: number = session.getVirtualAperture(); 6608 return virtualAperture; 6609} 6610``` 6611 6612### setVirtualAperture 6613 6614setVirtualAperture(aperture: number): void 6615 6616Sets a virtual aperture. Before the setting, use [getSupportedVirtualApertures](#getsupportedvirtualapertures) to obtain the supported virtual apertures. 6617 6618**System API**: This is a system API. 6619 6620**System capability**: SystemCapability.Multimedia.Camera.Core 6621 6622**Parameters** 6623 6624| Name | Type | Mandatory| Description | 6625| ------------ |------------------------- | -- | -------------------------- | 6626| aperture | number | Yes| Virtual aperture, which can be obtained by calling [getSupportedVirtualApertures](#getsupportedvirtualapertures). | 6627 6628**Error codes** 6629 6630For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 6631 6632| ID | Error Message | 6633| --------------- | --------------- | 6634| 7400103 | Session not config. | 6635| 202 | Not System Application. | 6636 6637**Example** 6638 6639```ts 6640setVirtualAperture: 6641function setVirtualAperture(session: camera.PortraitPhotoSession, virtualAperture: number): void { 6642 session.setVirtualAperture(virtualAperture); 6643} 6644``` 6645 6646### getSupportedPhysicalApertures 6647 6648getSupportedPhysicalApertures(): Array\<PhysicalAperture\> 6649 6650Obtains the supported physical apertures. 6651 6652**System API**: This is a system API. 6653 6654**System capability**: SystemCapability.Multimedia.Camera.Core 6655 6656**Return value** 6657 6658| Type | Description | 6659| ----------------------------------------------- | ---------------------------- | 6660| Array<[PhysicalAperture](#physicalaperture11)> | Array of physical apertures supported. | 6661 6662**Error codes** 6663 6664For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 6665 6666| ID | Error Message | 6667| --------------- | --------------- | 6668| 7400103 | Session not config. | 6669| 202 | Not System Application. | 6670 6671**Example** 6672 6673```ts 6674function getSupportedPhysicalApertures(session: camera.PortraitPhotoSession): Array<camera.PhysicalAperture> { 6675 let physicalApertures: Array<camera.PhysicalAperture> = session.getSupportedPhysicalApertures(); 6676 return physicalApertures; 6677} 6678``` 6679 6680### getPhysicalAperture 6681 6682getPhysicalAperture(): number 6683 6684Obtains the physical aperture in use. 6685 6686**System API**: This is a system API. 6687 6688**System capability**: SystemCapability.Multimedia.Camera.Core 6689 6690**Return value** 6691 6692| Type | Description | 6693| -------------------- | ---------------------------- | 6694| number | Physical aperture. | 6695 6696**Error codes** 6697 6698For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 6699 6700| ID | Error Message | 6701| --------------- | --------------- | 6702| 7400103 | Session not config. | 6703| 202 | Not System Application. | 6704 6705**Example** 6706 6707```ts 6708function getPhysicalAperture(session: camera.PortraitPhotoSession): number { 6709 let physicalAperture: number = session.getPhysicalAperture(); 6710 return physicalAperture; 6711} 6712``` 6713 6714### setPhysicalAperture 6715 6716setPhysicalAperture(aperture: number): void 6717 6718Sets a physical aperture. Before the setting, use [getSupportedPhysicalApertures](#getsupportedphysicalapertures) to obtain the supported physical apertures. 6719 6720**System API**: This is a system API. 6721 6722**System capability**: SystemCapability.Multimedia.Camera.Core 6723 6724**Parameters** 6725 6726| Name | Type | Mandatory| Description | 6727| ------------ |------------------------- | -- | -------------------------- | 6728| aperture | number | Yes| Physical aperture, which can be obtained by calling [getSupportedPhysicalApertures](#getsupportedphysicalapertures). | 6729 6730**Error codes** 6731 6732For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md). 6733 6734| ID | Error Message | 6735| --------------- | --------------- | 6736| 7400103 | Session not config. | 6737| 202 | Not System Application. | 6738 6739**Example** 6740 6741```ts 6742function setPhysicalAperture(session: camera.PortraitPhotoSession, physicalAperture: number): void { 6743 session.setPhysicalAperture(physicalAperture); 6744} 6745``` 6746 6747## CaptureSession<sup>(deprecated)</sup> 6748 6749CaptureSession extends Session, Flash, AutoExposure, Focus, Zoom, Beauty 6750 6751Implements a session, which saves all [CameraInput](#camerainput) and [CameraOutput](#cameraoutput) instances required to run the camera and requests the camera to take a photo or record a video. 6752 6753> **NOTE** 6754>This API is supported since API version 10 and deprecated since API version 11. You are advised to use [PhotoSession](#photosession11) and [VideoSession](#videosession11) instead. 6755 6756### on('error') 6757 6758on(type: 'error', callback: ErrorCallback): void 6759 6760Subscribes to **CaptureSession** error events. This API uses a callback to return the result. 6761 6762**System capability**: SystemCapability.Multimedia.Camera.Core 6763 6764**Parameters** 6765 6766| Name | Type | Mandatory| Description | 6767| -------- | ----------------------------------------------------------- | ---- |-----------------------------------------------------------------------------------------------------------------------------------------------------------------| 6768| type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a session is created. This event is triggered and the error message is returned when an error occurs during the calling of a session-related API such as [beginConfig](#beginconfig), [commitConfig](#commitconfig), and [addInput](#addinput).| 6769| callback | ErrorCallback| Yes | Callback used to return an error code defined in [CameraErrorCode](#cameraerrorcode). | 6770 6771**Example** 6772 6773```ts 6774import { BusinessError } from '@ohos.base'; 6775 6776function callback(err: BusinessError): void { 6777 console.error(`Capture session error code: ${err.code}`); 6778} 6779 6780function registerSessionError(captureSession: camera.CaptureSession): void { 6781 captureSession.on('error', callback); 6782} 6783``` 6784 6785### off('error') 6786 6787off(type: 'error', callback?: ErrorCallback): void 6788 6789Unsubscribes from **CaptureSession** error events. This API uses a callback to return the result. 6790 6791**System capability**: SystemCapability.Multimedia.Camera.Core 6792 6793**Parameters** 6794 6795| Name | Type | Mandatory| Description | 6796| -------- | -------------------- | ---- | ------------------------------ | 6797| type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a session is created.| 6798| callback | ErrorCallback | No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('error') with the specified callback is canceled. (The callback object cannot be an anonymous function.) | 6799 6800**Example** 6801 6802```ts 6803function unregisterSessionError(captureSession: camera.CaptureSession): void { 6804 captureSession.off('error'); 6805} 6806``` 6807 6808### on('focusStateChange') 6809 6810on(type: 'focusStateChange', callback: AsyncCallback\<FocusState\>): void 6811 6812Subscribes to focus state change events. This API uses an asynchronous callback to return the result. 6813 6814**System capability**: SystemCapability.Multimedia.Camera.Core 6815 6816**Parameters** 6817 6818| Name | Type | Mandatory| Description | 6819| -------- | ---------------- | ---- | ------------------------ | 6820| type | string | Yes | Event type. The value is fixed at **'focusStateChange'**. The event can be listened for when a session is created. This event is triggered only when the camera focus state changes in auto focus mode.| 6821| callback | AsyncCallback\<[FocusState](#focusstate)\> | Yes | Callback used to return the focus state change. | 6822 6823**Example** 6824 6825```ts 6826import { BusinessError } from '@ohos.base'; 6827 6828function callback(err: BusinessError, focusState: camera.FocusState): void { 6829 console.info(`Focus state: ${focusState}`); 6830} 6831 6832function registerFocusStateChange(captureSession: camera.CaptureSession): void { 6833 captureSession.on('focusStateChange', callback); 6834} 6835``` 6836 6837### off('focusStateChange') 6838 6839off(type: 'focusStateChange', callback?: AsyncCallback\<FocusState\>): void 6840 6841Unsubscribes from focus state change events. 6842 6843**System capability**: SystemCapability.Multimedia.Camera.Core 6844 6845**Parameters** 6846 6847| Name | Type | Mandatory| Description | 6848| -------- | ----------------------------------------- | ---- | ------------------------ | 6849| type | string | Yes | Event type. The value is fixed at **'focusStateChange'**. The event can be listened for when a session is created.| 6850| callback | AsyncCallback\<[FocusState](#focusstate)\> | No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('error') with the specified callback is canceled. (The callback object cannot be an anonymous function.) | 6851 6852**Example** 6853 6854```ts 6855function unregisterFocusStateChange(captureSession: camera.CaptureSession): void { 6856 captureSession.off('focusStateChange'); 6857} 6858``` 6859 6860## PhotoSession<sup>11+</sup> 6861 6862PhotoSession extends Session, Flash, AutoExposure, Focus, Zoom, Beauty, ColorEffect, ColorManagement, Macro 6863 6864Implements a photo session, which sets the parameters of the normal photo mode and saves all [CameraInput](#camerainput) and [CameraOutput](#cameraoutput) instances required to run the camera. It inherits from [Session](#session11). 6865 6866### on('error') 6867 6868on(type: 'error', callback: ErrorCallback): void 6869 6870Subscribes to **PhotoSession** error events. This API uses a callback to return the result. 6871 6872**System capability**: SystemCapability.Multimedia.Camera.Core 6873 6874**Parameters** 6875 6876| Name | Type | Mandatory| Description | 6877| -------- | ----------------------------------------------------------- | ---- | ------------------------------ | 6878| type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a session is created. This event is triggered and the error message is returned when an error occurs during the calling of a session-related API such as [beginConfig](#beginconfig), [commitConfig](#commitconfig), and [addInput](#addinput).| 6879| callback | ErrorCallback| Yes | Callback used to return an error code defined in [CameraErrorCode](#cameraerrorcode). | 6880 6881**Example** 6882 6883```ts 6884import { BusinessError } from '@ohos.base'; 6885 6886function callback(err: BusinessError): void { 6887 console.error(`Photo session error code: ${err.code}`); 6888} 6889 6890function registerSessionError(photoSession: camera.PhotoSession): void { 6891 photoSession.on('error', (error: BusinessError) => { 6892 console.error(`Photo session error code: ${error.code}`); 6893 }); 6894} 6895``` 6896 6897### off('error') 6898 6899off(type: 'error', callback?: ErrorCallback): void 6900 6901Unsubscribes from **PhotoSession** error events. This API uses a callback to return the result. 6902 6903**System capability**: SystemCapability.Multimedia.Camera.Core 6904 6905**Parameters** 6906 6907| Name | Type | Mandatory| Description | 6908| -------- | -------------------------------- | ---- | ------------------------------ | 6909| type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a session is created.| 6910| callback | ErrorCallback| No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('error') with the specified callback is canceled. (The callback object cannot be an anonymous function.) | 6911 6912**Example** 6913 6914```ts 6915function unregisterSessionError(photoSession: camera.PhotoSession): void { 6916 photoSession.off('error'); 6917} 6918``` 6919 6920### on('focusStateChange') 6921 6922on(type: 'focusStateChange', callback: AsyncCallback\<FocusState\>): void 6923 6924Subscribes to focus state change events. This API uses an asynchronous callback to return the result. 6925 6926**System capability**: SystemCapability.Multimedia.Camera.Core 6927 6928**Parameters** 6929 6930| Name | Type | Mandatory| Description | 6931| -------- | ---------------- | ---- | ------------------------ | 6932| type | string | Yes | Event type. The value is fixed at **'focusStateChange'**. The event can be listened for when a session is created. This event is triggered only when the camera focus state changes in auto focus mode.| 6933| callback | AsyncCallback\<[FocusState](#focusstate)\> | Yes | Callback used to return the focus state change. | 6934 6935**Example** 6936 6937```ts 6938import { BusinessError } from '@ohos.base'; 6939 6940function callback(err: BusinessError, focusState: camera.FocusState): void { 6941 console.info(`Focus state: ${focusState}`); 6942} 6943 6944function registerFocusStateChange(photoSession: camera.PhotoSession): void { 6945 photoSession.on('focusStateChange', callback); 6946} 6947``` 6948 6949### off('focusStateChange') 6950 6951off(type: 'focusStateChange', callback?: AsyncCallback\<FocusState\>): void 6952 6953Unsubscribes from focus state change events. 6954 6955**System capability**: SystemCapability.Multimedia.Camera.Core 6956 6957**Parameters** 6958 6959| Name | Type | Mandatory| Description | 6960| -------- | ----------------------------------------- | ---- | ------------------------ | 6961| type | string | Yes | Event type. The value is fixed at **'focusStateChange'**. The event can be listened for when a session is created.| 6962| callback | AsyncCallback\<[FocusState](#focusstate)\> | No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('error') with the specified callback is canceled. (The callback object cannot be an anonymous function.) | 6963 6964**Example** 6965 6966```ts 6967function unregisterFocusStateChange(photoSession: camera.PhotoSession): void { 6968 photoSession.off('focusStateChange'); 6969} 6970``` 6971 6972### on('smoothZoomInfoAvailable')<sup>11+</sup> 6973 6974on(type: 'smoothZoomInfoAvailable', callback: AsyncCallback\<SmoothZoomInfo\>): void 6975 6976Subscribes to smooth zoom state change events. This API uses an asynchronous callback to return the result. 6977 6978**System capability**: SystemCapability.Multimedia.Camera.Core 6979 6980**Parameters** 6981 6982| Name | Type | Mandatory| Description | 6983| -------- | ----------------------- | ---- | ------------------------ | 6984| type | string | Yes | Event type. The value is fixed at **'smoothZoomInfoAvailable'**. The event can be listened for when a session is created.| 6985| callback | AsyncCallback\<[SmoothZoomInfo](#smoothzoominfo11)\> | Yes | Callback used to return the smooth zoom state change. | 6986 6987**Example** 6988 6989```ts 6990import { BusinessError } from '@ohos.base'; 6991 6992function callback(err: BusinessError, smoothZoomInfo: camera.SmoothZoomInfo): void { 6993 console.info(`The duration of smooth zoom: ${smoothZoomInfo.duration}`); 6994} 6995 6996function registerSmoothZoomInfo(photoSession: camera.PhotoSession): void { 6997 photoSession.on('smoothZoomInfoAvailable', callback); 6998} 6999``` 7000 7001### off('smoothZoomInfoAvailable')<sup>11+</sup> 7002 7003off(type: 'smoothZoomInfoAvailable', callback?: AsyncCallback\<SmoothZoomInfo\>): void 7004 7005Unsubscribes from smooth zoom state change events. 7006 7007**System capability**: SystemCapability.Multimedia.Camera.Core 7008 7009**Parameters** 7010 7011| Name | Type | Mandatory| Description | 7012| -------- | ----------------------------------------- | ---- | ------------------------ | 7013| type | string | Yes | Event type. The value is fixed at **'smoothZoomInfoAvailable'**. The event can be listened for when a session is created.| 7014| callback | AsyncCallback\<[SmoothZoomInfo](#smoothzoominfo11)\> | No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('error') with the specified callback is canceled. (The callback object cannot be an anonymous function.) | 7015 7016**Example** 7017 7018```ts 7019function unregisterSmoothZoomInfo(photoSession: camera.PhotoSession): void { 7020 photoSession.off('smoothZoomInfoAvailable'); 7021} 7022``` 7023 7024### on('macroStatusChanged') 7025 7026on(type: 'macroStatusChanged', callback: AsyncCallback\<boolean\>): void 7027 7028Subscribes to macro state change events. This API uses an asynchronous callback to return the result. 7029 7030**System API**: This is a system API. 7031 7032**System capability**: SystemCapability.Multimedia.Camera.Core 7033 7034**Parameters** 7035 7036| Name | Type | Mandatory| Description | 7037| -------- | ----------------------------------------- | ---- | ------------------------ | 7038| type | string | Yes | Event type. The value is fixed at **'macroStatusChanged'**. The event can be listened for when a session is created.| 7039| callback | AsyncCallback\<boolean\> | Yes | Callback used to return the macro state change. | 7040 7041**Example** 7042 7043```ts 7044import { BusinessError } from '@ohos.base'; 7045 7046function callback(err: BusinessError, macroStatus: boolean): void { 7047 console.info(`Macro state: ${macroStatus}`); 7048} 7049 7050function registerMacroStatusChanged(photoSession: camera.PhotoSession): void { 7051 photoSession.on('macroStatusChanged', callback); 7052} 7053``` 7054 7055### off('macroStatusChanged') 7056 7057off(type: 'macroStatusChanged', callback?: AsyncCallback\<boolean\>): void 7058 7059Unsubscribes from macro state change events. 7060 7061**System API**: This is a system API. 7062 7063**System capability**: SystemCapability.Multimedia.Camera.Core 7064 7065**Parameters** 7066 7067| Name | Type | Mandatory| Description | 7068| -------- | ------------------------ | ---- | ------------------------ | 7069| type | string | Yes | Event type. The value is fixed at **'macroStatusChanged'**. The event can be listened for when a session is created.| 7070| callback | AsyncCallback\<boolean\> | No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('error') with the specified callback is canceled. (The callback object cannot be an anonymous function.)| 7071 7072**Example** 7073 7074```ts 7075function unregisterMacroStatusChanged(photoSession: camera.PhotoSession): void { 7076 photoSession.off('macroStatusChanged'); 7077} 7078``` 7079 7080## VideoSession<sup>11+</sup> 7081 7082VideoSession extends Session, Flash, AutoExposure, Focus, Zoom, Beauty, ColorEffect, ColorManagement, Macro, Stabilization 7083 7084Implements a video session, which sets the parameters of the normal video mode and saves all [CameraInput](#camerainput) and [CameraOutput](#cameraoutput) instances required to run the camera. It inherits from [Session](#session11). 7085 7086### on('error') 7087 7088on(type: 'error', callback: ErrorCallback): void 7089 7090Subscribes to **VideoSession** error events. This API uses a callback to return the result. 7091 7092**System capability**: SystemCapability.Multimedia.Camera.Core 7093 7094**Parameters** 7095 7096| Name | Type | Mandatory| Description | 7097| -------- | ------------------ | ---- | ------------------------------ | 7098| type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a session is created. This event is triggered and the error message is returned when an error occurs during the calling of a session-related API such as [beginConfig](#beginconfig), [commitConfig](#commitconfig), and [addInput](#addinput).| 7099| callback | ErrorCallback | Yes | Callback used to return an error code defined in [CameraErrorCode](#cameraerrorcode). | 7100 7101**Example** 7102 7103```ts 7104import { BusinessError } from '@ohos.base'; 7105 7106function callback(err: BusinessError): void { 7107 console.error(`Video session error code: ${err.code}`); 7108} 7109 7110function registerSessionError(videoSession: camera.VideoSession): void { 7111 videoSession.on('error', callback); 7112} 7113``` 7114 7115### off('error') 7116 7117off(type: 'error', callback?: ErrorCallback): void 7118 7119Unsubscribes from **VideoSession** error events. This API uses a callback to return the result. 7120 7121**System capability**: SystemCapability.Multimedia.Camera.Core 7122 7123**Parameters** 7124 7125| Name | Type | Mandatory| Description | 7126| -------- | --------------------------- | ---- | ------------------------------ | 7127| type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a session is created.| 7128| callback | ErrorCallback| No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('error') with the specified callback is canceled. (The callback object cannot be an anonymous function.) | 7129 7130**Example** 7131 7132```ts 7133function unregisterSessionError(videoSession: camera.VideoSession): void { 7134 videoSession.off('error'); 7135} 7136``` 7137 7138### on('focusStateChange') 7139 7140on(type: 'focusStateChange', callback: AsyncCallback\<FocusState\>): void 7141 7142Subscribes to focus state change events. This API uses an asynchronous callback to return the result. 7143 7144**System capability**: SystemCapability.Multimedia.Camera.Core 7145 7146**Parameters** 7147 7148| Name | Type | Mandatory| Description | 7149| -------- | ---------------- | ---- | ------------------------ | 7150| type | string | Yes | Event type. The value is fixed at **'focusStateChange'**. The event can be listened for when a session is created. This event is triggered only when the camera focus state changes in auto focus mode.| 7151| callback | AsyncCallback\<[FocusState](#focusstate)\> | Yes | Callback used to return the focus state change. | 7152 7153**Example** 7154 7155```ts 7156import { BusinessError } from '@ohos.base'; 7157 7158function callback(err: BusinessError, focusState: camera.FocusState): void { 7159 console.info(`Focus state: ${focusState}`); 7160} 7161 7162function registerFocusStateChange(videoSession: camera.VideoSession): void { 7163 videoSession.on('focusStateChange', callback); 7164} 7165``` 7166 7167### off('focusStateChange') 7168 7169off(type: 'focusStateChange', callback?: AsyncCallback\<FocusState\>): void 7170 7171Unsubscribes from focus state change events. 7172 7173**System capability**: SystemCapability.Multimedia.Camera.Core 7174 7175**Parameters** 7176 7177| Name | Type | Mandatory| Description | 7178| -------- | ----------------------------------------- | ---- | ------------------------ | 7179| type | string | Yes | Event type. The value is fixed at **'focusStateChange'**. The event can be listened for when a session is created.| 7180| callback | AsyncCallback\<[FocusState](#focusstate)\> | No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('error') with the specified callback is canceled. (The callback object cannot be an anonymous function.) | 7181 7182**Example** 7183 7184```ts 7185function unregisterFocusStateChange(videoSession: camera.VideoSession): void { 7186 videoSession.off('focusStateChange'); 7187} 7188``` 7189 7190### on('smoothZoomInfoAvailable')<sup>11+</sup> 7191 7192on(type: 'smoothZoomInfoAvailable', callback: AsyncCallback\<SmoothZoomInfo\>): void 7193 7194Subscribes to smooth zoom state change events. This API uses an asynchronous callback to return the result. 7195 7196**System capability**: SystemCapability.Multimedia.Camera.Core 7197 7198**Parameters** 7199 7200| Name | Type | Mandatory| Description | 7201| -------- | ----------------------- | ---- | ------------------------ | 7202| type | string | Yes | Event type. The value is fixed at **'smoothZoomInfoAvailable'**. The event can be listened for when a session is created.| 7203| callback | AsyncCallback\<[SmoothZoomInfo](#smoothzoominfo11)\> | Yes | Callback used to return the smooth zoom state change. | 7204 7205**Example** 7206 7207```ts 7208import { BusinessError } from '@ohos.base'; 7209 7210function callback(err: BusinessError, smoothZoomInfo: camera.SmoothZoomInfo): void { 7211 console.info(`The duration of smooth zoom: ${smoothZoomInfo.duration}`); 7212} 7213 7214function registerSmoothZoomInfo(videoSession: camera.VideoSession): void { 7215 videoSession.on('smoothZoomInfoAvailable', callback); 7216} 7217``` 7218 7219### off('smoothZoomInfoAvailable')<sup>11+</sup> 7220 7221off(type: 'smoothZoomInfoAvailable', callback?: AsyncCallback\<SmoothZoomInfo\>): void 7222 7223Unsubscribes from smooth zoom state change events. 7224 7225**System capability**: SystemCapability.Multimedia.Camera.Core 7226 7227**Parameters** 7228 7229| Name | Type | Mandatory| Description | 7230| -------- | ----------------------------------------- | ---- | ------------------------ | 7231| type | string | Yes | Event type. The value is fixed at **'smoothZoomInfoAvailable'**. The event can be listened for when a session is created.| 7232| callback | AsyncCallback\<[SmoothZoomInfo](#smoothzoominfo11)\> | No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('error') with the specified callback is canceled. (The callback object cannot be an anonymous function.) | 7233 7234**Example** 7235 7236```ts 7237function unregisterSmoothZoomInfo(videoSession: camera.VideoSession): void { 7238 videoSession.off('smoothZoomInfoAvailable'); 7239} 7240``` 7241 7242### on('macroStatusChanged') 7243 7244on(type: 'macroStatusChanged', callback: AsyncCallback\<boolean\>): void 7245 7246Subscribes to macro state change events. This API uses an asynchronous callback to return the result. 7247 7248**System API**: This is a system API. 7249 7250**System capability**: SystemCapability.Multimedia.Camera.Core 7251 7252**Parameters** 7253 7254| Name | Type | Mandatory| Description | 7255| -------- | ----------------------------------------- | ---- | ------------------------ | 7256| type | string | Yes | Event type. The value is fixed at **'macroStatusChanged'**. The event can be listened for when a session is created.| 7257| callback | AsyncCallback\<boolean\> | Yes | Callback used to return the macro state change. | 7258 7259**Example** 7260 7261```ts 7262import { BusinessError } from '@ohos.base'; 7263 7264function callback(err: BusinessError, macroStatus: boolean): void { 7265 console.info(`Macro state: ${macroStatus}`); 7266} 7267 7268function registerMacroStatusChanged(videoSession: camera.VideoSession): void { 7269 videoSession.on('macroStatusChanged', callback); 7270} 7271``` 7272 7273### off('macroStatusChanged') 7274 7275off(type: 'macroStatusChanged', callback?: AsyncCallback\<boolean\>): void 7276 7277Unsubscribes from macro state change events. 7278 7279**System API**: This is a system API. 7280 7281**System capability**: SystemCapability.Multimedia.Camera.Core 7282 7283**Parameters** 7284 7285| Name | Type | Mandatory| Description | 7286| -------- | ------------------------ | ---- | ------------------------ | 7287| type | string | Yes | Event type. The value is fixed at **'macroStatusChanged'**. The event can be listened for when a session is created.| 7288| callback | AsyncCallback\<boolean\> | No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('error') with the specified callback is canceled. (The callback object cannot be an anonymous function.)| 7289 7290**Example** 7291 7292```ts 7293function unregisterMacroStatusChanged(videoSession: camera.VideoSession): void { 7294 videoSession.off('macroStatusChanged'); 7295} 7296``` 7297 7298## PortraitPhotoSession<sup>11+</sup> 7299 7300PortraitPhotoSession extends Session, Flash, AutoExposure, Focus, Zoom, Beauty, ColorEffect, ColorManagement, Portrait, Aperture 7301 7302Implements a portrait photo session, which sets the parameters of the portrait photo mode and saves all [CameraInput](#camerainput) and [CameraOutput](#cameraoutput) instances required to run the camera. It inherits from [Session](#session11). 7303 7304### on('error') 7305 7306on(type: 'error', callback: ErrorCallback): void 7307 7308Subscribes to **PortraitSession** error events. This API uses a callback to return the result. 7309 7310**System API**: This is a system API. 7311 7312**System capability**: SystemCapability.Multimedia.Camera.Core 7313 7314**Parameters** 7315 7316| Name | Type | Mandatory| Description | 7317| -------- | --------------------------------- | ---- | ------------------------------ | 7318| type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a session is created. This event is triggered and the error message is returned when an error occurs during the calling of a session-related API such as [beginConfig](#beginconfig), [commitConfig](#commitconfig), and [addInput](#addinput).| 7319| callback | ErrorCallback| Yes | Callback used to return an error code defined in [CameraErrorCode](#cameraerrorcode). | 7320 7321**Example** 7322 7323```ts 7324import { BusinessError } from '@ohos.base'; 7325 7326function callback(err: BusinessError): void { 7327 console.error(`Portrait photo session error code: ${err.code}`); 7328} 7329 7330function registerSessionError(portraitPhotoSession: camera.PortraitPhotoSession): void { 7331 portraitPhotoSession.on('error', callback); 7332} 7333``` 7334 7335### off('error') 7336 7337off(type: 'error', callback?: ErrorCallback): void 7338 7339Unsubscribes from **PortraitSession** error events. This API uses a callback to return the result. 7340 7341**System API**: This is a system API. 7342 7343**System capability**: SystemCapability.Multimedia.Camera.Core 7344 7345**Parameters** 7346 7347| Name | Type | Mandatory| Description | 7348| -------- | -------------------------- | ---- | ------------------------------ | 7349| type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a session is created.| 7350| callback | ErrorCallback| No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('error') with the specified callback is canceled. (The callback object cannot be an anonymous function.) | 7351 7352**Example** 7353 7354```ts 7355function unregisterSessionError(portraitPhotoSession: camera.PortraitPhotoSession): void { 7356 portraitPhotoSession.off('error'); 7357} 7358``` 7359 7360### on('focusStateChange') 7361 7362on(type: 'focusStateChange', callback: AsyncCallback\<FocusState\>): void 7363 7364Subscribes to focus state change events. This API uses an asynchronous callback to return the result. 7365 7366**System API**: This is a system API. 7367 7368**System capability**: SystemCapability.Multimedia.Camera.Core 7369 7370**Parameters** 7371 7372| Name | Type | Mandatory| Description | 7373| -------- | ---------------- | ---- | ------------------------ | 7374| type | string | Yes | Event type. The value is fixed at **'focusStateChange'**. The event can be listened for when a session is created. This event is triggered only when the camera focus state changes in auto focus mode.| 7375| callback | AsyncCallback\<[FocusState](#focusstate)\> | Yes | Callback used to return the focus state change. | 7376 7377**Example** 7378 7379```ts 7380import { BusinessError } from '@ohos.base'; 7381 7382function callback(err: BusinessError, focusState: camera.FocusState): void { 7383 console.info(`Focus state: ${focusState}`); 7384} 7385 7386function registerFocusStateChange(portraitPhotoSession: camera.PortraitPhotoSession): void { 7387 portraitPhotoSession.on('focusStateChange', callback); 7388} 7389``` 7390 7391### off('focusStateChange') 7392 7393off(type: 'focusStateChange', callback?: AsyncCallback\<FocusState\>): void 7394 7395Unsubscribes from focus state change events. 7396 7397**System API**: This is a system API. 7398 7399**System capability**: SystemCapability.Multimedia.Camera.Core 7400 7401**Parameters** 7402 7403| Name | Type | Mandatory| Description | 7404| -------- | ----------------------------------------- | ---- | ------------------------ | 7405| type | string | Yes | Event type. The value is fixed at **'focusStateChange'**. The event can be listened for when a session is created.| 7406| callback | AsyncCallback\<[FocusState](#focusstate)\> | No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('error') with the specified callback is canceled. (The callback object cannot be an anonymous function.) | 7407 7408**Example** 7409 7410```ts 7411function unregisterFocusStateChange(portraitPhotoSession: camera.PortraitPhotoSession): void { 7412 portraitPhotoSession.off('focusStateChange'); 7413} 7414``` 7415 7416### on('smoothZoomInfoAvailable')<sup>11+</sup> 7417 7418on(type: 'smoothZoomInfoAvailable', callback: AsyncCallback\<SmoothZoomInfo\>): void 7419 7420Subscribes to smooth zoom state change events. This API uses an asynchronous callback to return the result. 7421 7422**System API**: This is a system API. 7423 7424**System capability**: SystemCapability.Multimedia.Camera.Core 7425 7426**Parameters** 7427 7428| Name | Type | Mandatory| Description | 7429| -------- | ----------------------- | ---- | ------------------------ | 7430| type | string | Yes | Event type. The value is fixed at **'smoothZoomInfoAvailable'**. The event can be listened for when a session is created.| 7431| callback | AsyncCallback\<[SmoothZoomInfo](#smoothzoominfo11)\> | Yes | Callback used to return the smooth zoom state change. | 7432 7433**Example** 7434 7435```ts 7436import { BusinessError } from '@ohos.base'; 7437 7438function callback(err: BusinessError, smoothZoomInfo: camera.SmoothZoomInfo): void { 7439 console.info(`The duration of smooth zoom: ${smoothZoomInfo.duration}`); 7440} 7441 7442function registerSmoothZoomInfo(portraitPhotoSession: camera.PortraitPhotoSession): void { 7443 portraitPhotoSession.on('smoothZoomInfoAvailable', callback); 7444} 7445``` 7446 7447### off('smoothZoomInfoAvailable')<sup>11+</sup> 7448 7449off(type: 'smoothZoomInfoAvailable', callback?: AsyncCallback\<SmoothZoomInfo\>): void 7450 7451Unsubscribes from smooth zoom state change events. 7452 7453**System API**: This is a system API. 7454 7455**System capability**: SystemCapability.Multimedia.Camera.Core 7456 7457**Parameters** 7458 7459| Name | Type | Mandatory| Description | 7460| -------- | ----------------------------------------- | ---- | ------------------------ | 7461| type | string | Yes | Event type. The value is fixed at **'smoothZoomInfoAvailable'**. The event can be listened for when a session is created.| 7462| callback | AsyncCallback\<[SmoothZoomInfo](#smoothzoominfo11)\> | No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('error') with the specified callback is canceled. (The callback object cannot be an anonymous function.) | 7463 7464**Example** 7465 7466```ts 7467function unregisterSmoothZoomInfo(portraitPhotoSession: camera.PortraitPhotoSession): void { 7468 portraitPhotoSession.off('smoothZoomInfoAvailable'); 7469} 7470``` 7471 7472## NightPhotoSession<sup>11+</sup> 7473 7474NightPhotoSession extends Session, Flash, AutoExposure, Focus, Zoom, ColorEffect, ColorManagement, ManualExposure 7475 7476Implements a night photo session, which sets the parameters of the night photo mode and saves all [CameraInput](#camerainput) and [CameraOutput](#cameraoutput) instances required to run the camera. It inherits from [Session](#session11). 7477 7478### on('error') 7479 7480on(type: 'error', callback: ErrorCallback): void 7481 7482Subscribes to **NightSession** error events. This API uses a callback to return the result. 7483 7484**System API**: This is a system API. 7485 7486**System capability**: SystemCapability.Multimedia.Camera.Core 7487 7488**Parameters** 7489 7490| Name | Type | Mandatory| Description | 7491| -------- | ----------------------------------------------------------- | ---- | ------------------------------ | 7492| type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a session is created. This event is triggered and the error message is returned when an error occurs during the calling of a session-related API such as [beginConfig](#beginconfig), [commitConfig](#commitconfig), and [addInput](#addinput).| 7493| callback | ErrorCallback| Yes | Callback used to return an error code defined in [CameraErrorCode](#cameraerrorcode).| 7494 7495**Example** 7496 7497```ts 7498import { BusinessError } from '@ohos.base'; 7499 7500function callback(err: BusinessError): void { 7501 console.error(`Night photo session error code: ${err.code}`); 7502} 7503 7504function registerSessionError(nightPhotoSession: camera.NightPhotoSession): void { 7505 nightPhotoSession.on('error', callback); 7506} 7507``` 7508 7509### off('error') 7510 7511off(type: 'error', callback?: ErrorCallback): void 7512 7513Unsubscribes from **NightSession** error events. This API uses a callback to return the result. 7514 7515**System API**: This is a system API. 7516 7517**System capability**: SystemCapability.Multimedia.Camera.Core 7518 7519**Parameters** 7520 7521| Name | Type | Mandatory| Description | 7522| -------- | ------------------------ | ---- | ------------------------------ | 7523| type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a session is created.| 7524| callback | ErrorCallback| No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('error') with the specified callback is canceled. (The callback object cannot be an anonymous function.) | 7525 7526**Example** 7527 7528```ts 7529function unregisterSessionError(nightPhotoSession: camera.NightPhotoSession): void { 7530 nightPhotoSession.off('error'); 7531} 7532``` 7533 7534### on('focusStateChange') 7535 7536on(type: 'focusStateChange', callback: AsyncCallback\<FocusState\>): void 7537 7538Subscribes to focus state change events. This API uses an asynchronous callback to return the result. 7539 7540**System API**: This is a system API. 7541 7542**System capability**: SystemCapability.Multimedia.Camera.Core 7543 7544**Parameters** 7545 7546| Name | Type | Mandatory| Description | 7547| -------- | ---------------- | ---- | ------------------------ | 7548| type | string | Yes | Event type. The value is fixed at **'focusStateChange'**. The event can be listened for when a session is created. This event is triggered only when the camera focus state changes in auto focus mode.| 7549| callback | AsyncCallback\<[FocusState](#focusstate)\> | Yes | Callback used to return the focus state change. | 7550 7551**Example** 7552 7553```ts 7554import { BusinessError } from '@ohos.base'; 7555 7556function callback(err: BusinessError, focusState: camera.FocusState): void { 7557 console.info(`Focus state: ${focusState}`); 7558} 7559 7560function registerFocusStateChange(nightPhotoSession: camera.NightPhotoSession): void { 7561 nightPhotoSession.on('focusStateChange', callback); 7562} 7563``` 7564 7565### off('focusStateChange') 7566 7567off(type: 'focusStateChange', callback?: AsyncCallback\<FocusState\>): void 7568 7569Unsubscribes from focus state change events. 7570 7571**System API**: This is a system API. 7572 7573**System capability**: SystemCapability.Multimedia.Camera.Core 7574 7575**Parameters** 7576 7577| Name | Type | Mandatory| Description | 7578| -------- | ----------------------------------------- | ---- | ------------------------ | 7579| type | string | Yes | Event type. The value is fixed at **'focusStateChange'**. The event can be listened for when a session is created.| 7580| callback | AsyncCallback\<[FocusState](#focusstate)\> | No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('error') with the specified callback is canceled. (The callback object cannot be an anonymous function.) | 7581 7582**Example** 7583 7584```ts 7585function unregisterFocusStateChange(nightPhotoSession: camera.NightPhotoSession): void { 7586 nightPhotoSession.off('focusStateChange'); 7587} 7588``` 7589 7590### on('smoothZoomInfoAvailable')<sup>11+</sup> 7591 7592on(type: 'smoothZoomInfoAvailable', callback: AsyncCallback\<SmoothZoomInfo\>): void 7593 7594Subscribes to smooth zoom state change events. This API uses an asynchronous callback to return the result. 7595 7596**System API**: This is a system API. 7597 7598**System capability**: SystemCapability.Multimedia.Camera.Core 7599 7600**Parameters** 7601 7602| Name | Type | Mandatory| Description | 7603| -------- | ----------------------- | ---- | ------------------------ | 7604| type | string | Yes | Event type. The value is fixed at **'smoothZoomInfoAvailable'**. The event can be listened for when a session is created.| 7605| callback | AsyncCallback\<[SmoothZoomInfo](#smoothzoominfo11)\> | Yes | Callback used to return the smooth zoom state change. | 7606 7607**Example** 7608 7609```ts 7610import { BusinessError } from '@ohos.base'; 7611 7612function callback(err: BusinessError, smoothZoomInfo: camera.SmoothZoomInfo): void { 7613 console.info(`The duration of smooth zoom: ${smoothZoomInfo.duration}`); 7614} 7615 7616function registerSmoothZoomInfo(nightPhotoSession: camera.NightPhotoSession): void { 7617 nightPhotoSession.on('smoothZoomInfoAvailable', callback); 7618} 7619``` 7620 7621### off('smoothZoomInfoAvailable')<sup>11+</sup> 7622 7623off(type: 'smoothZoomInfoAvailable', callback?: AsyncCallback\<SmoothZoomInfo\>): void 7624 7625Unsubscribes from smooth zoom state change events. 7626 7627**System API**: This is a system API. 7628 7629**System capability**: SystemCapability.Multimedia.Camera.Core 7630 7631**Parameters** 7632 7633| Name | Type | Mandatory| Description | 7634| -------- | ----------------------------------------- | ---- | ------------------------ | 7635| type | string | Yes | Event type. The value is fixed at **'smoothZoomInfoAvailable'**. The event can be listened for when a session is created.| 7636| callback | AsyncCallback\<[SmoothZoomInfo](#smoothzoominfo11)\> | No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('error') with the specified callback is canceled. (The callback object cannot be an anonymous function.) | 7637 7638**Example** 7639 7640```ts 7641function unregisterSmoothZoomInfo(nightPhotoSession: camera.NightPhotoSession): void { 7642 nightPhotoSession.off('smoothZoomInfoAvailable'); 7643} 7644``` 7645 7646## SketchStatusData<sup>11+</sup> 7647 7648Defines the PiP status data. 7649 7650**System API**: This is a system API. 7651 7652**System capability**: SystemCapability.Multimedia.Camera.Core 7653 7654| Name | Type | Mandatory| Description | 7655| -------------- | ------------------ | ---- | ---------- | 7656| status | number | Yes | Status of PiP. The options are 0 (stopped), 1 (started), 2 (stopping), and 3 (starting).| 7657| sketchRatio | number | Yes | Zoom ratio of PiP.| 7658