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