1# Interface (PhotoOutput) 2<!--Kit: Camera Kit--> 3<!--Subsystem: Multimedia--> 4<!--Owner: @qano--> 5<!--Designer: @leo_ysl--> 6<!--Tester: @xchaosioda--> 7<!--Adviser: @zengyawen--> 8 9> **说明:** 10> 11> 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 12 13拍照会话中使用的输出信息,继承[CameraOutput](arkts-apis-camera-CameraOutput.md)。 14 15## 导入模块 16 17```ts 18import { camera } from '@kit.CameraKit'; 19``` 20 21## capture 22 23capture(callback: AsyncCallback\<void\>): void 24 25以默认设置触发一次拍照,通过注册回调函数获取结果。使用callback异步回调。 26 27**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 28 29**系统能力:** SystemCapability.Multimedia.Camera.Core 30 31**参数:** 32 33| 参数名 | 类型 | 必填 | 说明 | 34| -------- | -------------------- | ---- | ------------------- | 35| callback | AsyncCallback\<void\> | 是 | 回调函数。当以默认设置触发拍照成功,err为undefined,否则为错误对象。错误码类型[CameraErrorCode](arkts-apis-camera-e.md#cameraerrorcode)。 | 36 37**错误码:** 38 39以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 40 41| 错误码ID | 错误信息 | 42| --------------- | --------------- | 43| 7400104 | Session not running. | 44| 7400201 | Camera service fatal error. | 45 46**示例:** 47 48```ts 49import { BusinessError } from '@kit.BasicServicesKit'; 50 51function capture(photoOutput: camera.PhotoOutput): void { 52 photoOutput.capture((err: BusinessError) => { 53 if (err) { 54 console.error(`Failed to capture the photo, error code: ${err.code}.`); 55 return; 56 } 57 console.info('Callback invoked to indicate the photo capture request success.'); 58 }); 59} 60``` 61 62## capture 63 64capture(): Promise\<void\> 65 66以默认设置触发一次拍照。使用Promise异步回调。 67 68**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 69 70**系统能力:** SystemCapability.Multimedia.Camera.Core 71 72**返回值:** 73 74| 类型 | 说明 | 75| -------------- | ------------------------ | 76| Promise\<void\> | Promise对象,无返回结果。 | 77 78**错误码:** 79 80以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 81 82| 错误码ID | 错误信息 | 83| --------------- | --------------- | 84| 7400104 | Session not running. | 85| 7400201 | Camera service fatal error. | 86 87**示例:** 88 89```ts 90import { BusinessError } from '@kit.BasicServicesKit'; 91 92function capture(photoOutput: camera.PhotoOutput): void { 93 photoOutput.capture().then(() => { 94 console.info('Promise returned to indicate that photo capture request success.'); 95 }).catch((error: BusinessError) => { 96 console.error(`Failed to photo output capture, error code: ${error.code}.`); 97 }); 98} 99``` 100 101## capture 102 103capture(setting: PhotoCaptureSetting, callback: AsyncCallback\<void\>): void 104 105以指定参数触发一次拍照,通过注册回调函数获取结果。使用callback异步回调。 106 107**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 108 109**系统能力:** SystemCapability.Multimedia.Camera.Core 110 111**参数:** 112 113| 参数名 | 类型 | 必填 | 说明 | 114| -------- | ------------------------------------------- | ---- | -------------------- | 115| setting | [PhotoCaptureSetting](arkts-apis-camera-i.md#photocapturesetting) | 是 | 拍照设置。 | 116| callback | AsyncCallback\<void\> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](arkts-apis-camera-e.md#cameraerrorcode)。 | 117 118**错误码:** 119 120以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 121 122| 错误码ID | 错误信息 | 123| --------------- | --------------- | 124| 7400101 | Parameter missing or parameter type incorrect. | 125| 7400104 | Session not running. | 126| 7400201 | Camera service fatal error. | 127 128**示例:** 129 130```ts 131import { BusinessError } from '@kit.BasicServicesKit'; 132 133function capture(photoOutput: camera.PhotoOutput): void { 134 let captureLocation: camera.Location = { 135 latitude: 0, 136 longitude: 0, 137 altitude: 0 138 } 139 let settings: camera.PhotoCaptureSetting = { 140 quality: camera.QualityLevel.QUALITY_LEVEL_LOW, 141 rotation: camera.ImageRotation.ROTATION_0, 142 location: captureLocation, 143 mirror: false 144 } 145 photoOutput.capture(settings, (err: BusinessError) => { 146 if (err) { 147 console.error(`Failed to capture the photo, error code: ${err.code}.`); 148 return; 149 } 150 console.info('Callback invoked to indicate the photo capture request success.'); 151 }); 152} 153``` 154 155## capture 156 157capture(setting: PhotoCaptureSetting): Promise\<void\> 158 159以指定参数触发一次拍照。使用Promise异步回调。 160 161**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 162 163**系统能力:** SystemCapability.Multimedia.Camera.Core 164 165**参数:** 166 167| 参数名 | 类型 | 必填 | 说明 | 168| ------- | ------------------------------------------- | ---- | -------- | 169| setting | [PhotoCaptureSetting](arkts-apis-camera-i.md#photocapturesetting) | 是 | 拍照设置,传入undefined类型数据按默认无参处理。 | 170 171**返回值:** 172 173| 类型 | 说明 | 174| -------------- | ------------------------ | 175| Promise\<void\> | Promise对象,无返回结果。 | 176 177**错误码:** 178 179以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 180 181| 错误码ID | 错误信息 | 182| --------------- | --------------- | 183| 7400101 | Parameter missing or parameter type incorrect. | 184| 7400104 | Session not running. | 185| 7400201 | Camera service fatal error. | 186 187**示例:** 188 189```ts 190import { BusinessError } from '@kit.BasicServicesKit'; 191 192function capture(photoOutput: camera.PhotoOutput): void { 193 let captureLocation: camera.Location = { 194 latitude: 0, 195 longitude: 0, 196 altitude: 0 197 } 198 let settings: camera.PhotoCaptureSetting = { 199 quality: camera.QualityLevel.QUALITY_LEVEL_LOW, 200 rotation: camera.ImageRotation.ROTATION_0, 201 location: captureLocation, 202 mirror: false 203 } 204 photoOutput.capture(settings).then(() => { 205 console.info('Promise returned to indicate that photo capture request success.'); 206 }).catch((error: BusinessError) => { 207 console.error(`Failed to photo output capture, error code: ${error.code}.`); 208 }); 209} 210``` 211 212## on('photoAvailable')<sup>11+</sup> 213 214on(type: 'photoAvailable', callback: AsyncCallback\<Photo\>): void 215 216注册监听全质量图上报。使用callback异步回调。 217 218> **说明:** 219> 220> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 221 222**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 223 224**系统能力:** SystemCapability.Multimedia.Camera.Core 225 226**参数:** 227 228| 参数名 | 类型 | 必填 | 说明 | 229| -------- | ---------- | --- | ------------------------------------ | 230| type | string | 是 | 监听事件,固定为'photoAvailable',photoOutput创建成功后可监听。 | 231| callback | AsyncCallback\<[Photo](arkts-apis-camera-Photo.md)\> | 是 | 回调函数,用于监听全质量图上报。 | 232 233**示例:** 234 235```ts 236import { BusinessError } from '@kit.BasicServicesKit'; 237import { image } from '@kit.ImageKit'; 238import { camera } from '@kit.CameraKit'; 239 240function callback(err: BusinessError, photo: camera.Photo): void { 241 if (err !== undefined && err.code !== 0) { 242 console.error(`Callback Error, errorCode: ${err.code}`); 243 return; 244 } 245 let mainImage: image.Image = photo.main; 246} 247 248function registerPhotoOutputPhotoAvailable(photoOutput: camera.PhotoOutput): void { 249 photoOutput.on('photoAvailable', callback); 250} 251``` 252 253## off('photoAvailable')<sup>11+</sup> 254 255off(type: 'photoAvailable', callback?: AsyncCallback\<Photo\>): void 256 257注销监听全质量图上报。 258 259**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 260 261**系统能力:** SystemCapability.Multimedia.Camera.Core 262 263**参数:** 264 265| 参数名 | 类型 | 必填 | 说明 | 266| -------- | ---------------------- | ---- | ------------------------------------------ | 267| type | string | 是 | 监听事件,固定为'photoAvailable',photoOutput创建成功后可监听。 | 268| callback | AsyncCallback\<[Photo](arkts-apis-camera-Photo.md)\> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 269 270**示例:** 271 272```ts 273import { BusinessError } from '@kit.BasicServicesKit'; 274import { image } from '@kit.ImageKit'; 275 276function callback(err: BusinessError, photo: camera.Photo): void { 277 if (err !== undefined && err.code !== 0) { 278 console.error(`Callback Error, errorCode: ${err.code}`); 279 return; 280 } 281 let mainImage: image.Image = photo.main; 282} 283 284function unRegisterPhotoOutputPhotoAvailable(photoOutput: camera.PhotoOutput): void { 285 photoOutput.off('photoAvailable', callback); 286} 287``` 288 289## on('captureStartWithInfo')<sup>11+</sup> 290 291on(type: 'captureStartWithInfo', callback: AsyncCallback\<CaptureStartInfo\>): void 292 293监听拍照开始,通过注册回调函数获取[CaptureStartInfo](arkts-apis-camera-i.md#capturestartinfo11)。使用callback异步回调。 294 295> **说明:** 296> 297> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 298 299**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 300 301**系统能力:** SystemCapability.Multimedia.Camera.Core 302 303**参数:** 304 305| 参数名 | 类型 | 必填 | 说明 | 306| -------- | ---------- | --- | ------------------------------------ | 307| type | string | 是 | 监听事件,固定为'captureStartWithInfo',photoOutput创建成功后可监听。 | 308| callback | AsyncCallback\<[CaptureStartInfo](arkts-apis-camera-i.md#capturestartinfo11)\> | 是 | 使用callback的方式获取Capture ID。| 309 310**示例:** 311 312```ts 313import { BusinessError } from '@kit.BasicServicesKit'; 314 315function callback(err: BusinessError, captureStartInfo: camera.CaptureStartInfo): void { 316 if (err !== undefined && err.code !== 0) { 317 console.error(`Callback Error, errorCode: ${err.code}`); 318 return; 319 } 320 console.info(`photo capture started, captureStartInfo : ${captureStartInfo}`); 321} 322 323function registerCaptureStartWithInfo(photoOutput: camera.PhotoOutput): void { 324 photoOutput.on('captureStartWithInfo', callback); 325} 326``` 327 328## off('captureStartWithInfo')<sup>11+</sup> 329 330off(type: 'captureStartWithInfo', callback?: AsyncCallback\<CaptureStartInfo\>): void 331 332注销监听拍照。 333 334**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 335 336**系统能力:** SystemCapability.Multimedia.Camera.Core 337 338**参数:** 339 340| 参数名 | 类型 | 必填 | 说明 | 341| -------- | ---------------------- | ---- | ------------------------------------------ | 342| type | string | 是 | 监听事件,固定为'captureStartWithInfo',photoOutput创建成功后可监听。 | 343| callback | AsyncCallback\<[CaptureStartInfo](arkts-apis-camera-i.md#capturestartinfo11)\> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 344 345**示例:** 346 347```ts 348import { BusinessError } from '@kit.BasicServicesKit'; 349 350function unRegisterCaptureStartWithInfo(photoOutput: camera.PhotoOutput): void { 351 photoOutput.off('captureStartWithInfo'); 352} 353``` 354 355## isMovingPhotoSupported<sup>12+</sup> 356 357isMovingPhotoSupported(): boolean 358 359查询是否支持动态照片拍摄。 360 361**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 362 363**系统能力:** SystemCapability.Multimedia.Camera.Core 364 365**返回值:** 366 367| 类型 | 说明 | 368| -------------- | ----------------------- | 369| boolean | 返回是否支持动态照片拍照。true表示支持,false表示不支持。 | 370 371**错误码:** 372 373以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 374 375| 错误码ID | 错误信息 | 376| -------------- | --------------- | 377| 7400201 | Camera service fatal error. | 378 379**示例:** 380 381```ts 382import { BusinessError } from '@kit.BasicServicesKit'; 383 384function isMovingPhotoSupported(photoOutput: camera.PhotoOutput): boolean { 385 let isSupported: boolean = false; 386 try { 387 isSupported = photoOutput.isMovingPhotoSupported(); 388 } catch (error) { 389 // 失败返回错误码error.code并处理。 390 let err = error as BusinessError; 391 console.error(`The isMovingPhotoSupported call failed. error code: ${err.code}`); 392 } 393 return isSupported; 394} 395``` 396 397## enableMovingPhoto<sup>12+</sup> 398 399enableMovingPhoto(enabled: boolean): void 400 401使能动态照片拍照。 402 403**需要权限:** ohos.permission.MICROPHONE 404 405**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 406 407**系统能力:** SystemCapability.Multimedia.Camera.Core 408 409**参数:** 410 411| 参数名 | 类型 | 必填 | 说明 | 412| -------- | ---------------------- | ---- | ------------------------------------------ | 413| enabled | boolean | 是 | 使能动态照片拍照。true为开启动态照片,false为关闭动态照片。 | 414 415**错误码:** 416 417以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 418 419| 错误码ID | 错误信息 | 420| -------- |------------------------------------------------| 421| 201 | permission denied. | 422| 7400101 | Parameter missing or parameter type incorrect. | 423| 7400201 | Camera service fatal error. | 424 425**示例:** 426 427```ts 428import { BusinessError } from '@kit.BasicServicesKit'; 429 430function enableMovingPhoto(photoOutput: camera.PhotoOutput): void { 431 try { 432 photoOutput.enableMovingPhoto(true); 433 } catch (error) { 434 // 失败返回错误码error.code并处理。 435 let err = error as BusinessError; 436 console.error(`The enableMovingPhoto call failed. error code: ${err.code}`); 437 } 438} 439``` 440 441## on('photoAssetAvailable')<sup>12+</sup> 442 443on(type: 'photoAssetAvailable', callback: AsyncCallback\<photoAccessHelper.PhotoAsset\>): void 444 445注册监听photoAsset上报。使用callback异步回调。 446 447> **说明:** 448> 449> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 450 451**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 452 453**系统能力:** SystemCapability.Multimedia.Camera.Core 454 455**参数:** 456 457| 参数名 | 类型 | 必填 | 说明 | 458| -------- | ---------- | --- | ------------------------------------ | 459| type | string | 是 | 监听事件,固定为'photoAssetAvailable',photoOutput创建成功后可监听。 | 460| callback | AsyncCallback\<[photoAccessHelper.PhotoAsset](../apis-media-library-kit/arkts-apis-photoAccessHelper-PhotoAsset.md)\> | 是 | 回调函数,用于监听photoAsset上报。 | 461 462**示例:** 463 464```ts 465import { BusinessError } from '@kit.BasicServicesKit'; 466import { photoAccessHelper } from '@kit.MediaLibraryKit'; 467 468function photoAssetAvailableCallback(err: BusinessError, photoAsset: photoAccessHelper.PhotoAsset): void { 469 if (err) { 470 console.info(`photoAssetAvailable error: ${JSON.stringify(err)}.`); 471 return; 472 } 473 console.info('photoOutPutCallBack photoAssetAvailable'); 474 // 开发者可通过photoAsset获取图片相关信息。 475} 476 477function onPhotoOutputPhotoAssetAvailable(photoOutput: camera.PhotoOutput): void { 478 photoOutput.on('photoAssetAvailable', photoAssetAvailableCallback); 479} 480``` 481 482## off('photoAssetAvailable')<sup>12+</sup> 483 484off(type: 'photoAssetAvailable', callback?: AsyncCallback\<photoAccessHelper.PhotoAsset\>): void 485 486注销photoAsset上报。 487 488**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 489 490**系统能力:** SystemCapability.Multimedia.Camera.Core 491 492**参数:** 493 494| 参数名 | 类型 | 必填 | 说明 | 495| -------- | ---------- |-----|----------------------------------------------------------------------------| 496| type | string | 是 | 监听事件,固定为'photoAssetAvailable',photoOutput创建成功后可监听。 | 497| callback | AsyncCallback\<[photoAccessHelper.PhotoAsset](../apis-media-library-kit/arkts-apis-photoAccessHelper-PhotoAsset.md)\> | 否 | 需要解监听的回调方法。如果callback不为空且与此对应的监听方法一致,不为匿名方法,则解注册该方法;如果callback为空,则解监听所有回调。 | 498 499**示例:** 500 501```ts 502function offPhotoOutputPhotoAssetAvailable(photoOutput: camera.PhotoOutput): void { 503 photoOutput.off('photoAssetAvailable'); 504} 505``` 506 507## isMirrorSupported 508 509isMirrorSupported(): boolean 510 511查询是否支持镜像拍照。 512 513**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 514 515**系统能力:** SystemCapability.Multimedia.Camera.Core 516 517**返回值:** 518 519| 类型 | 说明 | 520| -------------- | ----------------------- | 521| boolean | 返回是否支持镜像拍照,true表示支持,false表示不支持。 | 522 523**示例:** 524 525```ts 526function isMirrorSupported(photoOutput: camera.PhotoOutput): boolean { 527 let isSupported: boolean = photoOutput.isMirrorSupported(); 528 return isSupported; 529} 530``` 531 532## enableMirror<sup>13+</sup> 533 534enableMirror(enabled: boolean): void 535 536是否启用动态照片镜像拍照。 537 538调用该接口前,需要通过[isMovingPhotoSupported](#ismovingphotosupported12)查询是否支持动态照片拍摄功能以及通过[isMirrorSupported](#ismirrorsupported)查询是否支持镜像拍照功能。 539 540**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 541 542**系统能力:** SystemCapability.Multimedia.Camera.Core 543 544**参数:** 545 546| 参数名 | 类型 | 必填 | 说明 | 547|----------| ---------------------- | ---- |---------------------------| 548| enabled | boolean | 是 | 是否启用动态照片镜像拍照。true为开启动态照片镜像拍照,false为关闭动态照片镜像拍照。 | 549 550**错误码:** 551 552以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 553 554| 错误码ID | 错误信息 | 555| -------- |------------------------------------------------| 556| 7400101 | Parameter missing or parameter type incorrect. | 557| 7400103 | Session not config. | 558| 7400201 | Camera service fatal error. | 559 560 561**示例:** 562 563```ts 564import { BusinessError } from '@kit.BasicServicesKit'; 565 566function enableMirror(photoOutput: camera.PhotoOutput): void { 567 try { 568 photoOutput.enableMirror(true); 569 } catch (error) { 570 // 失败返回错误码error.code并处理。 571 let err = error as BusinessError; 572 console.error(`The enableMirror call failed. error code: ${err.code}`); 573 } 574} 575``` 576 577## getSupportedMovingPhotoVideoCodecTypes<sup>13+</sup> 578 579getSupportedMovingPhotoVideoCodecTypes(): Array\<VideoCodecType\> 580 581查询支持的动态照片短视频编码类型。 582 583**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 584 585**系统能力:** SystemCapability.Multimedia.Camera.Core 586 587**返回值:** 588 589| 类型 | 说明 | 590| -------------- |-------------------| 591| Array\<[VideoCodecType](arkts-apis-camera-e.md#videocodectype13)\> | 支持的动态照片短视频编码类型列表。 | 592 593**错误码:** 594 595以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 596 597| 错误码ID | 错误信息 | 598| --------------- | --------------- | 599| 7400201 | Camera service fatal error. | 600 601**示例:** 602 603```ts 604function getSupportedMovingPhotoVideoCodecType(photoOutput: camera.PhotoOutput): Array<camera.VideoCodecType> { 605 let supportedVideoCodecTypesArray: Array<camera.VideoCodecType> = photoOutput.getSupportedMovingPhotoVideoCodecTypes(); 606 return supportedVideoCodecTypesArray; 607} 608``` 609 610## setMovingPhotoVideoCodecType<sup>13+</sup> 611 612setMovingPhotoVideoCodecType(codecType: VideoCodecType): void 613 614设置动态照片短视频编码类型。 615 616**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 617 618**系统能力:** SystemCapability.Multimedia.Camera.Core 619 620**参数:** 621 622| 参数名 | 类型 | 必填 | 说明 | 623| ------------- |-------------------------------------|-------| ------------ | 624| codecType | [VideoCodecType](arkts-apis-camera-e.md#videocodectype13) | 是 |获取动态照片短视频编码类型。 | 625 626**错误码:** 627 628以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 629 630| 错误码ID | 错误信息 | 631| --------------- | --------------- | 632| 7400201 | Camera service fatal error. | 633 634**示例:** 635 636```ts 637function setMovingPhotoVideoCodecTypes(photoOutput: camera.PhotoOutput, videoCodecType: camera.VideoCodecType): void { 638 photoOutput.setMovingPhotoVideoCodecType(videoCodecType); 639} 640``` 641 642## on('frameShutter') 643 644on(type: 'frameShutter', callback: AsyncCallback\<FrameShutterInfo\>): void 645 646监听拍照帧输出捕获,通过注册回调函数获取结果。使用callback异步回调。 647 648**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 649 650**系统能力:** SystemCapability.Multimedia.Camera.Core 651 652**参数:** 653 654| 参数名 | 类型 | 必填 | 说明 | 655| -------- | ---------- | --- | ------------------------------------ | 656| type | string | 是 | 监听事件,固定为'frameShutter',photoOutput创建成功后可监听。 | 657| callback | AsyncCallback\<[FrameShutterInfo](arkts-apis-camera-i.md#frameshutterinfo)\> | 是 | 回调函数,用于获取相关信息。该回调返回意味着可以再次下发拍照请求。 | 658 659**示例:** 660 661```ts 662import { BusinessError } from '@kit.BasicServicesKit'; 663 664function callback(err: BusinessError, frameShutterInfo: camera.FrameShutterInfo): void { 665 if (err !== undefined && err.code !== 0) { 666 console.error(`Callback Error, errorCode: ${err.code}`); 667 return; 668 } 669 console.info(`CaptureId for frame : ${frameShutterInfo.captureId}`); 670 console.info(`Timestamp for frame : ${frameShutterInfo.timestamp}`); 671} 672 673function registerPhotoOutputFrameShutter(photoOutput: camera.PhotoOutput): void { 674 photoOutput.on('frameShutter', callback); 675} 676``` 677 678## off('frameShutter') 679 680off(type: 'frameShutter', callback?: AsyncCallback\<FrameShutterInfo\>): void 681 682注销监听拍照帧输出捕获。 683 684**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 685 686**系统能力:** SystemCapability.Multimedia.Camera.Core 687 688**参数:** 689 690| 参数名 | 类型 | 必填 | 说明 | 691| -------- | ---------- | --- | ------------------------------------ | 692| type | string | 是 | 监听事件,固定为'frameShutter',photoOutput创建成功后可监听。 | 693| callback | AsyncCallback\<[FrameShutterInfo](arkts-apis-camera-i.md#frameshutterinfo)\> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 694 695**示例:** 696 697```ts 698function unregisterPhotoOutputFrameShutter(photoOutput: camera.PhotoOutput): void { 699 photoOutput.off('frameShutter'); 700} 701``` 702 703## on('captureEnd') 704 705on(type: 'captureEnd', callback: AsyncCallback\<CaptureEndInfo\>): void 706 707监听拍照结束,通过注册回调函数获取结果。使用callback异步回调。 708 709> **说明:** 710> 711> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 712 713**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 714 715**系统能力:** SystemCapability.Multimedia.Camera.Core 716 717**参数:** 718 719| 参数名 | 类型 | 必填 | 说明 | 720| -------- | --------------- | ---- | ---------------------------------------- | 721| type | string | 是 | 监听事件,固定为'captureEnd'。photoOutput创建成功后可监听。拍照完全结束可触发该事件发生并返回相应信息。 | 722| callback | AsyncCallback\<[CaptureEndInfo](arkts-apis-camera-i.md#captureendinfo)\> | 是 | 回调函数,用于获取相关信息。 | 723 724**示例:** 725 726```ts 727import { BusinessError } from '@kit.BasicServicesKit'; 728 729function callback(err: BusinessError, captureEndInfo: camera.CaptureEndInfo): void { 730 if (err !== undefined && err.code !== 0) { 731 console.error(`Callback Error, errorCode: ${err.code}`); 732 return; 733 } 734 console.info(`photo capture end, captureId : ${captureEndInfo.captureId}`); 735 console.info(`frameCount : ${captureEndInfo.frameCount}`); 736} 737 738function registerPhotoOutputCaptureEnd(photoOutput: camera.PhotoOutput): void { 739 photoOutput.on('captureEnd', callback); 740} 741``` 742 743## off('captureEnd') 744 745off(type: 'captureEnd', callback?: AsyncCallback\<CaptureEndInfo\>): void 746 747注销监听拍照结束。 748 749**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 750 751**系统能力:** SystemCapability.Multimedia.Camera.Core 752 753**参数:** 754 755| 参数名 | 类型 | 必填 | 说明 | 756| -------- | --------------- | ---- | ---------------------------------------- | 757| type | string | 是 | 监听事件,固定为'captureEnd',photoOutput创建成功后可监听。 | 758| callback | AsyncCallback\<[CaptureEndInfo](arkts-apis-camera-i.md#captureendinfo)\> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 759 760**示例:** 761 762```ts 763function unregisterPhotoOutputCaptureEnd(photoOutput: camera.PhotoOutput): void { 764 photoOutput.off('captureEnd'); 765} 766``` 767 768## on('frameShutterEnd')<sup>12+</sup> 769 770on(type: 'frameShutterEnd', callback: AsyncCallback\<FrameShutterEndInfo\>): void 771 772监听拍照曝光结束捕获,通过注册回调函数获取结果。使用callback异步回调。 773 774> **说明:** 775> 776> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 777 778**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 779 780**系统能力:** SystemCapability.Multimedia.Camera.Core 781 782**参数:** 783 784| 参数名 | 类型 | 必填 | 说明 | 785| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 786| type | string | 是 | 监听事件,固定为'frameShutterEnd',photoOutput创建成功后可监听。 | 787| callback | AsyncCallback\<[FrameShutterEndInfo](arkts-apis-camera-i.md#frameshutterendinfo12)\> | 是 | 回调函数,用于获取相关信息。该回调返回表示拍照曝光结束。 | 788 789**示例:** 790 791```ts 792import { BusinessError } from '@kit.BasicServicesKit'; 793 794function callback(err: BusinessError, frameShutterEndInfo: camera.FrameShutterEndInfo): void { 795 if (err !== undefined && err.code !== 0) { 796 console.error(`Callback Error, errorCode: ${err.code}`); 797 return; 798 } 799 console.info(`CaptureId for frame : ${frameShutterEndInfo.captureId}`); 800} 801 802function registerPhotoOutputFrameShutterEnd(photoOutput: camera.PhotoOutput): void { 803 photoOutput.on('frameShutterEnd', callback); 804} 805``` 806 807## off('frameShutterEnd')<sup>12+</sup> 808 809off(type: 'frameShutterEnd', callback?: AsyncCallback\<FrameShutterEndInfo\>): void 810 811注销监听拍照帧输出捕获。 812 813**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 814 815**系统能力:** SystemCapability.Multimedia.Camera.Core 816 817**参数:** 818 819| 参数名 | 类型 | 必填 | 说明 | 820| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 821| type | string | 是 | 监听事件,固定为'frameShutterEnd',photoOutput创建成功后可监听。 | 822| callback | AsyncCallback\<[FrameShutterEndInfo](arkts-apis-camera-i.md#frameshutterendinfo12)\> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 823 824**示例:** 825 826```ts 827function unregisterPhotoOutputFrameShutterEnd(photoOutput: camera.PhotoOutput): void { 828 photoOutput.off('frameShutterEnd'); 829} 830``` 831 832## on('captureReady')<sup>12+</sup> 833 834on(type: 'captureReady', callback: AsyncCallback\<void\>): void 835 836监听可拍下一张,通过注册回调函数获取结果。使用callback异步回调。 837 838> **说明:** 839> 840> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 841 842**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 843 844**系统能力:** SystemCapability.Multimedia.Camera.Core 845 846**参数:** 847 848| 参数名 | 类型 | 必填 | 说明 | 849| -------- | --------------------- | ---- | ------------------------------------------------------------ | 850| type | string | 是 | 监听事件,固定为'captureReady',photoOutput创建成功后可监听。当下一张可拍时可触发该事件发生并返回相应信息。 | 851| callback | AsyncCallback\<void\> | 是 | 回调函数,用于获取相关信息。 | 852 853**示例:** 854 855```ts 856import { BusinessError } from '@kit.BasicServicesKit'; 857 858function callback(err: BusinessError): void { 859 if (err !== undefined && err.code !== 0) { 860 console.error(`Callback Error, errorCode: ${err.code}`); 861 return; 862 } 863 console.info(`photo capture ready`); 864} 865 866function registerPhotoOutputCaptureReady(photoOutput: camera.PhotoOutput): void { 867 photoOutput.on('captureReady', callback); 868} 869``` 870 871## off('captureReady')<sup>12+</sup> 872 873off(type: 'captureReady', callback?: AsyncCallback\<void\>): void 874 875注销监听可拍下一张。 876 877**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 878 879**系统能力:** SystemCapability.Multimedia.Camera.Core 880 881**参数:** 882 883| 参数名 | 类型 | 必填 | 说明 | 884| -------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------ | 885| type | string | 是 | 监听事件,固定为'captureReady',photoOutput创建成功后可监听。 | 886| callback | AsyncCallback\<void\> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 887 888**示例:** 889 890```ts 891function unregisterPhotoOutputCaptureReady(photoOutput: camera.PhotoOutput): void { 892 photoOutput.off('captureReady'); 893} 894``` 895 896## on('estimatedCaptureDuration')<sup>12+</sup> 897 898on(type: 'estimatedCaptureDuration', callback: AsyncCallback\<number\>): void 899 900监听预估的拍照时间,通过注册回调函数获取结果。使用callback异步回调。 901 902> **说明:** 903> 904> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 905 906**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 907 908**系统能力:** SystemCapability.Multimedia.Camera.Core 909 910**参数:** 911 912| 参数名 | 类型 | 必填 | 说明 | 913| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 914| type | string | 是 | 监听事件,固定为'estimatedCaptureDuration',photoOutput创建成功后可监听。拍照完全结束可触发该事件发生并返回相应信息。 | 915| callback | AsyncCallback\<number> | 是 | 回调函数,用于获取预估的单次拍照底层出sensor采集帧时间,单位:毫秒。如果上报-1,代表没有预估时间。 | 916 917**示例:** 918 919```ts 920import { BusinessError } from '@kit.BasicServicesKit'; 921 922function callback(err: BusinessError, duration: number): void { 923 if (err !== undefined && err.code !== 0) { 924 console.error(`Callback Error, errorCode: ${err.code}`); 925 return; 926 } 927 console.info(`photo estimated capture duration : ${duration}`); 928} 929 930function registerPhotoOutputEstimatedCaptureDuration(photoOutput: camera.PhotoOutput): void { 931 photoOutput.on('estimatedCaptureDuration', callback); 932} 933``` 934 935## off('estimatedCaptureDuration')<sup>12+</sup> 936 937off(type: 'estimatedCaptureDuration', callback?: AsyncCallback\<number\>): void 938 939注销监听预估的拍照时间。 940 941**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 942 943**系统能力:** SystemCapability.Multimedia.Camera.Core 944 945**参数:** 946 947| 参数名 | 类型 | 必填 | 说明 | 948| -------- | ----------------------- | ---- | ------------------------------------------------------------ | 949| type | string | 是 | 监听事件,固定为'estimatedCaptureDuration',photoOutput创建成功后可监听。 | 950| callback | AsyncCallback\<number\> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 951 952**示例:** 953 954```ts 955function unregisterPhotoOutputEstimatedCaptureDuration(photoOutput: camera.PhotoOutput): void { 956 photoOutput.off('estimatedCaptureDuration'); 957} 958``` 959 960## on('error') 961 962on(type: 'error', callback: ErrorCallback): void 963 964监听拍照输出发生错误,通过注册回调函数获取结果。使用callback异步回调。 965 966> **说明:** 967> 968> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 969 970**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 971 972**系统能力:** SystemCapability.Multimedia.Camera.Core 973 974**参数:** 975 976| 参数名 | 类型 | 必填 | 说明 | 977| -------- | ------------- | ---- | ----------------------------------- | 978| type | string | 是 | 监听事件,固定为'error',photoOutput创建成功后可监听。拍照接口调用时出现错误触发该事件并返回错误信息。 | 979| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | 是 | 回调函数,用于获取错误信息。返回错误码,错误码类型[CameraErrorCode](arkts-apis-camera-e.md#cameraerrorcode)。 | 980 981**示例:** 982 983```ts 984import { BusinessError } from '@kit.BasicServicesKit'; 985 986function callback(err: BusinessError): void { 987 console.error(`Photo output error code: ${err.code}`); 988} 989 990function registerPhotoOutputError(photoOutput: camera.PhotoOutput): void { 991 photoOutput.on('error', callback); 992} 993``` 994 995## off('error') 996 997off(type: 'error', callback?: ErrorCallback): void 998 999注销监听拍照输出发生错误。 1000 1001**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 1002 1003**系统能力:** SystemCapability.Multimedia.Camera.Core 1004 1005**参数:** 1006 1007| 参数名 | 类型 | 必填 | 说明 | 1008| -------- | ------------- | ---- | ----------------------------------- | 1009| type | string | 是 | 监听事件,固定为'error',photoOutput创建成功后可监听。 | 1010| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 1011 1012**示例:** 1013 1014```ts 1015function unregisterPhotoOutputError(photoOutput: camera.PhotoOutput): void { 1016 photoOutput.off('error'); 1017} 1018``` 1019 1020## getActiveProfile<sup>12+</sup> 1021 1022getActiveProfile(): Profile 1023 1024获取当前生效的配置信息。 1025 1026**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 1027 1028**系统能力:** SystemCapability.Multimedia.Camera.Core 1029 1030**返回值:** 1031 1032| 类型 | 说明 | 1033| ------------- |-----------| 1034| [Profile](arkts-apis-camera-i.md#profile) | 当前生效的配置信息 | 1035 1036**错误码:** 1037 1038以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 1039 1040| 错误码ID | 错误信息 | 1041|---------|------------------------------| 1042| 7400201 | Camera service fatal error. | 1043 1044**示例:** 1045 1046```ts 1047import { BusinessError } from '@kit.BasicServicesKit'; 1048 1049function testGetActiveProfile(photoOutput: camera.PhotoOutput): camera.Profile | undefined { 1050 let activeProfile: camera.Profile | undefined = undefined; 1051 try { 1052 activeProfile = photoOutput.getActiveProfile(); 1053 } catch (error) { 1054 // 失败返回错误码error.code并处理。 1055 let err = error as BusinessError; 1056 console.error(`The photoOutput.getActiveProfile call failed. error code: ${err.code}`); 1057 } 1058 return activeProfile; 1059} 1060``` 1061 1062## getPhotoRotation<sup>12+</sup> 1063 1064getPhotoRotation(deviceDegree: number): ImageRotation 1065 1066获取拍照旋转角度。 1067 1068- 设备自然方向:设备默认使用方向,手机为竖屏(充电口向下)。 1069- 相机镜头角度:值等于相机图像顺时针旋转到设备自然方向的角度,手机后置相机传感器是横屏安装的,所以需要顺时针旋转90度到设备自然方向。 1070- 屏幕显示方向:需要屏幕显示的图片左上角为第一个像素点为坐标原点。锁屏时与自然方向一致。 1071 1072**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 1073 1074**系统能力:** SystemCapability.Multimedia.Camera.Core 1075 1076**参数:** 1077 1078| 参数名 | 类型 | 必填 | 说明 | 1079| -------- | --------------| ---- | ------------------------ | 1080| deviceDegree | number | 是 | 设备旋转角度,单位度,取值范围:[0, 360]。<br>若入参超过该范围,则取入参除以360的余数。 | 1081 1082**返回值:** 1083 1084| 类型 | 说明 | 1085| ------------- |-----------| 1086| [ImageRotation](arkts-apis-camera-e.md#imagerotation) | 获取拍照旋转角度。 | 1087 1088**错误码:** 1089 1090以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 1091 1092| 错误码ID | 错误信息 | 1093|---------|------------------------------| 1094| 7400101 | Parameter missing or parameter type incorrect. | 1095| 7400201 | Camera service fatal error. | 1096 1097**示例:** 1098 1099```ts 1100import { BusinessError } from '@kit.BasicServicesKit'; 1101 1102function testGetPhotoRotation(photoOutput: camera.PhotoOutput, deviceDegree : number): camera.ImageRotation { 1103 let photoRotation: camera.ImageRotation = camera.ImageRotation.ROTATION_0; 1104 try { 1105 photoRotation = photoOutput.getPhotoRotation(deviceDegree); 1106 console.log(`Photo rotation is: ${photoRotation}`); 1107 } catch (error) { 1108 // 失败返回错误码error.code并处理。 1109 let err = error as BusinessError; 1110 console.error(`The photoOutput.getPhotoRotation call failed. error code: ${err.code}`); 1111 } 1112 return photoRotation; 1113} 1114``` 1115 1116 1117## on('captureStart')<sup>(deprecated)</sup> 1118 1119on(type: 'captureStart', callback: AsyncCallback\<number\>): void 1120 1121监听拍照开始,通过注册回调函数获取Capture ID。使用callback异步回调。 1122 1123> **说明:** 1124> 从 API version 10开始支持,从API version 11开始废弃。建议使用[on('captureStartWithInfo')](#oncapturestartwithinfo11)替代。 1125> 1126> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 1127 1128**系统能力:** SystemCapability.Multimedia.Camera.Core 1129 1130**参数:** 1131 1132| 参数名 | 类型 | 必填 | 说明 | 1133| -------- | ---------------------- | ---- | ------------------------------------------ | 1134| type | string | 是 | 监听事件,固定为'captureStart',photoOutput创建成功后可监听。每次拍照,底层开始曝光时触发该事件并返回。 | 1135| callback | AsyncCallback\<number\> | 是 | 使用callback的方式获取Capture ID。 | 1136 1137**示例:** 1138 1139```ts 1140import { BusinessError } from '@kit.BasicServicesKit'; 1141 1142function callback(err: BusinessError, captureId: number): void { 1143 if (err !== undefined && err.code !== 0) { 1144 console.error(`Callback Error, errorCode: ${err.code}`); 1145 return; 1146 } 1147 console.info(`photo capture started, captureId : ${captureId}`); 1148} 1149 1150function registerPhotoOutputCaptureStart(photoOutput: camera.PhotoOutput): void { 1151 photoOutput.on('captureStart', callback); 1152} 1153``` 1154 1155## off('captureStart')<sup>(deprecated)</sup> 1156 1157off(type: 'captureStart', callback?: AsyncCallback\<number\>): void 1158 1159注销拍照开始的监听。 1160 1161> **说明:** 1162> 从 API version 10开始支持,从API version 11开始废弃。建议使用[off('captureStartWithInfo')](#offcapturestartwithinfo11)替代。 1163> 1164> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 1165 1166**系统能力:** SystemCapability.Multimedia.Camera.Core 1167 1168**参数:** 1169 1170| 参数名 | 类型 | 必填 | 说明 | 1171| -------- | ---------------------- | ---- | ------------------------------------------ | 1172| type | string | 是 | 监听事件,固定为'captureStart',photoOutput创建成功后可监听。 | 1173| callback | AsyncCallback\<number\> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 1174 1175**示例:** 1176 1177```ts 1178function unregisterPhotoOutputCaptureStart(photoOutput: camera.PhotoOutput): void { 1179 photoOutput.off('captureStart'); 1180} 1181``` 1182