1# @ohos.multimedia.camera (相机管理) 2 3本模块为开发者提供一套简单且易于理解的相机服务接口,开发者通过调用接口可以开发相机应用。应用通过访问和操作相机硬件,实现基础操作,如预览、拍照和录像;还可以通过接口组合完成更多操作,如控制闪光灯和曝光时间、对焦或调焦等。 4 5> **说明:** 6> 7> 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 8 9## 导入模块 10 11```ts 12import { camera } from '@kit.CameraKit'; 13``` 14 15## camera.getCameraManager 16 17getCameraManager(context: Context): CameraManager 18 19获取相机管理器实例,同步返回结果。 20 21**系统能力:** SystemCapability.Multimedia.Camera.Core 22 23**参数:** 24 25| 参数名 | 类型 | 必填 | 说明 | 26| -------- | ----------------------------------------------- | ---- | ---------------------------- | 27| context | [Context](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 是 | 应用上下文。 | 28 29**返回值:** 30 31| 类型 | 说明 | 32| ----------------------------------------------- | ---------------------------- | 33| [CameraManager](#cameramanager) | 相机管理器。 | 34 35**错误码:** 36 37以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 38 39| 错误码ID | 错误信息 | 40| --------------- | --------------- | 41| 7400101 | Parameter missing or parameter type incorrect. | 42| 7400201 | Camera service fatal error. | 43 44**示例:** 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 64相机设备信息。 65 66**系统能力:** SystemCapability.Multimedia.Camera.Core 67 68| 名称 | 类型 | 只读 | 可选 | 说明 | 69| -------------- | --------------------------------- | ---- | ---- |---------- | 70| cameraId | string | 是 | 否 | 相机id。| 71| cameraPosition | [CameraPosition](#cameraposition) | 是 | 否 | 相机位置。 | 72| cameraType | [CameraType](#cameratype) | 是 | 否 | 相机类型。 | 73| connectionType | [ConnectionType](#connectiontype) | 是 | 否 | 相机连接类型。 | 74| cameraOrientation<sup>12+</sup> | number | 是 | 否 | 镜头的安装角度,不会随着屏幕旋转而改变,取值范围为0°-360°。 | 75 76## CameraPosition 77 78枚举,相机位置。 79 80**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 81 82**系统能力:** SystemCapability.Multimedia.Camera.Core 83 84| 名称 | 值 | 说明 | 85| --------------------------- | ---- |-----------------------------------------------------------------| 86| CAMERA_POSITION_UNSPECIFIED | 0 | 相机位置未指定。 | 87| CAMERA_POSITION_BACK | 1 | 后置相机。 | 88| CAMERA_POSITION_FRONT | 2 | 前置相机。 | 89| CAMERA_POSITION_FOLD_INNER<sup>(deprecated)</sup> | 3 | 折叠态相机。<br/> 从API version 11开始支持,从API version 12开始废弃。 | 90 91## CameraType 92 93枚举,相机类型。 94 95**系统能力:** SystemCapability.Multimedia.Camera.Core 96 97| 名称 | 值 | 说明 | 98| ----------------------- | ---- | -------------- | 99| CAMERA_TYPE_DEFAULT | 0 | 相机类型未指定。 | 100| CAMERA_TYPE_WIDE_ANGLE | 1 | 广角相机。 | 101| CAMERA_TYPE_ULTRA_WIDE | 2 | 超广角相机。 | 102| CAMERA_TYPE_TELEPHOTO | 3 | 长焦相机。 | 103| CAMERA_TYPE_TRUE_DEPTH | 4 | 带景深信息的相机。 | 104 105## ConnectionType 106 107枚举,相机连接类型。 108 109**系统能力:** SystemCapability.Multimedia.Camera.Core 110 111| 名称 | 值 | 说明 | 112| ---------------------------- | ---- | ------------- | 113| CAMERA_CONNECTION_BUILT_IN | 0 | 内置相机。 | 114| CAMERA_CONNECTION_USB_PLUGIN | 1 | USB连接的相机。 | 115| CAMERA_CONNECTION_REMOTE | 2 | 远程连接的相机。 | 116 117## CameraStatus 118 119枚举,相机状态。 120 121**系统能力:** SystemCapability.Multimedia.Camera.Core 122 123| 名称 | 值 | 说明 | 124| ------------------------- | ---- | ------------ | 125| CAMERA_STATUS_APPEAR | 0 | 新的相机出现。 | 126| CAMERA_STATUS_DISAPPEAR | 1 | 相机被移除。 | 127| CAMERA_STATUS_AVAILABLE | 2 | 相机可用。 | 128| CAMERA_STATUS_UNAVAILABLE | 3 | 相机不可用。 | 129 130## FoldStatus<sup>12+</sup> 131 132枚举,折叠机折叠状态。 133 134**系统能力:** SystemCapability.Multimedia.Camera.Core 135 136| 名称 | 值 | 说明 | 137| ------------------------- | ---- | ------------ | 138| NON_FOLDABLE | 0 | 表示当前设备不可折叠。 | 139| EXPANDED | 1 | 表示当前设备折叠状态为完全展开。 | 140| FOLDED | 2 | 表示当前设备折叠状态为折叠。 | 141 142## CameraStatusInfo 143 144相机管理器回调返回的接口实例,表示相机状态信息。 145 146**系统能力:** SystemCapability.Multimedia.Camera.Core 147 148| 名称 | 类型 | 只读 | 可选 | 说明 | 149| ------ | ----------------------------- | --------- |------------ | ---------- | 150| camera | [CameraDevice](#cameradevice) | 否 | 否 | 相机信息。 | 151| status | [CameraStatus](#camerastatus) | 否 | 否 | 相机状态。 | 152 153## FoldStatusInfo<sup>12+</sup> 154 155相机管理器回调返回的接口实例,表示折叠机折叠状态信息。 156 157**系统能力:** SystemCapability.Multimedia.Camera.Core 158 159| 名称 | 类型 | 只读 | 可选 | 说明 | 160| ------ | ----------------------------- | --------- |------------ | ---------- | 161| supportedCameras | [Array<CameraDevice\>](#cameradevice) | 否 | 否 | 当前折叠状态所支持的相机信息列表。 | 162| foldStatus | [FoldStatus](#foldstatus12) | 否 | 否 | 折叠屏折叠状态。 | 163 164## Profile 165 166相机配置信息项。 167 168**系统能力:** SystemCapability.Multimedia.Camera.Core 169 170| 名称 | 类型 | 只读 | 可选 | 说明 | 171| -------- | ----------------------------- |---- | ---- | ------------- | 172| format | [CameraFormat](#cameraformat) | 是 | 否 | 输出格式。 | 173| size | [Size](#size) | 是 | 否 | 分辨率。<br>设置的是相机分辨率宽高,非实际出图宽高。 | 174 175## FrameRateRange 176 177帧率范围。 178 179**系统能力:** SystemCapability.Multimedia.Camera.Core 180 181| 名称 | 类型 | 只读 | 可选 | 说明 | 182| -------- | ----------------------------- |----- |---| -------------- | 183| min | number | 是 | 否 | 最小帧率。 | 184| max | number | 是 | 否 | 最大帧率。 | 185 186## VideoProfile 187 188视频配置信息项,继承[Profile](#profile)。 189 190**系统能力:** SystemCapability.Multimedia.Camera.Core 191 192| 名称 | 类型 | 只读 | 可选 | 说明 | 193| ------------------------- | ----------------------------------------- | --- | ---- |----------- | 194| frameRateRange | [FrameRateRange](#frameraterange) | 是 | 否 | 帧率范围,fps(frames per second)。 | 195 196## CameraOutputCapability 197 198相机输出能力项。 199 200**系统能力:** SystemCapability.Multimedia.Camera.Core 201 202| 名称 | 类型 | 只读 | 可选 | 说明 | 203| ----------------------------- | --------------------------------------------------- | ---- | ---- |-------------------| 204| previewProfiles | Array\<[Profile](#profile)\> | 是 | 否 | 支持的预览配置信息集合。 | 205| photoProfiles | Array\<[Profile](#profile)\> | 是 | 否 | 支持的拍照配置信息集合。 | 206| videoProfiles | Array\<[VideoProfile](#videoprofile)\> | 是 | 否 | 支持的录像配置信息集合。 | 207| supportedMetadataObjectTypes | Array\<[MetadataObjectType](#metadataobjecttype)\> | 是 | 否 | 支持的metadata流类型信息集合。 | 208 209## SceneMode<sup>11+</sup> 210 211枚举,相机支持模式。 212 213**系统能力:** SystemCapability.Multimedia.Camera.Core 214 215| 名称 | 值 | 说明 | 216|----------------------------|---------|---------------------------------------------| 217| NORMAL_PHOTO | 1 | 普通拍照模式。详情见[PhotoSession](#photosession11) | 218| NORMAL_VIDEO | 2 | 普通录像模式。详情见[VideoSession](#videosession11) | 219| SECURE_PHOTO<sup>12+</sup> | 12 | 安全相机模式。详情见[SecureSession](#securesession12) | 220 221## CameraErrorCode 222 223相机错误码。 224 225接口使用不正确以及on接口监听error状态返回。 226 227**系统能力:** SystemCapability.Multimedia.Camera.Core 228 229| 名称 | 值 | 说明 | 230| ------------------------- | ---- | ------------ | 231| INVALID_ARGUMENT | 7400101 | 参数缺失或者参数类型不对。 | 232| OPERATION_NOT_ALLOWED | 7400102 | 操作流程不对,不允许。 | 233| SESSION_NOT_CONFIG | 7400103 | session 未配置返回。 | 234| SESSION_NOT_RUNNING | 7400104 | session 未运行返回。 | 235| SESSION_CONFIG_LOCKED | 7400105 | session 配置已锁定返回。 | 236| DEVICE_SETTING_LOCKED | 7400106 | 设备设置已锁定返回。 | 237| CONFLICT_CAMERA | 7400107 | 设备重复打开返回。 | 238| DEVICE_DISABLED | 7400108 | 安全原因摄像头被禁用。 | 239| DEVICE_PREEMPTED | 7400109 | 相机被抢占导致无法使用。 | 240| UNRESOLVED_CONFLICTS_WITH_CURRENT_CONFIGURATIONS<sup>12+</sup> | 7400110 | 与当前配置存在冲突。 | 241| SERVICE_FATAL_ERROR | 7400201 | 相机服务错误返回。 | 242 243## CameraManager 244 245相机管理器类,使用前需要通过[getCameraManager](#cameragetcameramanager)获取相机管理实例。 246 247### getSupportedCameras 248 249getSupportedCameras(): Array\<CameraDevice\> 250 251获取支持指定的相机设备对象,同步返回结果。 252 253**系统能力:** SystemCapability.Multimedia.Camera.Core 254 255**返回值:** 256 257| 类型 | 说明 | 258| ----------------------------------------------- | ---------------------------- | 259| Array\<[CameraDevice](#cameradevice)> | 相机设备列表。 | 260 261**示例:** 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 282获取指定的相机设备对象支持的模式,同步返回结果。 283 284**系统能力:** SystemCapability.Multimedia.Camera.Core 285 286**参数:** 287 288| 参数名 | 类型 | 必填 | 说明 | 289| ------------ |--------------------------------------------------------------- | -- | -------------------------- | 290| camera | [CameraDevice](#cameradevice) | 是 | 相机设备,通过 [getSupportedCameras](#getsupportedcameras) 接口获取。传参异常时,会返回错误码。 | 291 292**返回值:** 293 294| 类型 | 说明 | 295| ----------------------------------------------- | ---------------------------- | 296| Array\<[SceneMode](#scenemode11)> | 相机支持的模式列表。 | 297 298**示例:** 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 319查询相机设备支持的输出能力,同步返回结果。 320 321> **说明:** 322> 从 API version 10开始支持,从API version 11开始废弃。建议使用[getSupportedOutputCapability](#getsupportedoutputcapability11)替代。 323 324**系统能力:** SystemCapability.Multimedia.Camera.Core 325 326**参数:** 327 328| 参数名 | 类型 | 必填 | 说明 | 329| ------------ |--------------------------------------------------------------- | -- | -------------------------- | 330| camera | [CameraDevice](#cameradevice) | 是 | 相机设备,通过 [getSupportedCameras](#getsupportedcameras) 接口获取。传参异常时,会返回错误码。 | 331 332**返回值:** 333 334| 类型 | 说明 | 335| ----------------------------------------------- | ---------------------------- | 336| [CameraOutputCapability](#cameraoutputcapability) | 相机输出能力。 | 337 338**示例:** 339 340```ts 341function getSupportedOutputCapability(camera: camera.CameraDevice, cameraManager: camera.CameraManager): camera.CameraOutputCapability { 342 let cameraOutputCapability: camera.CameraOutputCapability = cameraManager.getSupportedOutputCapability(camera); 343 return cameraOutputCapability; 344} 345``` 346 347### getSupportedOutputCapability<sup>11+</sup> 348 349getSupportedOutputCapability(camera: CameraDevice, mode: SceneMode): CameraOutputCapability 350 351查询相机设备在模式下支持的输出能力,同步返回结果。 352 353**系统能力:** SystemCapability.Multimedia.Camera.Core 354 355**参数:** 356 357| 参数名 | 类型 | 必填 | 说明 | 358| ------------ |--------------------------------------------------------------- | -- | -------------------------- | 359| camera | [CameraDevice](#cameradevice) | 是 | 相机设备,通过 [getSupportedCameras](#getsupportedcameras) 接口获取。 | 360| mode | [SceneMode](#scenemode11) | 是 | 相机模式,通过 [getSupportedSceneModes](#getsupportedscenemodes11) 接口获取。 | 361 362**返回值:** 363 364| 类型 | 说明 | 365| ----------------------------------------------- | ---------------------------- | 366| [CameraOutputCapability](#cameraoutputcapability) | 相机输出能力。 | 367 368**示例:** 369 370```ts 371function getSupportedOutputCapability(camera: camera.CameraDevice, cameraManager: camera.CameraManager, sceneMode: camera.SceneMode): camera.CameraOutputCapability { 372 let cameraOutputCapability: camera.CameraOutputCapability = cameraManager.getSupportedOutputCapability(camera, sceneMode); 373 return cameraOutputCapability; 374} 375``` 376 377### isCameraMuted 378 379isCameraMuted(): boolean 380 381查询相机当前的禁用状态(禁用/未禁用)。 382 383**系统能力:** SystemCapability.Multimedia.Camera.Core 384 385**返回值:** 386 387| 类型 | 说明 | 388| ---------- | -------------------------------------------- | 389| boolean | 返回true表示相机被禁用,返回false表示相机未被禁用。 | 390 391**示例:** 392 393```ts 394function isCameraMuted(cameraManager: camera.CameraManager): boolean { 395 let isMuted: boolean = cameraManager.isCameraMuted(); 396 return isMuted; 397} 398``` 399 400### createCameraInput 401 402createCameraInput(camera: CameraDevice): CameraInput 403 404使用CameraDevice对象创建CameraInput实例,同步返回结果。 405 406**需要权限:** ohos.permission.CAMERA 407 408**系统能力:** SystemCapability.Multimedia.Camera.Core 409 410**参数:** 411 412| 参数名 | 类型 | 必填 | 说明 | 413| -------- | ------------------------------------------- | ---- |--------------------------------------------------| 414| camera | [CameraDevice](#cameradevice) | 是 | CameraDevice对象,通过 [getSupportedCameras](#getsupportedcameras) 接口获取。 | 415 416**返回值:** 417 418| 类型 | 说明 | 419| ---------- | ----------------------------- | 420| [CameraInput](#camerainput) | CameraInput实例。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 421 422**错误码:** 423 424以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 425 426| 错误码ID | 错误信息 | 427| --------------- | --------------- | 428| 7400101 | Parameter missing or parameter type incorrect. | 429| 7400102 | Operation not allowed. | 430| 7400201 | Camera service fatal error. | 431 432**示例:** 433 434```ts 435import { BusinessError } from '@kit.BasicServicesKit'; 436 437function createCameraInput(camera: camera.CameraDevice, cameraManager: camera.CameraManager): camera.CameraInput | undefined { 438 let cameraInput: camera.CameraInput | undefined = undefined; 439 try { 440 cameraInput = cameraManager.createCameraInput(camera); 441 } catch (error) { 442 // 失败返回错误码error.code并处理 443 let err = error as BusinessError; 444 console.error(`The createCameraInput call failed. error code: ${err.code}`); 445 } 446 return cameraInput; 447} 448``` 449 450### createCameraInput 451 452createCameraInput(position: CameraPosition, type: CameraType): CameraInput 453 454根据相机位置和类型创建CameraInput实例,同步返回结果。 455 456**需要权限:** ohos.permission.CAMERA 457 458**系统能力:** SystemCapability.Multimedia.Camera.Core 459 460**参数:** 461 462| 参数名 | 类型 | 必填 | 说明 | 463| -------- | ------------------------------------------- | ---- | --------------------------------- | 464| position | [CameraPosition](#cameraposition) | 是 | 相机位置,通过 [getSupportedCameras](#getsupportedcameras) 接口获取设备,然后获取设备位置信息。 | 465| type | [CameraType](#cameratype) | 是 | 相机类型,通过 [getSupportedCameras](#getsupportedcameras) 接口获取设备,然后获取设备类型信息。 | 466 467**返回值:** 468 469| 类型 | 说明 | 470| ---------- | ----------------------------- | 471| [CameraInput](#camerainput) | CameraInput实例。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 472 473**错误码:** 474 475以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 476 477| 错误码ID | 错误信息 | 478| --------------- | --------------- | 479| 7400101 | Parameter missing or parameter type incorrect. | 480| 7400102 | Operation not allowed. | 481| 7400201 | Camera service fatal error. | 482 483**示例:** 484 485```ts 486import { BusinessError } from '@kit.BasicServicesKit'; 487 488function createCameraInput(camera: camera.CameraDevice, cameraManager: camera.CameraManager): camera.CameraInput | undefined { 489 let position: camera.CameraPosition = camera.cameraPosition; 490 let type: camera.CameraType = camera.cameraType; 491 let cameraInput: camera.CameraInput | undefined = undefined; 492 try { 493 cameraInput = cameraManager.createCameraInput(position, type); 494 } catch (error) { 495 // 失败返回错误码error.code并处理 496 let err = error as BusinessError; 497 console.error(`The createCameraInput call failed. error code: ${err.code}`); 498 } 499 return cameraInput; 500} 501``` 502 503### createPreviewOutput 504 505createPreviewOutput(profile: Profile, surfaceId: string): PreviewOutput 506 507创建预览输出对象,同步返回结果。 508 509**系统能力:** SystemCapability.Multimedia.Camera.Core 510 511**参数:** 512 513| 参数名 | 类型 | 必填 | 说明 | 514| -------- | ----------------------------------------------- | ---- | ------------------------------- | 515| profile | [Profile](#profile) | 是 | 支持的预览配置信息,通过[getSupportedOutputCapability](#getsupportedoutputcapability11)接口获取。| 516| surfaceId| string | 是 | 从[XComponent](../apis-arkui/arkui-ts/ts-basic-components-xcomponent.md)或者[ImageReceiver](../apis-image-kit/js-apis-image.md#imagereceiver9)组件获取的surfaceId。| 517 518**返回值:** 519 520| 类型 | 说明 | 521| ---------- | ----------------------------- | 522| [PreviewOutput](#previewoutput) | PreviewOutput实例。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 523 524**错误码:** 525 526以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 527 528| 错误码ID | 错误信息 | 529| --------------- | --------------- | 530| 7400101 | Parameter missing or parameter type incorrect. | 531| 7400201 | Camera service fatal error. | 532 533**示例:** 534 535```ts 536import { BusinessError } from '@kit.BasicServicesKit'; 537 538function createPreviewOutput(cameraOutputCapability: camera.CameraOutputCapability, cameraManager: camera.CameraManager, surfaceId: string): camera.PreviewOutput | undefined { 539 let profile: camera.Profile = cameraOutputCapability.previewProfiles[0]; 540 let previewOutput: camera.PreviewOutput | undefined = undefined; 541 try { 542 previewOutput = cameraManager.createPreviewOutput(profile, surfaceId); 543 } catch (error) { 544 // 失败返回错误码error.code并处理 545 let err = error as BusinessError; 546 console.error(`The createPreviewOutput call failed. error code: ${err.code}`); 547 } 548 return previewOutput; 549} 550``` 551 552### createPreviewOutput<sup>12+</sup> 553 554createPreviewOutput(surfaceId: string): PreviewOutput 555 556创建无配置信息的预览输出对象,同步返回结果。该接口需配合[preconfig](#preconfig12)一起使用。 557 558**系统能力:** SystemCapability.Multimedia.Camera.Core 559 560**参数:** 561 562| 参数名 | 类型 | 必填 | 说明 | 563| -------- | ----------------------------------------------- | ---- | ------------------------------- | 564| surfaceId| string | 是 | 从[XComponent](../apis-arkui/arkui-ts/ts-basic-components-xcomponent.md)或者[ImageReceiver](../apis-image-kit/js-apis-image.md#imagereceiver9)组件获取的surfaceId。| 565 566**返回值:** 567 568| 类型 | 说明 | 569| ---------- | ----------------------------- | 570| [PreviewOutput](#previewoutput) | PreviewOutput实例。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 571 572**错误码:** 573 574以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 575 576| 错误码ID | 错误信息 | 577|---------|------------------------------------------------| 578| 7400101 | Parameter missing or parameter type incorrect. | 579| 7400201 | Camera service fatal error. | 580 581**示例:** 582 583```ts 584import { BusinessError } from '@kit.BasicServicesKit'; 585 586function createPreviewOutput(cameraManager: camera.CameraManager, surfaceId: string): camera.PreviewOutput | undefined { 587 let previewOutput: camera.PreviewOutput | undefined = undefined; 588 try { 589 previewOutput = cameraManager.createPreviewOutput(surfaceId); 590 } catch (error) { 591 // 失败返回错误码error.code并处理 592 let err = error as BusinessError; 593 console.error(`The createPreviewOutput call failed. error code: ${err.code}`); 594 } 595 return previewOutput; 596} 597``` 598 599### createPhotoOutput<sup>(deprecated)</sup> 600 601createPhotoOutput(profile: Profile, surfaceId: string): PhotoOutput 602 603创建拍照输出对象,同步返回结果。 604 605> **说明:** 606> 从 API version 10开始支持,从API version 11开始废弃。建议使用[createPhotoOutput](#createphotooutput11)替代。 607 608**系统能力:** SystemCapability.Multimedia.Camera.Core 609 610**参数:** 611 612| 参数名 | 类型 | 必填 | 说明 | 613| -------- | ------------------------------------------- | ---- | ----------------------------------- | 614| profile | [Profile](#profile) | 是 | 支持的拍照配置信息,通过[getSupportedOutputCapability](#getsupportedoutputcapability11)接口获取。| 615| surfaceId| string | 是 | 从[ImageReceiver](../apis-image-kit/js-apis-image.md#imagereceiver9)获取的surfaceId。| 616 617**返回值:** 618 619| 类型 | 说明 | 620| ---------- | ----------------------------- | 621| [PhotoOutput](#photooutput) | PhotoOutput实例。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 622 623**错误码:** 624 625以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 626 627| 错误码ID | 错误信息 | 628| --------------- | --------------- | 629| 7400101 | Parameter missing or parameter type incorrect. | 630 631```ts 632import { BusinessError } from '@kit.BasicServicesKit'; 633 634function createPhotoOutput(cameraOutputCapability: camera.CameraOutputCapability, cameraManager: camera.CameraManager, surfaceId: string): camera.PhotoOutput | undefined { 635 let profile: camera.Profile = cameraOutputCapability.photoProfiles[0]; 636 let photoOutput: camera.PhotoOutput | undefined = undefined; 637 try { 638 photoOutput = cameraManager.createPhotoOutput(profile, surfaceId); 639 } catch (error) { 640 // 失败返回错误码error.code并处理 641 let err = error as BusinessError; 642 console.error(`The createPhotoOutput call failed. error code: ${err.code}`); 643 } 644 return photoOutput; 645} 646``` 647 648### createPhotoOutput<sup>11+</sup> 649 650createPhotoOutput(profile?: Profile): PhotoOutput 651 652创建拍照输出对象,同步返回结果。 653 654**系统能力:** SystemCapability.Multimedia.Camera.Core 655 656**参数:** 657 658| 参数名 | 类型 | 必填 | 说明 | 659| -------- | ------------------------------------------- |----| ----------------------------------- | 660| profile | [Profile](#profile) | 否 | 支持的拍照配置信息,通过[getSupportedOutputCapability](#getsupportedoutputcapability11)接口获取。<br>API 11时,该参数必填;从API version 12开始,如果使用[preconfig](#preconfig12)进行预配置,传入profile参数会覆盖preconfig的预配置参数。| 661 662**返回值:** 663 664| 类型 | 说明 | 665| ---------- | ----------------------------- | 666| [PhotoOutput](#photooutput) | PhotoOutput实例。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 667 668**错误码:** 669 670以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 671 672| 错误码ID | 错误信息 | 673|----------|------------------------------------------------| 674| 7400101 | Parameter missing or parameter type incorrect. | 675| 7400201 | Camera service fatal error. | 676 677**示例:** 678 679```ts 680import { BusinessError } from '@kit.BasicServicesKit'; 681 682function createPhotoOutput(cameraOutputCapability: camera.CameraOutputCapability, cameraManager: camera.CameraManager): camera.PhotoOutput | undefined { 683 let profile: camera.Profile = cameraOutputCapability.photoProfiles[0]; 684 let photoOutput: camera.PhotoOutput | undefined = undefined; 685 try { 686 photoOutput = cameraManager.createPhotoOutput(profile); 687 } catch (error) { 688 // 失败返回错误码error.code并处理 689 let err = error as BusinessError; 690 console.error(`The createPhotoOutput call failed. error code: ${err.code}`); 691 } 692 return photoOutput; 693} 694``` 695 696### createVideoOutput 697 698createVideoOutput(profile: VideoProfile, surfaceId: string): VideoOutput 699 700创建录像输出对象,同步返回结果。 701 702**系统能力:** SystemCapability.Multimedia.Camera.Core 703 704**参数:** 705 706| 参数名 | 类型 | 必填 | 说明 | 707| -------- | ------------------------------------------- | ---- | ------------------------------ | 708| profile | [VideoProfile](#videoprofile) | 是 | 支持的录像配置信息,通过[getSupportedOutputCapability](#getsupportedoutputcapability11)接口获取。 | 709| surfaceId| string | 是 | 从[AVRecorder](../apis-media-kit/js-apis-media.md#avrecorder9)获取的surfaceId。| 710 711**返回值:** 712 713| 类型 | 说明 | 714| ---------- | ----------------------------- | 715| [VideoOutput](#videooutput) | VideoOutput实例。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 716 717**错误码:** 718 719以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 720 721| 错误码ID | 错误信息 | 722| --------------- | --------------- | 723| 7400101 | Parameter missing or parameter type incorrect. | 724| 7400201 | Camera service fatal error. | 725 726**示例:** 727 728```ts 729import { BusinessError } from '@kit.BasicServicesKit'; 730 731function createVideoOutput(cameraOutputCapability: camera.CameraOutputCapability, cameraManager: camera.CameraManager, surfaceId: string): camera.VideoOutput | undefined { 732 let profile: camera.VideoProfile = cameraOutputCapability.videoProfiles[0]; 733 let videoOutput: camera.VideoOutput | undefined = undefined; 734 try { 735 videoOutput = cameraManager.createVideoOutput(profile, surfaceId); 736 } catch (error) { 737 // 失败返回错误码error.code并处理 738 let err = error as BusinessError; 739 console.error(`The createVideoOutput call failed. error code: ${err.code}`); 740 } 741 return videoOutput; 742} 743``` 744 745### createVideoOutput<sup>12+</sup> 746 747createVideoOutput(surfaceId: string): VideoOutput 748 749创建无配置信息的录像输出对象,同步返回结果。该接口需配合[preconfig](#preconfig12-1)功能一起使用。 750 751**系统能力:** SystemCapability.Multimedia.Camera.Core 752 753**参数:** 754 755| 参数名 | 类型 | 必填 | 说明 | 756|-----------|--------|-------|----------------------------------------------------------------------------| 757| surfaceId | string | 是 | 从[AVRecorder](../apis-media-kit/js-apis-media.md#avrecorder9)获取的surfaceId。 | 758 759**返回值:** 760 761| 类型 | 说明 | 762| ---------- | ----------------------------- | 763| [VideoOutput](#videooutput) | VideoOutput实例。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 764 765**错误码:** 766 767以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 768 769| 错误码ID | 错误信息 | 770|----------|------------------------------------------------| 771| 7400101 | Parameter missing or parameter type incorrect. | 772| 7400201 | Camera service fatal error. | 773 774**示例:** 775 776```ts 777import { BusinessError } from '@kit.BasicServicesKit'; 778 779function createVideoOutput(cameraManager: camera.CameraManager, surfaceId: string): camera.VideoOutput | undefined { 780 let videoOutput: camera.VideoOutput | undefined = undefined; 781 try { 782 videoOutput = cameraManager.createVideoOutput(surfaceId); 783 } catch (error) { 784 // 失败返回错误码error.code并处理 785 let err = error as BusinessError; 786 console.error(`The createVideoOutput call failed. error code: ${err.code}`); 787 } 788 return videoOutput; 789} 790``` 791 792### createMetadataOutput 793 794createMetadataOutput(metadataObjectTypes: Array\<MetadataObjectType\>): MetadataOutput 795 796创建metadata流输出对象,同步返回结果。 797 798**系统能力:** SystemCapability.Multimedia.Camera.Core 799 800**参数:** 801 802| 参数名 | 类型 | 必填 | 说明 | 803| -------------------- | -------------------------------------------------- | --- | ---------------------------- | 804| metadataObjectTypes | Array\<[MetadataObjectType](#metadataobjecttype)\> | 是 | metadata流类型信息,通过[getSupportedOutputCapability](#getsupportedoutputcapability11)接口获取。 | 805 806**返回值:** 807 808| 类型 | 说明 | 809| ---------- | ----------------------------- | 810| [MetadataOutput](#metadataoutput) | MetadataOutput实例。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 811 812**错误码:** 813 814以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 815 816| 错误码ID | 错误信息 | 817| --------------- | --------------- | 818| 7400101 | Parameter missing or parameter type incorrect. | 819| 7400201 | Camera service fatal error. | 820 821**示例:** 822 823```ts 824import { BusinessError } from '@kit.BasicServicesKit'; 825 826function createMetadataOutput(cameraManager: camera.CameraManager, cameraOutputCapability: camera.CameraOutputCapability): void { 827 let metadataObjectTypes: Array<camera.MetadataObjectType> = cameraOutputCapability.supportedMetadataObjectTypes; 828 let metadataOutput: camera.MetadataOutput | undefined = undefined; 829 try { 830 metadataOutput = cameraManager.createMetadataOutput(metadataObjectTypes); 831 } catch (error) { 832 // 失败返回错误码error.code并处理 833 let err = error as BusinessError; 834 console.error(`createMetadataOutput error. error code: ${err.code}`); 835 } 836} 837``` 838 839### createCaptureSession<sup>(deprecated)</sup> 840 841createCaptureSession(): CaptureSession 842 843创建CaptureSession实例,同步返回结果。 844 845> **说明:** 846>从 API version 10开始支持,从API version 11开始废弃。建议使用[createSession](#createsession11)替代。 847 848**系统能力:** SystemCapability.Multimedia.Camera.Core 849 850**返回值:** 851 852| 类型 | 说明 | 853| ---------- | ----------------------------- | 854| [CaptureSession](#capturesessiondeprecated) | CaptureSession实例。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 855 856**错误码:** 857 858以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 859 860| 错误码ID | 错误信息 | 861| --------------- | --------------- | 862| 7400201 | Camera service fatal error. | 863 864**示例:** 865 866```ts 867import { BusinessError } from '@kit.BasicServicesKit'; 868 869function createCaptureSession(cameraManager: camera.CameraManager): camera.CaptureSession | undefined { 870 let captureSession: camera.CaptureSession | undefined = undefined; 871 try { 872 captureSession = cameraManager.createCaptureSession(); 873 } catch (error) { 874 // 失败返回错误码error.code并处理 875 let err = error as BusinessError; 876 console.error(`createCaptureSession error. error code: ${err.code}`); 877 } 878 return captureSession; 879} 880``` 881 882### createSession<sup>11+</sup> 883 884createSession\<T extends Session\>(mode: SceneMode): T 885 886创建指定SceneMode的Session实例,同步返回结果。 887 888**系统能力:** SystemCapability.Multimedia.Camera.Core 889 890**参数:** 891 892| 参数名 | 类型 | 必填 | 说明 | 893| -------- | -----------------| ---- | --------- | 894| mode | [SceneMode](#scenemode11) | 是 | 相机支持的模式。传参异常(如超出范围、传入null、未定义等),实际接口不会生效。 | 895 896**返回值:** 897 898| 类型 | 说明 | 899| ---------- | ----------------------------- | 900| [T extends Session](#session11) | Session实例。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 901 902**错误码:** 903 904以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 905 906| 错误码ID | 错误信息 | 907| --------------- | --------------- | 908| 7400201 | Camera service fatal error. | 909 910**示例:** 911 912```ts 913import { BusinessError } from '@kit.BasicServicesKit'; 914 915function createSession(cameraManager: camera.CameraManager, mode: camera.SceneMode): camera.Session | undefined { 916 let photoSession: camera.PhotoSession | undefined = undefined; 917 try { 918 photoSession = cameraManager.createSession(mode) as camera.PhotoSession; 919 } catch (error) { 920 // 失败返回错误码error.code并处理 921 let err = error as BusinessError; 922 console.error(`createCaptureSession error. error code: ${err.code}`); 923 } 924 return photoSession; 925} 926``` 927 928### on('cameraStatus') 929 930on(type: 'cameraStatus', callback: AsyncCallback\<CameraStatusInfo\>): void 931 932相机设备状态回调,通过注册回调函数获取相机的状态变化。使用callback异步回调。 933 934> **说明:** 935> 936> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 937 938**系统能力:** SystemCapability.Multimedia.Camera.Core 939 940**参数:** 941 942| 参数名 | 类型 | 必填 | 说明 | 943| -------- | -----------------| ---- | --------- | 944| type | string | 是 | 监听事件,固定为'cameraStatus'。cameraManager对象获取成功后可监听。目前只支持对设备打开或者关闭会触发该事件并返回对应信息。 | 945| callback | AsyncCallback\<[CameraStatusInfo](#camerastatusinfo)\> | 是 | 回调函数,用于获取镜头状态变化信息。 | | 946 947**示例:** 948 949```ts 950import { BusinessError } from '@kit.BasicServicesKit'; 951 952function callback(err: BusinessError, cameraStatusInfo: camera.CameraStatusInfo): void { 953 if (err !== undefined && err.code !== 0) { 954 console.error('cameraStatus with errorCode = ' + err.code); 955 return; 956 } 957 console.info(`camera : ${cameraStatusInfo.camera.cameraId}`); 958 console.info(`status: ${cameraStatusInfo.status}`); 959} 960 961function registerCameraStatus(cameraManager: camera.CameraManager): void { 962 cameraManager.on('cameraStatus', callback); 963} 964``` 965 966### off('cameraStatus') 967 968off(type: 'cameraStatus', callback?: AsyncCallback\<CameraStatusInfo\>): void 969 970相机设备状态注销回调,通过注销回调函数取消获取相机的状态变化。 971 972**系统能力:** SystemCapability.Multimedia.Camera.Core 973 974**参数:** 975 976| 参数名 | 类型 | 必填 | 说明 | 977| -------- | -----------------| ---- | --------- | 978| type | string | 是 | 监听事件,固定为'cameraStatus'。cameraManager对象获取成功后可监听。 | 979| callback | AsyncCallback\<[CameraStatusInfo](#camerastatusinfo)\> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 980 981**示例:** 982 983```ts 984function unregisterCameraStatus(cameraManager: camera.CameraManager): void { 985 cameraManager.off('cameraStatus'); 986} 987``` 988 989### on('foldStatusChange')<sup>12+</sup> 990 991on(type: 'foldStatusChange', callback: AsyncCallback\<FoldStatusInfo\>): void 992 993开启折叠设备折叠状态变化的监听。使用callback异步回调。 994 995> **说明:** 996> 997> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 998 999**系统能力:** SystemCapability.Multimedia.Camera.Core 1000 1001**参数:** 1002 1003| 参数名 | 类型 | 必填 | 说明 | 1004| -------- | -----------------| ---- | --------- | 1005| type | string | 是 | 监听事件,固定为'foldStatusChange'。表示折叠设备折叠状态发生变化。 | 1006| callback | AsyncCallback\<[FoldStatusInfo](#foldstatusinfo12)\> | 是 | 回调函数。返回折叠设备折叠信息。 | 1007 1008**示例:** 1009 1010```ts 1011import { BusinessError } from '@kit.BasicServicesKit'; 1012 1013function callback(err: BusinessError, foldStatusInfo: camera.FoldStatusInfo): void { 1014 if (err !== undefined && err.code !== 0) { 1015 console.error('foldStatusChange with errorCode = ' + err.code); 1016 return; 1017 } 1018 console.info(`camera length: ${foldStatusInfo.supportedCameras.length}`); 1019 console.info(`foldStatus: ${foldStatusInfo.foldStatus}`); 1020} 1021 1022function registerFoldStatusChange(cameraManager: camera.CameraManager): void { 1023 cameraManager.on('foldStatusChange', callback); 1024} 1025``` 1026 1027### off('foldStatusChange')<sup>12+</sup> 1028 1029off(type: 'foldStatusChange', callback?: AsyncCallback\<FoldStatusInfo\>): void 1030 1031关闭折叠设备折叠状态变化的监听。 1032 1033**系统能力:** SystemCapability.Multimedia.Camera.Core 1034 1035**参数:** 1036 1037| 参数名 | 类型 | 必填 | 说明 | 1038| -------- | -----------------| ---- | --------- | 1039| type | string | 是 | 监听事件,固定为'foldStatusChange'。表示折叠设备折叠状态发生变化。 | 1040| callback | AsyncCallback\<[FoldStatusInfo](#foldstatusinfo12)\> | 否 | 回调函数,返回折叠设备折叠信息。如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 1041 1042**示例:** 1043 1044```ts 1045function unregisterFoldStatusChange(cameraManager: camera.CameraManager): void { 1046 cameraManager.off('foldStatusChange'); 1047} 1048``` 1049 1050### isTorchSupported<sup>11+</sup> 1051 1052isTorchSupported(): boolean 1053 1054检测设备是否支持手电筒。 1055 1056**系统能力:** SystemCapability.Multimedia.Camera.Core 1057 1058**返回值:** 1059 1060| 类型 | 说明 | 1061| ---------- | ----------------------------- | 1062| boolean | 返回true表示设备支持手电筒。 | 1063 1064**示例:** 1065 1066```ts 1067function isTorchSupported(cameraManager: camera.CameraManager): boolean { 1068 let isSupported = cameraManager.isTorchSupported(); 1069 return isSupported; 1070} 1071``` 1072 1073### isTorchModeSupported<sup>11+</sup> 1074 1075isTorchModeSupported(mode: TorchMode): boolean 1076 1077检测是否支持设置的手电筒模式。 1078 1079**系统能力:** SystemCapability.Multimedia.Camera.Core 1080 1081**参数:** 1082 1083| 参数名 | 类型 | 必填 | 说明 | 1084| -------- | --------------- | ---- | --------- | 1085| mode | [TorchMode](#torchmode11) | 是 | 手电筒模式。传参为null或者undefined,作为0处理,手电筒关闭。 | 1086 1087**返回值:** 1088 1089| 类型 | 说明 | 1090| ---------- | ----------------------------- | 1091| boolean | 返回true表示设备支持设置的手电筒模式。 | 1092 1093**示例:** 1094 1095```ts 1096function isTorchModeSupported(cameraManager: camera.CameraManager, torchMode: camera.TorchMode): boolean { 1097 let isSupported = cameraManager.isTorchModeSupported(torchMode); 1098 return isSupported; 1099} 1100``` 1101 1102### getTorchMode<sup>11+</sup> 1103 1104getTorchMode(): TorchMode 1105 1106获取当前设备手电筒模式。 1107 1108**系统能力:** SystemCapability.Multimedia.Camera.Core 1109 1110**返回值:** 1111 1112| 类型 | 说明 | 1113| ---------- | ----------------------------- | 1114| [TorchMode](#torchmode11) | 返回设备当前手电筒模式。 | 1115 1116**示例:** 1117 1118```ts 1119function getTorchMode(cameraManager: camera.CameraManager): camera.TorchMode | undefined { 1120 let torchMode: camera.TorchMode | undefined = undefined; 1121 torchMode = cameraManager.getTorchMode(); 1122 return torchMode; 1123} 1124``` 1125 1126### setTorchMode<sup>11+</sup> 1127 1128setTorchMode(mode: TorchMode): void 1129 1130设置设备手电筒模式。 1131 1132**系统能力:** SystemCapability.Multimedia.Camera.Core 1133 1134**参数:** 1135 1136| 参数名 | 类型 | 必填 | 说明 | 1137| -------- | --------------- | ---- | --------- | 1138| mode | [TorchMode](#torchmode11) | 是 | 手电筒模式。传参为null或者undefined,作为0处理,手电筒关闭。 | 1139 1140**错误码:** 1141 1142以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 1143 1144| 错误码ID | 错误信息 | 1145| --------------- | --------------- | 1146| 7400101 | Parameter missing or parameter type incorrect. | 1147| 7400102 | Operation not allowed. | 1148| 7400201 | Camera service fatal error. | 1149 1150**示例:** 1151 1152```ts 1153import { BusinessError } from '@kit.BasicServicesKit'; 1154 1155function setTorchMode(cameraManager: camera.CameraManager, torchMode: camera.TorchMode): void { 1156 try { 1157 cameraManager.setTorchMode(torchMode); 1158 } catch (error) { 1159 // 失败返回错误码error.code并处理 1160 let err = error as BusinessError; 1161 console.error(`The setTorchMode call failed. error code: ${err.code}`); 1162 } 1163} 1164``` 1165 1166### on('torchStatusChange')<sup>11+</sup> 1167 1168on(type: 'torchStatusChange', callback: AsyncCallback\<TorchStatusInfo\>): void 1169 1170手电筒状态变化回调,通过注册回调函数获取手电筒状态变化。使用callback异步回调。 1171 1172> **说明:** 1173> 1174> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 1175 1176**系统能力:** SystemCapability.Multimedia.Camera.Core 1177 1178**参数:** 1179 1180| 参数名 | 类型 | 必填 | 说明 | 1181| -------- | --------------- | ---- | --------- | 1182| type | string | 是 | 监听事件,固定为'torchStatusChange'。cameraManager对象获取成功后可监听。目前只支持手电筒打开,手电筒关闭,手电筒不可用,手电筒恢复可用会触发该事件并返回对应信息。 | 1183| callback | AsyncCallback\<TorchStatusInfo> | 是 | 回调函数,用于获取手电筒状态变化信息。 | 1184 1185**示例:** 1186 1187```ts 1188import { BusinessError } from '@kit.BasicServicesKit'; 1189 1190function callback(err: BusinessError, torchStatusInfo: camera.TorchStatusInfo): void { 1191 if (err !== undefined && err.code !== 0) { 1192 console.error(`Callback Error, errorCode: ${err.code}`); 1193 return; 1194 } 1195 console.info(`onTorchStatusChange, isTorchAvailable: ${torchStatusInfo.isTorchAvailable}, isTorchActive: ${torchStatusInfo.isTorchActive}, level: ${torchStatusInfo.torchLevel}`); 1196} 1197 1198function registerTorchStatusChange(cameraManager: camera.CameraManager): void { 1199 cameraManager.on('torchStatusChange', callback); 1200} 1201``` 1202 1203### off('torchStatusChange')<sup>11+</sup> 1204 1205off(type: 'torchStatusChange', callback?: AsyncCallback\<TorchStatusInfo\>): void 1206 1207手电筒状态变化注销回调,通过注销回调函数取消获取手电筒状态变化。 1208 1209**系统能力:** SystemCapability.Multimedia.Camera.Core 1210 1211**参数:** 1212 1213| 参数名 | 类型 | 必填 | 说明 | 1214| -------- | --------------- | ---- | --------- | 1215| type | string | 是 | 监听事件,固定为'torchStatusChange'。cameraManager对象获取成功后可监听。 | 1216| callback | AsyncCallback\<TorchStatusInfo> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 1217 1218**示例:** 1219 1220```ts 1221function unregisterTorchStatusChange(cameraManager: camera.CameraManager): void { 1222 cameraManager.off('torchStatusChange'); 1223} 1224``` 1225 1226## TorchMode<sup>11+</sup> 1227 1228枚举,手电筒模式。 1229 1230**系统能力:** SystemCapability.Multimedia.Camera.Core 1231 1232| 名称 | 值 | 说明 | 1233| ---------------------------- | ---- | ------------- | 1234| OFF | 0 | 常关模式。 | 1235| ON | 1 | 常开模式。 | 1236| AUTO | 2 | 自动模式。 | 1237 1238## TorchStatusInfo<sup>11+</sup> 1239 1240手电筒回调返回的接口实例,表示手电筒状态信息。 1241 1242**系统能力:** SystemCapability.Multimedia.Camera.Core 1243 1244| 名称 | 类型 | 只读 | 可选 | 说明 | 1245| ---------------- | ---------- | ---- | ---- | ----------- | 1246| isTorchAvailable | boolean | 是 | 否 | 手电筒是否可用。| 1247| isTorchActive | boolean | 是 | 否 | 手电筒是否被激活。 | 1248| torchLevel | number | 是 | 否 | 手电筒亮度等级。取值范围为[0,1],越靠近1,亮度越大。 | 1249 1250## Size 1251 1252输出能力查询。 1253 1254**系统能力:** SystemCapability.Multimedia.Camera.Core 1255 1256| 名称 | 类型 | 只读 | 可选 | 说明 | 1257| ------ | ------ | ---- |-----| ------------ | 1258| height | number | 否 | 否 | 图像尺寸高(像素)。 | 1259| width | number | 否 | 否 | 图像尺寸宽(像素)。 | 1260 1261## Point 1262 1263点坐标用于对焦、曝光配置。 1264 1265**系统能力:** SystemCapability.Multimedia.Camera.Core 1266 1267| 名称 | 类型 | 只读 | 可选 | 说明 | 1268| ------ | ------ | ------ | ------ | ------------ | 1269| x | number | 否 | 否 | 点的x坐标。 | 1270| y | number | 否 | 否 | 点的y坐标。 | 1271 1272## CameraFormat 1273 1274枚举,输出格式。 1275 1276**系统能力:** SystemCapability.Multimedia.Camera.Core 1277 1278| 名称 | 值 | 说明 | 1279| ----------------------- | --------- | ------------ | 1280| CAMERA_FORMAT_RGBA_8888 | 3 | RGBA_888格式的图片。 | 1281| CAMERA_FORMAT_YUV_420_SP| 1003 | YUV_420_SP格式的图片。 | 1282| CAMERA_FORMAT_JPEG | 2000 | JPEG格式的图片。 | 1283| CAMERA_FORMAT_YCBCR_P010<sup>11+</sup> | 2001 | YCBCR_P010格式的图片。 | 1284| CAMERA_FORMAT_YCRCB_P010<sup>11+</sup> | 2002 | YCRCB_P010格式的图片。 | 1285| CAMERA_FORMAT_HEIC<sup>13+</sup> | 2003 | HEIF格式的图片。 | 1286 1287## VideoCodecType<sup>13+</sup> 1288 1289枚举,视频编码类型。 1290 1291**系统能力:** SystemCapability.Multimedia.Camera.Core 1292 1293| 名称 | 值 | 说明 | 1294|------|------|-------------| 1295| HVC | 0 | 视频编码类型HVC。 | 1296| HEVC | 1 | 视频编码类型HEVC。 | 1297 1298## CameraInput 1299 1300相机设备输入对象。 1301 1302会话中[Session](#session11)使用的相机信息。 1303 1304### open 1305 1306open(callback: AsyncCallback\<void\>): void 1307 1308打开相机,通过注册回调函数获取状态。使用callback异步回调。 1309 1310**系统能力:** SystemCapability.Multimedia.Camera.Core 1311 1312**参数:** 1313 1314| 参数名 | 类型 | 必填 | 说明 | 1315| -------- | -------------------- | ---- | ------------------- | 1316| callback | AsyncCallback\<void\> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 1317 1318**错误码:** 1319 1320以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 1321 1322| 错误码ID | 错误信息 | 1323| --------------- | --------------- | 1324| 7400107 | Can not use camera cause of conflict. | 1325| 7400108 | Camera disabled cause of security reason. | 1326| 7400201 | Camera service fatal error. | 1327 1328**示例:** 1329 1330```ts 1331import { BusinessError } from '@kit.BasicServicesKit'; 1332 1333function openCameraInput(cameraInput: camera.CameraInput): void { 1334 cameraInput.open((err: BusinessError) => { 1335 if (err) { 1336 console.error(`Failed to open the camera, error code: ${err.code}.`); 1337 return; 1338 } 1339 console.info('Callback returned with camera opened.'); 1340 }); 1341} 1342``` 1343 1344### open 1345 1346open(): Promise\<void\> 1347 1348打开相机,通过Promise获取相机的状态。 1349 1350**系统能力:** SystemCapability.Multimedia.Camera.Core 1351 1352**返回值:** 1353 1354| 类型 | 说明 | 1355| -------------- | ----------------------- | 1356| Promise\<void\> | 无返回结果的Promise对象。 | 1357 1358**错误码:** 1359 1360以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 1361 1362| 错误码ID | 错误信息 | 1363| --------------- | --------------- | 1364| 7400107 | Can not use camera cause of conflict. | 1365| 7400108 | Camera disabled cause of security reason. | 1366| 7400201 | Camera service fatal error. | 1367 1368**示例:** 1369 1370```ts 1371import { BusinessError } from '@kit.BasicServicesKit'; 1372 1373function openCameraInput(cameraInput: camera.CameraInput): void { 1374 cameraInput.open().then(() => { 1375 console.info('Promise returned with camera opened.'); 1376 }).catch((error: BusinessError) => { 1377 console.error(`Failed to open the camera, error code: ${error.code}.`); 1378 }); 1379} 1380``` 1381 1382### open<sup>12+</sup> 1383 1384open(isSecureEnabled: boolean): Promise\<bigint\> 1385 1386打开相机,获取安全相机的句柄。 1387 1388**系统能力:** SystemCapability.Multimedia.Camera.Core 1389 1390**参数:** 1391 1392| 参数名 | 类型 | 必填 | 说明 | 1393| -------- | -------------------- | ---- |-------------------------------------------------------------------------| 1394| isSecureEnabled | boolean | 是 | 是否使能以安全的方式打开相机。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 1395 1396**返回值:** 1397 1398| 类型 | 说明 | 1399| -------------- | ----------------------- | 1400| Promise\<bigint\> | 使用Promise的方式获取打开相机句柄。 | 1401 1402**错误码:** 1403 1404以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 1405 1406| 错误码ID | 错误信息 | 1407| --------------- | --------------- | 1408| 7400107 | Can not use camera cause of conflict. | 1409| 7400108 | Camera disabled cause of security reason. | 1410| 7400201 | Camera service fatal error. | 1411 1412**示例:** 1413 1414```ts 1415import { BusinessError } from '@kit.BasicServicesKit'; 1416 1417function openCameraInput(cameraInput: camera.CameraInput): void { 1418 cameraInput.open(true).then(() => { 1419 console.info('Promise returned with camera opened.'); 1420 }).catch((error: BusinessError) => { 1421 console.error(`Failed to open the camera, error code: ${error.code}.`); 1422 }); 1423} 1424``` 1425 1426### close 1427 1428close(callback: AsyncCallback\<void\>\): void 1429 1430关闭相机,通过注册回调函数获取状态。使用callback异步回调。 1431 1432**系统能力:** SystemCapability.Multimedia.Camera.Core 1433 1434**参数:** 1435 1436| 参数名 | 类型 | 必填 | 说明 | 1437| -------- | -------------------- | ---- | -------------------- | 1438| callback | AsyncCallback\<void\> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 1439 1440**错误码:** 1441 1442以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 1443 1444| 错误码ID | 错误信息 | 1445| --------------- | --------------- | 1446| 7400201 | Camera service fatal error. | 1447 1448**示例:** 1449 1450```ts 1451import { BusinessError } from '@kit.BasicServicesKit'; 1452 1453function closeCameraInput(cameraInput: camera.CameraInput): void { 1454 cameraInput.close((err: BusinessError) => { 1455 if (err) { 1456 console.error(`Failed to close the cameras, error code: ${err.code}.`); 1457 return; 1458 } 1459 console.info('Callback returned with camera closed.'); 1460 }); 1461} 1462``` 1463 1464### close 1465 1466close(): Promise\<void\> 1467 1468关闭相机,通过Promise获取状态。 1469 1470**系统能力:** SystemCapability.Multimedia.Camera.Core 1471 1472**返回值:** 1473 1474| 类型 | 说明 | 1475| -------------- | ----------------------- | 1476| Promise\<void\> | 无返回结果的Promise对象。 | 1477 1478**错误码:** 1479 1480以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 1481 1482| 错误码ID | 错误信息 | 1483| --------------- | --------------- | 1484| 7400201 | Camera service fatal error. | 1485 1486**示例:** 1487 1488```ts 1489import { BusinessError } from '@kit.BasicServicesKit'; 1490 1491function closeCameraInput(cameraInput: camera.CameraInput): void { 1492 cameraInput.close().then(() => { 1493 console.info('Promise returned with camera closed.'); 1494 }).catch((error: BusinessError) => { 1495 console.error(`Failed to close the cameras, error code: ${error.code}.`); 1496 }); 1497} 1498``` 1499 1500### on('error') 1501 1502on(type: 'error', camera: CameraDevice, callback: ErrorCallback): void 1503 1504监听CameraInput的错误事件,通过注册回调函数获取结果。使用callback异步回调。 1505 1506> **说明:** 1507> 1508> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 1509 1510**系统能力:** SystemCapability.Multimedia.Camera.Core 1511 1512**参数:** 1513 1514| 参数名 | 类型 | 必填 | 说明 | 1515| -------- | -------------------------------- | --- | ------------------------------------------- | 1516| type | string | 是 | 监听事件,固定为'error',CameraInput对象创建成功可监听。相机设备出错情况下可触发该事件并返回结果,比如设备不可用或者冲突等返回对应错误信息。 | 1517| camera | [CameraDevice](#cameradevice) | 是 | CameraDevice对象。 | 1518| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | 是 | 回调函数,用于获取结果。返回错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 1519 1520**示例:** 1521 1522```ts 1523import { BusinessError } from '@kit.BasicServicesKit'; 1524 1525function callback(err: BusinessError): void { 1526 console.error(`Camera input error code: ${err.code}`); 1527} 1528 1529function registerCameraInputError(cameraInput: camera.CameraInput, camera: camera.CameraDevice): void { 1530 cameraInput.on('error', camera, callback); 1531} 1532``` 1533 1534### off('error') 1535 1536off(type: 'error', camera: CameraDevice, callback?: ErrorCallback): void 1537 1538注销监听CameraInput的错误事件。 1539 1540**系统能力:** SystemCapability.Multimedia.Camera.Core 1541 1542**参数:** 1543 1544| 参数名 | 类型 | 必填 | 说明 | 1545| -------- | -------------------------------- | --- | ------------------------------------------- | 1546| type | string | 是 | 监听事件,固定为'error',CameraInput对象创建成功可监听。相机设备出错情况下可触发该事件并返回结果,比如设备不可用或者冲突等返回对应错误信息。 | 1547| camera | [CameraDevice](#cameradevice) | 是 | CameraDevice对象。 | 1548| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 1549 1550**示例:** 1551 1552```ts 1553function unregisterCameraInputError(cameraInput: camera.CameraInput, camera: camera.CameraDevice): void { 1554 cameraInput.off('error', camera); 1555} 1556``` 1557 1558## CameraOutput 1559 1560会话中[Session](#session11)使用的输出信息,output的基类。 1561 1562### release 1563 1564release(callback: AsyncCallback\<void\>): void 1565 1566释放输出资源,通过注册回调函数获取结果。使用callback异步回调。 1567 1568**系统能力:** SystemCapability.Multimedia.Camera.Core 1569 1570**参数:** 1571 1572| 参数名 | 类型 | 必填 | 说明 | 1573| -------- | -------------------- | ---- | ------------------- | 1574| callback | AsyncCallback\<void\> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 1575 1576**错误码:** 1577 1578以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 1579 1580| 错误码ID | 错误信息 | 1581| --------------- | --------------- | 1582| 7400201 | Camera service fatal error. | 1583 1584**示例:** 1585 1586```ts 1587import { BusinessError } from '@kit.BasicServicesKit'; 1588 1589function releasePreviewOutput(previewOutput: camera.PreviewOutput): void { 1590 previewOutput.release((err: BusinessError) => { 1591 if (err) { 1592 console.error(`Failed to release the Preview output instance ${err.code}`); 1593 return; 1594 } 1595 console.info('Callback invoked to indicate that the preview output instance is released successfully.'); 1596 }); 1597} 1598 1599function releaseVideoOutput(videoOutput: camera.VideoOutput): void { 1600 videoOutput.release((err: BusinessError) => { 1601 if (err) { 1602 console.error(`Failed to release the video output instance ${err.code}`); 1603 return; 1604 } 1605 console.info('Callback invoked to indicate that the video output instance is released successfully.'); 1606 }); 1607} 1608``` 1609 1610### release 1611 1612release(): Promise\<void\> 1613 1614释放输出资源,通过Promise获取结果。 1615 1616**系统能力:** SystemCapability.Multimedia.Camera.Core 1617 1618**返回值:** 1619 1620| 类型 | 说明 | 1621| -------------- | ----------------------- | 1622| Promise\<void\> | 无返回结果的Promise对象。 | 1623 1624**错误码:** 1625 1626以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 1627 1628| 错误码ID | 错误信息 | 1629| --------------- | --------------- | 1630| 7400201 | Camera service fatal error. | 1631 1632**示例:** 1633 1634```ts 1635import { BusinessError } from '@kit.BasicServicesKit'; 1636 1637function releasePreviewOutput(previewOutput: camera.PreviewOutput): void { 1638 previewOutput.release().then(() => { 1639 console.info('Promise returned to indicate that the preview output instance is released successfully.'); 1640 }).catch((error: BusinessError) => { 1641 console.error(`Failed to preview output release, error code: ${error.code}`); 1642 }); 1643} 1644 1645function releaseVideoOutput(videoOutput: camera.VideoOutput): void { 1646 videoOutput.release().then(() => { 1647 console.info('Promise returned to indicate that the video output instance is released successfully.'); 1648 }).catch((error: BusinessError) => { 1649 console.error(`Failed to video output release, error code: ${error.code}`); 1650 }); 1651} 1652``` 1653 1654## PreviewOutput 1655 1656预览输出类。继承[CameraOutput](#cameraoutput)。 1657 1658### start<sup>(deprecated)</sup> 1659 1660start(callback: AsyncCallback\<void\>): void 1661 1662开始输出预览流,通过注册回调函数获取结果。使用callback异步回调。 1663 1664> **说明:** 1665>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.start](#start11)替代。 1666 1667**系统能力:** SystemCapability.Multimedia.Camera.Core 1668 1669**参数:** 1670 1671| 参数名 | 类型 | 必填 | 说明 | 1672| -------- | -------------------- | ---- | -------------------- | 1673| callback | AsyncCallback\<void\> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 1674 1675**错误码:** 1676 1677以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 1678 1679| 错误码ID | 错误信息 | 1680| --------------- | --------------- | 1681| 7400103 | Session not config. | 1682 1683**示例:** 1684 1685```ts 1686import { BusinessError } from '@kit.BasicServicesKit'; 1687 1688function startPreviewOutput(previewOutput: camera.PreviewOutput): void { 1689 previewOutput.start((err: BusinessError) => { 1690 if (err) { 1691 console.error(`Failed to start the preview output, error code: ${err.code}.`); 1692 return; 1693 } 1694 console.info('Callback returned with preview output started.'); 1695 }); 1696} 1697``` 1698 1699### start<sup>(deprecated)</sup> 1700 1701start(): Promise\<void\> 1702 1703开始输出预览流,通过Promise获取结果。 1704 1705> **说明:** 1706>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.start](#start11-1)替代。 1707 1708**系统能力:** SystemCapability.Multimedia.Camera.Core 1709 1710**返回值:** 1711 1712| 类型 | 说明 | 1713| -------------- |-------------------| 1714| Promise\<void\> | 无返回结果的Promise对象。 | 1715 1716**错误码:** 1717 1718以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 1719 1720| 错误码ID | 错误信息 | 1721| --------------- | --------------- | 1722| 7400103 | Session not config. | 1723 1724**示例:** 1725 1726```ts 1727import { BusinessError } from '@kit.BasicServicesKit'; 1728 1729function startPreviewOutput(previewOutput: camera.PreviewOutput): void { 1730 previewOutput.start().then(() => { 1731 console.info('Promise returned with preview output started.'); 1732 }).catch((error: BusinessError) => { 1733 console.error(`Failed to preview output start, error code: ${error.code}.`); 1734 }); 1735} 1736``` 1737 1738### stop<sup>(deprecated)</sup> 1739 1740stop(callback: AsyncCallback\<void\>): void 1741 1742停止输出预览流,通过注册回调函数获取结果。使用callback异步回调。 1743 1744> **说明:** 1745>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.stop](#stop11)替代。 1746 1747**系统能力:** SystemCapability.Multimedia.Camera.Core 1748 1749**参数:** 1750 1751| 参数名 | 类型 | 必填 | 说明 | 1752| -------- | -------------------- | ---- | -------------------- | 1753| callback | AsyncCallback\<void\> | 是 | 回调函数,用于获取结果。 | 1754 1755**示例:** 1756 1757```ts 1758import { BusinessError } from '@kit.BasicServicesKit'; 1759 1760function stopPreviewOutput(previewOutput: camera.PreviewOutput): void { 1761 previewOutput.stop((err: BusinessError) => { 1762 if (err) { 1763 console.error(`Failed to stop the preview output, error code: ${err.code}.`); 1764 return; 1765 } 1766 console.info('Returned with preview output stopped.'); 1767 }) 1768} 1769``` 1770 1771### stop<sup>(deprecated)</sup> 1772 1773stop(): Promise\<void\> 1774 1775停止输出预览流,通过Promise获取结果。 1776 1777> **说明:** 1778>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.stop](#stop11-1)替代。 1779 1780**系统能力:** SystemCapability.Multimedia.Camera.Core 1781 1782**返回值:** 1783 1784| 类型 | 说明 | 1785| -------------- | ------------------------ | 1786| Promise\<void\> | 无返回结果的Promise对象。 | 1787 1788**示例:** 1789 1790```ts 1791import { BusinessError } from '@kit.BasicServicesKit'; 1792 1793function stopPreviewOutput(previewOutput: camera.PreviewOutput): void { 1794 previewOutput.stop().then(() => { 1795 console.info('Callback returned with preview output stopped.'); 1796 }).catch((error: BusinessError) => { 1797 console.error(`Failed to preview output stop, error code: ${error.code}.`); 1798 }); 1799} 1800``` 1801 1802### on('frameStart') 1803 1804on(type: 'frameStart', callback: AsyncCallback\<void\>): void 1805 1806监听预览帧启动,通过注册回调函数获取结果。使用callback异步回调。 1807 1808> **说明:** 1809> 1810> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 1811 1812**系统能力:** SystemCapability.Multimedia.Camera.Core 1813 1814**参数:** 1815 1816| 参数名 | 类型 | 必填 | 说明 | 1817| -------- | -------------------- | ---- | --------------------------------------- | 1818| type | string | 是 | 监听事件,固定为'frameStart',previewOutput创建成功可监听。底层第一次开始曝光时触发该事件并返回。 | 1819| callback | AsyncCallback\<void\> | 是 | 回调函数,用于获取结果。只要有该事件返回就证明预览开始。 | 1820 1821**示例:** 1822 1823```ts 1824import { BusinessError } from '@kit.BasicServicesKit'; 1825 1826function callback(err: BusinessError): void { 1827 if (err !== undefined && err.code !== 0) { 1828 console.error(`Callback Error, errorCode: ${err.code}`); 1829 return; 1830 } 1831 console.info('Preview frame started'); 1832} 1833 1834function registerPreviewOutputFrameStart(previewOutput: camera.PreviewOutput): void { 1835 previewOutput.on('frameStart', callback); 1836} 1837``` 1838 1839### off('frameStart') 1840 1841off(type: 'frameStart', callback?: AsyncCallback\<void\>): void 1842 1843注销监听预览帧启动。 1844 1845**系统能力:** SystemCapability.Multimedia.Camera.Core 1846 1847**参数:** 1848 1849| 参数名 | 类型 | 必填 | 说明 | 1850| -------- | -------------------- | ---- | --------------------------------------- | 1851| type | string | 是 | 监听事件,固定为'frameStart',previewOutput创建成功可监听。 | 1852| callback | AsyncCallback\<void\> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 1853 1854**示例:** 1855 1856```ts 1857function unregisterPreviewOutputFrameStart(previewOutput: camera.PreviewOutput): void { 1858 previewOutput.off('frameStart'); 1859} 1860``` 1861 1862### on('frameEnd') 1863 1864on(type: 'frameEnd', callback: AsyncCallback\<void\>): void 1865 1866监听预览帧结束,通过注册回调函数获取结果。使用callback异步回调。 1867 1868> **说明:** 1869> 1870> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 1871 1872**系统能力:** SystemCapability.Multimedia.Camera.Core 1873 1874**参数:** 1875 1876| 参数名 | 类型 | 必填 | 说明 | 1877| -------- | -------------------- | ---- | ------------------------------------- | 1878| type | string | 是 | 监听事件,固定为'frameEnd',previewOutput创建成功可监听。预览完全结束最后一帧时触发该事件并返回。 | 1879| callback | AsyncCallback\<void\> | 是 | 回调函数,用于获取结果。只要有该事件返回就证明预览结束。 | 1880 1881**示例:** 1882 1883```ts 1884import { BusinessError } from '@kit.BasicServicesKit'; 1885 1886function callback(err: BusinessError): void { 1887 if (err !== undefined && err.code !== 0) { 1888 console.error(`Callback Error, errorCode: ${err.code}`); 1889 return; 1890 } 1891 console.info('Preview frame ended'); 1892} 1893 1894function registerPreviewOutputFrameEnd(previewOutput: camera.PreviewOutput): void { 1895 previewOutput.on('frameEnd', callback); 1896} 1897``` 1898 1899### off('frameEnd') 1900 1901off(type: 'frameEnd', callback?: AsyncCallback\<void\>): void 1902 1903注销监听预览帧结束。 1904 1905**系统能力:** SystemCapability.Multimedia.Camera.Core 1906 1907**参数:** 1908 1909| 参数名 | 类型 | 必填 | 说明 | 1910| -------- | -------------------- | ---- | ------------------------------------- | 1911| type | string | 是 | 监听事件,固定为'frameEnd',previewOutput创建成功可监听。 | 1912| callback | AsyncCallback\<void\> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 1913 1914**示例:** 1915 1916```ts 1917function unregisterPreviewOutputFrameEnd(previewOutput: camera.PreviewOutput): void { 1918 previewOutput.off('frameEnd'); 1919} 1920``` 1921 1922### on('error') 1923 1924on(type: 'error', callback: ErrorCallback): void 1925 1926监听预览输出的错误事件,通过注册回调函数获取结果。使用callback异步回调。 1927 1928> **说明:** 1929> 1930> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 1931 1932**系统能力:** SystemCapability.Multimedia.Camera.Core 1933 1934**参数:** 1935 1936| 参数名 | 类型 | 必填 | 说明 | 1937| -------- | --------------| ---- | ------------------------ | 1938| type | string | 是 | 监听事件,固定为'error',previewOutput创建成功可监听。预览接口使用错误时触发该事件,比如调用[Session.start](#start11-1),[CameraOutput.release](#release-1)等接口发生错误时返回对应错误信息。 | 1939| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | 是 | 回调函数,用于获取错误信息。返回错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 1940 1941**示例:** 1942 1943```ts 1944import { BusinessError } from '@kit.BasicServicesKit'; 1945 1946function callback(previewOutputError: BusinessError): void { 1947 console.error(`Preview output error code: ${previewOutputError.code}`); 1948} 1949 1950function registerPreviewOutputError(previewOutput: camera.PreviewOutput): void { 1951 previewOutput.on('error', callback) 1952} 1953``` 1954 1955### off('error') 1956 1957off(type: 'error', callback?: ErrorCallback): void 1958 1959注销监听预览输出的错误事件。 1960 1961**系统能力:** SystemCapability.Multimedia.Camera.Core 1962 1963**参数:** 1964 1965| 参数名 | 类型 | 必填 | 说明 | 1966| -------- | --------------| ---- | ------------------------ | 1967| type | string | 是 | 监听事件,固定为'error',previewOutput创建成功可监听。 | 1968| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 1969 1970**示例:** 1971 1972```ts 1973function unregisterPreviewOutputError(previewOutput: camera.PreviewOutput): void { 1974 previewOutput.off('error'); 1975} 1976``` 1977 1978### getSupportedFrameRates<sup>12+</sup> 1979 1980 getSupportedFrameRates(): Array\<FrameRateRange\> 1981 1982查询支持的帧率范围。 1983 1984**系统能力:** SystemCapability.Multimedia.Camera.Core 1985 1986**返回值:** 1987| 类型 | 说明 | 1988| ------------- | ------------ | 1989| Array<[FrameRateRange](#frameraterange)> | 支持的帧率范围列表 | 1990 1991**示例:** 1992 1993```ts 1994function getSupportedFrameRates(previewOutput: camera.PreviewOutput): Array<camera.FrameRateRange> { 1995 let supportedFrameRatesArray: Array<camera.FrameRateRange> = previewOutput.getSupportedFrameRates(); 1996 return supportedFrameRatesArray; 1997} 1998``` 1999 2000### setFrameRate<sup>12+</sup> 2001 2002setFrameRate(minFps: number, maxFps: number): void 2003 2004设置预览流帧率范围,设置的范围必须在支持的帧率范围内。 2005进行设置前,可通过[getSupportedFrameRates](#getsupportedframerates12)查询支持的帧率范围。 2006 2007> **说明:** 2008> 仅在[PhotoSession](#photosession11)或[VideoSession](#videosession11)模式下支持。 2009 2010**系统能力:** SystemCapability.Multimedia.Camera.Core 2011 2012**参数:** 2013 2014| 参数名 | 类型 | 必填 | 说明 | 2015| -------- | --------------| ---- | ------------------------ | 2016| minFps | number | 是 | 最小帧率。 | 2017| maxFps | number | 是 | 最大帧率,当传入的最小值大于最大值时,传参异常,接口不生效。| 2018 2019**错误码:** 2020 2021以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 2022 2023| 错误码ID | 错误信息 | 2024| --------------- | --------------- | 2025| 7400101 | Parameter missing or parameter type incorrect. | 2026| 7400110 | Unresolved conflicts with current configurations. | 2027 2028**示例:** 2029 2030```ts 2031function setFrameRateRange(previewOutput: camera.PreviewOutput, frameRateRange: Array<number>): void { 2032 previewOutput.setFrameRate(frameRateRange[0], frameRateRange[1]); 2033} 2034``` 2035 2036### getActiveFrameRate<sup>12+</sup> 2037 2038getActiveFrameRate(): FrameRateRange 2039 2040获取已设置的帧率范围。 2041 2042使用[setFrameRate](#setframerate12)对预览流设置过帧率后可查询。 2043 2044**系统能力:** SystemCapability.Multimedia.Camera.Core 2045 2046**返回值:** 2047 2048| 类型 | 说明 | 2049| ------------- | ------------ | 2050| [FrameRateRange](#frameraterange) | 帧率范围 | 2051 2052**示例:** 2053 2054```ts 2055function getActiveFrameRate(previewOutput: camera.PreviewOutput): camera.FrameRateRange { 2056 let activeFrameRate: camera.FrameRateRange = previewOutput.getActiveFrameRate(); 2057 return activeFrameRate; 2058} 2059``` 2060 2061### getActiveProfile<sup>12+</sup> 2062 2063getActiveProfile(): Profile 2064 2065获取当前生效的配置信息。 2066 2067**系统能力:** SystemCapability.Multimedia.Camera.Core 2068 2069**返回值:** 2070 2071| 类型 | 说明 | 2072| ------------- |-----------| 2073| [Profile](#profile) | 当前生效的配置信息 | 2074 2075**错误码:** 2076 2077以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 2078 2079| 错误码ID | 错误信息 | 2080|---------|------------------------------| 2081| 7400201 | Camera service fatal error. | 2082 2083**示例:** 2084 2085```ts 2086function testGetActiveProfile(previewOutput: camera.PreviewOutput): camera.Profile | undefined { 2087 let activeProfile: camera.Profile | undefined = undefined; 2088 try { 2089 activeProfile = previewOutput.getActiveProfile(); 2090 } catch (error) { 2091 // 失败返回错误码error.code并处理 2092 let err = error as BusinessError; 2093 console.error(`The previewOutput.getActiveProfile call failed. error code: ${err.code}`); 2094 } 2095 return activeProfile; 2096} 2097``` 2098 2099### getPreviewRotation<sup>12+</sup> 2100 2101getPreviewRotation(displayRotation: number): ImageRotation 2102 2103获取预览旋转角度。 2104 2105- 设备自然方向:设备默认使用方向,手机为竖屏(充电口向下)。 2106- 相机镜头角度:值等于相机图像顺时针旋转到设备自然方向的角度,手机后置相机传感器是竖屏安装的,所以需要顺时针旋转90度到设备自然方向。 2107- 屏幕显示方向:需要屏幕显示的图片左上角为第一个像素点为坐标原点。锁屏时与自然方向一致。 2108 2109**系统能力:** SystemCapability.Multimedia.Camera.Core 2110 2111**参数:** 2112 2113| 参数名 | 类型 | 必填 | 说明 | 2114| -------- | --------------| ---- | ------------------------ | 2115| displayRotation | number | 是 | 显示设备的屏幕旋转角度,通过[display.getDefaultDisplaySync](../apis-arkui/js-apis-display.md#displaygetdefaultdisplaysync9)获得。 | 2116 2117**返回值:** 2118 2119| 类型 | 说明 | 2120| ------------- |-----------| 2121| [ImageRotation](#imagerotation) | 获取预览旋转角度。 | 2122 2123**错误码:** 2124 2125以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 2126 2127| 错误码ID | 错误信息 | 2128|---------|------------------------------| 2129| 7400101 | Parameter missing or parameter type incorrect. | 2130| 7400201 | Camera service fatal error. | 2131 2132**示例:** 2133 2134```ts 2135function testGetPreviewRotation(previewOutput: camera.PreviewOutput, imageRotation : camera.ImageRotation): camera.ImageRotation { 2136 let previewRotation: camera.ImageRotation; 2137 try { 2138 previewRotation = previewOutput.getPreviewRotation(imageRotation); 2139 console.log(`Preview rotation is: ${previewRotation}`); 2140 } catch (error) { 2141 // 失败返回错误码error.code并处理 2142 let err = error as BusinessError; 2143 console.error(`The previewOutput.getPreviewRotation call failed. error code: ${err.code}`); 2144 } 2145 return; 2146} 2147``` 2148### setPreviewRotation<sup>12+</sup> 2149setPreviewRotation(previewRotation: ImageRotation, isDisplayLocked?: boolean): void 2150 2151设置预览旋转角度。 2152 2153**系统能力:** SystemCapability.Multimedia.Camera.Core 2154 2155**参数:** 2156 2157| 参数名 | 类型 | 必填 | 说明 | 2158| -------- | --------------| ---- | ------------------------ | 2159| previewRotation | [ImageRotation](#imagerotation) | 是 | 预览旋转角度 | 2160| isDisplayLocked | boolean | 否 | 是否旋转锁定 | 2161 2162**错误码:** 2163 2164以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 2165 2166| 错误码ID | 错误信息 | 2167|---------|------------------------------| 2168| 7400101 | Parameter missing or parameter type incorrect. | 2169| 7400201 | Camera service fatal error. | 2170 2171**示例:** 2172 2173```ts 2174function testSetPreviewRotation(previewOutput: camera.PreviewOutput, previewRotation : camera.ImageRotation, isDisplayLocked: boolean): void { 2175 try { 2176 previewOutput.setPreviewRotation(previewRotation, isDisplayLocked); 2177 } catch (error) { 2178 // 失败返回错误码error.code并处理 2179 let err = error as BusinessError; 2180 console.error(`The previewOutput.setPreviewRotation call failed. error code: ${err.code}`); 2181 } 2182 return; 2183} 2184``` 2185## ImageRotation 2186 2187枚举,图片旋转角度。 2188 2189**系统能力:** SystemCapability.Multimedia.Camera.Core 2190 2191| 名称 | 值 | 说明 | 2192| ------------ | ---- | ------------- | 2193| ROTATION_0 | 0 | 图片旋转0度。 | 2194| ROTATION_90 | 90 | 图片旋转90度。 | 2195| ROTATION_180 | 180 | 图片旋转180度。 | 2196| ROTATION_270 | 270 | 图片旋转270度。 | 2197 2198## Location 2199 2200图片地理位置信息。 2201 2202**系统能力:** SystemCapability.Multimedia.Camera.Core 2203 2204| 名称 | 类型 | 只读 | 可选 |说明 | 2205| ------------ | ------ | ---- |-----|------------ | 2206| latitude | number | 否 | 否 |纬度(度)。 | 2207| longitude | number | 否 | 否 |经度(度)。 | 2208| altitude | number | 否 | 否 |海拔(米)。 | 2209 2210## QualityLevel 2211 2212枚举,图片质量。 2213 2214**系统能力:** SystemCapability.Multimedia.Camera.Core 2215 2216| 名称 | 值 | 说明 | 2217| -------------------- | ---- | ------------ | 2218| QUALITY_LEVEL_HIGH | 0 | 图片质量高。 | 2219| QUALITY_LEVEL_MEDIUM | 1 | 图片质量中等。 | 2220| QUALITY_LEVEL_LOW | 2 | 图片质量差。 | 2221 2222 2223## PhotoCaptureSetting 2224 2225拍摄照片的设置。 2226 2227**系统能力:** SystemCapability.Multimedia.Camera.Core 2228 2229| 名称 | 类型 | 只读 | 可选 | 说明 | 2230| -------- | ------------------------------- | ---- | ---- |----------------------------------------------------------------------| 2231| quality | [QualityLevel](#qualitylevel) | 否 | 是 | 图片质量(默认低)。 | 2232| rotation | [ImageRotation](#imagerotation) | 否 | 是 | 图片旋转角度(默认0度,顺时针旋转)。 | 2233| location | [Location](#location) | 否 | 是 | 图片地理位置信息(默认以设备硬件信息为准)。 | 2234| mirror | boolean | 否 | 是 | 镜像使能开关(默认关)。使用之前需要使用[isMirrorSupported](#ismirrorsupported)进行判断是否支持。 | 2235 2236## Photo<sup>11+</sup> 2237 2238全质量图对象。 2239 2240### 属性 2241 2242**系统能力:** SystemCapability.Multimedia.Camera.Core 2243 2244| 名称 | 类型 | 必填 | 说明 | 2245| ------ | ----------------------------- | -------------- | ---------- | 2246| main<sup>11+</sup> | [image.Image](../apis-image-kit/js-apis-image.md#image9) | 是 | 全质量图Image。 | 2247 2248### release<sup>11+</sup> 2249 2250release(): Promise\<void\> 2251 2252释放输出资源,通过Promise获取结果。 2253 2254**系统能力:** SystemCapability.Multimedia.Camera.Core 2255 2256**返回值:** 2257 2258| 类型 | 说明 | 2259| -------------- | ----------------------- | 2260| Promise\<void\> | 无返回结果的Promise对象。 | 2261 2262**示例:** 2263 2264```ts 2265async function releasePhoto(photo: camera.Photo): Promise<void> { 2266 await photo.release(); 2267} 2268``` 2269 2270## PhotoOutput 2271 2272拍照会话中使用的输出信息,继承[CameraOutput](#cameraoutput)。 2273 2274### capture 2275 2276capture(callback: AsyncCallback\<void\>): void 2277 2278以默认设置触发一次拍照,通过注册回调函数获取结果。使用callback异步回调。 2279 2280**系统能力:** SystemCapability.Multimedia.Camera.Core 2281 2282**参数:** 2283 2284| 参数名 | 类型 | 必填 | 说明 | 2285| -------- | -------------------- | ---- | ------------------- | 2286| callback | AsyncCallback\<void\> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 2287 2288**错误码:** 2289 2290以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 2291 2292| 错误码ID | 错误信息 | 2293| --------------- | --------------- | 2294| 7400104 | Session not running. | 2295| 7400201 | Camera service fatal error. | 2296 2297**示例:** 2298 2299```ts 2300import { BusinessError } from '@kit.BasicServicesKit'; 2301 2302function capture(photoOutput: camera.PhotoOutput): void { 2303 photoOutput.capture((err: BusinessError) => { 2304 if (err) { 2305 console.error(`Failed to capture the photo, error code: ${err.code}.`); 2306 return; 2307 } 2308 console.info('Callback invoked to indicate the photo capture request success.'); 2309 }); 2310} 2311``` 2312 2313### capture 2314 2315capture(): Promise\<void\> 2316 2317以默认设置触发一次拍照,通过Promise获取结果。 2318 2319**系统能力:** SystemCapability.Multimedia.Camera.Core 2320 2321**返回值:** 2322 2323| 类型 | 说明 | 2324| -------------- | ------------------------ | 2325| Promise\<void\> | 无返回结果的Promise对象。 | 2326 2327**错误码:** 2328 2329以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 2330 2331| 错误码ID | 错误信息 | 2332| --------------- | --------------- | 2333| 7400104 | Session not running. | 2334| 7400201 | Camera service fatal error. | 2335 2336**示例:** 2337 2338```ts 2339import { BusinessError } from '@kit.BasicServicesKit'; 2340 2341function capture(photoOutput: camera.PhotoOutput): void { 2342 photoOutput.capture().then(() => { 2343 console.info('Promise returned to indicate that photo capture request success.'); 2344 }).catch((error: BusinessError) => { 2345 console.error(`Failed to photo output capture, error code: ${error.code}.`); 2346 }); 2347} 2348``` 2349 2350### capture 2351 2352capture(setting: PhotoCaptureSetting, callback: AsyncCallback\<void\>): void 2353 2354以指定参数触发一次拍照,通过注册回调函数获取结果。使用callback异步回调。 2355 2356**系统能力:** SystemCapability.Multimedia.Camera.Core 2357 2358**参数:** 2359 2360| 参数名 | 类型 | 必填 | 说明 | 2361| -------- | ------------------------------------------- | ---- | -------------------- | 2362| setting | [PhotoCaptureSetting](#photocapturesetting) | 是 | 拍照设置。 | 2363| callback | AsyncCallback\<void\> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 2364 2365**错误码:** 2366 2367以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 2368 2369| 错误码ID | 错误信息 | 2370| --------------- | --------------- | 2371| 7400101 | Parameter missing or parameter type incorrect. | 2372| 7400104 | Session not running. | 2373| 7400201 | Camera service fatal error. | 2374 2375**示例:** 2376 2377```ts 2378import { BusinessError } from '@kit.BasicServicesKit'; 2379 2380function capture(photoOutput: camera.PhotoOutput): void { 2381 let captureLocation: camera.Location = { 2382 latitude: 0, 2383 longitude: 0, 2384 altitude: 0 2385 } 2386 let settings: camera.PhotoCaptureSetting = { 2387 quality: camera.QualityLevel.QUALITY_LEVEL_LOW, 2388 rotation: camera.ImageRotation.ROTATION_0, 2389 location: captureLocation, 2390 mirror: false 2391 } 2392 photoOutput.capture(settings, (err: BusinessError) => { 2393 if (err) { 2394 console.error(`Failed to capture the photo, error code: ${err.code}.`); 2395 return; 2396 } 2397 console.info('Callback invoked to indicate the photo capture request success.'); 2398 }); 2399} 2400``` 2401 2402### capture 2403 2404capture(setting: PhotoCaptureSetting): Promise\<void\> 2405 2406以指定参数触发一次拍照,通过Promise获取结果。 2407 2408**系统能力:** SystemCapability.Multimedia.Camera.Core 2409 2410**参数:** 2411 2412| 参数名 | 类型 | 必填 | 说明 | 2413| ------- | ------------------------------------------- | ---- | -------- | 2414| setting | [PhotoCaptureSetting](#photocapturesetting) | 是 | 拍照设置,传入undefined类型数据按默认无参处理。 | 2415 2416**返回值:** 2417 2418| 类型 | 说明 | 2419| -------------- | ------------------------ | 2420| Promise\<void\> | 无返回结果的Promise对象。 | 2421 2422**错误码:** 2423 2424以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 2425 2426| 错误码ID | 错误信息 | 2427| --------------- | --------------- | 2428| 7400101 | Parameter missing or parameter type incorrect. | 2429| 7400104 | Session not running. | 2430| 7400201 | Camera service fatal error. | 2431 2432**示例:** 2433 2434```ts 2435import { BusinessError } from '@kit.BasicServicesKit'; 2436 2437function capture(photoOutput: camera.PhotoOutput): void { 2438 let captureLocation: camera.Location = { 2439 latitude: 0, 2440 longitude: 0, 2441 altitude: 0 2442 } 2443 let settings: camera.PhotoCaptureSetting = { 2444 quality: camera.QualityLevel.QUALITY_LEVEL_LOW, 2445 rotation: camera.ImageRotation.ROTATION_0, 2446 location: captureLocation, 2447 mirror: false 2448 } 2449 photoOutput.capture(settings).then(() => { 2450 console.info('Promise returned to indicate that photo capture request success.'); 2451 }).catch((error: BusinessError) => { 2452 console.error(`Failed to photo output capture, error code: ${error.code}.`); 2453 }); 2454} 2455``` 2456 2457### on('photoAvailable')<sup>11+</sup> 2458 2459on(type: 'photoAvailable', callback: AsyncCallback\<Photo\>): void 2460 2461注册监听全质量图上报。使用callback异步回调。 2462 2463> **说明:** 2464> 2465> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 2466 2467**系统能力:** SystemCapability.Multimedia.Camera.Core 2468 2469**参数:** 2470 2471| 参数名 | 类型 | 必填 | 说明 | 2472| -------- | ---------- | --- | ------------------------------------ | 2473| type | string | 是 | 监听事件,固定为'photoAvailable',photoOutput创建成功后可监听。 | 2474| callback | AsyncCallback\<[Photo](#photo11)\> | 是 | 回调函数,用于监听全质量图上报。 | 2475 2476**示例:** 2477 2478```ts 2479import { BusinessError } from '@kit.BasicServicesKit'; 2480import { image } from '@kit.ImageKit'; 2481 2482function callback(err: BusinessError, photo: camera.Photo): void { 2483 if (err !== undefined && err.code !== 0) { 2484 console.error(`Callback Error, errorCode: ${err.code}`); 2485 return; 2486 } 2487 let mainImage: image.Image = photo.main; 2488} 2489 2490function registerPhotoOutputPhotoAvailable(photoOutput: camera.PhotoOutput): void { 2491 photoOutput.on('photoAvailable', callback); 2492} 2493``` 2494 2495### off('photoAvailable')<sup>11+</sup> 2496 2497off(type: 'photoAvailable', callback?: AsyncCallback\<Photo\>): void 2498 2499注销监听全质量图上报。 2500 2501**系统能力:** SystemCapability.Multimedia.Camera.Core 2502 2503**参数:** 2504 2505| 参数名 | 类型 | 必填 | 说明 | 2506| -------- | ---------------------- | ---- | ------------------------------------------ | 2507| type | string | 是 | 监听事件,固定为'photoAvailable',photoOutput创建成功后可监听。 | 2508| callback | AsyncCallback\<[Photo](#photo11)\> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 2509 2510**示例:** 2511 2512```ts 2513import { BusinessError } from '@kit.BasicServicesKit'; 2514import { image } from '@kit.ImageKit'; 2515 2516function callback(err: BusinessError, photo: camera.Photo): void { 2517 if (err !== undefined && err.code !== 0) { 2518 console.error(`Callback Error, errorCode: ${err.code}`); 2519 return; 2520 } 2521 let mainImage: image.Image = photo.main; 2522} 2523 2524function unRegisterPhotoOutputPhotoAvailable(photoOutput: camera.PhotoOutput): void { 2525 photoOutput.off('photoAvailable', callback); 2526} 2527``` 2528 2529### on('captureStartWithInfo')<sup>11+</sup> 2530 2531on(type: 'captureStartWithInfo', callback: AsyncCallback\<CaptureStartInfo\>): void 2532 2533监听拍照开始,通过注册回调函数获取[CaptureStartInfo](#capturestartinfo11)。使用callback异步回调。 2534 2535> **说明:** 2536> 2537> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 2538 2539**系统能力:** SystemCapability.Multimedia.Camera.Core 2540 2541**参数:** 2542 2543| 参数名 | 类型 | 必填 | 说明 | 2544| -------- | ---------- | --- | ------------------------------------ | 2545| type | string | 是 | 监听事件,固定为'captureStartWithInfo',photoOutput创建成功后可监听。 | 2546| callback | AsyncCallback\<[CaptureStartInfo](#capturestartinfo11)\> | 是 | 使用callback的方式获取Capture ID。| 2547 2548**示例:** 2549 2550```ts 2551import { BusinessError } from '@kit.BasicServicesKit'; 2552 2553function callback(err: BusinessError, captureStartInfo: camera.CaptureStartInfo): void { 2554 if (err !== undefined && err.code !== 0) { 2555 console.error(`Callback Error, errorCode: ${err.code}`); 2556 return; 2557 } 2558 console.info(`photo capture started, captureStartInfo : ${captureStartInfo}`); 2559} 2560 2561function registerCaptureStartWithInfo(photoOutput: camera.PhotoOutput): void { 2562 photoOutput.on('captureStartWithInfo', callback); 2563} 2564``` 2565 2566### off('captureStartWithInfo')<sup>11+</sup> 2567 2568off(type: 'captureStartWithInfo', callback?: AsyncCallback\<CaptureStartInfo\>): void 2569 2570注销监听拍照。 2571 2572**系统能力:** SystemCapability.Multimedia.Camera.Core 2573 2574**参数:** 2575 2576| 参数名 | 类型 | 必填 | 说明 | 2577| -------- | ---------------------- | ---- | ------------------------------------------ | 2578| type | string | 是 | 监听事件,固定为'captureStartWithInfo',photoOutput创建成功后可监听。 | 2579| callback | AsyncCallback\<[CaptureStartInfo](#capturestartinfo11)\> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 2580 2581**示例:** 2582 2583```ts 2584import { BusinessError } from '@kit.BasicServicesKit'; 2585 2586function unRegisterCaptureStartWithInfo(photoOutput: camera.PhotoOutput): void { 2587 photoOutput.off('captureStartWithInfo'); 2588} 2589``` 2590 2591### isMovingPhotoSupported<sup>12+</sup> 2592 2593isMovingPhotoSupported(): boolean 2594 2595查询是否支持动态照片拍摄。 2596 2597**系统能力:** SystemCapability.Multimedia.Camera.Core 2598 2599**返回值:** 2600 2601| 类型 | 说明 | 2602| -------------- | ----------------------- | 2603| boolean | 返回是否支持动态照片拍照,true表示支持,false表示不支持。 | 2604 2605**错误码:** 2606 2607以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 2608 2609| 错误码ID | 错误信息 | 2610| -------------- | --------------- | 2611| 7400201 | Camera service fatal error. | 2612 2613**示例:** 2614 2615```ts 2616import { BusinessError } from '@kit.BasicServicesKit'; 2617 2618function isMovingPhotoSupported(photoOutput: camera.PhotoOutput): boolean { 2619 let isSupported: boolean = false; 2620 try { 2621 isSupported = photoOutput.isMovingPhotoSupported(); 2622 } catch (error) { 2623 // 失败返回错误码error.code并处理 2624 let err = error as BusinessError; 2625 console.error(`The isMovingPhotoSupported call failed. error code: ${err.code}`); 2626 } 2627 return isSupported; 2628} 2629``` 2630 2631### enableMovingPhoto<sup>12+</sup> 2632 2633enableMovingPhoto(enabled: boolean): void 2634 2635使能动态照片拍照。 2636 2637**需要权限:** ohos.permission.MICROPHONE 2638 2639**系统能力:** SystemCapability.Multimedia.Camera.Core 2640 2641**参数:** 2642 2643| 参数名 | 类型 | 必填 | 说明 | 2644| -------- | ---------------------- | ---- | ------------------------------------------ | 2645| enabled | boolean | 是 | true为开启动态照片,false为关闭动态照片。 | 2646 2647**错误码:** 2648 2649以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 2650 2651| 错误码ID | 错误信息 | 2652| -------- |------------------------------------------------| 2653| 201 | permission denied. | 2654| 7400101 | Parameter missing or parameter type incorrect. | 2655| 7400201 | Camera service fatal error. | 2656 2657**示例:** 2658 2659```ts 2660import { BusinessError } from '@kit.BasicServicesKit'; 2661 2662function enableMovingPhoto(photoOutput: camera.PhotoOutput): void { 2663 try { 2664 photoOutput.enableMovingPhoto(true); 2665 } catch (error) { 2666 // 失败返回错误码error.code并处理 2667 let err = error as BusinessError; 2668 console.error(`The enableMovingPhoto call failed. error code: ${err.code}`); 2669 } 2670} 2671``` 2672 2673### on('photoAssetAvailable')<sup>12+</sup> 2674 2675on(type: 'photoAssetAvailable', callback: AsyncCallback\<photoAccessHelper.PhotoAsset\>): void 2676 2677注册监听photoAsset上报。使用callback异步回调。 2678 2679> **说明:** 2680> 2681> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 2682 2683**系统能力:** SystemCapability.Multimedia.Camera.Core 2684 2685**参数:** 2686 2687| 参数名 | 类型 | 必填 | 说明 | 2688| -------- | ---------- | --- | ------------------------------------ | 2689| type | string | 是 | 监听事件,固定为'photoAssetAvailable',photoOutput创建成功后可监听。 | 2690| callback | AsyncCallback\<[photoAccessHelper.PhotoAsset](../apis-media-library-kit/js-apis-photoAccessHelper.md#photoasset)\> | 是 | 回调函数,用于监听photoAsset上报。 | 2691 2692**示例:** 2693 2694```ts 2695import { BusinessError } from '@kit.BasicServicesKit'; 2696import { photoAccessHelper } from '@kit.MediaLibraryKit'; 2697 2698function photoAssetAvailableCallback(err: BusinessError, photoAsset: photoAccessHelper.PhotoAsset): void { 2699 if (err) { 2700 console.info(`photoAssetAvailable error: ${JSON.stringify(err)}.`); 2701 return; 2702 } 2703 console.info('photoOutPutCallBack photoAssetAvailable'); 2704 // 开发者可通过photoAsset获取图片相关信息 2705} 2706 2707function onPhotoOutputPhotoAssetAvailable(photoOutput: camera.PhotoOutput): void { 2708 photoOutput.on('photoAssetAvailable', photoAssetAvailableCallback); 2709} 2710``` 2711 2712### off('photoAssetAvailable')<sup>12+</sup> 2713 2714off(type: 'photoAssetAvailable', callback?: AsyncCallback\<photoAccessHelper.PhotoAsset\>): void 2715 2716解注册photoAsset上报。 2717 2718**系统能力:** SystemCapability.Multimedia.Camera.Core 2719 2720**参数:** 2721 2722| 参数名 | 类型 | 必填 | 说明 | 2723| -------- | ---------- |-----|----------------------------------------------------------------------------| 2724| type | string | 是 | 监听事件,固定为'photoAssetAvailable',photoOutput创建成功后可监听。 | 2725| callback | AsyncCallback\<[photoAccessHelper.PhotoAsset](../apis-media-library-kit/js-apis-photoAccessHelper.md#photoasset)\> | 否 | 需要解监听的回调方法。如果callback不为空且与此对应的监听方法一致,不为匿名方法,则解注册该方法;如果callback为空,则解监听所有回调。 | 2726 2727**示例:** 2728 2729```ts 2730function offPhotoOutputPhotoAssetAvailable(photoOutput: camera.PhotoOutput): void { 2731 photoOutput.off('photoAssetAvailable'); 2732} 2733``` 2734 2735### isMirrorSupported 2736 2737isMirrorSupported(): boolean 2738 2739查询是否支持镜像拍照。 2740 2741**系统能力:** SystemCapability.Multimedia.Camera.Core 2742 2743**返回值:** 2744 2745| 类型 | 说明 | 2746| -------------- | ----------------------- | 2747| boolean | 返回是否支持镜像拍照,true表示支持,false表示不支持。 | 2748 2749**示例:** 2750 2751```ts 2752function isMirrorSupported(photoOutput: camera.PhotoOutput): boolean { 2753 let isSupported: boolean = photoOutput.isMirrorSupported(); 2754 return isSupported; 2755} 2756``` 2757 2758### enableMirror<sup>13+</sup> 2759 2760enableMirror(enabled: boolean): void 2761 2762是否启用镜像拍照。 2763 2764**系统能力:** SystemCapability.Multimedia.Camera.Core 2765 2766**参数:** 2767 2768| 参数名 | 类型 | 必填 | 说明 | 2769|----------| ---------------------- | ---- |---------------------------| 2770| enabled | boolean | 是 | true为开启镜像拍照,false为关闭镜像拍照。 | 2771 2772**错误码:** 2773 2774以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 2775 2776| 错误码ID | 错误信息 | 2777| -------- |------------------------------------------------| 2778| 202 | Not System Application. | 2779| 7400101 | Parameter missing or parameter type incorrect. | 2780| 7400103 | Session not config. | 2781 2782**示例:** 2783 2784```ts 2785import { BusinessError } from '@kit.BasicServicesKit'; 2786 2787function enableMirror(photoOutput: camera.PhotoOutput): void { 2788 try { 2789 photoOutput.enableMirror(true); 2790 } catch (error) { 2791 // 失败返回错误码error.code并处理 2792 let err = error as BusinessError; 2793 console.error(`The enableMirror call failed. error code: ${err.code}`); 2794 } 2795} 2796``` 2797 2798### getSupportedMovingPhotoVideoCodecTypes<sup>13+</sup> 2799 2800getSupportedMovingPhotoVideoCodecTypes(): Array\<VideoCodecType\> 2801 2802查询支持的动态照片短视频编码类型。 2803 2804**系统能力:** SystemCapability.Multimedia.Camera.Core 2805 2806**返回值:** 2807 2808| 类型 | 说明 | 2809| -------------- |-------------------| 2810| Array\<[VideoCodecType](#videocodectype13)\> | 支持的动态照片短视频编码类型列表。 | 2811 2812**错误码:** 2813 2814以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 2815 2816| 错误码ID | 错误信息 | 2817| --------------- | --------------- | 2818| 7400201 | Camera service fatal error. | 2819 2820**示例:** 2821 2822```ts 2823function getSupportedMovingPhotoVideoCodecType(photoOutput: camera.PhotoOutput): Array<camera.VideoCodecType> { 2824 let supportedVideoCodecTypesArray: Array<camera.VideoCodecType> = photoOutput.getSupportedMovingPhotoVideoCodecTypes(); 2825 return supportedVideoCodecTypesArray; 2826} 2827``` 2828 2829### setMovingPhotoVideoCodecType<sup>13+</sup> 2830 2831setMovingPhotoVideoCodecType(codecType: VideoCodecType): void 2832 2833设置动态照片短视频编码类型。 2834 2835**系统能力:** SystemCapability.Multimedia.Camera.Core 2836 2837**参数:** 2838 2839| 参数名 | 类型 | 说明 | 2840| ------------- |-------------------------------------| ------------ | 2841| codecType | [VideoCodecType](#videocodectype13) | 获取动态照片短视频编码类型 | 2842 2843**错误码:** 2844 2845以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 2846 2847| 错误码ID | 错误信息 | 2848| --------------- | --------------- | 2849| 7400201 | Camera service fatal error. | 2850 2851**示例:** 2852 2853```ts 2854function setMovingPhotoVideoCodecTypes(photoOutput: camera.PhotoOutput, videoCodecType: camera.VideoCodecType): void { 2855 photoOutput.setMovingPhotoVideoCodecType(videoCodecType); 2856} 2857``` 2858 2859### on('captureStart')<sup>(deprecated)</sup> 2860 2861on(type: 'captureStart', callback: AsyncCallback\<number\>): void 2862 2863监听拍照开始,通过注册回调函数获取Capture ID。使用callback异步回调。 2864 2865> **说明:** 2866> 从 API version 10开始支持,从API version 11开始废弃。建议使用[on('captureStartWithInfo')](#oncapturestartwithinfo11)替代。 2867> 2868> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 2869 2870**系统能力:** SystemCapability.Multimedia.Camera.Core 2871 2872**参数:** 2873 2874| 参数名 | 类型 | 必填 | 说明 | 2875| -------- | ---------------------- | ---- | ------------------------------------------ | 2876| type | string | 是 | 监听事件,固定为'captureStart',photoOutput创建成功后可监听。每次拍照,底层开始曝光时触发该事件并返回。 | 2877| callback | AsyncCallback\<number\> | 是 | 使用callback的方式获取Capture ID。 | 2878 2879**示例:** 2880 2881```ts 2882import { BusinessError } from '@kit.BasicServicesKit'; 2883 2884function callback(err: BusinessError, captureId: number): void { 2885 if (err !== undefined && err.code !== 0) { 2886 console.error(`Callback Error, errorCode: ${err.code}`); 2887 return; 2888 } 2889 console.info(`photo capture started, captureId : ${captureId}`); 2890} 2891 2892function registerPhotoOutputCaptureStart(photoOutput: camera.PhotoOutput): void { 2893 photoOutput.on('captureStart', callback); 2894} 2895``` 2896 2897### off('captureStart')<sup>(deprecated)</sup> 2898 2899off(type: 'captureStart', callback?: AsyncCallback\<number\>): void 2900 2901注销监听拍照开始。 2902 2903> **说明:** 2904> 从 API version 10开始支持,从API version 11开始废弃。建议使用[off('captureStartWithInfo')](#offcapturestartwithinfo11)替代。 2905> 2906> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 2907 2908**系统能力:** SystemCapability.Multimedia.Camera.Core 2909 2910**参数:** 2911 2912| 参数名 | 类型 | 必填 | 说明 | 2913| -------- | ---------------------- | ---- | ------------------------------------------ | 2914| type | string | 是 | 监听事件,固定为'captureStart',photoOutput创建成功后可监听。 | 2915| callback | AsyncCallback\<number\> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 2916 2917**示例:** 2918 2919```ts 2920function unregisterPhotoOutputCaptureStart(photoOutput: camera.PhotoOutput): void { 2921 photoOutput.off('captureStart'); 2922} 2923``` 2924 2925### on('frameShutter') 2926 2927on(type: 'frameShutter', callback: AsyncCallback\<FrameShutterInfo\>): void 2928 2929监听拍照帧输出捕获,通过注册回调函数获取结果。使用callback异步回调。 2930 2931**系统能力:** SystemCapability.Multimedia.Camera.Core 2932 2933**参数:** 2934 2935| 参数名 | 类型 | 必填 | 说明 | 2936| -------- | ---------- | --- | ------------------------------------ | 2937| type | string | 是 | 监听事件,固定为'frameShutter',photoOutput创建成功后可监听。 | 2938| callback | AsyncCallback\<[FrameShutterInfo](#frameshutterinfo)\> | 是 | 回调函数,用于获取相关信息。该回调返回意味着可以再次下发拍照请求。 | 2939 2940**示例:** 2941 2942```ts 2943import { BusinessError } from '@kit.BasicServicesKit'; 2944 2945function callback(err: BusinessError, frameShutterInfo: camera.FrameShutterInfo): void { 2946 if (err !== undefined && err.code !== 0) { 2947 console.error(`Callback Error, errorCode: ${err.code}`); 2948 return; 2949 } 2950 console.info(`CaptureId for frame : ${frameShutterInfo.captureId}`); 2951 console.info(`Timestamp for frame : ${frameShutterInfo.timestamp}`); 2952} 2953 2954function registerPhotoOutputFrameShutter(photoOutput: camera.PhotoOutput): void { 2955 photoOutput.on('frameShutter', callback); 2956} 2957``` 2958 2959### off('frameShutter') 2960 2961off(type: 'frameShutter', callback?: AsyncCallback\<FrameShutterInfo\>): void 2962 2963注销监听拍照帧输出捕获。 2964 2965**系统能力:** SystemCapability.Multimedia.Camera.Core 2966 2967**参数:** 2968 2969| 参数名 | 类型 | 必填 | 说明 | 2970| -------- | ---------- | --- | ------------------------------------ | 2971| type | string | 是 | 监听事件,固定为'frameShutter',photoOutput创建成功后可监听。 | 2972| callback | AsyncCallback\<[FrameShutterInfo](#frameshutterinfo)\> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 2973 2974**示例:** 2975 2976```ts 2977function unregisterPhotoOutputFrameShutter(photoOutput: camera.PhotoOutput): void { 2978 photoOutput.off('frameShutter'); 2979} 2980``` 2981 2982### on('captureEnd') 2983 2984on(type: 'captureEnd', callback: AsyncCallback\<CaptureEndInfo\>): void 2985 2986监听拍照结束,通过注册回调函数获取结果。使用callback异步回调。 2987 2988> **说明:** 2989> 2990> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 2991 2992**系统能力:** SystemCapability.Multimedia.Camera.Core 2993 2994**参数:** 2995 2996| 参数名 | 类型 | 必填 | 说明 | 2997| -------- | --------------- | ---- | ---------------------------------------- | 2998| type | string | 是 | 监听事件,固定为'captureEnd',photoOutput创建成功后可监听。拍照完全结束可触发该事件发生并返回相应信息。 | 2999| callback | AsyncCallback\<[CaptureEndInfo](#captureendinfo)\> | 是 | 回调函数,用于获取相关信息。 | 3000 3001**示例:** 3002 3003```ts 3004import { BusinessError } from '@kit.BasicServicesKit'; 3005 3006function callback(err: BusinessError, captureEndInfo: camera.CaptureEndInfo): void { 3007 if (err !== undefined && err.code !== 0) { 3008 console.error(`Callback Error, errorCode: ${err.code}`); 3009 return; 3010 } 3011 console.info(`photo capture end, captureId : ${captureEndInfo.captureId}`); 3012 console.info(`frameCount : ${captureEndInfo.frameCount}`); 3013} 3014 3015function registerPhotoOutputCaptureEnd(photoOutput: camera.PhotoOutput): void { 3016 photoOutput.on('captureEnd', callback); 3017} 3018``` 3019 3020### off('captureEnd') 3021 3022off(type: 'captureEnd', callback?: AsyncCallback\<CaptureEndInfo\>): void 3023 3024注销监听拍照结束。 3025 3026**系统能力:** SystemCapability.Multimedia.Camera.Core 3027 3028**参数:** 3029 3030| 参数名 | 类型 | 必填 | 说明 | 3031| -------- | --------------- | ---- | ---------------------------------------- | 3032| type | string | 是 | 监听事件,固定为'captureEnd',photoOutput创建成功后可监听。 | 3033| callback | AsyncCallback\<[CaptureEndInfo](#captureendinfo)\> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 3034 3035**示例:** 3036 3037```ts 3038function unregisterPhotoOutputCaptureEnd(photoOutput: camera.PhotoOutput): void { 3039 photoOutput.off('captureEnd'); 3040} 3041``` 3042 3043### on('frameShutterEnd')<sup>12+</sup> 3044 3045on(type: 'frameShutterEnd', callback: AsyncCallback\<FrameShutterEndInfo\>): void 3046 3047监听拍照曝光结束捕获,通过注册回调函数获取结果。使用callback异步回调。 3048 3049> **说明:** 3050> 3051> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 3052 3053**系统能力:** SystemCapability.Multimedia.Camera.Core 3054 3055**参数:** 3056 3057| 参数名 | 类型 | 必填 | 说明 | 3058| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 3059| type | string | 是 | 监听事件,固定为'frameShutterEnd',photoOutput创建成功后可监听。 | 3060| callback | AsyncCallback\<[FrameShutterEndInfo](#frameshutterendinfo12)\> | 是 | 回调函数,用于获取相关信息。该回调返回表示拍照曝光结束。 | 3061 3062**示例:** 3063 3064```ts 3065import { BusinessError } from '@kit.BasicServicesKit'; 3066 3067function callback(err: BusinessError, frameShutterEndInfo: camera.FrameShutterEndInfo): void { 3068 if (err !== undefined && err.code !== 0) { 3069 console.error(`Callback Error, errorCode: ${err.code}`); 3070 return; 3071 } 3072 console.info(`CaptureId for frame : ${frameShutterEndInfo.captureId}`); 3073} 3074 3075function registerPhotoOutputFrameShutterEnd(photoOutput: camera.PhotoOutput): void { 3076 photoOutput.on('frameShutterEnd', callback); 3077} 3078``` 3079 3080### off('frameShutterEnd')<sup>12+</sup> 3081 3082off(type: 'frameShutterEnd', callback?: AsyncCallback\<FrameShutterEndInfo\>): void 3083 3084注销监听拍照帧输出捕获。 3085 3086**系统能力:** SystemCapability.Multimedia.Camera.Core 3087 3088**参数:** 3089 3090| 参数名 | 类型 | 必填 | 说明 | 3091| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 3092| type | string | 是 | 监听事件,固定为'frameShutterEnd',photoOutput创建成功后可监听。 | 3093| callback | AsyncCallback\<[FrameShutterEndInfo](#frameshutterendinfo12)\> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 3094 3095**示例:** 3096 3097```ts 3098function unregisterPhotoOutputFrameShutterEnd(photoOutput: camera.PhotoOutput): void { 3099 photoOutput.off('frameShutterEnd'); 3100} 3101``` 3102 3103### on('captureReady')<sup>12+</sup> 3104 3105on(type: 'captureReady', callback: AsyncCallback\<void\>): void 3106 3107监听可拍下一张,通过注册回调函数获取结果。使用callback异步回调。 3108 3109> **说明:** 3110> 3111> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 3112 3113**系统能力:** SystemCapability.Multimedia.Camera.Core 3114 3115**参数:** 3116 3117| 参数名 | 类型 | 必填 | 说明 | 3118| -------- | --------------------- | ---- | ------------------------------------------------------------ | 3119| type | string | 是 | 监听事件,固定为'captureReady',photoOutput创建成功后可监听。当下一张可拍时可触发该事件发生并返回相应信息。 | 3120| callback | AsyncCallback\<void\> | 是 | 回调函数,用于获取相关信息。 | 3121 3122**示例:** 3123 3124```ts 3125import { BusinessError } from '@kit.BasicServicesKit'; 3126 3127function callback(err: BusinessError): void { 3128 if (err !== undefined && err.code !== 0) { 3129 console.error(`Callback Error, errorCode: ${err.code}`); 3130 return; 3131 } 3132 console.info(`photo capture ready`); 3133} 3134 3135function registerPhotoOutputCaptureReady(photoOutput: camera.PhotoOutput): void { 3136 photoOutput.on('captureReady', callback); 3137} 3138``` 3139 3140### off('captureReady')<sup>12+</sup> 3141 3142off(type: 'captureReady', callback?: AsyncCallback\<void\>): void 3143 3144注销监听可拍下一张。 3145 3146**系统能力:** SystemCapability.Multimedia.Camera.Core 3147 3148**参数:** 3149 3150| 参数名 | 类型 | 必填 | 说明 | 3151| -------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------ | 3152| type | string | 是 | 监听事件,固定为'captureReady',photoOutput创建成功后可监听。 | 3153| callback | AsyncCallback\<[CaptureReadyInfo](#captureendinfo)\> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 3154 3155**示例:** 3156 3157```ts 3158function unregisterPhotoOutputCaptureReady(photoOutput: camera.PhotoOutput): void { 3159 photoOutput.off('captureReady'); 3160} 3161``` 3162 3163### on('estimatedCaptureDuration')<sup>12+</sup> 3164 3165on(type: 'estimatedCaptureDuration', callback: AsyncCallback\<number\>): void 3166 3167监听预估的拍照时间,通过注册回调函数获取结果。使用callback异步回调。 3168 3169> **说明:** 3170> 3171> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 3172 3173**系统能力:** SystemCapability.Multimedia.Camera.Core 3174 3175**参数:** 3176 3177| 参数名 | 类型 | 必填 | 说明 | 3178| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 3179| type | string | 是 | 监听事件,固定为'estimatedCaptureDuration',photoOutput创建成功后可监听。拍照完全结束可触发该事件发生并返回相应信息。 | 3180| callback | AsyncCallback\<number> | 是 | 回调函数,用于获取预估的单次拍照底层出sensor采集帧时间,如果上报-1,代表没有预估时间。 | 3181 3182**示例:** 3183 3184```ts 3185import { BusinessError } from '@kit.BasicServicesKit'; 3186 3187function callback(err: BusinessError, duration: number): void { 3188 if (err !== undefined && err.code !== 0) { 3189 console.error(`Callback Error, errorCode: ${err.code}`); 3190 return; 3191 } 3192 console.info(`photo estimated capture duration : ${duration}`); 3193} 3194 3195function registerPhotoOutputEstimatedCaptureDuration(photoOutput: camera.PhotoOutput): void { 3196 photoOutput.on('estimatedCaptureDuration', callback); 3197} 3198``` 3199 3200### off('estimatedCaptureDuration')<sup>12+</sup> 3201 3202off(type: 'estimatedCaptureDuration', callback?: AsyncCallback\<number\>): void 3203 3204注销监听预估的拍照时间。 3205 3206**系统能力:** SystemCapability.Multimedia.Camera.Core 3207 3208**参数:** 3209 3210| 参数名 | 类型 | 必填 | 说明 | 3211| -------- | ----------------------- | ---- | ------------------------------------------------------------ | 3212| type | string | 是 | 监听事件,固定为'estimatedCaptureDuration',photoOutput创建成功后可监听。 | 3213| callback | AsyncCallback\<number\> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 3214 3215**示例:** 3216 3217```ts 3218function unregisterPhotoOutputEstimatedCaptureDuration(photoOutput: camera.PhotoOutput): void { 3219 photoOutput.off('estimatedCaptureDuration'); 3220} 3221``` 3222 3223### on('error') 3224 3225on(type: 'error', callback: ErrorCallback): void 3226 3227监听拍照输出发生错误,通过注册回调函数获取结果。使用callback异步回调。 3228 3229> **说明:** 3230> 3231> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 3232 3233**系统能力:** SystemCapability.Multimedia.Camera.Core 3234 3235**参数:** 3236 3237| 参数名 | 类型 | 必填 | 说明 | 3238| -------- | ------------- | ---- | ----------------------------------- | 3239| type | string | 是 | 监听事件,固定为'error',photoOutput创建成功后可监听。拍照接口调用时出现错误触发该事件并返回错误信息。 | 3240| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | 是 | 回调函数,用于获取错误信息。返回错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 3241 3242**示例:** 3243 3244```ts 3245import { BusinessError } from '@kit.BasicServicesKit'; 3246 3247function callback(err: BusinessError): void { 3248 console.error(`Photo output error code: ${err.code}`); 3249} 3250 3251function registerPhotoOutputError(photoOutput: camera.PhotoOutput): void { 3252 photoOutput.on('error', callback); 3253} 3254``` 3255 3256### off('error') 3257 3258off(type: 'error', callback?: ErrorCallback): void 3259 3260注销监听拍照输出发生错误。 3261 3262**系统能力:** SystemCapability.Multimedia.Camera.Core 3263 3264**参数:** 3265 3266| 参数名 | 类型 | 必填 | 说明 | 3267| -------- | ------------- | ---- | ----------------------------------- | 3268| type | string | 是 | 监听事件,固定为'error',photoOutput创建成功后可监听。 | 3269| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 3270 3271**示例:** 3272 3273```ts 3274function unregisterPhotoOutputError(photoOutput: camera.PhotoOutput): void { 3275 photoOutput.off('error'); 3276} 3277``` 3278 3279### getActiveProfile<sup>12+</sup> 3280 3281getActiveProfile(): Profile 3282 3283获取当前生效的配置信息。 3284 3285**系统能力:** SystemCapability.Multimedia.Camera.Core 3286 3287**返回值:** 3288 3289| 类型 | 说明 | 3290| ------------- |-----------| 3291| [Profile](#profile) | 当前生效的配置信息 | 3292 3293**错误码:** 3294 3295以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 3296 3297| 错误码ID | 错误信息 | 3298|---------|------------------------------| 3299| 7400201 | Camera service fatal error. | 3300 3301**示例:** 3302 3303```ts 3304function testGetActiveProfile(photoOutput: camera.PhotoOutput): camera.Profile | undefined { 3305 let activeProfile: camera.Profile | undefined = undefined; 3306 try { 3307 activeProfile = photoOutput.getActiveProfile(); 3308 } catch (error) { 3309 // 失败返回错误码error.code并处理 3310 let err = error as BusinessError; 3311 console.error(`The photoOutput.getActiveProfile call failed. error code: ${err.code}`); 3312 } 3313 return activeProfile; 3314} 3315``` 3316### getPhotoRotation<sup>12+</sup> 3317 3318getPhotoRotation(deviceDegree: number): ImageRotation 3319 3320获取拍照旋转角度。 3321 3322- 设备自然方向:设备默认使用方向,手机为竖屏(充电口向下)。 3323- 相机镜头角度:值等于相机图像顺时针旋转到设备自然方向的角度,手机后置相机传感器是竖屏安装的,所以需要顺时针旋转90度到设备自然方向。 3324- 屏幕显示方向:需要屏幕显示的图片左上角为第一个像素点为坐标原点。锁屏时与自然方向一致。 3325 3326**系统能力:** SystemCapability.Multimedia.Camera.Core 3327 3328**参数:** 3329 3330| 参数名 | 类型 | 必填 | 说明 | 3331| -------- | --------------| ---- | ------------------------ | 3332| deviceDegree | number | 是 | 设备旋转角度 | 3333 3334**返回值:** 3335 3336| 类型 | 说明 | 3337| ------------- |-----------| 3338| [ImageRotation](#imagerotation) | 获取拍照旋转角度。 | 3339 3340**错误码:** 3341 3342以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 3343 3344| 错误码ID | 错误信息 | 3345|---------|------------------------------| 3346| 7400101 | Parameter missing or parameter type incorrect. | 3347| 7400201 | Camera service fatal error. | 3348 3349**示例:** 3350 3351```ts 3352function testGetPhotoRotation(photoOutput: camera.PreviewOutput, deviceDegree : number): camera.ImageRotation { 3353 let photoRotation: camera.ImageRotation; 3354 try { 3355 photoRotation = photoOutput.getPhotoRotation(deviceDegree); 3356 console.log(`Photo rotation is: ${photoRotation}`); 3357 } catch (error) { 3358 // 失败返回错误码error.code并处理 3359 let err = error as BusinessError; 3360 console.error(`The photoOutput.getPhotoRotation call failed. error code: ${err.code}`); 3361 } 3362 return; 3363} 3364``` 3365 3366## FrameShutterInfo 3367 3368拍照帧输出信息。 3369 3370**系统能力:** SystemCapability.Multimedia.Camera.Core 3371 3372| 名称 | 类型 | 只读 | 可选 | 说明 | 3373| --------- | ------ | ---- | ---- | ---------- | 3374| captureId | number | 否 | 否 | 拍照的ID。 | 3375| timestamp | number | 否 | 否 | 快门时间戳。 | 3376 3377## FrameShutterEndInfo<sup>12+</sup> 3378 3379拍照曝光结束信息。 3380 3381**系统能力:** SystemCapability.Multimedia.Camera.Core 3382 3383| 名称 | 类型 | 只读 | 可选 | 说明 | 3384| --------- | ------ | ---- | ---- | ---------- | 3385| captureId | number | 否 | 否 | 拍照的ID。 | 3386 3387## CaptureStartInfo<sup>11+</sup> 3388 3389拍照开始信息。 3390 3391**系统能力:** SystemCapability.Multimedia.Camera.Core 3392 3393| 名称 | 类型 | 只读 | 可选 | 说明 | 3394| ---------- | ------ | ---- | ---- | --------- | 3395| captureId | number | 否 | 否 | 拍照的ID。 | 3396| time | number | 否 | 否 | 预估的单次拍照底层出sensor采集帧时间,如果上报-1,代表没有预估时间。 | 3397 3398## CaptureEndInfo 3399 3400拍照停止信息。 3401 3402**系统能力:** SystemCapability.Multimedia.Camera.Core 3403 3404| 名称 | 类型 | 只读 | 可选 | 说明 | 3405| ---------- | ------ | ---- | ---- | ---------| 3406| captureId | number | 否 | 否 | 拍照的ID。 | 3407| frameCount | number | 否 | 否 | 帧数。 | 3408 3409## VideoOutput 3410 3411录像会话中使用的输出信息,继承[CameraOutput](#cameraoutput)。 3412 3413### start 3414 3415start(callback: AsyncCallback\<void\>): void 3416 3417启动录制,通过注册回调函数获取结果。使用callback异步回调。 3418 3419**系统能力:** SystemCapability.Multimedia.Camera.Core 3420 3421**参数:** 3422 3423| 参数名 | 类型 | 必填 | 说明 | 3424| -------- | -------------------- | ---- | -------------------- | 3425| callback | AsyncCallback\<void\> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 3426 3427**错误码:** 3428 3429以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 3430 3431| 错误码ID | 错误信息 | 3432| --------------- | --------------- | 3433| 7400103 | Session not config. | 3434| 7400201 | Camera service fatal error. | 3435 3436**示例:** 3437 3438```ts 3439import { BusinessError } from '@kit.BasicServicesKit'; 3440 3441function startVideoOutput(videoOutput: camera.VideoOutput): void { 3442 videoOutput.start((err: BusinessError) => { 3443 if (err) { 3444 console.error(`Failed to start the video output, error code: ${err.code}.`); 3445 return; 3446 } 3447 console.info('Callback invoked to indicate the video output start success.'); 3448 }); 3449} 3450``` 3451 3452### start 3453 3454start(): Promise\<void\> 3455 3456启动录制,通过Promise获取结果。 3457 3458**系统能力:** SystemCapability.Multimedia.Camera.Core 3459 3460**返回值:** 3461 3462| 类型 | 说明 | 3463| -------------- | ----------------------- | 3464| Promise\<void\> | 无返回结果的Promise对象。 | 3465 3466**错误码:** 3467 3468以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 3469 3470| 错误码ID | 错误信息 | 3471| --------------- | --------------- | 3472| 7400103 | Session not config. | 3473| 7400201 | Camera service fatal error. | 3474 3475**示例:** 3476 3477```ts 3478import { BusinessError } from '@kit.BasicServicesKit'; 3479 3480function startVideoOutput(videoOutput: camera.VideoOutput): void { 3481 videoOutput.start().then(() => { 3482 console.info('Promise returned to indicate that start method execution success.'); 3483 }).catch((error: BusinessError) => { 3484 console.error(`Failed to video output start, error code: ${error.code}.`); 3485 }); 3486} 3487``` 3488 3489### stop 3490 3491stop(callback: AsyncCallback\<void\>): void 3492 3493结束录制,通过注册回调函数获取结果。使用callback异步回调。 3494 3495**系统能力:** SystemCapability.Multimedia.Camera.Core 3496 3497**参数:** 3498 3499| 参数名 | 类型 | 必填 | 说明 | 3500| -------- | -------------------- | ---- | ------------------------ | 3501| callback | AsyncCallback\<void\> | 是 | 回调函数,用于获取结果。 | 3502 3503**示例:** 3504 3505```ts 3506import { BusinessError } from '@kit.BasicServicesKit'; 3507 3508function stopVideoOutput(videoOutput: camera.VideoOutput): void { 3509 videoOutput.stop((err: BusinessError) => { 3510 if (err) { 3511 console.error(`Failed to stop the video output, error code: ${err.code}.`); 3512 return; 3513 } 3514 console.info('Callback invoked to indicate the video output stop success.'); 3515 }); 3516} 3517``` 3518 3519### stop 3520 3521stop(): Promise\<void\> 3522 3523结束录制,通过Promise获取结果。 3524 3525**系统能力:** SystemCapability.Multimedia.Camera.Core 3526 3527**返回值:** 3528 3529| 类型 | 说明 | 3530| -------------- | ----------------------- | 3531| Promise\<void\> | 无返回结果的Promise对象。 | 3532 3533**示例:** 3534 3535```ts 3536import { BusinessError } from '@kit.BasicServicesKit'; 3537 3538function stopVideoOutput(videoOutput: camera.VideoOutput): void { 3539 videoOutput.stop().then(() => { 3540 console.info('Promise returned to indicate that stop method execution success.'); 3541 }).catch((error: BusinessError) => { 3542 console.error(`Failed to video output stop, error code: ${error.code}.`); 3543 }); 3544} 3545``` 3546 3547### on('frameStart') 3548 3549on(type: 'frameStart', callback: AsyncCallback\<void\>): void 3550 3551监听录像开始,通过注册回调函数获取结果。使用callback异步回调。 3552 3553> **说明:** 3554> 3555> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 3556 3557**系统能力:** SystemCapability.Multimedia.Camera.Core 3558 3559**参数:** 3560 3561| 参数名 | 类型 | 必填 | 说明 | 3562| -------- | -------------------- | ---- | ----------------------------------------- | 3563| type | string | 是 | 监听事件,固定为'frameStart',videoOutput创建成功后可监听。底层第一次曝光时触发该事件并返回。 | 3564| callback | AsyncCallback\<void\> | 是 | 回调函数,用于获取结果。 只要有该事件返回就证明录像开始。 | 3565 3566**示例:** 3567 3568```ts 3569import { BusinessError } from '@kit.BasicServicesKit'; 3570 3571function callback(err: BusinessError): void { 3572 if (err !== undefined && err.code !== 0) { 3573 console.error(`Callback Error, errorCode: ${err.code}`); 3574 return; 3575 } 3576 console.info('Video frame started'); 3577} 3578 3579function registerVideoOutputFrameStart(videoOutput: camera.VideoOutput): void { 3580 videoOutput.on('frameStart', callback); 3581} 3582``` 3583 3584### off('frameStart') 3585 3586off(type: 'frameStart', callback?: AsyncCallback\<void\>): void 3587 3588注销监听录像开始。 3589 3590> **说明:** 3591> 3592> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 3593 3594**系统能力:** SystemCapability.Multimedia.Camera.Core 3595 3596**参数:** 3597 3598| 参数名 | 类型 | 必填 | 说明 | 3599| -------- | -------------------- | ---- | ----------------------------------------- | 3600| type | string | 是 | 监听事件,固定为'frameStart',videoOutput创建成功后可监听。 | 3601| callback | AsyncCallback\<void\> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 3602 3603**示例:** 3604 3605```ts 3606function unregisterVideoOutputFrameStart(videoOutput: camera.VideoOutput): void { 3607 videoOutput.off('frameStart'); 3608} 3609 3610``` 3611 3612### on('frameEnd') 3613 3614on(type: 'frameEnd', callback: AsyncCallback\<void\>): void 3615 3616监听录像结束,通过注册回调函数获取结果。使用callback异步回调。 3617 3618**系统能力:** SystemCapability.Multimedia.Camera.Core 3619 3620**参数:** 3621 3622| 参数名 | 类型 | 必填 | 说明 | 3623| -------- | -------------------- | ---- | ------------------------------------------ | 3624| type | string | 是 | 监听事件,固定为'frameEnd',videoOutput创建成功后可监听。录像完全结束最后一帧时触发该事件并返回。 | 3625| callback | AsyncCallback\<void\> | 是 | 回调函数,用于获取结果。 只要有该事件返回就证明录像结束。 | 3626 3627**示例:** 3628 3629```ts 3630import { BusinessError } from '@kit.BasicServicesKit'; 3631 3632function callback(err: BusinessError): void { 3633 if (err !== undefined && err.code !== 0) { 3634 console.error(`Callback Error, errorCode: ${err.code}`); 3635 return; 3636 } 3637 console.info('Video frame ended'); 3638} 3639 3640function registerVideoOutputFrameEnd(videoOutput: camera.VideoOutput): void { 3641 videoOutput.on('frameEnd', callback); 3642} 3643``` 3644 3645### off('frameEnd') 3646 3647off(type: 'frameEnd', callback?: AsyncCallback\<void\>): void 3648 3649注销监听录像结束。 3650 3651**系统能力:** SystemCapability.Multimedia.Camera.Core 3652 3653**参数:** 3654 3655| 参数名 | 类型 | 必填 | 说明 | 3656| -------- | -------------------- | ---- | ------------------------------------------ | 3657| type | string | 是 | 监听事件,固定为'frameEnd',videoOutput创建成功后可监听。 | 3658| callback | AsyncCallback\<void\> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 3659 3660**示例:** 3661 3662```ts 3663function unregisterVideoOutputFrameEnd(videoOutput: camera.VideoOutput): void { 3664 videoOutput.off('frameEnd'); 3665} 3666``` 3667 3668### on('error') 3669 3670on(type: 'error', callback: ErrorCallback): void 3671 3672监听录像输出发生错误,通过注册回调函数获取结果。使用callback异步回调。 3673 3674> **说明:** 3675> 3676> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 3677 3678**系统能力:** SystemCapability.Multimedia.Camera.Core 3679 3680**参数:** 3681 3682| 参数名 | 类型 | 必填 | 说明 | 3683| -------- | ----------- | ---- | -------------------------------------- | 3684| type | string | 是 | 监听事件,固定为'error',videoOutput创建成功后可监听。录像接口调用出现错误时触发该事件并返回对应错误码,比如调用[start](#start-1),[CameraOutput.release](#release-1)接口时出现错误返回对应错误信息。 | 3685| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | 是 | 回调函数,用于获取错误信息。返回错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 3686 3687**示例:** 3688 3689```ts 3690import { BusinessError } from '@kit.BasicServicesKit'; 3691 3692function callback(err: BusinessError): void { 3693 console.error(`Video output error code: ${err.code}`); 3694} 3695 3696function registerVideoOutputError(videoOutput: camera.VideoOutput): void { 3697 videoOutput.on('error', callback); 3698} 3699``` 3700 3701### off('error') 3702 3703off(type: 'error', callback?: ErrorCallback): void 3704 3705注销监听录像输出发生错误。 3706 3707**系统能力:** SystemCapability.Multimedia.Camera.Core 3708 3709**参数:** 3710 3711| 参数名 | 类型 | 必填 | 说明 | 3712| -------- | ------------- | ---- | ----------------------------------- | 3713| type | string | 是 | 监听事件,固定为'error',photoOutput创建成功后可监听。 | 3714| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 3715 3716**示例:** 3717 3718```ts 3719function unregisterVideoOutputError(videoOutput: camera.VideoOutput): void { 3720 videoOutput.off('error'); 3721} 3722``` 3723 3724### getSupportedFrameRates<sup>12+</sup> 3725 3726getSupportedFrameRates(): Array\<FrameRateRange\> 3727 3728查询支持的帧率范围。 3729 3730**系统能力:** SystemCapability.Multimedia.Camera.Core 3731 3732**返回值:** 3733 3734| 类型 | 说明 | 3735| ------------- | ------------ | 3736| Array<[FrameRateRange](#frameraterange)> | 支持的帧率范围列表 | 3737 3738**示例:** 3739 3740```ts 3741function getSupportedFrameRates(videoOutput: camera.VideoOutput): Array<camera.FrameRateRange> { 3742 let supportedFrameRatesArray: Array<camera.FrameRateRange> = videoOutput.getSupportedFrameRates(); 3743 return supportedFrameRatesArray; 3744} 3745``` 3746 3747### setFrameRate<sup>12+</sup> 3748 3749setFrameRate(minFps: number, maxFps: number): void 3750 3751设置录像流帧率范围,设置的范围必须在支持的帧率范围内。 3752 3753进行设置前,可通过[getSupportedFrameRates](#getsupportedframerates12-1)查询支持的帧率范围。 3754 3755> **说明:** 3756> 仅在[PhotoSession](#photosession11)或[VideoSession](#videosession11)模式下支持。 3757 3758**系统能力:** SystemCapability.Multimedia.Camera.Core 3759 3760**参数:** 3761 3762| 参数名 | 类型 | 必填 | 说明 | 3763| -------- | --------------| ---- | ------------------------ | 3764| minFps | number | 是 | 最小帧率。 | 3765| maxFps | number | 是 | 最大帧率。当传入的最小值大于最大值时,传参异常,接口不生效。 | 3766 3767**错误码:** 3768 3769以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 3770 3771| 错误码ID | 错误信息 | 3772| --------------- | --------------- | 3773| 7400101 | Parameter missing or parameter type incorrect. | 3774| 7400110 | Unresolved conflicts with current configurations. | 3775 3776**示例:** 3777 3778```ts 3779function setFrameRateRange(videoOutput: camera.VideoOutput, frameRateRange: Array<number>): void { 3780 videoOutput.setFrameRate(frameRateRange[0], frameRateRange[1]); 3781} 3782``` 3783 3784### getActiveFrameRate<sup>12+</sup> 3785 3786getActiveFrameRate(): FrameRateRange 3787 3788获取已设置的帧率范围。 3789 3790使用[setFrameRate](#setframerate12-1)对录像流设置过帧率后可查询。 3791 3792**系统能力:** SystemCapability.Multimedia.Camera.Core 3793 3794**返回值:** 3795 3796| 类型 | 说明 | 3797| ------------- | ------------ | 3798| [FrameRateRange](#frameraterange) | 帧率范围 | 3799 3800**示例:** 3801 3802```ts 3803function getActiveFrameRate(videoOutput: camera.VideoOutput): camera.FrameRateRange { 3804 let activeFrameRate: camera.FrameRateRange = videoOutput.getActiveFrameRate(); 3805 return activeFrameRate; 3806} 3807``` 3808 3809### getActiveProfile<sup>12+</sup> 3810 3811getActiveProfile(): VideoProfile 3812 3813获取当前生效的配置信息。 3814 3815**系统能力:** SystemCapability.Multimedia.Camera.Core 3816 3817**返回值:** 3818 3819| 类型 | 说明 | 3820| ------------- |-----------| 3821| [VideoProfile](#videoprofile) | 当前生效的配置信息 | 3822 3823**错误码:** 3824 3825以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 3826 3827| 错误码ID | 错误信息 | 3828|---------|------------------------------| 3829| 7400201 | Camera service fatal error. | 3830 3831**示例:** 3832 3833```ts 3834function testGetActiveProfile(videoOutput: camera.VideoOutput): camera.Profile | undefined { 3835 let activeProfile: camera.VideoProfile | undefined = undefined; 3836 try { 3837 activeProfile = videoOutput.getActiveProfile(); 3838 } catch (error) { 3839 // 失败返回错误码error.code并处理 3840 let err = error as BusinessError; 3841 console.error(`The videoOutput.getActiveProfile call failed. error code: ${err.code}`); 3842 } 3843 return activeProfile; 3844} 3845``` 3846 3847### getVideoRotation<sup>12+</sup> 3848 3849getVideoRotation(deviceDegree: number): ImageRotation 3850 3851获取录像旋转角度。 3852 3853- 设备自然方向:设备默认使用方向,手机为竖屏(充电口向下)。 3854- 相机镜头角度:值等于相机图像顺时针旋转到设备自然方向的角度,手机后置相机传感器是竖屏安装的,所以需要顺时针旋转90度到设备自然方向。 3855- 屏幕显示方向:需要屏幕显示的图片左上角为第一个像素点为坐标原点。锁屏时与自然方向一致。 3856 3857**系统能力:** SystemCapability.Multimedia.Camera.Core 3858 3859**参数:** 3860 3861| 参数名 | 类型 | 必填 | 说明 | 3862| -------- | --------------| ---- | ------------------------ | 3863| deviceDegree | number | 是 | 设备旋转角度 | 3864 3865**返回值:** 3866 3867| 类型 | 说明 | 3868| ------------- |-----------| 3869| [ImageRotation](#imagerotation) | 获取录像旋转角度。 | 3870 3871**错误码:** 3872 3873以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 3874 3875| 错误码ID | 错误信息 | 3876|---------|------------------------------| 3877| 7400101 | Parameter missing or parameter type incorrect. | 3878| 7400201 | Camera service fatal error. | 3879 3880**示例:** 3881 3882```ts 3883function testGetVideoRotation(videoOutput: camera.PreviewOutput, deviceDegree : number): camera.ImageRotation { 3884 let videoRotation: camera.ImageRotation; 3885 try { 3886 videoRotation = videoOutput.getVideoRotation(deviceDegree); 3887 console.log(`Video rotation is: ${videoRotation}`); 3888 } catch (error) { 3889 // 失败返回错误码error.code并处理 3890 let err = error as BusinessError; 3891 console.error(`The videoOutput.getVideoRotation call failed. error code: ${err.code}`); 3892 } 3893 return; 3894} 3895``` 3896 3897## MetadataOutput 3898 3899metadata流。继承[CameraOutput](#cameraoutput)。 3900 3901### start 3902 3903start(callback: AsyncCallback\<void\>): void 3904 3905开始输出metadata,通过注册回调函数获取结果。使用callback异步回调。 3906 3907**系统能力:** SystemCapability.Multimedia.Camera.Core 3908 3909**参数:** 3910 3911| 参数名 | 类型 | 必填 | 说明 | 3912| -------- | -------------------------- | ---- | ------------------- | 3913| callback | AsyncCallback\<void\> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 3914 3915**错误码:** 3916 3917以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 3918 3919| 错误码ID | 错误信息 | 3920| --------------- | --------------- | 3921| 7400103 | Session not config. | 3922| 7400201 | Camera service fatal error. | 3923 3924**示例:** 3925 3926```ts 3927import { BusinessError } from '@kit.BasicServicesKit'; 3928 3929function startMetadataOutput(metadataOutput: camera.MetadataOutput): void { 3930 metadataOutput.start((err: BusinessError) => { 3931 if (err) { 3932 console.error(`Failed to start metadata output, error code: ${err.code}.`); 3933 return; 3934 } 3935 console.info('Callback returned with metadata output started.'); 3936 }); 3937} 3938``` 3939 3940### start 3941 3942start(): Promise\<void\> 3943 3944开始输出metadata,通过Promise获取结果。 3945 3946**系统能力:** SystemCapability.Multimedia.Camera.Core 3947 3948**返回值:** 3949 3950| 类型 | 说明 | 3951| ---------------------- | ------------------------ | 3952| Promise\<void\> | 无返回结果的Promise对象。 | 3953 3954**错误码:** 3955 3956以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 3957 3958| 错误码ID | 错误信息 | 3959| --------------- | --------------- | 3960| 7400103 | Session not config. | 3961| 7400201 | Camera service fatal error. | 3962 3963**示例:** 3964 3965```ts 3966import { BusinessError } from '@kit.BasicServicesKit'; 3967 3968function startMetadataOutput(metadataOutput: camera.MetadataOutput): void { 3969 metadataOutput.start().then(() => { 3970 console.info('Callback returned with metadata output started.'); 3971 }).catch((error: BusinessError) => { 3972 console.error(`Failed to metadata output stop, error code: ${error.code}`); 3973 }); 3974} 3975``` 3976 3977### stop 3978 3979stop(callback: AsyncCallback\<void\>): void 3980 3981停止输出metadata,通过注册回调函数获取结果。使用callback异步回调。 3982 3983**系统能力:** SystemCapability.Multimedia.Camera.Core 3984 3985**参数:** 3986 3987| 参数名 | 类型 | 必填 | 说明 | 3988| -------- | -------------------------- | ---- | ------------------- | 3989| callback | AsyncCallback\<void\> | 是 | 回调函数,用于获取结果。 | 3990 3991**示例:** 3992 3993```ts 3994import { BusinessError } from '@kit.BasicServicesKit'; 3995 3996function stopMetadataOutput(metadataOutput: camera.MetadataOutput): void { 3997 metadataOutput.stop((err: BusinessError) => { 3998 if (err) { 3999 console.error(`Failed to stop the metadata output, error code: ${err.code}.`); 4000 return; 4001 } 4002 console.info('Callback returned with metadata output stopped.'); 4003 }) 4004} 4005``` 4006 4007### stop 4008 4009stop(): Promise\<void\> 4010 4011停止输出metadata,通过Promise获取结果。 4012 4013**系统能力:** SystemCapability.Multimedia.Camera.Core 4014 4015**返回值:** 4016 4017| 类型 | 说明 | 4018| ---------------------- | --------------------------- | 4019| Promise\<void\> | 无返回结果的Promise对象。 | 4020 4021**示例:** 4022 4023```ts 4024import { BusinessError } from '@kit.BasicServicesKit'; 4025 4026function stopMetadataOutput(metadataOutput: camera.MetadataOutput): void { 4027 metadataOutput.stop().then(() => { 4028 console.info('Callback returned with metadata output stopped.'); 4029 }).catch((error: BusinessError) => { 4030 console.error(`Failed to metadata output stop, error code: ${error.code}`); 4031 }); 4032} 4033``` 4034 4035### on('metadataObjectsAvailable') 4036 4037on(type: 'metadataObjectsAvailable', callback: AsyncCallback\<Array\<MetadataObject\>\>): void 4038 4039监听检测到的metadata对象,通过注册回调函数获取结果。使用callback异步回调。 4040 4041> **说明:** 4042> 4043> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 4044 4045**系统能力:** SystemCapability.Multimedia.Camera.Core 4046 4047**参数:** 4048 4049| 参数名 | 类型 | 必填 | 说明 | 4050| -------- | -------------- | ---- | ------------------------------------ | 4051| type | string | 是 | 监听事件,固定为'metadataObjectsAvailable',metadataOutput创建成功后可监听。检测到有效的metadata数据时触发该事件发生并返回相应的metadata数据。 | 4052| callback | AsyncCallback\<Array\<[MetadataObject](#metadataobject)\>\> | 是 | 回调函数,用于获取metadata数据。 | 4053 4054**示例:** 4055 4056```ts 4057import { BusinessError } from '@kit.BasicServicesKit'; 4058 4059function callback(err: BusinessError, metadataObjectArr: Array<camera.MetadataObject>): void { 4060 if (err !== undefined && err.code !== 0) { 4061 console.error(`Callback Error, errorCode: ${err.code}`); 4062 return; 4063 } 4064 console.info('metadata output metadataObjectsAvailable'); 4065} 4066 4067function registerMetadataObjectsAvailable(metadataOutput: camera.MetadataOutput): void { 4068 metadataOutput.on('metadataObjectsAvailable', callback); 4069} 4070``` 4071 4072### off('metadataObjectsAvailable') 4073 4074off(type: 'metadataObjectsAvailable', callback?: AsyncCallback\<Array\<MetadataObject\>\>): void 4075 4076注销监听检测到的metadata对象。 4077 4078**系统能力:** SystemCapability.Multimedia.Camera.Core 4079 4080**参数:** 4081 4082| 参数名 | 类型 | 必填 | 说明 | 4083| -------- | -------------- | ---- | ------------------------------------ | 4084| type | string | 是 | 监听事件,固定为'metadataObjectsAvailable',metadataOutput创建成功后可监听。 | 4085| callback | AsyncCallback\<Array\<[MetadataObject](#metadataobject)\>\> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 4086 4087**示例:** 4088 4089```ts 4090function unregisterMetadataObjectsAvailable(metadataOutput: camera.MetadataOutput): void { 4091 metadataOutput.off('metadataObjectsAvailable'); 4092} 4093``` 4094 4095### on('error') 4096 4097on(type: 'error', callback: ErrorCallback): void 4098 4099监听metadata流的错误,通过注册回调函数获取结果。使用callback异步回调。 4100 4101> **说明:** 4102> 4103> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 4104 4105**系统能力:** SystemCapability.Multimedia.Camera.Core 4106 4107**参数:** 4108 4109| 参数名 | 类型 | 必填 | 说明 | 4110| -------- | ------------- | ---- | --------------------------------------- | 4111| type | string | 是 | 监听事件,固定为'error',metadataOutput创建成功后可监听。metadata接口使用错误时触发该事件并返回对应错误码,比如调用[start](#start-3),[CameraOutput.release](#release-1)接口时发生错误返回对应错误信息。 | 4112| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | 是 | 回调函数,用于获取错误信息。返回错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 4113 4114**示例:** 4115 4116```ts 4117import { BusinessError } from '@kit.BasicServicesKit'; 4118 4119function callback(metadataOutputError: BusinessError): void { 4120 console.error(`Metadata output error code: ${metadataOutputError.code}`); 4121} 4122 4123function registerMetadataOutputError(metadataOutput: camera.MetadataOutput): void { 4124 metadataOutput.on('error', callback); 4125} 4126``` 4127 4128### off('error') 4129 4130off(type: 'error', callback?: ErrorCallback): void 4131 4132注销监听metadata流的错误。 4133 4134**系统能力:** SystemCapability.Multimedia.Camera.Core 4135 4136**参数:** 4137 4138| 参数名 | 类型 | 必填 | 说明 | 4139| -------- | ------------- | ---- | --------------------------------------- | 4140| type | string | 是 | 监听事件,固定为'error',metadataOutput创建成功后可监听。 | 4141| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 4142 4143**示例:** 4144 4145```ts 4146function unregisterMetadataOutputError(metadataOutput: camera.MetadataOutput): void { 4147 metadataOutput.off('error'); 4148} 4149``` 4150 4151## MetadataObjectType 4152 4153枚举,metadata流。 4154 4155**系统能力:** SystemCapability.Multimedia.Camera.Core 4156 4157| 名称 | 值 | 说明 | 4158| ------------------------- | ---- | ----------------- | 4159| FACE_DETECTION | 0 | metadata对象类型,用于人脸检测。<br> 检测点应在0-1坐标系内,该坐标系左上角为(0,0),右下角为(1,1)。<br> 此坐标系以设备充电口在右侧时的横向设备方向为基准。<br>例如应用的预览界面布局以设备充电口在下侧时的竖向方向为基准,<br>布局宽高为(w,h), 返回点为(x,y),则转换后的坐标点为(1-y,x)。 | 4160 4161## Rect 4162 4163矩形定义。 4164 4165**系统能力:** SystemCapability.Multimedia.Camera.Core 4166 4167| 名称 | 类型 | 只读 | 可选 | 说明 | 4168| -------- | ------ | ------ |-----| --------------------- | 4169| topLeftX | number | 否 | 否 | 矩形区域左上角x坐标。 | 4170| topLeftY | number | 否 | 否 | 矩形区域左上角y坐标。 | 4171| width | number | 否 | 否 | 矩形宽,相对值,范围[0, 1]。 | 4172| height | number | 否 | 否 | 矩形高,相对值,范围[0, 1]。 | 4173 4174## MetadataObject 4175 4176相机元能力信息,[CameraInput](#camerainput)相机信息中的数据来源,通过metadataOutput.on('metadataObjectsAvailable')接口获取。 4177 4178**系统能力:** SystemCapability.Multimedia.Camera.Core 4179 4180| 名称 | 类型 | 只读 | 可选 |说明 | 4181| ----------- | ------------------------------------------- | ---- | ---- | ----------------- | 4182| type | [MetadataObjectType](#metadataobjecttype) | 是 | 否 | metadata 类型。 | 4183| timestamp | number | 是 | 否 | 当前时间戳(毫秒)。| 4184| boundingBox | [Rect](#rect) | 是 | 否 | metadata 区域框。 | 4185 4186## FlashMode 4187 4188枚举,闪光灯模式。 4189 4190**系统能力:** SystemCapability.Multimedia.Camera.Core 4191 4192| 名称 | 值 | 说明 | 4193| ---------------------- | ---- | ---------- | 4194| FLASH_MODE_CLOSE | 0 | 闪光灯关闭。 | 4195| FLASH_MODE_OPEN | 1 | 闪光灯打开。 | 4196| FLASH_MODE_AUTO | 2 | 自动闪光灯。 | 4197| FLASH_MODE_ALWAYS_OPEN | 3 | 闪光灯常亮。 | 4198 4199## ExposureMode 4200 4201枚举,曝光模式。 4202 4203**系统能力:** SystemCapability.Multimedia.Camera.Core 4204 4205| 名称 | 值 | 说明 | 4206| ----------------------------- | ---- | ----------- | 4207| EXPOSURE_MODE_LOCKED | 0 | 锁定曝光模式。不支持曝光区域中心点设置。 | 4208| EXPOSURE_MODE_AUTO | 1 | 自动曝光模式。支持曝光区域中心点设置,可以使用[AutoExposure.setMeteringPoint](#setmeteringpoint11)设置曝光区域中心点。 | 4209| EXPOSURE_MODE_CONTINUOUS_AUTO | 2 | 连续自动曝光。不支持曝光区域中心点设置。 | 4210 4211## FocusMode 4212 4213枚举,焦距模式。 4214 4215**系统能力:** SystemCapability.Multimedia.Camera.Core 4216 4217| 名称 | 值 | 说明 | 4218| -------------------------- | ---- | ------------ | 4219| FOCUS_MODE_MANUAL | 0 | 手动对焦。通过手动修改相机焦距来改变对焦位置,不支持对焦点设置。 | 4220| FOCUS_MODE_CONTINUOUS_AUTO | 1 | 连续自动对焦。不支持对焦点设置。 | 4221| FOCUS_MODE_AUTO | 2 | 自动对焦。支持对焦点设置,可以使用[Focus.setFocusPoint](#setfocuspoint11)设置对焦点,根据对焦点执行一次自动对焦。 | 4222| FOCUS_MODE_LOCKED | 3 | 对焦锁定。不支持对焦点设置。 | 4223 4224## FocusState 4225 4226枚举,焦距状态。 4227 4228**系统能力:** SystemCapability.Multimedia.Camera.Core 4229 4230| 名称 | 值 | 说明 | 4231| --------------------- | ---- | --------- | 4232| FOCUS_STATE_SCAN | 0 | 触发对焦。 | 4233| FOCUS_STATE_FOCUSED | 1 | 对焦成功。 | 4234| FOCUS_STATE_UNFOCUSED | 2 | 未完成对焦。 | 4235 4236## VideoStabilizationMode 4237 4238枚举,视频防抖模式。 4239 4240**系统能力:** SystemCapability.Multimedia.Camera.Core 4241 4242| 名称 | 值 | 说明 | 4243| --------- | ---- | ------------ | 4244| OFF | 0 | 关闭视频防抖功能。 | 4245| LOW | 1 | 使用基础防抖算法。 | 4246| MIDDLE | 2 | 使用防抖效果一般的防抖算法,防抖效果优于LOW类型。 | 4247| HIGH | 3 | 使用防抖效果最好的防抖算法,防抖效果优于MIDDLE类型。 | 4248| AUTO | 4 | 自动进行选择。 | 4249 4250## Session<sup>11+</sup> 4251 4252会话类,保存一次相机运行所需要的所有资源[CameraInput](#camerainput)、[CameraOutput](#cameraoutput),并向相机设备申请完成相机功能(录像,拍照)。 4253 4254### beginConfig<sup>11+</sup> 4255 4256beginConfig(): void 4257 4258开始配置会话。 4259 4260**系统能力:** SystemCapability.Multimedia.Camera.Core 4261 4262**错误码:** 4263 4264以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 4265 4266| 错误码ID | 错误信息 | 4267| --------------- | --------------- | 4268| 7400105 | Session config locked. | 4269| 7400201 | Camera service fatal error. | 4270 4271**示例:** 4272 4273```ts 4274import { BusinessError } from '@kit.BasicServicesKit'; 4275 4276function beginConfig(session: camera.Session): void { 4277 try { 4278 session.beginConfig(); 4279 } catch (error) { 4280 // 失败返回错误码error.code并处理 4281 let err = error as BusinessError; 4282 console.error(`The beginConfig call failed. error code: ${err.code}`); 4283 } 4284} 4285``` 4286 4287### commitConfig<sup>11+</sup> 4288 4289commitConfig(callback: AsyncCallback\<void\>): void 4290 4291提交配置信息,通过注册回调函数获取结果。使用callback异步回调。 4292 4293**系统能力:** SystemCapability.Multimedia.Camera.Core 4294 4295**参数:** 4296 4297| 参数名 | 类型 | 必填 | 说明 | 4298| -------- | -------------------- | ---- | -------------------- | 4299| callback | AsyncCallback\<void\> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 4300 4301**错误码:** 4302 4303以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 4304 4305| 错误码ID | 错误信息 | 4306| --------------- | --------------- | 4307| 7400102 | Operation not allowed. | 4308| 7400201 | Camera service fatal error. | 4309 4310**示例:** 4311 4312```ts 4313import { BusinessError } from '@kit.BasicServicesKit'; 4314 4315function commitConfig(session: camera.Session): void { 4316 session.commitConfig((err: BusinessError) => { 4317 if (err) { 4318 console.error(`The commitConfig call failed. error code: ${err.code}`); 4319 return; 4320 } 4321 console.info('Callback invoked to indicate the commit config success.'); 4322 }); 4323} 4324``` 4325 4326### commitConfig<sup>11+</sup> 4327 4328commitConfig(): Promise\<void\> 4329 4330提交配置信息,通过Promise获取结果。 4331 4332**系统能力:** SystemCapability.Multimedia.Camera.Core 4333 4334**返回值:** 4335 4336| 类型 | 说明 | 4337| -------------- | ------------------------ | 4338| Promise\<void\> | 无返回结果的Promise对象。 | 4339 4340**错误码:** 4341 4342以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 4343 4344| 错误码ID | 错误信息 | 4345| --------------- | --------------- | 4346| 7400102 | Operation not allowed. | 4347| 7400201 | Camera service fatal error. | 4348 4349**示例:** 4350 4351```ts 4352import { BusinessError } from '@kit.BasicServicesKit'; 4353 4354function commitConfig(session: camera.Session): void { 4355 session.commitConfig().then(() => { 4356 console.info('Promise returned to indicate the commit config success.'); 4357 }).catch((error: BusinessError) => { 4358 // 失败返回错误码error.code并处理 4359 console.error(`The commitConfig call failed. error code: ${error.code}`); 4360 }); 4361} 4362``` 4363 4364### canAddInput<sup>11+</sup> 4365 4366canAddInput(cameraInput: CameraInput): boolean 4367 4368判断当前cameraInput是否可以添加到session中。当前函数需要在[beginConfig](#beginconfig11)和[commitConfig](#commitconfig11-1)之间生效。 4369 4370**系统能力:** SystemCapability.Multimedia.Camera.Core 4371 4372**参数:** 4373 4374| 参数名 | 类型 | 必填 | 说明 | 4375| ----------- | --------------------------- | ---- | ------------------------ | 4376| cameraInput | [CameraInput](#camerainput) | 是 | 需要添加的CameraInput实例。传参异常(如超出范围、传入null、未定义等),实际接口不会生效。 | 4377 4378**返回值:** 4379 4380| 类型 | 说明 | 4381| -------------- | ------------------------ | 4382| boolean | 返回true表示支持添加当前cameraInput,返回false表示不支持添加。 | 4383 4384**示例:** 4385 4386```ts 4387import { BusinessError } from '@kit.BasicServicesKit'; 4388 4389function canAddInput(session: camera.Session, cameraInput: camera.CameraInput): void { 4390 let canAdd: boolean = session.canAddInput(cameraInput); 4391 console.info(`The input canAddInput: ${canAdd}`); 4392} 4393``` 4394 4395### addInput<sup>11+</sup> 4396 4397addInput(cameraInput: CameraInput): void 4398 4399把[CameraInput](#camerainput)加入到会话。 4400 4401**系统能力:** SystemCapability.Multimedia.Camera.Core 4402 4403**参数:** 4404 4405| 参数名 | 类型 | 必填 | 说明 | 4406| ----------- | --------------------------- | ---- | ------------------------ | 4407| cameraInput | [CameraInput](#camerainput) | 是 | 需要添加的CameraInput实例。 | 4408 4409**错误码:** 4410 4411以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 4412 4413| 错误码ID | 错误信息 | 4414| --------------- | --------------- | 4415| 7400101 | Parameter missing or parameter type incorrect. | 4416| 7400102 | Operation not allowed. | 4417| 7400103 | Session not config. | 4418| 7400201 | Camera service fatal error. | 4419 4420**示例:** 4421 4422```ts 4423import { BusinessError } from '@kit.BasicServicesKit'; 4424 4425function addInput(session: camera.Session, cameraInput: camera.CameraInput): void { 4426 try { 4427 session.addInput(cameraInput); 4428 } catch (error) { 4429 // 失败返回错误码error.code并处理 4430 let err = error as BusinessError; 4431 console.error(`The addInput call failed. error code: ${err.code}`); 4432 } 4433} 4434``` 4435 4436### removeInput<sup>11+</sup> 4437 4438removeInput(cameraInput: CameraInput): void 4439 4440移除[CameraInput](#camerainput)。当前函数需要在[beginConfig](#beginconfig11)和[commitConfig](#commitconfig11-1)之间生效。 4441 4442**系统能力:** SystemCapability.Multimedia.Camera.Core 4443 4444**参数:** 4445 4446| 参数名 | 类型 | 必填 | 说明 | 4447| ----------- | --------------------------- | ---- | ------------------------ | 4448| cameraInput | [CameraInput](#camerainput) | 是 | 需要移除的CameraInput实例。 | 4449 4450**错误码:** 4451 4452以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 4453 4454| 错误码ID | 错误信息 | 4455| --------------- | --------------- | 4456| 7400101 | Parameter missing or parameter type incorrect. | 4457| 7400102 | Operation not allowed. | 4458| 7400103 | Session not config. | 4459| 7400201 | Camera service fatal error. | 4460 4461**示例:** 4462 4463```ts 4464import { BusinessError } from '@kit.BasicServicesKit'; 4465 4466function removeInput(session: camera.Session, cameraInput: camera.CameraInput): void { 4467 try { 4468 session.removeInput(cameraInput); 4469 } catch (error) { 4470 // 失败返回错误码error.code并处理 4471 let err = error as BusinessError; 4472 console.error(`The removeInput call failed. error code: ${err.code}`); 4473 } 4474} 4475``` 4476 4477### canAddOutput<sup>11+</sup> 4478 4479canAddOutput(cameraOutput: CameraOutput): boolean 4480 4481判断当前cameraOutput是否可以添加到session中。当前函数需要在[addInput](#addinput11)和[commitConfig](#commitconfig11-1)之间生效。 4482 4483**系统能力:** SystemCapability.Multimedia.Camera.Core 4484 4485**参数:** 4486 4487| 参数名 | 类型 | 必填 | 说明 | 4488| ----------- | --------------------------- | ---- | ------------------------ | 4489| cameraOutput | [CameraOutput](#cameraoutput) | 是 | 需要添加的CameraOutput实例。传参异常(如超出范围、传入null、未定义等),实际接口不会生效。 | 4490 4491**返回值:** 4492 4493| 类型 | 说明 | 4494| -------------- | ------------------------ | 4495| boolean | 是否可以添加当前cameraOutput到session中。 | 4496 4497**示例:** 4498 4499```ts 4500import { BusinessError } from '@kit.BasicServicesKit'; 4501 4502function canAddOutput(session: camera.Session, cameraOutput: camera.CameraOutput): void { 4503 let canAdd: boolean = session.canAddOutput(cameraOutput); 4504 console.info(`This addOutput can add: ${canAdd}`); 4505} 4506``` 4507 4508### addOutput<sup>11+</sup> 4509 4510addOutput(cameraOutput: CameraOutput): void 4511 4512把[CameraOutput](#cameraoutput)加入到会话。 4513 4514**系统能力:** SystemCapability.Multimedia.Camera.Core 4515 4516**参数:** 4517 4518| 参数名 | 类型 | 必填 | 说明 | 4519| ------------- | ------------------------------- | ---- | ------------------------ | 4520| cameraOutput | [CameraOutput](#cameraoutput) | 是 | 需要添加的CameraOutput实例。 | 4521 4522**错误码:** 4523 4524以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 4525 4526| 错误码ID | 错误信息 | 4527| --------------- | --------------- | 4528| 7400101 | Parameter missing or parameter type incorrect. | 4529| 7400102 | Operation not allowed. | 4530| 7400103 | Session not config. | 4531| 7400201 | Camera service fatal error. | 4532 4533**示例:** 4534 4535```ts 4536import { BusinessError } from '@kit.BasicServicesKit'; 4537 4538function addOutput(session: camera.Session, cameraOutput: camera.CameraOutput): void { 4539 try { 4540 session.addOutput(cameraOutput); 4541 } catch (error) { 4542 // 失败返回错误码error.code并处理 4543 let err = error as BusinessError; 4544 console.error(`The addOutput call failed. error code: ${err.code}`); 4545 } 4546} 4547``` 4548 4549### removeOutput<sup>11+</sup> 4550 4551removeOutput(cameraOutput: CameraOutput): void 4552 4553从会话中移除[CameraOutput](#cameraoutput)。 4554 4555**系统能力:** SystemCapability.Multimedia.Camera.Core 4556 4557**参数:** 4558 4559| 参数名 | 类型 | 必填 | 说明 | 4560| ------------- | ------------------------------- | ---- | ------------------------ | 4561| cameraOutput | [CameraOutput](#cameraoutput) | 是 | 需要移除的CameraOutput实例。 | 4562 4563**错误码:** 4564 4565以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 4566 4567| 错误码ID | 错误信息 | 4568| --------------- | --------------- | 4569| 7400101 | Parameter missing or parameter type incorrect. | 4570| 7400102 | Operation not allowed. | 4571| 7400103 | Session not config. | 4572| 7400201 | Camera service fatal error. | 4573 4574**示例:** 4575 4576```ts 4577import { BusinessError } from '@kit.BasicServicesKit'; 4578 4579function removeOutput(session: camera.Session, previewOutput: camera.PreviewOutput): void { 4580 try { 4581 session.removeOutput(previewOutput); 4582 } catch (error) { 4583 // 失败返回错误码error.code并处理 4584 let err = error as BusinessError; 4585 console.error(`The removeOutput call failed. error code: ${err.code}`); 4586 } 4587} 4588``` 4589 4590### start<sup>11+</sup> 4591 4592start(callback: AsyncCallback\<void\>): void 4593 4594开始会话工作,通过注册回调函数获取结果。使用callback异步回调。 4595 4596**系统能力:** SystemCapability.Multimedia.Camera.Core 4597 4598**参数:** 4599 4600| 参数名 | 类型 | 必填 | 说明 | 4601| -------- | -------------------- | ---- | -------------------- | 4602| callback | AsyncCallback\<void\> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 4603 4604**错误码:** 4605 4606以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 4607 4608| 错误码ID | 错误信息 | 4609| --------------- | --------------- | 4610| 7400102 | Operation not allowed. | 4611| 7400103 | Session not config. | 4612| 7400201 | Camera service fatal error. | 4613 4614**示例:** 4615 4616```ts 4617import { BusinessError } from '@kit.BasicServicesKit'; 4618 4619function startCaptureSession(session: camera.Session): void { 4620 session.start((err: BusinessError) => { 4621 if (err) { 4622 console.error(`Failed to start the session, error code: ${err.code}.`); 4623 return; 4624 } 4625 console.info('Callback invoked to indicate the session start success.'); 4626 }); 4627} 4628``` 4629 4630### start<sup>11+</sup> 4631 4632start(): Promise\<void\> 4633 4634开始会话工作,通过Promise获取结果。 4635 4636**系统能力:** SystemCapability.Multimedia.Camera.Core 4637 4638**返回值:** 4639 4640| 类型 | 说明 | 4641| -------------- | ------------------------ | 4642| Promise\<void\> | 无返回结果的Promise对象。 | 4643 4644**错误码:** 4645 4646以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 4647 4648| 错误码ID | 错误信息 | 4649| --------------- | --------------- | 4650| 7400102 | Operation not allowed. | 4651| 7400103 | Session not config. | 4652| 7400201 | Camera service fatal error. | 4653 4654**示例:** 4655 4656```ts 4657import { BusinessError } from '@kit.BasicServicesKit'; 4658 4659function startCaptureSession(session: camera.Session): void { 4660 session.start().then(() => { 4661 console.info('Promise returned to indicate the session start success.'); 4662 }).catch((error: BusinessError) => { 4663 console.error(`Failed to start the session, error code: ${error.code}.`); 4664 }); 4665} 4666``` 4667 4668### stop<sup>11+</sup> 4669 4670stop(callback: AsyncCallback\<void\>): void 4671 4672停止会话工作,通过注册回调函数获取结果。使用callback异步回调。 4673 4674**系统能力:** SystemCapability.Multimedia.Camera.Core 4675 4676**参数:** 4677 4678| 参数名 | 类型 | 必填 | 说明 | 4679| -------- | -------------------- | ---- | ------------------- | 4680| callback | AsyncCallback\<void\> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 4681 4682**错误码:** 4683 4684以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 4685 4686| 错误码ID | 错误信息 | 4687| --------------- | --------------- | 4688| 7400201 | Camera service fatal error. | 4689 4690**示例:** 4691 4692```ts 4693import { BusinessError } from '@kit.BasicServicesKit'; 4694 4695function stopCaptureSession(session: camera.Session): void { 4696 session.stop((err: BusinessError) => { 4697 if (err) { 4698 console.error(`Failed to stop the session, error code: ${err.code}.`); 4699 return; 4700 } 4701 console.info('Callback invoked to indicate the session stop success.'); 4702 }); 4703} 4704``` 4705 4706### stop<sup>11+</sup> 4707 4708stop(): Promise\<void\> 4709 4710停止会话工作,通过Promise获取结果。 4711 4712**系统能力:** SystemCapability.Multimedia.Camera.Core 4713 4714**返回值:** 4715 4716| 类型 | 说明 | 4717| -------------- |-------------------| 4718| Promise\<void\> | 无返回结果的Promise对象。 | 4719 4720**错误码:** 4721 4722以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 4723 4724| 错误码ID | 错误信息 | 4725| --------------- | --------------- | 4726| 7400201 | Camera service fatal error. | 4727 4728**示例:** 4729 4730```ts 4731import { BusinessError } from '@kit.BasicServicesKit'; 4732 4733function stopCaptureSession(session: camera.Session): void { 4734 session.stop().then(() => { 4735 console.info('Promise returned to indicate the session stop success.'); 4736 }).catch((error: BusinessError) => { 4737 console.error(`Failed to stop the session, error code: ${error.code}.`); 4738 }); 4739} 4740``` 4741 4742### release<sup>11+</sup> 4743 4744release(callback: AsyncCallback\<void\>): void 4745 4746释放会话资源,通过注册回调函数获取结果。使用callback异步回调。 4747 4748**系统能力:** SystemCapability.Multimedia.Camera.Core 4749 4750**参数:** 4751 4752| 参数名 | 类型 | 必填 | 说明 | 4753| -------- | -------------------- | ---- | -------------------- | 4754| callback | AsyncCallback\<void\> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 4755 4756**错误码:** 4757 4758以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 4759 4760| 错误码ID | 错误信息 | 4761| --------------- | --------------- | 4762| 7400201 | Camera service fatal error. | 4763 4764**示例:** 4765 4766```ts 4767import { BusinessError } from '@kit.BasicServicesKit'; 4768 4769function releaseCaptureSession(session: camera.Session): void { 4770 session.release((err: BusinessError) => { 4771 if (err) { 4772 console.error(`Failed to release the session instance, error code: ${err.code}.`); 4773 return; 4774 } 4775 console.info('Callback invoked to indicate that the session instance is released successfully.'); 4776 }); 4777} 4778``` 4779 4780### release<sup>11+</sup> 4781 4782release(): Promise\<void\> 4783 4784释放会话资源,通过Promise获取结果。 4785 4786**系统能力:** SystemCapability.Multimedia.Camera.Core 4787 4788**返回值:** 4789 4790| 类型 | 说明 | 4791| -------------- | ------------------------ | 4792| Promise\<void\> | 无返回结果的Promise对象。 | 4793 4794**错误码:** 4795 4796以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 4797 4798| 错误码ID | 错误信息 | 4799| --------------- | --------------- | 4800| 7400201 | Camera service fatal error. | 4801 4802**示例:** 4803 4804```ts 4805import { BusinessError } from '@kit.BasicServicesKit'; 4806 4807function releaseCaptureSession(session: camera.Session): void { 4808 session.release().then(() => { 4809 console.info('Promise returned to indicate that the session instance is released successfully.'); 4810 }).catch((error: BusinessError) => { 4811 console.error(`Failed to release the session instance, error code: ${error.code}.`); 4812 }); 4813} 4814``` 4815 4816## Flash<sup>11+</sup> 4817 4818Flash extends [FlashQuery](#flashquery12) 4819 4820闪光灯类,对设备闪光灯操作。 4821 4822### setFlashMode<sup>11+</sup> 4823 4824setFlashMode(flashMode: FlashMode): void 4825 4826设置闪光灯模式。 4827 4828进行设置之前,需要先检查: 4829 48301. 设备是否支持闪光灯,可使用方法[hasFlash](#hasflash11)。 48312. 设备是否支持指定的闪光灯模式,可使用方法[isFlashModeSupported](#isflashmodesupported11)。 4832 4833**系统能力:** SystemCapability.Multimedia.Camera.Core 4834 4835**参数:** 4836 4837| 参数名 | 类型 | 必填 | 说明 | 4838| --------- | ----------------------- | ---- | --------------------- | 4839| flashMode | [FlashMode](#flashmode) | 是 | 指定闪光灯模式。传参为null或者undefined,作为0处理,闪光灯关闭。 | 4840 4841**错误码:** 4842 4843以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 4844 4845| 错误码ID | 错误信息 | 4846| --------------- | --------------- | 4847| 7400103 | Session not config. | 4848 4849**示例:** 4850 4851```ts 4852import { BusinessError } from '@kit.BasicServicesKit'; 4853 4854function setFlashMode(photoSession: camera.PhotoSession): void { 4855 try { 4856 photoSession.setFlashMode(camera.FlashMode.FLASH_MODE_AUTO); 4857 } catch (error) { 4858 // 失败返回错误码error.code并处理 4859 let err = error as BusinessError; 4860 console.error(`The setFlashMode call failed. error code: ${err.code}`); 4861 } 4862} 4863``` 4864 4865### getFlashMode<sup>11+</sup> 4866 4867getFlashMode(): FlashMode 4868 4869获取当前设备的闪光灯模式。 4870 4871**系统能力:** SystemCapability.Multimedia.Camera.Core 4872 4873**返回值:** 4874 4875| 类型 | 说明 | 4876| ---------- | ----------------------------- | 4877| [FlashMode](#flashmode) | 获取当前设备的闪光灯模式。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 4878 4879**错误码:** 4880 4881以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 4882 4883| 错误码ID | 错误信息 | 4884| --------------- | --------------- | 4885| 7400103 | Session not config. | 4886 4887**示例:** 4888 4889```ts 4890import { BusinessError } from '@kit.BasicServicesKit'; 4891 4892function getFlashMode(photoSession: camera.PhotoSession): camera.FlashMode | undefined { 4893 let flashMode: camera.FlashMode | undefined = undefined; 4894 try { 4895 flashMode = photoSession.getFlashMode(); 4896 } catch (error) { 4897 // 失败返回错误码error.code并处理 4898 let err = error as BusinessError; 4899 console.error(`The getFlashMode call failed.error code: ${err.code}`); 4900 } 4901 return flashMode; 4902} 4903``` 4904 4905## FlashQuery<sup>12+</sup> 4906 4907提供了查询设备的闪光灯状态和模式的能力。 4908 4909### hasFlash<sup>11+</sup> 4910 4911hasFlash(): boolean 4912 4913检测是否有闪光灯,通过注册回调函数获取结果。 4914 4915**系统能力:** SystemCapability.Multimedia.Camera.Core 4916 4917**返回值:** 4918 4919| 类型 | 说明 | 4920| ---------- | ----------------------------- | 4921| boolean | 返回true表示设备支持闪光灯,false表示不支持。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 4922 4923**错误码:** 4924 4925以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 4926 4927| 错误码ID | 错误信息 | 4928| --------------- | --------------- | 4929| 7400103 | Session not config, only throw in session usage. | 4930 4931**示例:** 4932 4933```ts 4934import { BusinessError } from '@kit.BasicServicesKit'; 4935 4936function hasFlash(photoSession: camera.PhotoSession): boolean { 4937 let status: boolean = false; 4938 try { 4939 status = photoSession.hasFlash(); 4940 } catch (error) { 4941 // 失败返回错误码error.code并处理 4942 let err = error as BusinessError; 4943 console.error(`The hasFlash call failed. error code: ${err.code}`); 4944 } 4945 return status; 4946} 4947``` 4948 4949### isFlashModeSupported<sup>11+</sup> 4950 4951isFlashModeSupported(flashMode: FlashMode): boolean 4952 4953检测闪光灯模式是否支持。 4954 4955**系统能力:** SystemCapability.Multimedia.Camera.Core 4956 4957**参数:** 4958 4959| 参数名 | 类型 | 必填 | 说明 | 4960| --------- | ----------------------- | ---- | --------------------------------- | 4961| flashMode | [FlashMode](#flashmode) | 是 | 指定闪光灯模式。传参为null或者undefined,作为0处理,闪光灯关闭。 | 4962 4963**返回值:** 4964 4965| 类型 | 说明 | 4966| ---------- | ----------------------------- | 4967| boolean | 返回true表示支持该闪光灯模式,false表示不支持。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 4968 4969**错误码:** 4970 4971以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 4972 4973| 错误码ID | 错误信息 | 4974| --------------- | --------------- | 4975| 7400103 | Session not config, only throw in session usage. | 4976 4977**示例:** 4978 4979```ts 4980import { BusinessError } from '@kit.BasicServicesKit'; 4981 4982function isFlashModeSupported(photoSession: camera.PhotoSession): boolean { 4983 let status: boolean = false; 4984 try { 4985 status = photoSession.isFlashModeSupported(camera.FlashMode.FLASH_MODE_AUTO); 4986 } catch (error) { 4987 // 失败返回错误码error.code并处理 4988 let err = error as BusinessError; 4989 console.error(`The isFlashModeSupported call failed. error code: ${err.code}`); 4990 } 4991 return status; 4992} 4993``` 4994 4995## AutoExposure<sup>11+</sup> 4996 4997AutoExposure extends [AutoExposureQuery](#autoexposurequery12) 4998 4999自动曝光类,对设备自动曝光(AE)操作。 5000 5001### getExposureMode<sup>11+</sup> 5002 5003getExposureMode(): ExposureMode 5004 5005获取当前曝光模式。 5006 5007**系统能力:** SystemCapability.Multimedia.Camera.Core 5008 5009**返回值:** 5010 5011| 类型 | 说明 | 5012| ---------- | ----------------------------- | 5013| [ExposureMode](#exposuremode) | 获取当前曝光模式。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 5014 5015**错误码:** 5016 5017以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 5018 5019| 错误码ID | 错误信息 | 5020| --------------- | --------------- | 5021| 7400103 | Session not config. | 5022 5023**示例:** 5024 5025```ts 5026import { BusinessError } from '@kit.BasicServicesKit'; 5027 5028function getExposureMode(photoSession: camera.PhotoSession): camera.ExposureMode | undefined { 5029 let exposureMode: camera.ExposureMode | undefined = undefined; 5030 try { 5031 exposureMode = photoSession.getExposureMode(); 5032 } catch (error) { 5033 // 失败返回错误码error.code并处理 5034 let err = error as BusinessError; 5035 console.error(`The getExposureMode call failed. error code: ${err.code}`); 5036 } 5037 return exposureMode; 5038} 5039``` 5040 5041### setExposureMode<sup>11+</sup> 5042 5043setExposureMode(aeMode: ExposureMode): void 5044 5045设置曝光模式。进行设置之前,需要先检查设备是否支持指定的曝光模式,可使用方法[isExposureModeSupported](#isexposuremodesupported11)。 5046 5047**系统能力:** SystemCapability.Multimedia.Camera.Core 5048 5049**参数:** 5050 5051| 参数名 | 类型 | 必填 | 说明 | 5052| -------- | -------------------------------| ---- | ----------------------- | 5053| aeMode | [ExposureMode](#exposuremode) | 是 | 曝光模式。传参为null或者undefined,作为0处理,曝光锁定。 | 5054 5055**错误码:** 5056 5057以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 5058 5059| 错误码ID | 错误信息 | 5060| --------------- | --------------- | 5061| 7400103 | Session not config. | 5062 5063**示例:** 5064 5065```ts 5066import { BusinessError } from '@kit.BasicServicesKit'; 5067 5068function setExposureMode(photoSession: camera.PhotoSession): void { 5069 try { 5070 photoSession.setExposureMode(camera.ExposureMode.EXPOSURE_MODE_LOCKED); 5071 } catch (error) { 5072 // 失败返回错误码error.code并处理 5073 let err = error as BusinessError; 5074 console.error(`The setExposureMode call failed. error code: ${err.code}`); 5075 } 5076} 5077``` 5078 5079### getMeteringPoint<sup>11+</sup> 5080 5081getMeteringPoint(): Point 5082 5083查询曝光区域中心点。 5084 5085**系统能力:** SystemCapability.Multimedia.Camera.Core 5086 5087**返回值:** 5088 5089| 类型 | 说明 | 5090| ---------- | ----------------------------- | 5091| [Point](#point) | 获取当前曝光点。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 5092 5093**错误码:** 5094 5095以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 5096 5097| 错误码ID | 错误信息 | 5098| --------------- | --------------- | 5099| 7400103 | Session not config. | 5100 5101**示例:** 5102 5103```ts 5104import { BusinessError } from '@kit.BasicServicesKit'; 5105 5106function getMeteringPoint(photoSession: camera.PhotoSession): camera.Point | undefined { 5107 let exposurePoint: camera.Point | undefined = undefined; 5108 try { 5109 exposurePoint = photoSession.getMeteringPoint(); 5110 } catch (error) { 5111 // 失败返回错误码error.code并处理 5112 let err = error as BusinessError; 5113 console.error(`The getMeteringPoint call failed. error code: ${err.code}`); 5114 } 5115 return exposurePoint; 5116} 5117``` 5118 5119### setMeteringPoint<sup>11+</sup> 5120 5121setMeteringPoint(point: Point): void 5122 5123设置曝光区域中心点,曝光点应在0-1坐标系内,该坐标系左上角为{0,0},右下角为{1,1}。<br>此坐标系是以设备充电口在右侧时的横向设备方向为基准的,例如应用的预览界面布局以<br>设备充电口在下侧时的竖向方向为基准,布局宽高为{w,h},且触碰点为{x,y},<br>则转换后的坐标点为{y/h,1-x/w}。 5124 5125**系统能力:** SystemCapability.Multimedia.Camera.Core 5126 5127**参数:** 5128 5129| 参数名 | 类型 | 必填 | 说明 | 5130| ------------- | -------------------------------| ---- | ------------------- | 5131| point | [Point](#point) | 是 | 曝光点,x、y设置范围应在[0,1]之内,超过范围,如果小于0设置0,大于1设置1。 | 5132 5133**错误码:** 5134 5135以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 5136 5137| 错误码ID | 错误信息 | 5138| --------------- | --------------- | 5139| 7400103 | Session not config. | 5140 5141**示例:** 5142 5143```ts 5144import { BusinessError } from '@kit.BasicServicesKit'; 5145 5146function setMeteringPoint(photoSession: camera.PhotoSession): void { 5147 const point: camera.Point = {x: 1, y: 1}; 5148 try { 5149 photoSession.setMeteringPoint(point); 5150 } catch (error) { 5151 // 失败返回错误码error.code并处理 5152 let err = error as BusinessError; 5153 console.error(`The setMeteringPoint call failed. error code: ${err.code}`); 5154 } 5155} 5156``` 5157 5158### setExposureBias<sup>11+</sup> 5159 5160setExposureBias(exposureBias: number): void 5161 5162设置曝光补偿,曝光补偿值(EV)。 5163 5164进行设置之前,建议先通过方法[getExposureBiasRange](#getexposurebiasrange11)查询支持的范围。 5165 5166**系统能力:** SystemCapability.Multimedia.Camera.Core 5167 5168**参数:** 5169 5170| 参数名 | 类型 | 必填 | 说明 | 5171| -------- | -------------------------------| ---- |-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| 5172| exposureBias | number | 是 | 曝光补偿,[getExposureBiasRange](#getexposurebiasrange11)查询支持的范围,如果设置超过支持范围的值,自动匹配到就近临界点。<br>曝光补偿存在步长,如步长为0.5。则设置1.2时,获取到实际生效曝光补偿为1.0。<br>接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 5173 5174**错误码:** 5175 5176以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 5177 5178| 错误码ID | 错误信息 | 5179| --------------- | --------------- | 5180| 7400102 | Operation not allowed. | 5181| 7400103 | Session not config. | 5182 5183**示例:** 5184 5185```ts 5186import { BusinessError } from '@kit.BasicServicesKit'; 5187 5188function setExposureBias(photoSession: camera.PhotoSession, biasRangeArray: Array<number>): void { 5189 if (biasRangeArray && biasRangeArray.length > 0) { 5190 let exposureBias = biasRangeArray[0]; 5191 try { 5192 photoSession.setExposureBias(exposureBias); 5193 } catch (error) { 5194 // 失败返回错误码error.code并处理 5195 let err = error as BusinessError; 5196 console.error(`The setExposureBias call failed. error code: ${err.code}`); 5197 } 5198 } 5199} 5200``` 5201 5202### getExposureValue<sup>11+</sup> 5203 5204getExposureValue(): number 5205 5206查询当前曝光值。 5207 5208**系统能力:** SystemCapability.Multimedia.Camera.Core 5209 5210**返回值:** 5211 5212| 类型 | 说明 | 5213| ---------- | ----------------------------- | 5214| number | 获取曝光值。曝光补偿存在步长,如步长为0.5。则设置1.2时,获取到实际生效曝光补偿为1.0。<br>接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 5215 5216**错误码:** 5217 5218以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 5219 5220| 错误码ID | 错误信息 | 5221| --------------- | --------------- | 5222| 7400103 | Session not config. | 5223 5224**示例:** 5225 5226```ts 5227import { BusinessError } from '@kit.BasicServicesKit'; 5228 5229function getExposureValue(photoSession: camera.PhotoSession): number { 5230 const invalidValue: number = -1; 5231 let exposureValue: number = invalidValue; 5232 try { 5233 exposureValue = photoSession.getExposureValue(); 5234 } catch (error) { 5235 // 失败返回错误码error.code并处理 5236 let err = error as BusinessError; 5237 console.error(`The getExposureValue call failed. error code: ${err.code}`); 5238 } 5239 return exposureValue; 5240} 5241``` 5242 5243## AutoExposureQuery<sup>12+</sup> 5244 5245提供了针对设备的自动曝光特性提供了一系列查询功能。 5246 5247### isExposureModeSupported<sup>11+</sup> 5248 5249isExposureModeSupported(aeMode: ExposureMode): boolean 5250 5251检测曝光模式是否支持。 5252 5253**系统能力:** SystemCapability.Multimedia.Camera.Core 5254 5255**参数:** 5256 5257| 参数名 | 类型 | 必填 | 说明 | 5258| -------- | -------------------------------| ---- | ----------------------------- | 5259| aeMode | [ExposureMode](#exposuremode) | 是 | 曝光模式。传参为null或者undefined,作为0处理,曝光锁定。 | 5260 5261**返回值:** 5262 5263| 类型 | 说明 | 5264| ---------- | ----------------------------- | 5265| boolean | 获取是否支持曝光模式。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 5266 5267**错误码:** 5268 5269以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 5270 5271| 错误码ID | 错误信息 | 5272| --------------- | --------------- | 5273| 7400103 | Session not config, only throw in session usage. | 5274 5275**示例:** 5276 5277```ts 5278import { BusinessError } from '@kit.BasicServicesKit'; 5279 5280function isExposureModeSupported(photoSession: camera.PhotoSession): boolean { 5281 let isSupported: boolean = false; 5282 try { 5283 isSupported = photoSession.isExposureModeSupported(camera.ExposureMode.EXPOSURE_MODE_LOCKED); 5284 } catch (error) { 5285 // 失败返回错误码error.code并处理 5286 let err = error as BusinessError; 5287 console.error(`The isExposureModeSupported call failed. error code: ${err.code}`); 5288 } 5289 return isSupported; 5290} 5291``` 5292 5293### getExposureBiasRange<sup>11+</sup> 5294 5295getExposureBiasRange(): Array\<number\> 5296 5297查询曝光补偿范围。 5298 5299**系统能力:** SystemCapability.Multimedia.Camera.Core 5300 5301**返回值:** 5302 5303| 类型 | 说明 | 5304| ---------- | ----------------------------- | 5305| Array\<number\> | 获取补偿范围的数组。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 5306 5307**错误码:** 5308 5309以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 5310 5311| 错误码ID | 错误信息 | 5312| --------------- | --------------- | 5313| 7400103 | Session not config, only throw in session usage. | 5314 5315**示例:** 5316 5317```ts 5318import { BusinessError } from '@kit.BasicServicesKit'; 5319 5320function getExposureBiasRange(photoSession: camera.PhotoSession): Array<number> { 5321 let biasRangeArray: Array<number> = []; 5322 try { 5323 biasRangeArray = photoSession.getExposureBiasRange(); 5324 } catch (error) { 5325 // 失败返回错误码error.code并处理 5326 let err = error as BusinessError; 5327 console.error(`The getExposureBiasRange call failed. error code: ${err.code}`); 5328 } 5329 return biasRangeArray; 5330} 5331``` 5332 5333## Focus<sup>11+</sup> 5334 5335Focus extends [FocusQuery](#focusquery12) 5336 5337对焦类,对设备对焦操作。 5338 5339### setFocusMode<sup>11+</sup> 5340 5341setFocusMode(afMode: FocusMode): void 5342 5343设置对焦模式。 5344 5345进行设置之前,需要先检查设备是否支持指定的焦距模式,可使用方法[isFocusModeSupported](#isfocusmodesupported11)。 5346 5347**系统能力:** SystemCapability.Multimedia.Camera.Core 5348 5349**参数:** 5350 5351| 参数名 | 类型 | 必填 | 说明 | 5352| -------- | ----------------------- | ---- | ------------------- | 5353| afMode | [FocusMode](#focusmode) | 是 | 指定的焦距模式。传参为null或者undefined,作为0处理,手动对焦模式。 | 5354 5355**错误码:** 5356 5357以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 5358 5359| 错误码ID | 错误信息 | 5360| --------------- | --------------- | 5361| 7400103 | Session not config. | 5362 5363**示例:** 5364 5365```ts 5366import { BusinessError } from '@kit.BasicServicesKit'; 5367 5368function setFocusMode(photoSession: camera.PhotoSession): void { 5369 try { 5370 photoSession.setFocusMode(camera.FocusMode.FOCUS_MODE_AUTO); 5371 } catch (error) { 5372 // 失败返回错误码error.code并处理 5373 let err = error as BusinessError; 5374 console.error(`The setFocusMode call failed. error code: ${err.code}`); 5375 } 5376} 5377``` 5378 5379### getFocusMode<sup>11+</sup> 5380 5381getFocusMode(): FocusMode 5382 5383获取当前的对焦模式。 5384 5385**系统能力:** SystemCapability.Multimedia.Camera.Core 5386 5387**返回值:** 5388 5389| 类型 | 说明 | 5390| ---------- | ----------------------------- | 5391| [FocusMode](#focusmode) | 获取当前设备的焦距模式。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 5392 5393**错误码:** 5394 5395以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 5396 5397| 错误码ID | 错误信息 | 5398| --------------- | --------------- | 5399| 7400103 | Session not config. | 5400 5401**示例:** 5402 5403```ts 5404import { BusinessError } from '@kit.BasicServicesKit'; 5405 5406function getFocusMode(photoSession: camera.PhotoSession): camera.FocusMode | undefined { 5407 let afMode: camera.FocusMode | undefined = undefined; 5408 try { 5409 afMode = photoSession.getFocusMode(); 5410 } catch (error) { 5411 // 失败返回错误码error.code并处理 5412 let err = error as BusinessError; 5413 console.error(`The getFocusMode call failed. error code: ${err.code}`); 5414 } 5415 return afMode; 5416} 5417``` 5418 5419### setFocusPoint<sup>11+</sup> 5420 5421setFocusPoint(point: Point): void 5422 5423设置焦点,焦点应在0-1坐标系内,该坐标系左上角为{0,0},右下角为{1,1}。<br>此坐标系是以设备充电口在右侧时的横向设备方向为基准的,例如应用的预览界面布局以<br>设备充电口在下侧时的竖向方向为基准,布局宽高为{w,h},且触碰点为{x,y},<br>则转换后的坐标点为{y/h,1-x/w}。 5424 5425**系统能力:** SystemCapability.Multimedia.Camera.Core 5426 5427**参数:** 5428 5429| 参数名 | 类型 | 必填 | 说明 | 5430| -------- | ----------------------- | ---- | ------------------- | 5431| point | [Point](#point) | 是 | 焦点。x、y设置范围应在[0,1]之内,超过范围,如果小于0设置0,大于1设置1。 | 5432 5433**错误码:** 5434 5435以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 5436 5437| 错误码ID | 错误信息 | 5438| --------------- | --------------- | 5439| 7400103 | Session not config. | 5440 5441**示例:** 5442 5443```ts 5444import { BusinessError } from '@kit.BasicServicesKit'; 5445 5446function setFocusPoint(photoSession: camera.PhotoSession): void { 5447 const focusPoint: camera.Point = {x: 1, y: 1}; 5448 try { 5449 photoSession.setFocusPoint(focusPoint); 5450 } catch (error) { 5451 // 失败返回错误码error.code并处理 5452 let err = error as BusinessError; 5453 console.error(`The setFocusPoint call failed. error code: ${err.code}`); 5454 } 5455} 5456``` 5457 5458### getFocusPoint<sup>11+</sup> 5459 5460getFocusPoint(): Point 5461 5462查询焦点。 5463 5464**系统能力:** SystemCapability.Multimedia.Camera.Core 5465 5466**返回值:** 5467 5468| 类型 | 说明 | 5469| ---------- | ----------------------------- | 5470| [Point](#point) | 用于获取当前焦点。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 5471 5472**错误码:** 5473 5474以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 5475 5476| 错误码ID | 错误信息 | 5477| --------------- | --------------- | 5478| 7400103 | Session not config. | 5479 5480**示例:** 5481 5482```ts 5483import { BusinessError } from '@kit.BasicServicesKit'; 5484 5485function getFocusPoint(photoSession: camera.PhotoSession): camera.Point | undefined { 5486 let point: camera.Point | undefined = undefined; 5487 try { 5488 point = photoSession.getFocusPoint(); 5489 } catch (error) { 5490 // 失败返回错误码error.code并处理 5491 let err = error as BusinessError; 5492 console.error(`The getFocusPoint call failed. error code: ${err.code}`); 5493 } 5494 return point; 5495} 5496``` 5497 5498### getFocalLength<sup>11+</sup> 5499 5500getFocalLength(): number 5501 5502查询焦距值。 5503 5504**系统能力:** SystemCapability.Multimedia.Camera.Core 5505 5506**返回值:** 5507 5508| 类型 | 说明 | 5509| ---------- | ----------------------------- | 5510| number | 用于获取当前焦距,单位mm。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 5511 5512**错误码:** 5513 5514以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 5515 5516| 错误码ID | 错误信息 | 5517| --------------- | --------------- | 5518| 7400103 | Session not config. | 5519 5520**示例:** 5521 5522```ts 5523import { BusinessError } from '@kit.BasicServicesKit'; 5524 5525function getFocalLength(photoSession: camera.PhotoSession): number { 5526 const invalidValue: number = -1; 5527 let focalLength: number = invalidValue; 5528 try { 5529 focalLength = photoSession.getFocalLength(); 5530 } catch (error) { 5531 // 失败返回错误码error.code并处理 5532 let err = error as BusinessError; 5533 console.error(`The getFocalLength call failed. error code: ${err.code}`); 5534 } 5535 return focalLength; 5536} 5537``` 5538 5539## FocusQuery<sup>12+</sup> 5540 5541提供了查询是否支持当前对焦模式的方法。 5542 5543### isFocusModeSupported<sup>11+</sup> 5544 5545isFocusModeSupported(afMode: FocusMode): boolean 5546 5547检测对焦模式是否支持。 5548 5549**系统能力:** SystemCapability.Multimedia.Camera.Core 5550 5551**参数:** 5552 5553| 参数名 | 类型 | 必填 | 说明 | 5554| -------- | ----------------------- | ---- | -------------------------------- | 5555| afMode | [FocusMode](#focusmode) | 是 | 指定的焦距模式。传参为null或者undefined,作为0处理,手动对焦模式。 | 5556 5557**返回值:** 5558 5559| 类型 | 说明 | 5560| ---------- | ----------------------------- | 5561| boolean | 返回true表示支持该焦距模式,false表示不支持。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 5562 5563**错误码:** 5564 5565以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 5566 5567| 错误码ID | 错误信息 | 5568| --------------- | --------------- | 5569| 7400103 | Session not config, only throw in session usage. | 5570 5571**示例:** 5572 5573```ts 5574import { BusinessError } from '@kit.BasicServicesKit'; 5575 5576function isFocusModeSupported(photoSession: camera.PhotoSession): boolean { 5577 let status: boolean = false; 5578 try { 5579 status = photoSession.isFocusModeSupported(camera.FocusMode.FOCUS_MODE_AUTO); 5580 } catch (error) { 5581 // 失败返回错误码error.code并处理 5582 let err = error as BusinessError; 5583 console.error(`The isFocusModeSupported call failed. error code: ${err.code}`); 5584 } 5585 return status; 5586} 5587``` 5588 5589## SmoothZoomMode<sup>11+</sup> 5590 5591平滑变焦模式。 5592 5593**系统能力:** SystemCapability.Multimedia.Camera.Core 5594 5595| 名称 | 值 | 说明 | 5596| ------------ | ---- | -------------- | 5597| NORMAL | 0 | 贝塞尔曲线模式。 | 5598 5599## SmoothZoomInfo<sup>11+</sup> 5600 5601平滑变焦参数信息。 5602 5603**系统能力:** SystemCapability.Multimedia.Camera.Core 5604 5605| 名称 | 类型 | 只读 | 可选 | 说明 | 5606| -------- | ---------- | -------- | -------- | ---------- | 5607| duration | number | 否 | 否 | 平滑变焦总时长,单位ms。 | 5608 5609## Zoom<sup>11+</sup> 5610 5611Zoom extends [ZoomQuery](#zoomquery12) 5612 5613变焦类,对设备变焦操作。 5614 5615### setZoomRatio<sup>11+</sup> 5616 5617setZoomRatio(zoomRatio: number): void 5618 5619设置变焦比,变焦精度最高为小数点后两位,如果设置超过支持的精度范围,则只保留精度范围内数值。 5620 5621**系统能力:** SystemCapability.Multimedia.Camera.Core 5622 5623**参数:** 5624 5625| 参数名 | 类型 | 必填 | 说明 | 5626| --------- | -------------------- | ---- |---------------------------------------------------------------------------------------------------------------------------------| 5627| zoomRatio | number | 是 | 可变焦距比,通过[getZoomRatioRange](#getzoomratiorange11)获取支持的变焦范围,如果设置超过支持范围的值,则只保留精度范围内数值。<br>设置可变焦距比到底层生效需要一定时间,获取正确设置的可变焦距比需要等待1~2帧的时间。 | 5628 5629**错误码:** 5630 5631以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 5632 5633| 错误码ID | 错误信息 | 5634| --------------- | --------------- | 5635| 7400103 | Session not config. | 5636 5637**示例:** 5638 5639```ts 5640import { BusinessError } from '@kit.BasicServicesKit'; 5641 5642function setZoomRatio(photoSession: camera.PhotoSession, zoomRatioRange: Array<number>): void { 5643 if (zoomRatioRange === undefined || zoomRatioRange.length <= 0) { 5644 return; 5645 } 5646 let zoomRatio = zoomRatioRange[0]; 5647 try { 5648 photoSession.setZoomRatio(zoomRatio); 5649 } catch (error) { 5650 // 失败返回错误码error.code并处理 5651 let err = error as BusinessError; 5652 console.error(`The setZoomRatio call failed. error code: ${err.code}`); 5653 } 5654} 5655``` 5656 5657### getZoomRatio<sup>11+</sup> 5658 5659getZoomRatio(): number 5660 5661获取当前的变焦比。 5662 5663**系统能力:** SystemCapability.Multimedia.Camera.Core 5664 5665**返回值:** 5666 5667| 类型 | 说明 | 5668| ---------- | ----------------------------- | 5669| number | 获取当前的变焦比结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 5670 5671**错误码:** 5672 5673以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 5674 5675| 错误码ID | 错误信息 | 5676| --------------- | --------------- | 5677| 7400103 | Session not config. | 5678| 7400201 | Camera service fatal error. | 5679 5680**示例:** 5681 5682```ts 5683import { BusinessError } from '@kit.BasicServicesKit'; 5684 5685function getZoomRatio(photoSession: camera.PhotoSession): number { 5686 const invalidValue: number = -1; 5687 let zoomRatio: number = invalidValue; 5688 try { 5689 zoomRatio = photoSession.getZoomRatio(); 5690 } catch (error) { 5691 // 失败返回错误码error.code并处理 5692 let err = error as BusinessError; 5693 console.error(`The getZoomRatio call failed. error code: ${err.code}`); 5694 } 5695 return zoomRatio; 5696} 5697``` 5698 5699### setSmoothZoom<sup>11+</sup> 5700 5701setSmoothZoom(targetRatio: number, mode?: SmoothZoomMode): void 5702 5703触发平滑变焦。 5704 5705**系统能力:** SystemCapability.Multimedia.Camera.Core 5706 5707**参数:** 5708 5709| 参数名 | 类型 | 必填 | 说明 | 5710| ------------ | -------------- | ---- | ----------------- | 5711| targetRatio | number | 是 | 目标值。 | 5712| mode | [SmoothZoomMode](#smoothzoommode11) | 否 | 模式。 | 5713 5714**错误码:** 5715 5716以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 5717 5718| 错误码ID | 错误信息 | 5719| --------------- | --------------- | 5720| 7400103 | Session not config. | 5721 5722**示例:** 5723 5724```ts 5725import { BusinessError } from '@kit.BasicServicesKit'; 5726 5727function setSmoothZoom(sessionExtendsZoom: camera.Zoom, targetZoomRatio: number, mode: camera.SmoothZoomMode): void { 5728 try { 5729 sessionExtendsZoom.setSmoothZoom(targetZoomRatio, mode); 5730 } catch (error) { 5731 // 失败返回错误码error.code并处理 5732 let err = error as BusinessError; 5733 console.error(`The setSmoothZoom call failed. error code: ${err.code}`); 5734 } 5735} 5736``` 5737 5738## ZoomQuery<sup>12+</sup> 5739 5740提供了与设备的缩放相关的查询功能,包括获取支持的缩放比例范围。 5741 5742### getZoomRatioRange<sup>11+</sup> 5743 5744getZoomRatioRange(): Array\<number\> 5745 5746获取支持的变焦范围。 5747 5748**系统能力:** SystemCapability.Multimedia.Camera.Core 5749 5750**返回值:** 5751 5752| 类型 | 说明 | 5753| ---------- | ----------------------------- | 5754| Array\<number\> | 用于获取可变焦距比范围,返回的数组包括其最小值和最大值。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 5755 5756**错误码:** 5757 5758以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 5759 5760| 错误码ID | 错误信息 | 5761| --------------- | --------------- | 5762| 7400103 | Session not config, only throw in session usage. | 5763 5764**示例:** 5765 5766```ts 5767import { BusinessError } from '@kit.BasicServicesKit'; 5768 5769function getZoomRatioRange(photoSession: camera.PhotoSession): Array<number> { 5770 let zoomRatioRange: Array<number> = []; 5771 try { 5772 zoomRatioRange = photoSession.getZoomRatioRange(); 5773 } catch (error) { 5774 // 失败返回错误码error.code并处理 5775 let err = error as BusinessError; 5776 console.error(`The getZoomRatioRange call failed. error code: ${err.code}`); 5777 } 5778 return zoomRatioRange; 5779} 5780``` 5781 5782## Stabilization<sup>11+</sup> 5783 5784Stabilization extends [StabilizationQuery](#stabilizationquery12) 5785 5786提供设备在录像模式下设置视频防抖的操作。 5787 5788 > **说明:** 5789 > 5790 > 需要会话中有录像流([VideoOutput](#videooutput))的前提下,才可以对视频进行防抖设置, 5791 > 其中[VideoStabilizationMode](#videostabilizationmode)中的枚举HIGH需要在[Profile](#profile)的分辨率为1920*1080的场景下生效。 5792 5793### getActiveVideoStabilizationMode<sup>11+</sup> 5794 5795getActiveVideoStabilizationMode(): VideoStabilizationMode 5796 5797查询当前正在使用的视频防抖模式。 5798 5799**系统能力:** SystemCapability.Multimedia.Camera.Core 5800 5801**返回值:** 5802 5803| 类型 | 说明 | 5804| ---------- |-------------| 5805| [VideoStabilizationMode](#videostabilizationmode) | 视频防抖是否正在使用。 | 5806 5807**错误码:** 5808 5809以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 5810 5811| 错误码ID | 错误信息 | 5812| --------------- | --------------- | 5813| 7400103 | Session not config. | 5814 5815**示例:** 5816 5817```ts 5818import { BusinessError } from '@kit.BasicServicesKit'; 5819 5820function getActiveVideoStabilizationMode(videoSession: camera.VideoSession): camera.VideoStabilizationMode | undefined { 5821 let vsMode: camera.VideoStabilizationMode | undefined = undefined; 5822 try { 5823 vsMode = videoSession.getActiveVideoStabilizationMode(); 5824 } catch (error) { 5825 // 失败返回错误码error.code并处理 5826 let err = error as BusinessError; 5827 console.error(`The getActiveVideoStabilizationMode call failed. error code: ${err.code}`); 5828 } 5829 return vsMode; 5830} 5831``` 5832 5833### setVideoStabilizationMode<sup>11+</sup> 5834 5835setVideoStabilizationMode(mode: VideoStabilizationMode): void 5836 5837设置视频防抖模式。需要先检查设备是否支持对应的防抖模式,可以通过[isVideoStabilizationModeSupported](#isvideostabilizationmodesupported11)方法判断所设置的模式是否支持。 5838 5839**系统能力:** SystemCapability.Multimedia.Camera.Core 5840 5841**参数:** 5842 5843| 参数名 | 类型 | 必填 | 说明 | 5844| -------- | ------------------------------------------------- | ---- | --------------------- | 5845| mode | [VideoStabilizationMode](#videostabilizationmode) | 是 | 需要设置的视频防抖模式。 | 5846 5847**错误码:** 5848 5849以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 5850 5851| 错误码ID | 错误信息 | 5852| --------------- | --------------- | 5853| 7400103 | Session not config. | 5854 5855**示例:** 5856 5857```ts 5858import { BusinessError } from '@kit.BasicServicesKit'; 5859 5860function setVideoStabilizationMode(videoSession: camera.VideoSession): void { 5861 try { 5862 videoSession.setVideoStabilizationMode(camera.VideoStabilizationMode.OFF); 5863 } catch (error) { 5864 // 失败返回错误码error.code并处理 5865 let err = error as BusinessError; 5866 console.error(`The setVideoStabilizationMode call failed. error code: ${err.code}`); 5867 } 5868} 5869``` 5870 5871## StabilizationQuery<sup>12+</sup> 5872 5873提供了查询设备在录像模式下是否支持对应的视频防抖模式的能力。 5874 5875### isVideoStabilizationModeSupported<sup>11+</sup> 5876 5877isVideoStabilizationModeSupported(vsMode: VideoStabilizationMode): boolean 5878 5879查询是否支持指定的视频防抖模式。 5880 5881**系统能力:** SystemCapability.Multimedia.Camera.Core 5882 5883**参数:** 5884 5885| 参数名 | 类型 | 必填 | 说明 | 5886| -------- | ------------------------------------------------- | ---- | ------------------------------ | 5887| vsMode | [VideoStabilizationMode](#videostabilizationmode) | 是 | 视频防抖模式。 | 5888 5889**返回值:** 5890 5891| 类型 | 说明 | 5892| ---------- | ----------------------------- | 5893| boolean | 返回视频防抖模式是否支持,true表示支持,false表示不支持。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 5894 5895**错误码:** 5896 5897以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 5898 5899| 错误码ID | 错误信息 | 5900| --------------- | --------------- | 5901| 7400103 | Session not config, only throw in session usage. | 5902 5903**示例:** 5904 5905```ts 5906import { BusinessError } from '@kit.BasicServicesKit'; 5907 5908function isVideoStabilizationModeSupported(videoSession: camera.VideoSession): boolean { 5909 let isSupported: boolean = false; 5910 try { 5911 isSupported = videoSession.isVideoStabilizationModeSupported(camera.VideoStabilizationMode.OFF); 5912 } catch (error) { 5913 // 失败返回错误码error.code并处理 5914 let err = error as BusinessError; 5915 console.error(`The isVideoStabilizationModeSupported call failed. error code: ${err.code}`); 5916 } 5917 return isSupported; 5918} 5919``` 5920 5921## CaptureSession<sup>(deprecated)</sup> 5922 5923拍照会话类,保存一次相机运行所需要的所有资源[CameraInput](#camerainput)、[CameraOutput](#cameraoutput),并向相机设备申请完成相机功能(录像,拍照)。 5924 5925> **说明:** 5926>从 API version 10开始支持,从API version 11开始废弃。建议使用[PhotoSession](#photosession11)、[VideoSession](#videosession11)替代。 5927 5928### beginConfig<sup>(deprecated)</sup> 5929 5930beginConfig(): void 5931 5932开始配置会话。 5933 5934> **说明:** 5935>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.beginConfig](#beginconfig11)替代。 5936 5937**系统能力:** SystemCapability.Multimedia.Camera.Core 5938 5939**错误码:** 5940 5941以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 5942 5943| 错误码ID | 错误信息 | 5944| --------------- | --------------- | 5945| 7400105 | Session config locked. | 5946 5947**示例:** 5948 5949```ts 5950import { BusinessError } from '@kit.BasicServicesKit'; 5951 5952function beginConfig(captureSession: camera.CaptureSession): void { 5953 try { 5954 captureSession.beginConfig(); 5955 } catch (error) { 5956 // 失败返回错误码error.code并处理 5957 let err = error as BusinessError; 5958 console.error(`The beginConfig call failed. error code: ${err.code}`); 5959 } 5960} 5961``` 5962 5963### commitConfig<sup>(deprecated)</sup> 5964 5965commitConfig(callback: AsyncCallback\<void\>): void 5966 5967提交配置信息,通过注册回调函数获取结果。使用callback异步回调。 5968 5969> **说明:** 5970>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.commitConfig](#commitconfig11)替代。 5971 5972**系统能力:** SystemCapability.Multimedia.Camera.Core 5973 5974**参数:** 5975 5976| 参数名 | 类型 | 必填 | 说明 | 5977| -------- | -------------------- | ---- | -------------------- | 5978| callback | AsyncCallback\<void\> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) | 5979 5980**错误码:** 5981 5982以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 5983 5984| 错误码ID | 错误信息 | 5985| --------------- | --------------- | 5986| 7400102 | Operation not allowed. | 5987| 7400201 | Camera service fatal error. | 5988 5989**示例:** 5990 5991```ts 5992import { BusinessError } from '@kit.BasicServicesKit'; 5993 5994function commitConfig(captureSession: camera.CaptureSession): void { 5995 captureSession.commitConfig((err: BusinessError) => { 5996 if (err) { 5997 console.error(`The commitConfig call failed. error code: ${err.code}`); 5998 return; 5999 } 6000 console.info('Callback invoked to indicate the commit config success.'); 6001 }); 6002} 6003``` 6004 6005### commitConfig<sup>(deprecated)</sup> 6006 6007commitConfig(): Promise\<void\> 6008 6009提交配置信息,通过Promise获取结果。 6010 6011> **说明:** 6012>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.commitConfig](#commitconfig11-1)替代。 6013 6014**系统能力:** SystemCapability.Multimedia.Camera.Core 6015 6016**返回值:** 6017 6018| 类型 | 说明 | 6019| -------------- |-------------------| 6020| Promise\<void\> | 无返回结果的Promise对象。 | 6021 6022**错误码:** 6023 6024以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 6025 6026| 错误码ID | 错误信息 | 6027| --------------- | --------------- | 6028| 7400102 | Operation not allowed. | 6029| 7400201 | Camera service fatal error. | 6030 6031**示例:** 6032 6033```ts 6034import { BusinessError } from '@kit.BasicServicesKit'; 6035 6036function commitConfig(captureSession: camera.CaptureSession): void { 6037 captureSession.commitConfig().then(() => { 6038 console.info('Promise returned to indicate the commit config success.'); 6039 }).catch((error: BusinessError) => { 6040 // 失败返回错误码error.code并处理 6041 console.error(`The commitConfig call failed. error code: ${error.code}`); 6042 }); 6043} 6044``` 6045 6046### addInput<sup>(deprecated)</sup> 6047 6048addInput(cameraInput: CameraInput): void 6049 6050把[CameraInput](#camerainput)加入到会话。 6051 6052> **说明:** 6053>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.addInput](#addinput11)替代。 6054 6055**系统能力:** SystemCapability.Multimedia.Camera.Core 6056 6057**参数:** 6058 6059| 参数名 | 类型 | 必填 | 说明 | 6060| ----------- | --------------------------- | ---- | ------------------------ | 6061| cameraInput | [CameraInput](#camerainput) | 是 | 需要添加的CameraInput实例。 | 6062 6063**错误码:** 6064 6065以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 6066 6067| 错误码ID | 错误信息 | 6068|---------|-----------------------------------------------| 6069| 7400101 | Parameter missing or parameter type incorrect. | 6070| 7400102 | Operation not allowed. | 6071 6072**示例:** 6073 6074```ts 6075import { BusinessError } from '@kit.BasicServicesKit'; 6076 6077function addInput(captureSession: camera.CaptureSession, cameraInput: camera.CameraInput): void { 6078 try { 6079 captureSession.addInput(cameraInput); 6080 } catch (error) { 6081 // 失败返回错误码error.code并处理 6082 let err = error as BusinessError; 6083 console.error(`The addInput call failed. error code: ${err.code}`); 6084 } 6085} 6086``` 6087 6088### removeInput<sup>(deprecated)</sup> 6089 6090removeInput(cameraInput: CameraInput): void 6091 6092移除[CameraInput](#camerainput)。 6093 6094> **说明:** 6095>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.removeInput](#removeinput11)替代。 6096 6097**系统能力:** SystemCapability.Multimedia.Camera.Core 6098 6099**参数:** 6100 6101| 参数名 | 类型 | 必填 | 说明 | 6102| ----------- | --------------------------- | ---- | ------------------------ | 6103| cameraInput | [CameraInput](#camerainput) | 是 | 需要移除的CameraInput实例。 | 6104 6105**错误码:** 6106 6107以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 6108 6109| 错误码ID | 错误信息 | 6110| --------------- | --------------- | 6111| 7400101 | Parameter missing or parameter type incorrect. | 6112| 7400102 | Operation not allowed. | 6113 6114**示例:** 6115 6116```ts 6117import { BusinessError } from '@kit.BasicServicesKit'; 6118 6119function removeInput(captureSession: camera.CaptureSession, cameraInput: camera.CameraInput): void { 6120 try { 6121 captureSession.removeInput(cameraInput); 6122 } catch (error) { 6123 // 失败返回错误码error.code并处理 6124 let err = error as BusinessError; 6125 console.error(`The removeInput call failed. error code: ${err.code}`); 6126 } 6127} 6128``` 6129 6130### addOutput<sup>(deprecated)</sup> 6131 6132addOutput(cameraOutput: CameraOutput): void 6133 6134把[CameraOutput](#cameraoutput)加入到会话。 6135 6136> **说明:** 6137>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.addOutput](#addoutput11)替代。 6138 6139**系统能力:** SystemCapability.Multimedia.Camera.Core 6140 6141**参数:** 6142 6143| 参数名 | 类型 | 必填 | 说明 | 6144| ------------- | ------------------------------- | ---- | ------------------------ | 6145| cameraOutput | [CameraOutput](#cameraoutput) | 是 | 需要添加的CameraOutput实例。 | 6146 6147**错误码:** 6148 6149以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 6150 6151| 错误码ID | 错误信息 | 6152| --------------- | --------------- | 6153| 7400101 | Parameter missing or parameter type incorrect. | 6154| 7400102 | Operation not allowed. | 6155 6156**示例:** 6157 6158```ts 6159import { BusinessError } from '@kit.BasicServicesKit'; 6160 6161function addOutput(captureSession: camera.CaptureSession, cameraOutput: camera.CameraOutput): void { 6162 try { 6163 captureSession.addOutput(cameraOutput); 6164 } catch (error) { 6165 // 失败返回错误码error.code并处理 6166 let err = error as BusinessError; 6167 console.error(`The addOutput call failed. error code: ${err.code}`); 6168 } 6169} 6170``` 6171 6172### removeOutput<sup>(deprecated)</sup> 6173 6174removeOutput(cameraOutput: CameraOutput): void 6175 6176从会话中移除[CameraOutput](#cameraoutput)。 6177 6178> **说明:** 6179>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.removeOutput](#removeoutput11)替代。 6180 6181**系统能力:** SystemCapability.Multimedia.Camera.Core 6182 6183**参数:** 6184 6185| 参数名 | 类型 | 必填 | 说明 | 6186| ------------- | ------------------------------- | ---- | ------------------------ | 6187| cameraOutput | [CameraOutput](#cameraoutput) | 是 | 需要移除的CameraOutput实例。 | 6188 6189**错误码:** 6190 6191以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 6192 6193| 错误码ID | 错误信息 | 6194| --------------- | --------------- | 6195| 7400101 | Parameter missing or parameter type incorrect. | 6196| 7400102 | Operation not allowed. | 6197 6198**示例:** 6199 6200```ts 6201import { BusinessError } from '@kit.BasicServicesKit'; 6202 6203function removeOutput(captureSession: camera.CaptureSession, previewOutput: camera.PreviewOutput): void { 6204 try { 6205 captureSession.removeOutput(previewOutput); 6206 } catch (error) { 6207 // 失败返回错误码error.code并处理 6208 let err = error as BusinessError; 6209 console.error(`The removeOutput call failed. error code: ${err.code}`); 6210 } 6211} 6212``` 6213 6214### start<sup>(deprecated)</sup> 6215 6216start(callback: AsyncCallback\<void\>): void 6217 6218开始会话工作,通过注册回调函数获取结果。使用callback异步回调。 6219 6220> **说明:** 6221>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.start](#start11)替代。 6222 6223**系统能力:** SystemCapability.Multimedia.Camera.Core 6224 6225**参数:** 6226 6227| 参数名 | 类型 | 必填 | 说明 | 6228| -------- | -------------------- | ---- | -------------------- | 6229| callback | AsyncCallback\<void\> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 6230 6231**错误码:** 6232 6233以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 6234 6235| 错误码ID | 错误信息 | 6236| --------------- | --------------- | 6237| 7400103 | Session not config. | 6238| 7400201 | Camera service fatal error. | 6239 6240**示例:** 6241 6242```ts 6243import { BusinessError } from '@kit.BasicServicesKit'; 6244 6245function startCaptureSession(captureSession: camera.CaptureSession): void { 6246 captureSession.start((err: BusinessError) => { 6247 if (err) { 6248 console.error(`Failed to start the session, error code: ${err.code}.`); 6249 return; 6250 } 6251 console.info('Callback invoked to indicate the session start success.'); 6252 }); 6253} 6254``` 6255 6256### start<sup>(deprecated)</sup> 6257 6258start(): Promise\<void\> 6259 6260开始会话工作,通过Promise获取结果。 6261 6262> **说明:** 6263>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.start](#start11-1)替代。 6264 6265**系统能力:** SystemCapability.Multimedia.Camera.Core 6266 6267**返回值:** 6268 6269| 类型 | 说明 | 6270| -------------- | ------------------------ | 6271| Promise\<void\> | 无返回结果的Promise对象。 | 6272 6273**错误码:** 6274 6275以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 6276 6277| 错误码ID | 错误信息 | 6278| --------------- | --------------- | 6279| 7400103 | Session not config. | 6280| 7400201 | Camera service fatal error. | 6281 6282**示例:** 6283 6284```ts 6285import { BusinessError } from '@kit.BasicServicesKit'; 6286 6287function startCaptureSession(captureSession: camera.CaptureSession): void { 6288 captureSession.start().then(() => { 6289 console.info('Promise returned to indicate the session start success.'); 6290 }).catch((err: BusinessError) => { 6291 console.error(`Failed to start the session, error code: ${err.code}.`); 6292 }); 6293} 6294``` 6295 6296### stop<sup>(deprecated)</sup> 6297 6298stop(callback: AsyncCallback\<void\>): void 6299 6300停止会话工作,通过注册回调函数获取结果。使用callback异步回调。 6301 6302> **说明:** 6303>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.stop](#stop11)替代。 6304 6305**系统能力:** SystemCapability.Multimedia.Camera.Core 6306 6307**参数:** 6308 6309| 参数名 | 类型 | 必填 | 说明 | 6310| -------- | -------------------- | ---- | ------------------- | 6311| callback | AsyncCallback\<void\> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 6312 6313**错误码:** 6314 6315以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 6316 6317| 错误码ID | 错误信息 | 6318| --------------- | --------------- | 6319| 7400201 | Camera service fatal error. | 6320 6321**示例:** 6322 6323```ts 6324import { BusinessError } from '@kit.BasicServicesKit'; 6325 6326function stopCaptureSession(captureSession: camera.CaptureSession): void { 6327 captureSession.stop((err: BusinessError) => { 6328 if (err) { 6329 console.error(`Failed to stop the session, error code: ${err.code}.`); 6330 return; 6331 } 6332 console.info('Callback invoked to indicate the session stop success.'); 6333 }); 6334} 6335``` 6336 6337### stop<sup>(deprecated)</sup> 6338 6339stop(): Promise\<void\> 6340 6341停止会话工作,通过Promise获取结果。 6342 6343> **说明:** 6344>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.stop](#stop11-1)替代。 6345 6346**系统能力:** SystemCapability.Multimedia.Camera.Core 6347 6348**返回值:** 6349 6350| 类型 | 说明 | 6351| -------------- | ----------------------- | 6352| Promise\<void\> | 无返回结果的Promise对象。。 | 6353 6354**错误码:** 6355 6356以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 6357 6358| 错误码ID | 错误信息 | 6359| --------------- | --------------- | 6360| 7400201 | Camera service fatal error. | 6361 6362**示例:** 6363 6364```ts 6365import { BusinessError } from '@kit.BasicServicesKit'; 6366 6367function stopCaptureSession(captureSession: camera.CaptureSession): void { 6368 captureSession.stop().then(() => { 6369 console.info('Promise returned to indicate the session stop success.'); 6370 }).catch((err: BusinessError) => { 6371 console.error(`Failed to stop the session, error code: ${err.code}.`); 6372 }); 6373} 6374``` 6375 6376### release<sup>(deprecated)</sup> 6377 6378release(callback: AsyncCallback\<void\>): void 6379 6380释放会话资源,通过注册回调函数获取结果。使用callback异步回调。 6381 6382> **说明:** 6383>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.release](#release11-1)替代。 6384 6385**系统能力:** SystemCapability.Multimedia.Camera.Core 6386 6387**参数:** 6388 6389| 参数名 | 类型 | 必填 | 说明 | 6390| -------- | -------------------- | ---- | -------------------- | 6391| callback | AsyncCallback\<void\> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 6392 6393**错误码:** 6394 6395以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 6396 6397| 错误码ID | 错误信息 | 6398| --------------- | --------------- | 6399| 7400201 | Camera service fatal error. | 6400 6401**示例:** 6402 6403```ts 6404import { BusinessError } from '@kit.BasicServicesKit'; 6405 6406function releaseCaptureSession(captureSession: camera.CaptureSession): void { 6407 captureSession.release((err: BusinessError) => { 6408 if (err) { 6409 console.error(`Failed to release the CaptureSession instance, error code: ${err.code}.`); 6410 return; 6411 } 6412 console.info('Callback invoked to indicate that the CaptureSession instance is released successfully.'); 6413 }); 6414} 6415``` 6416 6417### release<sup>(deprecated)</sup> 6418 6419release(): Promise\<void\> 6420 6421释放会话资源,通过Promise获取结果。 6422 6423> **说明:** 6424>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.release](#release11-2)替代。 6425 6426**系统能力:** SystemCapability.Multimedia.Camera.Core 6427 6428**返回值:** 6429 6430| 类型 | 说明 | 6431| -------------- | ------------------------ | 6432| Promise\<void\> | 无返回结果的Promise对象。 | 6433 6434**错误码:** 6435 6436以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 6437 6438| 错误码ID | 错误信息 | 6439| --------------- | --------------- | 6440| 7400201 | Camera service fatal error. | 6441 6442**示例:** 6443 6444```ts 6445import { BusinessError } from '@kit.BasicServicesKit'; 6446 6447function releaseCaptureSession(captureSession: camera.CaptureSession): void { 6448 captureSession.release().then(() => { 6449 console.info('Promise returned to indicate that the CaptureSession instance is released successfully.'); 6450 }).catch((err: BusinessError) => { 6451 console.error(`Failed to release the CaptureSession instance, error code: ${err.code}.`); 6452 }); 6453} 6454``` 6455 6456### hasFlash<sup>(deprecated)</sup> 6457 6458hasFlash(): boolean 6459 6460检测是否有闪光灯。 6461 6462> **说明:** 6463>从 API version 10开始支持,从API version 11开始废弃。建议使用[Flash.hasFlash](#hasflash11)替代。 6464 6465**系统能力:** SystemCapability.Multimedia.Camera.Core 6466 6467**返回值:** 6468 6469| 类型 | 说明 | 6470| ---------- | ----------------------------- | 6471| boolean | 返回true表示设备支持闪光灯,false表示不支持。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 6472 6473**错误码:** 6474 6475以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 6476 6477| 错误码ID | 错误信息 | 6478| --------------- | --------------- | 6479| 7400103 | Session not config. | 6480 6481**示例:** 6482 6483```ts 6484import { BusinessError } from '@kit.BasicServicesKit'; 6485 6486function hasFlash(captureSession: camera.CaptureSession): boolean { 6487 let status: boolean = false; 6488 try { 6489 status = captureSession.hasFlash(); 6490 } catch (error) { 6491 // 失败返回错误码error.code并处理 6492 let err = error as BusinessError; 6493 console.error(`The hasFlash call failed. error code: ${err.code}`); 6494 } 6495 return status; 6496} 6497``` 6498 6499### isFlashModeSupported<sup>(deprecated)</sup> 6500 6501isFlashModeSupported(flashMode: FlashMode): boolean 6502 6503检测闪光灯模式是否支持。 6504 6505> **说明:** 6506>从 API version 10开始支持,从API version 11开始废弃。建议使用[Flash.isFlashModeSupported](#isflashmodesupported11)替代。 6507 6508**系统能力:** SystemCapability.Multimedia.Camera.Core 6509 6510**参数:** 6511 6512| 参数名 | 类型 | 必填 | 说明 | 6513| --------- | ----------------------- | ---- | --------------------------------- | 6514| flashMode | [FlashMode](#flashmode) | 是 | 指定闪光灯模式。 | 6515 6516**返回值:** 6517 6518| 类型 | 说明 | 6519| ---------- | ----------------------------- | 6520| boolean | 返回true表示支持该闪光灯模式,false表示不支持。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 6521 6522**错误码:** 6523 6524以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 6525 6526| 错误码ID | 错误信息 | 6527| --------------- | --------------- | 6528| 7400103 | Session not config. | 6529 6530**示例:** 6531 6532```ts 6533import { BusinessError } from '@kit.BasicServicesKit'; 6534 6535function isFlashModeSupported(captureSession: camera.CaptureSession): boolean { 6536 let status: boolean = false; 6537 try { 6538 status = captureSession.isFlashModeSupported(camera.FlashMode.FLASH_MODE_AUTO); 6539 } catch (error) { 6540 // 失败返回错误码error.code并处理 6541 let err = error as BusinessError; 6542 console.error(`The isFlashModeSupported call failed. error code: ${err.code}`); 6543 } 6544 return status; 6545} 6546``` 6547 6548### setFlashMode<sup>(deprecated)</sup> 6549 6550setFlashMode(flashMode: FlashMode): void 6551 6552设置闪光灯模式。 6553 6554进行设置之前,需要先检查: 6555 65561. 设备是否支持闪光灯,可使用方法[hasFlash](#hasflashdeprecated)。 65572. 设备是否支持指定的闪光灯模式,可使用方法[isFlashModeSupported](#isflashmodesupporteddeprecated)。 6558 6559> **说明:** 6560>从 API version 10开始支持,从API version 11开始废弃。建议使用[Flash.setFlashMode](#setflashmode11)替代。 6561 6562**系统能力:** SystemCapability.Multimedia.Camera.Core 6563 6564**参数:** 6565 6566| 参数名 | 类型 | 必填 | 说明 | 6567| --------- | ----------------------- | ---- | -------------------- | 6568| flashMode | [FlashMode](#flashmode) | 是 | 指定闪光灯模式。 | 6569 6570**错误码:** 6571 6572以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 6573 6574| 错误码ID | 错误信息 | 6575| --------------- | --------------- | 6576| 7400103 | Session not config. | 6577 6578**示例:** 6579 6580```ts 6581import { BusinessError } from '@kit.BasicServicesKit'; 6582 6583function setFlashMode(captureSession: camera.CaptureSession): void { 6584 try { 6585 captureSession.setFlashMode(camera.FlashMode.FLASH_MODE_AUTO); 6586 } catch (error) { 6587 // 失败返回错误码error.code并处理 6588 let err = error as BusinessError; 6589 console.error(`The setFlashMode call failed. error code: ${err.code}`); 6590 } 6591} 6592``` 6593 6594### getFlashMode<sup>(deprecated)</sup> 6595 6596getFlashMode(): FlashMode 6597 6598获取当前设备的闪光灯模式。 6599 6600> **说明:** 6601>从 API version 10开始支持,从API version 11开始废弃。建议使用[Flash.getFlashMode](#getflashmode11)替代。 6602 6603**系统能力:** SystemCapability.Multimedia.Camera.Core 6604 6605**返回值:** 6606 6607| 类型 | 说明 | 6608| ---------- | ----------------------------- | 6609| [FlashMode](#flashmode) | 获取当前设备的闪光灯模式。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 6610 6611**错误码:** 6612 6613以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 6614 6615| 错误码ID | 错误信息 | 6616| --------------- | --------------- | 6617| 7400103 | Session not config. | 6618 6619**示例:** 6620 6621```ts 6622import { BusinessError } from '@kit.BasicServicesKit'; 6623 6624function getFlashMode(captureSession: camera.CaptureSession): camera.FlashMode | undefined { 6625 let flashMode: camera.FlashMode | undefined = undefined; 6626 try { 6627 flashMode = captureSession.getFlashMode(); 6628 } catch (error) { 6629 // 失败返回错误码error.code并处理 6630 let err = error as BusinessError; 6631 console.error(`The getFlashMode call failed.error code: ${err.code}`); 6632 } 6633 return flashMode; 6634} 6635``` 6636 6637### isExposureModeSupported<sup>(deprecated)</sup> 6638 6639isExposureModeSupported(aeMode: ExposureMode): boolean 6640 6641检测曝光模式是否支持。 6642 6643> **说明:** 6644>从 API version 10开始支持,从API version 11开始废弃。建议使用[AutoExposure.isExposureModeSupported](#isexposuremodesupported11)替代。 6645 6646**系统能力:** SystemCapability.Multimedia.Camera.Core 6647 6648**参数:** 6649 6650| 参数名 | 类型 | 必填 | 说明 | 6651| -------- | -------------------------------| ---- | ----------------------------- | 6652| aeMode | [ExposureMode](#exposuremode) | 是 | 曝光模式。 | 6653 6654**返回值:** 6655 6656| 类型 | 说明 | 6657| ---------- | ----------------------------- | 6658| boolean | 获取是否支持曝光模式。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 6659 6660**错误码:** 6661 6662以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 6663 6664| 错误码ID | 错误信息 | 6665| --------------- | --------------- | 6666| 7400103 | Session not config. | 6667 6668**示例:** 6669 6670```ts 6671import { BusinessError } from '@kit.BasicServicesKit'; 6672 6673function isExposureModeSupported(captureSession: camera.CaptureSession): boolean { 6674 let isSupported: boolean = false; 6675 try { 6676 isSupported = captureSession.isExposureModeSupported(camera.ExposureMode.EXPOSURE_MODE_LOCKED); 6677 } catch (error) { 6678 // 失败返回错误码error.code并处理 6679 let err = error as BusinessError; 6680 console.error(`The isExposureModeSupported call failed. error code: ${err.code}`); 6681 } 6682 return isSupported; 6683} 6684``` 6685 6686### getExposureMode<sup>(deprecated)</sup> 6687 6688getExposureMode(): ExposureMode 6689 6690获取当前曝光模式。 6691 6692> **说明:** 6693>从 API version 10开始支持,从API version 11开始废弃。建议使用[AutoExposure.getExposureMode](#getexposuremode11)替代。 6694 6695**系统能力:** SystemCapability.Multimedia.Camera.Core 6696 6697**返回值:** 6698 6699| 类型 | 说明 | 6700| ---------- | ----------------------------- | 6701| [ExposureMode](#exposuremode) | 获取当前曝光模式。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 6702 6703**错误码:** 6704 6705以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 6706 6707| 错误码ID | 错误信息 | 6708| --------------- | --------------- | 6709| 7400103 | Session not config. | 6710 6711**示例:** 6712 6713```ts 6714import { BusinessError } from '@kit.BasicServicesKit'; 6715 6716function getExposureMode(captureSession: camera.CaptureSession): camera.ExposureMode | undefined { 6717 let exposureMode: camera.ExposureMode | undefined = undefined; 6718 try { 6719 exposureMode = captureSession.getExposureMode(); 6720 } catch (error) { 6721 // 失败返回错误码error.code并处理 6722 let err = error as BusinessError; 6723 console.error(`The getExposureMode call failed. error code: ${err.code}`); 6724 } 6725 return exposureMode; 6726} 6727``` 6728 6729### setExposureMode<sup>(deprecated)</sup> 6730 6731setExposureMode(aeMode: ExposureMode): void 6732 6733设置曝光模式。进行设置之前,需要先检查设备是否支持指定的曝光模式,可使用方法[isExposureModeSupported](#isexposuremodesupporteddeprecated)。 6734 6735> **说明:** 6736>从 API version 10开始支持,从API version 11开始废弃。建议使用[AutoExposure.setExposureMode](#setexposuremode11)替代。 6737 6738**系统能力:** SystemCapability.Multimedia.Camera.Core 6739 6740**参数:** 6741 6742| 参数名 | 类型 | 必填 | 说明 | 6743| -------- | -------------------------------| ---- | ----------------------- | 6744| aeMode | [ExposureMode](#exposuremode) | 是 | 曝光模式。 | 6745 6746**错误码:** 6747 6748以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 6749 6750| 错误码ID | 错误信息 | 6751| --------------- | --------------- | 6752| 7400103 | Session not config. | 6753 6754**示例:** 6755 6756```ts 6757import { BusinessError } from '@kit.BasicServicesKit'; 6758 6759function setExposureMode(captureSession: camera.CaptureSession): void { 6760 try { 6761 captureSession.setExposureMode(camera.ExposureMode.EXPOSURE_MODE_LOCKED); 6762 } catch (error) { 6763 // 失败返回错误码error.code并处理 6764 let err = error as BusinessError; 6765 console.error(`The setExposureMode call failed. error code: ${err.code}`); 6766 } 6767} 6768``` 6769 6770### getMeteringPoint<sup>(deprecated)</sup> 6771 6772getMeteringPoint(): Point 6773 6774查询曝光区域中心点。 6775 6776> **说明:** 6777>从 API version 10开始支持,从API version 11开始废弃。建议使用[AutoExposure.getMeteringPoint](#getmeteringpoint11)替代。 6778 6779**系统能力:** SystemCapability.Multimedia.Camera.Core 6780 6781**返回值:** 6782 6783| 类型 | 说明 | 6784| ---------- | ----------------------------- | 6785| [Point](#point) | 获取当前曝光点。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 6786 6787**错误码:** 6788 6789以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 6790 6791| 错误码ID | 错误信息 | 6792| --------------- | --------------- | 6793| 7400103 | Session not config. | 6794 6795**示例:** 6796 6797```ts 6798import { BusinessError } from '@kit.BasicServicesKit'; 6799 6800function getMeteringPoint(captureSession: camera.CaptureSession): camera.Point | undefined { 6801 let exposurePoint: camera.Point | undefined = undefined; 6802 try { 6803 exposurePoint = captureSession.getMeteringPoint(); 6804 } catch (error) { 6805 // 失败返回错误码error.code并处理 6806 let err = error as BusinessError; 6807 console.error(`The getMeteringPoint call failed. error code: ${err.code}`); 6808 } 6809 return exposurePoint; 6810} 6811``` 6812 6813### setMeteringPoint<sup>(deprecated)</sup> 6814 6815setMeteringPoint(point: Point): void 6816 6817设置曝光区域中心点,曝光点应在0-1坐标系内,该坐标系左上角为{0,0},右下角为{1,1}。 6818此坐标系是以设备充电口在右侧时的横向设备方向为基准的,例如应用的预览界面布局以 6819设备充电口在下侧时的竖向方向为基准,布局宽高为{w,h},且触碰点为{x,y}, 6820则转换后的坐标点为{y/h,1-x/w}。 6821 6822> **说明:** 6823>从 API version 10开始支持,从API version 11开始废弃。建议使用[AutoExposure.setMeteringPoint](#setmeteringpoint11)替代。 6824 6825**系统能力:** SystemCapability.Multimedia.Camera.Core 6826 6827**参数:** 6828 6829| 参数名 | 类型 | 必填 | 说明 | 6830| ------------- | -------------------------------| ---- | ------------------- | 6831| point | [Point](#point) | 是 | 曝光点,x,y设置范围应在[0,1]之内,超过范围,如果小于0设置0,大于1设置1。 | 6832 6833**错误码:** 6834 6835以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 6836 6837| 错误码ID | 错误信息 | 6838| --------------- | --------------- | 6839| 7400103 | Session not config. | 6840 6841**示例:** 6842 6843```ts 6844import { BusinessError } from '@kit.BasicServicesKit'; 6845 6846function setMeteringPoint(captureSession: camera.CaptureSession): void { 6847 const point: camera.Point = {x: 1, y: 1}; 6848 try { 6849 captureSession.setMeteringPoint(point); 6850 } catch (error) { 6851 // 失败返回错误码error.code并处理 6852 let err = error as BusinessError; 6853 console.error(`The setMeteringPoint call failed. error code: ${err.code}`); 6854 } 6855} 6856``` 6857 6858### getExposureBiasRange<sup>(deprecated)</sup> 6859 6860getExposureBiasRange(): Array\<number\> 6861 6862查询曝光补偿范围。 6863 6864> **说明:** 6865>从 API version 10开始支持,从API version 11开始废弃。建议使用[AutoExposure.getExposureBiasRange](#getexposurebiasrange11)替代。 6866 6867**系统能力:** SystemCapability.Multimedia.Camera.Core 6868 6869**返回值:** 6870 6871| 类型 | 说明 | 6872| ---------- | ----------------------------- | 6873| Array\<number\> | 获取补偿范围的数组。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 6874 6875**错误码:** 6876 6877以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 6878 6879| 错误码ID | 错误信息 | 6880| --------------- | --------------- | 6881| 7400103 | Session not config. | 6882 6883**示例:** 6884 6885```ts 6886import { BusinessError } from '@kit.BasicServicesKit'; 6887 6888function getExposureBiasRange(captureSession: camera.CaptureSession): Array<number> { 6889 let biasRangeArray: Array<number> = []; 6890 try { 6891 biasRangeArray = captureSession.getExposureBiasRange(); 6892 } catch (error) { 6893 // 失败返回错误码error.code并处理 6894 let err = error as BusinessError; 6895 console.error(`The getExposureBiasRange call failed. error code: ${err.code}`); 6896 } 6897 return biasRangeArray; 6898} 6899``` 6900 6901### setExposureBias<sup>(deprecated)</sup> 6902 6903setExposureBias(exposureBias: number): void 6904 6905设置曝光补偿,曝光补偿值(EV)。 6906 6907进行设置之前,建议先通过方法[getExposureBiasRange](#getexposurebiasrangedeprecated)查询支持的范围。 6908 6909> **说明:** 6910>从 API version 10开始支持,从API version 11开始废弃。建议使用[AutoExposure.setExposureBias](#setexposurebias11)替代。 6911 6912**系统能力:** SystemCapability.Multimedia.Camera.Core 6913 6914**参数:** 6915 6916| 参数名 | 类型 | 必填 | 说明 | 6917| -------- | -------------------------------|-----|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| 6918| exposureBias | number | 是 | 曝光补偿,[getExposureBiasRange](#getexposurebiasrange11)查询支持的范围,如果设置超过支持范围的值,自动匹配到就近临界点。曝光补偿存在步长,如步长为0.5。则设置1.2时,获取到实际生效曝光补偿为1.0。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。传参为null或者undefined,作为0处理,曝光补偿设置0。 | 6919 6920**错误码:** 6921 6922以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 6923 6924| 错误码ID | 错误信息 | 6925| --------------- | --------------- | 6926| 7400103 | Session not config. | 6927 6928**示例:** 6929 6930```ts 6931import { BusinessError } from '@kit.BasicServicesKit'; 6932 6933function setExposureBias(captureSession: camera.CaptureSession, biasRangeArray: Array<number>): void { 6934 if (biasRangeArray && biasRangeArray.length > 0) { 6935 let exposureBias = biasRangeArray[0]; 6936 try { 6937 captureSession.setExposureBias(exposureBias); 6938 } catch (error) { 6939 // 失败返回错误码error.code并处理 6940 let err = error as BusinessError; 6941 console.error(`The setExposureBias call failed. error code: ${err.code}`); 6942 } 6943 } 6944} 6945``` 6946 6947### getExposureValue<sup>(deprecated)</sup> 6948 6949getExposureValue(): number 6950 6951查询当前曝光值。 6952 6953> **说明:** 6954>从 API version 10开始支持,从API version 11开始废弃。建议使用[AutoExposure.getExposureValue](#getexposurevalue11)替代。 6955 6956**系统能力:** SystemCapability.Multimedia.Camera.Core 6957 6958**返回值:** 6959 6960| 类型 | 说明 | 6961| ---------- | ----------------------------- | 6962| number | 获取曝光值。曝光补偿存在步长,如步长为0.5。则设置1.2时,获取到实际生效曝光补偿为1.0。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 6963 6964**错误码:** 6965 6966以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 6967 6968| 错误码ID | 错误信息 | 6969| --------------- | --------------- | 6970| 7400103 | Session not config. | 6971 6972**示例:** 6973 6974```ts 6975import { BusinessError } from '@kit.BasicServicesKit'; 6976 6977function getExposureValue(captureSession: camera.CaptureSession): number { 6978 const invalidValue: number = -1; 6979 let exposureValue: number = invalidValue; 6980 try { 6981 exposureValue = captureSession.getExposureValue(); 6982 } catch (error) { 6983 // 失败返回错误码error.code并处理 6984 let err = error as BusinessError; 6985 console.error(`The getExposureValue call failed. error code: ${err.code}`); 6986 } 6987 return exposureValue; 6988} 6989``` 6990 6991### isFocusModeSupported<sup>(deprecated)</sup> 6992 6993isFocusModeSupported(afMode: FocusMode): boolean 6994 6995检测对焦模式是否支持。 6996 6997> **说明:** 6998>从 API version 10开始支持,从API version 11开始废弃。建议使用[Focus.isFocusModeSupported](#isfocusmodesupported11)替代。 6999 7000**系统能力:** SystemCapability.Multimedia.Camera.Core 7001 7002**参数:** 7003 7004| 参数名 | 类型 | 必填 | 说明 | 7005| -------- | ----------------------- | ---- | -------------------------------- | 7006| afMode | [FocusMode](#focusmode) | 是 | 指定的焦距模式。 | 7007 7008**返回值:** 7009 7010| 类型 | 说明 | 7011| ---------- | ----------------------------- | 7012| boolean | 返回true表示支持该焦距模式,false表示不支持。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 7013 7014**错误码:** 7015 7016以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 7017 7018| 错误码ID | 错误信息 | 7019| --------------- | --------------- | 7020| 7400103 | Session not config. | 7021 7022**示例:** 7023 7024```ts 7025import { BusinessError } from '@kit.BasicServicesKit'; 7026 7027function isFocusModeSupported(captureSession: camera.CaptureSession): boolean { 7028 let status: boolean = false; 7029 try { 7030 status = captureSession.isFocusModeSupported(camera.FocusMode.FOCUS_MODE_AUTO); 7031 } catch (error) { 7032 // 失败返回错误码error.code并处理 7033 let err = error as BusinessError; 7034 console.error(`The isFocusModeSupported call failed. error code: ${err.code}`); 7035 } 7036 return status; 7037} 7038``` 7039 7040### setFocusMode<sup>(deprecated)</sup> 7041 7042setFocusMode(afMode: FocusMode): void 7043 7044设置对焦模式。 7045 7046进行设置之前,需要先检查设备是否支持指定的焦距模式,可使用方法[isFocusModeSupported](#isfocusmodesupporteddeprecated)。 7047 7048> **说明:** 7049>从 API version 10开始支持,从API version 11开始废弃。建议使用[Focus.setFocusMode](#setfocusmode11)替代。 7050 7051**系统能力:** SystemCapability.Multimedia.Camera.Core 7052 7053**参数:** 7054 7055| 参数名 | 类型 | 必填 | 说明 | 7056| -------- | ----------------------- | ---- | ------------------- | 7057| afMode | [FocusMode](#focusmode) | 是 | 指定的焦距模式。 | 7058 7059**错误码:** 7060 7061以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 7062 7063| 错误码ID | 错误信息 | 7064| --------------- | --------------- | 7065| 7400103 | Session not config. | 7066 7067**示例:** 7068 7069```ts 7070import { BusinessError } from '@kit.BasicServicesKit'; 7071 7072function setFocusMode(captureSession: camera.CaptureSession): void { 7073 try { 7074 captureSession.setFocusMode(camera.FocusMode.FOCUS_MODE_AUTO); 7075 } catch (error) { 7076 // 失败返回错误码error.code并处理 7077 let err = error as BusinessError; 7078 console.error(`The setFocusMode call failed. error code: ${err.code}`); 7079 } 7080} 7081``` 7082 7083### getFocusMode<sup>(deprecated)</sup> 7084 7085getFocusMode(): FocusMode 7086 7087获取当前的对焦模式。 7088 7089> **说明:** 7090>从 API version 10开始支持,从API version 11开始废弃。建议使用[Focus.getFocusMode](#getfocusmode11)替代。 7091 7092**系统能力:** SystemCapability.Multimedia.Camera.Core 7093 7094**返回值:** 7095 7096| 类型 | 说明 | 7097| ---------- | ----------------------------- | 7098| [FocusMode](#focusmode) | 获取当前设备的焦距模式。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 7099 7100**错误码:** 7101 7102以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 7103 7104| 错误码ID | 错误信息 | 7105| --------------- | --------------- | 7106| 7400103 | Session not config. | 7107 7108**示例:** 7109 7110```ts 7111import { BusinessError } from '@kit.BasicServicesKit'; 7112 7113function getFocusMode(captureSession: camera.CaptureSession): camera.FocusMode | undefined { 7114 let afMode: camera.FocusMode | undefined = undefined; 7115 try { 7116 afMode = captureSession.getFocusMode(); 7117 } catch (error) { 7118 // 失败返回错误码error.code并处理 7119 let err = error as BusinessError; 7120 console.error(`The getFocusMode call failed. error code: ${err.code}`); 7121 } 7122 return afMode; 7123} 7124``` 7125 7126### setFocusPoint<sup>(deprecated)</sup> 7127 7128setFocusPoint(point: Point): void 7129 7130设置焦点,焦点应在0-1坐标系内,该坐标系左上角为{0,0},右下角为{1,1}。 7131此坐标系是以设备充电口在右侧时的横向设备方向为基准的,例如应用的预览界面布局以 7132设备充电口在下侧时的竖向方向为基准,布局宽高为{w,h},且触碰点为{x,y}, 7133则转换后的坐标点为{y/h,1-x/w}。 7134 7135> **说明:** 7136>从 API version 10开始支持,从API version 11开始废弃。建议使用[Focus.setFocusPoint](#setfocuspoint11)替代。 7137 7138**系统能力:** SystemCapability.Multimedia.Camera.Core 7139 7140**参数:** 7141 7142| 参数名 | 类型 | 必填 | 说明 | 7143|-------| ----------------------- |-----| ------------------- | 7144| point | [Point](#point) | 是 | 焦点。x,y设置范围应在[0,1]之内,超过范围,如果小于0设置0,大于1设置1。 | 7145 7146**错误码:** 7147 7148以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 7149 7150| 错误码ID | 错误信息 | 7151| --------------- | --------------- | 7152| 7400103 | Session not config. | 7153 7154**示例:** 7155 7156```ts 7157import { BusinessError } from '@kit.BasicServicesKit'; 7158 7159function setFocusPoint(captureSession: camera.CaptureSession): void { 7160 const focusPoint: camera.Point = {x: 1, y: 1}; 7161 try { 7162 captureSession.setFocusPoint(focusPoint); 7163 } catch (error) { 7164 // 失败返回错误码error.code并处理 7165 let err = error as BusinessError; 7166 console.error(`The setFocusPoint call failed. error code: ${err.code}`); 7167 } 7168} 7169``` 7170 7171### getFocusPoint<sup>(deprecated)</sup> 7172 7173getFocusPoint(): Point 7174 7175查询焦点。 7176 7177> **说明:** 7178>从 API version 10开始支持,从API version 11开始废弃。建议使用[Focus.getFocusPoint](#getfocuspoint11)替代。 7179 7180**系统能力:** SystemCapability.Multimedia.Camera.Core 7181 7182**返回值:** 7183 7184| 类型 | 说明 | 7185| ---------- | ----------------------------- | 7186| [Point](#point) | 用于获取当前焦点。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 7187 7188**错误码:** 7189 7190以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 7191 7192| 错误码ID | 错误信息 | 7193| --------------- | --------------- | 7194| 7400103 | Session not config. | 7195 7196**示例:** 7197 7198```ts 7199import { BusinessError } from '@kit.BasicServicesKit'; 7200 7201function getFocusPoint(captureSession: camera.CaptureSession): camera.Point | undefined { 7202 let point: camera.Point | undefined = undefined; 7203 try { 7204 point = captureSession.getFocusPoint(); 7205 } catch (error) { 7206 // 失败返回错误码error.code并处理 7207 let err = error as BusinessError; 7208 console.error(`The getFocusPoint call failed. error code: ${err.code}`); 7209 } 7210 return point; 7211} 7212``` 7213 7214### getFocalLength<sup>(deprecated)</sup> 7215 7216getFocalLength(): number 7217 7218查询焦距值。 7219 7220> **说明:** 7221>从 API version 10开始支持,从API version 11开始废弃。建议使用[Focus.getFocalLength](#getfocallength11)替代。 7222 7223**系统能力:** SystemCapability.Multimedia.Camera.Core 7224 7225**返回值:** 7226 7227| 类型 | 说明 | 7228| ---------- | ----------------------------- | 7229| number | 用于获取当前焦距。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 7230 7231**错误码:** 7232 7233以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 7234 7235| 错误码ID | 错误信息 | 7236| --------------- | --------------- | 7237| 7400103 | Session not config. | 7238 7239**示例:** 7240 7241```ts 7242import { BusinessError } from '@kit.BasicServicesKit'; 7243 7244function getFocalLength(captureSession: camera.CaptureSession): number { 7245 const invalidValue: number = -1; 7246 let focalLength: number = invalidValue; 7247 try { 7248 focalLength = captureSession.getFocalLength(); 7249 } catch (error) { 7250 // 失败返回错误码error.code并处理 7251 let err = error as BusinessError; 7252 console.error(`The getFocalLength call failed. error code: ${err.code}`); 7253 } 7254 return focalLength; 7255} 7256``` 7257 7258### getZoomRatioRange<sup>(deprecated)</sup> 7259 7260getZoomRatioRange(): Array\<number\> 7261 7262获取支持的变焦范围。 7263 7264> **说明:** 7265>从 API version 10开始支持,从API version 11开始废弃。建议使用[Zoom.getZoomRatioRange](#getzoomratiorange11)替代。 7266 7267**系统能力:** SystemCapability.Multimedia.Camera.Core 7268 7269**返回值:** 7270 7271| 类型 | 说明 | 7272| ---------- | ----------------------------- | 7273| Array\<number\> | 用于获取可变焦距比范围,返回的数组包括其最小值和最大值。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 7274 7275**错误码:** 7276 7277以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 7278 7279| 错误码ID | 错误信息 | 7280| --------------- | --------------- | 7281| 7400103 | Session not config. | 7282 7283**示例:** 7284 7285```ts 7286import { BusinessError } from '@kit.BasicServicesKit'; 7287 7288function getZoomRatioRange(captureSession: camera.CaptureSession): Array<number> { 7289 let zoomRatioRange: Array<number> = []; 7290 try { 7291 zoomRatioRange = captureSession.getZoomRatioRange(); 7292 } catch (error) { 7293 // 失败返回错误码error.code并处理 7294 let err = error as BusinessError; 7295 console.error(`The getZoomRatioRange call failed. error code: ${err.code}`); 7296 } 7297 return zoomRatioRange; 7298} 7299``` 7300 7301### setZoomRatio<sup>(deprecated)</sup> 7302 7303setZoomRatio(zoomRatio: number): void 7304 7305设置变焦比,变焦精度最高为小数点后两位,如果设置超过支持的精度范围,则只保留精度范围内数值。 7306 7307> **说明:** 7308>从 API version 10开始支持,从API version 11开始废弃。建议使用[Zoom.setZoomRatio](#setzoomratio11)替代。 7309 7310**系统能力:** SystemCapability.Multimedia.Camera.Core 7311 7312**参数:** 7313 7314| 参数名 | 类型 | 必填 | 说明 | 7315| --------- | -------------------- |-----| ------------------- | 7316| zoomRatio | number | 是 | 可变焦距比,通过[getZoomRatioRange](#getzoomratiorange11)获取支持的变焦范围,如果设置超过支持范围的值,则只保留精度范围内数值。传参为null或者undefined,作为0处理,变焦设置最小值。 | 7317 7318**错误码:** 7319 7320以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 7321 7322| 错误码ID | 错误信息 | 7323| --------------- | --------------- | 7324| 7400103 | Session not config. | 7325 7326**示例:** 7327 7328```ts 7329import { BusinessError } from '@kit.BasicServicesKit'; 7330 7331function setZoomRatio(captureSession: camera.CaptureSession, zoomRatioRange: Array<number>): void { 7332 if (zoomRatioRange === undefined || zoomRatioRange.length <= 0) { 7333 return; 7334 } 7335 let zoomRatio = zoomRatioRange[0]; 7336 try { 7337 captureSession.setZoomRatio(zoomRatio); 7338 } catch (error) { 7339 // 失败返回错误码error.code并处理 7340 let err = error as BusinessError; 7341 console.error(`The setZoomRatio call failed. error code: ${err.code}`); 7342 } 7343} 7344``` 7345 7346### getZoomRatio<sup>(deprecated)</sup> 7347 7348getZoomRatio(): number 7349 7350获取当前的变焦比。 7351 7352> **说明:** 7353>从 API version 10开始支持,从API version 11开始废弃。建议使用[Zoom.getZoomRatio](#getzoomratio11)替代。 7354 7355**系统能力:** SystemCapability.Multimedia.Camera.Core 7356 7357**返回值:** 7358 7359| 类型 | 说明 | 7360| ---------- | ----------------------------- | 7361| number | 获取当前的变焦比结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 7362 7363**错误码:** 7364 7365以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 7366 7367| 错误码ID | 错误信息 | 7368| --------------- | --------------- | 7369| 7400103 | Session not config. | 7370 7371**示例:** 7372 7373```ts 7374import { BusinessError } from '@kit.BasicServicesKit'; 7375 7376function getZoomRatio(captureSession: camera.CaptureSession): number { 7377 const invalidValue: number = -1; 7378 let zoomRatio: number = invalidValue; 7379 try { 7380 zoomRatio = captureSession.getZoomRatio(); 7381 } catch (error) { 7382 // 失败返回错误码error.code并处理 7383 let err = error as BusinessError; 7384 console.error(`The getZoomRatio call failed. error code: ${err.code}`); 7385 } 7386 return zoomRatio; 7387} 7388``` 7389 7390### isVideoStabilizationModeSupported<sup>(deprecated)</sup> 7391 7392isVideoStabilizationModeSupported(vsMode: VideoStabilizationMode): boolean 7393 7394查询是否支持指定的视频防抖模式。 7395 7396> **说明:** 7397>从 API version 10开始支持,从API version 11开始废弃。建议使用[Stabilization.isVideoStabilizationModeSupported](#isvideostabilizationmodesupported11)替代。 7398 7399**系统能力:** SystemCapability.Multimedia.Camera.Core 7400 7401**参数:** 7402 7403| 参数名 | 类型 | 必填 | 说明 | 7404| -------- | ------------------------------------------------- | ---- | ------------------------------ | 7405| vsMode | [VideoStabilizationMode](#videostabilizationmode) | 是 | 视频防抖模式。传参为null或者undefined,作为0处理,超级防抖模式关闭。 | 7406 7407**返回值:** 7408 7409| 类型 | 说明 | 7410| ---------- | ----------------------------- | 7411| boolean | 返回视频防抖模式是否支持,true表示支持,false表示不支持。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 7412 7413**错误码:** 7414 7415以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 7416 7417| 错误码ID | 错误信息 | 7418| --------------- | --------------- | 7419| 7400103 | Session not config. | 7420 7421**示例:** 7422 7423```ts 7424import { BusinessError } from '@kit.BasicServicesKit'; 7425 7426function isVideoStabilizationModeSupported(captureSession: camera.CaptureSession): boolean { 7427 let isSupported: boolean = false; 7428 try { 7429 isSupported = captureSession.isVideoStabilizationModeSupported(camera.VideoStabilizationMode.OFF); 7430 } catch (error) { 7431 // 失败返回错误码error.code并处理 7432 let err = error as BusinessError; 7433 console.error(`The isVideoStabilizationModeSupported call failed. error code: ${err.code}`); 7434 } 7435 return isSupported; 7436} 7437``` 7438 7439### getActiveVideoStabilizationMode<sup>(deprecated)</sup> 7440 7441getActiveVideoStabilizationMode(): VideoStabilizationMode 7442 7443查询当前正在使用的视频防抖模式。 7444 7445> **说明:** 7446>从 API version 10开始支持,从API version 11开始废弃。建议使用[Stabilization.getActiveVideoStabilizationMode](#getactivevideostabilizationmode11)替代。 7447 7448**系统能力:** SystemCapability.Multimedia.Camera.Core 7449 7450**返回值:** 7451 7452| 类型 | 说明 | 7453| ---------- | ----------------------------- | 7454| [VideoStabilizationMode](#videostabilizationmode) | 视频防抖是否正在使用。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 7455 7456**错误码:** 7457 7458以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 7459 7460| 错误码ID | 错误信息 | 7461| --------------- | --------------- | 7462| 7400103 | Session not config. | 7463 7464**示例:** 7465 7466```ts 7467import { BusinessError } from '@kit.BasicServicesKit'; 7468 7469function getActiveVideoStabilizationMode(captureSession: camera.CaptureSession): camera.VideoStabilizationMode | undefined { 7470 let vsMode: camera.VideoStabilizationMode | undefined = undefined; 7471 try { 7472 vsMode = captureSession.getActiveVideoStabilizationMode(); 7473 } catch (error) { 7474 // 失败返回错误码error.code并处理 7475 let err = error as BusinessError; 7476 console.error(`The getActiveVideoStabilizationMode call failed. error code: ${err.code}`); 7477 } 7478 return vsMode; 7479} 7480``` 7481 7482### setVideoStabilizationMode<sup>(deprecated)</sup> 7483 7484setVideoStabilizationMode(mode: VideoStabilizationMode): void 7485 7486设置视频防抖模式。需要先检查设备是否支持对应的防抖模式,可以通过[isVideoStabilizationModeSupported](#isvideostabilizationmodesupporteddeprecated)方法判断所设置的模式是否支持。 7487 7488> **说明:** 7489>从 API version 10开始支持,从API version 11开始废弃。建议使用[Stabilization.setVideoStabilizationMode](#setvideostabilizationmode11)替代。 7490 7491**系统能力:** SystemCapability.Multimedia.Camera.Core 7492 7493**参数:** 7494 7495| 参数名 | 类型 | 必填 | 说明 | 7496| -------- | ------------------------------------------------- | ---- | --------------------- | 7497| mode | [VideoStabilizationMode](#videostabilizationmode) | 是 | 需要设置的视频防抖模式。传参为null或者undefined,作为0处理,超级防抖模式关闭。 | 7498 7499**错误码:** 7500 7501以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 7502 7503| 错误码ID | 错误信息 | 7504| --------------- | --------------- | 7505| 7400103 | Session not config. | 7506 7507**示例:** 7508 7509```ts 7510import { BusinessError } from '@kit.BasicServicesKit'; 7511 7512function setVideoStabilizationMode(captureSession: camera.CaptureSession): void { 7513 try { 7514 captureSession.setVideoStabilizationMode(camera.VideoStabilizationMode.OFF); 7515 } catch (error) { 7516 // 失败返回错误码error.code并处理 7517 let err = error as BusinessError; 7518 console.error(`The setVideoStabilizationMode call failed. error code: ${err.code}`); 7519 } 7520} 7521``` 7522 7523### on('focusStateChange')<sup>(deprecated)</sup> 7524 7525on(type: 'focusStateChange', callback: AsyncCallback\<FocusState\>): void 7526 7527监听相机聚焦的状态变化,通过注册回调函数获取结果。使用callback异步回调。 7528 7529> **说明:** 7530> 从 API version 10开始支持,从API version 11开始废弃。建议使用[VideoSession.on('focusStateChange')](#onfocusstatechange11-1)替代。 7531> 7532> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 7533 7534**系统能力:** SystemCapability.Multimedia.Camera.Core 7535 7536**参数:** 7537 7538| 参数名 | 类型 | 必填 | 说明 | 7539| -------- | ----------------------------------------- | ---- | ------------------------ | 7540| type | string | 是 | 监听事件,固定为'focusStateChange',session 创建成功可监听。仅当自动对焦模式时,且相机对焦状态发生改变时可触发该事件。 | 7541| callback | AsyncCallback\<[FocusState](#focusstate)\> | 是 | 回调函数,用于获取当前对焦状态。 | 7542 7543**示例:** 7544 7545```ts 7546import { BusinessError } from '@kit.BasicServicesKit'; 7547 7548function registerFocusStateChange(captureSession: camera.CaptureSession): void { 7549 captureSession.on('focusStateChange', (err: BusinessError, focusState: camera.FocusState) => { 7550 if (err !== undefined && err.code !== 0) { 7551 console.error(`Callback Error, errorCode: ${err.code}`); 7552 return; 7553 } 7554 console.info(`Focus state: ${focusState}`); 7555 }); 7556} 7557``` 7558 7559### off('focusStateChange')<sup>(deprecated)</sup> 7560 7561off(type: 'focusStateChange', callback?: AsyncCallback\<FocusState\>): void 7562 7563注销监听相机聚焦的状态变化。 7564 7565> **说明:** 7566>从 API version 10开始支持,从API version 11开始废弃。建议使用[VideoSession.off('focusStateChange')](#offfocusstatechange11-1)替代。 7567 7568**系统能力:** SystemCapability.Multimedia.Camera.Core 7569 7570**参数:** 7571 7572| 参数名 | 类型 | 必填 | 说明 | 7573| -------- | ----------------------------------------- | ---- | ------------------------ | 7574| type | string | 是 | 监听事件,固定为'focusStateChange',session 创建成功可监听。| 7575| callback | AsyncCallback\<[FocusState](#focusstate)\> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 7576 7577**示例:** 7578 7579```ts 7580function unregisterFocusStateChange(captureSession: camera.CaptureSession): void { 7581 captureSession.off('focusStateChange'); 7582} 7583``` 7584 7585### on('error')<sup>(deprecated)</sup> 7586 7587on(type: 'error', callback: ErrorCallback): void 7588 7589监听拍照会话的错误事件,通过注册回调函数获取结果。使用callback异步回调。 7590 7591> **说明:** 7592> 7593> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 7594 7595> **说明:** 7596>从 API version 10开始支持,从API version 11开始废弃。建议使用[VideoSession.on('error')](#onerror11-1)替代。 7597 7598**系统能力:** SystemCapability.Multimedia.Camera.Core 7599 7600**参数:** 7601 7602| 参数名 | 类型 | 必填 | 说明 | 7603| -------- |--------------------------------------------------------------------------| ---- | ------------------------------ | 7604| type | string | 是 | 监听事件,固定为'error',session创建成功之后可监听该接口。session调用相关接口出现错误时会触发该事件,比如调用[beginConfig](#beginconfigdeprecated),[commitConfig](#commitconfigdeprecated-1),[addInput](#addinputdeprecated)等接口发生错误时返回错误信息。 | 7605| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | 是 | 回调函数,用于获取错误信息。返回错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 7606 7607**示例:** 7608 7609```ts 7610import { BusinessError } from '@kit.BasicServicesKit'; 7611 7612function registerCaptureSessionError(captureSession: camera.CaptureSession): void { 7613 captureSession.on('error', (error: BusinessError) => { 7614 console.error(`Capture session error code: ${error.code}`); 7615 }); 7616} 7617``` 7618 7619### off('error')<sup>(deprecated)</sup> 7620 7621off(type: 'error', callback?: ErrorCallback): void 7622 7623注销监听拍照会话的错误事件,通过注册回调函数获取结果。 7624 7625> **说明:** 7626>从 API version 10开始支持,从API version 11开始废弃。建议使用[VideoSession.off('error')](#offerror11-1)替代。 7627 7628**系统能力:** SystemCapability.Multimedia.Camera.Core 7629 7630**参数:** 7631 7632| 参数名 | 类型 | 必填 | 说明 | 7633| -------- | ----------------------------------------------------------- | ---- | ------------------------------ | 7634| type | string | 是 | 监听事件,固定为'error',session创建成功之后可监听该接口。 | 7635| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback)| 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 7636 7637**示例:** 7638 7639```ts 7640function unregisterCaptureSessionError(captureSession: camera.CaptureSession): void { 7641 captureSession.off('error'); 7642} 7643``` 7644## ColorManagementQuery<sup>12+</sup> 7645 7646色彩管理类,用于查询色彩空间参数。 7647 7648### getSupportedColorSpaces<sup>12+</sup> 7649 7650getSupportedColorSpaces(): Array\<colorSpaceManager.ColorSpace\> 7651 7652获取支持的色彩空间列表。 7653 7654**系统能力:** SystemCapability.Multimedia.Camera.Core 7655 7656**返回值:** 7657 7658| 类型 | 说明 | 7659| ----------------------------------------------- | ---------------------------- | 7660| Array<[colorSpaceManager.ColorSpace](../apis-arkgraphics2d/js-apis-colorSpaceManager.md#colorspace)>| 支持的色彩空间列表。 | 7661 7662**错误码:** 7663 7664以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 7665 7666| 错误码ID | 错误信息 | 7667| --------------- | --------------- | 7668| 7400103 | Session not config, only throw in session usage. | 7669 7670**示例:** 7671 7672```ts 7673import { BusinessError } from '@kit.BasicServicesKit'; 7674import { colorSpaceManager } from '@kit.ArkGraphics2D'; 7675 7676function getSupportedColorSpaces(session: camera.PhotoSession): Array<colorSpaceManager.ColorSpace> { 7677 let colorSpaces: Array<colorSpaceManager.ColorSpace> = []; 7678 try { 7679 colorSpaces = session.getSupportedColorSpaces(); 7680 } catch (error) { 7681 let err = error as BusinessError; 7682 console.error(`The getSupportedColorSpaces call failed. error code: ${err.code}`); 7683 } 7684 return colorSpaces; 7685} 7686``` 7687## ColorManagement<sup>12+</sup> 7688 7689ColorManagement extends [ColorManagementQuery](#colormanagementquery12) 7690 7691色彩管理类,继承自[ColorManagementQuery](#colormanagementquery12),用于设置色彩空间参数。 7692 7693### setColorSpace<sup>12+</sup> 7694 7695setColorSpace(colorSpace: colorSpaceManager.ColorSpace): void 7696 7697设置色彩空间。可以先通过[getSupportedColorSpaces](#getsupportedcolorspaces12)获取当前设备所支持的ColorSpaces。 7698 7699**P3广色域与HDR高动态范围成像** 7700 7701应用可以下发不同的色彩空间(ColorSpace)参数来支持P3广色域以及HDR的功能。 7702当应用不主动设置色彩空间时,拍照以及录像模式默认为HDR拍摄效果。 7703在拍照模式下设置HDR高显效果可直接支持P3色域。 7704应用针对不同模式使能HDR效果以及设置的色彩空间可参考下表。 7705 7706**录像模式:** 7707 7708| SDR/HRD拍摄 | CameraFormat | ColorSpace | 7709|--------------------|--------------------------|------------------| 7710| SDR | CAMERA_FORMAT_YUV_420_SP | BT709_LIMIT | 7711| HDR_VIVID(Default) | CAMERA_FORMAT_YCRCB_P010 | BT2020_HLG_LIMIT | 7712 7713**拍照模式:** 7714 7715| SDR/HRD拍摄 | ColorSpace | 7716|--------------|------------| 7717| SDR | SRGB | 7718| HDR(Default) | DISPLAY_P3 | 7719 7720**系统能力:** SystemCapability.Multimedia.Camera.Core 7721 7722**参数:** 7723 7724| 参数名 | 类型 | 必填 | 说明 | 7725| ------------ |---------------------- | -- | -------------------------- | 7726| colorSpace | [colorSpaceManager.ColorSpace](../apis-arkgraphics2d/js-apis-colorSpaceManager.md#colorspace) | 是 | 色彩空间,通过[getSupportedColorSpaces](#getsupportedcolorspaces12)接口获取。 | 7727 7728**错误码:** 7729 7730以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 7731 7732| 错误码ID | 错误信息 | 7733| --------------- | --------------- | 7734| 7400101 | Parameter missing or parameter type incorrect. | 7735| 7400102 | The colorSpace does not match the format. | 7736| 7400103 | Session not config. | 7737| 7400201 | Camera service fatal error. | 7738 7739**示例:** 7740 7741```ts 7742import { BusinessError } from '@kit.BasicServicesKit'; 7743import { colorSpaceManager } from '@kit.ArkGraphics2D'; 7744 7745function setColorSpace(session: camera.PhotoSession, colorSpaces: Array<colorSpaceManager.ColorSpace>): void { 7746 if (colorSpaces === undefined || colorSpaces.length <= 0) { 7747 return; 7748 } 7749 try { 7750 session.setColorSpace(colorSpaces[0]); 7751 } catch (error) { 7752 let err = error as BusinessError; 7753 console.error(`The setColorSpace call failed, error code: ${err.code}`); 7754 } 7755} 7756``` 7757 7758### getActiveColorSpace<sup>12+</sup> 7759 7760getActiveColorSpace(): colorSpaceManager.ColorSpace 7761 7762获取当前设置的色彩空间。 7763 7764**系统能力:** SystemCapability.Multimedia.Camera.Core 7765 7766**返回值:** 7767 7768| 类型 | 说明 | 7769| ----------------------------------------------- | ---------------------------- | 7770| [colorSpaceManager.ColorSpace](../apis-arkgraphics2d/js-apis-colorSpaceManager.md#colorspace) | 当前设置的色彩空间。 | 7771 7772**错误码:** 7773 7774以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 7775 7776| 错误码ID | 错误信息 | 7777| --------------- | --------------- | 7778| 7400103 | Session not config. | 7779 7780**示例:** 7781 7782```ts 7783import { BusinessError } from '@kit.BasicServicesKit'; 7784import { colorSpaceManager } from '@kit.ArkGraphics2D'; 7785 7786function getActiveColorSpace(session: camera.PhotoSession): colorSpaceManager.ColorSpace | undefined { 7787 let colorSpace: colorSpaceManager.ColorSpace | undefined = undefined; 7788 try { 7789 colorSpace = session.getActiveColorSpace(); 7790 } catch (error) { 7791 let err = error as BusinessError; 7792 console.error(`The getActiveColorSpace call failed. error code: ${err.code}`); 7793 } 7794 return colorSpace; 7795} 7796``` 7797 7798## PreconfigType<sup>12+</sup> 7799 7800枚举,提供预配置的类型。 7801 7802**系统能力:** SystemCapability.Multimedia.Camera.Core 7803 7804| 名称 | 值 | 说明 | 7805|-------------------------|---|------------| 7806| PRECONFIG_720P | 0 | 720P预配置。 | 7807| PRECONFIG_1080P | 1 | 1080P预配置。 | 7808| PRECONFIG_4K | 2 | 4K预配置。 | 7809| PRECONFIG_HIGH_QUALITY | 3 | 高质量预配置。 | 7810 7811## PreconfigRatio<sup>12+</sup> 7812 7813枚举,提供预配置的分辨率比例。 7814 7815**系统能力:** SystemCapability.Multimedia.Camera.Core 7816 7817| 名称 | 值 | 说明 | 7818|--------------------------|---|---------| 7819| PRECONFIG_RATIO_1_1 | 0 | 1:1画幅。 | 7820| PRECONFIG_RATIO_4_3 | 1 | 4:3画幅。 | 7821| PRECONFIG_RATIO_16_9 | 2 | 16:9画幅。 | 7822 7823## PhotoSession<sup>11+</sup> 7824 7825PhotoSession extends [Session](#session11), [Flash](#flash11), [AutoExposure](#autoexposure11), [Focus](#focus11), [Zoom](#zoom11), [ColorManagement](#colormanagement12) 7826 7827普通拍照模式会话类,提供了对闪光灯、曝光、对焦、变焦、色彩空间的操作。 7828 7829> **说明:** 7830> 7831> 默认的拍照模式,用于拍摄标准照片。支持多种照片格式和分辨率,适合大多数日常拍摄场景。 7832 7833### canPreconfig<sup>12+</sup> 7834 7835canPreconfig(preconfigType: PreconfigType, preconfigRatio?: PreconfigRatio): boolean 7836 7837查询当前Session是否支持指定的与配置类型。 7838 7839**系统能力:** SystemCapability.Multimedia.Camera.Core 7840 7841**参数:** 7842 7843| 参数名 | 类型 | 必填 | 说明 | 7844|----------------|-------------------------------------|-----|-----------------| 7845| preconfigType | [PreconfigType](#preconfigtype12) | 是 | 指定配置预期分辨率。 | 7846| preconfigRatio | [PreconfigRatio](#preconfigratio12) | 否 | 可选画幅比例,默认为4:3。 | 7847 7848**返回值:** 7849 7850| 类型 | 说明 | 7851|---------|-----------------------------------------| 7852| boolean | true: 支持指定预配值类型。<br/>false: 不支持指定预配值类型。 | 7853 7854**错误码:** 7855 7856以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 7857 7858| 错误码ID | 错误信息 | 7859|---------|-----------------------------| 7860| 7400201 | Camera service fatal error. | 7861 7862**示例:** 7863 7864```ts 7865function testCanPreconfig(photoSession: camera.PhotoSession, preconfigType: camera.PreconfigType, 7866 preconfigRatio: camera.PreconfigRatio): void { 7867 try { 7868 let result = photoSession.canPreconfig(preconfigType, preconfigRatio); 7869 console.info(`canPreconfig ${preconfigType} ${preconfigRatio} result is : ${result}`); 7870 } catch (error) { 7871 let err = error as BusinessError; 7872 console.error(`The canPreconfig call failed. error code: ${err.code}`); 7873 } 7874} 7875``` 7876 7877### preconfig<sup>12+</sup> 7878 7879preconfig(preconfigType: PreconfigType, preconfigRatio?: PreconfigRatio): void 7880 7881对当前Session进行预配置。 7882 7883**系统能力:** SystemCapability.Multimedia.Camera.Core 7884 7885**参数:** 7886 7887| 参数名 | 类型 | 必填 | 说明 | 7888|----------------|-------------------------------------|-----|-----------------| 7889| preconfigType | [PreconfigType](#preconfigtype12) | 是 | 指定配置预期分辨率。 | 7890| preconfigRatio | [PreconfigRatio](#preconfigratio12) | 否 | 可选画幅比例,默认为4:3。 | 7891 7892**错误码:** 7893 7894以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 7895 7896| 错误码ID | 错误信息 | 7897|---------|-----------------------------| 7898| 7400201 | Camera service fatal error. | 7899 7900**示例:** 7901 7902```ts 7903function testPreconfig(photoSession: camera.PhotoSession, preconfigType: camera.PreconfigType, 7904 preconfigRatio: camera.PreconfigRatio): void { 7905 try { 7906 photoSession.preconfig(preconfigType, preconfigRatio); 7907 console.info(`preconfig ${preconfigType} ${preconfigRatio} success`); 7908 } catch (error) { 7909 let err = error as BusinessError; 7910 console.error(`The preconfig call failed. error code: ${err.code}`); 7911 } 7912} 7913``` 7914 7915### on('error')<sup>11+</sup> 7916 7917on(type: 'error', callback: ErrorCallback): void 7918 7919监听普通拍照会话的错误事件,通过注册回调函数获取结果。使用callback异步回调。 7920 7921> **说明:** 7922> 7923> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 7924 7925**系统能力:** SystemCapability.Multimedia.Camera.Core 7926 7927**参数:** 7928 7929| 参数名 | 类型 | 必填 | 说明 | 7930| -------- | ----------------------------------------------------------- | ---- | ------------------------------ | 7931| type | string | 是 | 监听事件,固定为'error',session创建成功之后可监听该接口。session调用相关接口出现错误时会触发该事件,比如调用[beginConfig](#beginconfig11),[commitConfig](#commitconfig11-1),[addInput](#addinput11)等接口发生错误时返回错误信息。 | 7932| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback)| 是 | 回调函数,用于获取错误信息。返回错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 7933 7934**示例:** 7935 7936```ts 7937import { BusinessError } from '@kit.BasicServicesKit'; 7938 7939function callback(err: BusinessError): void { 7940 console.error(`Photo session error code: ${err.code}`); 7941} 7942 7943function registerSessionError(photoSession: camera.PhotoSession): void { 7944 photoSession.on('error', callback); 7945} 7946``` 7947 7948### off('error')<sup>11+</sup> 7949 7950off(type: 'error', callback?: ErrorCallback): void 7951 7952注销监听普通拍照会话的错误事件,通过注册回调函数获取结果。 7953 7954**系统能力:** SystemCapability.Multimedia.Camera.Core 7955 7956**参数:** 7957 7958| 参数名 | 类型 | 必填 | 说明 | 7959| -------- | -------------------------------- | ---- | ------------------------------ | 7960| type | string | 是 | 监听事件,固定为'error',session创建成功之后可监听该接口。 | 7961| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback)| 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 7962 7963**示例:** 7964 7965```ts 7966function unregisterSessionError(photoSession: camera.PhotoSession): void { 7967 photoSession.off('error'); 7968} 7969``` 7970 7971### on('focusStateChange')<sup>11+</sup> 7972 7973on(type: 'focusStateChange', callback: AsyncCallback\<FocusState\>): void 7974 7975监听相机聚焦的状态变化,通过注册回调函数获取结果。使用callback异步回调。 7976 7977> **说明:** 7978> 7979> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 7980 7981**系统能力:** SystemCapability.Multimedia.Camera.Core 7982 7983**参数:** 7984 7985| 参数名 | 类型 | 必填 | 说明 | 7986| -------- | ---------------- | ---- | ------------------------ | 7987| type | string | 是 | 监听事件,固定为'focusStateChange',session创建成功可监听。仅当自动对焦模式时,且相机对焦状态发生改变时可触发该事件。 | 7988| callback | AsyncCallback\<[FocusState](#focusstate)\> | 是 | 回调函数,用于获取当前对焦状态。 | 7989 7990**示例:** 7991 7992```ts 7993import { BusinessError } from '@kit.BasicServicesKit'; 7994 7995function callback(err: BusinessError, focusState: camera.FocusState): void { 7996 if (err !== undefined && err.code !== 0) { 7997 console.error(`Callback Error, errorCode: ${err.code}`); 7998 return; 7999 } 8000 console.info(`Focus state: ${focusState}`); 8001} 8002 8003function registerFocusStateChange(photoSession: camera.PhotoSession): void { 8004 photoSession.on('focusStateChange', callback); 8005} 8006``` 8007 8008### off('focusStateChange')<sup>11+</sup> 8009 8010off(type: 'focusStateChange', callback?: AsyncCallback\<FocusState\>): void 8011 8012注销监听相机聚焦的状态变化。 8013 8014**系统能力:** SystemCapability.Multimedia.Camera.Core 8015 8016**参数:** 8017 8018| 参数名 | 类型 | 必填 | 说明 | 8019| -------- | ----------------------------------------- | ---- | ------------------------ | 8020| type | string | 是 | 监听事件,固定为'focusStateChange',session创建成功可监听。 | 8021| callback | AsyncCallback\<[FocusState](#focusstate)\> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 8022 8023**示例:** 8024 8025```ts 8026function unregisterFocusStateChange(photoSession: camera.PhotoSession): void { 8027 photoSession.off('focusStateChange'); 8028} 8029``` 8030 8031### on('smoothZoomInfoAvailable')<sup>11+</sup> 8032 8033on(type: 'smoothZoomInfoAvailable', callback: AsyncCallback\<SmoothZoomInfo\>): void 8034 8035监听相机平滑变焦的状态变化,通过注册回调函数获取结果。使用callback异步回调。 8036 8037> **说明:** 8038> 8039> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 8040 8041**系统能力:** SystemCapability.Multimedia.Camera.Core 8042 8043**参数:** 8044 8045| 参数名 | 类型 | 必填 | 说明 | 8046| -------- | ----------------------- | ---- | ------------------------ | 8047| type | string | 是 | 监听事件,固定为'smoothZoomInfoAvailable',session创建成功可监听。| 8048| callback | AsyncCallback\<[SmoothZoomInfo](#smoothzoominfo11)\> | 是 | 回调函数,用于获取当前平滑变焦状态。 | 8049 8050**示例:** 8051 8052```ts 8053import { BusinessError } from '@kit.BasicServicesKit'; 8054 8055function callback(err: BusinessError, smoothZoomInfo: camera.SmoothZoomInfo): void { 8056 if (err !== undefined && err.code !== 0) { 8057 console.error(`Callback Error, errorCode: ${err.code}`); 8058 return; 8059 } 8060 console.info(`The duration of smooth zoom: ${smoothZoomInfo.duration}`); 8061} 8062 8063function registerSmoothZoomInfo(photoSession: camera.PhotoSession): void { 8064 photoSession.on('smoothZoomInfoAvailable', callback); 8065} 8066``` 8067 8068### off('smoothZoomInfoAvailable')<sup>11+</sup> 8069 8070off(type: 'smoothZoomInfoAvailable', callback?: AsyncCallback\<SmoothZoomInfo\>): void 8071 8072注销监听相机平滑变焦的状态变化。 8073 8074**系统能力:** SystemCapability.Multimedia.Camera.Core 8075 8076**参数:** 8077 8078| 参数名 | 类型 | 必填 | 说明 | 8079| -------- | ----------------------------------------- | ---- | ------------------------ | 8080| type | string | 是 | 监听事件,固定为'smoothZoomInfoAvailable',session创建成功可监听。| 8081| callback | AsyncCallback\<[SmoothZoomInfo](#smoothzoominfo11)\> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 8082 8083**示例:** 8084 8085```ts 8086function unregisterSmoothZoomInfo(photoSession: camera.PhotoSession): void { 8087 photoSession.off('smoothZoomInfoAvailable'); 8088} 8089``` 8090 8091## VideoSession<sup>11+</sup> 8092 8093VideoSession extends [Session](#session11), [Flash](#flash11), [AutoExposure](#autoexposure11), [Focus](#focus11), [Zoom](#zoom11), [Stabilization](#stabilization11), [ColorManagement](#colormanagement12) 8094 8095普通录像模式会话类,提供了对闪光灯、曝光、对焦、变焦、视频防抖、色彩空间的操作。 8096 8097> **说明:** 8098> 8099> 默认的视频录制模式,适用于一般场景。支持720P、1080p等多种分辨率的录制,可选择不同帧率(如30fps、60fps)。 8100 8101### canPreconfig<sup>12+</sup> 8102 8103canPreconfig(preconfigType: PreconfigType, preconfigRatio?: PreconfigRatio): boolean 8104 8105查询当前Session是否支持指定的与配置类型。 8106 8107**系统能力:** SystemCapability.Multimedia.Camera.Core 8108 8109**参数:** 8110 8111| 参数名 | 类型 | 必填 | 说明 | 8112|----------------|-------------------------------------|-----|-----------------| 8113| preconfigType | [PreconfigType](#preconfigtype12) | 是 | 指定配置预期分辨率。 | 8114| preconfigRatio | [PreconfigRatio](#preconfigratio12) | 否 | 可选画幅比例,默认为16:9。 | 8115 8116**返回值:** 8117 8118| 类型 | 说明 | 8119|---------|-----------------------------------------| 8120| boolean | true: 支持指定预配值类型。<br/>false: 不支持指定预配值类型。 | 8121 8122**错误码:** 8123 8124以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 8125 8126| 错误码ID | 错误信息 | 8127|---------|-----------------------------| 8128| 7400201 | Camera service fatal error. | 8129 8130**示例:** 8131 8132```ts 8133function testCanPreconfig(videoSession: camera.VideoSession, preconfigType: camera.PreconfigType, 8134 preconfigRatio: camera.PreconfigRatio): void { 8135 try { 8136 let result = videoSession.canPreconfig(preconfigType, preconfigRatio); 8137 console.info(`canPreconfig ${preconfigType} ${preconfigRatio} result is : ${result}`); 8138 } catch (error) { 8139 let err = error as BusinessError; 8140 console.error(`The canPreconfig call failed. error code: ${err.code}`); 8141 } 8142} 8143``` 8144 8145### preconfig<sup>12+</sup> 8146 8147preconfig(preconfigType: PreconfigType, preconfigRatio?: PreconfigRatio): void 8148 8149对当前Session进行预配置。 8150 8151**系统能力:** SystemCapability.Multimedia.Camera.Core 8152 8153**参数:** 8154 8155| 参数名 | 类型 | 必填 | 说明 | 8156|----------------|-------------------------------------|-----|-----------------| 8157| preconfigType | [PreconfigType](#preconfigtype12) | 是 | 指定配置预期分辨率。 | 8158| preconfigRatio | [PreconfigRatio](#preconfigratio12) | 否 | 可选画幅比例,默认为16:9。 | 8159 8160**错误码:** 8161 8162以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 8163 8164| 错误码ID | 错误信息 | 8165|---------|-----------------------------| 8166| 7400201 | Camera service fatal error. | 8167 8168**示例:** 8169 8170```ts 8171function testPreconfig(videoSession: camera.VideoSession, preconfigType: camera.PreconfigType, 8172 preconfigRatio: camera.PreconfigRatio): void { 8173 try { 8174 videoSession.preconfig(preconfigType, preconfigRatio); 8175 console.info(`preconfig ${preconfigType} ${preconfigRatio} success`); 8176 } catch (error) { 8177 let err = error as BusinessError; 8178 console.error(`The preconfig call failed. error code: ${err.code}`); 8179 } 8180} 8181``` 8182 8183### on('error')<sup>11+</sup> 8184 8185on(type: 'error', callback: ErrorCallback): void 8186 8187监听普通录像会话的错误事件,通过注册回调函数获取结果。使用callback异步回调。 8188 8189> **说明:** 8190> 8191> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 8192 8193**系统能力:** SystemCapability.Multimedia.Camera.Core 8194 8195**参数:** 8196 8197| 参数名 | 类型 | 必填 | 说明 | 8198| -------- | ------------------ | ---- | ------------------------------ | 8199| type | string | 是 | 监听事件,固定为'error',session创建成功之后可监听该接口。session调用相关接口出现错误时会触发该事件,比如调用[beginConfig](#beginconfig11),[commitConfig](#commitconfig11-1),[addInput](#addinput11)等接口发生错误时返回错误信息。 | 8200| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | 是 | 回调函数,用于获取错误信息。返回错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 8201 8202**示例:** 8203 8204```ts 8205import { BusinessError } from '@kit.BasicServicesKit'; 8206 8207function callback(err: BusinessError): void { 8208 console.error(`Video session error code: ${err.code}`); 8209} 8210 8211function registerSessionError(videoSession: camera.VideoSession): void { 8212 videoSession.on('error', callback); 8213} 8214``` 8215 8216### off('error')<sup>11+</sup> 8217 8218off(type: 'error', callback?: ErrorCallback): void 8219 8220注销监听普通录像会话的错误事件,通过注册回调函数获取结果。 8221 8222**系统能力:** SystemCapability.Multimedia.Camera.Core 8223 8224**参数:** 8225 8226| 参数名 | 类型 | 必填 | 说明 | 8227| -------- | --------------------------- | ---- | ------------------------------ | 8228| type | string | 是 | 监听事件,固定为'error',session创建成功之后可监听该接口。 | 8229| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback)| 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 8230 8231**示例:** 8232 8233```ts 8234function unregisterSessionError(videoSession: camera.VideoSession): void { 8235 videoSession.off('error'); 8236} 8237``` 8238 8239### on('focusStateChange')<sup>11+</sup> 8240 8241on(type: 'focusStateChange', callback: AsyncCallback\<FocusState\>): void 8242 8243监听相机聚焦的状态变化,通过注册回调函数获取结果。使用callback异步回调。 8244 8245> **说明:** 8246> 8247> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 8248 8249**系统能力:** SystemCapability.Multimedia.Camera.Core 8250 8251**参数:** 8252 8253| 参数名 | 类型 | 必填 | 说明 | 8254| -------- | ---------------- | ---- | ------------------------ | 8255| type | string | 是 | 监听事件,固定为'focusStateChange',session创建成功可监听。仅当自动对焦模式时,且相机对焦状态发生改变时可触发该事件。 | 8256| callback | AsyncCallback\<[FocusState](#focusstate)\> | 是 | 回调函数,用于获取当前对焦状态。 | 8257 8258**示例:** 8259 8260```ts 8261import { BusinessError } from '@kit.BasicServicesKit'; 8262 8263function callback(err: BusinessError, focusState: camera.FocusState): void { 8264 if (err !== undefined && err.code !== 0) { 8265 console.error(`Callback Error, errorCode: ${err.code}`); 8266 return; 8267 } 8268 console.info(`Focus state: ${focusState}`); 8269} 8270 8271function registerFocusStateChange(videoSession: camera.VideoSession): void { 8272 videoSession.on('focusStateChange', callback); 8273} 8274``` 8275 8276### off('focusStateChange')<sup>11+</sup> 8277 8278off(type: 'focusStateChange', callback?: AsyncCallback\<FocusState\>): void 8279 8280注销监听相机聚焦的状态变化。 8281 8282**系统能力:** SystemCapability.Multimedia.Camera.Core 8283 8284**参数:** 8285 8286| 参数名 | 类型 | 必填 | 说明 | 8287| -------- | ----------------------------------------- | ---- | ------------------------ | 8288| type | string | 是 | 监听事件,固定为'focusStateChange',session创建成功可监听。 | 8289| callback | AsyncCallback\<[FocusState](#focusstate)\> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 8290 8291**示例:** 8292 8293```ts 8294function unregisterFocusStateChange(videoSession: camera.VideoSession): void { 8295 videoSession.off('focusStateChange'); 8296} 8297``` 8298 8299### on('smoothZoomInfoAvailable')<sup>11+</sup> 8300 8301on(type: 'smoothZoomInfoAvailable', callback: AsyncCallback\<SmoothZoomInfo\>): void 8302 8303监听相机平滑变焦的状态变化,通过注册回调函数获取结果。使用callback异步回调。 8304 8305> **说明:** 8306> 8307> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 8308 8309**系统能力:** SystemCapability.Multimedia.Camera.Core 8310 8311**参数:** 8312 8313| 参数名 | 类型 | 必填 | 说明 | 8314| -------- | ----------------------- | ---- | ------------------------ | 8315| type | string | 是 | 监听事件,固定为'smoothZoomInfoAvailable',session创建成功可监听。| 8316| callback | AsyncCallback\<[SmoothZoomInfo](#smoothzoominfo11)\> | 是 | 回调函数,用于获取当前平滑变焦状态。 | 8317 8318**示例:** 8319 8320```ts 8321import { BusinessError } from '@kit.BasicServicesKit'; 8322 8323function callback(err: BusinessError, smoothZoomInfo: camera.SmoothZoomInfo): void { 8324 if (err !== undefined && err.code !== 0) { 8325 console.error(`Callback Error, errorCode: ${err.code}`); 8326 return; 8327 } 8328 console.info(`The duration of smooth zoom: ${smoothZoomInfo.duration}`); 8329} 8330 8331function registerSmoothZoomInfo(videoSession: camera.VideoSession): void { 8332 videoSession.on('smoothZoomInfoAvailable', callback); 8333} 8334``` 8335 8336### off('smoothZoomInfoAvailable')<sup>11+</sup> 8337 8338off(type: 'smoothZoomInfoAvailable', callback?: AsyncCallback\<SmoothZoomInfo\>): void 8339 8340注销监听相机平滑变焦的状态变化。 8341 8342**系统能力:** SystemCapability.Multimedia.Camera.Core 8343 8344**参数:** 8345 8346| 参数名 | 类型 | 必填 | 说明 | 8347| -------- | ----------------------------------------- | ---- | ------------------------ | 8348| type | string | 是 | 监听事件,固定为'smoothZoomInfoAvailable',session创建成功可监听。| 8349| callback | AsyncCallback\<[SmoothZoomInfo](#smoothzoominfo11)\> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 8350 8351**示例:** 8352 8353```ts 8354function unregisterSmoothZoomInfo(videoSession: camera.VideoSession): void { 8355 videoSession.off('smoothZoomInfoAvailable'); 8356} 8357``` 8358 8359## SecureSession<sup>12+</sup> 8360 8361SecureSession extends [Session](#session11), [Flash](#flash11), [AutoExposure](#autoexposure11), [Focus](#focus11), [Zoom](#zoom11) 8362 8363安全模式会话类,提供了对闪光灯、曝光、对焦、变焦的操作。 8364 8365> **说明:** 8366> 8367> 通过[createSession](#createsession11)接口传入[SceneMode](#scenemode11)为SECURE_PHOTO模式创建一个安全模式的会话。该模式开放给人脸识别、银行等有安全诉求的应用,需要结合安全TA使用,支持同时出普通预览流和安全流的业务场景。 8368> 安全TA:可用于图片处理,它具备验证服务器下发数据的验签能力、图片签名、解析及组装tlv逻辑的能力,还具备密钥读取、创建及操作能力。 8369 8370### addSecureOutput<sup>12+</sup> 8371 8372addSecureOutput(previewOutput: PreviewOutput): void 8373 8374把其中一条[PreviewOutput](#previewoutput)标记成安全输出。 8375 8376**系统能力:** SystemCapability.Multimedia.Camera.Core 8377 8378**参数:** 8379 8380| 参数名 | 类型 | 必填 | 说明 | 8381| ------------- | ------------------------------- | ---- |---------------| 8382| previewOutput | [PreviewOutput](#previewoutput) | 是 | 需要标记成安全输出的预览流,传参异常时,会返回错误码。 | 8383 8384**错误码:** 8385 8386以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 8387 8388| 错误码ID | 错误信息 | 8389| --------------- | --------------- | 8390| 7400101 | Parameter missing or parameter type incorrect. | 8391| 7400102 | Operation not allowed. | 8392| 7400103 | Session not config. | 8393 8394**示例:** 8395 8396```ts 8397import { BusinessError } from '@kit.BasicServicesKit'; 8398 8399function addSecureOutput(session: camera.SecureSession, previewOutput: camera.PreviewOutput): void { 8400 try { 8401 session.addSecureOutput(previewOutput); 8402 } catch (error) { 8403 // 失败返回错误码error.code并处理 8404 let err = error as BusinessError; 8405 console.error(`The addOutput call failed. error code: ${err.code}`); 8406 } 8407} 8408``` 8409### on('error')<sup>12+</sup> 8410 8411on(type: 'error', callback: ErrorCallback): void 8412 8413监听安全相机会话的错误事件,通过注册回调函数获取结果。使用callback异步回调。 8414 8415> **说明:** 8416> 8417> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 8418 8419**系统能力:** SystemCapability.Multimedia.Camera.Core 8420 8421**参数:** 8422 8423| 参数名 | 类型 | 必填 | 说明 | 8424| -------- | ------------------ | ---- | ------------------------------ | 8425| type | string | 是 | 监听事件,固定为'error',session创建成功之后可监听该接口。session调用相关接口出现错误时会触发该事件,比如调用[beginConfig](#beginconfig11),[commitConfig](#commitconfig11-1),[addInput](#addinput11)等接口发生错误时返回错误信息。 | 8426| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | 是 | 回调函数,用于获取错误信息。返回错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 8427 8428**示例:** 8429 8430```ts 8431import { BusinessError } from '@kit.BasicServicesKit'; 8432 8433function callback(err: BusinessError): void { 8434 console.error(`Video session error code: ${err.code}`); 8435} 8436 8437function registerSessionError(secureSession: camera.SecureSession): void { 8438 secureSession.on('error', callback); 8439} 8440``` 8441 8442### off('error')<sup>12+</sup> 8443 8444off(type: 'error', callback?: ErrorCallback): void 8445 8446注销监听安全相机会话的错误事件,通过注册回调函数获取结果。 8447 8448**系统能力:** SystemCapability.Multimedia.Camera.Core 8449 8450**参数:** 8451 8452| 参数名 | 类型 | 必填 | 说明 | 8453| -------- | --------------------------- | ---- | ------------------------------ | 8454| type | string | 是 | 监听事件,固定为'error',session创建成功之后可监听该接口。 | 8455| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback)| 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 8456 8457**示例:** 8458 8459```ts 8460function unregisterSessionError(secureSession: camera.SecureSession): void { 8461 secureSession.off('error'); 8462} 8463``` 8464 8465### on('focusStateChange')<sup>12+</sup> 8466 8467on(type: 'focusStateChange', callback: AsyncCallback\<FocusState\>): void 8468 8469监听相机聚焦的状态变化,通过注册回调函数获取结果。使用callback异步回调。 8470 8471> **说明:** 8472> 8473> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 8474 8475**系统能力:** SystemCapability.Multimedia.Camera.Core 8476 8477**参数:** 8478 8479| 参数名 | 类型 | 必填 | 说明 | 8480| -------- | ---------------- | ---- | ------------------------ | 8481| type | string | 是 | 监听事件,固定为'focusStateChange',session创建成功可监听。仅当自动对焦模式时,且相机对焦状态发生改变时可触发该事件。 | 8482| callback | AsyncCallback\<[FocusState](#focusstate)\> | 是 | 回调函数,用于获取当前对焦状态。 | 8483 8484**示例:** 8485 8486```ts 8487import { BusinessError } from '@kit.BasicServicesKit'; 8488 8489function callback(err: BusinessError, focusState: camera.FocusState): void { 8490 if (err !== undefined && err.code !== 0) { 8491 console.error(`Callback Error, errorCode: ${err.code}`); 8492 return; 8493 } 8494 console.info(`Focus state: ${focusState}`); 8495} 8496 8497function registerFocusStateChange(secureSession: camera.SecureSession): void { 8498 secureSession.on('focusStateChange', callback); 8499} 8500``` 8501 8502### off('focusStateChange')<sup>12+</sup> 8503 8504off(type: 'focusStateChange', callback?: AsyncCallback\<FocusState\>): void 8505 8506注销监听相机聚焦的状态变化。 8507 8508**系统能力:** SystemCapability.Multimedia.Camera.Core 8509 8510**参数:** 8511 8512| 参数名 | 类型 | 必填 | 说明 | 8513| -------- | ----------------------------------------- | ---- | ------------------------ | 8514| type | string | 是 | 监听事件,固定为'focusStateChange',session创建成功可监听。 | 8515| callback | AsyncCallback\<[FocusState](#focusstate)\> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 8516 8517**示例:** 8518 8519```ts 8520function unregisterFocusStateChange(secureSession: camera.SecureSession): void { 8521 secureSession.off('focusStateChange'); 8522} 8523```