1# Interface (PhotoOutput) 2<!--Kit: Camera Kit--> 3<!--Subsystem: Multimedia--> 4<!--Owner: @qano--> 5<!--SE: @leo_ysl--> 6<!--TSE: @xchaosioda--> 7 8> **NOTE** 9> 10> 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. 11 12PhotoOutput implements output information used in a photo session. It inherits from [CameraOutput](arkts-apis-camera-CameraOutput.md). 13 14## Modules to Import 15 16```ts 17import { camera } from '@kit.CameraKit'; 18``` 19 20## capture 21 22capture(callback: AsyncCallback\<void\>): void 23 24Captures a photo with the default photo capture parameters. This API uses an asynchronous callback to return the result. 25 26**Atomic service API**: This API can be used in atomic services since API version 19. 27 28**System capability**: SystemCapability.Multimedia.Camera.Core 29 30**Parameters** 31 32| Name | Type | Mandatory| Description | 33| -------- | -------------------- | ---- | ------------------- | 34| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](arkts-apis-camera-e.md#cameraerrorcode) is returned.| 35 36**Error codes** 37 38For details about the error codes, see [Camera Error Codes](errorcode-camera.md). 39 40| ID | Error Message | 41| --------------- | --------------- | 42| 7400104 | Session not running. | 43| 7400201 | Camera service fatal error. | 44 45**Example** 46 47```ts 48import { BusinessError } from '@kit.BasicServicesKit'; 49 50function capture(photoOutput: camera.PhotoOutput): void { 51 photoOutput.capture((err: BusinessError) => { 52 if (err) { 53 console.error(`Failed to capture the photo, error code: ${err.code}.`); 54 return; 55 } 56 console.info('Callback invoked to indicate the photo capture request success.'); 57 }); 58} 59``` 60 61## capture 62 63capture(): Promise\<void\> 64 65Captures a photo with the default photo capture parameters. This API uses a promise to return the result. 66 67**Atomic service API**: This API can be used in atomic services since API version 19. 68 69**System capability**: SystemCapability.Multimedia.Camera.Core 70 71**Return value** 72 73| Type | Description | 74| -------------- | ------------------------ | 75| Promise\<void\> | Promise that returns no value.| 76 77**Error codes** 78 79For details about the error codes, see [Camera Error Codes](errorcode-camera.md). 80 81| ID | Error Message | 82| --------------- | --------------- | 83| 7400104 | Session not running. | 84| 7400201 | Camera service fatal error. | 85 86**Example** 87 88```ts 89import { BusinessError } from '@kit.BasicServicesKit'; 90 91function capture(photoOutput: camera.PhotoOutput): void { 92 photoOutput.capture().then(() => { 93 console.info('Promise returned to indicate that photo capture request success.'); 94 }).catch((error: BusinessError) => { 95 console.error(`Failed to photo output capture, error code: ${error.code}.`); 96 }); 97} 98``` 99 100## capture 101 102capture(setting: PhotoCaptureSetting, callback: AsyncCallback\<void\>): void 103 104Captures a photo with the specified photo capture parameters. This API uses an asynchronous callback to return the result. 105 106**Atomic service API**: This API can be used in atomic services since API version 19. 107 108**System capability**: SystemCapability.Multimedia.Camera.Core 109 110**Parameters** 111 112| Name | Type | Mandatory| Description | 113| -------- | ------------------------------------------- | ---- | -------------------- | 114| setting | [PhotoCaptureSetting](arkts-apis-camera-i.md#photocapturesetting) | Yes | Photo capture settings. | 115| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](arkts-apis-camera-e.md#cameraerrorcode) is returned. | 116 117**Error codes** 118 119For details about the error codes, see [Camera Error Codes](errorcode-camera.md). 120 121| ID | Error Message | 122| --------------- | --------------- | 123| 7400101 | Parameter missing or parameter type incorrect. | 124| 7400104 | Session not running. | 125| 7400201 | Camera service fatal error. | 126 127**Example** 128 129```ts 130import { BusinessError } from '@kit.BasicServicesKit'; 131 132function capture(photoOutput: camera.PhotoOutput): void { 133 let captureLocation: camera.Location = { 134 latitude: 0, 135 longitude: 0, 136 altitude: 0 137 } 138 let settings: camera.PhotoCaptureSetting = { 139 quality: camera.QualityLevel.QUALITY_LEVEL_LOW, 140 rotation: camera.ImageRotation.ROTATION_0, 141 location: captureLocation, 142 mirror: false 143 } 144 photoOutput.capture(settings, (err: BusinessError) => { 145 if (err) { 146 console.error(`Failed to capture the photo, error code: ${err.code}.`); 147 return; 148 } 149 console.info('Callback invoked to indicate the photo capture request success.'); 150 }); 151} 152``` 153 154## capture 155 156capture(setting: PhotoCaptureSetting): Promise\<void\> 157 158Captures a photo with the specified photo capture parameters. This API uses a promise to return the result. 159 160**Atomic service API**: This API can be used in atomic services since API version 19. 161 162**System capability**: SystemCapability.Multimedia.Camera.Core 163 164**Parameters** 165 166| Name | Type | Mandatory| Description | 167| ------- | ------------------------------------------- | ---- | -------- | 168| setting | [PhotoCaptureSetting](arkts-apis-camera-i.md#photocapturesetting) | Yes | Photo capture parameters. The input of **undefined** is processed as if no parameters were passed.| 169 170**Return value** 171 172| Type | Description | 173| -------------- | ------------------------ | 174| Promise\<void\> | Promise that returns no value.| 175 176**Error codes** 177 178For details about the error codes, see [Camera Error Codes](errorcode-camera.md). 179 180| ID | Error Message | 181| --------------- | --------------- | 182| 7400101 | Parameter missing or parameter type incorrect. | 183| 7400104 | Session not running. | 184| 7400201 | Camera service fatal error. | 185 186**Example** 187 188```ts 189import { BusinessError } from '@kit.BasicServicesKit'; 190 191function capture(photoOutput: camera.PhotoOutput): void { 192 let captureLocation: camera.Location = { 193 latitude: 0, 194 longitude: 0, 195 altitude: 0 196 } 197 let settings: camera.PhotoCaptureSetting = { 198 quality: camera.QualityLevel.QUALITY_LEVEL_LOW, 199 rotation: camera.ImageRotation.ROTATION_0, 200 location: captureLocation, 201 mirror: false 202 } 203 photoOutput.capture(settings).then(() => { 204 console.info('Promise returned to indicate that photo capture request success.'); 205 }).catch((error: BusinessError) => { 206 console.error(`Failed to photo output capture, error code: ${error.code}.`); 207 }); 208} 209``` 210 211## on('photoAvailable')<sup>11+</sup> 212 213on(type: 'photoAvailable', callback: AsyncCallback\<Photo\>): void 214 215Subscribes to events indicating available high-resolution images. This API uses an asynchronous callback to return the result. 216 217> **NOTE** 218> 219> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**. 220 221**Atomic service API**: This API can be used in atomic services since API version 19. 222 223**System capability**: SystemCapability.Multimedia.Camera.Core 224 225**Parameters** 226 227| Name | Type | Mandatory| Description | 228| -------- | ---------- | --- | ------------------------------------ | 229| type | string | Yes | Event type. The value is fixed at **'photoAvailable'**. The event can be listened for when a photoOutput instance is created.| 230| callback | AsyncCallback\<[Photo](arkts-apis-camera-Photo.md)\> | Yes | Callback used to return the high-resolution image.| 231 232**Example** 233 234```ts 235import { BusinessError } from '@kit.BasicServicesKit'; 236import { image } from '@kit.ImageKit'; 237 238function callback(err: BusinessError, photo: camera.Photo): void { 239 if (err !== undefined && err.code !== 0) { 240 console.error(`Callback Error, errorCode: ${err.code}`); 241 return; 242 } 243 let mainImage: image.Image = photo.main; 244} 245 246function registerPhotoOutputPhotoAvailable(photoOutput: camera.PhotoOutput): void { 247 photoOutput.on('photoAvailable', callback); 248} 249``` 250 251## off('photoAvailable')<sup>11+</sup> 252 253off(type: 'photoAvailable', callback?: AsyncCallback\<Photo\>): void 254 255Unsubscribes from events indicating available high-resolution images. 256 257**Atomic service API**: This API can be used in atomic services since API version 19. 258 259**System capability**: SystemCapability.Multimedia.Camera.Core 260 261**Parameters** 262 263| Name | Type | Mandatory| Description | 264| -------- | ---------------------- | ---- | ------------------------------------------ | 265| type | string | Yes | Event type. The value is fixed at **'photoAvailable'**. The event can be listened for when a photoOutput instance is created.| 266| callback | AsyncCallback\<[Photo](arkts-apis-camera-Photo.md)\> | 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.| 267 268**Example** 269 270```ts 271import { BusinessError } from '@kit.BasicServicesKit'; 272import { image } from '@kit.ImageKit'; 273 274function callback(err: BusinessError, photo: camera.Photo): void { 275 if (err !== undefined && err.code !== 0) { 276 console.error(`Callback Error, errorCode: ${err.code}`); 277 return; 278 } 279 let mainImage: image.Image = photo.main; 280} 281 282function unRegisterPhotoOutputPhotoAvailable(photoOutput: camera.PhotoOutput): void { 283 photoOutput.off('photoAvailable', callback); 284} 285``` 286 287## on('captureStartWithInfo')<sup>11+</sup> 288 289on(type: 'captureStartWithInfo', callback: AsyncCallback\<CaptureStartInfo\>): void 290 291Subscribes to capture start events. This API uses an asynchronous callback to return the result. 292 293> **NOTE** 294> 295> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**. 296 297**Atomic service API**: This API can be used in atomic services since API version 19. 298 299**System capability**: SystemCapability.Multimedia.Camera.Core 300 301**Parameters** 302 303| Name | Type | Mandatory| Description | 304| -------- | ---------- | --- | ------------------------------------ | 305| type | string | Yes | Event type. The value is fixed at **'captureStartWithInfo'**. The event can be listened for when a photoOutput instance is created.| 306| callback | AsyncCallback\<[CaptureStartInfo](arkts-apis-camera-i.md#capturestartinfo11)\> | Yes | Callback used to return the capture ID.| 307 308**Example** 309 310```ts 311import { BusinessError } from '@kit.BasicServicesKit'; 312 313function callback(err: BusinessError, captureStartInfo: camera.CaptureStartInfo): void { 314 if (err !== undefined && err.code !== 0) { 315 console.error(`Callback Error, errorCode: ${err.code}`); 316 return; 317 } 318 console.info(`photo capture started, captureStartInfo : ${captureStartInfo}`); 319} 320 321function registerCaptureStartWithInfo(photoOutput: camera.PhotoOutput): void { 322 photoOutput.on('captureStartWithInfo', callback); 323} 324``` 325 326## off('captureStartWithInfo')<sup>11+</sup> 327 328off(type: 'captureStartWithInfo', callback?: AsyncCallback\<CaptureStartInfo\>): void 329 330Unsubscribes from capture start events. 331 332**Atomic service API**: This API can be used in atomic services since API version 19. 333 334**System capability**: SystemCapability.Multimedia.Camera.Core 335 336**Parameters** 337 338| Name | Type | Mandatory| Description | 339| -------- | ---------------------- | ---- | ------------------------------------------ | 340| type | string | Yes | Event type. The value is fixed at **'captureStartWithInfo'**. The event can be listened for when a photoOutput instance is created.| 341| callback | AsyncCallback\<[CaptureStartInfo](arkts-apis-camera-i.md#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.| 342 343**Example** 344 345```ts 346import { BusinessError } from '@kit.BasicServicesKit'; 347 348function unRegisterCaptureStartWithInfo(photoOutput: camera.PhotoOutput): void { 349 photoOutput.off('captureStartWithInfo'); 350} 351``` 352 353## isMovingPhotoSupported<sup>12+</sup> 354 355isMovingPhotoSupported(): boolean 356 357Checks whether taking moving photos is supported. 358 359**Atomic service API**: This API can be used in atomic services since API version 19. 360 361**System capability**: SystemCapability.Multimedia.Camera.Core 362 363**Return value** 364 365| Type | Description | 366| -------------- | ----------------------- | 367| boolean | Check result for the support of taking moving photos. **true** if supported, **false** otherwise.| 368 369**Error codes** 370 371For details about the error codes, see [Camera Error Codes](errorcode-camera.md). 372 373| ID | Error Message | 374| -------------- | --------------- | 375| 7400201 | Camera service fatal error. | 376 377**Example** 378 379```ts 380import { BusinessError } from '@kit.BasicServicesKit'; 381 382function isMovingPhotoSupported(photoOutput: camera.PhotoOutput): boolean { 383 let isSupported: boolean = false; 384 try { 385 isSupported = photoOutput.isMovingPhotoSupported(); 386 } catch (error) { 387 // If the operation fails, error.code is returned and processed. 388 let err = error as BusinessError; 389 console.error(`The isMovingPhotoSupported call failed. error code: ${err.code}`); 390 } 391 return isSupported; 392} 393``` 394 395## enableMovingPhoto<sup>12+</sup> 396 397enableMovingPhoto(enabled: boolean): void 398 399Enables or disables the feature of taking moving photos. 400 401**Required permissions:** ohos.permission.MICROPHONE 402 403**Atomic service API**: This API can be used in atomic services since API version 19. 404 405**System capability**: SystemCapability.Multimedia.Camera.Core 406 407**Parameters** 408 409| Name | Type | Mandatory| Description | 410| -------- | ---------------------- | ---- | ------------------------------------------ | 411| enabled | boolean | Yes | Whether to enable the feature of taking moving photos. **true** to enable, **false** otherwise. | 412 413**Error codes** 414 415For details about the error codes, see [Camera Error Codes](errorcode-camera.md). 416 417| ID | Error Message | 418| -------- |------------------------------------------------| 419| 201 | permission denied. | 420| 7400101 | Parameter missing or parameter type incorrect. | 421| 7400201 | Camera service fatal error. | 422 423**Example** 424 425```ts 426import { BusinessError } from '@kit.BasicServicesKit'; 427 428function enableMovingPhoto(photoOutput: camera.PhotoOutput): void { 429 try { 430 photoOutput.enableMovingPhoto(true); 431 } catch (error) { 432 // If the operation fails, error.code is returned and processed. 433 let err = error as BusinessError; 434 console.error(`The enableMovingPhoto call failed. error code: ${err.code}`); 435 } 436} 437``` 438 439## on('photoAssetAvailable')<sup>12+</sup> 440 441on(type: 'photoAssetAvailable', callback: AsyncCallback\<photoAccessHelper.PhotoAsset\>): void 442 443Subscribes to photo asset available events. This API uses an asynchronous callback to return the result. 444 445> **NOTE** 446> 447> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**. 448 449**Atomic service API**: This API can be used in atomic services since API version 19. 450 451**System capability**: SystemCapability.Multimedia.Camera.Core 452 453**Parameters** 454 455| Name | Type | Mandatory| Description | 456| -------- | ---------- | --- | ------------------------------------ | 457| type | string | Yes | Event type. The value is fixed at **'photoAssetAvailable'**. The event can be listened for when a photoOutput instance is created.| 458| callback | AsyncCallback\<[photoAccessHelper.PhotoAsset](../apis-media-library-kit/arkts-apis-photoAccessHelper-PhotoAsset.md)\> | Yes | Callback used to return the photo asset.| 459 460**Example** 461 462```ts 463import { BusinessError } from '@kit.BasicServicesKit'; 464import { photoAccessHelper } from '@kit.MediaLibraryKit'; 465 466function photoAssetAvailableCallback(err: BusinessError, photoAsset: photoAccessHelper.PhotoAsset): void { 467 if (err) { 468 console.info(`photoAssetAvailable error: ${JSON.stringify(err)}.`); 469 return; 470 } 471 console.info('photoOutPutCallBack photoAssetAvailable'); 472 // You can use photoAsset to obtain image information. 473} 474 475function onPhotoOutputPhotoAssetAvailable(photoOutput: camera.PhotoOutput): void { 476 photoOutput.on('photoAssetAvailable', photoAssetAvailableCallback); 477} 478``` 479 480## off('photoAssetAvailable')<sup>12+</sup> 481 482off(type: 'photoAssetAvailable', callback?: AsyncCallback\<photoAccessHelper.PhotoAsset\>): void 483 484Unsubscribes from photo asset available events. 485 486**Atomic service API**: This API can be used in atomic services since API version 19. 487 488**System capability**: SystemCapability.Multimedia.Camera.Core 489 490**Parameters** 491 492| Name | Type | Mandatory | Description | 493| -------- | ---------- |-----|----------------------------------------------------------------------------| 494| type | string | Yes | Event type. The value is fixed at **'photoAssetAvailable'**. The event can be listened for when a photoOutput instance is created. | 495| callback | AsyncCallback\<[photoAccessHelper.PhotoAsset](../apis-media-library-kit/arkts-apis-photoAccessHelper-PhotoAsset.md)\> | 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.| 496 497**Example** 498 499```ts 500function offPhotoOutputPhotoAssetAvailable(photoOutput: camera.PhotoOutput): void { 501 photoOutput.off('photoAssetAvailable'); 502} 503``` 504 505## isMirrorSupported 506 507isMirrorSupported(): boolean 508 509Checks whether mirror photography is supported. 510 511**Atomic service API**: This API can be used in atomic services since API version 19. 512 513**System capability**: SystemCapability.Multimedia.Camera.Core 514 515**Return value** 516 517| Type | Description | 518| -------------- | ----------------------- | 519| boolean | Check result for the support of mirror photography. **true** if supported, **false** otherwise.| 520 521**Example** 522 523```ts 524function isMirrorSupported(photoOutput: camera.PhotoOutput): boolean { 525 let isSupported: boolean = photoOutput.isMirrorSupported(); 526 return isSupported; 527} 528``` 529 530## enableMirror<sup>13+</sup> 531 532enableMirror(enabled: boolean): void 533 534Enables dynamic photo capture. 535 536Before calling this API, check whether dynamic photo capture is supported by calling [isMovingPhotoSupported](#ismovingphotosupported12) and whether mirroring is supported by calling [isMirrorSupported](#ismirrorsupported). 537 538**Atomic service API**: This API can be used in atomic services since API version 19. 539 540**System capability**: SystemCapability.Multimedia.Camera.Core 541 542**Parameters** 543 544| Name | Type | Mandatory| Description | 545|----------| ---------------------- | ---- |---------------------------| 546| enabled | boolean | Yes | Whether to enable or disable dynamic photo capture. **true** to enable, **false** otherwise.| 547 548**Error codes** 549 550For details about the error codes, see [Camera Error Codes](errorcode-camera.md). 551 552| ID | Error Message | 553| -------- |------------------------------------------------| 554| 7400101 | Parameter missing or parameter type incorrect. | 555| 7400103 | Session not config. | 556| 7400201 | Camera service fatal error. | 557 558 559**Example** 560 561```ts 562import { BusinessError } from '@kit.BasicServicesKit'; 563 564function enableMirror(photoOutput: camera.PhotoOutput): void { 565 try { 566 photoOutput.enableMirror(true); 567 } catch (error) { 568 // If the operation fails, error.code is returned and processed. 569 let err = error as BusinessError; 570 console.error(`The enableMirror call failed. error code: ${err.code}`); 571 } 572} 573``` 574 575## getSupportedMovingPhotoVideoCodecTypes<sup>13+</sup> 576 577getSupportedMovingPhotoVideoCodecTypes(): Array\<VideoCodecType\> 578 579Obtains the supported video codec types of moving photos. 580 581**Atomic service API**: This API can be used in atomic services since API version 19. 582 583**System capability**: SystemCapability.Multimedia.Camera.Core 584 585**Return value** 586 587| Type | Description | 588| -------------- |-------------------| 589| Array\<[VideoCodecType](arkts-apis-camera-e.md#videocodectype13)\> | Array holding the supported video codec types.| 590 591**Error codes** 592 593For details about the error codes, see [Camera Error Codes](errorcode-camera.md). 594 595| ID | Error Message | 596| --------------- | --------------- | 597| 7400201 | Camera service fatal error. | 598 599**Example** 600 601```ts 602function getSupportedMovingPhotoVideoCodecType(photoOutput: camera.PhotoOutput): Array<camera.VideoCodecType> { 603 let supportedVideoCodecTypesArray: Array<camera.VideoCodecType> = photoOutput.getSupportedMovingPhotoVideoCodecTypes(); 604 return supportedVideoCodecTypesArray; 605} 606``` 607 608## setMovingPhotoVideoCodecType<sup>13+</sup> 609 610setMovingPhotoVideoCodecType(codecType: VideoCodecType): void 611 612Sets a video codec type for moving photos. 613 614**Atomic service API**: This API can be used in atomic services since API version 19. 615 616**System capability**: SystemCapability.Multimedia.Camera.Core 617 618**Parameters** 619 620| Name | Type | Mandatory| Description | 621| ------------- |-------------------------------------|-------| ------------ | 622| codecType | [VideoCodecType](arkts-apis-camera-e.md#videocodectype13) | Yes |Video codec type. | 623 624**Error codes** 625 626For details about the error codes, see [Camera Error Codes](errorcode-camera.md). 627 628| ID | Error Message | 629| --------------- | --------------- | 630| 7400201 | Camera service fatal error. | 631 632**Example** 633 634```ts 635function setMovingPhotoVideoCodecTypes(photoOutput: camera.PhotoOutput, videoCodecType: camera.VideoCodecType): void { 636 photoOutput.setMovingPhotoVideoCodecType(videoCodecType); 637} 638``` 639 640## on('frameShutter') 641 642on(type: 'frameShutter', callback: AsyncCallback\<FrameShutterInfo\>): void 643 644Subscribes to frame shutter events. This API uses an asynchronous callback to return the result. 645 646**Atomic service API**: This API can be used in atomic services since API version 19. 647 648**System capability**: SystemCapability.Multimedia.Camera.Core 649 650**Parameters** 651 652| Name | Type | Mandatory| Description | 653| -------- | ---------- | --- | ------------------------------------ | 654| type | string | Yes | Event type. The value is fixed at **'frameShutter'**. The event can be listened for when a photoOutput instance is created.| 655| callback | AsyncCallback\<[FrameShutterInfo](arkts-apis-camera-i.md#frameshutterinfo)\> | Yes | Callback used to return the result. A new photo capture request can be delivered as long as this event is returned. | 656 657**Example** 658 659```ts 660import { BusinessError } from '@kit.BasicServicesKit'; 661 662function callback(err: BusinessError, frameShutterInfo: camera.FrameShutterInfo): void { 663 if (err !== undefined && err.code !== 0) { 664 console.error(`Callback Error, errorCode: ${err.code}`); 665 return; 666 } 667 console.info(`CaptureId for frame : ${frameShutterInfo.captureId}`); 668 console.info(`Timestamp for frame : ${frameShutterInfo.timestamp}`); 669} 670 671function registerPhotoOutputFrameShutter(photoOutput: camera.PhotoOutput): void { 672 photoOutput.on('frameShutter', callback); 673} 674``` 675 676## off('frameShutter') 677 678off(type: 'frameShutter', callback?: AsyncCallback\<FrameShutterInfo\>): void 679 680Unsubscribes from frame shutter events. 681 682**Atomic service API**: This API can be used in atomic services since API version 19. 683 684**System capability**: SystemCapability.Multimedia.Camera.Core 685 686**Parameters** 687 688| Name | Type | Mandatory| Description | 689| -------- | ---------- | --- | ------------------------------------ | 690| type | string | Yes | Event type. The value is fixed at **'frameShutter'**. The event can be listened for when a photoOutput instance is created.| 691| callback | AsyncCallback\<[FrameShutterInfo](arkts-apis-camera-i.md#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.| 692 693**Example** 694 695```ts 696function unregisterPhotoOutputFrameShutter(photoOutput: camera.PhotoOutput): void { 697 photoOutput.off('frameShutter'); 698} 699``` 700 701## on('captureEnd') 702 703on(type: 'captureEnd', callback: AsyncCallback\<CaptureEndInfo\>): void 704 705Subscribes to capture end events. This API uses an asynchronous callback to return the result. 706 707> **NOTE** 708> 709> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**. 710 711**Atomic service API**: This API can be used in atomic services since API version 19. 712 713**System capability**: SystemCapability.Multimedia.Camera.Core 714 715**Parameters** 716 717| Name | Type | Mandatory| Description | 718| -------- | --------------- | ---- | ---------------------------------------- | 719| 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 photo capture is complete.| 720| callback | AsyncCallback\<[CaptureEndInfo](arkts-apis-camera-i.md#captureendinfo)\> | Yes | Callback used to return the result. | 721 722**Example** 723 724```ts 725import { BusinessError } from '@kit.BasicServicesKit'; 726 727function callback(err: BusinessError, captureEndInfo: camera.CaptureEndInfo): void { 728 if (err !== undefined && err.code !== 0) { 729 console.error(`Callback Error, errorCode: ${err.code}`); 730 return; 731 } 732 console.info(`photo capture end, captureId : ${captureEndInfo.captureId}`); 733 console.info(`frameCount : ${captureEndInfo.frameCount}`); 734} 735 736function registerPhotoOutputCaptureEnd(photoOutput: camera.PhotoOutput): void { 737 photoOutput.on('captureEnd', callback); 738} 739``` 740 741## off('captureEnd') 742 743off(type: 'captureEnd', callback?: AsyncCallback\<CaptureEndInfo\>): void 744 745Unsubscribes from capture end events. 746 747**Atomic service API**: This API can be used in atomic services since API version 19. 748 749**System capability**: SystemCapability.Multimedia.Camera.Core 750 751**Parameters** 752 753| Name | Type | Mandatory| Description | 754| -------- | --------------- | ---- | ---------------------------------------- | 755| type | string | Yes | Event type. The value is fixed at **'captureEnd'**. The event can be listened for when a photoOutput instance is created.| 756| callback | AsyncCallback\<[CaptureEndInfo](arkts-apis-camera-i.md#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.| 757 758**Example** 759 760```ts 761function unregisterPhotoOutputCaptureEnd(photoOutput: camera.PhotoOutput): void { 762 photoOutput.off('captureEnd'); 763} 764``` 765 766## on('frameShutterEnd')<sup>12+</sup> 767 768on(type: 'frameShutterEnd', callback: AsyncCallback\<FrameShutterEndInfo\>): void 769 770Subscribes to frame shutter end events. This API uses an asynchronous callback to return the result. 771 772> **NOTE** 773> 774> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**. 775 776**Atomic service API**: This API can be used in atomic services since API version 19. 777 778**System capability**: SystemCapability.Multimedia.Camera.Core 779 780**Parameters** 781 782| Name | Type | Mandatory| Description | 783| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 784| type | string | Yes | Event type. The value is fixed at **'frameShutterEnd'**. The event can be listened for when a photoOutput instance is created.| 785| callback | AsyncCallback\<[FrameShutterEndInfo](arkts-apis-camera-i.md#frameshutterendinfo12)\> | Yes | Callback used to return the result. It is invoked when the frame shutter ends. | 786 787**Example** 788 789```ts 790import { BusinessError } from '@kit.BasicServicesKit'; 791 792function callback(err: BusinessError, frameShutterEndInfo: camera.FrameShutterEndInfo): void { 793 if (err !== undefined && err.code !== 0) { 794 console.error(`Callback Error, errorCode: ${err.code}`); 795 return; 796 } 797 console.info(`CaptureId for frame : ${frameShutterEndInfo.captureId}`); 798} 799 800function registerPhotoOutputFrameShutterEnd(photoOutput: camera.PhotoOutput): void { 801 photoOutput.on('frameShutterEnd', callback); 802} 803``` 804 805## off('frameShutterEnd')<sup>12+</sup> 806 807off(type: 'frameShutterEnd', callback?: AsyncCallback\<FrameShutterEndInfo\>): void 808 809Unsubscribes from frame shutter end events. 810 811**Atomic service API**: This API can be used in atomic services since API version 19. 812 813**System capability**: SystemCapability.Multimedia.Camera.Core 814 815**Parameters** 816 817| Name | Type | Mandatory| Description | 818| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 819| type | string | Yes | Event type. The value is fixed at **'frameShutterEnd'**. The event can be listened for when a photoOutput instance is created.| 820| callback | AsyncCallback\<[FrameShutterEndInfo](arkts-apis-camera-i.md#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.| 821 822**Example** 823 824```ts 825function unregisterPhotoOutputFrameShutterEnd(photoOutput: camera.PhotoOutput): void { 826 photoOutput.off('frameShutterEnd'); 827} 828``` 829 830## on('captureReady')<sup>12+</sup> 831 832on(type: 'captureReady', callback: AsyncCallback\<void\>): void 833 834Subscribes to capture ready events. This API uses an asynchronous callback to return the result. 835 836> **NOTE** 837> 838> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**. 839 840**Atomic service API**: This API can be used in atomic services since API version 19. 841 842**System capability**: SystemCapability.Multimedia.Camera.Core 843 844**Parameters** 845 846| Name | Type | Mandatory| Description | 847| -------- | --------------------- | ---- | ------------------------------------------------------------ | 848| 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.| 849| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. | 850 851**Example** 852 853```ts 854import { BusinessError } from '@kit.BasicServicesKit'; 855 856function callback(err: BusinessError): void { 857 if (err !== undefined && err.code !== 0) { 858 console.error(`Callback Error, errorCode: ${err.code}`); 859 return; 860 } 861 console.info(`photo capture ready`); 862} 863 864function registerPhotoOutputCaptureReady(photoOutput: camera.PhotoOutput): void { 865 photoOutput.on('captureReady', callback); 866} 867``` 868 869## off('captureReady')<sup>12+</sup> 870 871off(type: 'captureReady', callback?: AsyncCallback\<void\>): void 872 873Unsubscribes from capture ready events. 874 875**Atomic service API**: This API can be used in atomic services since API version 19. 876 877**System capability**: SystemCapability.Multimedia.Camera.Core 878 879**Parameters** 880 881| Name | Type | Mandatory| Description | 882| -------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------ | 883| type | string | Yes | Event type. The value is fixed at **'captureReady'**. The event can be listened for when a photoOutput instance is created.| 884| 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.| 885 886**Example** 887 888```ts 889function unregisterPhotoOutputCaptureReady(photoOutput: camera.PhotoOutput): void { 890 photoOutput.off('captureReady'); 891} 892``` 893 894## on('estimatedCaptureDuration')<sup>12+</sup> 895 896on(type: 'estimatedCaptureDuration', callback: AsyncCallback\<number\>): void 897 898Subscribes to estimated capture duration events. This API uses an asynchronous callback to return the result. 899 900> **NOTE** 901> 902> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**. 903 904**Atomic service API**: This API can be used in atomic services since API version 19. 905 906**System capability**: SystemCapability.Multimedia.Camera.Core 907 908**Parameters** 909 910| Name | Type | Mandatory| Description | 911| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 912| 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 photo capture is complete.| 913| 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. | 914 915**Example** 916 917```ts 918import { BusinessError } from '@kit.BasicServicesKit'; 919 920function callback(err: BusinessError, duration: number): void { 921 if (err !== undefined && err.code !== 0) { 922 console.error(`Callback Error, errorCode: ${err.code}`); 923 return; 924 } 925 console.info(`photo estimated capture duration : ${duration}`); 926} 927 928function registerPhotoOutputEstimatedCaptureDuration(photoOutput: camera.PhotoOutput): void { 929 photoOutput.on('estimatedCaptureDuration', callback); 930} 931``` 932 933## off('estimatedCaptureDuration')<sup>12+</sup> 934 935off(type: 'estimatedCaptureDuration', callback?: AsyncCallback\<number\>): void 936 937Unsubscribes from estimated capture duration events. 938 939**Atomic service API**: This API can be used in atomic services since API version 19. 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 **'estimatedCaptureDuration'**. The event can be listened for when a photoOutput instance is created.| 948| 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.| 949 950**Example** 951 952```ts 953function unregisterPhotoOutputEstimatedCaptureDuration(photoOutput: camera.PhotoOutput): void { 954 photoOutput.off('estimatedCaptureDuration'); 955} 956``` 957 958## on('error') 959 960on(type: 'error', callback: ErrorCallback): void 961 962Subscribes to PhotoOutput error events. This API uses an asynchronous callback to return the result. 963 964> **NOTE** 965> 966> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**. 967 968**Atomic service API**: This API can be used in atomic services since API version 19. 969 970**System capability**: SystemCapability.Multimedia.Camera.Core 971 972**Parameters** 973 974| Name | Type | Mandatory| Description | 975| -------- | ------------- | ---- | ----------------------------------- | 976| 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.| 977| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | Yes | Callback used to return an error code defined in [CameraErrorCode](arkts-apis-camera-e.md#cameraerrorcode). | 978 979**Example** 980 981```ts 982import { BusinessError } from '@kit.BasicServicesKit'; 983 984function callback(err: BusinessError): void { 985 console.error(`Photo output error code: ${err.code}`); 986} 987 988function registerPhotoOutputError(photoOutput: camera.PhotoOutput): void { 989 photoOutput.on('error', callback); 990} 991``` 992 993## off('error') 994 995off(type: 'error', callback?: ErrorCallback): void 996 997Unsubscribes from PhotoOutput error events. 998 999**Atomic service API**: This API can be used in atomic services since API version 19. 1000 1001**System capability**: SystemCapability.Multimedia.Camera.Core 1002 1003**Parameters** 1004 1005| Name | Type | Mandatory| Description | 1006| -------- | ------------- | ---- | ----------------------------------- | 1007| type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a photoOutput instance is created.| 1008| 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.| 1009 1010**Example** 1011 1012```ts 1013function unregisterPhotoOutputError(photoOutput: camera.PhotoOutput): void { 1014 photoOutput.off('error'); 1015} 1016``` 1017 1018## getActiveProfile<sup>12+</sup> 1019 1020getActiveProfile(): Profile 1021 1022Obtains the profile that takes effect currently. 1023 1024**Atomic service API**: This API can be used in atomic services since API version 19. 1025 1026**System capability**: SystemCapability.Multimedia.Camera.Core 1027 1028**Return value** 1029 1030| Type | Description | 1031| ------------- |-----------| 1032| [Profile](arkts-apis-camera-i.md#profile) | Profile obtained.| 1033 1034**Error codes** 1035 1036For details about the error codes, see [Camera Error Codes](errorcode-camera.md). 1037 1038| ID | Error Message | 1039|---------|------------------------------| 1040| 7400201 | Camera service fatal error. | 1041 1042**Example** 1043 1044```ts 1045import { BusinessError } from '@kit.BasicServicesKit'; 1046 1047function testGetActiveProfile(photoOutput: camera.PhotoOutput): camera.Profile | undefined { 1048 let activeProfile: camera.Profile | undefined = undefined; 1049 try { 1050 activeProfile = photoOutput.getActiveProfile(); 1051 } catch (error) { 1052 // If the operation fails, error.code is returned and processed. 1053 let err = error as BusinessError; 1054 console.error(`The photoOutput.getActiveProfile call failed. error code: ${err.code}`); 1055 } 1056 return activeProfile; 1057} 1058``` 1059 1060## getPhotoRotation<sup>12+</sup> 1061 1062getPhotoRotation(deviceDegree: number): ImageRotation 1063 1064Obtains the photo rotation degree. 1065 1066- Device' natural orientation: The default orientation of the device (phone) is in portrait mode, with the charging port facing downward. 1067- Camera lens angle: equivalent to the angle at which the camera is rotated clockwise to match the device's natural direction. The rear camera sensor of a phone is installed in landscape mode. Therefore, it needs to be rotated by 90 degrees clockwise to match the device's natural direction. 1068- 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. 1069 1070**Atomic service API**: This API can be used in atomic services since API version 19. 1071 1072**System capability**: SystemCapability.Multimedia.Camera.Core 1073 1074**Parameters** 1075 1076| Name | Type | Mandatory| Description | 1077| -------- | --------------| ---- | ------------------------ | 1078| deviceDegree | number | Yes | Rotation angle.| 1079 1080**Return value** 1081 1082| Type | Description | 1083| ------------- |-----------| 1084| [ImageRotation](arkts-apis-camera-e.md#imagerotation) | Photo rotation degree.| 1085 1086**Error codes** 1087 1088For details about the error codes, see [Camera Error Codes](errorcode-camera.md). 1089 1090| ID | Error Message | 1091|---------|------------------------------| 1092| 7400101 | Parameter missing or parameter type incorrect. | 1093| 7400201 | Camera service fatal error. | 1094 1095**Example** 1096 1097```ts 1098function testGetPhotoRotation(photoOutput: camera.PhotoOutput, deviceDegree : number): camera.ImageRotation { 1099 let photoRotation: camera.ImageRotation = camera.ImageRotation.ROTATION_0; 1100 try { 1101 photoRotation = photoOutput.getPhotoRotation(deviceDegree); 1102 console.log(`Photo rotation is: ${photoRotation}`); 1103 } catch (error) { 1104 // If the operation fails, error.code is returned and processed. 1105 let err = error as BusinessError; 1106 console.error(`The photoOutput.getPhotoRotation call failed. error code: ${err.code}`); 1107 } 1108 return photoRotation; 1109} 1110``` 1111 1112 1113## on('captureStart')<sup>(deprecated)</sup> 1114 1115on(type: 'captureStart', callback: AsyncCallback\<number\>): void 1116 1117Subscribes to capture start events. This API uses an asynchronous callback to return the result. 1118 1119> **NOTE** 1120> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [on('captureStartWithInfo')](#oncapturestartwithinfo11) instead. 1121> 1122> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**. 1123 1124**System capability**: SystemCapability.Multimedia.Camera.Core 1125 1126**Parameters** 1127 1128| Name | Type | Mandatory| Description | 1129| -------- | ---------------------- | ---- | ------------------------------------------ | 1130| 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.| 1131| callback | AsyncCallback\<number\> | Yes | Callback used to return the capture ID. | 1132 1133**Example** 1134 1135```ts 1136import { BusinessError } from '@kit.BasicServicesKit'; 1137 1138function callback(err: BusinessError, captureId: number): void { 1139 if (err !== undefined && err.code !== 0) { 1140 console.error(`Callback Error, errorCode: ${err.code}`); 1141 return; 1142 } 1143 console.info(`photo capture started, captureId : ${captureId}`); 1144} 1145 1146function registerPhotoOutputCaptureStart(photoOutput: camera.PhotoOutput): void { 1147 photoOutput.on('captureStart', callback); 1148} 1149``` 1150 1151## off('captureStart')<sup>(deprecated)</sup> 1152 1153off(type: 'captureStart', callback?: AsyncCallback\<number\>): void 1154 1155Unsubscribes from capture start events. 1156 1157> **NOTE** 1158> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [off('captureStartWithInfo')](#offcapturestartwithinfo11) instead. 1159> 1160> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**. 1161 1162**System capability**: SystemCapability.Multimedia.Camera.Core 1163 1164**Parameters** 1165 1166| Name | Type | Mandatory| Description | 1167| -------- | ---------------------- | ---- | ------------------------------------------ | 1168| type | string | Yes | Event type. The value is fixed at **'captureStart'**. The event can be listened for when a photoOutput instance is created.| 1169| 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.| 1170 1171**Example** 1172 1173```ts 1174function unregisterPhotoOutputCaptureStart(photoOutput: camera.PhotoOutput): void { 1175 photoOutput.off('captureStart'); 1176} 1177``` 1178