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