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