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