1# @ohos.multimedia.camera (相机管理) 2<!--Kit: Camera Kit--> 3<!--Subsystem: Multimedia--> 4<!--Owner: @qano--> 5<!--SE: @leo_ysl--> 6<!--TSE: @xchaosioda--> 7 8本模块为开发者提供了一套简单易懂的相机服务接口。通过调用这些接口,开发者可以开发相机应用,访问和操作相机硬件,实现基础功能如预览、拍照和录像。此外,还可以通过接口组合完成更多操作,如控制闪光灯、曝光时间和对焦等。 9 10> **说明:** 11> 12> 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 13 14## 导入模块 15 16```ts 17import { camera } from '@kit.CameraKit'; 18``` 19 20## camera.getCameraManager 21 22getCameraManager(context: Context): CameraManager 23 24获取相机管理器实例,同步返回结果。 25 26**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 27 28**系统能力:** SystemCapability.Multimedia.Camera.Core 29 30**参数:** 31 32| 参数名 | 类型 | 必填 | 说明 | 33| -------- | ----------------------------------------------- | ---- | ---------------------------- | 34| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | 是 | 应用上下文。 | 35 36**返回值:** 37 38| 类型 | 说明 | 39| ----------------------------------------------- | ---------------------------- | 40| [CameraManager](#cameramanager) | 相机管理器。 | 41 42**错误码:** 43 44以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 45 46| 错误码ID | 错误信息 | 47| --------------- | --------------- | 48| 7400101 | Parameter missing or parameter type incorrect. | 49| 7400201 | Camera service fatal error. | 50 51**示例:** 52 53```ts 54import { common } from '@kit.AbilityKit'; 55import { BusinessError } from '@kit.BasicServicesKit'; 56 57function getCameraManager(context: common.BaseContext): camera.CameraManager | undefined { 58 let cameraManager: camera.CameraManager | undefined = undefined; 59 try { 60 cameraManager = camera.getCameraManager(context); 61 } catch (error) { 62 let err = error as BusinessError; 63 console.error(`The getCameraManager call failed. error code: ${err.code}`); 64 } 65 return cameraManager; 66} 67``` 68 69## CameraDevice 70 71相机设备信息。 72 73**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 74 75**系统能力:** SystemCapability.Multimedia.Camera.Core 76 77| 名称 | 类型 | 只读 | 可选 | 说明 | 78|---------------------------------|-------------------------------------| ---- |----|---------- | 79| cameraId | string | 是 | 否 | 相机ID。| 80| cameraPosition | [CameraPosition](#cameraposition) | 是 | 否 | 相机位置。 | 81| cameraType | [CameraType](#cameratype) | 是 | 否 | 相机类型。 | 82| connectionType | [ConnectionType](#connectiontype) | 是 | 否 | 相机连接类型。 | 83| cameraOrientation<sup>12+</sup> | number | 是 | 否 | 相机安装角度,不会随着屏幕旋转而改变,取值范围为0°-360°,单位:度。 | 84| hostDeviceName<sup>15+</sup> | string | 是 | 否 | 远端设备名称。 | 85| hostDeviceType<sup>15+</sup> | [HostDeviceType](#hostdevicetype15) | 是 | 否 | 远端设备类型。 | 86 87## CameraPosition 88 89枚举,相机位置。 90 91**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 92 93**系统能力:** SystemCapability.Multimedia.Camera.Core 94 95| 名称 | 值 | 说明 | 96| --------------------------- | ---- |-----------------------------------------------------------------| 97| CAMERA_POSITION_UNSPECIFIED | 0 | 相对于设备屏幕没有固定的朝向的相机。 | 98| CAMERA_POSITION_BACK | 1 | 后置相机。 | 99| CAMERA_POSITION_FRONT | 2 | 前置相机。 | 100| CAMERA_POSITION_FOLD_INNER<sup>(deprecated)</sup> | 3 | 折叠态相机。<br/> 从API version 11开始支持,从API version 12开始废弃。 | 101 102## CameraType 103 104枚举,相机类型。 105 106**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 107 108**系统能力:** SystemCapability.Multimedia.Camera.Core 109 110| 名称 | 值 | 说明 | 111| ----------------------- | ---- | -------------- | 112| CAMERA_TYPE_DEFAULT | 0 | 相机类型未指定。 | 113| CAMERA_TYPE_WIDE_ANGLE | 1 | 广角相机。 | 114| CAMERA_TYPE_ULTRA_WIDE | 2 | 超广角相机。 | 115| CAMERA_TYPE_TELEPHOTO | 3 | 长焦相机。 | 116| CAMERA_TYPE_TRUE_DEPTH | 4 | 带景深信息的相机。 | 117 118## ConnectionType 119 120枚举,相机连接类型。 121 122**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 123 124**系统能力:** SystemCapability.Multimedia.Camera.Core 125 126| 名称 | 值 | 说明 | 127| ---------------------------- | ---- | ------------- | 128| CAMERA_CONNECTION_BUILT_IN | 0 | 内置相机。 | 129| CAMERA_CONNECTION_USB_PLUGIN | 1 | USB连接的相机。 | 130| CAMERA_CONNECTION_REMOTE | 2 | 远程连接的相机。 | 131 132## HostDeviceType<sup>15+</sup> 133 134枚举,远端相机设备类型。 135 136**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 137 138**系统能力:** SystemCapability.Multimedia.Camera.Core 139 140| 名称 | 值 | 说明 | 141| ---------------------------- | ---- |---------| 142| UNKNOWN_TYPE | 0 | 未知设备类型。 | 143| PHONE | 0x0E | 手机设备。 | 144| TABLET | 0x11 | 平板设备。 | 145 146## CameraStatus 147 148枚举,相机状态。 149 150**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 151 152**系统能力:** SystemCapability.Multimedia.Camera.Core 153 154| 名称 | 值 | 说明 | 155| ------------------------- | ---- | ------------ | 156| CAMERA_STATUS_APPEAR | 0 | 新的相机出现。 | 157| CAMERA_STATUS_DISAPPEAR | 1 | 相机被移除。 | 158| CAMERA_STATUS_AVAILABLE | 2 | 相机可用。 | 159| CAMERA_STATUS_UNAVAILABLE | 3 | 相机不可用。 | 160 161## FoldStatus<sup>12+</sup> 162 163枚举,折叠机折叠状态。 164 165**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 166 167**系统能力:** SystemCapability.Multimedia.Camera.Core 168 169| 名称 | 值 | 说明 | 170| ------------------------- | ---- | ------------ | 171| NON_FOLDABLE | 0 | 表示当前设备不可折叠。 | 172| EXPANDED | 1 | 表示当前设备折叠状态为完全展开。 | 173| FOLDED | 2 | 表示当前设备折叠状态为折叠。 | 174 175## CameraStatusInfo 176 177相机管理器回调返回的接口实例,该实例表示相机状态信息。 178 179**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 180 181**系统能力:** SystemCapability.Multimedia.Camera.Core 182 183| 名称 | 类型 | 只读 | 可选 | 说明 | 184| ------ | ----------------------------- | --------- |------------ | ---------- | 185| camera | [CameraDevice](#cameradevice) | 否 | 否 | 相机信息。 | 186| status | [CameraStatus](#camerastatus) | 否 | 否 | 相机状态。 | 187 188## FoldStatusInfo<sup>12+</sup> 189 190相机管理器回调返回的接口实例,表示折叠机折叠状态信息。 191 192**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 193 194**系统能力:** SystemCapability.Multimedia.Camera.Core 195 196| 名称 | 类型 | 只读 | 可选 | 说明 | 197| ------ | ----------------------------- | --------- |------------ | ---------- | 198| supportedCameras | [Array<CameraDevice\>](#cameradevice) | 否 | 否 | 当前折叠状态所支持的相机信息列表。 | 199| foldStatus | [FoldStatus](#foldstatus12) | 否 | 否 | 折叠屏折叠状态。 | 200 201## Profile 202 203相机配置信息项。 204 205**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 206 207**系统能力:** SystemCapability.Multimedia.Camera.Core 208 209| 名称 | 类型 | 只读 | 可选 | 说明 | 210| -------- | ----------------------------- |---- | ---- | ------------- | 211| format | [CameraFormat](#cameraformat) | 是 | 否 | 输出格式。 | 212| size | [Size](#size) | 是 | 否 | 分辨率。<br>设置的是相机的分辨率宽度和高度,而非实际输出图像的宽度和高度。 | 213 214## FrameRateRange 215 216帧率范围。 217 218**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 219 220**系统能力:** SystemCapability.Multimedia.Camera.Core 221 222| 名称 | 类型 | 只读 | 可选 | 说明 | 223| -------- | ----------------------------- |----- |---| -------------- | 224| min | number | 是 | 否 | 最小帧率。 | 225| max | number | 是 | 否 | 最大帧率。 | 226 227## VideoProfile 228 229视频配置信息项,继承[Profile](#profile)。 230 231**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 232 233**系统能力:** SystemCapability.Multimedia.Camera.Core 234 235| 名称 | 类型 | 只读 | 可选 | 说明 | 236| ------------------------- | ----------------------------------------- | --- | ---- |----------- | 237| frameRateRange | [FrameRateRange](#frameraterange) | 是 | 否 | 帧率范围,单位:fps(frames per second)。 | 238 239## CameraOutputCapability 240 241相机输出能力项。 242 243**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 244 245**系统能力:** SystemCapability.Multimedia.Camera.Core 246 247| 名称 | 类型 | 只读 | 可选 | 说明 | 248| ----------------------------- | --------------------------------------------------- | ---- | ---- |-------------------| 249| previewProfiles | Array\<[Profile](#profile)\> | 是 | 否 | 支持的预览配置信息集合。 | 250| photoProfiles | Array\<[Profile](#profile)\> | 是 | 否 | 支持的拍照配置信息集合。 | 251| videoProfiles | Array\<[VideoProfile](#videoprofile)\> | 是 | 否 | 支持的录像配置信息集合。 | 252| supportedMetadataObjectTypes | Array\<[MetadataObjectType](#metadataobjecttype)\> | 是 | 否 | 支持的metadata流类型信息集合。 | 253 254## SceneMode<sup>11+</sup> 255 256枚举,相机模式。 257 258**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 259 260**系统能力:** SystemCapability.Multimedia.Camera.Core 261 262| 名称 | 值 | 说明 | 263|----------------------------|---------|---------------------------------------------| 264| NORMAL_PHOTO | 1 | 普通拍照模式。详情见[PhotoSession](#photosession11) | 265| NORMAL_VIDEO | 2 | 普通录像模式。详情见[VideoSession](#videosession11) | 266| SECURE_PHOTO<sup>12+</sup> | 12 | 安全相机模式。详情见[SecureSession](#securesession12) | 267 268## CameraErrorCode 269 270相机错误码。 271 272接口使用不正确以及on接口监听error状态返回。 273 274**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 275 276**系统能力:** SystemCapability.Multimedia.Camera.Core 277 278| 名称 | 值 | 说明 | 279| ------------------------- | ---- | ------------ | 280| INVALID_ARGUMENT | 7400101 | 参数缺失或者参数类型不对。 | 281| OPERATION_NOT_ALLOWED | 7400102 | 操作流程不对,不允许。 | 282| SESSION_NOT_CONFIG | 7400103 | session 未配置返回。 | 283| SESSION_NOT_RUNNING | 7400104 | session 未运行返回。 | 284| SESSION_CONFIG_LOCKED | 7400105 | session 配置已锁定返回。 | 285| DEVICE_SETTING_LOCKED | 7400106 | 设备设置已锁定返回。 | 286| CONFLICT_CAMERA | 7400107 | 设备重复打开返回。 | 287| DEVICE_DISABLED | 7400108 | 安全原因相机被禁用。 | 288| DEVICE_PREEMPTED | 7400109 | 相机被抢占导致无法使用。 | 289| UNRESOLVED_CONFLICTS_WITH_CURRENT_CONFIGURATIONS<sup>12+</sup> | 7400110 | 与当前配置存在冲突。 | 290| SERVICE_FATAL_ERROR | 7400201 | 相机服务错误返回。 | 291 292## CameraManager 293 294相机管理器类,使用前需要通过[getCameraManager](#cameragetcameramanager)接口获取相机管理实例。 295 296### getSupportedCameras 297 298getSupportedCameras(): Array\<CameraDevice\> 299 300获取支持的相机设备对象,同步返回结果。 301 302**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 303 304**系统能力:** SystemCapability.Multimedia.Camera.Core 305 306**返回值:** 307 308| 类型 | 说明 | 309| ----------------------------------------------- | ---------------------------- | 310| Array\<[CameraDevice](#cameradevice)> | 相机设备列表。 | 311 312**示例:** 313 314```ts 315import { BusinessError } from '@kit.BasicServicesKit'; 316 317function getSupportedCameras(cameraManager: camera.CameraManager): Array<camera.CameraDevice> { 318 let cameras: Array<camera.CameraDevice> = []; 319 try { 320 cameras = cameraManager.getSupportedCameras(); 321 } catch (error) { 322 let err = error as BusinessError; 323 console.error(`The getSupportedCameras call failed. error code: ${err.code}`); 324 } 325 return cameras; 326} 327``` 328 329### getSupportedSceneModes<sup>11+</sup> 330 331getSupportedSceneModes(camera: CameraDevice): Array\<SceneMode\> 332 333获取指定的相机设备对象支持的模式,同步返回结果。 334 335**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 336 337**系统能力:** SystemCapability.Multimedia.Camera.Core 338 339**参数:** 340 341| 参数名 | 类型 | 必填 | 说明 | 342| ------------ |--------------------------------------------------------------- | -- | -------------------------- | 343| camera | [CameraDevice](#cameradevice) | 是 | 相机设备,通过 [getSupportedCameras](#getsupportedcameras) 接口获取。传参异常时,会返回错误码。 | 344 345**返回值:** 346 347| 类型 | 说明 | 348| ----------------------------------------------- | ---------------------------- | 349| Array\<[SceneMode](#scenemode11)> | 相机支持的模式列表。 | 350 351**示例:** 352 353```ts 354import { BusinessError } from '@kit.BasicServicesKit'; 355 356function getSupportedSceneModes(cameraManager: camera.CameraManager, camera: camera.CameraDevice): Array<camera.SceneMode> { 357 let modes: Array<camera.SceneMode> = []; 358 try { 359 modes = cameraManager.getSupportedSceneModes(camera); 360 } catch (error) { 361 let err = error as BusinessError; 362 console.error(`The getSupportedSceneModes call failed. error code: ${err.code}`); 363 } 364 return modes; 365} 366``` 367 368### getSupportedOutputCapability<sup>(deprecated)</sup> 369 370getSupportedOutputCapability(camera: CameraDevice): CameraOutputCapability 371 372查询相机设备支持的输出能力,同步返回结果。 373 374> **说明:** 375> 从 API version 10开始支持,从API version 11开始废弃。建议使用[getSupportedOutputCapability](#getsupportedoutputcapability11)替代。 376 377**系统能力:** SystemCapability.Multimedia.Camera.Core 378 379**参数:** 380 381| 参数名 | 类型 | 必填 | 说明 | 382| ------------ |--------------------------------------------------------------- | -- | -------------------------- | 383| camera | [CameraDevice](#cameradevice) | 是 | 相机设备,通过 [getSupportedCameras](#getsupportedcameras) 接口获取。传参异常时,会返回错误码。 | 384 385**返回值:** 386 387| 类型 | 说明 | 388| ----------------------------------------------- | ---------------------------- | 389| [CameraOutputCapability](#cameraoutputcapability) | 相机输出能力。 | 390 391**示例:** 392 393```ts 394function getSupportedOutputCapability(camera: camera.CameraDevice, cameraManager: camera.CameraManager): camera.CameraOutputCapability { 395 let cameraOutputCapability: camera.CameraOutputCapability = cameraManager.getSupportedOutputCapability(camera); 396 return cameraOutputCapability; 397} 398``` 399 400### getSupportedOutputCapability<sup>11+</sup> 401 402getSupportedOutputCapability(camera: CameraDevice, mode: SceneMode): CameraOutputCapability 403 404查询相机设备在指定模式下支持的输出能力,同步返回结果。 405 406**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 407 408**系统能力:** SystemCapability.Multimedia.Camera.Core 409 410**参数:** 411 412| 参数名 | 类型 | 必填 | 说明 | 413| ------------ |--------------------------------------------------------------- | -- | -------------------------- | 414| camera | [CameraDevice](#cameradevice) | 是 | 相机设备,通过 [getSupportedCameras](#getsupportedcameras) 接口获取。 | 415| mode | [SceneMode](#scenemode11) | 是 | 相机模式,通过 [getSupportedSceneModes](#getsupportedscenemodes11) 接口获取。 | 416 417**返回值:** 418 419| 类型 | 说明 | 420| ----------------------------------------------- | ---------------------------- | 421| [CameraOutputCapability](#cameraoutputcapability) | 相机输出能力。 | 422 423**示例:** 424 425```ts 426function getSupportedOutputCapability(camera: camera.CameraDevice, cameraManager: camera.CameraManager, sceneMode: camera.SceneMode): camera.CameraOutputCapability { 427 let cameraOutputCapability: camera.CameraOutputCapability = cameraManager.getSupportedOutputCapability(camera, sceneMode); 428 return cameraOutputCapability; 429} 430``` 431 432### isCameraMuted 433 434isCameraMuted(): boolean 435 436查询当前相机是否禁用。 437 438**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 439 440**系统能力:** SystemCapability.Multimedia.Camera.Core 441 442**返回值:** 443 444| 类型 | 说明 | 445| ---------- | -------------------------------------------- | 446| boolean | 返回true表示相机被禁用,返回false表示相机未被禁用。 | 447 448**示例:** 449 450```ts 451function isCameraMuted(cameraManager: camera.CameraManager): boolean { 452 let isMuted: boolean = cameraManager.isCameraMuted(); 453 return isMuted; 454} 455``` 456 457### createCameraInput 458 459createCameraInput(camera: CameraDevice): CameraInput 460 461使用CameraDevice对象创建CameraInput实例,同步返回结果。 462 463该接口使用前首先通过[getSupportedCameras](#getsupportedcameras)接口查询当前设备支持的相机设备信息列表,开发者需要根据具体使用场景选择符合需求的相机设备,然后使用该接口创建CameraInput实例。 464 465**需要权限:** ohos.permission.CAMERA 466 467**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 468 469**系统能力:** SystemCapability.Multimedia.Camera.Core 470 471**参数:** 472 473| 参数名 | 类型 | 必填 | 说明 | 474| -------- | ------------------------------------------- | ---- |--------------------------------------------------| 475| camera | [CameraDevice](#cameradevice) | 是 | CameraDevice对象,通过 [getSupportedCameras](#getsupportedcameras) 接口获取。 | 476 477**返回值:** 478 479| 类型 | 说明 | 480| ---------- | ----------------------------- | 481| [CameraInput](#camerainput) | 返回CameraInput实例。接口调用失败会返回相应错误码,错误码类型为[CameraErrorCode](#cameraerrorcode)。 | 482 483**错误码:** 484 485以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 486 487| 错误码ID | 错误信息 | 488| --------------- | --------------- | 489| 7400101 | Parameter missing or parameter type incorrect. | 490| 7400102 | Operation not allowed. | 491| 7400201 | Camera service fatal error. | 492 493**示例:** 494 495```ts 496import { BusinessError } from '@kit.BasicServicesKit'; 497 498function createCameraInput(camera: camera.CameraDevice, cameraManager: camera.CameraManager): camera.CameraInput | undefined { 499 let cameraInput: camera.CameraInput | undefined = undefined; 500 try { 501 cameraInput = cameraManager.createCameraInput(camera); 502 } catch (error) { 503 // 失败返回错误码error.code并处理。 504 let err = error as BusinessError; 505 console.error(`The createCameraInput call failed. error code: ${err.code}`); 506 } 507 return cameraInput; 508} 509``` 510 511### createCameraInput 512 513createCameraInput(position: CameraPosition, type: CameraType): CameraInput 514 515根据相机位置和类型创建CameraInput实例,同步返回结果。 516 517该接口使用前需要开发者根据应用具体使用场景自行指定相机位置和类型,例如打开前置相机进入自拍功能。 518 519**需要权限:** ohos.permission.CAMERA 520 521**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 522 523**系统能力:** SystemCapability.Multimedia.Camera.Core 524 525**参数:** 526 527| 参数名 | 类型 | 必填 | 说明 | 528| -------- | ------------------------------------------- | ---- | --------------------------------- | 529| position | [CameraPosition](#cameraposition) | 是 | 相机位置,首先通过 [getSupportedCameras](#getsupportedcameras) 接口获取支持的相机设备对象,然后根据返回的相机设备对象获取设备位置信息。 | 530| type | [CameraType](#cameratype) | 是 | 相机类型,首先通过 [getSupportedCameras](#getsupportedcameras) 接口获取支持的相机设备对象,然后根据返回的相机设备对象获取设备类型信息。 | 531 532**返回值:** 533 534| 类型 | 说明 | 535| ---------- | ----------------------------- | 536| [CameraInput](#camerainput) | 返回CameraInput实例。接口调用失败会返回相应错误码,错误码类型为[CameraErrorCode](#cameraerrorcode)。 | 537 538**错误码:** 539 540以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 541 542| 错误码ID | 错误信息 | 543| --------------- | --------------- | 544| 7400101 | Parameter missing or parameter type incorrect. | 545| 7400102 | Operation not allowed. | 546| 7400201 | Camera service fatal error. | 547 548**示例:** 549 550```ts 551import { BusinessError } from '@kit.BasicServicesKit'; 552 553function createCameraInput(camera: camera.CameraDevice, cameraManager: camera.CameraManager): camera.CameraInput | undefined { 554 let position: camera.CameraPosition = camera.cameraPosition; 555 let type: camera.CameraType = camera.cameraType; 556 let cameraInput: camera.CameraInput | undefined = undefined; 557 try { 558 cameraInput = cameraManager.createCameraInput(position, type); 559 } catch (error) { 560 // 失败返回错误码error.code并处理。 561 let err = error as BusinessError; 562 console.error(`The createCameraInput call failed. error code: ${err.code}`); 563 } 564 return cameraInput; 565} 566``` 567 568### createPreviewOutput 569 570createPreviewOutput(profile: Profile, surfaceId: string): PreviewOutput 571 572创建预览输出对象,同步返回结果。 573 574**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 575 576**系统能力:** SystemCapability.Multimedia.Camera.Core 577 578**参数:** 579 580| 参数名 | 类型 | 必填 | 说明 | 581| -------- | ----------------------------------------------- | ---- | ------------------------------- | 582| profile | [Profile](#profile) | 是 | 支持的预览配置信息,通过[getSupportedOutputCapability](#getsupportedoutputcapability11)接口获取。| 583| surfaceId| string | 是 | 从[XComponent](../apis-arkui/arkui-ts/ts-basic-components-xcomponent.md)或者[ImageReceiver](../apis-image-kit/arkts-apis-image-ImageReceiver.md)组件获取的surfaceId。| 584 585**返回值:** 586 587| 类型 | 说明 | 588| ---------- | ----------------------------- | 589| [PreviewOutput](#previewoutput) | PreviewOutput实例。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 590 591**错误码:** 592 593以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 594 595| 错误码ID | 错误信息 | 596| --------------- | --------------- | 597| 7400101 | Parameter missing or parameter type incorrect. | 598| 7400201 | Camera service fatal error. | 599 600**示例:** 601 602```ts 603import { BusinessError } from '@kit.BasicServicesKit'; 604 605function createPreviewOutput(cameraOutputCapability: camera.CameraOutputCapability, cameraManager: camera.CameraManager, surfaceId: string): camera.PreviewOutput | undefined { 606 let profile: camera.Profile = cameraOutputCapability.previewProfiles[0]; 607 let previewOutput: camera.PreviewOutput | undefined = undefined; 608 try { 609 previewOutput = cameraManager.createPreviewOutput(profile, surfaceId); 610 } catch (error) { 611 // 失败返回错误码error.code并处理。 612 let err = error as BusinessError; 613 console.error(`The createPreviewOutput call failed. error code: ${err.code}`); 614 } 615 return previewOutput; 616} 617``` 618 619### createPreviewOutput<sup>12+</sup> 620 621createPreviewOutput(surfaceId: string): PreviewOutput 622 623创建无配置信息的预览输出对象,同步返回结果。该接口需配合[preconfig](#preconfig12)一起使用。 624 625**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 626 627**系统能力:** SystemCapability.Multimedia.Camera.Core 628 629**参数:** 630 631| 参数名 | 类型 | 必填 | 说明 | 632| -------- | ----------------------------------------------- | ---- | ------------------------------- | 633| surfaceId| string | 是 | 从[XComponent](../apis-arkui/arkui-ts/ts-basic-components-xcomponent.md)或者[ImageReceiver](../apis-image-kit/arkts-apis-image-ImageReceiver.md)组件获取的surfaceId。| 634 635**返回值:** 636 637| 类型 | 说明 | 638| ---------- | ----------------------------- | 639| [PreviewOutput](#previewoutput) | PreviewOutput实例。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 640 641**错误码:** 642 643以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 644 645| 错误码ID | 错误信息 | 646|---------|------------------------------------------------| 647| 7400101 | Parameter missing or parameter type incorrect. | 648| 7400201 | Camera service fatal error. | 649 650**示例:** 651 652```ts 653import { BusinessError } from '@kit.BasicServicesKit'; 654 655function createPreviewOutput(cameraManager: camera.CameraManager, surfaceId: string): camera.PreviewOutput | undefined { 656 let previewOutput: camera.PreviewOutput | undefined = undefined; 657 try { 658 previewOutput = cameraManager.createPreviewOutput(surfaceId); 659 } catch (error) { 660 // 失败返回错误码error.code并处理。 661 let err = error as BusinessError; 662 console.error(`The createPreviewOutput call failed. error code: ${err.code}`); 663 } 664 return previewOutput; 665} 666``` 667 668### createPhotoOutput<sup>(deprecated)</sup> 669 670createPhotoOutput(profile: Profile, surfaceId: string): PhotoOutput 671 672创建拍照输出对象,同步返回结果。 673 674> **说明:** 675> 从 API version 10开始支持,从API version 11开始废弃。建议使用[createPhotoOutput](#createphotooutput11)替代。 676 677**系统能力:** SystemCapability.Multimedia.Camera.Core 678 679**参数:** 680 681| 参数名 | 类型 | 必填 | 说明 | 682| -------- | ------------------------------------------- | ---- | ----------------------------------- | 683| profile | [Profile](#profile) | 是 | 支持的拍照配置信息,通过[getSupportedOutputCapability](#getsupportedoutputcapability11)接口获取。| 684| surfaceId| string | 是 | 从[ImageReceiver](../apis-image-kit/arkts-apis-image-ImageReceiver.md)获取的surfaceId。| 685 686**返回值:** 687 688| 类型 | 说明 | 689| ---------- | ----------------------------- | 690| [PhotoOutput](#photooutput) | PhotoOutput实例。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 691 692**错误码:** 693 694以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 695 696| 错误码ID | 错误信息 | 697| --------------- | --------------- | 698| 7400101 | Parameter missing or parameter type incorrect. | 699 700```ts 701import { BusinessError } from '@kit.BasicServicesKit'; 702 703function createPhotoOutput(cameraOutputCapability: camera.CameraOutputCapability, cameraManager: camera.CameraManager, surfaceId: string): camera.PhotoOutput | undefined { 704 let profile: camera.Profile = cameraOutputCapability.photoProfiles[0]; 705 let photoOutput: camera.PhotoOutput | undefined = undefined; 706 try { 707 photoOutput = cameraManager.createPhotoOutput(profile, surfaceId); 708 } catch (error) { 709 // 失败返回错误码error.code并处理。 710 let err = error as BusinessError; 711 console.error(`The createPhotoOutput call failed. error code: ${err.code}`); 712 } 713 return photoOutput; 714} 715``` 716 717### createPhotoOutput<sup>11+</sup> 718 719createPhotoOutput(profile?: Profile): PhotoOutput 720 721创建拍照输出对象,同步返回结果。 722 723**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 724 725**系统能力:** SystemCapability.Multimedia.Camera.Core 726 727**参数:** 728 729| 参数名 | 类型 | 必填 | 说明 | 730| -------- | ------------------------------------------- |----| ----------------------------------- | 731| profile | [Profile](#profile) | 否 | 支持的拍照配置信息,通过[getSupportedOutputCapability](#getsupportedoutputcapability11)接口获取。<br>API 11时,该参数必填;从API version 12开始,如果使用[preconfig](#preconfig12)进行预配置,传入profile参数会覆盖preconfig的预配置参数。| 732 733**返回值:** 734 735| 类型 | 说明 | 736| ---------- | ----------------------------- | 737| [PhotoOutput](#photooutput) | PhotoOutput实例。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 738 739**错误码:** 740 741以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 742 743| 错误码ID | 错误信息 | 744|----------|------------------------------------------------| 745| 7400101 | Parameter missing or parameter type incorrect. | 746| 7400201 | Camera service fatal error. | 747 748**示例:** 749 750```ts 751import { BusinessError } from '@kit.BasicServicesKit'; 752 753function createPhotoOutput(cameraOutputCapability: camera.CameraOutputCapability, cameraManager: camera.CameraManager): camera.PhotoOutput | undefined { 754 let profile: camera.Profile = cameraOutputCapability.photoProfiles[0]; 755 let photoOutput: camera.PhotoOutput | undefined = undefined; 756 try { 757 photoOutput = cameraManager.createPhotoOutput(profile); 758 } catch (error) { 759 // 失败返回错误码error.code并处理。 760 let err = error as BusinessError; 761 console.error(`The createPhotoOutput call failed. error code: ${err.code}`); 762 } 763 return photoOutput; 764} 765``` 766 767### createVideoOutput 768 769createVideoOutput(profile: VideoProfile, surfaceId: string): VideoOutput 770 771创建录像输出对象,同步返回结果。 772 773**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 774 775**系统能力:** SystemCapability.Multimedia.Camera.Core 776 777**参数:** 778 779| 参数名 | 类型 | 必填 | 说明 | 780| -------- | ------------------------------------------- | ---- | ------------------------------ | 781| profile | [VideoProfile](#videoprofile) | 是 | 支持的录像配置信息,通过[getSupportedOutputCapability](#getsupportedoutputcapability11)接口获取。 | 782| surfaceId| string | 是 | 从[AVRecorder](../apis-media-kit/js-apis-media.md#avrecorder9)获取的surfaceId。| 783 784**返回值:** 785 786| 类型 | 说明 | 787| ---------- | ----------------------------- | 788| [VideoOutput](#videooutput) | VideoOutput实例。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 789 790**错误码:** 791 792以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 793 794| 错误码ID | 错误信息 | 795| --------------- | --------------- | 796| 7400101 | Parameter missing or parameter type incorrect. | 797| 7400201 | Camera service fatal error. | 798 799**示例:** 800 801```ts 802import { BusinessError } from '@kit.BasicServicesKit'; 803 804function createVideoOutput(cameraOutputCapability: camera.CameraOutputCapability, cameraManager: camera.CameraManager, surfaceId: string): camera.VideoOutput | undefined { 805 let profile: camera.VideoProfile = cameraOutputCapability.videoProfiles[0]; 806 let videoOutput: camera.VideoOutput | undefined = undefined; 807 try { 808 videoOutput = cameraManager.createVideoOutput(profile, surfaceId); 809 } catch (error) { 810 // 失败返回错误码error.code并处理。 811 let err = error as BusinessError; 812 console.error(`The createVideoOutput call failed. error code: ${err.code}`); 813 } 814 return videoOutput; 815} 816``` 817 818### createVideoOutput<sup>12+</sup> 819 820createVideoOutput(surfaceId: string): VideoOutput 821 822创建无配置信息的录像输出对象,同步返回结果。该接口需配合[preconfig](#preconfig12-1)功能一起使用。 823 824**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 825 826**系统能力:** SystemCapability.Multimedia.Camera.Core 827 828**参数:** 829 830| 参数名 | 类型 | 必填 | 说明 | 831|-----------|--------|-------|----------------------------------------------------------------------------| 832| surfaceId | string | 是 | 从[AVRecorder](../apis-media-kit/js-apis-media.md#avrecorder9)获取的surfaceId。 | 833 834**返回值:** 835 836| 类型 | 说明 | 837| ---------- | ----------------------------- | 838| [VideoOutput](#videooutput) | VideoOutput实例。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 839 840**错误码:** 841 842以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 843 844| 错误码ID | 错误信息 | 845|----------|------------------------------------------------| 846| 7400101 | Parameter missing or parameter type incorrect. | 847| 7400201 | Camera service fatal error. | 848 849**示例:** 850 851```ts 852import { BusinessError } from '@kit.BasicServicesKit'; 853 854function createVideoOutput(cameraManager: camera.CameraManager, surfaceId: string): camera.VideoOutput | undefined { 855 let videoOutput: camera.VideoOutput | undefined = undefined; 856 try { 857 videoOutput = cameraManager.createVideoOutput(surfaceId); 858 } catch (error) { 859 // 失败返回错误码error.code并处理。 860 let err = error as BusinessError; 861 console.error(`The createVideoOutput call failed. error code: ${err.code}`); 862 } 863 return videoOutput; 864} 865``` 866 867### createMetadataOutput 868 869createMetadataOutput(metadataObjectTypes: Array\<MetadataObjectType\>): MetadataOutput 870 871创建metadata流输出对象,同步返回结果。 872 873**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 874 875**系统能力:** SystemCapability.Multimedia.Camera.Core 876 877**参数:** 878 879| 参数名 | 类型 | 必填 | 说明 | 880| -------------------- | -------------------------------------------------- | --- | ---------------------------- | 881| metadataObjectTypes | Array\<[MetadataObjectType](#metadataobjecttype)\> | 是 | metadata流类型信息,通过[getSupportedOutputCapability](#getsupportedoutputcapability11)接口获取。 | 882 883**返回值:** 884 885| 类型 | 说明 | 886| ---------- | ----------------------------- | 887| [MetadataOutput](#metadataoutput) | MetadataOutput实例。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 888 889**错误码:** 890 891以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 892 893| 错误码ID | 错误信息 | 894| --------------- | --------------- | 895| 7400101 | Parameter missing or parameter type incorrect. | 896| 7400201 | Camera service fatal error. | 897 898**示例:** 899 900```ts 901import { BusinessError } from '@kit.BasicServicesKit'; 902 903function createMetadataOutput(cameraManager: camera.CameraManager, cameraOutputCapability: camera.CameraOutputCapability): void { 904 let metadataObjectTypes: Array<camera.MetadataObjectType> = cameraOutputCapability.supportedMetadataObjectTypes; 905 let metadataOutput: camera.MetadataOutput | undefined = undefined; 906 try { 907 metadataOutput = cameraManager.createMetadataOutput(metadataObjectTypes); 908 } catch (error) { 909 // 失败返回错误码error.code并处理。 910 let err = error as BusinessError; 911 console.error(`createMetadataOutput error. error code: ${err.code}`); 912 } 913} 914``` 915 916### createCaptureSession<sup>(deprecated)</sup> 917 918createCaptureSession(): CaptureSession 919 920创建CaptureSession实例,同步返回结果。 921 922> **说明:** 923>从 API version 10开始支持,从API version 11开始废弃。建议使用[createSession](#createsession11)替代。 924 925**系统能力:** SystemCapability.Multimedia.Camera.Core 926 927**返回值:** 928 929| 类型 | 说明 | 930| ---------- | ----------------------------- | 931| [CaptureSession](#capturesessiondeprecated) | CaptureSession实例。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 932 933**错误码:** 934 935以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 936 937| 错误码ID | 错误信息 | 938| --------------- | --------------- | 939| 7400201 | Camera service fatal error. | 940 941**示例:** 942 943```ts 944import { BusinessError } from '@kit.BasicServicesKit'; 945 946function createCaptureSession(cameraManager: camera.CameraManager): camera.CaptureSession | undefined { 947 let captureSession: camera.CaptureSession | undefined = undefined; 948 try { 949 captureSession = cameraManager.createCaptureSession(); 950 } catch (error) { 951 // 失败返回错误码error.code并处理。 952 let err = error as BusinessError; 953 console.error(`createCaptureSession error. error code: ${err.code}`); 954 } 955 return captureSession; 956} 957``` 958 959### createSession<sup>11+</sup> 960 961createSession\<T extends Session\>(mode: SceneMode): T 962 963创建指定SceneMode的Session实例,同步返回结果。 964 965**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 966 967**系统能力:** SystemCapability.Multimedia.Camera.Core 968 969**参数:** 970 971| 参数名 | 类型 | 必填 | 说明 | 972| -------- | -----------------| ---- | --------- | 973| mode | [SceneMode](#scenemode11) | 是 | 相机支持的模式。如果传入的参数异常(如超出范围、传入null或未定义等),实际接口不会生效。 | 974 975**返回值:** 976 977| 类型 | 说明 | 978| ---------- | ----------------------------- | 979| [T extends Session](#session11) | Session实例。接口调用失败会返回相应的错误码,错误码类型为[CameraErrorCode](#cameraerrorcode)。 | 980 981**错误码:** 982 983以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 984 985| 错误码ID | 错误信息 | 986|---------|------------------------------------------------------------------------------------------------------------------------------------------------| 987| 7400101 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3.Parameter verification failed. | 988| 7400201 | Camera service fatal error. | 989 990**示例:** 991 992```ts 993import { BusinessError } from '@kit.BasicServicesKit'; 994 995function createSession(cameraManager: camera.CameraManager, mode: camera.SceneMode): camera.Session | undefined { 996 let photoSession: camera.PhotoSession | undefined = undefined; 997 try { 998 photoSession = cameraManager.createSession(mode) as camera.PhotoSession; 999 } catch (error) { 1000 // 失败返回错误码error.code并处理。 1001 let err = error as BusinessError; 1002 console.error(`createCaptureSession error. error code: ${err.code}`); 1003 } 1004 return photoSession; 1005} 1006``` 1007 1008### on('cameraStatus') 1009 1010on(type: 'cameraStatus', callback: AsyncCallback\<CameraStatusInfo\>): void 1011 1012相机设备状态回调,通过注册回调函数获取相机的状态变化。使用callback异步回调。 1013 1014> **说明:** 1015> 1016> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 1017 1018**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 1019 1020**系统能力:** SystemCapability.Multimedia.Camera.Core 1021 1022**参数:** 1023 1024| 参数名 | 类型 | 必填 | 说明 | 1025| -------- | -----------------| ---- | --------- | 1026| type | string | 是 | 监听事件,固定为'cameraStatus'。cameraManager对象获取成功后可监听。目前只支持对设备打开或者关闭会触发该事件并返回对应信息。 | 1027| callback | AsyncCallback\<[CameraStatusInfo](#camerastatusinfo)\> | 是 | 回调函数,用于获取镜头状态变化信息。 | | 1028 1029**示例:** 1030 1031```ts 1032import { BusinessError } from '@kit.BasicServicesKit'; 1033 1034function callback(err: BusinessError, cameraStatusInfo: camera.CameraStatusInfo): void { 1035 if (err !== undefined && err.code !== 0) { 1036 console.error('cameraStatus with errorCode = ' + err.code); 1037 return; 1038 } 1039 console.info(`camera : ${cameraStatusInfo.camera.cameraId}`); 1040 console.info(`status: ${cameraStatusInfo.status}`); 1041} 1042 1043function registerCameraStatus(cameraManager: camera.CameraManager): void { 1044 cameraManager.on('cameraStatus', callback); 1045} 1046``` 1047 1048### off('cameraStatus') 1049 1050off(type: 'cameraStatus', callback?: AsyncCallback\<CameraStatusInfo\>): void 1051 1052相机设备状态注销回调,通过注销回调函数取消获取相机的状态变化。 1053 1054**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 1055 1056**系统能力:** SystemCapability.Multimedia.Camera.Core 1057 1058**参数:** 1059 1060| 参数名 | 类型 | 必填 | 说明 | 1061| -------- | -----------------| ---- | --------- | 1062| type | string | 是 | 监听事件,固定为'cameraStatus'。cameraManager对象获取成功后可监听。 | 1063| callback | AsyncCallback\<[CameraStatusInfo](#camerastatusinfo)\> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 1064 1065**示例:** 1066 1067```ts 1068function unregisterCameraStatus(cameraManager: camera.CameraManager): void { 1069 cameraManager.off('cameraStatus'); 1070} 1071``` 1072 1073### on('foldStatusChange')<sup>12+</sup> 1074 1075on(type: 'foldStatusChange', callback: AsyncCallback\<FoldStatusInfo\>): void 1076 1077注册折叠设备折叠状态变化的监听。使用callback异步回调。 1078 1079> **说明:** 1080> 1081> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 1082 1083**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 1084 1085**系统能力:** SystemCapability.Multimedia.Camera.Core 1086 1087**参数:** 1088 1089| 参数名 | 类型 | 必填 | 说明 | 1090| -------- | -----------------| ---- | --------- | 1091| type | string | 是 | 监听事件,固定为'foldStatusChange'。表示折叠设备折叠状态发生变化。 | 1092| callback | AsyncCallback\<[FoldStatusInfo](#foldstatusinfo12)\> | 是 | 回调函数。返回折叠设备折叠信息。 | 1093 1094**示例:** 1095 1096```ts 1097import { BusinessError } from '@kit.BasicServicesKit'; 1098 1099function callback(err: BusinessError, foldStatusInfo: camera.FoldStatusInfo): void { 1100 if (err !== undefined && err.code !== 0) { 1101 console.error('foldStatusChange with errorCode = ' + err.code); 1102 return; 1103 } 1104 console.info(`camera length: ${foldStatusInfo.supportedCameras.length}`); 1105 console.info(`foldStatus: ${foldStatusInfo.foldStatus}`); 1106} 1107 1108function registerFoldStatusChange(cameraManager: camera.CameraManager): void { 1109 cameraManager.on('foldStatusChange', callback); 1110} 1111``` 1112 1113### off('foldStatusChange')<sup>12+</sup> 1114 1115off(type: 'foldStatusChange', callback?: AsyncCallback\<FoldStatusInfo\>): void 1116 1117关闭折叠设备折叠状态变化的监听。 1118 1119**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 1120 1121**系统能力:** SystemCapability.Multimedia.Camera.Core 1122 1123**参数:** 1124 1125| 参数名 | 类型 | 必填 | 说明 | 1126| -------- | -----------------| ---- | --------- | 1127| type | string | 是 | 监听事件,固定为'foldStatusChange'。表示折叠设备折叠状态发生变化。 | 1128| callback | AsyncCallback\<[FoldStatusInfo](#foldstatusinfo12)\> | 否 | 回调函数,返回折叠设备折叠信息。如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 1129 1130**示例:** 1131 1132```ts 1133function unregisterFoldStatusChange(cameraManager: camera.CameraManager): void { 1134 cameraManager.off('foldStatusChange'); 1135} 1136``` 1137 1138### isTorchSupported<sup>11+</sup> 1139 1140isTorchSupported(): boolean 1141 1142检测设备是否支持手电筒。 1143 1144**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 1145 1146**系统能力:** SystemCapability.Multimedia.Camera.Core 1147 1148**返回值:** 1149 1150| 类型 | 说明 | 1151| ---------- | ----------------------------- | 1152| boolean | 返回true表示设备支持手电筒,返回false表示设备不支持手电。 | 1153 1154**示例:** 1155 1156```ts 1157function isTorchSupported(cameraManager: camera.CameraManager): boolean { 1158 let isSupported = cameraManager.isTorchSupported(); 1159 return isSupported; 1160} 1161``` 1162 1163### isTorchModeSupported<sup>11+</sup> 1164 1165isTorchModeSupported(mode: TorchMode): boolean 1166 1167检测是否支持设置的手电筒模式。 1168 1169**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 1170 1171**系统能力:** SystemCapability.Multimedia.Camera.Core 1172 1173**参数:** 1174 1175| 参数名 | 类型 | 必填 | 说明 | 1176| -------- | --------------- | ---- | --------- | 1177| mode | [TorchMode](#torchmode11) | 是 | 手电筒模式。传参为null或者undefined,作为0处理,手电筒关闭。 | 1178 1179**返回值:** 1180 1181| 类型 | 说明 | 1182| ---------- | ----------------------------- | 1183| boolean | 返回true表示设备支持设置的手电筒模式,返回false表示设备不支持的手电筒模式。 | 1184 1185**示例:** 1186 1187```ts 1188function isTorchModeSupported(cameraManager: camera.CameraManager, torchMode: camera.TorchMode): boolean { 1189 let isSupported = cameraManager.isTorchModeSupported(torchMode); 1190 return isSupported; 1191} 1192``` 1193 1194### getTorchMode<sup>11+</sup> 1195 1196getTorchMode(): TorchMode 1197 1198获取当前设备手电筒模式。 1199 1200**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 1201 1202**系统能力:** SystemCapability.Multimedia.Camera.Core 1203 1204**返回值:** 1205 1206| 类型 | 说明 | 1207| ---------- | ----------------------------- | 1208| [TorchMode](#torchmode11) | 返回设备当前手电筒模式。 | 1209 1210**示例:** 1211 1212```ts 1213function getTorchMode(cameraManager: camera.CameraManager): camera.TorchMode | undefined { 1214 let torchMode: camera.TorchMode | undefined = undefined; 1215 torchMode = cameraManager.getTorchMode(); 1216 return torchMode; 1217} 1218``` 1219 1220### setTorchMode<sup>11+</sup> 1221 1222setTorchMode(mode: TorchMode): void 1223 1224设置设备手电筒模式。 1225 1226**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 1227 1228**系统能力:** SystemCapability.Multimedia.Camera.Core 1229 1230**参数:** 1231 1232| 参数名 | 类型 | 必填 | 说明 | 1233| -------- | --------------- | ---- | --------- | 1234| mode | [TorchMode](#torchmode11) | 是 | 手电筒模式。传参为null或者undefined,作为0处理,手电筒关闭。 | 1235 1236**错误码:** 1237 1238以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 1239 1240| 错误码ID | 错误信息 | 1241| --------------- | --------------- | 1242| 7400102 | Operation not allowed. | 1243| 7400201 | Camera service fatal error. | 1244 1245**示例:** 1246 1247```ts 1248import { BusinessError } from '@kit.BasicServicesKit'; 1249 1250function setTorchMode(cameraManager: camera.CameraManager, torchMode: camera.TorchMode): void { 1251 try { 1252 cameraManager.setTorchMode(torchMode); 1253 } catch (error) { 1254 // 失败返回错误码error.code并处理。 1255 let err = error as BusinessError; 1256 console.error(`The setTorchMode call failed. error code: ${err.code}`); 1257 } 1258} 1259``` 1260 1261### on('torchStatusChange')<sup>11+</sup> 1262 1263on(type: 'torchStatusChange', callback: AsyncCallback\<TorchStatusInfo\>): void 1264 1265手电筒状态变化回调,通过注册回调函数获取手电筒状态变化。使用callback异步回调。 1266 1267> **说明:** 1268> 1269> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 1270 1271**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 1272 1273**系统能力:** SystemCapability.Multimedia.Camera.Core 1274 1275**参数:** 1276 1277| 参数名 | 类型 | 必填 | 说明 | 1278| -------- | --------------- | ---- | --------- | 1279| type | string | 是 | 监听事件,固定为'torchStatusChange'。cameraManager对象获取成功后可监听。目前只支持手电筒打开,手电筒关闭,手电筒不可用,手电筒恢复可用会触发该事件并返回对应信息。 | 1280| callback | AsyncCallback\<TorchStatusInfo> | 是 | 回调函数,用于获取手电筒状态变化信息。 | 1281 1282**示例:** 1283 1284```ts 1285import { BusinessError } from '@kit.BasicServicesKit'; 1286 1287function callback(err: BusinessError, torchStatusInfo: camera.TorchStatusInfo): void { 1288 if (err !== undefined && err.code !== 0) { 1289 console.error(`Callback Error, errorCode: ${err.code}`); 1290 return; 1291 } 1292 console.info(`onTorchStatusChange, isTorchAvailable: ${torchStatusInfo.isTorchAvailable}, isTorchActive: ${torchStatusInfo.isTorchActive}, level: ${torchStatusInfo.torchLevel}`); 1293} 1294 1295function registerTorchStatusChange(cameraManager: camera.CameraManager): void { 1296 cameraManager.on('torchStatusChange', callback); 1297} 1298``` 1299 1300### off('torchStatusChange')<sup>11+</sup> 1301 1302off(type: 'torchStatusChange', callback?: AsyncCallback\<TorchStatusInfo\>): void 1303 1304手电筒状态变化注销回调,通过注销回调函数取消获取手电筒状态变化。 1305 1306**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 1307 1308**系统能力:** SystemCapability.Multimedia.Camera.Core 1309 1310**参数:** 1311 1312| 参数名 | 类型 | 必填 | 说明 | 1313| -------- | --------------- | ---- | --------- | 1314| type | string | 是 | 监听事件,固定为'torchStatusChange'。cameraManager对象获取成功后可监听。 | 1315| callback | AsyncCallback\<TorchStatusInfo> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 1316 1317**示例:** 1318 1319```ts 1320function unregisterTorchStatusChange(cameraManager: camera.CameraManager): void { 1321 cameraManager.off('torchStatusChange'); 1322} 1323``` 1324 1325### getCameraDevice<sup>18+</sup> 1326 1327getCameraDevice(position:CameraPosition, type: CameraType): CameraDevice 1328 1329根据相机位置和相机类型查询对应相机。 1330 1331**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 1332 1333**系统能力:** SystemCapability.Multimedia.Camera.Core 1334 1335**参数:** 1336 1337| 参数名 | 类型 | 必填 | 说明 | 1338| -------- | --------------- | ---- | --------- | 1339| position | [CameraPosition](#cameraposition) | 是 | 需要得到的CameraDevice对象对应的CameraPosition条件。 | 1340| type | [CameraType](#cameratype) | 是 | 需要得到的CameraDevice对象对应的CameraType条件。 | 1341 1342**返回值:** 1343 1344| 类型 | 说明 | 1345| -----------------| ------------------------ | 1346| [CameraDevice](#cameradevice) | 根据相机位置和相机类型查询的对应相机。 | 1347 1348**错误码:** 1349 1350以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[Camera错误码](errorcode-camera.md)。 1351 1352| 错误码ID | 错误信息 | 1353| --------------- | --------------- | 1354| 7400201 | Camera service fatal error. | 1355 1356**示例:** 1357 1358```ts 1359import { camera } from '@kit.CameraKit'; 1360 1361function getCameraDevice(cameraManager: camera.CameraManager, position: camera.CameraPosition, type: camera.CameraType): void { 1362 try { 1363 let curCameraDev: camera.CameraDevice | undefined = undefined; 1364 curCameraDev = cameraManager.getCameraDevice(position, type); 1365 } catch (error) { 1366 // 失败返回错误码并处理。 1367 let err = error as BusinessError; 1368 console.error(`The getCameraDevice call failed. error code: ${err.code}`); 1369 } 1370} 1371``` 1372 1373### getCameraConcurrentInfos<sup>18+</sup> 1374 1375getCameraConcurrentInfos(cameras: Array\<CameraDevice\>): Array\<CameraConcurrentInfo\> 1376 1377获取指定相机设备的并发信息。返回空数组表示不支持并发。 1378 1379**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 1380 1381**系统能力:** SystemCapability.Multimedia.Camera.Core 1382 1383**参数:** 1384 1385| 参数名 | 类型 | 必填 | 说明 | 1386| -------- | --------------- | ---- | --------- | 1387| cameras | Array\<[CameraDevice](#cameradevice)\> | 是 | 一组CameraDevice相机设备,并得到与这一组CamraDevice对应的并发信息,推荐设置为由[getCameraDevice](#getcameradevice18)获取的前置与后置两个用于并发的相机设备。 | 1388 1389**返回值:** 1390 1391| 类型 | 说明 | 1392| -----------------| ------------------------ | 1393| Array\<[CameraConcurrentInfo](#cameraconcurrentinfo18)\> | 一组CameraDevice相机设备对象对应的并发信息,与CameraDevice相机设备一一对应。 | 1394 1395**错误码:** 1396 1397以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[Camera错误码](errorcode-camera.md)。 1398 1399| 错误码ID | 错误信息 | 1400| --------------- | --------------- | 1401| 7400201 | Camera service fatal error. | 1402 1403**示例:** 1404 1405```ts 1406import { camera } from '@kit.CameraKit'; 1407 1408function getCameraConcurrentInfos(cameraManager: camera.CameraManager, cameraDeviceArray: Array<camera.CameraDevice>): void { 1409 try { 1410 let cameraconcurrentinfos: Array<camera.CameraConcurrentInfo> = []; 1411 cameraconcurrentinfos = cameraManager.getCameraConcurrentInfos(cameraDeviceArray); 1412 } catch (error) { 1413 // 失败返回错误码并处理。 1414 let err = error as BusinessError; 1415 console.error(`The getCameraConcurrentInfos call failed. error code: ${err.code}`); 1416 } 1417} 1418``` 1419 1420## TorchMode<sup>11+</sup> 1421 1422枚举,手电筒模式。 1423 1424**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 1425 1426**系统能力:** SystemCapability.Multimedia.Camera.Core 1427 1428| 名称 | 值 | 说明 | 1429| ---------------------------- | ---- | ------------- | 1430| OFF | 0 | 常关模式。 | 1431| ON | 1 | 常开模式。 | 1432| AUTO | 2 | 自动模式,系统根据环境自动调节手电筒亮度。| 1433 1434## TorchStatusInfo<sup>11+</sup> 1435 1436手电筒回调返回的接口实例,表示手电筒状态信息。 1437 1438**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 1439 1440**系统能力:** SystemCapability.Multimedia.Camera.Core 1441 1442| 名称 | 类型 | 只读 | 可选 | 说明 | 1443| ---------------- | ---------- | ---- | ---- | ----------- | 1444| isTorchAvailable | boolean | 是 | 否 | 手电筒是否可用。true表示手电筒可用,false表示手电筒不可用。| 1445| isTorchActive | boolean | 是 | 否 | 手电筒是否被激活。true表示手电筒被激活,false表示手电筒未被激活。 | 1446| torchLevel | number | 是 | 否 | 手电筒亮度等级,取值范围为[0,1],越靠近1,亮度越大。 | 1447 1448## Size 1449 1450输出能力查询。 1451 1452**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 1453 1454**系统能力:** SystemCapability.Multimedia.Camera.Core 1455 1456| 名称 | 类型 | 只读 | 可选 | 说明 | 1457| ------ | ------ | ---- |-----| ------------ | 1458| height | number | 否 | 否 | 图像尺寸高(像素)。 | 1459| width | number | 否 | 否 | 图像尺寸宽(像素)。 | 1460 1461## Point 1462 1463点坐标用于对焦和曝光配置。 1464 1465**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 1466 1467**系统能力:** SystemCapability.Multimedia.Camera.Core 1468 1469| 名称 | 类型 | 只读 | 可选 | 说明 | 1470| ------ | ------ | ------ | ------ | ------------ | 1471| x | number | 否 | 否 | 点的x坐标。 | 1472| y | number | 否 | 否 | 点的y坐标。 | 1473 1474## CameraFormat 1475 1476枚举,输出格式。 1477 1478**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 1479 1480**系统能力:** SystemCapability.Multimedia.Camera.Core 1481 1482| 名称 | 值 | 说明 | 1483| ----------------------- | --------- | ------------ | 1484| CAMERA_FORMAT_RGBA_8888 | 3 | RGBA_8888格式的图片。 | 1485| CAMERA_FORMAT_YUV_420_SP| 1003 | YUV_420_SP格式的图片。 | 1486| CAMERA_FORMAT_JPEG | 2000 | JPEG格式的图片。 | 1487| CAMERA_FORMAT_YCBCR_P010<sup>11+</sup> | 2001 | YCBCR_P010格式的图片。 | 1488| CAMERA_FORMAT_YCRCB_P010<sup>11+</sup> | 2002 | YCRCB_P010格式的图片。 | 1489| CAMERA_FORMAT_HEIC<sup>13+</sup> | 2003 | HEIF格式的图片。 | 1490 1491## VideoCodecType<sup>13+</sup> 1492 1493枚举,视频编码类型。 1494 1495**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 1496 1497**系统能力:** SystemCapability.Multimedia.Camera.Core 1498 1499| 名称 | 值 | 说明 | 1500|------|------|-------------| 1501| AVC | 0 | 视频编码类型AVC。| 1502| HEVC | 1 | 视频编码类型HEVC。| 1503 1504## CameraConcurrentType<sup>18+</sup> 1505 1506枚举,镜头并发类型。 1507 1508**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 1509 1510**系统能力:** SystemCapability.Multimedia.Camera.Core 1511 1512| 名称 | 值 | 说明 | 1513|------|------|-------------| 1514| CAMERA_LIMITED_CAPABILITY | 0 | 镜头受限能力并发。 | 1515| CAMERA_FULL_CAPABILITY | 1 | 镜头全量能力并发。 | 1516 1517## CameraConcurrentInfo<sup>18+</sup> 1518 1519相机的输出并发能力信息。 1520 1521**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 1522 1523**系统能力:** SystemCapability.Multimedia.Camera.Core 1524 1525| 名称 | 类型 | 只读 | 可选 | 说明 | 1526| ------ | ------ | ---- |-----| ------------ | 1527| device | [CameraDevice](#cameradevice) | 是 | 否 | 相机并发设备。 | 1528| type | [CameraConcurrentType](#cameraconcurrenttype18) | 是 | 否 | 镜头并发类型。 | 1529| modes | Array\<[SceneMode](#scenemode11) \> | 是 | 否 | 相机支持的模式。 | 1530| outputCapabilities | Array\<[CameraOutputCapability](#cameraoutputcapability) \> | 是 | 否 | 相机对应模式的输出能力集。 | 1531 1532## CameraInput 1533 1534相机设备输入对象。 1535 1536会话中[Session](#session11)使用的相机信息。 1537 1538### open 1539 1540open(callback: AsyncCallback\<void\>): void 1541 1542打开相机,通过注册回调函数获取状态。使用callback异步回调。 1543 1544**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 1545 1546**系统能力:** SystemCapability.Multimedia.Camera.Core 1547 1548**参数:** 1549 1550| 参数名 | 类型 | 必填 | 说明 | 1551| -------- | -------------------- | ---- | ------------------- | 1552| callback | AsyncCallback\<void\> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 1553 1554**错误码:** 1555 1556以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 1557 1558| 错误码ID | 错误信息 | 1559| --------------- | --------------- | 1560| 7400107 | Can not use camera cause of conflict. | 1561| 7400108 | Camera disabled cause of security reason. | 1562| 7400201 | Camera service fatal error. | 1563 1564**示例:** 1565 1566```ts 1567import { BusinessError } from '@kit.BasicServicesKit'; 1568 1569function openCameraInput(cameraInput: camera.CameraInput): void { 1570 cameraInput.open((err: BusinessError) => { 1571 if (err) { 1572 console.error(`Failed to open the camera, error code: ${err.code}.`); 1573 return; 1574 } 1575 console.info('Callback returned with camera opened.'); 1576 }); 1577} 1578``` 1579 1580### open 1581 1582open(): Promise\<void\> 1583 1584打开相机,通过Promise获取相机的状态。 1585 1586**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 1587 1588**系统能力:** SystemCapability.Multimedia.Camera.Core 1589 1590**返回值:** 1591 1592| 类型 | 说明 | 1593| -------------- | ----------------------- | 1594| Promise\<void\> | 无返回结果的Promise对象。 | 1595 1596**错误码:** 1597 1598以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 1599 1600| 错误码ID | 错误信息 | 1601|---------|-------------------------------------------| 1602| 7400102 | Operation not allowed. | 1603| 7400107 | Can not use camera cause of conflict. | 1604| 7400108 | Camera disabled cause of security reason. | 1605| 7400201 | Camera service fatal error. | 1606 1607**示例:** 1608 1609```ts 1610import { BusinessError } from '@kit.BasicServicesKit'; 1611 1612function openCameraInput(cameraInput: camera.CameraInput): void { 1613 cameraInput.open().then(() => { 1614 console.info('Promise returned with camera opened.'); 1615 }).catch((error: BusinessError) => { 1616 console.error(`Failed to open the camera, error code: ${error.code}.`); 1617 }); 1618} 1619``` 1620 1621### open<sup>12+</sup> 1622 1623open(isSecureEnabled: boolean): Promise\<bigint\> 1624 1625打开相机,获取安全相机的句柄。 1626 1627**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 1628 1629**系统能力:** SystemCapability.Multimedia.Camera.Core 1630 1631**参数:** 1632 1633| 参数名 | 类型 | 必填 | 说明 | 1634| -------- | -------------------- | ---- |-------------------------------------------------------------------------| 1635| isSecureEnabled | boolean | 是 | 设置true为使能以安全的方式打开相机,设置false则反之。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 1636 1637**返回值:** 1638 1639| 类型 | 说明 | 1640| -------------- | ----------------------- | 1641| Promise\<bigint\> | 使用Promise的方式获取打开相机句柄。 | 1642 1643**错误码:** 1644 1645以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 1646 1647| 错误码ID | 错误信息 | 1648| --------------- | --------------- | 1649| 7400107 | Can not use camera cause of conflict. | 1650| 7400108 | Camera disabled cause of security reason. | 1651| 7400201 | Camera service fatal error. | 1652 1653**示例:** 1654 1655```ts 1656import { BusinessError } from '@kit.BasicServicesKit'; 1657 1658function openCameraInput(cameraInput: camera.CameraInput): void { 1659 cameraInput.open(true).then(() => { 1660 console.info('Promise returned with camera opened.'); 1661 }).catch((error: BusinessError) => { 1662 console.error(`Failed to open the camera, error code: ${error.code}.`); 1663 }); 1664} 1665``` 1666 1667### open<sup>18+</sup> 1668 1669open(type: CameraConcurrentType): Promise\<void\> 1670 1671以指定的并发类型打开相机。 1672 1673**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 1674 1675**系统能力:** SystemCapability.Multimedia.Camera.Core 1676 1677**参数:** 1678 1679| 参数名 | 类型 | 必填 | 说明 | 1680| -------- | -------------------- | ---- |-------------------------------------------------------------------------| 1681| type | [CameraConcurrentType](#cameraconcurrenttype18) | 是 | 以指定的并发类型打开相机。接口调用失败会返回相应错误码。| 1682 1683**返回值:** 1684 1685| 类型 | 说明 | 1686| -------------- | ----------------------- | 1687| Promise\<void\> | Promise对象。无返回结果的Promise对象。 | 1688 1689**错误码:** 1690 1691以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 1692 1693| 错误码ID | 错误信息 | 1694|---------|-------------------------------------------| 1695| 7400102 | Operation not allowed. | 1696| 7400107 | Can not use camera cause of conflict. | 1697| 7400108 | Camera disabled cause of security reason. | 1698| 7400201 | Camera service fatal error. | 1699 1700**示例:** 1701 1702```ts 1703import { BusinessError } from '@kit.BasicServicesKit'; 1704 1705function openCameraInput(cameraInput: camera.CameraInput): void { 1706 cameraInput.open(0).then(() => { 1707 console.info('Promise returned with camera opened.'); 1708 }).catch((error: BusinessError) => { 1709 console.error(`Failed to open the camera, error code: ${error.code}.`); 1710 }); 1711} 1712``` 1713 1714### close 1715 1716close(callback: AsyncCallback\<void\>\): void 1717 1718关闭相机,通过注册回调函数获取状态。使用callback异步回调。 1719 1720**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 1721 1722**系统能力:** SystemCapability.Multimedia.Camera.Core 1723 1724**参数:** 1725 1726| 参数名 | 类型 | 必填 | 说明 | 1727| -------- | -------------------- | ---- | -------------------- | 1728| callback | AsyncCallback\<void\> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 1729 1730**错误码:** 1731 1732以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 1733 1734| 错误码ID | 错误信息 | 1735| --------------- | --------------- | 1736| 7400201 | Camera service fatal error. | 1737 1738**示例:** 1739 1740```ts 1741import { BusinessError } from '@kit.BasicServicesKit'; 1742 1743function closeCameraInput(cameraInput: camera.CameraInput): void { 1744 cameraInput.close((err: BusinessError) => { 1745 if (err) { 1746 console.error(`Failed to close the cameras, error code: ${err.code}.`); 1747 return; 1748 } 1749 console.info('Callback returned with camera closed.'); 1750 }); 1751} 1752``` 1753 1754### close 1755 1756close(): Promise\<void\> 1757 1758关闭相机,通过Promise获取状态。 1759 1760**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 1761 1762**系统能力:** SystemCapability.Multimedia.Camera.Core 1763 1764**返回值:** 1765 1766| 类型 | 说明 | 1767| -------------- | ----------------------- | 1768| Promise\<void\> | 无返回结果的Promise对象。 | 1769 1770**错误码:** 1771 1772以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 1773 1774| 错误码ID | 错误信息 | 1775| --------------- | --------------- | 1776| 7400201 | Camera service fatal error. | 1777 1778**示例:** 1779 1780```ts 1781import { BusinessError } from '@kit.BasicServicesKit'; 1782 1783function closeCameraInput(cameraInput: camera.CameraInput): void { 1784 cameraInput.close().then(() => { 1785 console.info('Promise returned with camera closed.'); 1786 }).catch((error: BusinessError) => { 1787 console.error(`Failed to close the cameras, error code: ${error.code}.`); 1788 }); 1789} 1790``` 1791 1792### on('error') 1793 1794on(type: 'error', camera: CameraDevice, callback: ErrorCallback): void 1795 1796监听CameraInput的错误事件,通过注册回调函数获取结果。使用callback异步回调。 1797 1798> **说明:** 1799> 1800> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 1801 1802**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 1803 1804**系统能力:** SystemCapability.Multimedia.Camera.Core 1805 1806**参数:** 1807 1808| 参数名 | 类型 | 必填 | 说明 | 1809| -------- | -------------------------------- | --- | ------------------------------------------- | 1810| type | string | 是 | 监听事件,固定为'error',CameraInput对象创建成功可监听。相机设备出错情况下可触发该事件并返回结果,比如设备不可用或者冲突等返回对应错误信息。 | 1811| camera | [CameraDevice](#cameradevice) | 是 | CameraDevice对象。 | 1812| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | 是 | 回调函数,用于获取结果。返回错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 1813 1814**示例:** 1815 1816```ts 1817import { BusinessError } from '@kit.BasicServicesKit'; 1818 1819function callback(err: BusinessError): void { 1820 console.error(`Camera input error code: ${err.code}`); 1821} 1822 1823function registerCameraInputError(cameraInput: camera.CameraInput, camera: camera.CameraDevice): void { 1824 cameraInput.on('error', camera, callback); 1825} 1826``` 1827 1828### off('error') 1829 1830off(type: 'error', camera: CameraDevice, callback?: ErrorCallback): void 1831 1832注销监听CameraInput的错误事件。 1833 1834**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 1835 1836**系统能力:** SystemCapability.Multimedia.Camera.Core 1837 1838**参数:** 1839 1840| 参数名 | 类型 | 必填 | 说明 | 1841| -------- | -------------------------------- | --- | ------------------------------------------- | 1842| type | string | 是 | 监听事件,固定为'error',CameraInput对象创建成功可监听。相机设备出错情况下可触发该事件并返回结果,比如设备不可用或者冲突等返回对应错误信息。 | 1843| camera | [CameraDevice](#cameradevice) | 是 | CameraDevice对象。 | 1844| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 1845 1846**示例:** 1847 1848```ts 1849function unregisterCameraInputError(cameraInput: camera.CameraInput, camera: camera.CameraDevice): void { 1850 cameraInput.off('error', camera); 1851} 1852``` 1853 1854## CameraOutput 1855 1856会话中[Session](#session11)使用的输出信息,output的基类。 1857 1858### release 1859 1860release(callback: AsyncCallback\<void\>): void 1861 1862释放输出资源,通过注册回调函数获取结果。使用callback异步回调。 1863 1864**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 1865 1866**系统能力:** SystemCapability.Multimedia.Camera.Core 1867 1868**参数:** 1869 1870| 参数名 | 类型 | 必填 | 说明 | 1871| -------- | -------------------- | ---- | ------------------- | 1872| callback | AsyncCallback\<void\> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 1873 1874**错误码:** 1875 1876以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 1877 1878| 错误码ID | 错误信息 | 1879| --------------- | --------------- | 1880| 7400201 | Camera service fatal error. | 1881 1882**示例:** 1883 1884```ts 1885import { BusinessError } from '@kit.BasicServicesKit'; 1886 1887function releasePreviewOutput(previewOutput: camera.PreviewOutput): void { 1888 previewOutput.release((err: BusinessError) => { 1889 if (err) { 1890 console.error(`Failed to release the Preview output instance ${err.code}`); 1891 return; 1892 } 1893 console.info('Callback invoked to indicate that the preview output instance is released successfully.'); 1894 }); 1895} 1896 1897function releaseVideoOutput(videoOutput: camera.VideoOutput): void { 1898 videoOutput.release((err: BusinessError) => { 1899 if (err) { 1900 console.error(`Failed to release the video output instance ${err.code}`); 1901 return; 1902 } 1903 console.info('Callback invoked to indicate that the video output instance is released successfully.'); 1904 }); 1905} 1906``` 1907 1908### release 1909 1910release(): Promise\<void\> 1911 1912释放输出资源,通过Promise获取结果。 1913 1914**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 1915 1916**系统能力:** SystemCapability.Multimedia.Camera.Core 1917 1918**返回值:** 1919 1920| 类型 | 说明 | 1921| -------------- | ----------------------- | 1922| Promise\<void\> | 无返回结果的Promise对象。 | 1923 1924**错误码:** 1925 1926以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 1927 1928| 错误码ID | 错误信息 | 1929| --------------- | --------------- | 1930| 7400201 | Camera service fatal error. | 1931 1932**示例:** 1933 1934```ts 1935import { BusinessError } from '@kit.BasicServicesKit'; 1936 1937function releasePreviewOutput(previewOutput: camera.PreviewOutput): void { 1938 previewOutput.release().then(() => { 1939 console.info('Promise returned to indicate that the preview output instance is released successfully.'); 1940 }).catch((error: BusinessError) => { 1941 console.error(`Failed to preview output release, error code: ${error.code}`); 1942 }); 1943} 1944 1945function releaseVideoOutput(videoOutput: camera.VideoOutput): void { 1946 videoOutput.release().then(() => { 1947 console.info('Promise returned to indicate that the video output instance is released successfully.'); 1948 }).catch((error: BusinessError) => { 1949 console.error(`Failed to video output release, error code: ${error.code}`); 1950 }); 1951} 1952``` 1953 1954## PreviewOutput 1955 1956预览输出类。继承[CameraOutput](#cameraoutput)。 1957 1958### start<sup>(deprecated)</sup> 1959 1960start(callback: AsyncCallback\<void\>): void 1961 1962开始输出预览流,通过注册回调函数获取结果。使用callback异步回调。 1963 1964> **说明:** 1965>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.start](#start11)替代。 1966 1967**系统能力:** SystemCapability.Multimedia.Camera.Core 1968 1969**参数:** 1970 1971| 参数名 | 类型 | 必填 | 说明 | 1972| -------- | -------------------- | ---- | -------------------- | 1973| callback | AsyncCallback\<void\> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 1974 1975**错误码:** 1976 1977以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 1978 1979| 错误码ID | 错误信息 | 1980| --------------- | --------------- | 1981| 7400103 | Session not config. | 1982 1983**示例:** 1984 1985```ts 1986import { BusinessError } from '@kit.BasicServicesKit'; 1987 1988function startPreviewOutput(previewOutput: camera.PreviewOutput): void { 1989 previewOutput.start((err: BusinessError) => { 1990 if (err) { 1991 console.error(`Failed to start the preview output, error code: ${err.code}.`); 1992 return; 1993 } 1994 console.info('Callback returned with preview output started.'); 1995 }); 1996} 1997``` 1998 1999### start<sup>(deprecated)</sup> 2000 2001start(): Promise\<void\> 2002 2003开始输出预览流,通过Promise获取结果。 2004 2005> **说明:** 2006>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.start](#start11-1)替代。 2007 2008**系统能力:** SystemCapability.Multimedia.Camera.Core 2009 2010**返回值:** 2011 2012| 类型 | 说明 | 2013| -------------- |-------------------| 2014| Promise\<void\> | 无返回结果的Promise对象。 | 2015 2016**错误码:** 2017 2018以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 2019 2020| 错误码ID | 错误信息 | 2021| --------------- | --------------- | 2022| 7400103 | Session not config. | 2023 2024**示例:** 2025 2026```ts 2027import { BusinessError } from '@kit.BasicServicesKit'; 2028 2029function startPreviewOutput(previewOutput: camera.PreviewOutput): void { 2030 previewOutput.start().then(() => { 2031 console.info('Promise returned with preview output started.'); 2032 }).catch((error: BusinessError) => { 2033 console.error(`Failed to preview output start, error code: ${error.code}.`); 2034 }); 2035} 2036``` 2037 2038### stop<sup>(deprecated)</sup> 2039 2040stop(callback: AsyncCallback\<void\>): void 2041 2042停止输出预览流,通过注册回调函数获取结果。使用callback异步回调。 2043 2044> **说明:** 2045>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.stop](#stop11)替代。 2046 2047**系统能力:** SystemCapability.Multimedia.Camera.Core 2048 2049**参数:** 2050 2051| 参数名 | 类型 | 必填 | 说明 | 2052| -------- | -------------------- | ---- | -------------------- | 2053| callback | AsyncCallback\<void\> | 是 | 回调函数,用于获取结果。 | 2054 2055**示例:** 2056 2057```ts 2058import { BusinessError } from '@kit.BasicServicesKit'; 2059 2060function stopPreviewOutput(previewOutput: camera.PreviewOutput): void { 2061 previewOutput.stop((err: BusinessError) => { 2062 if (err) { 2063 console.error(`Failed to stop the preview output, error code: ${err.code}.`); 2064 return; 2065 } 2066 console.info('Returned with preview output stopped.'); 2067 }) 2068} 2069``` 2070 2071### stop<sup>(deprecated)</sup> 2072 2073stop(): Promise\<void\> 2074 2075停止输出预览流,通过Promise获取结果。 2076 2077> **说明:** 2078>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.stop](#stop11-1)替代。 2079 2080**系统能力:** SystemCapability.Multimedia.Camera.Core 2081 2082**返回值:** 2083 2084| 类型 | 说明 | 2085| -------------- | ------------------------ | 2086| Promise\<void\> | 无返回结果的Promise对象。 | 2087 2088**示例:** 2089 2090```ts 2091import { BusinessError } from '@kit.BasicServicesKit'; 2092 2093function stopPreviewOutput(previewOutput: camera.PreviewOutput): void { 2094 previewOutput.stop().then(() => { 2095 console.info('Callback returned with preview output stopped.'); 2096 }).catch((error: BusinessError) => { 2097 console.error(`Failed to preview output stop, error code: ${error.code}.`); 2098 }); 2099} 2100``` 2101 2102### on('frameStart') 2103 2104on(type: 'frameStart', callback: AsyncCallback\<void\>): void 2105 2106监听预览帧启动,通过注册回调函数获取结果。使用callback异步回调。 2107 2108> **说明:** 2109> 2110> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 2111 2112**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 2113 2114**系统能力:** SystemCapability.Multimedia.Camera.Core 2115 2116**参数:** 2117 2118| 参数名 | 类型 | 必填 | 说明 | 2119| -------- | -------------------- | ---- | --------------------------------------- | 2120| type | string | 是 | 监听事件,固定为'frameStart',previewOutput创建成功可监听。底层第一次开始曝光时触发该事件并返回。 | 2121| callback | AsyncCallback\<void\> | 是 | 回调函数,用于获取结果。只要有该事件返回就证明预览开始。 | 2122 2123**示例:** 2124 2125```ts 2126import { BusinessError } from '@kit.BasicServicesKit'; 2127 2128function callback(err: BusinessError): void { 2129 if (err !== undefined && err.code !== 0) { 2130 console.error(`Callback Error, errorCode: ${err.code}`); 2131 return; 2132 } 2133 console.info('Preview frame started'); 2134} 2135 2136function registerPreviewOutputFrameStart(previewOutput: camera.PreviewOutput): void { 2137 previewOutput.on('frameStart', callback); 2138} 2139``` 2140 2141### off('frameStart') 2142 2143off(type: 'frameStart', callback?: AsyncCallback\<void\>): void 2144 2145注销预览帧启动的监听。 2146 2147**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 2148 2149**系统能力:** SystemCapability.Multimedia.Camera.Core 2150 2151**参数:** 2152 2153| 参数名 | 类型 | 必填 | 说明 | 2154| -------- | -------------------- | ---- | --------------------------------------- | 2155| type | string | 是 | 监听事件,固定为'frameStart',previewOutput创建成功可监听。 | 2156| callback | AsyncCallback\<void\> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 2157 2158**示例:** 2159 2160```ts 2161function unregisterPreviewOutputFrameStart(previewOutput: camera.PreviewOutput): void { 2162 previewOutput.off('frameStart'); 2163} 2164``` 2165 2166### on('frameEnd') 2167 2168on(type: 'frameEnd', callback: AsyncCallback\<void\>): void 2169 2170监听预览帧结束,通过注册回调函数获取结果。使用callback异步回调。 2171 2172> **说明:** 2173> 2174> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 2175 2176**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 2177 2178**系统能力:** SystemCapability.Multimedia.Camera.Core 2179 2180**参数:** 2181 2182| 参数名 | 类型 | 必填 | 说明 | 2183| -------- | -------------------- | ---- | ------------------------------------- | 2184| type | string | 是 | 监听事件,固定为'frameEnd',previewOutput创建成功可监听。预览完全结束最后一帧时触发该事件并返回。 | 2185| callback | AsyncCallback\<void\> | 是 | 回调函数,用于获取结果。只要有该事件返回就证明预览结束。 | 2186 2187**示例:** 2188 2189```ts 2190import { BusinessError } from '@kit.BasicServicesKit'; 2191 2192function callback(err: BusinessError): void { 2193 if (err !== undefined && err.code !== 0) { 2194 console.error(`Callback Error, errorCode: ${err.code}`); 2195 return; 2196 } 2197 console.info('Preview frame ended'); 2198} 2199 2200function registerPreviewOutputFrameEnd(previewOutput: camera.PreviewOutput): void { 2201 previewOutput.on('frameEnd', callback); 2202} 2203``` 2204 2205### off('frameEnd') 2206 2207off(type: 'frameEnd', callback?: AsyncCallback\<void\>): void 2208 2209注销监听预览帧结束。 2210 2211**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 2212 2213**系统能力:** SystemCapability.Multimedia.Camera.Core 2214 2215**参数:** 2216 2217| 参数名 | 类型 | 必填 | 说明 | 2218| -------- | -------------------- | ---- | ------------------------------------- | 2219| type | string | 是 | 监听事件,固定为'frameEnd',previewOutput创建成功可监听。 | 2220| callback | AsyncCallback\<void\> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 2221 2222**示例:** 2223 2224```ts 2225function unregisterPreviewOutputFrameEnd(previewOutput: camera.PreviewOutput): void { 2226 previewOutput.off('frameEnd'); 2227} 2228``` 2229 2230### on('error') 2231 2232on(type: 'error', callback: ErrorCallback): void 2233 2234监听预览输出的错误事件,通过注册回调函数获取结果。使用callback异步回调。 2235 2236> **说明:** 2237> 2238> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 2239 2240**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 2241 2242**系统能力:** SystemCapability.Multimedia.Camera.Core 2243 2244**参数:** 2245 2246| 参数名 | 类型 | 必填 | 说明 | 2247| -------- | --------------| ---- | ------------------------ | 2248| type | string | 是 | 监听事件,固定为'error',previewOutput创建成功可监听。预览接口使用错误时触发该事件,比如调用[Session.start](#start11-1),[CameraOutput.release](#release-1)等接口发生错误时返回对应错误信息。 | 2249| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | 是 | 回调函数,用于获取错误信息。返回错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 2250 2251**示例:** 2252 2253```ts 2254import { BusinessError } from '@kit.BasicServicesKit'; 2255 2256function callback(previewOutputError: BusinessError): void { 2257 console.error(`Preview output error code: ${previewOutputError.code}`); 2258} 2259 2260function registerPreviewOutputError(previewOutput: camera.PreviewOutput): void { 2261 previewOutput.on('error', callback) 2262} 2263``` 2264 2265### off('error') 2266 2267off(type: 'error', callback?: ErrorCallback): void 2268 2269注销监听预览输出的错误事件。 2270 2271**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 2272 2273**系统能力:** SystemCapability.Multimedia.Camera.Core 2274 2275**参数:** 2276 2277| 参数名 | 类型 | 必填 | 说明 | 2278| -------- | --------------| ---- | ------------------------ | 2279| type | string | 是 | 监听事件,固定为'error',previewOutput创建成功可监听。 | 2280| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 2281 2282**示例:** 2283 2284```ts 2285function unregisterPreviewOutputError(previewOutput: camera.PreviewOutput): void { 2286 previewOutput.off('error'); 2287} 2288``` 2289 2290### getSupportedFrameRates<sup>12+</sup> 2291 2292 getSupportedFrameRates(): Array\<FrameRateRange\> 2293 2294查询支持的帧率范围。 2295 2296**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 2297 2298**系统能力:** SystemCapability.Multimedia.Camera.Core 2299 2300**返回值:** 2301| 类型 | 说明 | 2302| ------------- | ------------ | 2303| Array<[FrameRateRange](#frameraterange)> | 支持的帧率范围列表 | 2304 2305**示例:** 2306 2307```ts 2308function getSupportedFrameRates(previewOutput: camera.PreviewOutput): Array<camera.FrameRateRange> { 2309 let supportedFrameRatesArray: Array<camera.FrameRateRange> = previewOutput.getSupportedFrameRates(); 2310 return supportedFrameRatesArray; 2311} 2312``` 2313 2314### setFrameRate<sup>12+</sup> 2315 2316setFrameRate(minFps: number, maxFps: number): void 2317 2318设置预览流帧率范围,设置的范围必须在支持的帧率范围内。 2319进行设置前,可通过[getSupportedFrameRates](#getsupportedframerates12)接口查询支持的帧率范围。 2320 2321> **说明:** 2322> 仅在[PhotoSession](#photosession11)或[VideoSession](#videosession11)模式下支持。 2323 2324**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 2325 2326**系统能力:** SystemCapability.Multimedia.Camera.Core 2327 2328**参数:** 2329 2330| 参数名 | 类型 | 必填 | 说明 | 2331| -------- | --------------| ---- | ------------------------ | 2332| minFps | number | 是 | 最小帧率(单位:fps)。 | 2333| maxFps | number | 是 | 最大帧率(单位:fps),当传入的最小值大于最大值时,传参异常,接口不生效。| 2334 2335**错误码:** 2336 2337以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 2338 2339| 错误码ID | 错误信息 | 2340| --------------- | --------------- | 2341| 7400101 | Parameter missing or parameter type incorrect. | 2342| 7400110 | Unresolved conflicts with current configurations. | 2343 2344**示例:** 2345 2346```ts 2347function setFrameRateRange(previewOutput: camera.PreviewOutput, frameRateRange: Array<number>): void { 2348 previewOutput.setFrameRate(frameRateRange[0], frameRateRange[1]); 2349} 2350``` 2351 2352### getActiveFrameRate<sup>12+</sup> 2353 2354getActiveFrameRate(): FrameRateRange 2355 2356获取已设置的帧率范围。 2357 2358使用[setFrameRate](#setframerate12)接口对预览流设置过帧率后可查询。 2359 2360**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 2361 2362**系统能力:** SystemCapability.Multimedia.Camera.Core 2363 2364**返回值:** 2365 2366| 类型 | 说明 | 2367| ------------- | ------------ | 2368| [FrameRateRange](#frameraterange) | 帧率范围 | 2369 2370**示例:** 2371 2372```ts 2373function getActiveFrameRate(previewOutput: camera.PreviewOutput): camera.FrameRateRange { 2374 let activeFrameRate: camera.FrameRateRange = previewOutput.getActiveFrameRate(); 2375 return activeFrameRate; 2376} 2377``` 2378 2379### getActiveProfile<sup>12+</sup> 2380 2381getActiveProfile(): Profile 2382 2383获取当前生效的配置信息。 2384 2385**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 2386 2387**系统能力:** SystemCapability.Multimedia.Camera.Core 2388 2389**返回值:** 2390 2391| 类型 | 说明 | 2392| ------------- |-----------| 2393| [Profile](#profile) | 当前生效的配置信息 | 2394 2395**错误码:** 2396 2397以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 2398 2399| 错误码ID | 错误信息 | 2400|---------|------------------------------| 2401| 7400201 | Camera service fatal error. | 2402 2403**示例:** 2404 2405```ts 2406function testGetActiveProfile(previewOutput: camera.PreviewOutput): camera.Profile | undefined { 2407 let activeProfile: camera.Profile | undefined = undefined; 2408 try { 2409 activeProfile = previewOutput.getActiveProfile(); 2410 } catch (error) { 2411 // 失败返回错误码error.code并处理。 2412 let err = error as BusinessError; 2413 console.error(`The previewOutput.getActiveProfile call failed. error code: ${err.code}`); 2414 } 2415 return activeProfile; 2416} 2417``` 2418 2419### getPreviewRotation<sup>12+</sup> 2420 2421getPreviewRotation(displayRotation: number): ImageRotation 2422 2423获取预览旋转角度。 2424 2425- 设备自然方向:设备默认使用方向,手机为竖屏(充电口向下)。 2426- 相机镜头角度:值等于相机图像顺时针旋转到设备自然方向的角度,手机后置相机传感器是横屏安装的,所以需要顺时针旋转90度到设备自然方向。 2427- 屏幕显示方向:需要屏幕显示的图片左上角为第一个像素点为坐标原点。锁屏时与自然方向一致。 2428 2429**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 2430 2431**系统能力:** SystemCapability.Multimedia.Camera.Core 2432 2433**参数:** 2434 2435| 参数名 | 类型 | 必填 | 说明 | 2436| -------- | --------------| ---- | ------------------------ | 2437| displayRotation | number | 是 | 显示设备的屏幕旋转角度,通过[display.getDefaultDisplaySync](../apis-arkui/js-apis-display.md#displaygetdefaultdisplaysync9)获得。 | 2438 2439**返回值:** 2440 2441| 类型 | 说明 | 2442| ------------- |-----------| 2443| [ImageRotation](#imagerotation) | 获取预览旋转角度。 | 2444 2445**错误码:** 2446 2447以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 2448 2449| 错误码ID | 错误信息 | 2450|---------|------------------------------| 2451| 7400101 | Parameter missing or parameter type incorrect. | 2452| 7400201 | Camera service fatal error. | 2453 2454**示例:** 2455 2456```ts 2457function testGetPreviewRotation(previewOutput: camera.PreviewOutput, imageRotation : camera.ImageRotation): camera.ImageRotation { 2458 let previewRotation: camera.ImageRotation = camera.ImageRotation.ROTATION_0; 2459 try { 2460 previewRotation = previewOutput.getPreviewRotation(imageRotation); 2461 console.log(`Preview rotation is: ${previewRotation}`); 2462 } catch (error) { 2463 // 失败返回错误码error.code并处理。 2464 let err = error as BusinessError; 2465 console.error(`The previewOutput.getPreviewRotation call failed. error code: ${err.code}`); 2466 } 2467 return previewRotation; 2468} 2469``` 2470### setPreviewRotation<sup>12+</sup> 2471 2472setPreviewRotation(previewRotation: ImageRotation, isDisplayLocked?: boolean): void 2473 2474设置预览旋转角度。 2475 2476**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 2477 2478**系统能力:** SystemCapability.Multimedia.Camera.Core 2479 2480**参数:** 2481 2482| 参数名 | 类型 | 必填 | 说明 | 2483| -------- | --------------| ---- | ------------------------ | 2484| previewRotation | [ImageRotation](#imagerotation) | 是 | 预览旋转角度 | 2485| isDisplayLocked | boolean | 否 | 是否旋转锁定 | 2486 2487**错误码:** 2488 2489以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 2490 2491| 错误码ID | 错误信息 | 2492|---------|------------------------------| 2493| 7400101 | Parameter missing or parameter type incorrect. | 2494| 7400201 | Camera service fatal error. | 2495 2496**示例:** 2497 2498```ts 2499function testSetPreviewRotation(previewOutput: camera.PreviewOutput, previewRotation : camera.ImageRotation, isDisplayLocked: boolean): void { 2500 try { 2501 previewOutput.setPreviewRotation(previewRotation, isDisplayLocked); 2502 } catch (error) { 2503 // 失败返回错误码error.code并处理。 2504 let err = error as BusinessError; 2505 console.error(`The previewOutput.setPreviewRotation call failed. error code: ${err.code}`); 2506 } 2507 return; 2508} 2509``` 2510## ImageRotation 2511 2512枚举,图片旋转角度。 2513 2514**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 2515 2516**系统能力:** SystemCapability.Multimedia.Camera.Core 2517 2518| 名称 | 值 | 说明 | 2519| ------------ | ---- | ------------- | 2520| ROTATION_0 | 0 | 图片旋转0度。 | 2521| ROTATION_90 | 90 | 图片旋转90度。 | 2522| ROTATION_180 | 180 | 图片旋转180度。 | 2523| ROTATION_270 | 270 | 图片旋转270度。 | 2524 2525## Location 2526 2527图片地理位置信息。 2528 2529**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 2530 2531**系统能力:** SystemCapability.Multimedia.Camera.Core 2532 2533| 名称 | 类型 | 只读 | 可选 |说明 | 2534| ------------ | ------ | ---- |-----|------------ | 2535| latitude | number | 否 | 否 |纬度(度)。 | 2536| longitude | number | 否 | 否 |经度(度)。 | 2537| altitude | number | 否 | 否 |海拔(米)。 | 2538 2539## QualityLevel 2540 2541枚举,图片质量。 2542 2543**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 2544 2545**系统能力:** SystemCapability.Multimedia.Camera.Core 2546 2547| 名称 | 值 | 说明 | 2548| -------------------- | ---- | ------------ | 2549| QUALITY_LEVEL_HIGH | 0 | 图片质量高。 | 2550| QUALITY_LEVEL_MEDIUM | 1 | 图片质量中等。 | 2551| QUALITY_LEVEL_LOW | 2 | 图片质量差。 | 2552 2553 2554## PhotoCaptureSetting 2555 2556拍摄照片的设置。 2557 2558**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 2559 2560**系统能力:** SystemCapability.Multimedia.Camera.Core 2561 2562| 名称 | 类型 | 只读 | 可选 | 说明 | 2563| -------- | ------------------------------- | ---- | ---- |----------------------------------------------------------------------| 2564| quality | [QualityLevel](#qualitylevel) | 否 | 是 | 图片质量(默认低)。 | 2565| rotation | [ImageRotation](#imagerotation) | 否 | 是 | 图片旋转角度(默认0度,顺时针旋转)。 | 2566| location | [Location](#location) | 否 | 是 | 图片地理位置信息(默认以设备硬件信息为准)。 | 2567| mirror | boolean | 否 | 是 | 镜像使能开关(默认关)。使用之前需要使用[isMirrorSupported](#ismirrorsupported)进行判断是否支持。 | 2568 2569## Photo<sup>11+</sup> 2570 2571全质量图对象。 2572 2573### 属性 2574 2575**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 2576 2577**系统能力:** SystemCapability.Multimedia.Camera.Core 2578 2579| 名称 | 类型 | 必填 | 说明 | 2580| ------ | ----------------------------- | -------------- | ---------- | 2581| main<sup>11+</sup> | [image.Image](../apis-image-kit/arkts-apis-image-Image.md) | 是 | 全质量图Image。 | 2582 2583### release<sup>11+</sup> 2584 2585release(): Promise\<void\> 2586 2587释放输出资源,通过Promise获取结果。 2588 2589**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 2590 2591**系统能力:** SystemCapability.Multimedia.Camera.Core 2592 2593**返回值:** 2594 2595| 类型 | 说明 | 2596| -------------- | ----------------------- | 2597| Promise\<void\> | 无返回结果的Promise对象。 | 2598 2599**示例:** 2600 2601```ts 2602async function releasePhoto(photo: camera.Photo): Promise<void> { 2603 await photo.release(); 2604} 2605``` 2606 2607## PhotoOutput 2608 2609拍照会话中使用的输出信息,继承[CameraOutput](#cameraoutput)。 2610 2611### capture 2612 2613capture(callback: AsyncCallback\<void\>): void 2614 2615以默认设置触发一次拍照,通过注册回调函数获取结果。使用callback异步回调。 2616 2617**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 2618 2619**系统能力:** SystemCapability.Multimedia.Camera.Core 2620 2621**参数:** 2622 2623| 参数名 | 类型 | 必填 | 说明 | 2624| -------- | -------------------- | ---- | ------------------- | 2625| callback | AsyncCallback\<void\> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 2626 2627**错误码:** 2628 2629以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 2630 2631| 错误码ID | 错误信息 | 2632| --------------- | --------------- | 2633| 7400104 | Session not running. | 2634| 7400201 | Camera service fatal error. | 2635 2636**示例:** 2637 2638```ts 2639import { BusinessError } from '@kit.BasicServicesKit'; 2640 2641function capture(photoOutput: camera.PhotoOutput): void { 2642 photoOutput.capture((err: BusinessError) => { 2643 if (err) { 2644 console.error(`Failed to capture the photo, error code: ${err.code}.`); 2645 return; 2646 } 2647 console.info('Callback invoked to indicate the photo capture request success.'); 2648 }); 2649} 2650``` 2651 2652### capture 2653 2654capture(): Promise\<void\> 2655 2656以默认设置触发一次拍照,通过Promise获取结果。 2657 2658**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 2659 2660**系统能力:** SystemCapability.Multimedia.Camera.Core 2661 2662**返回值:** 2663 2664| 类型 | 说明 | 2665| -------------- | ------------------------ | 2666| Promise\<void\> | 无返回结果的Promise对象。 | 2667 2668**错误码:** 2669 2670以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 2671 2672| 错误码ID | 错误信息 | 2673| --------------- | --------------- | 2674| 7400104 | Session not running. | 2675| 7400201 | Camera service fatal error. | 2676 2677**示例:** 2678 2679```ts 2680import { BusinessError } from '@kit.BasicServicesKit'; 2681 2682function capture(photoOutput: camera.PhotoOutput): void { 2683 photoOutput.capture().then(() => { 2684 console.info('Promise returned to indicate that photo capture request success.'); 2685 }).catch((error: BusinessError) => { 2686 console.error(`Failed to photo output capture, error code: ${error.code}.`); 2687 }); 2688} 2689``` 2690 2691### capture 2692 2693capture(setting: PhotoCaptureSetting, callback: AsyncCallback\<void\>): void 2694 2695以指定参数触发一次拍照,通过注册回调函数获取结果。使用callback异步回调。 2696 2697**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 2698 2699**系统能力:** SystemCapability.Multimedia.Camera.Core 2700 2701**参数:** 2702 2703| 参数名 | 类型 | 必填 | 说明 | 2704| -------- | ------------------------------------------- | ---- | -------------------- | 2705| setting | [PhotoCaptureSetting](#photocapturesetting) | 是 | 拍照设置。 | 2706| callback | AsyncCallback\<void\> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 2707 2708**错误码:** 2709 2710以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 2711 2712| 错误码ID | 错误信息 | 2713| --------------- | --------------- | 2714| 7400101 | Parameter missing or parameter type incorrect. | 2715| 7400104 | Session not running. | 2716| 7400201 | Camera service fatal error. | 2717 2718**示例:** 2719 2720```ts 2721import { BusinessError } from '@kit.BasicServicesKit'; 2722 2723function capture(photoOutput: camera.PhotoOutput): void { 2724 let captureLocation: camera.Location = { 2725 latitude: 0, 2726 longitude: 0, 2727 altitude: 0 2728 } 2729 let settings: camera.PhotoCaptureSetting = { 2730 quality: camera.QualityLevel.QUALITY_LEVEL_LOW, 2731 rotation: camera.ImageRotation.ROTATION_0, 2732 location: captureLocation, 2733 mirror: false 2734 } 2735 photoOutput.capture(settings, (err: BusinessError) => { 2736 if (err) { 2737 console.error(`Failed to capture the photo, error code: ${err.code}.`); 2738 return; 2739 } 2740 console.info('Callback invoked to indicate the photo capture request success.'); 2741 }); 2742} 2743``` 2744 2745### capture 2746 2747capture(setting: PhotoCaptureSetting): Promise\<void\> 2748 2749以指定参数触发一次拍照,通过Promise获取结果。 2750 2751**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 2752 2753**系统能力:** SystemCapability.Multimedia.Camera.Core 2754 2755**参数:** 2756 2757| 参数名 | 类型 | 必填 | 说明 | 2758| ------- | ------------------------------------------- | ---- | -------- | 2759| setting | [PhotoCaptureSetting](#photocapturesetting) | 是 | 拍照设置,传入undefined类型数据按默认无参处理。 | 2760 2761**返回值:** 2762 2763| 类型 | 说明 | 2764| -------------- | ------------------------ | 2765| Promise\<void\> | 无返回结果的Promise对象。 | 2766 2767**错误码:** 2768 2769以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 2770 2771| 错误码ID | 错误信息 | 2772| --------------- | --------------- | 2773| 7400101 | Parameter missing or parameter type incorrect. | 2774| 7400104 | Session not running. | 2775| 7400201 | Camera service fatal error. | 2776 2777**示例:** 2778 2779```ts 2780import { BusinessError } from '@kit.BasicServicesKit'; 2781 2782function capture(photoOutput: camera.PhotoOutput): void { 2783 let captureLocation: camera.Location = { 2784 latitude: 0, 2785 longitude: 0, 2786 altitude: 0 2787 } 2788 let settings: camera.PhotoCaptureSetting = { 2789 quality: camera.QualityLevel.QUALITY_LEVEL_LOW, 2790 rotation: camera.ImageRotation.ROTATION_0, 2791 location: captureLocation, 2792 mirror: false 2793 } 2794 photoOutput.capture(settings).then(() => { 2795 console.info('Promise returned to indicate that photo capture request success.'); 2796 }).catch((error: BusinessError) => { 2797 console.error(`Failed to photo output capture, error code: ${error.code}.`); 2798 }); 2799} 2800``` 2801 2802### on('photoAvailable')<sup>11+</sup> 2803 2804on(type: 'photoAvailable', callback: AsyncCallback\<Photo\>): void 2805 2806注册监听全质量图上报。使用callback异步回调。 2807 2808> **说明:** 2809> 2810> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 2811 2812**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 2813 2814**系统能力:** SystemCapability.Multimedia.Camera.Core 2815 2816**参数:** 2817 2818| 参数名 | 类型 | 必填 | 说明 | 2819| -------- | ---------- | --- | ------------------------------------ | 2820| type | string | 是 | 监听事件,固定为'photoAvailable',photoOutput创建成功后可监听。 | 2821| callback | AsyncCallback\<[Photo](#photo11)\> | 是 | 回调函数,用于监听全质量图上报。 | 2822 2823**示例:** 2824 2825```ts 2826import { BusinessError } from '@kit.BasicServicesKit'; 2827import { image } from '@kit.ImageKit'; 2828 2829function callback(err: BusinessError, photo: camera.Photo): void { 2830 if (err !== undefined && err.code !== 0) { 2831 console.error(`Callback Error, errorCode: ${err.code}`); 2832 return; 2833 } 2834 let mainImage: image.Image = photo.main; 2835} 2836 2837function registerPhotoOutputPhotoAvailable(photoOutput: camera.PhotoOutput): void { 2838 photoOutput.on('photoAvailable', callback); 2839} 2840``` 2841 2842### off('photoAvailable')<sup>11+</sup> 2843 2844off(type: 'photoAvailable', callback?: AsyncCallback\<Photo\>): void 2845 2846注销监听全质量图上报。 2847 2848**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 2849 2850**系统能力:** SystemCapability.Multimedia.Camera.Core 2851 2852**参数:** 2853 2854| 参数名 | 类型 | 必填 | 说明 | 2855| -------- | ---------------------- | ---- | ------------------------------------------ | 2856| type | string | 是 | 监听事件,固定为'photoAvailable',photoOutput创建成功后可监听。 | 2857| callback | AsyncCallback\<[Photo](#photo11)\> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 2858 2859**示例:** 2860 2861```ts 2862import { BusinessError } from '@kit.BasicServicesKit'; 2863import { image } from '@kit.ImageKit'; 2864 2865function callback(err: BusinessError, photo: camera.Photo): void { 2866 if (err !== undefined && err.code !== 0) { 2867 console.error(`Callback Error, errorCode: ${err.code}`); 2868 return; 2869 } 2870 let mainImage: image.Image = photo.main; 2871} 2872 2873function unRegisterPhotoOutputPhotoAvailable(photoOutput: camera.PhotoOutput): void { 2874 photoOutput.off('photoAvailable', callback); 2875} 2876``` 2877 2878### on('captureStartWithInfo')<sup>11+</sup> 2879 2880on(type: 'captureStartWithInfo', callback: AsyncCallback\<CaptureStartInfo\>): void 2881 2882监听拍照开始,通过注册回调函数获取[CaptureStartInfo](#capturestartinfo11)。使用callback异步回调。 2883 2884> **说明:** 2885> 2886> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 2887 2888**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 2889 2890**系统能力:** SystemCapability.Multimedia.Camera.Core 2891 2892**参数:** 2893 2894| 参数名 | 类型 | 必填 | 说明 | 2895| -------- | ---------- | --- | ------------------------------------ | 2896| type | string | 是 | 监听事件,固定为'captureStartWithInfo',photoOutput创建成功后可监听。 | 2897| callback | AsyncCallback\<[CaptureStartInfo](#capturestartinfo11)\> | 是 | 使用callback的方式获取Capture ID。| 2898 2899**示例:** 2900 2901```ts 2902import { BusinessError } from '@kit.BasicServicesKit'; 2903 2904function callback(err: BusinessError, captureStartInfo: camera.CaptureStartInfo): void { 2905 if (err !== undefined && err.code !== 0) { 2906 console.error(`Callback Error, errorCode: ${err.code}`); 2907 return; 2908 } 2909 console.info(`photo capture started, captureStartInfo : ${captureStartInfo}`); 2910} 2911 2912function registerCaptureStartWithInfo(photoOutput: camera.PhotoOutput): void { 2913 photoOutput.on('captureStartWithInfo', callback); 2914} 2915``` 2916 2917### off('captureStartWithInfo')<sup>11+</sup> 2918 2919off(type: 'captureStartWithInfo', callback?: AsyncCallback\<CaptureStartInfo\>): void 2920 2921注销监听拍照。 2922 2923**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 2924 2925**系统能力:** SystemCapability.Multimedia.Camera.Core 2926 2927**参数:** 2928 2929| 参数名 | 类型 | 必填 | 说明 | 2930| -------- | ---------------------- | ---- | ------------------------------------------ | 2931| type | string | 是 | 监听事件,固定为'captureStartWithInfo',photoOutput创建成功后可监听。 | 2932| callback | AsyncCallback\<[CaptureStartInfo](#capturestartinfo11)\> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 2933 2934**示例:** 2935 2936```ts 2937import { BusinessError } from '@kit.BasicServicesKit'; 2938 2939function unRegisterCaptureStartWithInfo(photoOutput: camera.PhotoOutput): void { 2940 photoOutput.off('captureStartWithInfo'); 2941} 2942``` 2943 2944### isMovingPhotoSupported<sup>12+</sup> 2945 2946isMovingPhotoSupported(): boolean 2947 2948查询是否支持动态照片拍摄。 2949 2950**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 2951 2952**系统能力:** SystemCapability.Multimedia.Camera.Core 2953 2954**返回值:** 2955 2956| 类型 | 说明 | 2957| -------------- | ----------------------- | 2958| boolean | 返回是否支持动态照片拍照。true表示支持,false表示不支持。 | 2959 2960**错误码:** 2961 2962以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 2963 2964| 错误码ID | 错误信息 | 2965| -------------- | --------------- | 2966| 7400201 | Camera service fatal error. | 2967 2968**示例:** 2969 2970```ts 2971import { BusinessError } from '@kit.BasicServicesKit'; 2972 2973function isMovingPhotoSupported(photoOutput: camera.PhotoOutput): boolean { 2974 let isSupported: boolean = false; 2975 try { 2976 isSupported = photoOutput.isMovingPhotoSupported(); 2977 } catch (error) { 2978 // 失败返回错误码error.code并处理。 2979 let err = error as BusinessError; 2980 console.error(`The isMovingPhotoSupported call failed. error code: ${err.code}`); 2981 } 2982 return isSupported; 2983} 2984``` 2985 2986### enableMovingPhoto<sup>12+</sup> 2987 2988enableMovingPhoto(enabled: boolean): void 2989 2990使能动态照片拍照。 2991 2992**需要权限:** ohos.permission.MICROPHONE 2993 2994**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 2995 2996**系统能力:** SystemCapability.Multimedia.Camera.Core 2997 2998**参数:** 2999 3000| 参数名 | 类型 | 必填 | 说明 | 3001| -------- | ---------------------- | ---- | ------------------------------------------ | 3002| enabled | boolean | 是 | 使能动态照片拍照。true为开启动态照片,false为关闭动态照片。 | 3003 3004**错误码:** 3005 3006以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 3007 3008| 错误码ID | 错误信息 | 3009| -------- |------------------------------------------------| 3010| 201 | permission denied. | 3011| 7400101 | Parameter missing or parameter type incorrect. | 3012| 7400201 | Camera service fatal error. | 3013 3014**示例:** 3015 3016```ts 3017import { BusinessError } from '@kit.BasicServicesKit'; 3018 3019function enableMovingPhoto(photoOutput: camera.PhotoOutput): void { 3020 try { 3021 photoOutput.enableMovingPhoto(true); 3022 } catch (error) { 3023 // 失败返回错误码error.code并处理。 3024 let err = error as BusinessError; 3025 console.error(`The enableMovingPhoto call failed. error code: ${err.code}`); 3026 } 3027} 3028``` 3029 3030### on('photoAssetAvailable')<sup>12+</sup> 3031 3032on(type: 'photoAssetAvailable', callback: AsyncCallback\<photoAccessHelper.PhotoAsset\>): void 3033 3034注册监听photoAsset上报。使用callback异步回调。 3035 3036> **说明:** 3037> 3038> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 3039 3040**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 3041 3042**系统能力:** SystemCapability.Multimedia.Camera.Core 3043 3044**参数:** 3045 3046| 参数名 | 类型 | 必填 | 说明 | 3047| -------- | ---------- | --- | ------------------------------------ | 3048| type | string | 是 | 监听事件,固定为'photoAssetAvailable',photoOutput创建成功后可监听。 | 3049| callback | AsyncCallback\<[photoAccessHelper.PhotoAsset](../apis-media-library-kit/js-apis-photoAccessHelper.md#photoasset)\> | 是 | 回调函数,用于监听photoAsset上报。 | 3050 3051**示例:** 3052 3053```ts 3054import { BusinessError } from '@kit.BasicServicesKit'; 3055import { photoAccessHelper } from '@kit.MediaLibraryKit'; 3056 3057function photoAssetAvailableCallback(err: BusinessError, photoAsset: photoAccessHelper.PhotoAsset): void { 3058 if (err) { 3059 console.info(`photoAssetAvailable error: ${JSON.stringify(err)}.`); 3060 return; 3061 } 3062 console.info('photoOutPutCallBack photoAssetAvailable'); 3063 // 开发者可通过photoAsset获取图片相关信息。 3064} 3065 3066function onPhotoOutputPhotoAssetAvailable(photoOutput: camera.PhotoOutput): void { 3067 photoOutput.on('photoAssetAvailable', photoAssetAvailableCallback); 3068} 3069``` 3070 3071### off('photoAssetAvailable')<sup>12+</sup> 3072 3073off(type: 'photoAssetAvailable', callback?: AsyncCallback\<photoAccessHelper.PhotoAsset\>): void 3074 3075注销photoAsset上报。 3076 3077**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 3078 3079**系统能力:** SystemCapability.Multimedia.Camera.Core 3080 3081**参数:** 3082 3083| 参数名 | 类型 | 必填 | 说明 | 3084| -------- | ---------- |-----|----------------------------------------------------------------------------| 3085| type | string | 是 | 监听事件,固定为'photoAssetAvailable',photoOutput创建成功后可监听。 | 3086| callback | AsyncCallback\<[photoAccessHelper.PhotoAsset](../apis-media-library-kit/js-apis-photoAccessHelper.md#photoasset)\> | 否 | 需要解监听的回调方法。如果callback不为空且与此对应的监听方法一致,不为匿名方法,则解注册该方法;如果callback为空,则解监听所有回调。 | 3087 3088**示例:** 3089 3090```ts 3091function offPhotoOutputPhotoAssetAvailable(photoOutput: camera.PhotoOutput): void { 3092 photoOutput.off('photoAssetAvailable'); 3093} 3094``` 3095 3096### isMirrorSupported 3097 3098isMirrorSupported(): boolean 3099 3100查询是否支持镜像拍照。 3101 3102**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 3103 3104**系统能力:** SystemCapability.Multimedia.Camera.Core 3105 3106**返回值:** 3107 3108| 类型 | 说明 | 3109| -------------- | ----------------------- | 3110| boolean | 返回是否支持镜像拍照,true表示支持,false表示不支持。 | 3111 3112**示例:** 3113 3114```ts 3115function isMirrorSupported(photoOutput: camera.PhotoOutput): boolean { 3116 let isSupported: boolean = photoOutput.isMirrorSupported(); 3117 return isSupported; 3118} 3119``` 3120 3121### enableMirror<sup>13+</sup> 3122 3123enableMirror(enabled: boolean): void 3124 3125是否启用动态照片镜像拍照。 3126 3127调用该接口前,需要通过[isMovingPhotoSupported](#ismovingphotosupported12)查询是否支持动态照片拍摄功能以及通过[isMirrorSupported](#ismirrorsupported)查询是否支持镜像拍照功能。 3128 3129**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 3130 3131**系统能力:** SystemCapability.Multimedia.Camera.Core 3132 3133**参数:** 3134 3135| 参数名 | 类型 | 必填 | 说明 | 3136|----------| ---------------------- | ---- |---------------------------| 3137| enabled | boolean | 是 | 是否启用动态照片镜像拍照。true为开启动态照片镜像拍照,false为关闭动态照片镜像拍照。 | 3138 3139**错误码:** 3140 3141以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 3142 3143| 错误码ID | 错误信息 | 3144| -------- |------------------------------------------------| 3145| 7400101 | Parameter missing or parameter type incorrect. | 3146| 7400103 | Session not config. | 3147| 7400201 | Camera service fatal error. | 3148 3149 3150**示例:** 3151 3152```ts 3153import { BusinessError } from '@kit.BasicServicesKit'; 3154 3155function enableMirror(photoOutput: camera.PhotoOutput): void { 3156 try { 3157 photoOutput.enableMirror(true); 3158 } catch (error) { 3159 // 失败返回错误码error.code并处理。 3160 let err = error as BusinessError; 3161 console.error(`The enableMirror call failed. error code: ${err.code}`); 3162 } 3163} 3164``` 3165 3166### getSupportedMovingPhotoVideoCodecTypes<sup>13+</sup> 3167 3168getSupportedMovingPhotoVideoCodecTypes(): Array\<VideoCodecType\> 3169 3170查询支持的动态照片短视频编码类型。 3171 3172**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 3173 3174**系统能力:** SystemCapability.Multimedia.Camera.Core 3175 3176**返回值:** 3177 3178| 类型 | 说明 | 3179| -------------- |-------------------| 3180| Array\<[VideoCodecType](#videocodectype13)\> | 支持的动态照片短视频编码类型列表。 | 3181 3182**错误码:** 3183 3184以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 3185 3186| 错误码ID | 错误信息 | 3187| --------------- | --------------- | 3188| 7400201 | Camera service fatal error. | 3189 3190**示例:** 3191 3192```ts 3193function getSupportedMovingPhotoVideoCodecType(photoOutput: camera.PhotoOutput): Array<camera.VideoCodecType> { 3194 let supportedVideoCodecTypesArray: Array<camera.VideoCodecType> = photoOutput.getSupportedMovingPhotoVideoCodecTypes(); 3195 return supportedVideoCodecTypesArray; 3196} 3197``` 3198 3199### setMovingPhotoVideoCodecType<sup>13+</sup> 3200 3201setMovingPhotoVideoCodecType(codecType: VideoCodecType): void 3202 3203设置动态照片短视频编码类型。 3204 3205**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 3206 3207**系统能力:** SystemCapability.Multimedia.Camera.Core 3208 3209**参数:** 3210 3211| 参数名 | 类型 | 必填 | 说明 | 3212| ------------- |-------------------------------------|-------| ------------ | 3213| codecType | [VideoCodecType](#videocodectype13) | 是 |获取动态照片短视频编码类型。 | 3214 3215**错误码:** 3216 3217以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 3218 3219| 错误码ID | 错误信息 | 3220| --------------- | --------------- | 3221| 7400201 | Camera service fatal error. | 3222 3223**示例:** 3224 3225```ts 3226function setMovingPhotoVideoCodecTypes(photoOutput: camera.PhotoOutput, videoCodecType: camera.VideoCodecType): void { 3227 photoOutput.setMovingPhotoVideoCodecType(videoCodecType); 3228} 3229``` 3230 3231### on('captureStart')<sup>(deprecated)</sup> 3232 3233on(type: 'captureStart', callback: AsyncCallback\<number\>): void 3234 3235监听拍照开始,通过注册回调函数获取Capture ID。使用callback异步回调。 3236 3237> **说明:** 3238> 从 API version 10开始支持,从API version 11开始废弃。建议使用[on('captureStartWithInfo')](#oncapturestartwithinfo11)替代。 3239> 3240> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 3241 3242**系统能力:** SystemCapability.Multimedia.Camera.Core 3243 3244**参数:** 3245 3246| 参数名 | 类型 | 必填 | 说明 | 3247| -------- | ---------------------- | ---- | ------------------------------------------ | 3248| type | string | 是 | 监听事件,固定为'captureStart',photoOutput创建成功后可监听。每次拍照,底层开始曝光时触发该事件并返回。 | 3249| callback | AsyncCallback\<number\> | 是 | 使用callback的方式获取Capture ID。 | 3250 3251**示例:** 3252 3253```ts 3254import { BusinessError } from '@kit.BasicServicesKit'; 3255 3256function callback(err: BusinessError, captureId: number): void { 3257 if (err !== undefined && err.code !== 0) { 3258 console.error(`Callback Error, errorCode: ${err.code}`); 3259 return; 3260 } 3261 console.info(`photo capture started, captureId : ${captureId}`); 3262} 3263 3264function registerPhotoOutputCaptureStart(photoOutput: camera.PhotoOutput): void { 3265 photoOutput.on('captureStart', callback); 3266} 3267``` 3268 3269### off('captureStart')<sup>(deprecated)</sup> 3270 3271off(type: 'captureStart', callback?: AsyncCallback\<number\>): void 3272 3273注销拍照开始的监听。 3274 3275> **说明:** 3276> 从 API version 10开始支持,从API version 11开始废弃。建议使用[off('captureStartWithInfo')](#offcapturestartwithinfo11)替代。 3277> 3278> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 3279 3280**系统能力:** SystemCapability.Multimedia.Camera.Core 3281 3282**参数:** 3283 3284| 参数名 | 类型 | 必填 | 说明 | 3285| -------- | ---------------------- | ---- | ------------------------------------------ | 3286| type | string | 是 | 监听事件,固定为'captureStart',photoOutput创建成功后可监听。 | 3287| callback | AsyncCallback\<number\> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 3288 3289**示例:** 3290 3291```ts 3292function unregisterPhotoOutputCaptureStart(photoOutput: camera.PhotoOutput): void { 3293 photoOutput.off('captureStart'); 3294} 3295``` 3296 3297### on('frameShutter') 3298 3299on(type: 'frameShutter', callback: AsyncCallback\<FrameShutterInfo\>): void 3300 3301监听拍照帧输出捕获,通过注册回调函数获取结果。使用callback异步回调。 3302 3303**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 3304 3305**系统能力:** SystemCapability.Multimedia.Camera.Core 3306 3307**参数:** 3308 3309| 参数名 | 类型 | 必填 | 说明 | 3310| -------- | ---------- | --- | ------------------------------------ | 3311| type | string | 是 | 监听事件,固定为'frameShutter',photoOutput创建成功后可监听。 | 3312| callback | AsyncCallback\<[FrameShutterInfo](#frameshutterinfo)\> | 是 | 回调函数,用于获取相关信息。该回调返回意味着可以再次下发拍照请求。 | 3313 3314**示例:** 3315 3316```ts 3317import { BusinessError } from '@kit.BasicServicesKit'; 3318 3319function callback(err: BusinessError, frameShutterInfo: camera.FrameShutterInfo): void { 3320 if (err !== undefined && err.code !== 0) { 3321 console.error(`Callback Error, errorCode: ${err.code}`); 3322 return; 3323 } 3324 console.info(`CaptureId for frame : ${frameShutterInfo.captureId}`); 3325 console.info(`Timestamp for frame : ${frameShutterInfo.timestamp}`); 3326} 3327 3328function registerPhotoOutputFrameShutter(photoOutput: camera.PhotoOutput): void { 3329 photoOutput.on('frameShutter', callback); 3330} 3331``` 3332 3333### off('frameShutter') 3334 3335off(type: 'frameShutter', callback?: AsyncCallback\<FrameShutterInfo\>): void 3336 3337注销监听拍照帧输出捕获。 3338 3339**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 3340 3341**系统能力:** SystemCapability.Multimedia.Camera.Core 3342 3343**参数:** 3344 3345| 参数名 | 类型 | 必填 | 说明 | 3346| -------- | ---------- | --- | ------------------------------------ | 3347| type | string | 是 | 监听事件,固定为'frameShutter',photoOutput创建成功后可监听。 | 3348| callback | AsyncCallback\<[FrameShutterInfo](#frameshutterinfo)\> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 3349 3350**示例:** 3351 3352```ts 3353function unregisterPhotoOutputFrameShutter(photoOutput: camera.PhotoOutput): void { 3354 photoOutput.off('frameShutter'); 3355} 3356``` 3357 3358### on('captureEnd') 3359 3360on(type: 'captureEnd', callback: AsyncCallback\<CaptureEndInfo\>): void 3361 3362监听拍照结束,通过注册回调函数获取结果。使用callback异步回调。 3363 3364> **说明:** 3365> 3366> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 3367 3368**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 3369 3370**系统能力:** SystemCapability.Multimedia.Camera.Core 3371 3372**参数:** 3373 3374| 参数名 | 类型 | 必填 | 说明 | 3375| -------- | --------------- | ---- | ---------------------------------------- | 3376| type | string | 是 | 监听事件,固定为'captureEnd'。photoOutput创建成功后可监听。拍照完全结束可触发该事件发生并返回相应信息。 | 3377| callback | AsyncCallback\<[CaptureEndInfo](#captureendinfo)\> | 是 | 回调函数,用于获取相关信息。 | 3378 3379**示例:** 3380 3381```ts 3382import { BusinessError } from '@kit.BasicServicesKit'; 3383 3384function callback(err: BusinessError, captureEndInfo: camera.CaptureEndInfo): void { 3385 if (err !== undefined && err.code !== 0) { 3386 console.error(`Callback Error, errorCode: ${err.code}`); 3387 return; 3388 } 3389 console.info(`photo capture end, captureId : ${captureEndInfo.captureId}`); 3390 console.info(`frameCount : ${captureEndInfo.frameCount}`); 3391} 3392 3393function registerPhotoOutputCaptureEnd(photoOutput: camera.PhotoOutput): void { 3394 photoOutput.on('captureEnd', callback); 3395} 3396``` 3397 3398### off('captureEnd') 3399 3400off(type: 'captureEnd', callback?: AsyncCallback\<CaptureEndInfo\>): void 3401 3402注销监听拍照结束。 3403 3404**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 3405 3406**系统能力:** SystemCapability.Multimedia.Camera.Core 3407 3408**参数:** 3409 3410| 参数名 | 类型 | 必填 | 说明 | 3411| -------- | --------------- | ---- | ---------------------------------------- | 3412| type | string | 是 | 监听事件,固定为'captureEnd',photoOutput创建成功后可监听。 | 3413| callback | AsyncCallback\<[CaptureEndInfo](#captureendinfo)\> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 3414 3415**示例:** 3416 3417```ts 3418function unregisterPhotoOutputCaptureEnd(photoOutput: camera.PhotoOutput): void { 3419 photoOutput.off('captureEnd'); 3420} 3421``` 3422 3423### on('frameShutterEnd')<sup>12+</sup> 3424 3425on(type: 'frameShutterEnd', callback: AsyncCallback\<FrameShutterEndInfo\>): void 3426 3427监听拍照曝光结束捕获,通过注册回调函数获取结果。使用callback异步回调。 3428 3429> **说明:** 3430> 3431> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 3432 3433**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 3434 3435**系统能力:** SystemCapability.Multimedia.Camera.Core 3436 3437**参数:** 3438 3439| 参数名 | 类型 | 必填 | 说明 | 3440| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 3441| type | string | 是 | 监听事件,固定为'frameShutterEnd',photoOutput创建成功后可监听。 | 3442| callback | AsyncCallback\<[FrameShutterEndInfo](#frameshutterendinfo12)\> | 是 | 回调函数,用于获取相关信息。该回调返回表示拍照曝光结束。 | 3443 3444**示例:** 3445 3446```ts 3447import { BusinessError } from '@kit.BasicServicesKit'; 3448 3449function callback(err: BusinessError, frameShutterEndInfo: camera.FrameShutterEndInfo): void { 3450 if (err !== undefined && err.code !== 0) { 3451 console.error(`Callback Error, errorCode: ${err.code}`); 3452 return; 3453 } 3454 console.info(`CaptureId for frame : ${frameShutterEndInfo.captureId}`); 3455} 3456 3457function registerPhotoOutputFrameShutterEnd(photoOutput: camera.PhotoOutput): void { 3458 photoOutput.on('frameShutterEnd', callback); 3459} 3460``` 3461 3462### off('frameShutterEnd')<sup>12+</sup> 3463 3464off(type: 'frameShutterEnd', callback?: AsyncCallback\<FrameShutterEndInfo\>): void 3465 3466注销监听拍照帧输出捕获。 3467 3468**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 3469 3470**系统能力:** SystemCapability.Multimedia.Camera.Core 3471 3472**参数:** 3473 3474| 参数名 | 类型 | 必填 | 说明 | 3475| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 3476| type | string | 是 | 监听事件,固定为'frameShutterEnd',photoOutput创建成功后可监听。 | 3477| callback | AsyncCallback\<[FrameShutterEndInfo](#frameshutterendinfo12)\> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 3478 3479**示例:** 3480 3481```ts 3482function unregisterPhotoOutputFrameShutterEnd(photoOutput: camera.PhotoOutput): void { 3483 photoOutput.off('frameShutterEnd'); 3484} 3485``` 3486 3487### on('captureReady')<sup>12+</sup> 3488 3489on(type: 'captureReady', callback: AsyncCallback\<void\>): void 3490 3491监听可拍下一张,通过注册回调函数获取结果。使用callback异步回调。 3492 3493> **说明:** 3494> 3495> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 3496 3497**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 3498 3499**系统能力:** SystemCapability.Multimedia.Camera.Core 3500 3501**参数:** 3502 3503| 参数名 | 类型 | 必填 | 说明 | 3504| -------- | --------------------- | ---- | ------------------------------------------------------------ | 3505| type | string | 是 | 监听事件,固定为'captureReady',photoOutput创建成功后可监听。当下一张可拍时可触发该事件发生并返回相应信息。 | 3506| callback | AsyncCallback\<void\> | 是 | 回调函数,用于获取相关信息。 | 3507 3508**示例:** 3509 3510```ts 3511import { BusinessError } from '@kit.BasicServicesKit'; 3512 3513function callback(err: BusinessError): void { 3514 if (err !== undefined && err.code !== 0) { 3515 console.error(`Callback Error, errorCode: ${err.code}`); 3516 return; 3517 } 3518 console.info(`photo capture ready`); 3519} 3520 3521function registerPhotoOutputCaptureReady(photoOutput: camera.PhotoOutput): void { 3522 photoOutput.on('captureReady', callback); 3523} 3524``` 3525 3526### off('captureReady')<sup>12+</sup> 3527 3528off(type: 'captureReady', callback?: AsyncCallback\<void\>): void 3529 3530注销监听可拍下一张。 3531 3532**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 3533 3534**系统能力:** SystemCapability.Multimedia.Camera.Core 3535 3536**参数:** 3537 3538| 参数名 | 类型 | 必填 | 说明 | 3539| -------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------ | 3540| type | string | 是 | 监听事件,固定为'captureReady',photoOutput创建成功后可监听。 | 3541| callback | AsyncCallback\<[CaptureReadyInfo](#captureendinfo)\> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 3542 3543**示例:** 3544 3545```ts 3546function unregisterPhotoOutputCaptureReady(photoOutput: camera.PhotoOutput): void { 3547 photoOutput.off('captureReady'); 3548} 3549``` 3550 3551### on('estimatedCaptureDuration')<sup>12+</sup> 3552 3553on(type: 'estimatedCaptureDuration', callback: AsyncCallback\<number\>): void 3554 3555监听预估的拍照时间,通过注册回调函数获取结果。使用callback异步回调。 3556 3557> **说明:** 3558> 3559> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 3560 3561**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 3562 3563**系统能力:** SystemCapability.Multimedia.Camera.Core 3564 3565**参数:** 3566 3567| 参数名 | 类型 | 必填 | 说明 | 3568| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 3569| type | string | 是 | 监听事件,固定为'estimatedCaptureDuration',photoOutput创建成功后可监听。拍照完全结束可触发该事件发生并返回相应信息。 | 3570| callback | AsyncCallback\<number> | 是 | 回调函数,用于获取预估的单次拍照底层出sensor采集帧时间,如果上报-1,代表没有预估时间。 | 3571 3572**示例:** 3573 3574```ts 3575import { BusinessError } from '@kit.BasicServicesKit'; 3576 3577function callback(err: BusinessError, duration: number): void { 3578 if (err !== undefined && err.code !== 0) { 3579 console.error(`Callback Error, errorCode: ${err.code}`); 3580 return; 3581 } 3582 console.info(`photo estimated capture duration : ${duration}`); 3583} 3584 3585function registerPhotoOutputEstimatedCaptureDuration(photoOutput: camera.PhotoOutput): void { 3586 photoOutput.on('estimatedCaptureDuration', callback); 3587} 3588``` 3589 3590### off('estimatedCaptureDuration')<sup>12+</sup> 3591 3592off(type: 'estimatedCaptureDuration', callback?: AsyncCallback\<number\>): void 3593 3594注销监听预估的拍照时间。 3595 3596**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 3597 3598**系统能力:** SystemCapability.Multimedia.Camera.Core 3599 3600**参数:** 3601 3602| 参数名 | 类型 | 必填 | 说明 | 3603| -------- | ----------------------- | ---- | ------------------------------------------------------------ | 3604| type | string | 是 | 监听事件,固定为'estimatedCaptureDuration',photoOutput创建成功后可监听。 | 3605| callback | AsyncCallback\<number\> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 3606 3607**示例:** 3608 3609```ts 3610function unregisterPhotoOutputEstimatedCaptureDuration(photoOutput: camera.PhotoOutput): void { 3611 photoOutput.off('estimatedCaptureDuration'); 3612} 3613``` 3614 3615### on('error') 3616 3617on(type: 'error', callback: ErrorCallback): void 3618 3619监听拍照输出发生错误,通过注册回调函数获取结果。使用callback异步回调。 3620 3621> **说明:** 3622> 3623> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 3624 3625**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 3626 3627**系统能力:** SystemCapability.Multimedia.Camera.Core 3628 3629**参数:** 3630 3631| 参数名 | 类型 | 必填 | 说明 | 3632| -------- | ------------- | ---- | ----------------------------------- | 3633| type | string | 是 | 监听事件,固定为'error',photoOutput创建成功后可监听。拍照接口调用时出现错误触发该事件并返回错误信息。 | 3634| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | 是 | 回调函数,用于获取错误信息。返回错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 3635 3636**示例:** 3637 3638```ts 3639import { BusinessError } from '@kit.BasicServicesKit'; 3640 3641function callback(err: BusinessError): void { 3642 console.error(`Photo output error code: ${err.code}`); 3643} 3644 3645function registerPhotoOutputError(photoOutput: camera.PhotoOutput): void { 3646 photoOutput.on('error', callback); 3647} 3648``` 3649 3650### off('error') 3651 3652off(type: 'error', callback?: ErrorCallback): void 3653 3654注销监听拍照输出发生错误。 3655 3656**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 3657 3658**系统能力:** SystemCapability.Multimedia.Camera.Core 3659 3660**参数:** 3661 3662| 参数名 | 类型 | 必填 | 说明 | 3663| -------- | ------------- | ---- | ----------------------------------- | 3664| type | string | 是 | 监听事件,固定为'error',photoOutput创建成功后可监听。 | 3665| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 3666 3667**示例:** 3668 3669```ts 3670function unregisterPhotoOutputError(photoOutput: camera.PhotoOutput): void { 3671 photoOutput.off('error'); 3672} 3673``` 3674 3675### getActiveProfile<sup>12+</sup> 3676 3677getActiveProfile(): Profile 3678 3679获取当前生效的配置信息。 3680 3681**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 3682 3683**系统能力:** SystemCapability.Multimedia.Camera.Core 3684 3685**返回值:** 3686 3687| 类型 | 说明 | 3688| ------------- |-----------| 3689| [Profile](#profile) | 当前生效的配置信息 | 3690 3691**错误码:** 3692 3693以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 3694 3695| 错误码ID | 错误信息 | 3696|---------|------------------------------| 3697| 7400201 | Camera service fatal error. | 3698 3699**示例:** 3700 3701```ts 3702function testGetActiveProfile(photoOutput: camera.PhotoOutput): camera.Profile | undefined { 3703 let activeProfile: camera.Profile | undefined = undefined; 3704 try { 3705 activeProfile = photoOutput.getActiveProfile(); 3706 } catch (error) { 3707 // 失败返回错误码error.code并处理。 3708 let err = error as BusinessError; 3709 console.error(`The photoOutput.getActiveProfile call failed. error code: ${err.code}`); 3710 } 3711 return activeProfile; 3712} 3713``` 3714### getPhotoRotation<sup>12+</sup> 3715 3716getPhotoRotation(deviceDegree: number): ImageRotation 3717 3718获取拍照旋转角度。 3719 3720- 设备自然方向:设备默认使用方向,手机为竖屏(充电口向下)。 3721- 相机镜头角度:值等于相机图像顺时针旋转到设备自然方向的角度,手机后置相机传感器是横屏安装的,所以需要顺时针旋转90度到设备自然方向。 3722- 屏幕显示方向:需要屏幕显示的图片左上角为第一个像素点为坐标原点。锁屏时与自然方向一致。 3723 3724**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 3725 3726**系统能力:** SystemCapability.Multimedia.Camera.Core 3727 3728**参数:** 3729 3730| 参数名 | 类型 | 必填 | 说明 | 3731| -------- | --------------| ---- | ------------------------ | 3732| deviceDegree | number | 是 | 设备旋转角度 | 3733 3734**返回值:** 3735 3736| 类型 | 说明 | 3737| ------------- |-----------| 3738| [ImageRotation](#imagerotation) | 获取拍照旋转角度。 | 3739 3740**错误码:** 3741 3742以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 3743 3744| 错误码ID | 错误信息 | 3745|---------|------------------------------| 3746| 7400101 | Parameter missing or parameter type incorrect. | 3747| 7400201 | Camera service fatal error. | 3748 3749**示例:** 3750 3751```ts 3752function testGetPhotoRotation(photoOutput: camera.PhotoOutput, deviceDegree : number): camera.ImageRotation { 3753 let photoRotation: camera.ImageRotation = camera.ImageRotation.ROTATION_0; 3754 try { 3755 photoRotation = photoOutput.getPhotoRotation(deviceDegree); 3756 console.log(`Photo rotation is: ${photoRotation}`); 3757 } catch (error) { 3758 // 失败返回错误码error.code并处理。 3759 let err = error as BusinessError; 3760 console.error(`The photoOutput.getPhotoRotation call failed. error code: ${err.code}`); 3761 } 3762 return photoRotation; 3763} 3764``` 3765 3766## FrameShutterInfo 3767 3768拍照帧输出信息。 3769 3770**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 3771 3772**系统能力:** SystemCapability.Multimedia.Camera.Core 3773 3774| 名称 | 类型 | 只读 | 可选 | 说明 | 3775| --------- | ------ | ---- | ---- | ---------- | 3776| captureId | number | 否 | 否 | 拍照的ID。| 3777| timestamp | number | 否 | 否 | 快门时间戳。| 3778 3779## FrameShutterEndInfo<sup>12+</sup> 3780 3781拍照曝光结束信息。 3782 3783**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 3784 3785**系统能力:** SystemCapability.Multimedia.Camera.Core 3786 3787| 名称 | 类型 | 只读 | 可选 | 说明 | 3788| --------- | ------ | ---- | ---- | ---------- | 3789| captureId | number | 否 | 否 | 拍照的ID。| 3790 3791## CaptureStartInfo<sup>11+</sup> 3792 3793拍照开始信息。 3794 3795**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 3796 3797**系统能力:** SystemCapability.Multimedia.Camera.Core 3798 3799| 名称 | 类型 | 只读 | 可选 | 说明 | 3800| ---------- | ------ | ---- | ---- | --------- | 3801| captureId | number | 否 | 否 | 拍照的ID。| 3802| time | number | 否 | 否 | 预估的单次拍照底层出sensor采集帧时间,如果上报-1,代表没有预估时间。 | 3803 3804## CaptureEndInfo 3805 3806拍照停止信息。 3807 3808**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 3809 3810**系统能力:** SystemCapability.Multimedia.Camera.Core 3811 3812| 名称 | 类型 | 只读 | 可选 | 说明 | 3813| ---------- | ------ | ---- | ---- | ---------| 3814| captureId | number | 否 | 否 | 拍照的ID。| 3815| frameCount | number | 否 | 否 | 帧数。| 3816 3817## AutoDeviceSwitchStatus<sup>13+</sup> 3818 3819自动切换镜头状态信息。 3820 3821**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 3822 3823**系统能力:** SystemCapability.Multimedia.Camera.Core 3824 3825| 名称 | 类型 | 只读 | 可选 | 说明 | 3826| ---------- |---------| ---- | ---- |-------------------------| 3827| isDeviceSwitched | boolean | 否 | 否 | 自动切换镜头是否成功。true表示成功,false表示失败。 | 3828| isDeviceCapabilityChanged | boolean | 否 | 否 | 自动切换镜头成功后,其镜头能力值是否发生改变。true表示发生变化,false表示未发生变化。 | 3829 3830## VideoOutput 3831 3832录像会话中使用的输出信息,继承[CameraOutput](#cameraoutput)。 3833 3834### start 3835 3836start(callback: AsyncCallback\<void\>): void 3837 3838启动录制,通过注册回调函数获取结果。使用callback异步回调。 3839 3840**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 3841 3842**系统能力:** SystemCapability.Multimedia.Camera.Core 3843 3844**参数:** 3845 3846| 参数名 | 类型 | 必填 | 说明 | 3847| -------- | -------------------- | ---- | -------------------- | 3848| callback | AsyncCallback\<void\> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 3849 3850**错误码:** 3851 3852以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 3853 3854| 错误码ID | 错误信息 | 3855| --------------- | --------------- | 3856| 7400103 | Session not config. | 3857| 7400201 | Camera service fatal error. | 3858 3859**示例:** 3860 3861```ts 3862import { BusinessError } from '@kit.BasicServicesKit'; 3863 3864function startVideoOutput(videoOutput: camera.VideoOutput): void { 3865 videoOutput.start((err: BusinessError) => { 3866 if (err) { 3867 console.error(`Failed to start the video output, error code: ${err.code}.`); 3868 return; 3869 } 3870 console.info('Callback invoked to indicate the video output start success.'); 3871 }); 3872} 3873``` 3874 3875### start 3876 3877start(): Promise\<void\> 3878 3879启动录制,通过Promise获取结果。 3880 3881**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 3882 3883**系统能力:** SystemCapability.Multimedia.Camera.Core 3884 3885**返回值:** 3886 3887| 类型 | 说明 | 3888| -------------- | ----------------------- | 3889| Promise\<void\> | 无返回结果的Promise对象。 | 3890 3891**错误码:** 3892 3893以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 3894 3895| 错误码ID | 错误信息 | 3896| --------------- | --------------- | 3897| 7400103 | Session not config. | 3898| 7400201 | Camera service fatal error. | 3899 3900**示例:** 3901 3902```ts 3903import { BusinessError } from '@kit.BasicServicesKit'; 3904 3905function startVideoOutput(videoOutput: camera.VideoOutput): void { 3906 videoOutput.start().then(() => { 3907 console.info('Promise returned to indicate that start method execution success.'); 3908 }).catch((error: BusinessError) => { 3909 console.error(`Failed to video output start, error code: ${error.code}.`); 3910 }); 3911} 3912``` 3913 3914### stop 3915 3916stop(callback: AsyncCallback\<void\>): void 3917 3918结束录制,通过注册回调函数获取结果。使用callback异步回调。 3919 3920**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 3921 3922**系统能力:** SystemCapability.Multimedia.Camera.Core 3923 3924**参数:** 3925 3926| 参数名 | 类型 | 必填 | 说明 | 3927| -------- | -------------------- | ---- | ------------------------ | 3928| callback | AsyncCallback\<void\> | 是 | 回调函数,用于获取结果。 | 3929 3930**示例:** 3931 3932```ts 3933import { BusinessError } from '@kit.BasicServicesKit'; 3934 3935function stopVideoOutput(videoOutput: camera.VideoOutput): void { 3936 videoOutput.stop((err: BusinessError) => { 3937 if (err) { 3938 console.error(`Failed to stop the video output, error code: ${err.code}.`); 3939 return; 3940 } 3941 console.info('Callback invoked to indicate the video output stop success.'); 3942 }); 3943} 3944``` 3945 3946### stop 3947 3948stop(): Promise\<void\> 3949 3950结束录制,通过Promise获取结果。 3951 3952**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 3953 3954**系统能力:** SystemCapability.Multimedia.Camera.Core 3955 3956**返回值:** 3957 3958| 类型 | 说明 | 3959| -------------- | ----------------------- | 3960| Promise\<void\> | 无返回结果的Promise对象。 | 3961 3962**示例:** 3963 3964```ts 3965import { BusinessError } from '@kit.BasicServicesKit'; 3966 3967function stopVideoOutput(videoOutput: camera.VideoOutput): void { 3968 videoOutput.stop().then(() => { 3969 console.info('Promise returned to indicate that stop method execution success.'); 3970 }).catch((error: BusinessError) => { 3971 console.error(`Failed to video output stop, error code: ${error.code}.`); 3972 }); 3973} 3974``` 3975 3976### on('frameStart') 3977 3978on(type: 'frameStart', callback: AsyncCallback\<void\>): void 3979 3980监听录像开始,通过注册回调函数获取结果。使用callback异步回调。 3981 3982> **说明:** 3983> 3984> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 3985 3986**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 3987 3988**系统能力:** SystemCapability.Multimedia.Camera.Core 3989 3990**参数:** 3991 3992| 参数名 | 类型 | 必填 | 说明 | 3993| -------- | -------------------- | ---- | ----------------------------------------- | 3994| type | string | 是 | 监听事件,固定为'frameStart',videoOutput创建成功后可监听。底层第一次曝光时触发该事件并返回。 | 3995| callback | AsyncCallback\<void\> | 是 | 回调函数,用于获取结果。 只要有该事件返回就证明录像开始。 | 3996 3997**示例:** 3998 3999```ts 4000import { BusinessError } from '@kit.BasicServicesKit'; 4001 4002function callback(err: BusinessError): void { 4003 if (err !== undefined && err.code !== 0) { 4004 console.error(`Callback Error, errorCode: ${err.code}`); 4005 return; 4006 } 4007 console.info('Video frame started'); 4008} 4009 4010function registerVideoOutputFrameStart(videoOutput: camera.VideoOutput): void { 4011 videoOutput.on('frameStart', callback); 4012} 4013``` 4014 4015### off('frameStart') 4016 4017off(type: 'frameStart', callback?: AsyncCallback\<void\>): void 4018 4019注销监听录像开始。 4020 4021> **说明:** 4022> 4023> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 4024 4025**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 4026 4027**系统能力:** SystemCapability.Multimedia.Camera.Core 4028 4029**参数:** 4030 4031| 参数名 | 类型 | 必填 | 说明 | 4032| -------- | -------------------- | ---- | ----------------------------------------- | 4033| type | string | 是 | 监听事件,固定为'frameStart',videoOutput创建成功后可监听。 | 4034| callback | AsyncCallback\<void\> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 4035 4036**示例:** 4037 4038```ts 4039function unregisterVideoOutputFrameStart(videoOutput: camera.VideoOutput): void { 4040 videoOutput.off('frameStart'); 4041} 4042 4043``` 4044 4045### on('frameEnd') 4046 4047on(type: 'frameEnd', callback: AsyncCallback\<void\>): void 4048 4049监听录像结束,通过注册回调函数获取结果。使用callback异步回调。 4050 4051**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 4052 4053**系统能力:** SystemCapability.Multimedia.Camera.Core 4054 4055**参数:** 4056 4057| 参数名 | 类型 | 必填 | 说明 | 4058| -------- | -------------------- | ---- | ------------------------------------------ | 4059| type | string | 是 | 监听事件,固定为'frameEnd',videoOutput创建成功后可监听。录像完全结束最后一帧时触发该事件并返回。 | 4060| callback | AsyncCallback\<void\> | 是 | 回调函数,用于获取结果。 只要有该事件返回就证明录像结束。 | 4061 4062**示例:** 4063 4064```ts 4065import { BusinessError } from '@kit.BasicServicesKit'; 4066 4067function callback(err: BusinessError): void { 4068 if (err !== undefined && err.code !== 0) { 4069 console.error(`Callback Error, errorCode: ${err.code}`); 4070 return; 4071 } 4072 console.info('Video frame ended'); 4073} 4074 4075function registerVideoOutputFrameEnd(videoOutput: camera.VideoOutput): void { 4076 videoOutput.on('frameEnd', callback); 4077} 4078``` 4079 4080### off('frameEnd') 4081 4082off(type: 'frameEnd', callback?: AsyncCallback\<void\>): void 4083 4084注销监听录像结束。 4085 4086**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 4087 4088**系统能力:** SystemCapability.Multimedia.Camera.Core 4089 4090**参数:** 4091 4092| 参数名 | 类型 | 必填 | 说明 | 4093| -------- | -------------------- | ---- | ------------------------------------------ | 4094| type | string | 是 | 监听事件,固定为'frameEnd',videoOutput创建成功后可监听。 | 4095| callback | AsyncCallback\<void\> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 4096 4097**示例:** 4098 4099```ts 4100function unregisterVideoOutputFrameEnd(videoOutput: camera.VideoOutput): void { 4101 videoOutput.off('frameEnd'); 4102} 4103``` 4104 4105### on('error') 4106 4107on(type: 'error', callback: ErrorCallback): void 4108 4109监听录像输出发生错误,通过注册回调函数获取结果。使用callback异步回调。 4110 4111> **说明:** 4112> 4113> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 4114 4115**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 4116 4117**系统能力:** SystemCapability.Multimedia.Camera.Core 4118 4119**参数:** 4120 4121| 参数名 | 类型 | 必填 | 说明 | 4122| -------- | ----------- | ---- | -------------------------------------- | 4123| type | string | 是 | 监听事件,固定为'error',videoOutput创建成功后可监听。录像接口调用出现错误时触发该事件并返回对应错误码,比如调用[start](#start-1),[CameraOutput.release](#release-1)接口时出现错误返回对应错误信息。 | 4124| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | 是 | 回调函数,用于获取错误信息。返回错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 4125 4126**示例:** 4127 4128```ts 4129import { BusinessError } from '@kit.BasicServicesKit'; 4130 4131function callback(err: BusinessError): void { 4132 console.error(`Video output error code: ${err.code}`); 4133} 4134 4135function registerVideoOutputError(videoOutput: camera.VideoOutput): void { 4136 videoOutput.on('error', callback); 4137} 4138``` 4139 4140### off('error') 4141 4142off(type: 'error', callback?: ErrorCallback): void 4143 4144注销监听录像输出发生错误。 4145 4146**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 4147 4148**系统能力:** SystemCapability.Multimedia.Camera.Core 4149 4150**参数:** 4151 4152| 参数名 | 类型 | 必填 | 说明 | 4153| -------- | ------------- | ---- | ----------------------------------- | 4154| type | string | 是 | 监听事件,固定为'error',photoOutput创建成功后可监听。 | 4155| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 4156 4157**示例:** 4158 4159```ts 4160function unregisterVideoOutputError(videoOutput: camera.VideoOutput): void { 4161 videoOutput.off('error'); 4162} 4163``` 4164 4165### getSupportedFrameRates<sup>12+</sup> 4166 4167getSupportedFrameRates(): Array\<FrameRateRange\> 4168 4169查询支持的帧率范围。 4170 4171**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 4172 4173**系统能力:** SystemCapability.Multimedia.Camera.Core 4174 4175**返回值:** 4176 4177| 类型 | 说明 | 4178| ------------- | ------------ | 4179| Array<[FrameRateRange](#frameraterange)> | 支持的帧率范围列表 | 4180 4181**示例:** 4182 4183```ts 4184function getSupportedFrameRates(videoOutput: camera.VideoOutput): Array<camera.FrameRateRange> { 4185 let supportedFrameRatesArray: Array<camera.FrameRateRange> = videoOutput.getSupportedFrameRates(); 4186 return supportedFrameRatesArray; 4187} 4188``` 4189 4190### setFrameRate<sup>12+</sup> 4191 4192setFrameRate(minFps: number, maxFps: number): void 4193 4194设置录像流帧率范围,设置的范围必须在支持的帧率范围内。 4195 4196进行设置前,可通过[getSupportedFrameRates](#getsupportedframerates12-1)查询支持的帧率范围。 4197 4198> **说明:** 4199> 仅在[PhotoSession](#photosession11)或[VideoSession](#videosession11)模式下支持。 4200 4201**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 4202 4203**系统能力:** SystemCapability.Multimedia.Camera.Core 4204 4205**参数:** 4206 4207| 参数名 | 类型 | 必填 | 说明 | 4208| -------- | --------------| ---- | ------------------------ | 4209| minFps | number | 是 | 最小帧率。 | 4210| maxFps | number | 是 | 最大帧率。当传入的最小值大于最大值时,传参异常,接口不生效。 | 4211 4212**错误码:** 4213 4214以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 4215 4216| 错误码ID | 错误信息 | 4217| --------------- | --------------- | 4218| 7400101 | Parameter missing or parameter type incorrect. | 4219| 7400110 | Unresolved conflicts with current configurations. | 4220 4221**示例:** 4222 4223```ts 4224function setFrameRateRange(videoOutput: camera.VideoOutput, frameRateRange: Array<number>): void { 4225 videoOutput.setFrameRate(frameRateRange[0], frameRateRange[1]); 4226} 4227``` 4228 4229### getActiveFrameRate<sup>12+</sup> 4230 4231getActiveFrameRate(): FrameRateRange 4232 4233获取已设置的帧率范围。 4234 4235使用[setFrameRate](#setframerate12-1)对录像流设置过帧率后可查询。 4236 4237**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 4238 4239**系统能力:** SystemCapability.Multimedia.Camera.Core 4240 4241**返回值:** 4242 4243| 类型 | 说明 | 4244| ------------- | ------------ | 4245| [FrameRateRange](#frameraterange) | 帧率范围 | 4246 4247**示例:** 4248 4249```ts 4250function getActiveFrameRate(videoOutput: camera.VideoOutput): camera.FrameRateRange { 4251 let activeFrameRate: camera.FrameRateRange = videoOutput.getActiveFrameRate(); 4252 return activeFrameRate; 4253} 4254``` 4255 4256### getActiveProfile<sup>12+</sup> 4257 4258getActiveProfile(): VideoProfile 4259 4260获取当前生效的配置信息。 4261 4262**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 4263 4264**系统能力:** SystemCapability.Multimedia.Camera.Core 4265 4266**返回值:** 4267 4268| 类型 | 说明 | 4269| ------------- |-----------| 4270| [VideoProfile](#videoprofile) | 当前生效的配置信息 | 4271 4272**错误码:** 4273 4274以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 4275 4276| 错误码ID | 错误信息 | 4277|---------|------------------------------| 4278| 7400201 | Camera service fatal error. | 4279 4280**示例:** 4281 4282```ts 4283function testGetActiveProfile(videoOutput: camera.VideoOutput): camera.Profile | undefined { 4284 let activeProfile: camera.VideoProfile | undefined = undefined; 4285 try { 4286 activeProfile = videoOutput.getActiveProfile(); 4287 } catch (error) { 4288 // 失败返回错误码error.code并处理。 4289 let err = error as BusinessError; 4290 console.error(`The videoOutput.getActiveProfile call failed. error code: ${err.code}`); 4291 } 4292 return activeProfile; 4293} 4294``` 4295### isMirrorSupported<sup>15+</sup> 4296 4297isMirrorSupported(): boolean 4298 4299查询是否支持镜像录像。 4300 4301**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 4302 4303**系统能力:** SystemCapability.Multimedia.Camera.Core 4304 4305**返回值:** 4306 4307| 类型 | 说明 | 4308| -------------- |---------------------------------| 4309| boolean | 返回是否支持镜像录像,true表示支持,false表示不支持。 | 4310 4311**示例:** 4312 4313```ts 4314function testIsMirrorSupported(videoOutput: camera.VideoOutput): boolean { 4315 let isSupported: boolean = videoOutput.isMirrorSupported(); 4316 return isSupported; 4317} 4318``` 4319### enableMirror<sup>15+</sup> 4320 4321enableMirror(enabled: boolean): void 4322 4323启用/关闭镜像录像。 4324- 调用该接口前,需要通过[isMirrorSupported](#ismirrorsupported15)查询是否支录像镜像功能。 4325 4326- 启用/关闭录像镜像后,需要通过[getVideoRotation](#getvideorotation12)以及[updateRotation](../apis-media-kit/js-apis-media.md#updaterotation12)更新旋转角度。 4327 4328**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 4329 4330**系统能力:** SystemCapability.Multimedia.Camera.Core 4331 4332**参数:** 4333 4334| 参数名 | 类型 | 必填 | 说明 | 4335|----------| ---------------------- | ---- |---------------------------| 4336| enabled | boolean | 是 | 启用/关闭镜像录像。true为开启镜像录像,false为关闭镜像录像。 | 4337 4338**错误码:** 4339 4340以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 4341 4342| 错误码ID | 错误信息 | 4343| -------- |------------------------------------------------| 4344| 7400101 | Parameter missing or parameter type incorrect. | 4345| 7400103 | Session not config. | 4346 4347 4348**示例:** 4349 4350```ts 4351import { camera } from '@kit.CameraKit'; 4352import { media } from '@kit.MediaKit'; 4353import { BusinessError } from '@kit.BasicServicesKit'; 4354 4355function enableMirror(videoOutput: camera.VideoOutput, mirrorMode: boolean, aVRecorder: media.AVRecorder, deviceDegree : number): void { 4356 try { 4357 videoOutput.enableMirror(mirrorMode); 4358 aVRecorder.updateRotation(videoOutput.getVideoRotation(deviceDegree)); 4359 } catch (error) { 4360 let err = error as BusinessError; 4361 } 4362} 4363``` 4364 4365### getVideoRotation<sup>12+</sup> 4366 4367getVideoRotation(deviceDegree: number): ImageRotation 4368 4369获取录像旋转角度。 4370 4371- 设备自然方向:设备默认使用方向,手机为竖屏(充电口向下)。 4372- 相机镜头角度:值等于相机图像顺时针旋转到设备自然方向的角度,手机后置相机传感器是横屏安装的,所以需要顺时针旋转90度到设备自然方向。 4373- 屏幕显示方向:需要屏幕显示的图片左上角为第一个像素点为坐标原点。锁屏时与自然方向一致。 4374 4375**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 4376 4377**系统能力:** SystemCapability.Multimedia.Camera.Core 4378 4379**参数:** 4380 4381| 参数名 | 类型 | 必填 | 说明 | 4382| -------- | --------------| ---- | ------------------------ | 4383| deviceDegree | number | 是 | 设备旋转角度(单位:度)。 | 4384 4385**返回值:** 4386 4387| 类型 | 说明 | 4388| ------------- |-----------| 4389| [ImageRotation](#imagerotation) | 获取录像旋转角度。 | 4390 4391**错误码:** 4392 4393以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 4394 4395| 错误码ID | 错误信息 | 4396|---------|------------------------------| 4397| 7400101 | Parameter missing or parameter type incorrect. | 4398| 7400201 | Camera service fatal error. | 4399 4400**示例:** 4401 4402```ts 4403import { camera } from '@kit.CameraKit'; 4404import { Decimal } from '@kit.ArkTS'; 4405import { sensor } from '@kit.SensorServiceKit'; 4406import { BusinessError } from '@kit.BasicServicesKit'; 4407 4408function getVideoRotation(videoOutput: camera.VideoOutput): camera.ImageRotation { 4409 let videoRotation: camera.ImageRotation = camera.ImageRotation.ROTATION_0; 4410 try { 4411 videoRotation = videoOutput.getVideoRotation(getDeviceDegree()); 4412 } catch (error) { 4413 let err = error as BusinessError; 4414 } 4415 return videoRotation; 4416} 4417 4418//获取deviceDegree。 4419function getDeviceDegree(): number { 4420 let deviceDegree: number = -1; 4421 try { 4422 sensor.once(sensor.SensorId.GRAVITY, (data: sensor.GravityResponse) => { 4423 console.info('Succeeded in invoking once. X-coordinate component: ' + data.x); 4424 console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y); 4425 console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z); 4426 let x = data.x; 4427 let y = data.y; 4428 let z = data.z; 4429 if ((x * x + y * y) * 3 < z * z) { 4430 deviceDegree = -1; 4431 } else { 4432 let sd: Decimal = Decimal.atan2(y, -x); 4433 let sc: Decimal = Decimal.round(Number(sd) / 3.141592653589 * 180) 4434 deviceDegree = 90 - Number(sc); 4435 deviceDegree = deviceDegree >= 0 ? deviceDegree% 360 : deviceDegree% 360 + 360; 4436 } 4437 }); 4438 } catch (error) { 4439 let err: BusinessError = error as BusinessError; 4440 } 4441 return deviceDegree; 4442} 4443``` 4444 4445## MetadataOutput 4446 4447metadata流。继承[CameraOutput](#cameraoutput)。 4448 4449### start 4450 4451start(callback: AsyncCallback\<void\>): void 4452 4453开始输出metadata,通过注册回调函数获取结果。使用callback异步回调。 4454 4455**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 4456 4457**系统能力:** SystemCapability.Multimedia.Camera.Core 4458 4459**参数:** 4460 4461| 参数名 | 类型 | 必填 | 说明 | 4462| -------- | -------------------------- | ---- | ------------------- | 4463| callback | AsyncCallback\<void\> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 4464 4465**错误码:** 4466 4467以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 4468 4469| 错误码ID | 错误信息 | 4470| --------------- | --------------- | 4471| 7400103 | Session not config. | 4472| 7400201 | Camera service fatal error. | 4473 4474**示例:** 4475 4476```ts 4477import { BusinessError } from '@kit.BasicServicesKit'; 4478 4479function startMetadataOutput(metadataOutput: camera.MetadataOutput): void { 4480 metadataOutput.start((err: BusinessError) => { 4481 if (err) { 4482 console.error(`Failed to start metadata output, error code: ${err.code}.`); 4483 return; 4484 } 4485 console.info('Callback returned with metadata output started.'); 4486 }); 4487} 4488``` 4489 4490### start 4491 4492start(): Promise\<void\> 4493 4494开始输出metadata,通过Promise获取结果。 4495 4496**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 4497 4498**系统能力:** SystemCapability.Multimedia.Camera.Core 4499 4500**返回值:** 4501 4502| 类型 | 说明 | 4503| ---------------------- | ------------------------ | 4504| Promise\<void\> | 无返回结果的Promise对象。 | 4505 4506**错误码:** 4507 4508以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 4509 4510| 错误码ID | 错误信息 | 4511| --------------- | --------------- | 4512| 7400103 | Session not config. | 4513| 7400201 | Camera service fatal error. | 4514 4515**示例:** 4516 4517```ts 4518import { BusinessError } from '@kit.BasicServicesKit'; 4519 4520function startMetadataOutput(metadataOutput: camera.MetadataOutput): void { 4521 metadataOutput.start().then(() => { 4522 console.info('Callback returned with metadata output started.'); 4523 }).catch((error: BusinessError) => { 4524 console.error(`Failed to metadata output stop, error code: ${error.code}`); 4525 }); 4526} 4527``` 4528 4529### stop 4530 4531stop(callback: AsyncCallback\<void\>): void 4532 4533停止输出metadata,通过注册回调函数获取结果。使用callback异步回调。 4534 4535**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 4536 4537**系统能力:** SystemCapability.Multimedia.Camera.Core 4538 4539**参数:** 4540 4541| 参数名 | 类型 | 必填 | 说明 | 4542| -------- | -------------------------- | ---- | ------------------- | 4543| callback | AsyncCallback\<void\> | 是 | 回调函数,用于获取结果。 | 4544 4545**示例:** 4546 4547```ts 4548import { BusinessError } from '@kit.BasicServicesKit'; 4549 4550function stopMetadataOutput(metadataOutput: camera.MetadataOutput): void { 4551 metadataOutput.stop((err: BusinessError) => { 4552 if (err) { 4553 console.error(`Failed to stop the metadata output, error code: ${err.code}.`); 4554 return; 4555 } 4556 console.info('Callback returned with metadata output stopped.'); 4557 }) 4558} 4559``` 4560 4561### stop 4562 4563stop(): Promise\<void\> 4564 4565停止输出metadata,通过Promise获取结果。 4566 4567**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 4568 4569**系统能力:** SystemCapability.Multimedia.Camera.Core 4570 4571**返回值:** 4572 4573| 类型 | 说明 | 4574| ---------------------- | --------------------------- | 4575| Promise\<void\> | 无返回结果的Promise对象。 | 4576 4577**示例:** 4578 4579```ts 4580import { BusinessError } from '@kit.BasicServicesKit'; 4581 4582function stopMetadataOutput(metadataOutput: camera.MetadataOutput): void { 4583 metadataOutput.stop().then(() => { 4584 console.info('Callback returned with metadata output stopped.'); 4585 }).catch((error: BusinessError) => { 4586 console.error(`Failed to metadata output stop, error code: ${error.code}`); 4587 }); 4588} 4589``` 4590 4591### on('metadataObjectsAvailable') 4592 4593on(type: 'metadataObjectsAvailable', callback: AsyncCallback\<Array\<MetadataObject\>\>): void 4594 4595监听检测到的metadata对象,通过注册回调函数获取结果。使用callback异步回调。 4596 4597> **说明:** 4598> 4599> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 4600 4601**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 4602 4603**系统能力:** SystemCapability.Multimedia.Camera.Core 4604 4605**参数:** 4606 4607| 参数名 | 类型 | 必填 | 说明 | 4608| -------- | -------------- | ---- | ------------------------------------ | 4609| type | string | 是 | 监听事件,固定为'metadataObjectsAvailable',metadataOutput创建成功后可监听。检测到有效的metadata数据时触发该事件发生并返回相应的metadata数据。 | 4610| callback | AsyncCallback\<Array\<[MetadataObject](#metadataobject)\>\> | 是 | 回调函数,用于获取metadata数据。 | 4611 4612**示例:** 4613 4614```ts 4615import { BusinessError } from '@kit.BasicServicesKit'; 4616 4617function callback(err: BusinessError, metadataObjectArr: Array<camera.MetadataObject>): void { 4618 if (err !== undefined && err.code !== 0) { 4619 console.error(`Callback Error, errorCode: ${err.code}`); 4620 return; 4621 } 4622 console.info('metadata output metadataObjectsAvailable'); 4623} 4624 4625function registerMetadataObjectsAvailable(metadataOutput: camera.MetadataOutput): void { 4626 metadataOutput.on('metadataObjectsAvailable', callback); 4627} 4628``` 4629 4630### off('metadataObjectsAvailable') 4631 4632off(type: 'metadataObjectsAvailable', callback?: AsyncCallback\<Array\<MetadataObject\>\>): void 4633 4634注销监听检测到的metadata对象。 4635 4636**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 4637 4638**系统能力:** SystemCapability.Multimedia.Camera.Core 4639 4640**参数:** 4641 4642| 参数名 | 类型 | 必填 | 说明 | 4643| -------- | -------------- | ---- | ------------------------------------ | 4644| type | string | 是 | 监听事件,固定为'metadataObjectsAvailable',metadataOutput创建成功后可监听。 | 4645| callback | AsyncCallback\<Array\<[MetadataObject](#metadataobject)\>\> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 4646 4647**示例:** 4648 4649```ts 4650function unregisterMetadataObjectsAvailable(metadataOutput: camera.MetadataOutput): void { 4651 metadataOutput.off('metadataObjectsAvailable'); 4652} 4653``` 4654 4655### on('error') 4656 4657on(type: 'error', callback: ErrorCallback): void 4658 4659监听metadata流的错误,通过注册回调函数获取结果。使用callback异步回调。 4660 4661> **说明:** 4662> 4663> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 4664 4665**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 4666 4667**系统能力:** SystemCapability.Multimedia.Camera.Core 4668 4669**参数:** 4670 4671| 参数名 | 类型 | 必填 | 说明 | 4672| -------- | ------------- | ---- | --------------------------------------- | 4673| type | string | 是 | 监听事件,固定为'error',metadataOutput创建成功后可监听。metadata接口使用错误时触发该事件并返回对应错误码,比如调用[start](#start-3),[CameraOutput.release](#release-1)接口时发生错误返回对应错误信息。 | 4674| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | 是 | 回调函数,用于获取错误信息。返回错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 4675 4676**示例:** 4677 4678```ts 4679import { BusinessError } from '@kit.BasicServicesKit'; 4680 4681function callback(metadataOutputError: BusinessError): void { 4682 console.error(`Metadata output error code: ${metadataOutputError.code}`); 4683} 4684 4685function registerMetadataOutputError(metadataOutput: camera.MetadataOutput): void { 4686 metadataOutput.on('error', callback); 4687} 4688``` 4689 4690### off('error') 4691 4692off(type: 'error', callback?: ErrorCallback): void 4693 4694注销监听metadata流的错误。 4695 4696**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 4697 4698**系统能力:** SystemCapability.Multimedia.Camera.Core 4699 4700**参数:** 4701 4702| 参数名 | 类型 | 必填 | 说明 | 4703| -------- | ------------- | ---- | --------------------------------------- | 4704| type | string | 是 | 监听事件,固定为'error',metadataOutput创建成功后可监听。 | 4705| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 4706 4707**示例:** 4708 4709```ts 4710function unregisterMetadataOutputError(metadataOutput: camera.MetadataOutput): void { 4711 metadataOutput.off('error'); 4712} 4713``` 4714 4715## MetadataObjectType 4716 4717枚举,metadata流。 4718 4719**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 4720 4721**系统能力:** SystemCapability.Multimedia.Camera.Core 4722 4723| 名称 | 值 | 说明 | 4724| ------------------------- | ---- | ----------------- | 4725| FACE_DETECTION | 0 | metadata对象类型,用于人脸检测。<br> 检测点应在0-1坐标系内,该坐标系左上角为(0,0),右下角为(1,1)。<br> 此坐标系以设备充电口在右侧时的横向设备方向为基准。<br>例如应用的预览界面布局以设备充电口在下侧时的竖向方向为基准,<br>布局宽高为(w,h), 返回点为(x,y),则转换后的坐标点为(1-y,x)。 | 4726 4727## Rect 4728 4729矩形定义。 4730 4731**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 4732 4733**系统能力:** SystemCapability.Multimedia.Camera.Core 4734 4735| 名称 | 类型 | 只读 | 可选 | 说明 | 4736| -------- | ------ | ------ |-----| --------------------- | 4737| topLeftX | number | 否 | 否 | 矩形区域左上角x坐标。 | 4738| topLeftY | number | 否 | 否 | 矩形区域左上角y坐标。 | 4739| width | number | 否 | 否 | 矩形宽,相对值,范围[0, 1]。 | 4740| height | number | 否 | 否 | 矩形高,相对值,范围[0, 1]。 | 4741 4742## MetadataObject 4743 4744相机元能力信息,[CameraInput](#camerainput)相机信息中的数据来源,通过metadataOutput.on('metadataObjectsAvailable')接口获取。 4745 4746**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 4747 4748**系统能力:** SystemCapability.Multimedia.Camera.Core 4749 4750| 名称 | 类型 | 只读 | 可选 |说明 | 4751| ----------- | ------------------------------------------- | ---- | ---- | ----------------- | 4752| type | [MetadataObjectType](#metadataobjecttype) | 是 | 否 | metadata 类型。 | 4753| timestamp | number | 是 | 否 | 当前时间戳(毫秒)。| 4754| boundingBox | [Rect](#rect) | 是 | 否 | metadata 区域框。 | 4755 4756## FlashMode 4757 4758枚举,闪光灯模式。 4759 4760**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 4761 4762**系统能力:** SystemCapability.Multimedia.Camera.Core 4763 4764| 名称 | 值 | 说明 | 4765| ---------------------- | ---- | ---------- | 4766| FLASH_MODE_CLOSE | 0 | 闪光灯关闭。 | 4767| FLASH_MODE_OPEN | 1 | 闪光灯打开。 | 4768| FLASH_MODE_AUTO | 2 | 自动闪光灯。 | 4769| FLASH_MODE_ALWAYS_OPEN | 3 | 闪光灯常亮。 | 4770 4771## ExposureMode 4772 4773枚举,曝光模式。 4774 4775**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 4776 4777**系统能力:** SystemCapability.Multimedia.Camera.Core 4778 4779| 名称 | 值 | 说明 | 4780| ----------------------------- | ---- | ----------- | 4781| EXPOSURE_MODE_LOCKED | 0 | 锁定曝光模式。不支持曝光区域中心点设置。 | 4782| EXPOSURE_MODE_AUTO | 1 | 自动曝光模式。支持曝光区域中心点设置,可以使用[AutoExposure.setMeteringPoint](#setmeteringpoint11)接口设置曝光区域中心点。 | 4783| EXPOSURE_MODE_CONTINUOUS_AUTO | 2 | 连续自动曝光。不支持曝光区域中心点设置。 | 4784 4785## FocusMode 4786 4787枚举,焦距模式。 4788 4789**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 4790 4791**系统能力:** SystemCapability.Multimedia.Camera.Core 4792 4793| 名称 | 值 | 说明 | 4794| -------------------------- | ---- | ------------ | 4795| FOCUS_MODE_MANUAL | 0 | 手动对焦。通过手动修改相机焦距来改变对焦位置,不支持对焦点设置。 | 4796| FOCUS_MODE_CONTINUOUS_AUTO | 1 | 连续自动对焦。不支持对焦点设置。 | 4797| FOCUS_MODE_AUTO | 2 | 自动对焦。支持对焦点设置,可以使用[Focus.setFocusPoint](#setfocuspoint11)设置对焦点,根据对焦点执行一次自动对焦。 | 4798| FOCUS_MODE_LOCKED | 3 | 对焦锁定。不支持对焦点设置。 | 4799 4800## FocusState 4801 4802枚举,焦距状态。 4803 4804**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 4805 4806**系统能力:** SystemCapability.Multimedia.Camera.Core 4807 4808| 名称 | 值 | 说明 | 4809| --------------------- | ---- | --------- | 4810| FOCUS_STATE_SCAN | 0 | 触发对焦。 | 4811| FOCUS_STATE_FOCUSED | 1 | 对焦成功。 | 4812| FOCUS_STATE_UNFOCUSED | 2 | 未完成对焦。 | 4813 4814## VideoStabilizationMode 4815 4816枚举,视频防抖模式。 4817 4818**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 4819 4820**系统能力:** SystemCapability.Multimedia.Camera.Core 4821 4822| 名称 | 值 | 说明 | 4823| --------- | ---- | ------------ | 4824| OFF | 0 | 关闭视频防抖功能。 | 4825| LOW | 1 | 使用基础防抖算法。 | 4826| MIDDLE | 2 | 使用防抖效果一般的防抖算法,防抖效果优于LOW类型。 | 4827| HIGH | 3 | 使用防抖效果最好的防抖算法,防抖效果优于MIDDLE类型。 | 4828| AUTO | 4 | 自动进行选择防抖算法。 | 4829 4830## Session<sup>11+</sup> 4831 4832会话类,保存一次相机运行所需要的所有资源[CameraInput](#camerainput)、[CameraOutput](#cameraoutput),并向相机设备申请完成相机功能(录像,拍照)。 4833 4834### beginConfig<sup>11+</sup> 4835 4836beginConfig(): void 4837 4838开始配置会话。 4839 4840**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 4841 4842**系统能力:** SystemCapability.Multimedia.Camera.Core 4843 4844**错误码:** 4845 4846以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 4847 4848| 错误码ID | 错误信息 | 4849| --------------- | --------------- | 4850| 7400105 | Session config locked. | 4851| 7400201 | Camera service fatal error. | 4852 4853**示例:** 4854 4855```ts 4856import { BusinessError } from '@kit.BasicServicesKit'; 4857 4858function beginConfig(session: camera.Session): void { 4859 try { 4860 session.beginConfig(); 4861 } catch (error) { 4862 // 失败返回错误码error.code并处理。 4863 let err = error as BusinessError; 4864 console.error(`The beginConfig call failed. error code: ${err.code}`); 4865 } 4866} 4867``` 4868 4869### commitConfig<sup>11+</sup> 4870 4871commitConfig(callback: AsyncCallback\<void\>): void 4872 4873提交配置信息,通过注册回调函数获取结果。使用callback异步回调。 4874 4875**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 4876 4877**系统能力:** SystemCapability.Multimedia.Camera.Core 4878 4879**参数:** 4880 4881| 参数名 | 类型 | 必填 | 说明 | 4882| -------- | -------------------- | ---- | -------------------- | 4883| callback | AsyncCallback\<void\> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode),比如预览流与录像输出流的分辨率的宽高比不一致,会返回7400201。 | 4884 4885**错误码:** 4886 4887以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 4888 4889| 错误码ID | 错误信息 | 4890| --------------- | --------------- | 4891| 7400102 | Operation not allowed. | 4892| 7400201 | Camera service fatal error. | 4893 4894**示例:** 4895 4896```ts 4897import { BusinessError } from '@kit.BasicServicesKit'; 4898 4899function commitConfig(session: camera.Session): void { 4900 session.commitConfig((err: BusinessError) => { 4901 if (err) { 4902 console.error(`The commitConfig call failed. error code: ${err.code}`); 4903 return; 4904 } 4905 console.info('Callback invoked to indicate the commit config success.'); 4906 }); 4907} 4908``` 4909 4910### commitConfig<sup>11+</sup> 4911 4912commitConfig(): Promise\<void\> 4913 4914提交配置信息,通过Promise获取结果。 4915 4916**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 4917 4918**系统能力:** SystemCapability.Multimedia.Camera.Core 4919 4920**返回值:** 4921 4922| 类型 | 说明 | 4923| -------------- | ------------------------ | 4924| Promise\<void\> | 无返回结果的Promise对象。 | 4925 4926**错误码:** 4927 4928以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 4929 4930| 错误码ID | 错误信息 | 4931| --------------- | --------------- | 4932| 7400102 | Operation not allowed. | 4933| 7400201 | Camera service fatal error. | 4934 4935**示例:** 4936 4937```ts 4938import { BusinessError } from '@kit.BasicServicesKit'; 4939 4940function commitConfig(session: camera.Session): void { 4941 session.commitConfig().then(() => { 4942 console.info('Promise returned to indicate the commit config success.'); 4943 }).catch((error: BusinessError) => { 4944 // 失败返回错误码error.code并处理。 4945 console.error(`The commitConfig call failed. error code: ${error.code}`); 4946 }); 4947} 4948``` 4949 4950### canAddInput<sup>11+</sup> 4951 4952canAddInput(cameraInput: CameraInput): boolean 4953 4954判断当前cameraInput是否可以添加到session中。当前函数需要在[beginConfig](#beginconfig11)和[commitConfig](#commitconfig11-1)之间生效。 4955 4956**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 4957 4958**系统能力:** SystemCapability.Multimedia.Camera.Core 4959 4960**参数:** 4961 4962| 参数名 | 类型 | 必填 | 说明 | 4963| ----------- | --------------------------- | ---- | ------------------------ | 4964| cameraInput | [CameraInput](#camerainput) | 是 | 需要添加的CameraInput实例。传参异常(如超出范围、传入null、未定义等),实际接口不会生效。 | 4965 4966**返回值:** 4967 4968| 类型 | 说明 | 4969| -------------- | ------------------------ | 4970| boolean | 判断当前cameraInput是否可以添加到session中。true表示支持添加当前cameraInput,false表示不支持添加。 | 4971 4972**示例:** 4973 4974```ts 4975import { BusinessError } from '@kit.BasicServicesKit'; 4976 4977function canAddInput(session: camera.Session, cameraInput: camera.CameraInput): void { 4978 let canAdd: boolean = session.canAddInput(cameraInput); 4979 console.info(`The input canAddInput: ${canAdd}`); 4980} 4981``` 4982 4983### addInput<sup>11+</sup> 4984 4985addInput(cameraInput: CameraInput): void 4986 4987把[CameraInput](#camerainput)加入到会话。 4988 4989**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 4990 4991**系统能力:** SystemCapability.Multimedia.Camera.Core 4992 4993**参数:** 4994 4995| 参数名 | 类型 | 必填 | 说明 | 4996| ----------- | --------------------------- | ---- | ------------------------ | 4997| cameraInput | [CameraInput](#camerainput) | 是 | 需要添加的CameraInput实例。 | 4998 4999**错误码:** 5000 5001以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 5002 5003| 错误码ID | 错误信息 | 5004| --------------- | --------------- | 5005| 7400101 | Parameter missing or parameter type incorrect. | 5006| 7400102 | Operation not allowed. | 5007| 7400201 | Camera service fatal error. | 5008 5009**示例:** 5010 5011```ts 5012import { BusinessError } from '@kit.BasicServicesKit'; 5013 5014function addInput(session: camera.Session, cameraInput: camera.CameraInput): void { 5015 try { 5016 session.addInput(cameraInput); 5017 } catch (error) { 5018 // 失败返回错误码error.code并处理。 5019 let err = error as BusinessError; 5020 console.error(`The addInput call failed. error code: ${err.code}`); 5021 } 5022} 5023``` 5024 5025### removeInput<sup>11+</sup> 5026 5027removeInput(cameraInput: CameraInput): void 5028 5029移除[CameraInput](#camerainput)。当前函数需要在[beginConfig](#beginconfig11)和[commitConfig](#commitconfig11-1)之间生效。 5030 5031**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 5032 5033**系统能力:** SystemCapability.Multimedia.Camera.Core 5034 5035**参数:** 5036 5037| 参数名 | 类型 | 必填 | 说明 | 5038| ----------- | --------------------------- | ---- | ------------------------ | 5039| cameraInput | [CameraInput](#camerainput) | 是 | 需要移除的CameraInput实例。 | 5040 5041**错误码:** 5042 5043以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 5044 5045| 错误码ID | 错误信息 | 5046| --------------- | --------------- | 5047| 7400101 | Parameter missing or parameter type incorrect. | 5048| 7400102 | Operation not allowed. | 5049| 7400201 | Camera service fatal error. | 5050 5051**示例:** 5052 5053```ts 5054import { BusinessError } from '@kit.BasicServicesKit'; 5055 5056function removeInput(session: camera.Session, cameraInput: camera.CameraInput): void { 5057 try { 5058 session.removeInput(cameraInput); 5059 } catch (error) { 5060 // 失败返回错误码error.code并处理。 5061 let err = error as BusinessError; 5062 console.error(`The removeInput call failed. error code: ${err.code}`); 5063 } 5064} 5065``` 5066 5067### canAddOutput<sup>11+</sup> 5068 5069canAddOutput(cameraOutput: CameraOutput): boolean 5070 5071判断当前cameraOutput是否可以添加到session中。当前函数需要在[addInput](#addinput11)和[commitConfig](#commitconfig11-1)之间生效。 5072 5073**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 5074 5075**系统能力:** SystemCapability.Multimedia.Camera.Core 5076 5077**参数:** 5078 5079| 参数名 | 类型 | 必填 | 说明 | 5080| ----------- | --------------------------- | ---- | ------------------------ | 5081| cameraOutput | [CameraOutput](#cameraoutput) | 是 | 需要添加的CameraOutput实例。传参异常(如超出范围、传入null、未定义等),实际接口不会生效。 | 5082 5083**返回值:** 5084 5085| 类型 | 说明 | 5086| -------------- | ------------------------ | 5087| boolean | 是否可以添加当前cameraOutput到session中,true为可添加,false为不可添加。 | 5088 5089**示例:** 5090 5091```ts 5092import { BusinessError } from '@kit.BasicServicesKit'; 5093 5094function canAddOutput(session: camera.Session, cameraOutput: camera.CameraOutput): void { 5095 let canAdd: boolean = session.canAddOutput(cameraOutput); 5096 console.info(`This addOutput can add: ${canAdd}`); 5097} 5098``` 5099 5100### addOutput<sup>11+</sup> 5101 5102addOutput(cameraOutput: CameraOutput): void 5103 5104把[CameraOutput](#cameraoutput)加入到会话。 5105 5106**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 5107 5108**系统能力:** SystemCapability.Multimedia.Camera.Core 5109 5110**参数:** 5111 5112| 参数名 | 类型 | 必填 | 说明 | 5113| ------------- | ------------------------------- | ---- | ------------------------ | 5114| cameraOutput | [CameraOutput](#cameraoutput) | 是 | 需要添加的CameraOutput实例。 | 5115 5116**错误码:** 5117 5118以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 5119 5120| 错误码ID | 错误信息 | 5121| --------------- | --------------- | 5122| 7400101 | Parameter missing or parameter type incorrect. | 5123| 7400102 | Operation not allowed. | 5124| 7400201 | Camera service fatal error. | 5125 5126**示例:** 5127 5128```ts 5129import { BusinessError } from '@kit.BasicServicesKit'; 5130 5131function addOutput(session: camera.Session, cameraOutput: camera.CameraOutput): void { 5132 try { 5133 session.addOutput(cameraOutput); 5134 } catch (error) { 5135 // 失败返回错误码error.code并处理。 5136 let err = error as BusinessError; 5137 console.error(`The addOutput call failed. error code: ${err.code}`); 5138 } 5139} 5140``` 5141 5142### removeOutput<sup>11+</sup> 5143 5144removeOutput(cameraOutput: CameraOutput): void 5145 5146从会话中移除[CameraOutput](#cameraoutput)。 5147 5148**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 5149 5150**系统能力:** SystemCapability.Multimedia.Camera.Core 5151 5152**参数:** 5153 5154| 参数名 | 类型 | 必填 | 说明 | 5155| ------------- | ------------------------------- | ---- | ------------------------ | 5156| cameraOutput | [CameraOutput](#cameraoutput) | 是 | 需要移除的CameraOutput实例。 | 5157 5158**错误码:** 5159 5160以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 5161 5162| 错误码ID | 错误信息 | 5163| --------------- | --------------- | 5164| 7400101 | Parameter missing or parameter type incorrect. | 5165| 7400102 | Operation not allowed. | 5166| 7400201 | Camera service fatal error. | 5167 5168**示例:** 5169 5170```ts 5171import { BusinessError } from '@kit.BasicServicesKit'; 5172 5173function removeOutput(session: camera.Session, previewOutput: camera.PreviewOutput): void { 5174 try { 5175 session.removeOutput(previewOutput); 5176 } catch (error) { 5177 // 失败返回错误码error.code并处理。 5178 let err = error as BusinessError; 5179 console.error(`The removeOutput call failed. error code: ${err.code}`); 5180 } 5181} 5182``` 5183 5184### start<sup>11+</sup> 5185 5186start(callback: AsyncCallback\<void\>): void 5187 5188开始会话工作,通过注册回调函数获取结果。使用callback异步回调。 5189 5190**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 5191 5192**系统能力:** SystemCapability.Multimedia.Camera.Core 5193 5194**参数:** 5195 5196| 参数名 | 类型 | 必填 | 说明 | 5197| -------- | -------------------- | ---- | -------------------- | 5198| callback | AsyncCallback\<void\> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 5199 5200**错误码:** 5201 5202以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 5203 5204| 错误码ID | 错误信息 | 5205| --------------- | --------------- | 5206| 7400102 | Operation not allowed. | 5207| 7400103 | Session not config. | 5208| 7400201 | Camera service fatal error. | 5209 5210**示例:** 5211 5212```ts 5213import { BusinessError } from '@kit.BasicServicesKit'; 5214 5215function startCaptureSession(session: camera.Session): void { 5216 session.start((err: BusinessError) => { 5217 if (err) { 5218 console.error(`Failed to start the session, error code: ${err.code}.`); 5219 return; 5220 } 5221 console.info('Callback invoked to indicate the session start success.'); 5222 }); 5223} 5224``` 5225 5226### start<sup>11+</sup> 5227 5228start(): Promise\<void\> 5229 5230开始会话工作,通过Promise获取结果。 5231 5232**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 5233 5234**系统能力:** SystemCapability.Multimedia.Camera.Core 5235 5236**返回值:** 5237 5238| 类型 | 说明 | 5239| -------------- | ------------------------ | 5240| Promise\<void\> | 无返回结果的Promise对象。 | 5241 5242**错误码:** 5243 5244以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 5245 5246| 错误码ID | 错误信息 | 5247| --------------- | --------------- | 5248| 7400102 | Operation not allowed. | 5249| 7400103 | Session not config. | 5250| 7400201 | Camera service fatal error. | 5251 5252**示例:** 5253 5254```ts 5255import { BusinessError } from '@kit.BasicServicesKit'; 5256 5257function startCaptureSession(session: camera.Session): void { 5258 session.start().then(() => { 5259 console.info('Promise returned to indicate the session start success.'); 5260 }).catch((error: BusinessError) => { 5261 console.error(`Failed to start the session, error code: ${error.code}.`); 5262 }); 5263} 5264``` 5265 5266### stop<sup>11+</sup> 5267 5268stop(callback: AsyncCallback\<void\>): void 5269 5270停止会话工作,通过注册回调函数获取结果。使用callback异步回调。 5271 5272**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 5273 5274**系统能力:** SystemCapability.Multimedia.Camera.Core 5275 5276**参数:** 5277 5278| 参数名 | 类型 | 必填 | 说明 | 5279| -------- | -------------------- | ---- | ------------------- | 5280| callback | AsyncCallback\<void\> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 5281 5282**错误码:** 5283 5284以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 5285 5286| 错误码ID | 错误信息 | 5287| --------------- | --------------- | 5288| 7400201 | Camera service fatal error. | 5289 5290**示例:** 5291 5292```ts 5293import { BusinessError } from '@kit.BasicServicesKit'; 5294 5295function stopCaptureSession(session: camera.Session): void { 5296 session.stop((err: BusinessError) => { 5297 if (err) { 5298 console.error(`Failed to stop the session, error code: ${err.code}.`); 5299 return; 5300 } 5301 console.info('Callback invoked to indicate the session stop success.'); 5302 }); 5303} 5304``` 5305 5306### stop<sup>11+</sup> 5307 5308stop(): Promise\<void\> 5309 5310停止会话工作,通过Promise获取结果。 5311 5312**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 5313 5314**系统能力:** SystemCapability.Multimedia.Camera.Core 5315 5316**返回值:** 5317 5318| 类型 | 说明 | 5319| -------------- |-------------------| 5320| Promise\<void\> | 无返回结果的Promise对象。 | 5321 5322**错误码:** 5323 5324以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 5325 5326| 错误码ID | 错误信息 | 5327| --------------- | --------------- | 5328| 7400201 | Camera service fatal error. | 5329 5330**示例:** 5331 5332```ts 5333import { BusinessError } from '@kit.BasicServicesKit'; 5334 5335function stopCaptureSession(session: camera.Session): void { 5336 session.stop().then(() => { 5337 console.info('Promise returned to indicate the session stop success.'); 5338 }).catch((error: BusinessError) => { 5339 console.error(`Failed to stop the session, error code: ${error.code}.`); 5340 }); 5341} 5342``` 5343 5344### release<sup>11+</sup> 5345 5346release(callback: AsyncCallback\<void\>): void 5347 5348释放会话资源,通过注册回调函数获取结果。使用callback异步回调。 5349 5350**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 5351 5352**系统能力:** SystemCapability.Multimedia.Camera.Core 5353 5354**参数:** 5355 5356| 参数名 | 类型 | 必填 | 说明 | 5357| -------- | -------------------- | ---- | -------------------- | 5358| callback | AsyncCallback\<void\> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 5359 5360**错误码:** 5361 5362以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 5363 5364| 错误码ID | 错误信息 | 5365| --------------- | --------------- | 5366| 7400201 | Camera service fatal error. | 5367 5368**示例:** 5369 5370```ts 5371import { BusinessError } from '@kit.BasicServicesKit'; 5372 5373function releaseCaptureSession(session: camera.Session): void { 5374 session.release((err: BusinessError) => { 5375 if (err) { 5376 console.error(`Failed to release the session instance, error code: ${err.code}.`); 5377 return; 5378 } 5379 console.info('Callback invoked to indicate that the session instance is released successfully.'); 5380 }); 5381} 5382``` 5383 5384### release<sup>11+</sup> 5385 5386release(): Promise\<void\> 5387 5388释放会话资源,通过Promise获取结果。 5389 5390**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 5391 5392**系统能力:** SystemCapability.Multimedia.Camera.Core 5393 5394**返回值:** 5395 5396| 类型 | 说明 | 5397| -------------- | ------------------------ | 5398| Promise\<void\> | 无返回结果的Promise对象。 | 5399 5400**错误码:** 5401 5402以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 5403 5404| 错误码ID | 错误信息 | 5405| --------------- | --------------- | 5406| 7400201 | Camera service fatal error. | 5407 5408**示例:** 5409 5410```ts 5411import { BusinessError } from '@kit.BasicServicesKit'; 5412 5413function releaseCaptureSession(session: camera.Session): void { 5414 session.release().then(() => { 5415 console.info('Promise returned to indicate that the session instance is released successfully.'); 5416 }).catch((error: BusinessError) => { 5417 console.error(`Failed to release the session instance, error code: ${error.code}.`); 5418 }); 5419} 5420``` 5421 5422## Flash<sup>11+</sup> 5423 5424Flash extends [FlashQuery](#flashquery12) 5425 5426闪光灯类,对设备闪光灯操作。 5427 5428### setFlashMode<sup>11+</sup> 5429 5430setFlashMode(flashMode: FlashMode): void 5431 5432设置闪光灯模式。 5433 5434进行设置之前,需要先检查: 5435 54361. 设备是否支持闪光灯,可使用方法[hasFlash](#hasflash11)。 54372. 设备是否支持指定的闪光灯模式,可使用方法[isFlashModeSupported](#isflashmodesupported11)。 5438 5439**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 5440 5441**系统能力:** SystemCapability.Multimedia.Camera.Core 5442 5443**参数:** 5444 5445| 参数名 | 类型 | 必填 | 说明 | 5446| --------- | ----------------------- | ---- | --------------------- | 5447| flashMode | [FlashMode](#flashmode) | 是 | 指定闪光灯模式。传参为null或者undefined,作为0处理,闪光灯关闭。 | 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 setFlashMode(photoSession: camera.PhotoSession): void { 5463 try { 5464 photoSession.setFlashMode(camera.FlashMode.FLASH_MODE_AUTO); 5465 } catch (error) { 5466 // 失败返回错误码error.code并处理。 5467 let err = error as BusinessError; 5468 console.error(`The setFlashMode call failed. error code: ${err.code}`); 5469 } 5470} 5471``` 5472 5473### getFlashMode<sup>11+</sup> 5474 5475getFlashMode(): FlashMode 5476 5477获取当前设备的闪光灯模式。 5478 5479**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 5480 5481**系统能力:** SystemCapability.Multimedia.Camera.Core 5482 5483**返回值:** 5484 5485| 类型 | 说明 | 5486| ---------- | ----------------------------- | 5487| [FlashMode](#flashmode) | 获取当前设备的闪光灯模式。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 5488 5489**错误码:** 5490 5491以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 5492 5493| 错误码ID | 错误信息 | 5494| --------------- | --------------- | 5495| 7400103 | Session not config. | 5496 5497**示例:** 5498 5499```ts 5500import { BusinessError } from '@kit.BasicServicesKit'; 5501 5502function getFlashMode(photoSession: camera.PhotoSession): camera.FlashMode | undefined { 5503 let flashMode: camera.FlashMode | undefined = undefined; 5504 try { 5505 flashMode = photoSession.getFlashMode(); 5506 } catch (error) { 5507 // 失败返回错误码error.code并处理。 5508 let err = error as BusinessError; 5509 console.error(`The getFlashMode call failed.error code: ${err.code}`); 5510 } 5511 return flashMode; 5512} 5513``` 5514 5515## FlashQuery<sup>12+</sup> 5516 5517提供了查询设备的闪光灯状态和模式的能力。 5518 5519### hasFlash<sup>11+</sup> 5520 5521hasFlash(): boolean 5522 5523检测是否有闪光灯,通过注册回调函数获取结果。 5524 5525**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 5526 5527**系统能力:** SystemCapability.Multimedia.Camera.Core 5528 5529**返回值:** 5530 5531| 类型 | 说明 | 5532| ---------- | ----------------------------- | 5533| boolean | 设备是否支持闪光灯。true表示支持,false表示不支持。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 5534 5535**错误码:** 5536 5537以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 5538 5539| 错误码ID | 错误信息 | 5540| --------------- | --------------- | 5541| 7400103 | Session not config, only throw in session usage. | 5542 5543**示例:** 5544 5545```ts 5546import { BusinessError } from '@kit.BasicServicesKit'; 5547 5548function hasFlash(photoSession: camera.PhotoSession): boolean { 5549 let status: boolean = false; 5550 try { 5551 status = photoSession.hasFlash(); 5552 } catch (error) { 5553 // 失败返回错误码error.code并处理。 5554 let err = error as BusinessError; 5555 console.error(`The hasFlash call failed. error code: ${err.code}`); 5556 } 5557 return status; 5558} 5559``` 5560 5561### isFlashModeSupported<sup>11+</sup> 5562 5563isFlashModeSupported(flashMode: FlashMode): boolean 5564 5565检测闪光灯模式是否支持。 5566 5567**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 5568 5569**系统能力:** SystemCapability.Multimedia.Camera.Core 5570 5571**参数:** 5572 5573| 参数名 | 类型 | 必填 | 说明 | 5574| --------- | ----------------------- | ---- | --------------------------------- | 5575| flashMode | [FlashMode](#flashmode) | 是 | 指定闪光灯模式。传参为null或者undefined,作为0处理,闪光灯关闭。 | 5576 5577**返回值:** 5578 5579| 类型 | 说明 | 5580| ---------- | ----------------------------- | 5581| boolean | 检测表示支持该闪光灯模式。true表示支持,false表示不支持。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 5582 5583**错误码:** 5584 5585以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 5586 5587| 错误码ID | 错误信息 | 5588| --------------- | --------------- | 5589| 7400103 | Session not config, only throw in session usage. | 5590 5591**示例:** 5592 5593```ts 5594import { BusinessError } from '@kit.BasicServicesKit'; 5595 5596function isFlashModeSupported(photoSession: camera.PhotoSession): boolean { 5597 let status: boolean = false; 5598 try { 5599 status = photoSession.isFlashModeSupported(camera.FlashMode.FLASH_MODE_AUTO); 5600 } catch (error) { 5601 // 失败返回错误码error.code并处理。 5602 let err = error as BusinessError; 5603 console.error(`The isFlashModeSupported call failed. error code: ${err.code}`); 5604 } 5605 return status; 5606} 5607``` 5608 5609## AutoExposure<sup>11+</sup> 5610 5611AutoExposure extends [AutoExposureQuery](#autoexposurequery12) 5612 5613自动曝光类,对设备自动曝光(AE)操作。 5614 5615### getExposureMode<sup>11+</sup> 5616 5617getExposureMode(): ExposureMode 5618 5619获取当前曝光模式。 5620 5621**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 5622 5623**系统能力:** SystemCapability.Multimedia.Camera.Core 5624 5625**返回值:** 5626 5627| 类型 | 说明 | 5628| ---------- | ----------------------------- | 5629| [ExposureMode](#exposuremode) | 获取当前曝光模式。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 5630 5631**错误码:** 5632 5633以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 5634 5635| 错误码ID | 错误信息 | 5636| --------------- | --------------- | 5637| 7400103 | Session not config. | 5638 5639**示例:** 5640 5641```ts 5642import { BusinessError } from '@kit.BasicServicesKit'; 5643 5644function getExposureMode(photoSession: camera.PhotoSession): camera.ExposureMode | undefined { 5645 let exposureMode: camera.ExposureMode | undefined = undefined; 5646 try { 5647 exposureMode = photoSession.getExposureMode(); 5648 } catch (error) { 5649 // 失败返回错误码error.code并处理。 5650 let err = error as BusinessError; 5651 console.error(`The getExposureMode call failed. error code: ${err.code}`); 5652 } 5653 return exposureMode; 5654} 5655``` 5656 5657### setExposureMode<sup>11+</sup> 5658 5659setExposureMode(aeMode: ExposureMode): void 5660 5661设置曝光模式。进行设置之前,需要先检查设备是否支持指定的曝光模式,可使用方法[isExposureModeSupported](#isexposuremodesupported11)。 5662 5663**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 5664 5665**系统能力:** SystemCapability.Multimedia.Camera.Core 5666 5667**参数:** 5668 5669| 参数名 | 类型 | 必填 | 说明 | 5670| -------- | -------------------------------| ---- | ----------------------- | 5671| aeMode | [ExposureMode](#exposuremode) | 是 | 曝光模式。传参为null或者undefined,作为0处理,曝光锁定。 | 5672 5673**错误码:** 5674 5675以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 5676 5677| 错误码ID | 错误信息 | 5678| --------------- | --------------- | 5679| 7400102 | Operation not allowed. | 5680| 7400103 | Session not config. | 5681 5682**示例:** 5683 5684```ts 5685import { BusinessError } from '@kit.BasicServicesKit'; 5686 5687function setExposureMode(photoSession: camera.PhotoSession): void { 5688 try { 5689 photoSession.setExposureMode(camera.ExposureMode.EXPOSURE_MODE_LOCKED); 5690 } catch (error) { 5691 // 失败返回错误码error.code并处理。 5692 let err = error as BusinessError; 5693 console.error(`The setExposureMode call failed. error code: ${err.code}`); 5694 } 5695} 5696``` 5697 5698### getMeteringPoint<sup>11+</sup> 5699 5700getMeteringPoint(): Point 5701 5702查询曝光区域中心点。 5703 5704**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 5705 5706**系统能力:** SystemCapability.Multimedia.Camera.Core 5707 5708**返回值:** 5709 5710| 类型 | 说明 | 5711| ---------- | ----------------------------- | 5712| [Point](#point) | 获取当前曝光点。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 5713 5714**错误码:** 5715 5716以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 5717 5718| 错误码ID | 错误信息 | 5719|---------| --------------- | 5720| 7400103 | Session not config. | 5721 5722**示例:** 5723 5724```ts 5725import { BusinessError } from '@kit.BasicServicesKit'; 5726 5727function getMeteringPoint(photoSession: camera.PhotoSession): camera.Point | undefined { 5728 let exposurePoint: camera.Point | undefined = undefined; 5729 try { 5730 exposurePoint = photoSession.getMeteringPoint(); 5731 } catch (error) { 5732 // 失败返回错误码error.code并处理。 5733 let err = error as BusinessError; 5734 console.error(`The getMeteringPoint call failed. error code: ${err.code}`); 5735 } 5736 return exposurePoint; 5737} 5738``` 5739 5740### setMeteringPoint<sup>11+</sup> 5741 5742setMeteringPoint(point: Point): void 5743 5744设置曝光区域中心点,曝光点应在0-1坐标系内,该坐标系左上角为{0,0},右下角为{1,1}。<br>此坐标系是以设备充电口在右侧时的横向设备方向为基准的,例如应用的预览界面布局以<br>设备充电口在下侧时的竖向方向为基准,布局宽高为{w,h},且触碰点为{x,y},<br>则转换后的坐标点为{y/h,1-x/w}。 5745 5746**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 5747 5748**系统能力:** SystemCapability.Multimedia.Camera.Core 5749 5750**参数:** 5751 5752| 参数名 | 类型 | 必填 | 说明 | 5753| ------------- | -------------------------------| ---- | ------------------- | 5754| point | [Point](#point) | 是 | 曝光点,x、y设置范围应在[0,1]之内,超过范围,如果小于0设置0,大于1设置1。 | 5755 5756**错误码:** 5757 5758以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 5759 5760| 错误码ID | 错误信息 | 5761| --------------- | --------------- | 5762| 7400103 | Session not config. | 5763 5764**示例:** 5765 5766```ts 5767import { BusinessError } from '@kit.BasicServicesKit'; 5768 5769function setMeteringPoint(photoSession: camera.PhotoSession): void { 5770 const point: camera.Point = {x: 1, y: 1}; 5771 try { 5772 photoSession.setMeteringPoint(point); 5773 } catch (error) { 5774 // 失败返回错误码error.code并处理。 5775 let err = error as BusinessError; 5776 console.error(`The setMeteringPoint call failed. error code: ${err.code}`); 5777 } 5778} 5779``` 5780 5781### setExposureBias<sup>11+</sup> 5782 5783setExposureBias(exposureBias: number): void 5784 5785设置曝光补偿,曝光补偿值(EV)。 5786 5787进行设置之前,建议先通过方法[getExposureBiasRange](#getexposurebiasrange11)查询支持的范围。 5788 5789**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 5790 5791**系统能力:** SystemCapability.Multimedia.Camera.Core 5792 5793**参数:** 5794 5795| 参数名 | 类型 | 必填 | 说明 | 5796| -------- | -------------------------------| ---- |-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| 5797| exposureBias | number | 是 | 曝光补偿,[getExposureBiasRange](#getexposurebiasrange11)查询支持的范围,如果设置超过支持范围的值,自动匹配到就近临界点。<br>曝光补偿存在步长,如步长为0.5。则设置1.2时,获取到实际生效曝光补偿为1.0。<br>接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 5798 5799**错误码:** 5800 5801以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 5802 5803| 错误码ID | 错误信息 | 5804| --------------- | --------------- | 5805| 7400102 | Operation not allowed. | 5806| 7400103 | Session not config. | 5807 5808**示例:** 5809 5810```ts 5811import { BusinessError } from '@kit.BasicServicesKit'; 5812 5813function setExposureBias(photoSession: camera.PhotoSession, biasRangeArray: Array<number>): void { 5814 if (biasRangeArray && biasRangeArray.length > 0) { 5815 let exposureBias = biasRangeArray[0]; 5816 try { 5817 photoSession.setExposureBias(exposureBias); 5818 } catch (error) { 5819 // 失败返回错误码error.code并处理。 5820 let err = error as BusinessError; 5821 console.error(`The setExposureBias call failed. error code: ${err.code}`); 5822 } 5823 } 5824} 5825``` 5826 5827### getExposureValue<sup>11+</sup> 5828 5829getExposureValue(): number 5830 5831查询当前曝光值。 5832 5833**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 5834 5835**系统能力:** SystemCapability.Multimedia.Camera.Core 5836 5837**返回值:** 5838 5839| 类型 | 说明 | 5840| ---------- | ----------------------------- | 5841| number | 获取曝光值。曝光补偿存在步长,如步长为0.5。则设置1.2时,获取到实际生效曝光补偿为1.0。<br>接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 5842 5843**错误码:** 5844 5845以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 5846 5847| 错误码ID | 错误信息 | 5848| --------------- | --------------- | 5849| 7400103 | Session not config. | 5850 5851**示例:** 5852 5853```ts 5854import { BusinessError } from '@kit.BasicServicesKit'; 5855 5856function getExposureValue(photoSession: camera.PhotoSession): number { 5857 const invalidValue: number = -1; 5858 let exposureValue: number = invalidValue; 5859 try { 5860 exposureValue = photoSession.getExposureValue(); 5861 } catch (error) { 5862 // 失败返回错误码error.code并处理。 5863 let err = error as BusinessError; 5864 console.error(`The getExposureValue call failed. error code: ${err.code}`); 5865 } 5866 return exposureValue; 5867} 5868``` 5869 5870## AutoExposureQuery<sup>12+</sup> 5871 5872提供了针对设备的自动曝光特性提供了一系列查询功能。 5873 5874### isExposureModeSupported<sup>11+</sup> 5875 5876isExposureModeSupported(aeMode: ExposureMode): boolean 5877 5878检测曝光模式是否支持。 5879 5880**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 5881 5882**系统能力:** SystemCapability.Multimedia.Camera.Core 5883 5884**参数:** 5885 5886| 参数名 | 类型 | 必填 | 说明 | 5887| -------- | -------------------------------| ---- | ----------------------------- | 5888| aeMode | [ExposureMode](#exposuremode) | 是 | 曝光模式。传参为null或者undefined,作为0处理,曝光锁定。 | 5889 5890**返回值:** 5891 5892| 类型 | 说明 | 5893| ---------- | ----------------------------- | 5894| boolean | 获取是否支持曝光模式,true为支持,false为不支持。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 5895 5896**错误码:** 5897 5898以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 5899 5900| 错误码ID | 错误信息 | 5901| --------------- | --------------- | 5902| 7400103 | Session not config, only throw in session usage. | 5903 5904**示例:** 5905 5906```ts 5907import { BusinessError } from '@kit.BasicServicesKit'; 5908 5909function isExposureModeSupported(photoSession: camera.PhotoSession): boolean { 5910 let isSupported: boolean = false; 5911 try { 5912 isSupported = photoSession.isExposureModeSupported(camera.ExposureMode.EXPOSURE_MODE_LOCKED); 5913 } catch (error) { 5914 // 失败返回错误码error.code并处理。 5915 let err = error as BusinessError; 5916 console.error(`The isExposureModeSupported call failed. error code: ${err.code}`); 5917 } 5918 return isSupported; 5919} 5920``` 5921 5922### getExposureBiasRange<sup>11+</sup> 5923 5924getExposureBiasRange(): Array\<number\> 5925 5926查询曝光补偿范围。 5927 5928**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 5929 5930**系统能力:** SystemCapability.Multimedia.Camera.Core 5931 5932**返回值:** 5933 5934| 类型 | 说明 | 5935| ---------- | ----------------------------- | 5936| Array\<number\> | 获取补偿范围的数组。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 5937 5938**错误码:** 5939 5940以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 5941 5942| 错误码ID | 错误信息 | 5943| --------------- | --------------- | 5944| 7400103 | Session not config, only throw in session usage. | 5945 5946**示例:** 5947 5948```ts 5949import { BusinessError } from '@kit.BasicServicesKit'; 5950 5951function getExposureBiasRange(photoSession: camera.PhotoSession): Array<number> { 5952 let biasRangeArray: Array<number> = []; 5953 try { 5954 biasRangeArray = photoSession.getExposureBiasRange(); 5955 } catch (error) { 5956 // 失败返回错误码error.code并处理。 5957 let err = error as BusinessError; 5958 console.error(`The getExposureBiasRange call failed. error code: ${err.code}`); 5959 } 5960 return biasRangeArray; 5961} 5962``` 5963 5964## Focus<sup>11+</sup> 5965 5966Focus extends [FocusQuery](#focusquery12) 5967 5968对焦类,对设备对焦操作。 5969 5970### setFocusMode<sup>11+</sup> 5971 5972setFocusMode(afMode: FocusMode): void 5973 5974设置对焦模式。 5975 5976进行设置之前,需要先检查设备是否支持指定的焦距模式,可使用方法[isFocusModeSupported](#isfocusmodesupported11)。 5977 5978**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 5979 5980**系统能力:** SystemCapability.Multimedia.Camera.Core 5981 5982**参数:** 5983 5984| 参数名 | 类型 | 必填 | 说明 | 5985| -------- | ----------------------- | ---- | ------------------- | 5986| afMode | [FocusMode](#focusmode) | 是 | 指定的焦距模式。传参为null或者undefined,作为0处理,手动对焦模式。 | 5987 5988**错误码:** 5989 5990以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 5991 5992| 错误码ID | 错误信息 | 5993| --------------- | --------------- | 5994| 7400103 | Session not config. | 5995 5996**示例:** 5997 5998```ts 5999import { BusinessError } from '@kit.BasicServicesKit'; 6000 6001function setFocusMode(photoSession: camera.PhotoSession): void { 6002 try { 6003 photoSession.setFocusMode(camera.FocusMode.FOCUS_MODE_AUTO); 6004 } catch (error) { 6005 // 失败返回错误码error.code并处理。 6006 let err = error as BusinessError; 6007 console.error(`The setFocusMode call failed. error code: ${err.code}`); 6008 } 6009} 6010``` 6011 6012### getFocusMode<sup>11+</sup> 6013 6014getFocusMode(): FocusMode 6015 6016获取当前的对焦模式。 6017 6018**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 6019 6020**系统能力:** SystemCapability.Multimedia.Camera.Core 6021 6022**返回值:** 6023 6024| 类型 | 说明 | 6025| ---------- | ----------------------------- | 6026| [FocusMode](#focusmode) | 获取当前设备的焦距模式。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 6027 6028**错误码:** 6029 6030以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 6031 6032| 错误码ID | 错误信息 | 6033| --------------- | --------------- | 6034| 7400103 | Session not config. | 6035 6036**示例:** 6037 6038```ts 6039import { BusinessError } from '@kit.BasicServicesKit'; 6040 6041function getFocusMode(photoSession: camera.PhotoSession): camera.FocusMode | undefined { 6042 let afMode: camera.FocusMode | undefined = undefined; 6043 try { 6044 afMode = photoSession.getFocusMode(); 6045 } catch (error) { 6046 // 失败返回错误码error.code并处理。 6047 let err = error as BusinessError; 6048 console.error(`The getFocusMode call failed. error code: ${err.code}`); 6049 } 6050 return afMode; 6051} 6052``` 6053 6054### setFocusPoint<sup>11+</sup> 6055 6056setFocusPoint(point: Point): void 6057 6058设置焦点,焦点应在0-1坐标系内,该坐标系左上角为{0,0},右下角为{1,1}。<br>此坐标系是以设备充电口在右侧时的横向设备方向为基准的,例如应用的预览界面布局以<br>设备充电口在下侧时的竖向方向为基准,布局宽高为{w,h},且触碰点为{x,y},<br>则转换后的坐标点为{y/h,1-x/w}。 6059 6060**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 6061 6062**系统能力:** SystemCapability.Multimedia.Camera.Core 6063 6064**参数:** 6065 6066| 参数名 | 类型 | 必填 | 说明 | 6067| -------- | ----------------------- | ---- | ------------------- | 6068| point | [Point](#point) | 是 | 焦点。x、y设置范围应在[0,1]之内,超过范围,如果小于0设置0,大于1设置1。 | 6069 6070**错误码:** 6071 6072以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 6073 6074| 错误码ID | 错误信息 | 6075| --------------- | --------------- | 6076| 7400103 | Session not config. | 6077 6078**示例:** 6079 6080```ts 6081import { BusinessError } from '@kit.BasicServicesKit'; 6082 6083function setFocusPoint(photoSession: camera.PhotoSession): void { 6084 const focusPoint: camera.Point = {x: 1, y: 1}; 6085 try { 6086 photoSession.setFocusPoint(focusPoint); 6087 } catch (error) { 6088 // 失败返回错误码error.code并处理。 6089 let err = error as BusinessError; 6090 console.error(`The setFocusPoint call failed. error code: ${err.code}`); 6091 } 6092} 6093``` 6094 6095### getFocusPoint<sup>11+</sup> 6096 6097getFocusPoint(): Point 6098 6099查询当前的焦点。 6100 6101**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 6102 6103**系统能力:** SystemCapability.Multimedia.Camera.Core 6104 6105**返回值:** 6106 6107| 类型 | 说明 | 6108| ---------- | ----------------------------- | 6109| [Point](#point) | 用于获取当前的焦点。接口调用失败会返回相应错误码,错误码类型为[CameraErrorCode](#cameraerrorcode)。 | 6110 6111**错误码:** 6112 6113以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 6114 6115| 错误码ID | 错误信息 | 6116| --------------- | --------------- | 6117| 7400103 | Session not config. | 6118 6119**示例:** 6120 6121```ts 6122import { BusinessError } from '@kit.BasicServicesKit'; 6123 6124function getFocusPoint(photoSession: camera.PhotoSession): camera.Point | undefined { 6125 let point: camera.Point | undefined = undefined; 6126 try { 6127 point = photoSession.getFocusPoint(); 6128 } catch (error) { 6129 // 失败返回错误码error.code并处理。 6130 let err = error as BusinessError; 6131 console.error(`The getFocusPoint call failed. error code: ${err.code}`); 6132 } 6133 return point; 6134} 6135``` 6136 6137### getFocalLength<sup>11+</sup> 6138 6139getFocalLength(): number 6140 6141查询当前的焦距值。 6142 6143**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 6144 6145**系统能力:** SystemCapability.Multimedia.Camera.Core 6146 6147**返回值:** 6148 6149| 类型 | 说明 | 6150| ---------- | ----------------------------- | 6151| number | 用于获取当前焦距,单位mm。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 6152 6153**错误码:** 6154 6155以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 6156 6157| 错误码ID | 错误信息 | 6158| --------------- | --------------- | 6159| 7400103 | Session not config. | 6160 6161**示例:** 6162 6163```ts 6164import { BusinessError } from '@kit.BasicServicesKit'; 6165 6166function getFocalLength(photoSession: camera.PhotoSession): number { 6167 const invalidValue: number = -1; 6168 let focalLength: number = invalidValue; 6169 try { 6170 focalLength = photoSession.getFocalLength(); 6171 } catch (error) { 6172 // 失败返回错误码error.code并处理。 6173 let err = error as BusinessError; 6174 console.error(`The getFocalLength call failed. error code: ${err.code}`); 6175 } 6176 return focalLength; 6177} 6178``` 6179 6180## FocusQuery<sup>12+</sup> 6181 6182提供了查询是否支持当前对焦模式的方法。 6183 6184### isFocusModeSupported<sup>11+</sup> 6185 6186isFocusModeSupported(afMode: FocusMode): boolean 6187 6188检测对焦模式是否支持。 6189 6190**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 6191 6192**系统能力:** SystemCapability.Multimedia.Camera.Core 6193 6194**参数:** 6195 6196| 参数名 | 类型 | 必填 | 说明 | 6197| -------- | ----------------------- | ---- | -------------------------------- | 6198| afMode | [FocusMode](#focusmode) | 是 | 指定的焦距模式。传参为null或者undefined,作为0处理,手动对焦模式。 | 6199 6200**返回值:** 6201 6202| 类型 | 说明 | 6203| ---------- | ----------------------------- | 6204| boolean | 检测对焦模式是否支持。true表示支持,false表示不支持。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 6205 6206**错误码:** 6207 6208以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 6209 6210| 错误码ID | 错误信息 | 6211| --------------- | --------------- | 6212| 7400103 | Session not config, only throw in session usage. | 6213 6214**示例:** 6215 6216```ts 6217import { BusinessError } from '@kit.BasicServicesKit'; 6218 6219function isFocusModeSupported(photoSession: camera.PhotoSession): boolean { 6220 let status: boolean = false; 6221 try { 6222 status = photoSession.isFocusModeSupported(camera.FocusMode.FOCUS_MODE_AUTO); 6223 } catch (error) { 6224 // 失败返回错误码error.code并处理。 6225 let err = error as BusinessError; 6226 console.error(`The isFocusModeSupported call failed. error code: ${err.code}`); 6227 } 6228 return status; 6229} 6230``` 6231 6232## MacroQuery<sup>19+</sup> 6233 6234提供查询设备是否支持相机微距拍摄的方法。 6235 6236### isMacroSupported<sup>19+</sup> 6237 6238isMacroSupported(): boolean 6239 6240检测当前状态下是否支持微距能力,需要在CaptureSession调用[commitConfig](#commitconfig11-1)之后进行调用。 6241 6242**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 6243 6244**系统能力:** SystemCapability.Multimedia.Camera.Core 6245 6246**返回值:** 6247 6248| 类型 | 说明 | 6249| ---------- | ----------------------------- | 6250| boolean | 返回是否支持微距能力。true表示支持,false表示不支持。 | 6251 6252**示例:** 6253 6254```ts 6255function isMacroSupported(photoSession: camera.PhotoSession): boolean { 6256 let isSupported: boolean = photoSession.isMacroSupported(); 6257 return isSupported; 6258} 6259``` 6260 6261## Macro<sup>19+</sup> 6262 6263Macro extends [MacroQuery](#macroquery19) 6264 6265提供使能微距能力的接口。 6266 6267### enableMacro<sup>19+</sup> 6268 6269enableMacro(enabled: boolean): void 6270 6271使能当前的微距能力,需要在支持微距能力的情况下进行调用。 6272 6273**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 6274 6275**系统能力:** SystemCapability.Multimedia.Camera.Core 6276 6277**参数:** 6278 6279| 参数名 | 类型 | 必填 | 说明 | 6280| -------- | -------------------- | ---- | -------------------- | 6281| enabled | boolean | 是 | 是否开启微距能力。true表示开启微距能力,false表示关闭微距能力。 | 6282 6283**错误码:** 6284 6285以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 6286 6287| 错误码ID | 错误信息 | 6288|----------|--------------------------| 6289| 7400102 | Operation not allowed. | 6290| 7400103 | Session not config. | 6291 6292**示例:** 6293 6294```ts 6295function enableMacro(photoSession: camera.PhotoSession): void { 6296 let isSupported: boolean = photoSession.isMacroSupported(); 6297 if (isSupported) { 6298 photoSession.enableMacro(true); 6299 } 6300} 6301``` 6302 6303## SmoothZoomMode<sup>11+</sup> 6304 6305平滑变焦模式。 6306 6307**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 6308 6309**系统能力:** SystemCapability.Multimedia.Camera.Core 6310 6311| 名称 | 值 | 说明 | 6312| ------------ | ---- | -------------- | 6313| NORMAL | 0 | 贝塞尔曲线模式。 | 6314 6315## SmoothZoomInfo<sup>11+</sup> 6316 6317平滑变焦参数信息。 6318 6319**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 6320 6321**系统能力:** SystemCapability.Multimedia.Camera.Core 6322 6323| 名称 | 类型 | 只读 | 可选 | 说明 | 6324| -------- | ---------- | -------- | -------- | ---------- | 6325| duration | number | 否 | 否 | 平滑变焦总时长,单位ms。 | 6326 6327## Zoom<sup>11+</sup> 6328 6329Zoom extends [ZoomQuery](#zoomquery12) 6330 6331变焦类,对设备变焦操作。 6332 6333### setZoomRatio<sup>11+</sup> 6334 6335setZoomRatio(zoomRatio: number): void 6336 6337设置变焦比,变焦精度最高为小数点后两位,如果设置超过支持的精度范围,则只保留精度范围内数值。 6338 6339**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 6340 6341**系统能力:** SystemCapability.Multimedia.Camera.Core 6342 6343**参数:** 6344 6345| 参数名 | 类型 | 必填 | 说明 | 6346| --------- | -------------------- | ---- |---------------------------------------------------------------------------------------------------------------------------------| 6347| zoomRatio | number | 是 | 可变焦距比,通过[getZoomRatioRange](#getzoomratiorange11)获取支持的变焦范围,如果设置超过支持范围的值,则只保留精度范围内数值。<br>设置可变焦距比到底层生效需要一定时间,获取正确设置的可变焦距比需要等待1~2帧的时间。 | 6348 6349**错误码:** 6350 6351以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 6352 6353| 错误码ID | 错误信息 | 6354| --------------- | --------------- | 6355| 7400103 | Session not config. | 6356 6357**示例:** 6358 6359```ts 6360import { BusinessError } from '@kit.BasicServicesKit'; 6361 6362function setZoomRatio(photoSession: camera.PhotoSession, zoomRatioRange: Array<number>): void { 6363 if (zoomRatioRange === undefined || zoomRatioRange.length <= 0) { 6364 return; 6365 } 6366 let zoomRatio = zoomRatioRange[0]; 6367 try { 6368 photoSession.setZoomRatio(zoomRatio); 6369 } catch (error) { 6370 // 失败返回错误码error.code并处理。 6371 let err = error as BusinessError; 6372 console.error(`The setZoomRatio call failed. error code: ${err.code}`); 6373 } 6374} 6375``` 6376 6377### getZoomRatio<sup>11+</sup> 6378 6379getZoomRatio(): number 6380 6381获取当前的变焦比。 6382 6383**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 6384 6385**系统能力:** SystemCapability.Multimedia.Camera.Core 6386 6387**返回值:** 6388 6389| 类型 | 说明 | 6390| ---------- | ----------------------------- | 6391| number | 获取当前的变焦比结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 6392 6393**错误码:** 6394 6395以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 6396 6397| 错误码ID | 错误信息 | 6398| --------------- | --------------- | 6399| 7400103 | Session not config. | 6400| 7400201 | Camera service fatal error. | 6401 6402**示例:** 6403 6404```ts 6405import { BusinessError } from '@kit.BasicServicesKit'; 6406 6407function getZoomRatio(photoSession: camera.PhotoSession): number { 6408 const invalidValue: number = -1; 6409 let zoomRatio: number = invalidValue; 6410 try { 6411 zoomRatio = photoSession.getZoomRatio(); 6412 } catch (error) { 6413 // 失败返回错误码error.code并处理。 6414 let err = error as BusinessError; 6415 console.error(`The getZoomRatio call failed. error code: ${err.code}`); 6416 } 6417 return zoomRatio; 6418} 6419``` 6420 6421### setSmoothZoom<sup>11+</sup> 6422 6423setSmoothZoom(targetRatio: number, mode?: SmoothZoomMode): void 6424 6425触发平滑变焦。 6426 6427**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 6428 6429**系统能力:** SystemCapability.Multimedia.Camera.Core 6430 6431**参数:** 6432 6433| 参数名 | 类型 | 必填 | 说明 | 6434| ------------ | -------------- | ---- | ----------------- | 6435| targetRatio | number | 是 | 目标值。 | 6436| mode | [SmoothZoomMode](#smoothzoommode11) | 否 | 模式。 | 6437 6438**示例:** 6439 6440```ts 6441import { BusinessError } from '@kit.BasicServicesKit'; 6442 6443function setSmoothZoom(sessionExtendsZoom: camera.Zoom, targetZoomRatio: number, mode: camera.SmoothZoomMode): void { 6444 sessionExtendsZoom.setSmoothZoom(targetZoomRatio, mode); 6445} 6446``` 6447 6448## ZoomQuery<sup>12+</sup> 6449 6450提供了与设备的缩放相关的查询功能,包括获取支持的缩放比例范围。 6451 6452### getZoomRatioRange<sup>11+</sup> 6453 6454getZoomRatioRange(): Array\<number\> 6455 6456获取支持的变焦范围。 6457 6458**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 6459 6460**系统能力:** SystemCapability.Multimedia.Camera.Core 6461 6462**返回值:** 6463 6464| 类型 | 说明 | 6465| ---------- | ----------------------------- | 6466| Array\<number\> | 用于获取可变焦距比范围,返回的数组包括其最小值和最大值。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 6467 6468**错误码:** 6469 6470以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 6471 6472| 错误码ID | 错误信息 | 6473| --------------- | --------------- | 6474| 7400103 | Session not config, only throw in session usage. | 6475 6476**示例:** 6477 6478```ts 6479import { BusinessError } from '@kit.BasicServicesKit'; 6480 6481function getZoomRatioRange(photoSession: camera.PhotoSession): Array<number> { 6482 let zoomRatioRange: Array<number> = []; 6483 try { 6484 zoomRatioRange = photoSession.getZoomRatioRange(); 6485 } catch (error) { 6486 // 失败返回错误码error.code并处理。 6487 let err = error as BusinessError; 6488 console.error(`The getZoomRatioRange call failed. error code: ${err.code}`); 6489 } 6490 return zoomRatioRange; 6491} 6492``` 6493 6494## Stabilization<sup>11+</sup> 6495 6496Stabilization extends [StabilizationQuery](#stabilizationquery12) 6497 6498提供设备在录像模式下设置视频防抖的操作。 6499 6500 > **说明:** 6501 > 6502 > 需要会话中有录像流([VideoOutput](#videooutput))的前提下,才可以对视频进行防抖设置, 6503 > 其中[VideoStabilizationMode](#videostabilizationmode)中的枚举HIGH需要在[Profile](#profile)的分辨率为1920*1080的场景下生效。 6504 6505### getActiveVideoStabilizationMode<sup>11+</sup> 6506 6507getActiveVideoStabilizationMode(): VideoStabilizationMode 6508 6509查询当前正在使用的视频防抖模式。 6510 6511**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 6512 6513**系统能力:** SystemCapability.Multimedia.Camera.Core 6514 6515**返回值:** 6516 6517| 类型 | 说明 | 6518| ---------- |-------------| 6519| [VideoStabilizationMode](#videostabilizationmode) | 视频防抖是否正在使用。 | 6520 6521**错误码:** 6522 6523以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 6524 6525| 错误码ID | 错误信息 | 6526| --------------- | --------------- | 6527| 7400103 | Session not config. | 6528 6529**示例:** 6530 6531```ts 6532import { BusinessError } from '@kit.BasicServicesKit'; 6533 6534function getActiveVideoStabilizationMode(videoSession: camera.VideoSession): camera.VideoStabilizationMode | undefined { 6535 let vsMode: camera.VideoStabilizationMode | undefined = undefined; 6536 try { 6537 vsMode = videoSession.getActiveVideoStabilizationMode(); 6538 } catch (error) { 6539 // 失败返回错误码error.code并处理。 6540 let err = error as BusinessError; 6541 console.error(`The getActiveVideoStabilizationMode call failed. error code: ${err.code}`); 6542 } 6543 return vsMode; 6544} 6545``` 6546 6547### setVideoStabilizationMode<sup>11+</sup> 6548 6549setVideoStabilizationMode(mode: VideoStabilizationMode): void 6550 6551设置视频防抖模式。需要先检查设备是否支持对应的防抖模式,可以通过[isVideoStabilizationModeSupported](#isvideostabilizationmodesupported11)方法判断所设置的模式是否支持。 6552 6553**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 6554 6555**系统能力:** SystemCapability.Multimedia.Camera.Core 6556 6557**参数:** 6558 6559| 参数名 | 类型 | 必填 | 说明 | 6560| -------- | ------------------------------------------------- | ---- | --------------------- | 6561| mode | [VideoStabilizationMode](#videostabilizationmode) | 是 | 需要设置的视频防抖模式。 | 6562 6563**错误码:** 6564 6565以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 6566 6567| 错误码ID | 错误信息 | 6568| --------------- | --------------- | 6569| 7400103 | Session not config. | 6570 6571**示例:** 6572 6573```ts 6574import { BusinessError } from '@kit.BasicServicesKit'; 6575 6576function setVideoStabilizationMode(videoSession: camera.VideoSession): void { 6577 try { 6578 videoSession.setVideoStabilizationMode(camera.VideoStabilizationMode.OFF); 6579 } catch (error) { 6580 // 失败返回错误码error.code并处理。 6581 let err = error as BusinessError; 6582 console.error(`The setVideoStabilizationMode call failed. error code: ${err.code}`); 6583 } 6584} 6585``` 6586 6587## StabilizationQuery<sup>12+</sup> 6588 6589提供了查询设备在录像模式下是否支持对应的视频防抖模式的能力。 6590 6591### isVideoStabilizationModeSupported<sup>11+</sup> 6592 6593isVideoStabilizationModeSupported(vsMode: VideoStabilizationMode): boolean 6594 6595查询是否支持指定的视频防抖模式。 6596 6597**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 6598 6599**系统能力:** SystemCapability.Multimedia.Camera.Core 6600 6601**参数:** 6602 6603| 参数名 | 类型 | 必填 | 说明 | 6604| -------- | ------------------------------------------------- | ---- | ------------------------------ | 6605| vsMode | [VideoStabilizationMode](#videostabilizationmode) | 是 | 视频防抖模式。 | 6606 6607**返回值:** 6608 6609| 类型 | 说明 | 6610| ---------- | ----------------------------- | 6611| boolean | 返回视频防抖模式是否支持。true表示支持,false表示不支持。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 6612 6613**错误码:** 6614 6615以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 6616 6617| 错误码ID | 错误信息 | 6618| --------------- | --------------- | 6619| 7400103 | Session not config, only throw in session usage. | 6620 6621**示例:** 6622 6623```ts 6624import { BusinessError } from '@kit.BasicServicesKit'; 6625 6626function isVideoStabilizationModeSupported(videoSession: camera.VideoSession): boolean { 6627 let isSupported: boolean = false; 6628 try { 6629 isSupported = videoSession.isVideoStabilizationModeSupported(camera.VideoStabilizationMode.OFF); 6630 } catch (error) { 6631 // 失败返回错误码error.code并处理。 6632 let err = error as BusinessError; 6633 console.error(`The isVideoStabilizationModeSupported call failed. error code: ${err.code}`); 6634 } 6635 return isSupported; 6636} 6637``` 6638 6639## CaptureSession<sup>(deprecated)</sup> 6640 6641拍照会话类,保存一次相机运行所需要的所有资源[CameraInput](#camerainput)、[CameraOutput](#cameraoutput),并向相机设备申请完成相机功能(录像,拍照)。 6642 6643> **说明:** 6644>从 API version 10开始支持,从API version 11开始废弃。建议使用[PhotoSession](#photosession11)、[VideoSession](#videosession11)替代。 6645 6646### beginConfig<sup>(deprecated)</sup> 6647 6648beginConfig(): void 6649 6650开始配置会话。 6651 6652> **说明:** 6653>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.beginConfig](#beginconfig11)替代。 6654 6655**系统能力:** SystemCapability.Multimedia.Camera.Core 6656 6657**错误码:** 6658 6659以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 6660 6661| 错误码ID | 错误信息 | 6662| --------------- | --------------- | 6663| 7400105 | Session config locked. | 6664 6665**示例:** 6666 6667```ts 6668import { BusinessError } from '@kit.BasicServicesKit'; 6669 6670function beginConfig(captureSession: camera.CaptureSession): void { 6671 try { 6672 captureSession.beginConfig(); 6673 } catch (error) { 6674 // 失败返回错误码error.code并处理。 6675 let err = error as BusinessError; 6676 console.error(`The beginConfig call failed. error code: ${err.code}`); 6677 } 6678} 6679``` 6680 6681### commitConfig<sup>(deprecated)</sup> 6682 6683commitConfig(callback: AsyncCallback\<void\>): void 6684 6685提交配置信息,通过注册回调函数获取结果。使用callback异步回调。 6686 6687> **说明:** 6688>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.commitConfig](#commitconfig11)替代。 6689 6690**系统能力:** SystemCapability.Multimedia.Camera.Core 6691 6692**参数:** 6693 6694| 参数名 | 类型 | 必填 | 说明 | 6695| -------- | -------------------- | ---- | -------------------- | 6696| callback | AsyncCallback\<void\> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) | 6697 6698**错误码:** 6699 6700以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 6701 6702| 错误码ID | 错误信息 | 6703| --------------- | --------------- | 6704| 7400102 | Operation not allowed. | 6705| 7400201 | Camera service fatal error. | 6706 6707**示例:** 6708 6709```ts 6710import { BusinessError } from '@kit.BasicServicesKit'; 6711 6712function commitConfig(captureSession: camera.CaptureSession): void { 6713 captureSession.commitConfig((err: BusinessError) => { 6714 if (err) { 6715 console.error(`The commitConfig call failed. error code: ${err.code}`); 6716 return; 6717 } 6718 console.info('Callback invoked to indicate the commit config success.'); 6719 }); 6720} 6721``` 6722 6723### commitConfig<sup>(deprecated)</sup> 6724 6725commitConfig(): Promise\<void\> 6726 6727提交配置信息,通过Promise获取结果。 6728 6729> **说明:** 6730>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.commitConfig](#commitconfig11-1)替代。 6731 6732**系统能力:** SystemCapability.Multimedia.Camera.Core 6733 6734**返回值:** 6735 6736| 类型 | 说明 | 6737| -------------- |-------------------| 6738| Promise\<void\> | 无返回结果的Promise对象。 | 6739 6740**错误码:** 6741 6742以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 6743 6744| 错误码ID | 错误信息 | 6745| --------------- | --------------- | 6746| 7400102 | Operation not allowed. | 6747| 7400201 | Camera service fatal error. | 6748 6749**示例:** 6750 6751```ts 6752import { BusinessError } from '@kit.BasicServicesKit'; 6753 6754function commitConfig(captureSession: camera.CaptureSession): void { 6755 captureSession.commitConfig().then(() => { 6756 console.info('Promise returned to indicate the commit config success.'); 6757 }).catch((error: BusinessError) => { 6758 // 失败返回错误码error.code并处理。 6759 console.error(`The commitConfig call failed. error code: ${error.code}`); 6760 }); 6761} 6762``` 6763 6764### addInput<sup>(deprecated)</sup> 6765 6766addInput(cameraInput: CameraInput): void 6767 6768把[CameraInput](#camerainput)加入到会话。 6769 6770> **说明:** 6771>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.addInput](#addinput11)替代。 6772 6773**系统能力:** SystemCapability.Multimedia.Camera.Core 6774 6775**参数:** 6776 6777| 参数名 | 类型 | 必填 | 说明 | 6778| ----------- | --------------------------- | ---- | ------------------------ | 6779| cameraInput | [CameraInput](#camerainput) | 是 | 需要添加的CameraInput实例。 | 6780 6781**错误码:** 6782 6783以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 6784 6785| 错误码ID | 错误信息 | 6786|---------|-----------------------------------------------| 6787| 7400101 | Parameter missing or parameter type incorrect. | 6788| 7400102 | Operation not allowed. | 6789 6790**示例:** 6791 6792```ts 6793import { BusinessError } from '@kit.BasicServicesKit'; 6794 6795function addInput(captureSession: camera.CaptureSession, cameraInput: camera.CameraInput): void { 6796 try { 6797 captureSession.addInput(cameraInput); 6798 } catch (error) { 6799 // 失败返回错误码error.code并处理。 6800 let err = error as BusinessError; 6801 console.error(`The addInput call failed. error code: ${err.code}`); 6802 } 6803} 6804``` 6805 6806### removeInput<sup>(deprecated)</sup> 6807 6808removeInput(cameraInput: CameraInput): void 6809 6810移除[CameraInput](#camerainput)。 6811 6812> **说明:** 6813>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.removeInput](#removeinput11)替代。 6814 6815**系统能力:** SystemCapability.Multimedia.Camera.Core 6816 6817**参数:** 6818 6819| 参数名 | 类型 | 必填 | 说明 | 6820| ----------- | --------------------------- | ---- | ------------------------ | 6821| cameraInput | [CameraInput](#camerainput) | 是 | 需要移除的CameraInput实例。 | 6822 6823**错误码:** 6824 6825以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 6826 6827| 错误码ID | 错误信息 | 6828| --------------- | --------------- | 6829| 7400101 | Parameter missing or parameter type incorrect. | 6830| 7400102 | Operation not allowed. | 6831 6832**示例:** 6833 6834```ts 6835import { BusinessError } from '@kit.BasicServicesKit'; 6836 6837function removeInput(captureSession: camera.CaptureSession, cameraInput: camera.CameraInput): void { 6838 try { 6839 captureSession.removeInput(cameraInput); 6840 } catch (error) { 6841 // 失败返回错误码error.code并处理。 6842 let err = error as BusinessError; 6843 console.error(`The removeInput call failed. error code: ${err.code}`); 6844 } 6845} 6846``` 6847 6848### addOutput<sup>(deprecated)</sup> 6849 6850addOutput(cameraOutput: CameraOutput): void 6851 6852把[CameraOutput](#cameraoutput)加入到会话。 6853 6854> **说明:** 6855>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.addOutput](#addoutput11)替代。 6856 6857**系统能力:** SystemCapability.Multimedia.Camera.Core 6858 6859**参数:** 6860 6861| 参数名 | 类型 | 必填 | 说明 | 6862| ------------- | ------------------------------- | ---- | ------------------------ | 6863| cameraOutput | [CameraOutput](#cameraoutput) | 是 | 需要添加的CameraOutput实例。 | 6864 6865**错误码:** 6866 6867以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 6868 6869| 错误码ID | 错误信息 | 6870| --------------- | --------------- | 6871| 7400101 | Parameter missing or parameter type incorrect. | 6872| 7400102 | Operation not allowed. | 6873 6874**示例:** 6875 6876```ts 6877import { BusinessError } from '@kit.BasicServicesKit'; 6878 6879function addOutput(captureSession: camera.CaptureSession, cameraOutput: camera.CameraOutput): void { 6880 try { 6881 captureSession.addOutput(cameraOutput); 6882 } catch (error) { 6883 // 失败返回错误码error.code并处理。 6884 let err = error as BusinessError; 6885 console.error(`The addOutput call failed. error code: ${err.code}`); 6886 } 6887} 6888``` 6889 6890### removeOutput<sup>(deprecated)</sup> 6891 6892removeOutput(cameraOutput: CameraOutput): void 6893 6894从会话中移除[CameraOutput](#cameraoutput)。 6895 6896> **说明:** 6897>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.removeOutput](#removeoutput11)替代。 6898 6899**系统能力:** SystemCapability.Multimedia.Camera.Core 6900 6901**参数:** 6902 6903| 参数名 | 类型 | 必填 | 说明 | 6904| ------------- | ------------------------------- | ---- | ------------------------ | 6905| cameraOutput | [CameraOutput](#cameraoutput) | 是 | 需要移除的CameraOutput实例。 | 6906 6907**错误码:** 6908 6909以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 6910 6911| 错误码ID | 错误信息 | 6912| --------------- | --------------- | 6913| 7400101 | Parameter missing or parameter type incorrect. | 6914| 7400102 | Operation not allowed. | 6915 6916**示例:** 6917 6918```ts 6919import { BusinessError } from '@kit.BasicServicesKit'; 6920 6921function removeOutput(captureSession: camera.CaptureSession, previewOutput: camera.PreviewOutput): void { 6922 try { 6923 captureSession.removeOutput(previewOutput); 6924 } catch (error) { 6925 // 失败返回错误码error.code并处理。 6926 let err = error as BusinessError; 6927 console.error(`The removeOutput call failed. error code: ${err.code}`); 6928 } 6929} 6930``` 6931 6932### start<sup>(deprecated)</sup> 6933 6934start(callback: AsyncCallback\<void\>): void 6935 6936开始会话工作,通过注册回调函数获取结果。使用callback异步回调。 6937 6938> **说明:** 6939>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.start](#start11)替代。 6940 6941**系统能力:** SystemCapability.Multimedia.Camera.Core 6942 6943**参数:** 6944 6945| 参数名 | 类型 | 必填 | 说明 | 6946| -------- | -------------------- | ---- | -------------------- | 6947| callback | AsyncCallback\<void\> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 6948 6949**错误码:** 6950 6951以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 6952 6953| 错误码ID | 错误信息 | 6954| --------------- | --------------- | 6955| 7400103 | Session not config. | 6956| 7400201 | Camera service fatal error. | 6957 6958**示例:** 6959 6960```ts 6961import { BusinessError } from '@kit.BasicServicesKit'; 6962 6963function startCaptureSession(captureSession: camera.CaptureSession): void { 6964 captureSession.start((err: BusinessError) => { 6965 if (err) { 6966 console.error(`Failed to start the session, error code: ${err.code}.`); 6967 return; 6968 } 6969 console.info('Callback invoked to indicate the session start success.'); 6970 }); 6971} 6972``` 6973 6974### start<sup>(deprecated)</sup> 6975 6976start(): Promise\<void\> 6977 6978开始会话工作,通过Promise获取结果。 6979 6980> **说明:** 6981>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.start](#start11-1)替代。 6982 6983**系统能力:** SystemCapability.Multimedia.Camera.Core 6984 6985**返回值:** 6986 6987| 类型 | 说明 | 6988| -------------- | ------------------------ | 6989| Promise\<void\> | 无返回结果的Promise对象。 | 6990 6991**错误码:** 6992 6993以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 6994 6995| 错误码ID | 错误信息 | 6996| --------------- | --------------- | 6997| 7400103 | Session not config. | 6998| 7400201 | Camera service fatal error. | 6999 7000**示例:** 7001 7002```ts 7003import { BusinessError } from '@kit.BasicServicesKit'; 7004 7005function startCaptureSession(captureSession: camera.CaptureSession): void { 7006 captureSession.start().then(() => { 7007 console.info('Promise returned to indicate the session start success.'); 7008 }).catch((err: BusinessError) => { 7009 console.error(`Failed to start the session, error code: ${err.code}.`); 7010 }); 7011} 7012``` 7013 7014### stop<sup>(deprecated)</sup> 7015 7016stop(callback: AsyncCallback\<void\>): void 7017 7018停止会话工作,通过注册回调函数获取结果。使用callback异步回调。 7019 7020> **说明:** 7021>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.stop](#stop11)替代。 7022 7023**系统能力:** SystemCapability.Multimedia.Camera.Core 7024 7025**参数:** 7026 7027| 参数名 | 类型 | 必填 | 说明 | 7028| -------- | -------------------- | ---- | ------------------- | 7029| callback | AsyncCallback\<void\> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 7030 7031**错误码:** 7032 7033以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 7034 7035| 错误码ID | 错误信息 | 7036| --------------- | --------------- | 7037| 7400201 | Camera service fatal error. | 7038 7039**示例:** 7040 7041```ts 7042import { BusinessError } from '@kit.BasicServicesKit'; 7043 7044function stopCaptureSession(captureSession: camera.CaptureSession): void { 7045 captureSession.stop((err: BusinessError) => { 7046 if (err) { 7047 console.error(`Failed to stop the session, error code: ${err.code}.`); 7048 return; 7049 } 7050 console.info('Callback invoked to indicate the session stop success.'); 7051 }); 7052} 7053``` 7054 7055### stop<sup>(deprecated)</sup> 7056 7057stop(): Promise\<void\> 7058 7059停止会话工作,通过Promise获取结果。 7060 7061> **说明:** 7062>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.stop](#stop11-1)替代。 7063 7064**系统能力:** SystemCapability.Multimedia.Camera.Core 7065 7066**返回值:** 7067 7068| 类型 | 说明 | 7069| -------------- | ----------------------- | 7070| Promise\<void\> | 无返回结果的Promise对象。 | 7071 7072**错误码:** 7073 7074以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 7075 7076| 错误码ID | 错误信息 | 7077| --------------- | --------------- | 7078| 7400201 | Camera service fatal error. | 7079 7080**示例:** 7081 7082```ts 7083import { BusinessError } from '@kit.BasicServicesKit'; 7084 7085function stopCaptureSession(captureSession: camera.CaptureSession): void { 7086 captureSession.stop().then(() => { 7087 console.info('Promise returned to indicate the session stop success.'); 7088 }).catch((err: BusinessError) => { 7089 console.error(`Failed to stop the session, error code: ${err.code}.`); 7090 }); 7091} 7092``` 7093 7094### release<sup>(deprecated)</sup> 7095 7096release(callback: AsyncCallback\<void\>): void 7097 7098释放会话资源,通过注册回调函数获取结果。使用callback异步回调。 7099 7100> **说明:** 7101>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.release](#release11-1)替代。 7102 7103**系统能力:** SystemCapability.Multimedia.Camera.Core 7104 7105**参数:** 7106 7107| 参数名 | 类型 | 必填 | 说明 | 7108| -------- | -------------------- | ---- | -------------------- | 7109| callback | AsyncCallback\<void\> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 7110 7111**错误码:** 7112 7113以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 7114 7115| 错误码ID | 错误信息 | 7116| --------------- | --------------- | 7117| 7400201 | Camera service fatal error. | 7118 7119**示例:** 7120 7121```ts 7122import { BusinessError } from '@kit.BasicServicesKit'; 7123 7124function releaseCaptureSession(captureSession: camera.CaptureSession): void { 7125 captureSession.release((err: BusinessError) => { 7126 if (err) { 7127 console.error(`Failed to release the CaptureSession instance, error code: ${err.code}.`); 7128 return; 7129 } 7130 console.info('Callback invoked to indicate that the CaptureSession instance is released successfully.'); 7131 }); 7132} 7133``` 7134 7135### release<sup>(deprecated)</sup> 7136 7137release(): Promise\<void\> 7138 7139释放会话资源,通过Promise获取结果。 7140 7141> **说明:** 7142>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.release](#release11-2)替代。 7143 7144**系统能力:** SystemCapability.Multimedia.Camera.Core 7145 7146**返回值:** 7147 7148| 类型 | 说明 | 7149| -------------- | ------------------------ | 7150| Promise\<void\> | 无返回结果的Promise对象。 | 7151 7152**错误码:** 7153 7154以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 7155 7156| 错误码ID | 错误信息 | 7157| --------------- | --------------- | 7158| 7400201 | Camera service fatal error. | 7159 7160**示例:** 7161 7162```ts 7163import { BusinessError } from '@kit.BasicServicesKit'; 7164 7165function releaseCaptureSession(captureSession: camera.CaptureSession): void { 7166 captureSession.release().then(() => { 7167 console.info('Promise returned to indicate that the CaptureSession instance is released successfully.'); 7168 }).catch((err: BusinessError) => { 7169 console.error(`Failed to release the CaptureSession instance, error code: ${err.code}.`); 7170 }); 7171} 7172``` 7173 7174### hasFlash<sup>(deprecated)</sup> 7175 7176hasFlash(): boolean 7177 7178检测是否有闪光灯。 7179 7180> **说明:** 7181>从 API version 10开始支持,从API version 11开始废弃。建议使用[Flash.hasFlash](#hasflash11)替代。 7182 7183**系统能力:** SystemCapability.Multimedia.Camera.Core 7184 7185**返回值:** 7186 7187| 类型 | 说明 | 7188| ---------- | ----------------------------- | 7189| boolean | 设备支持闪光灯。true表示支持,false表示不支持。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 7190 7191**错误码:** 7192 7193以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 7194 7195| 错误码ID | 错误信息 | 7196| --------------- | --------------- | 7197| 7400103 | Session not config. | 7198 7199**示例:** 7200 7201```ts 7202import { BusinessError } from '@kit.BasicServicesKit'; 7203 7204function hasFlash(captureSession: camera.CaptureSession): boolean { 7205 let status: boolean = false; 7206 try { 7207 status = captureSession.hasFlash(); 7208 } catch (error) { 7209 // 失败返回错误码error.code并处理。 7210 let err = error as BusinessError; 7211 console.error(`The hasFlash call failed. error code: ${err.code}`); 7212 } 7213 return status; 7214} 7215``` 7216 7217### isFlashModeSupported<sup>(deprecated)</sup> 7218 7219isFlashModeSupported(flashMode: FlashMode): boolean 7220 7221检测闪光灯模式是否支持。 7222 7223> **说明:** 7224>从 API version 10开始支持,从API version 11开始废弃。建议使用[Flash.isFlashModeSupported](#isflashmodesupported11)替代。 7225 7226**系统能力:** SystemCapability.Multimedia.Camera.Core 7227 7228**参数:** 7229 7230| 参数名 | 类型 | 必填 | 说明 | 7231| --------- | ----------------------- | ---- | --------------------------------- | 7232| flashMode | [FlashMode](#flashmode) | 是 | 指定闪光灯模式。 | 7233 7234**返回值:** 7235 7236| 类型 | 说明 | 7237| ---------- | ----------------------------- | 7238| boolean | 检测闪光灯模式是否支持。true表示支持,false表示不支持。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 7239 7240**错误码:** 7241 7242以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 7243 7244| 错误码ID | 错误信息 | 7245| --------------- | --------------- | 7246| 7400103 | Session not config. | 7247 7248**示例:** 7249 7250```ts 7251import { BusinessError } from '@kit.BasicServicesKit'; 7252 7253function isFlashModeSupported(captureSession: camera.CaptureSession): boolean { 7254 let status: boolean = false; 7255 try { 7256 status = captureSession.isFlashModeSupported(camera.FlashMode.FLASH_MODE_AUTO); 7257 } catch (error) { 7258 // 失败返回错误码error.code并处理。 7259 let err = error as BusinessError; 7260 console.error(`The isFlashModeSupported call failed. error code: ${err.code}`); 7261 } 7262 return status; 7263} 7264``` 7265 7266### setFlashMode<sup>(deprecated)</sup> 7267 7268setFlashMode(flashMode: FlashMode): void 7269 7270设置闪光灯模式。 7271 7272进行设置之前,需要先检查: 7273 72741. 设备是否支持闪光灯,可使用方法[hasFlash](#hasflashdeprecated)。 72752. 设备是否支持指定的闪光灯模式,可使用方法[isFlashModeSupported](#isflashmodesupporteddeprecated)。 7276 7277> **说明:** 7278>从 API version 10开始支持,从API version 11开始废弃。建议使用[Flash.setFlashMode](#setflashmode11)替代。 7279 7280**系统能力:** SystemCapability.Multimedia.Camera.Core 7281 7282**参数:** 7283 7284| 参数名 | 类型 | 必填 | 说明 | 7285| --------- | ----------------------- | ---- | -------------------- | 7286| flashMode | [FlashMode](#flashmode) | 是 | 指定闪光灯模式。 | 7287 7288**错误码:** 7289 7290以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 7291 7292| 错误码ID | 错误信息 | 7293| --------------- | --------------- | 7294| 7400103 | Session not config. | 7295 7296**示例:** 7297 7298```ts 7299import { BusinessError } from '@kit.BasicServicesKit'; 7300 7301function setFlashMode(captureSession: camera.CaptureSession): void { 7302 try { 7303 captureSession.setFlashMode(camera.FlashMode.FLASH_MODE_AUTO); 7304 } catch (error) { 7305 // 失败返回错误码error.code并处理。 7306 let err = error as BusinessError; 7307 console.error(`The setFlashMode call failed. error code: ${err.code}`); 7308 } 7309} 7310``` 7311 7312### getFlashMode<sup>(deprecated)</sup> 7313 7314getFlashMode(): FlashMode 7315 7316获取当前设备的闪光灯模式。 7317 7318> **说明:** 7319>从 API version 10开始支持,从API version 11开始废弃。建议使用[Flash.getFlashMode](#getflashmode11)替代。 7320 7321**系统能力:** SystemCapability.Multimedia.Camera.Core 7322 7323**返回值:** 7324 7325| 类型 | 说明 | 7326| ---------- | ----------------------------- | 7327| [FlashMode](#flashmode) | 获取当前设备的闪光灯模式。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 7328 7329**错误码:** 7330 7331以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 7332 7333| 错误码ID | 错误信息 | 7334| --------------- | --------------- | 7335| 7400103 | Session not config. | 7336 7337**示例:** 7338 7339```ts 7340import { BusinessError } from '@kit.BasicServicesKit'; 7341 7342function getFlashMode(captureSession: camera.CaptureSession): camera.FlashMode | undefined { 7343 let flashMode: camera.FlashMode | undefined = undefined; 7344 try { 7345 flashMode = captureSession.getFlashMode(); 7346 } catch (error) { 7347 // 失败返回错误码error.code并处理。 7348 let err = error as BusinessError; 7349 console.error(`The getFlashMode call failed.error code: ${err.code}`); 7350 } 7351 return flashMode; 7352} 7353``` 7354 7355### isExposureModeSupported<sup>(deprecated)</sup> 7356 7357isExposureModeSupported(aeMode: ExposureMode): boolean 7358 7359查询曝光模式是否支持。 7360 7361> **说明:** 7362>从 API version 10开始支持,从API version 11开始废弃。建议使用[AutoExposure.isExposureModeSupported](#isexposuremodesupported11)替代。 7363 7364**系统能力:** SystemCapability.Multimedia.Camera.Core 7365 7366**参数:** 7367 7368| 参数名 | 类型 | 必填 | 说明 | 7369| -------- | -------------------------------| ---- | ----------------------------- | 7370| aeMode | [ExposureMode](#exposuremode) | 是 | 曝光模式。 | 7371 7372**返回值:** 7373 7374| 类型 | 说明 | 7375| ---------- | ----------------------------- | 7376| boolean | 获取是否支持曝光模式。true表示支持,false表示不支持。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 7377 7378**错误码:** 7379 7380以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 7381 7382| 错误码ID | 错误信息 | 7383| --------------- | --------------- | 7384| 7400103 | Session not config. | 7385 7386**示例:** 7387 7388```ts 7389import { BusinessError } from '@kit.BasicServicesKit'; 7390 7391function isExposureModeSupported(captureSession: camera.CaptureSession): boolean { 7392 let isSupported: boolean = false; 7393 try { 7394 isSupported = captureSession.isExposureModeSupported(camera.ExposureMode.EXPOSURE_MODE_LOCKED); 7395 } catch (error) { 7396 // 失败返回错误码error.code并处理。 7397 let err = error as BusinessError; 7398 console.error(`The isExposureModeSupported call failed. error code: ${err.code}`); 7399 } 7400 return isSupported; 7401} 7402``` 7403 7404### getExposureMode<sup>(deprecated)</sup> 7405 7406getExposureMode(): ExposureMode 7407 7408获取当前曝光模式。 7409 7410> **说明:** 7411>从 API version 10开始支持,从API version 11开始废弃。建议使用[AutoExposure.getExposureMode](#getexposuremode11)替代。 7412 7413**系统能力:** SystemCapability.Multimedia.Camera.Core 7414 7415**返回值:** 7416 7417| 类型 | 说明 | 7418| ---------- | ----------------------------- | 7419| [ExposureMode](#exposuremode) | 获取当前曝光模式。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 7420 7421**错误码:** 7422 7423以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 7424 7425| 错误码ID | 错误信息 | 7426| --------------- | --------------- | 7427| 7400103 | Session not config. | 7428 7429**示例:** 7430 7431```ts 7432import { BusinessError } from '@kit.BasicServicesKit'; 7433 7434function getExposureMode(captureSession: camera.CaptureSession): camera.ExposureMode | undefined { 7435 let exposureMode: camera.ExposureMode | undefined = undefined; 7436 try { 7437 exposureMode = captureSession.getExposureMode(); 7438 } catch (error) { 7439 // 失败返回错误码error.code并处理。 7440 let err = error as BusinessError; 7441 console.error(`The getExposureMode call failed. error code: ${err.code}`); 7442 } 7443 return exposureMode; 7444} 7445``` 7446 7447### setExposureMode<sup>(deprecated)</sup> 7448 7449setExposureMode(aeMode: ExposureMode): void 7450 7451设置曝光模式。进行设置之前,需要先检查设备是否支持指定的曝光模式,可使用方法[isExposureModeSupported](#isexposuremodesupporteddeprecated)。 7452 7453> **说明:** 7454>从 API version 10开始支持,从API version 11开始废弃。建议使用[AutoExposure.setExposureMode](#setexposuremode11)替代。 7455 7456**系统能力:** SystemCapability.Multimedia.Camera.Core 7457 7458**参数:** 7459 7460| 参数名 | 类型 | 必填 | 说明 | 7461| -------- | -------------------------------| ---- | ----------------------- | 7462| aeMode | [ExposureMode](#exposuremode) | 是 | 曝光模式。 | 7463 7464**错误码:** 7465 7466以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 7467 7468| 错误码ID | 错误信息 | 7469| --------------- | --------------- | 7470| 7400103 | Session not config. | 7471 7472**示例:** 7473 7474```ts 7475import { BusinessError } from '@kit.BasicServicesKit'; 7476 7477function setExposureMode(captureSession: camera.CaptureSession): void { 7478 try { 7479 captureSession.setExposureMode(camera.ExposureMode.EXPOSURE_MODE_LOCKED); 7480 } catch (error) { 7481 // 失败返回错误码error.code并处理。 7482 let err = error as BusinessError; 7483 console.error(`The setExposureMode call failed. error code: ${err.code}`); 7484 } 7485} 7486``` 7487 7488### getMeteringPoint<sup>(deprecated)</sup> 7489 7490getMeteringPoint(): Point 7491 7492查询曝光区域中心点。 7493 7494> **说明:** 7495>从 API version 10开始支持,从API version 11开始废弃。建议使用[AutoExposure.getMeteringPoint](#getmeteringpoint11)替代。 7496 7497**系统能力:** SystemCapability.Multimedia.Camera.Core 7498 7499**返回值:** 7500 7501| 类型 | 说明 | 7502| ---------- | ----------------------------- | 7503| [Point](#point) | 获取当前曝光点。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 7504 7505**错误码:** 7506 7507以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 7508 7509| 错误码ID | 错误信息 | 7510| --------------- | --------------- | 7511| 7400103 | Session not config. | 7512 7513**示例:** 7514 7515```ts 7516import { BusinessError } from '@kit.BasicServicesKit'; 7517 7518function getMeteringPoint(captureSession: camera.CaptureSession): camera.Point | undefined { 7519 let exposurePoint: camera.Point | undefined = undefined; 7520 try { 7521 exposurePoint = captureSession.getMeteringPoint(); 7522 } catch (error) { 7523 // 失败返回错误码error.code并处理。 7524 let err = error as BusinessError; 7525 console.error(`The getMeteringPoint call failed. error code: ${err.code}`); 7526 } 7527 return exposurePoint; 7528} 7529``` 7530 7531### setMeteringPoint<sup>(deprecated)</sup> 7532 7533setMeteringPoint(point: Point): void 7534 7535设置曝光区域中心点,曝光点应位于0-1坐标系内,该坐标系左上角为{0,0},右下角为{1,1}。 7536此坐标系是以设备充电口在右侧时的横向设备方向为基准的,例如应用的预览界面布局以 7537设备充电口在下侧时的竖向方向为基准,布局宽高为{w,h},且触碰点为{x,y}, 7538则转换后的坐标点为{y/h,1-x/w}。 7539 7540> **说明:** 7541>从 API version 10开始支持,从API version 11开始废弃。建议使用[AutoExposure.setMeteringPoint](#setmeteringpoint11)替代。 7542 7543**系统能力:** SystemCapability.Multimedia.Camera.Core 7544 7545**参数:** 7546 7547| 参数名 | 类型 | 必填 | 说明 | 7548| ------------- | -------------------------------| ---- | ------------------- | 7549| point | [Point](#point) | 是 | 曝光点,x,y设置范围应在[0,1]之内,超过范围,如果小于0设置0,大于1设置1。 | 7550 7551**错误码:** 7552 7553以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 7554 7555| 错误码ID | 错误信息 | 7556| --------------- | --------------- | 7557| 7400103 | Session not config. | 7558 7559**示例:** 7560 7561```ts 7562import { BusinessError } from '@kit.BasicServicesKit'; 7563 7564function setMeteringPoint(captureSession: camera.CaptureSession): void { 7565 const point: camera.Point = {x: 1, y: 1}; 7566 try { 7567 captureSession.setMeteringPoint(point); 7568 } catch (error) { 7569 // 失败返回错误码error.code并处理。 7570 let err = error as BusinessError; 7571 console.error(`The setMeteringPoint call failed. error code: ${err.code}`); 7572 } 7573} 7574``` 7575 7576### getExposureBiasRange<sup>(deprecated)</sup> 7577 7578getExposureBiasRange(): Array\<number\> 7579 7580查询曝光补偿范围。 7581 7582> **说明:** 7583>从 API version 10开始支持,从API version 11开始废弃。建议使用[AutoExposure.getExposureBiasRange](#getexposurebiasrange11)替代。 7584 7585**系统能力:** SystemCapability.Multimedia.Camera.Core 7586 7587**返回值:** 7588 7589| 类型 | 说明 | 7590| ---------- | ----------------------------- | 7591| Array\<number\> | 获取补偿范围的数组。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 7592 7593**错误码:** 7594 7595以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 7596 7597| 错误码ID | 错误信息 | 7598| --------------- | --------------- | 7599| 7400103 | Session not config. | 7600 7601**示例:** 7602 7603```ts 7604import { BusinessError } from '@kit.BasicServicesKit'; 7605 7606function getExposureBiasRange(captureSession: camera.CaptureSession): Array<number> { 7607 let biasRangeArray: Array<number> = []; 7608 try { 7609 biasRangeArray = captureSession.getExposureBiasRange(); 7610 } catch (error) { 7611 // 失败返回错误码error.code并处理。 7612 let err = error as BusinessError; 7613 console.error(`The getExposureBiasRange call failed. error code: ${err.code}`); 7614 } 7615 return biasRangeArray; 7616} 7617``` 7618 7619### setExposureBias<sup>(deprecated)</sup> 7620 7621setExposureBias(exposureBias: number): void 7622 7623设置曝光补偿,曝光补偿值(EV)。 7624 7625进行设置之前,建议先通过方法[getExposureBiasRange](#getexposurebiasrangedeprecated)查询支持的范围。 7626 7627> **说明:** 7628>从 API version 10开始支持,从API version 11开始废弃。建议使用[AutoExposure.setExposureBias](#setexposurebias11)替代。 7629 7630**系统能力:** SystemCapability.Multimedia.Camera.Core 7631 7632**参数:** 7633 7634| 参数名 | 类型 | 必填 | 说明 | 7635| -------- | -------------------------------|-----|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| 7636| exposureBias | number | 是 | 曝光补偿,[getExposureBiasRange](#getexposurebiasrange11)查询支持的范围,如果设置超过支持范围的值,自动匹配到就近临界点。曝光补偿存在步长,如步长为0.5。则设置1.2时,获取到实际生效曝光补偿为1.0。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。传参为null或者undefined,作为0处理,曝光补偿设置0。 | 7637 7638**错误码:** 7639 7640以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 7641 7642| 错误码ID | 错误信息 | 7643| --------------- | --------------- | 7644| 7400103 | Session not config. | 7645 7646**示例:** 7647 7648```ts 7649import { BusinessError } from '@kit.BasicServicesKit'; 7650 7651function setExposureBias(captureSession: camera.CaptureSession, biasRangeArray: Array<number>): void { 7652 if (biasRangeArray && biasRangeArray.length > 0) { 7653 let exposureBias = biasRangeArray[0]; 7654 try { 7655 captureSession.setExposureBias(exposureBias); 7656 } catch (error) { 7657 // 失败返回错误码error.code并处理。 7658 let err = error as BusinessError; 7659 console.error(`The setExposureBias call failed. error code: ${err.code}`); 7660 } 7661 } 7662} 7663``` 7664 7665### getExposureValue<sup>(deprecated)</sup> 7666 7667getExposureValue(): number 7668 7669查询当前的曝光值。 7670 7671> **说明:** 7672>从 API version 10开始支持,从API version 11开始废弃。建议使用[AutoExposure.getExposureValue](#getexposurevalue11)替代。 7673 7674**系统能力:** SystemCapability.Multimedia.Camera.Core 7675 7676**返回值:** 7677 7678| 类型 | 说明 | 7679| ---------- | ----------------------------- | 7680| number | 获取曝光值。曝光补偿存在步长,如步长为0.5。则设置1.2时,获取到实际生效曝光补偿为1.0。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 7681 7682**错误码:** 7683 7684以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 7685 7686| 错误码ID | 错误信息 | 7687| --------------- | --------------- | 7688| 7400103 | Session not config. | 7689 7690**示例:** 7691 7692```ts 7693import { BusinessError } from '@kit.BasicServicesKit'; 7694 7695function getExposureValue(captureSession: camera.CaptureSession): number { 7696 const invalidValue: number = -1; 7697 let exposureValue: number = invalidValue; 7698 try { 7699 exposureValue = captureSession.getExposureValue(); 7700 } catch (error) { 7701 // 失败返回错误码error.code并处理。 7702 let err = error as BusinessError; 7703 console.error(`The getExposureValue call failed. error code: ${err.code}`); 7704 } 7705 return exposureValue; 7706} 7707``` 7708 7709### isFocusModeSupported<sup>(deprecated)</sup> 7710 7711isFocusModeSupported(afMode: FocusMode): boolean 7712 7713查询对焦模式是否支持。 7714 7715> **说明:** 7716>从 API version 10开始支持,从API version 11开始废弃。建议使用[Focus.isFocusModeSupported](#isfocusmodesupported11)替代。 7717 7718**系统能力:** SystemCapability.Multimedia.Camera.Core 7719 7720**参数:** 7721 7722| 参数名 | 类型 | 必填 | 说明 | 7723| -------- | ----------------------- | ---- | -------------------------------- | 7724| afMode | [FocusMode](#focusmode) | 是 | 指定的焦距模式。 | 7725 7726**返回值:** 7727 7728| 类型 | 说明 | 7729| ---------- | ----------------------------- | 7730| boolean | 检测对焦模式是否支持。true表示支持,false表示不支持。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 7731 7732**错误码:** 7733 7734以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 7735 7736| 错误码ID | 错误信息 | 7737| --------------- | --------------- | 7738| 7400103 | Session not config. | 7739 7740**示例:** 7741 7742```ts 7743import { BusinessError } from '@kit.BasicServicesKit'; 7744 7745function isFocusModeSupported(captureSession: camera.CaptureSession): boolean { 7746 let status: boolean = false; 7747 try { 7748 status = captureSession.isFocusModeSupported(camera.FocusMode.FOCUS_MODE_AUTO); 7749 } catch (error) { 7750 // 失败返回错误码error.code并处理。 7751 let err = error as BusinessError; 7752 console.error(`The isFocusModeSupported call failed. error code: ${err.code}`); 7753 } 7754 return status; 7755} 7756``` 7757 7758### setFocusMode<sup>(deprecated)</sup> 7759 7760setFocusMode(afMode: FocusMode): void 7761 7762设置对焦模式。 7763 7764进行设置之前,需要先检查设备是否支持指定的焦距模式,可使用方法[isFocusModeSupported](#isfocusmodesupporteddeprecated)。 7765 7766> **说明:** 7767>从 API version 10开始支持,从API version 11开始废弃。建议使用[Focus.setFocusMode](#setfocusmode11)替代。 7768 7769**系统能力:** SystemCapability.Multimedia.Camera.Core 7770 7771**参数:** 7772 7773| 参数名 | 类型 | 必填 | 说明 | 7774| -------- | ----------------------- | ---- | ------------------- | 7775| afMode | [FocusMode](#focusmode) | 是 | 指定的焦距模式。 | 7776 7777**错误码:** 7778 7779以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 7780 7781| 错误码ID | 错误信息 | 7782| --------------- | --------------- | 7783| 7400103 | Session not config. | 7784 7785**示例:** 7786 7787```ts 7788import { BusinessError } from '@kit.BasicServicesKit'; 7789 7790function setFocusMode(captureSession: camera.CaptureSession): void { 7791 try { 7792 captureSession.setFocusMode(camera.FocusMode.FOCUS_MODE_AUTO); 7793 } catch (error) { 7794 // 失败返回错误码error.code并处理。 7795 let err = error as BusinessError; 7796 console.error(`The setFocusMode call failed. error code: ${err.code}`); 7797 } 7798} 7799``` 7800 7801### getFocusMode<sup>(deprecated)</sup> 7802 7803getFocusMode(): FocusMode 7804 7805获取当前的对焦模式。 7806 7807> **说明:** 7808>从 API version 10开始支持,从API version 11开始废弃。建议使用[Focus.getFocusMode](#getfocusmode11)替代。 7809 7810**系统能力:** SystemCapability.Multimedia.Camera.Core 7811 7812**返回值:** 7813 7814| 类型 | 说明 | 7815| ---------- | ----------------------------- | 7816| [FocusMode](#focusmode) | 获取当前设备的焦距模式。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 7817 7818**错误码:** 7819 7820以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 7821 7822| 错误码ID | 错误信息 | 7823| --------------- | --------------- | 7824| 7400103 | Session not config. | 7825 7826**示例:** 7827 7828```ts 7829import { BusinessError } from '@kit.BasicServicesKit'; 7830 7831function getFocusMode(captureSession: camera.CaptureSession): camera.FocusMode | undefined { 7832 let afMode: camera.FocusMode | undefined = undefined; 7833 try { 7834 afMode = captureSession.getFocusMode(); 7835 } catch (error) { 7836 // 失败返回错误码error.code并处理。 7837 let err = error as BusinessError; 7838 console.error(`The getFocusMode call failed. error code: ${err.code}`); 7839 } 7840 return afMode; 7841} 7842``` 7843 7844### setFocusPoint<sup>(deprecated)</sup> 7845 7846setFocusPoint(point: Point): void 7847 7848设置焦点,焦点应在0-1坐标系内,该坐标系左上角为{0,0},右下角为{1,1}。 7849此坐标系是以设备充电口在右侧时的横向设备方向为基准的,例如应用的预览界面布局以 7850设备充电口在下侧时的竖向方向为基准,布局宽高为{w,h},且触碰点为{x,y}, 7851则转换后的坐标点为{y/h,1-x/w}。 7852 7853> **说明:** 7854>从 API version 10开始支持,从API version 11开始废弃。建议使用[Focus.setFocusPoint](#setfocuspoint11)替代。 7855 7856**系统能力:** SystemCapability.Multimedia.Camera.Core 7857 7858**参数:** 7859 7860| 参数名 | 类型 | 必填 | 说明 | 7861|-------| ----------------------- |-----| ------------------- | 7862| point | [Point](#point) | 是 | 焦点。x,y设置范围应在[0,1]之内,超过范围,如果小于0设置0,大于1设置1。 | 7863 7864**错误码:** 7865 7866以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 7867 7868| 错误码ID | 错误信息 | 7869| --------------- | --------------- | 7870| 7400103 | Session not config. | 7871 7872**示例:** 7873 7874```ts 7875import { BusinessError } from '@kit.BasicServicesKit'; 7876 7877function setFocusPoint(captureSession: camera.CaptureSession): void { 7878 const focusPoint: camera.Point = {x: 1, y: 1}; 7879 try { 7880 captureSession.setFocusPoint(focusPoint); 7881 } catch (error) { 7882 // 失败返回错误码error.code并处理。 7883 let err = error as BusinessError; 7884 console.error(`The setFocusPoint call failed. error code: ${err.code}`); 7885 } 7886} 7887``` 7888 7889### getFocusPoint<sup>(deprecated)</sup> 7890 7891getFocusPoint(): Point 7892 7893查询焦点。 7894 7895> **说明:** 7896>从 API version 10开始支持,从API version 11开始废弃。建议使用[Focus.getFocusPoint](#getfocuspoint11)替代。 7897 7898**系统能力:** SystemCapability.Multimedia.Camera.Core 7899 7900**返回值:** 7901 7902| 类型 | 说明 | 7903| ---------- | ----------------------------- | 7904| [Point](#point) | 用于获取当前焦点。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 7905 7906**错误码:** 7907 7908以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 7909 7910| 错误码ID | 错误信息 | 7911| --------------- | --------------- | 7912| 7400103 | Session not config. | 7913 7914**示例:** 7915 7916```ts 7917import { BusinessError } from '@kit.BasicServicesKit'; 7918 7919function getFocusPoint(captureSession: camera.CaptureSession): camera.Point | undefined { 7920 let point: camera.Point | undefined = undefined; 7921 try { 7922 point = captureSession.getFocusPoint(); 7923 } catch (error) { 7924 // 失败返回错误码error.code并处理。 7925 let err = error as BusinessError; 7926 console.error(`The getFocusPoint call failed. error code: ${err.code}`); 7927 } 7928 return point; 7929} 7930``` 7931 7932### getFocalLength<sup>(deprecated)</sup> 7933 7934getFocalLength(): number 7935 7936查询焦距值。 7937 7938> **说明:** 7939>从 API version 10开始支持,从API version 11开始废弃。建议使用[Focus.getFocalLength](#getfocallength11)替代。 7940 7941**系统能力:** SystemCapability.Multimedia.Camera.Core 7942 7943**返回值:** 7944 7945| 类型 | 说明 | 7946| ---------- | ----------------------------- | 7947| number | 用于获取当前焦距。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 7948 7949**错误码:** 7950 7951以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 7952 7953| 错误码ID | 错误信息 | 7954| --------------- | --------------- | 7955| 7400103 | Session not config. | 7956 7957**示例:** 7958 7959```ts 7960import { BusinessError } from '@kit.BasicServicesKit'; 7961 7962function getFocalLength(captureSession: camera.CaptureSession): number { 7963 const invalidValue: number = -1; 7964 let focalLength: number = invalidValue; 7965 try { 7966 focalLength = captureSession.getFocalLength(); 7967 } catch (error) { 7968 // 失败返回错误码error.code并处理。 7969 let err = error as BusinessError; 7970 console.error(`The getFocalLength call failed. error code: ${err.code}`); 7971 } 7972 return focalLength; 7973} 7974``` 7975 7976### getZoomRatioRange<sup>(deprecated)</sup> 7977 7978getZoomRatioRange(): Array\<number\> 7979 7980获取支持的变焦范围。 7981 7982> **说明:** 7983>从 API version 10开始支持,从API version 11开始废弃。建议使用[Zoom.getZoomRatioRange](#getzoomratiorange11)替代。 7984 7985**系统能力:** SystemCapability.Multimedia.Camera.Core 7986 7987**返回值:** 7988 7989| 类型 | 说明 | 7990| ---------- | ----------------------------- | 7991| Array\<number\> | 用于获取可变焦距比范围,返回的数组包括其最小值和最大值。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 7992 7993**错误码:** 7994 7995以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 7996 7997| 错误码ID | 错误信息 | 7998| --------------- | --------------- | 7999| 7400103 | Session not config. | 8000 8001**示例:** 8002 8003```ts 8004import { BusinessError } from '@kit.BasicServicesKit'; 8005 8006function getZoomRatioRange(captureSession: camera.CaptureSession): Array<number> { 8007 let zoomRatioRange: Array<number> = []; 8008 try { 8009 zoomRatioRange = captureSession.getZoomRatioRange(); 8010 } catch (error) { 8011 // 失败返回错误码error.code并处理。 8012 let err = error as BusinessError; 8013 console.error(`The getZoomRatioRange call failed. error code: ${err.code}`); 8014 } 8015 return zoomRatioRange; 8016} 8017``` 8018 8019### setZoomRatio<sup>(deprecated)</sup> 8020 8021setZoomRatio(zoomRatio: number): void 8022 8023设置变焦比,变焦精度最高为小数点后两位,如果设置超过支持的精度范围,则只保留精度范围内数值。 8024 8025> **说明:** 8026>从 API version 10开始支持,从API version 11开始废弃。建议使用[Zoom.setZoomRatio](#setzoomratio11)替代。 8027 8028**系统能力:** SystemCapability.Multimedia.Camera.Core 8029 8030**参数:** 8031 8032| 参数名 | 类型 | 必填 | 说明 | 8033| --------- | -------------------- |-----| ------------------- | 8034| zoomRatio | number | 是 | 可变焦距比,通过[getZoomRatioRange](#getzoomratiorange11)获取支持的变焦范围,如果设置超过支持范围的值,则只保留精度范围内数值。传参为null或者undefined,作为0处理,变焦设置最小值。 | 8035 8036**错误码:** 8037 8038以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 8039 8040| 错误码ID | 错误信息 | 8041| --------------- | --------------- | 8042| 7400103 | Session not config. | 8043 8044**示例:** 8045 8046```ts 8047import { BusinessError } from '@kit.BasicServicesKit'; 8048 8049function setZoomRatio(captureSession: camera.CaptureSession, zoomRatioRange: Array<number>): void { 8050 if (zoomRatioRange === undefined || zoomRatioRange.length <= 0) { 8051 return; 8052 } 8053 let zoomRatio = zoomRatioRange[0]; 8054 try { 8055 captureSession.setZoomRatio(zoomRatio); 8056 } catch (error) { 8057 // 失败返回错误码error.code并处理。 8058 let err = error as BusinessError; 8059 console.error(`The setZoomRatio call failed. error code: ${err.code}`); 8060 } 8061} 8062``` 8063 8064### getZoomRatio<sup>(deprecated)</sup> 8065 8066getZoomRatio(): number 8067 8068获取当前的变焦比。 8069 8070> **说明:** 8071>从 API version 10开始支持,从API version 11开始废弃。建议使用[Zoom.getZoomRatio](#getzoomratio11)替代。 8072 8073**系统能力:** SystemCapability.Multimedia.Camera.Core 8074 8075**返回值:** 8076 8077| 类型 | 说明 | 8078| ---------- | ----------------------------- | 8079| number | 获取当前的变焦比结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 8080 8081**错误码:** 8082 8083以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 8084 8085| 错误码ID | 错误信息 | 8086| --------------- | --------------- | 8087| 7400103 | Session not config. | 8088 8089**示例:** 8090 8091```ts 8092import { BusinessError } from '@kit.BasicServicesKit'; 8093 8094function getZoomRatio(captureSession: camera.CaptureSession): number { 8095 const invalidValue: number = -1; 8096 let zoomRatio: number = invalidValue; 8097 try { 8098 zoomRatio = captureSession.getZoomRatio(); 8099 } catch (error) { 8100 // 失败返回错误码error.code并处理。 8101 let err = error as BusinessError; 8102 console.error(`The getZoomRatio call failed. error code: ${err.code}`); 8103 } 8104 return zoomRatio; 8105} 8106``` 8107 8108### isVideoStabilizationModeSupported<sup>(deprecated)</sup> 8109 8110isVideoStabilizationModeSupported(vsMode: VideoStabilizationMode): boolean 8111 8112查询是否支持指定的视频防抖模式。 8113 8114> **说明:** 8115>从 API version 10开始支持,从API version 11开始废弃。建议使用[Stabilization.isVideoStabilizationModeSupported](#isvideostabilizationmodesupported11)替代。 8116 8117**系统能力:** SystemCapability.Multimedia.Camera.Core 8118 8119**参数:** 8120 8121| 参数名 | 类型 | 必填 | 说明 | 8122| -------- | ------------------------------------------------- | ---- | ------------------------------ | 8123| vsMode | [VideoStabilizationMode](#videostabilizationmode) | 是 | 视频防抖模式。传参为null或者undefined,作为0处理,超级防抖模式关闭。 | 8124 8125**返回值:** 8126 8127| 类型 | 说明 | 8128| ---------- | ----------------------------- | 8129| boolean | 返回视频防抖模式是否支持。true表示支持,false表示不支持。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 8130 8131**错误码:** 8132 8133以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 8134 8135| 错误码ID | 错误信息 | 8136| --------------- | --------------- | 8137| 7400103 | Session not config. | 8138 8139**示例:** 8140 8141```ts 8142import { BusinessError } from '@kit.BasicServicesKit'; 8143 8144function isVideoStabilizationModeSupported(captureSession: camera.CaptureSession): boolean { 8145 let isSupported: boolean = false; 8146 try { 8147 isSupported = captureSession.isVideoStabilizationModeSupported(camera.VideoStabilizationMode.OFF); 8148 } catch (error) { 8149 // 失败返回错误码error.code并处理。 8150 let err = error as BusinessError; 8151 console.error(`The isVideoStabilizationModeSupported call failed. error code: ${err.code}`); 8152 } 8153 return isSupported; 8154} 8155``` 8156 8157### getActiveVideoStabilizationMode<sup>(deprecated)</sup> 8158 8159getActiveVideoStabilizationMode(): VideoStabilizationMode 8160 8161查询当前正在使用的视频防抖模式。 8162 8163> **说明:** 8164>从 API version 10开始支持,从API version 11开始废弃。建议使用[Stabilization.getActiveVideoStabilizationMode](#getactivevideostabilizationmode11)替代。 8165 8166**系统能力:** SystemCapability.Multimedia.Camera.Core 8167 8168**返回值:** 8169 8170| 类型 | 说明 | 8171| ---------- | ----------------------------- | 8172| [VideoStabilizationMode](#videostabilizationmode) | 视频防抖是否正在使用。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 8173 8174**错误码:** 8175 8176以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 8177 8178| 错误码ID | 错误信息 | 8179| --------------- | --------------- | 8180| 7400103 | Session not config. | 8181 8182**示例:** 8183 8184```ts 8185import { BusinessError } from '@kit.BasicServicesKit'; 8186 8187function getActiveVideoStabilizationMode(captureSession: camera.CaptureSession): camera.VideoStabilizationMode | undefined { 8188 let vsMode: camera.VideoStabilizationMode | undefined = undefined; 8189 try { 8190 vsMode = captureSession.getActiveVideoStabilizationMode(); 8191 } catch (error) { 8192 // 失败返回错误码error.code并处理。 8193 let err = error as BusinessError; 8194 console.error(`The getActiveVideoStabilizationMode call failed. error code: ${err.code}`); 8195 } 8196 return vsMode; 8197} 8198``` 8199 8200### setVideoStabilizationMode<sup>(deprecated)</sup> 8201 8202setVideoStabilizationMode(mode: VideoStabilizationMode): void 8203 8204设置视频防抖模式。需要先检查设备是否支持对应的防抖模式,可以通过[isVideoStabilizationModeSupported](#isvideostabilizationmodesupporteddeprecated)方法判断所设置的模式是否支持。 8205 8206> **说明:** 8207>从 API version 10开始支持,从API version 11开始废弃。建议使用[Stabilization.setVideoStabilizationMode](#setvideostabilizationmode11)替代。 8208 8209**系统能力:** SystemCapability.Multimedia.Camera.Core 8210 8211**参数:** 8212 8213| 参数名 | 类型 | 必填 | 说明 | 8214| -------- | ------------------------------------------------- | ---- | --------------------- | 8215| mode | [VideoStabilizationMode](#videostabilizationmode) | 是 | 需要设置的视频防抖模式。传参为null或者undefined,作为0处理,超级防抖模式关闭。 | 8216 8217**错误码:** 8218 8219以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 8220 8221| 错误码ID | 错误信息 | 8222| --------------- | --------------- | 8223| 7400103 | Session not config. | 8224 8225**示例:** 8226 8227```ts 8228import { BusinessError } from '@kit.BasicServicesKit'; 8229 8230function setVideoStabilizationMode(captureSession: camera.CaptureSession): void { 8231 try { 8232 captureSession.setVideoStabilizationMode(camera.VideoStabilizationMode.OFF); 8233 } catch (error) { 8234 // 失败返回错误码error.code并处理。 8235 let err = error as BusinessError; 8236 console.error(`The setVideoStabilizationMode call failed. error code: ${err.code}`); 8237 } 8238} 8239``` 8240 8241### on('focusStateChange')<sup>(deprecated)</sup> 8242 8243on(type: 'focusStateChange', callback: AsyncCallback\<FocusState\>): void 8244 8245监听相机聚焦的状态变化,通过注册回调函数获取结果。使用callback异步回调。 8246 8247> **说明:** 8248> 从 API version 10开始支持,从API version 11开始废弃。建议使用[VideoSession.on('focusStateChange')](#onfocusstatechange11-1)替代。 8249> 8250> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 8251 8252**系统能力:** SystemCapability.Multimedia.Camera.Core 8253 8254**参数:** 8255 8256| 参数名 | 类型 | 必填 | 说明 | 8257| -------- | ----------------------------------------- | ---- | ------------------------ | 8258| type | string | 是 | 监听事件,固定为'focusStateChange',session 创建成功可监听。仅当自动对焦模式时,且相机对焦状态发生改变时可触发该事件。 | 8259| callback | AsyncCallback\<[FocusState](#focusstate)\> | 是 | 回调函数,用于获取当前对焦状态。 | 8260 8261**示例:** 8262 8263```ts 8264import { BusinessError } from '@kit.BasicServicesKit'; 8265 8266function registerFocusStateChange(captureSession: camera.CaptureSession): void { 8267 captureSession.on('focusStateChange', (err: BusinessError, focusState: camera.FocusState) => { 8268 if (err !== undefined && err.code !== 0) { 8269 console.error(`Callback Error, errorCode: ${err.code}`); 8270 return; 8271 } 8272 console.info(`Focus state: ${focusState}`); 8273 }); 8274} 8275``` 8276 8277### off('focusStateChange')<sup>(deprecated)</sup> 8278 8279off(type: 'focusStateChange', callback?: AsyncCallback\<FocusState\>): void 8280 8281注销监听相机聚焦的状态变化。 8282 8283> **说明:** 8284>从 API version 10开始支持,从API version 11开始废弃。建议使用[VideoSession.off('focusStateChange')](#offfocusstatechange11-1)替代。 8285 8286**系统能力:** SystemCapability.Multimedia.Camera.Core 8287 8288**参数:** 8289 8290| 参数名 | 类型 | 必填 | 说明 | 8291| -------- | ----------------------------------------- | ---- | ------------------------ | 8292| type | string | 是 | 监听事件,固定为'focusStateChange',session 创建成功可监听。| 8293| callback | AsyncCallback\<[FocusState](#focusstate)\> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 8294 8295**示例:** 8296 8297```ts 8298function unregisterFocusStateChange(captureSession: camera.CaptureSession): void { 8299 captureSession.off('focusStateChange'); 8300} 8301``` 8302 8303### on('error')<sup>(deprecated)</sup> 8304 8305on(type: 'error', callback: ErrorCallback): void 8306 8307监听拍照会话的错误事件,通过注册回调函数获取结果。使用callback异步回调。 8308 8309> **说明:** 8310> 8311> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 8312 8313> **说明:** 8314>从 API version 10开始支持,从API version 11开始废弃。建议使用[VideoSession.on('error')](#onerror11-1)替代。 8315 8316**系统能力:** SystemCapability.Multimedia.Camera.Core 8317 8318**参数:** 8319 8320| 参数名 | 类型 | 必填 | 说明 | 8321| -------- |--------------------------------------------------------------------------| ---- | ------------------------------ | 8322| type | string | 是 | 监听事件,固定为'error',session创建成功之后可监听该接口。session调用相关接口出现错误时会触发该事件,比如调用[beginConfig](#beginconfigdeprecated),[commitConfig](#commitconfigdeprecated-1),[addInput](#addinputdeprecated)等接口发生错误时返回错误信息。 | 8323| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | 是 | 回调函数,用于获取错误信息。返回错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 8324 8325**示例:** 8326 8327```ts 8328import { BusinessError } from '@kit.BasicServicesKit'; 8329 8330function registerCaptureSessionError(captureSession: camera.CaptureSession): void { 8331 captureSession.on('error', (error: BusinessError) => { 8332 console.error(`Capture session error code: ${error.code}`); 8333 }); 8334} 8335``` 8336 8337### off('error')<sup>(deprecated)</sup> 8338 8339off(type: 'error', callback?: ErrorCallback): void 8340 8341注销监听拍照会话的错误事件,通过注册回调函数获取结果。 8342 8343> **说明:** 8344>从 API version 10开始支持,从API version 11开始废弃。建议使用[VideoSession.off('error')](#offerror11-1)替代。 8345 8346**系统能力:** SystemCapability.Multimedia.Camera.Core 8347 8348**参数:** 8349 8350| 参数名 | 类型 | 必填 | 说明 | 8351| -------- | ----------------------------------------------------------- | ---- | ------------------------------ | 8352| type | string | 是 | 监听事件,固定为'error',session创建成功之后可监听该接口。 | 8353| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback)| 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 8354 8355**示例:** 8356 8357```ts 8358function unregisterCaptureSessionError(captureSession: camera.CaptureSession): void { 8359 captureSession.off('error'); 8360} 8361``` 8362## ColorManagementQuery<sup>12+</sup> 8363 8364色彩管理类,用于查询色彩空间参数。 8365 8366### getSupportedColorSpaces<sup>12+</sup> 8367 8368getSupportedColorSpaces(): Array\<colorSpaceManager.ColorSpace\> 8369 8370获取支持的色彩空间列表。 8371 8372**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 8373 8374**系统能力:** SystemCapability.Multimedia.Camera.Core 8375 8376**返回值:** 8377 8378| 类型 | 说明 | 8379| ----------------------------------------------- | ---------------------------- | 8380| Array<[colorSpaceManager.ColorSpace](../apis-arkgraphics2d/js-apis-colorSpaceManager.md#colorspace)>| 支持的色彩空间列表。 | 8381 8382**示例:** 8383 8384```ts 8385import { BusinessError } from '@kit.BasicServicesKit'; 8386import { colorSpaceManager } from '@kit.ArkGraphics2D'; 8387 8388function getSupportedColorSpaces(session: camera.PhotoSession): Array<colorSpaceManager.ColorSpace> { 8389 let colorSpaces: Array<colorSpaceManager.ColorSpace> = []; 8390 colorSpaces = session.getSupportedColorSpaces(); 8391 return colorSpaces; 8392} 8393``` 8394## ColorManagement<sup>12+</sup> 8395 8396ColorManagement extends [ColorManagementQuery](#colormanagementquery12) 8397 8398色彩管理类,继承自[ColorManagementQuery](#colormanagementquery12),用于设置色彩空间参数。 8399 8400### setColorSpace<sup>12+</sup> 8401 8402setColorSpace(colorSpace: colorSpaceManager.ColorSpace): void 8403 8404设置色彩空间。可以先通过[getSupportedColorSpaces](#getsupportedcolorspaces12)获取当前设备所支持的ColorSpaces。 8405 8406**P3广色域与HDR高动态范围成像** 8407 8408应用可以下发不同的色彩空间(ColorSpace)参数来支持P3广色域以及HDR的功能。 8409当应用不主动设置色彩空间时,拍照模式默认为SDR拍摄效果。 8410在拍照模式下设置HDR高显效果可直接支持P3色域。 8411应用针对不同模式使能HDR效果以及设置的色彩空间可参考下表。 8412 8413**录像模式:** 8414 8415| SDR/HRD拍摄 | CameraFormat | ColorSpace | 8416|--------------------|--------------------------|------------------| 8417| SDR | CAMERA_FORMAT_YUV_420_SP | BT709_LIMIT | 8418| HDR_VIVID | CAMERA_FORMAT_YCRCB_P010 | BT2020_HLG_LIMIT | 8419 8420**拍照模式:** 8421 8422| SDR/HRD拍摄 | ColorSpace | 8423|--------------------|------------| 8424| SDR(Default) | SRGB | 8425| HDR | DISPLAY_P3 | 8426 8427**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 8428 8429**系统能力:** SystemCapability.Multimedia.Camera.Core 8430 8431**参数:** 8432 8433| 参数名 | 类型 | 必填 | 说明 | 8434| ------------ |---------------------- | -- | -------------------------- | 8435| colorSpace | [colorSpaceManager.ColorSpace](../apis-arkgraphics2d/js-apis-colorSpaceManager.md#colorspace) | 是 | 色彩空间,通过[getSupportedColorSpaces](#getsupportedcolorspaces12)接口获取。 | 8436 8437**错误码:** 8438 8439以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 8440 8441| 错误码ID | 错误信息 | 8442| --------------- | --------------- | 8443| 7400101 | Parameter missing or parameter type incorrect. | 8444| 7400102 | The colorSpace does not match the format. | 8445| 7400103 | Session not config. | 8446| 7400201 | Camera service fatal error. | 8447 8448**示例:** 8449 8450```ts 8451import { BusinessError } from '@kit.BasicServicesKit'; 8452import { colorSpaceManager } from '@kit.ArkGraphics2D'; 8453 8454function setColorSpace(session: camera.PhotoSession, colorSpaces: Array<colorSpaceManager.ColorSpace>): void { 8455 if (colorSpaces === undefined || colorSpaces.length <= 0) { 8456 return; 8457 } 8458 try { 8459 session.setColorSpace(colorSpaces[0]); 8460 } catch (error) { 8461 let err = error as BusinessError; 8462 console.error(`The setColorSpace call failed, error code: ${err.code}`); 8463 } 8464} 8465``` 8466 8467### getActiveColorSpace<sup>12+</sup> 8468 8469getActiveColorSpace(): colorSpaceManager.ColorSpace 8470 8471获取当前设置的色彩空间。 8472 8473**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 8474 8475**系统能力:** SystemCapability.Multimedia.Camera.Core 8476 8477**返回值:** 8478 8479| 类型 | 说明 | 8480| ----------------------------------------------- | ---------------------------- | 8481| [colorSpaceManager.ColorSpace](../apis-arkgraphics2d/js-apis-colorSpaceManager.md#colorspace) | 当前设置的色彩空间。 | 8482 8483**错误码:** 8484 8485以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 8486 8487| 错误码ID | 错误信息 | 8488| --------------- | --------------- | 8489| 7400103 | Session not config. | 8490 8491**示例:** 8492 8493```ts 8494import { BusinessError } from '@kit.BasicServicesKit'; 8495import { colorSpaceManager } from '@kit.ArkGraphics2D'; 8496 8497function getActiveColorSpace(session: camera.PhotoSession): colorSpaceManager.ColorSpace | undefined { 8498 let colorSpace: colorSpaceManager.ColorSpace | undefined = undefined; 8499 try { 8500 colorSpace = session.getActiveColorSpace(); 8501 } catch (error) { 8502 let err = error as BusinessError; 8503 console.error(`The getActiveColorSpace call failed. error code: ${err.code}`); 8504 } 8505 return colorSpace; 8506} 8507``` 8508 8509## AutoDeviceSwitchQuery<sup>13+</sup> 8510 8511自动切换镜头查询类,用于查询设备是否支持自动切换镜头。 8512 8513### isAutoDeviceSwitchSupported<sup>13+</sup> 8514 8515isAutoDeviceSwitchSupported(): boolean 8516 8517查询设备是否支持自动切换镜头能力。 8518 8519**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 8520 8521**系统能力:** SystemCapability.Multimedia.Camera.Core 8522 8523**返回值:** 8524 8525| 类型 | 说明 | 8526| ----------------------------------------------- |-------------| 8527| boolean | 是否支持自动切换镜头,true为支持,false为不支持。 | 8528 8529**示例:** 8530 8531```ts 8532import { BusinessError } from '@kit.BasicServicesKit'; 8533 8534function isAutoDeviceSwitchSupported(session: camera.PhotoSession): boolean { 8535 let isSupported = false; 8536 isSupported = session.isAutoDeviceSwitchSupported(); 8537 return isSupported; 8538} 8539``` 8540 8541## AutoDeviceSwitch<sup>13+</sup> 8542 8543AutoDeviceSwitch extends [AutoDeviceSwitchQuery](#autodeviceswitchquery13) 8544 8545自动切换镜头类,继承自[AutoDeviceSwitchQuery](#autodeviceswitchquery13),用于使能或去使能自动切换镜头。 8546 8547使用建议:自动切换镜头功能由系统自动完成输入设备切换、会话配置和参数接续, 8548如系统发现镜头切换时,两颗镜头的变焦范围不一致,则会通过[AutoDeviceSwitchStatus](#autodeviceswitchstatus13)中的isDeviceCapabilityChanged字段告知应用, 8549但仍需要应用自己处理UX的变更(如变焦范围的调整,需要重新通过[getZoomRatioRange](#getzoomratiorange11)接口获取数据并更新UX), 8550因此更适用于极简UX交换的场景。 8551 8552### enableAutoDeviceSwitch<sup>13+</sup> 8553 8554enableAutoDeviceSwitch(enabled: boolean): void 8555 8556使能或去使能自动切换镜头。可以先通过[isAutoDeviceSwitchSupported](#isautodeviceswitchsupported13)获取当前设备是否支持自动切换镜头。 8557 8558> **说明:** 8559> 该接口仅用于有多个前置镜头的折叠设备,在不同的折叠状态下可自动切换到当前可使用的前置镜头。无法实现前后置镜头的切换。 8560 8561**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 8562 8563**系统能力:** SystemCapability.Multimedia.Camera.Core 8564 8565**参数:** 8566 8567| 参数名 | 类型 | 必填 | 说明 | 8568| ----------- |---------------------- |---| -------------------------- | 8569| enabled | boolean | 是 | 使能或去使能自动切换镜头。true表示使能,false表示不使能。 | 8570 8571**错误码:** 8572 8573以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 8574 8575| 错误码ID | 错误信息 | 8576|---------|------------------------------------------------------------------------------------------------------------------------------------------------| 8577| 7400101 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameters verification failed. | 8578| 7400102 | Operation not allowed. | 8579| 7400103 | Session not config. | 8580| 7400201 | Camera service fatal error. | 8581 8582**示例:** 8583 8584```ts 8585import { BusinessError } from '@kit.BasicServicesKit'; 8586 8587function enableAutoDeviceSwitch(session: camera.PhotoSession, isEnable: boolean): void { 8588 try { 8589 session.enableAutoDeviceSwitch(isEnable); 8590 } catch (error) { 8591 let err = error as BusinessError; 8592 console.error(`The enableAutoDeviceSwitch call failed, error code: ${err.code}`); 8593 } 8594} 8595``` 8596 8597## PreconfigType<sup>12+</sup> 8598 8599枚举,提供预配置的类型。 8600 8601**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 8602 8603**系统能力:** SystemCapability.Multimedia.Camera.Core 8604 8605| 名称 | 值 | 说明 | 8606|-------------------------|---|------------| 8607| PRECONFIG_720P | 0 | 720P预配置。 | 8608| PRECONFIG_1080P | 1 | 1080P预配置。 | 8609| PRECONFIG_4K | 2 | 4K预配置。 | 8610| PRECONFIG_HIGH_QUALITY | 3 | 高质量预配置。 | 8611 8612## PreconfigRatio<sup>12+</sup> 8613 8614枚举,提供预配置的分辨率比例。 8615 8616**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 8617 8618**系统能力:** SystemCapability.Multimedia.Camera.Core 8619 8620| 名称 | 值 | 说明 | 8621|--------------------------|---|---------| 8622| PRECONFIG_RATIO_1_1 | 0 | 1:1画幅。 | 8623| PRECONFIG_RATIO_4_3 | 1 | 4:3画幅。 | 8624| PRECONFIG_RATIO_16_9 | 2 | 16:9画幅。 | 8625 8626## PhotoSession<sup>11+</sup> 8627 8628PhotoSession extends [Session](#session11), [Flash](#flash11), [AutoExposure](#autoexposure11), [Focus](#focus11), [Zoom](#zoom11), [ColorManagement](#colormanagement12), [AutoDeviceSwitch](#autodeviceswitch13), [Macro](#macro19) 8629 8630普通拍照模式会话类,提供了对闪光灯、曝光、对焦、变焦、色彩空间及微距的操作。 8631 8632> **说明:** 8633> 8634> 默认的拍照模式,用于拍摄标准照片。支持多种照片格式和分辨率,适合大多数日常拍摄场景。 8635 8636### canPreconfig<sup>12+</sup> 8637 8638canPreconfig(preconfigType: PreconfigType, preconfigRatio?: PreconfigRatio): boolean 8639 8640查询当前Session是否支持指定的预配置类型。 8641 8642**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 8643 8644**系统能力:** SystemCapability.Multimedia.Camera.Core 8645 8646**参数:** 8647 8648| 参数名 | 类型 | 必填 | 说明 | 8649|----------------|-------------------------------------|-----|-----------------| 8650| preconfigType | [PreconfigType](#preconfigtype12) | 是 | 指定配置预期分辨率。 | 8651| preconfigRatio | [PreconfigRatio](#preconfigratio12) | 否 | 可选画幅比例,默认为4:3。 | 8652 8653**返回值:** 8654 8655| 类型 | 说明 | 8656|---------|-----------------------------------------| 8657| boolean | true: 支持指定预配值类型。<br/>false: 不支持指定预配值类型。 | 8658 8659**错误码:** 8660 8661以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 8662 8663| 错误码ID | 错误信息 | 8664|---------|-----------------------------| 8665| 7400201 | Camera service fatal error. | 8666 8667**示例:** 8668 8669```ts 8670function testCanPreconfig(photoSession: camera.PhotoSession, preconfigType: camera.PreconfigType, 8671 preconfigRatio: camera.PreconfigRatio): void { 8672 try { 8673 let result = photoSession.canPreconfig(preconfigType, preconfigRatio); 8674 console.info(`canPreconfig ${preconfigType} ${preconfigRatio} result is : ${result}`); 8675 } catch (error) { 8676 let err = error as BusinessError; 8677 console.error(`The canPreconfig call failed. error code: ${err.code}`); 8678 } 8679} 8680``` 8681 8682### preconfig<sup>12+</sup> 8683 8684preconfig(preconfigType: PreconfigType, preconfigRatio?: PreconfigRatio): void 8685 8686对当前Session进行预配置。 8687 8688**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 8689 8690**系统能力:** SystemCapability.Multimedia.Camera.Core 8691 8692**参数:** 8693 8694| 参数名 | 类型 | 必填 | 说明 | 8695|----------------|-------------------------------------|-----|-----------------| 8696| preconfigType | [PreconfigType](#preconfigtype12) | 是 | 指定配置预期分辨率。 | 8697| preconfigRatio | [PreconfigRatio](#preconfigratio12) | 否 | 可选画幅比例,默认为4:3。 | 8698 8699**错误码:** 8700 8701以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 8702 8703| 错误码ID | 错误信息 | 8704|---------|-----------------------------| 8705| 7400201 | Camera service fatal error. | 8706 8707**示例:** 8708 8709```ts 8710function testPreconfig(photoSession: camera.PhotoSession, preconfigType: camera.PreconfigType, 8711 preconfigRatio: camera.PreconfigRatio): void { 8712 try { 8713 photoSession.preconfig(preconfigType, preconfigRatio); 8714 console.info(`preconfig ${preconfigType} ${preconfigRatio} success`); 8715 } catch (error) { 8716 let err = error as BusinessError; 8717 console.error(`The preconfig call failed. error code: ${err.code}`); 8718 } 8719} 8720``` 8721 8722### on('error')<sup>11+</sup> 8723 8724on(type: 'error', callback: ErrorCallback): void 8725 8726监听普通拍照会话的错误事件,通过注册回调函数获取结果。使用callback异步回调。 8727 8728> **说明:** 8729> 8730> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 8731 8732**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 8733 8734**系统能力:** SystemCapability.Multimedia.Camera.Core 8735 8736**参数:** 8737 8738| 参数名 | 类型 | 必填 | 说明 | 8739| -------- | ----------------------------------------------------------- | ---- | ------------------------------ | 8740| type | string | 是 | 监听事件,固定为'error',session创建成功之后可监听该接口。session调用相关接口出现错误时会触发该事件,比如调用[beginConfig](#beginconfig11),[commitConfig](#commitconfig11-1),[addInput](#addinput11)等接口发生错误时返回错误信息。 | 8741| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback)| 是 | 回调函数,用于获取错误信息。返回错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 8742 8743**示例:** 8744 8745```ts 8746import { BusinessError } from '@kit.BasicServicesKit'; 8747 8748function callback(err: BusinessError): void { 8749 console.error(`Photo session error code: ${err.code}`); 8750} 8751 8752function registerSessionError(photoSession: camera.PhotoSession): void { 8753 photoSession.on('error', callback); 8754} 8755``` 8756 8757### off('error')<sup>11+</sup> 8758 8759off(type: 'error', callback?: ErrorCallback): void 8760 8761注销监听普通拍照会话的错误事件,通过注册回调函数获取结果。 8762 8763**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 8764 8765**系统能力:** SystemCapability.Multimedia.Camera.Core 8766 8767**参数:** 8768 8769| 参数名 | 类型 | 必填 | 说明 | 8770| -------- | -------------------------------- | ---- | ------------------------------ | 8771| type | string | 是 | 监听事件,固定为'error',session创建成功之后可监听该接口。 | 8772| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback)| 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 8773 8774**示例:** 8775 8776```ts 8777function unregisterSessionError(photoSession: camera.PhotoSession): void { 8778 photoSession.off('error'); 8779} 8780``` 8781 8782### on('focusStateChange')<sup>11+</sup> 8783 8784on(type: 'focusStateChange', callback: AsyncCallback\<FocusState\>): void 8785 8786监听相机聚焦的状态变化,通过注册回调函数获取结果。使用callback异步回调。 8787 8788> **说明:** 8789> 8790> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 8791 8792**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 8793 8794**系统能力:** SystemCapability.Multimedia.Camera.Core 8795 8796**参数:** 8797 8798| 参数名 | 类型 | 必填 | 说明 | 8799| -------- | ---------------- | ---- | ------------------------ | 8800| type | string | 是 | 监听事件,固定为'focusStateChange',session创建成功可监听。仅当自动对焦模式时,且相机对焦状态发生改变时可触发该事件。 | 8801| callback | AsyncCallback\<[FocusState](#focusstate)\> | 是 | 回调函数,用于获取当前对焦状态。 | 8802 8803**示例:** 8804 8805```ts 8806import { BusinessError } from '@kit.BasicServicesKit'; 8807 8808function callback(err: BusinessError, focusState: camera.FocusState): void { 8809 if (err !== undefined && err.code !== 0) { 8810 console.error(`Callback Error, errorCode: ${err.code}`); 8811 return; 8812 } 8813 console.info(`Focus state: ${focusState}`); 8814} 8815 8816function registerFocusStateChange(photoSession: camera.PhotoSession): void { 8817 photoSession.on('focusStateChange', callback); 8818} 8819``` 8820 8821### off('focusStateChange')<sup>11+</sup> 8822 8823off(type: 'focusStateChange', callback?: AsyncCallback\<FocusState\>): void 8824 8825注销监听相机聚焦的状态变化。 8826 8827**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 8828 8829**系统能力:** SystemCapability.Multimedia.Camera.Core 8830 8831**参数:** 8832 8833| 参数名 | 类型 | 必填 | 说明 | 8834| -------- | ----------------------------------------- | ---- | ------------------------ | 8835| type | string | 是 | 监听事件,固定为'focusStateChange',session创建成功可监听。 | 8836| callback | AsyncCallback\<[FocusState](#focusstate)\> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 8837 8838**示例:** 8839 8840```ts 8841function unregisterFocusStateChange(photoSession: camera.PhotoSession): void { 8842 photoSession.off('focusStateChange'); 8843} 8844``` 8845 8846### on('smoothZoomInfoAvailable')<sup>11+</sup> 8847 8848on(type: 'smoothZoomInfoAvailable', callback: AsyncCallback\<SmoothZoomInfo\>): void 8849 8850监听相机平滑变焦的状态变化,通过注册回调函数获取结果。使用callback异步回调。 8851 8852> **说明:** 8853> 8854> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 8855 8856**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 8857 8858**系统能力:** SystemCapability.Multimedia.Camera.Core 8859 8860**参数:** 8861 8862| 参数名 | 类型 | 必填 | 说明 | 8863| -------- | ----------------------- | ---- | ------------------------ | 8864| type | string | 是 | 监听事件,固定为'smoothZoomInfoAvailable',session创建成功可监听。| 8865| callback | AsyncCallback\<[SmoothZoomInfo](#smoothzoominfo11)\> | 是 | 回调函数,用于获取当前平滑变焦状态。 | 8866 8867**示例:** 8868 8869```ts 8870import { BusinessError } from '@kit.BasicServicesKit'; 8871 8872function callback(err: BusinessError, smoothZoomInfo: camera.SmoothZoomInfo): void { 8873 if (err !== undefined && err.code !== 0) { 8874 console.error(`Callback Error, errorCode: ${err.code}`); 8875 return; 8876 } 8877 console.info(`The duration of smooth zoom: ${smoothZoomInfo.duration}`); 8878} 8879 8880function registerSmoothZoomInfo(photoSession: camera.PhotoSession): void { 8881 photoSession.on('smoothZoomInfoAvailable', callback); 8882} 8883``` 8884 8885### off('smoothZoomInfoAvailable')<sup>11+</sup> 8886 8887off(type: 'smoothZoomInfoAvailable', callback?: AsyncCallback\<SmoothZoomInfo\>): void 8888 8889注销监听相机平滑变焦的状态变化。 8890 8891**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 8892 8893**系统能力:** SystemCapability.Multimedia.Camera.Core 8894 8895**参数:** 8896 8897| 参数名 | 类型 | 必填 | 说明 | 8898| -------- | ----------------------------------------- | ---- | ------------------------ | 8899| type | string | 是 | 监听事件,固定为'smoothZoomInfoAvailable',session创建成功可监听。| 8900| callback | AsyncCallback\<[SmoothZoomInfo](#smoothzoominfo11)\> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 8901 8902**示例:** 8903 8904```ts 8905function unregisterSmoothZoomInfo(photoSession: camera.PhotoSession): void { 8906 photoSession.off('smoothZoomInfoAvailable'); 8907} 8908``` 8909 8910### on('autoDeviceSwitchStatusChange')<sup>13+</sup> 8911 8912on(type: 'autoDeviceSwitchStatusChange', callback: AsyncCallback\<AutoDeviceSwitchStatus\>): void 8913 8914监听相机自动切换镜头状态变化,通过注册回调函数获取结果。使用callback异步回调。 8915 8916> **说明:** 8917> 8918> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 8919 8920**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 8921 8922**系统能力:** SystemCapability.Multimedia.Camera.Core 8923 8924**参数:** 8925 8926| 参数名 | 类型 | 必填 | 说明 | 8927| -------- |----------------------------------------------------------------------| ---- |--------------------------------------------------------| 8928| type | string | 是 | 监听事件,固定为'autoDeviceSwitchStatusChange',session创建成功可监听。 | 8929| callback | AsyncCallback\<[AutoDeviceSwitchStatus](#autodeviceswitchstatus13)\> | 是 | 回调函数,用于获取当前自动切换镜头的状态。 | 8930 8931**示例:** 8932 8933```ts 8934import { BusinessError } from '@kit.BasicServicesKit'; 8935 8936function callback(err: BusinessError, autoDeviceSwitchStatus: camera.AutoDeviceSwitchStatus): void { 8937 if (err !== undefined && err.code !== 0) { 8938 console.error(`Callback Error, errorCode: ${err.code}`); 8939 return; 8940 } 8941 console.info(`isDeviceSwitched: ${autoDeviceSwitchStatus.isDeviceSwitched}, isDeviceCapabilityChanged: ${autoDeviceSwitchStatus.isDeviceCapabilityChanged}`); 8942} 8943 8944function registerAutoDeviceSwitchStatus(photoSession: camera.PhotoSession): void { 8945 photoSession.on('autoDeviceSwitchStatusChange', callback); 8946} 8947``` 8948 8949### off('autoDeviceSwitchStatusChange')<sup>13+</sup> 8950 8951off(type: 'autoDeviceSwitchStatusChange', callback?: AsyncCallback\<AutoDeviceSwitchStatus\>): void 8952 8953注销监听相机自动切换镜头状态变化。 8954 8955**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 8956 8957**系统能力:** SystemCapability.Multimedia.Camera.Core 8958 8959**参数:** 8960 8961| 参数名 | 类型 | 必填 | 说明 | 8962| -------- |----------------------------------------------| ---- | ------------------------ | 8963| type | string | 是 | 监听事件,固定为'autoDeviceSwitchStatusChange',session创建成功可监听。| 8964| callback | AsyncCallback\<[AutoDeviceSwitchStatus](#autodeviceswitchstatus13)\> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 8965 8966**示例:** 8967 8968```ts 8969function unregisterSmoothZoomInfo(photoSession: camera.PhotoSession): void { 8970 photoSession.off('autoDeviceSwitchStatusChange'); 8971} 8972``` 8973 8974## QualityPrioritization<sup>14+</sup> 8975 8976枚举,录像质量优先级。 8977 8978**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 8979 8980**系统能力:** SystemCapability.Multimedia.Camera.Core 8981 8982| 名称 | 值 | 说明 | 8983| ------------- | --- | ---------- | 8984| HIGH_QUALITY | 0 | 高录像质量。 | 8985| POWER_BALANCE | 1 | 功耗平衡的录像质量。 | 8986 8987## VideoSession<sup>11+</sup> 8988 8989VideoSession extends [Session](#session11), [Flash](#flash11), [AutoExposure](#autoexposure11), [Focus](#focus11), [Zoom](#zoom11), [Stabilization](#stabilization11), [ColorManagement](#colormanagement12), [AutoDeviceSwitch](#autodeviceswitch13), [Macro](#macro19) 8990 8991普通录像模式会话类,提供了对闪光灯、曝光、对焦、变焦、视频防抖、色彩空间及微距的操作。 8992 8993> **说明:** 8994> 8995> 默认的视频录制模式,适用于一般场景。支持720P、1080p等多种分辨率的录制,可选择不同帧率(如30fps、60fps)。 8996 8997### canPreconfig<sup>12+</sup> 8998 8999canPreconfig(preconfigType: PreconfigType, preconfigRatio?: PreconfigRatio): boolean 9000 9001查询当前Session是否支持指定的与配置类型。 9002 9003**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 9004 9005**系统能力:** SystemCapability.Multimedia.Camera.Core 9006 9007**参数:** 9008 9009| 参数名 | 类型 | 必填 | 说明 | 9010|----------------|-------------------------------------|-----|-----------------| 9011| preconfigType | [PreconfigType](#preconfigtype12) | 是 | 指定配置预期分辨率。 | 9012| preconfigRatio | [PreconfigRatio](#preconfigratio12) | 否 | 可选画幅比例,默认为16:9。 | 9013 9014**返回值:** 9015 9016| 类型 | 说明 | 9017|---------|-----------------------------------------| 9018| boolean | true: 支持指定预配值类型。<br/>false: 不支持指定预配值类型。 | 9019 9020**错误码:** 9021 9022以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 9023 9024| 错误码ID | 错误信息 | 9025|---------|-----------------------------| 9026| 7400201 | Camera service fatal error. | 9027 9028**示例:** 9029 9030```ts 9031function testCanPreconfig(videoSession: camera.VideoSession, preconfigType: camera.PreconfigType, 9032 preconfigRatio: camera.PreconfigRatio): void { 9033 try { 9034 let result = videoSession.canPreconfig(preconfigType, preconfigRatio); 9035 console.info(`canPreconfig ${preconfigType} ${preconfigRatio} result is : ${result}`); 9036 } catch (error) { 9037 let err = error as BusinessError; 9038 console.error(`The canPreconfig call failed. error code: ${err.code}`); 9039 } 9040} 9041``` 9042 9043### preconfig<sup>12+</sup> 9044 9045preconfig(preconfigType: PreconfigType, preconfigRatio?: PreconfigRatio): void 9046 9047对当前Session进行预配置。 9048 9049**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 9050 9051**系统能力:** SystemCapability.Multimedia.Camera.Core 9052 9053**参数:** 9054 9055| 参数名 | 类型 | 必填 | 说明 | 9056|----------------|-------------------------------------|-----|-----------------| 9057| preconfigType | [PreconfigType](#preconfigtype12) | 是 | 指定配置预期分辨率。 | 9058| preconfigRatio | [PreconfigRatio](#preconfigratio12) | 否 | 可选画幅比例,默认为16:9。 | 9059 9060**错误码:** 9061 9062以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 9063 9064| 错误码ID | 错误信息 | 9065|---------|-----------------------------| 9066| 7400201 | Camera service fatal error. | 9067 9068**示例:** 9069 9070```ts 9071function testPreconfig(videoSession: camera.VideoSession, preconfigType: camera.PreconfigType, 9072 preconfigRatio: camera.PreconfigRatio): void { 9073 try { 9074 videoSession.preconfig(preconfigType, preconfigRatio); 9075 console.info(`preconfig ${preconfigType} ${preconfigRatio} success`); 9076 } catch (error) { 9077 let err = error as BusinessError; 9078 console.error(`The preconfig call failed. error code: ${err.code}`); 9079 } 9080} 9081``` 9082 9083### on('error')<sup>11+</sup> 9084 9085on(type: 'error', callback: ErrorCallback): void 9086 9087监听普通录像会话的错误事件,通过注册回调函数获取结果。使用callback异步回调。 9088 9089> **说明:** 9090> 9091> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 9092 9093**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 9094 9095**系统能力:** SystemCapability.Multimedia.Camera.Core 9096 9097**参数:** 9098 9099| 参数名 | 类型 | 必填 | 说明 | 9100| -------- | ------------------ | ---- | ------------------------------ | 9101| type | string | 是 | 监听事件,固定为'error',session创建成功之后可监听该接口。session调用相关接口出现错误时会触发该事件,比如调用[beginConfig](#beginconfig11),[commitConfig](#commitconfig11-1),[addInput](#addinput11)等接口发生错误时返回错误信息。 | 9102| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | 是 | 回调函数,用于获取错误信息。返回错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 9103 9104**示例:** 9105 9106```ts 9107import { BusinessError } from '@kit.BasicServicesKit'; 9108 9109function callback(err: BusinessError): void { 9110 console.error(`Video session error code: ${err.code}`); 9111} 9112 9113function registerSessionError(videoSession: camera.VideoSession): void { 9114 videoSession.on('error', callback); 9115} 9116``` 9117 9118### off('error')<sup>11+</sup> 9119 9120off(type: 'error', callback?: ErrorCallback): void 9121 9122注销监听普通录像会话的错误事件,通过注册回调函数获取结果。 9123 9124**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 9125 9126**系统能力:** SystemCapability.Multimedia.Camera.Core 9127 9128**参数:** 9129 9130| 参数名 | 类型 | 必填 | 说明 | 9131| -------- | --------------------------- | ---- | ------------------------------ | 9132| type | string | 是 | 监听事件,固定为'error',session创建成功之后可监听该接口。 | 9133| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback)| 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 9134 9135**示例:** 9136 9137```ts 9138function unregisterSessionError(videoSession: camera.VideoSession): void { 9139 videoSession.off('error'); 9140} 9141``` 9142 9143### on('focusStateChange')<sup>11+</sup> 9144 9145on(type: 'focusStateChange', callback: AsyncCallback\<FocusState\>): void 9146 9147监听相机聚焦的状态变化,通过注册回调函数获取结果。使用callback异步回调。 9148 9149> **说明:** 9150> 9151> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 9152 9153**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 9154 9155**系统能力:** SystemCapability.Multimedia.Camera.Core 9156 9157**参数:** 9158 9159| 参数名 | 类型 | 必填 | 说明 | 9160| -------- | ---------------- | ---- | ------------------------ | 9161| type | string | 是 | 监听事件,固定为'focusStateChange',session创建成功可监听。仅当自动对焦模式时,且相机对焦状态发生改变时可触发该事件。 | 9162| callback | AsyncCallback\<[FocusState](#focusstate)\> | 是 | 回调函数,用于获取当前对焦状态。 | 9163 9164**示例:** 9165 9166```ts 9167import { BusinessError } from '@kit.BasicServicesKit'; 9168 9169function callback(err: BusinessError, focusState: camera.FocusState): void { 9170 if (err !== undefined && err.code !== 0) { 9171 console.error(`Callback Error, errorCode: ${err.code}`); 9172 return; 9173 } 9174 console.info(`Focus state: ${focusState}`); 9175} 9176 9177function registerFocusStateChange(videoSession: camera.VideoSession): void { 9178 videoSession.on('focusStateChange', callback); 9179} 9180``` 9181 9182### off('focusStateChange')<sup>11+</sup> 9183 9184off(type: 'focusStateChange', callback?: AsyncCallback\<FocusState\>): void 9185 9186注销监听相机聚焦的状态变化。 9187 9188**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 9189 9190**系统能力:** SystemCapability.Multimedia.Camera.Core 9191 9192**参数:** 9193 9194| 参数名 | 类型 | 必填 | 说明 | 9195| -------- | ----------------------------------------- | ---- | ------------------------ | 9196| type | string | 是 | 监听事件,固定为'focusStateChange',session创建成功可监听。 | 9197| callback | AsyncCallback\<[FocusState](#focusstate)\> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 9198 9199**示例:** 9200 9201```ts 9202function unregisterFocusStateChange(videoSession: camera.VideoSession): void { 9203 videoSession.off('focusStateChange'); 9204} 9205``` 9206 9207### on('smoothZoomInfoAvailable')<sup>11+</sup> 9208 9209on(type: 'smoothZoomInfoAvailable', callback: AsyncCallback\<SmoothZoomInfo\>): void 9210 9211监听相机平滑变焦的状态变化,通过注册回调函数获取结果。使用callback异步回调。 9212 9213> **说明:** 9214> 9215> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 9216 9217**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 9218 9219**系统能力:** SystemCapability.Multimedia.Camera.Core 9220 9221**参数:** 9222 9223| 参数名 | 类型 | 必填 | 说明 | 9224| -------- | ----------------------- | ---- | ------------------------ | 9225| type | string | 是 | 监听事件,固定为'smoothZoomInfoAvailable',session创建成功可监听。| 9226| callback | AsyncCallback\<[SmoothZoomInfo](#smoothzoominfo11)\> | 是 | 回调函数,用于获取当前平滑变焦状态。 | 9227 9228**示例:** 9229 9230```ts 9231import { BusinessError } from '@kit.BasicServicesKit'; 9232 9233function callback(err: BusinessError, smoothZoomInfo: camera.SmoothZoomInfo): void { 9234 if (err !== undefined && err.code !== 0) { 9235 console.error(`Callback Error, errorCode: ${err.code}`); 9236 return; 9237 } 9238 console.info(`The duration of smooth zoom: ${smoothZoomInfo.duration}`); 9239} 9240 9241function registerSmoothZoomInfo(videoSession: camera.VideoSession): void { 9242 videoSession.on('smoothZoomInfoAvailable', callback); 9243} 9244``` 9245 9246### off('smoothZoomInfoAvailable')<sup>11+</sup> 9247 9248off(type: 'smoothZoomInfoAvailable', callback?: AsyncCallback\<SmoothZoomInfo\>): void 9249 9250注销监听相机平滑变焦的状态变化。 9251 9252**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 9253 9254**系统能力:** SystemCapability.Multimedia.Camera.Core 9255 9256**参数:** 9257 9258| 参数名 | 类型 | 必填 | 说明 | 9259| -------- | ----------------------------------------- | ---- | ------------------------ | 9260| type | string | 是 | 监听事件,固定为'smoothZoomInfoAvailable',session创建成功可监听。| 9261| callback | AsyncCallback\<[SmoothZoomInfo](#smoothzoominfo11)\> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 9262 9263**示例:** 9264 9265```ts 9266function unregisterSmoothZoomInfo(videoSession: camera.VideoSession): void { 9267 videoSession.off('smoothZoomInfoAvailable'); 9268} 9269``` 9270 9271### on('autoDeviceSwitchStatusChange')<sup>13+</sup> 9272 9273on(type: 'autoDeviceSwitchStatusChange', callback: AsyncCallback\<AutoDeviceSwitchStatus\>): void 9274 9275监听相机自动切换镜头状态变化,通过注册回调函数获取结果。使用callback异步回调。 9276 9277> **说明:** 9278> 9279> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 9280 9281**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 9282 9283**系统能力:** SystemCapability.Multimedia.Camera.Core 9284 9285**参数:** 9286 9287| 参数名 | 类型 | 必填 | 说明 | 9288| -------- |----------------------------------------------------------------------| ---- | ------------------------ | 9289| type | string | 是 | 监听事件,固定为'autoDeviceSwitchStatusChange',session创建成功可监听。| 9290| callback | AsyncCallback\<[AutoDeviceSwitchStatus](#autodeviceswitchstatus13)\> | 是 | 回调函数,用于获取当前自动切换镜头的状态。 | 9291 9292**示例:** 9293 9294```ts 9295import { BusinessError } from '@kit.BasicServicesKit'; 9296 9297function callback(err: BusinessError, autoDeviceSwitchStatus: camera.AutoDeviceSwitchStatus): void { 9298 if (err !== undefined && err.code !== 0) { 9299 console.error(`Callback Error, errorCode: ${err.code}`); 9300 return; 9301 } 9302 console.info(`isDeviceSwitched: ${autoDeviceSwitchStatus.isDeviceSwitched}, isDeviceCapabilityChanged: ${autoDeviceSwitchStatus.isDeviceCapabilityChanged}`); 9303} 9304 9305function registerAutoDeviceSwitchStatus(videoSession: camera.VideoSession): void { 9306 videoSession.on('autoDeviceSwitchStatusChange', callback); 9307} 9308``` 9309 9310### off('autoDeviceSwitchStatusChange')<sup>13+</sup> 9311 9312off(type: 'autoDeviceSwitchStatusChange', callback?: AsyncCallback\<AutoDeviceSwitchStatus\>): void 9313 9314注销监听相机自动切换镜头状态变化。 9315 9316**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 9317 9318**系统能力:** SystemCapability.Multimedia.Camera.Core 9319 9320**参数:** 9321 9322| 参数名 | 类型 | 必填 | 说明 | 9323| -------- |----------------------------------------------| ---- | ------------------------ | 9324| type | string | 是 | 监听事件,固定为'autoDeviceSwitchStatusChange',session创建成功可监听。| 9325| callback | AsyncCallback\<[AutoDeviceSwitchStatus](#autodeviceswitchstatus13)\> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 9326 9327**示例:** 9328 9329```ts 9330function unregisterSmoothZoomInfo(videoSession: camera.VideoSession): void { 9331 videoSession.off('autoDeviceSwitchStatusChange'); 9332} 9333``` 9334 9335### setQualityPrioritization<sup>14+</sup> 9336 9337setQualityPrioritization(quality : QualityPrioritization) : void; 9338 9339设置录像质量优先级。 9340 9341> **说明:** 9342> 默认为高质量,设置为功耗平衡将降低录像质量以减少功耗。实际功耗收益因平台而异。 9343 9344**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 9345 9346**系统能力:** SystemCapability.Multimedia.Camera.Core 9347 9348**参数:** 9349 9350| 参数名 | 类型 | 必填 | 说明 | 9351| ------- | ------------------------------------------------- | ---- | ------------------------------------------ | 9352| quality | [QualityPrioritization](#qualityprioritization14) | 是 | 需要设置的视频质量优先级(默认为高质量)。 | 9353 9354**错误码:** 9355 9356以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 9357 9358| 错误码ID | 错误信息 | 9359| -------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | 9360| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 9361| 7400103 | Session not config. The session has not been committed or configured. | 9362 9363**示例:** 9364 9365```ts 9366import { BusinessError } from '@kit.BasicServicesKit'; 9367 9368function setQualityPrioritization(videoSession: camera.VideoSession): void { 9369 try { 9370 videoSession.setQualityPrioritization(camera.QualityPrioritization.POWER_BALANCE); 9371 } catch (error) { 9372 // 失败返回错误码error.code并处理。 9373 let err = error as BusinessError; 9374 console.error(`The setQualityPrioritization call failed. error code: ${err.code}`); 9375 } 9376} 9377``` 9378 9379## SecureSession<sup>12+</sup> 9380 9381SecureSession extends [Session](#session11), [Flash](#flash11), [AutoExposure](#autoexposure11), [Focus](#focus11), [Zoom](#zoom11) 9382 9383安全模式会话类,提供了对闪光灯、曝光、对焦、变焦的操作。 9384 9385> **说明:** 9386> 9387> 通过[createSession](#createsession11)接口传入[SceneMode](#scenemode11)为SECURE_PHOTO模式创建一个安全模式的会话。该模式开放给人脸识别、银行等有安全诉求的应用,需要结合<!--RP1-->安全TA<!--RP1End-->使用,支持同时出普通预览流和安全流的业务场景。<!--RP2--> 9388> <br>安全TA:可用于图片处理,它具备验证服务器下发数据的验签能力、图片签名、解析及组装tlv逻辑的能力,还具备密钥读取、创建及操作能力。<!--RP2End--> 9389 9390### addSecureOutput<sup>12+</sup> 9391 9392addSecureOutput(previewOutput: PreviewOutput): void 9393 9394将其中一条[PreviewOutput](#previewoutput)标记成安全输出。 9395 9396**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 9397 9398**系统能力:** SystemCapability.Multimedia.Camera.Core 9399 9400**参数:** 9401 9402| 参数名 | 类型 | 必填 | 说明 | 9403| ------------- | ------------------------------- | ---- |---------------| 9404| previewOutput | [PreviewOutput](#previewoutput) | 是 | 需要标记成安全输出的预览流,传参异常时,会返回错误码。 | 9405 9406**错误码:** 9407 9408以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 9409 9410| 错误码ID | 错误信息 | 9411| --------------- | --------------- | 9412| 7400101 | Parameter missing or parameter type incorrect. | 9413| 7400102 | Operation not allowed. | 9414 9415**示例:** 9416 9417```ts 9418import { BusinessError } from '@kit.BasicServicesKit'; 9419 9420function addSecureOutput(session: camera.SecureSession, previewOutput: camera.PreviewOutput): void { 9421 try { 9422 session.addSecureOutput(previewOutput); 9423 } catch (error) { 9424 // 失败返回错误码error.code并处理。 9425 let err = error as BusinessError; 9426 console.error(`The addOutput call failed. error code: ${err.code}`); 9427 } 9428} 9429``` 9430### on('error')<sup>12+</sup> 9431 9432on(type: 'error', callback: ErrorCallback): void 9433 9434监听安全相机会话的错误事件,通过注册回调函数获取结果。使用callback异步回调。 9435 9436> **说明:** 9437> 9438> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 9439 9440**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 9441 9442**系统能力:** SystemCapability.Multimedia.Camera.Core 9443 9444**参数:** 9445 9446| 参数名 | 类型 | 必填 | 说明 | 9447| -------- | ------------------ | ---- | ------------------------------ | 9448| type | string | 是 | 监听事件,固定为'error',session创建成功之后可监听该接口。session调用相关接口出现错误时会触发该事件,比如调用[beginConfig](#beginconfig11),[commitConfig](#commitconfig11-1),[addInput](#addinput11)等接口发生错误时返回错误信息。 | 9449| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | 是 | 回调函数,用于获取错误信息。返回错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 | 9450 9451**示例:** 9452 9453```ts 9454import { BusinessError } from '@kit.BasicServicesKit'; 9455 9456function callback(err: BusinessError): void { 9457 console.error(`Video session error code: ${err.code}`); 9458} 9459 9460function registerSessionError(secureSession: camera.SecureSession): void { 9461 secureSession.on('error', callback); 9462} 9463``` 9464 9465### off('error')<sup>12+</sup> 9466 9467off(type: 'error', callback?: ErrorCallback): void 9468 9469注销监听安全相机会话的错误事件,通过注册回调函数获取结果。 9470 9471**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 9472 9473**系统能力:** SystemCapability.Multimedia.Camera.Core 9474 9475**参数:** 9476 9477| 参数名 | 类型 | 必填 | 说明 | 9478| -------- | --------------------------- | ---- | ------------------------------ | 9479| type | string | 是 | 监听事件,固定为'error',session创建成功之后可监听该接口。 | 9480| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback)| 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 9481 9482**示例:** 9483 9484```ts 9485function unregisterSessionError(secureSession: camera.SecureSession): void { 9486 secureSession.off('error'); 9487} 9488``` 9489 9490### on('focusStateChange')<sup>12+</sup> 9491 9492on(type: 'focusStateChange', callback: AsyncCallback\<FocusState\>): void 9493 9494监听相机聚焦的状态变化,通过注册回调函数获取结果。使用callback异步回调。 9495 9496> **说明:** 9497> 9498> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。 9499 9500**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 9501 9502**系统能力:** SystemCapability.Multimedia.Camera.Core 9503 9504**参数:** 9505 9506| 参数名 | 类型 | 必填 | 说明 | 9507| -------- | ---------------- | ---- | ------------------------ | 9508| type | string | 是 | 监听事件,固定为'focusStateChange',session创建成功可监听。仅当自动对焦模式时,且相机对焦状态发生改变时可触发该事件。 | 9509| callback | AsyncCallback\<[FocusState](#focusstate)\> | 是 | 回调函数,用于获取当前对焦状态。 | 9510 9511**示例:** 9512 9513```ts 9514import { BusinessError } from '@kit.BasicServicesKit'; 9515 9516function callback(err: BusinessError, focusState: camera.FocusState): void { 9517 if (err !== undefined && err.code !== 0) { 9518 console.error(`Callback Error, errorCode: ${err.code}`); 9519 return; 9520 } 9521 console.info(`Focus state: ${focusState}`); 9522} 9523 9524function registerFocusStateChange(secureSession: camera.SecureSession): void { 9525 secureSession.on('focusStateChange', callback); 9526} 9527``` 9528 9529### off('focusStateChange')<sup>12+</sup> 9530 9531off(type: 'focusStateChange', callback?: AsyncCallback\<FocusState\>): void 9532 9533注销监听相机聚焦的状态变化。 9534 9535**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 9536 9537**系统能力:** SystemCapability.Multimedia.Camera.Core 9538 9539**参数:** 9540 9541| 参数名 | 类型 | 必填 | 说明 | 9542| -------- | ----------------------------------------- | ---- | ------------------------ | 9543| type | string | 是 | 监听事件,固定为'focusStateChange',session创建成功可监听。 | 9544| callback | AsyncCallback\<[FocusState](#focusstate)\> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 | 9545 9546**示例:** 9547 9548```ts 9549function unregisterFocusStateChange(secureSession: camera.SecureSession): void { 9550 secureSession.off('focusStateChange'); 9551} 9552``` 9553 9554## WhiteBalanceMode<sup>20+</sup> 9555 9556枚举,白平衡模式。 9557 9558**原子化服务API:** 从API version 20开始,该接口支持在原子化服务中使用。 9559 9560**系统能力:** SystemCapability.Multimedia.Camera.Core 9561 9562| 名称 | 值 | 说明 | 9563|----------------|---| ----------- | 9564| AUTO | 0 | 自动 | 9565| CLOUDY | 1 | 阴天 | 9566| INCANDESCENT | 2 | 白炽光 | 9567| FLUORESCENT | 3 | 荧光 | 9568| DAYLIGHT | 4 | 日光 | 9569| MANUAL | 5 | 手动 | 9570 9571## WhiteBalanceQuery<sup>20+</sup> 9572 9573提供了查询设备对指定的白平衡模式是否支持,以及获取设备支持的白平衡模式范围的方法。 9574 9575**原子化服务API:** 从API version 20开始,该接口支持在原子化服务中使用。 9576 9577**系统能力:** SystemCapability.Multimedia.Camera.Core 9578 9579### isWhiteBalanceModeSupported<sup>20+</sup> 9580 9581isWhiteBalanceModeSupported(mode: WhiteBalanceMode): boolean 9582 9583检测是否支持当前传入的白平衡模式。 9584 9585**原子化服务API:** 从API version 20开始,该接口支持在原子化服务中使用。 9586 9587**系统能力:** SystemCapability.Multimedia.Camera.Core 9588 9589**参数:** 9590 9591| 参数名 | 类型 | 必填 | 说明 | 9592| -------- |-----------------------------------------| ---- | ----------------------------- | 9593| mode | [WhiteBalanceMode](#whitebalancemode20) | 是 | 白平衡模式。 | 9594 9595**返回值:** 9596 9597| 类型 | 说明 | 9598| ---------- | ----------------------------- | 9599| boolean | 表示是否支持白平衡模式。true表示支持,false表示不支持。 | 9600 9601**错误码:** 9602 9603以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 9604 9605| 错误码ID | 错误信息 | 9606| --------------- | --------------- | 9607| 7400101 | Parameter missing or parameter type incorrect. | 9608| 7400103 | Session not config, only throw in session usage. | 9609 9610**示例:** 9611 9612```ts 9613import { BusinessError } from '@kit.BasicServicesKit'; 9614 9615function isWhiteBalanceModeSupported(session: camera.PhotoSession | camera.VideoSession): boolean { 9616 let status: boolean = false; 9617 try { 9618 let mode: WhiteBalanceMode = camera.WhiteBalanceMode.DAYLIGHT; 9619 status = session.isWhiteBalanceModeSupported(mode); 9620 } catch (error) { 9621 let err = error as BusinessError; 9622 console.error(`The isWhiteBalanceModeSupported call failed. error code: ${err.code}`); 9623 } 9624 return status; 9625} 9626``` 9627 9628### getWhiteBalanceRange<sup>20+</sup> 9629 9630getWhiteBalanceRange(): Array\<number\> 9631 9632获取手动白平衡模式下,白平衡值的范围。 9633 9634**原子化服务API:** 从API version 20开始,该接口支持在原子化服务中使用。 9635 9636**系统能力:** SystemCapability.Multimedia.Camera.Core 9637 9638**返回值:** 9639 9640| 类型 | 说明 | 9641| ---------- | ----------------------------- | 9642| Array\<number\> | 用于获取手动白平衡值的可调范围,如[2800,10000],单位为K(Kelvin,温度单位),实际情况根据底层能力返回为准。 | 9643 9644**错误码:** 9645 9646以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 9647 9648| 错误码ID | 错误信息 | 9649| --------------- | --------------- | 9650| 7400103 | Session not config, only throw in session usage. | 9651 9652**示例:** 9653 9654```ts 9655import { BusinessError } from '@kit.BasicServicesKit'; 9656 9657function getWhiteBalanceRange(session: camera.PhotoSession | camera.VideoSession): Array<number> { 9658 let range: Array<number> = []; 9659 try { 9660 range = session.getWhiteBalanceRange(); 9661 } catch (error) { 9662 let err = error as BusinessError; 9663 console.error(`The getWhiteBalanceRange call failed. error code: ${err.code}`); 9664 } 9665 return range; 9666} 9667``` 9668 9669## WhiteBalance<sup>20+</sup> 9670 9671WhiteBalance extends [WhiteBalanceQuery](#whitebalancequery20) 9672 9673提供了处理设备白平衡的相关功能,包括获取和设置白平衡模式以及白平衡值。 9674 9675**原子化服务API:** 从API version 20开始,该接口支持在原子化服务中使用。 9676 9677**系统能力:** SystemCapability.Multimedia.Camera.Core 9678 9679### setWhiteBalanceMode<sup>20+</sup> 9680 9681setWhiteBalanceMode(mode: WhiteBalanceMode): void 9682 9683设置白平衡模式。设置之前需要先检查设备是否支持指定的白平衡模式,具体方法请参考[isWhiteBalanceModeSupported](#iswhitebalancemodesupported20)。 9684 9685**原子化服务API:** 从API version 20开始,该接口支持在原子化服务中使用。 9686 9687**系统能力:** SystemCapability.Multimedia.Camera.Core 9688 9689**参数:** 9690 9691| 参数名 | 类型 | 必填 | 说明 | 9692| -------- |-----------------------------------------| ---- | ----------------------- | 9693| mode | [WhiteBalanceMode](#whitebalancemode20) | 是 | 白平衡模式。 | 9694 9695**错误码:** 9696 9697以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 9698 9699| 错误码ID | 错误信息 | 9700| --------------- | --------------- | 9701| 7400101 | Parameter missing or parameter type incorrect. | 9702| 7400103 | Session not config. | 9703 9704**示例:** 9705 9706```ts 9707import { BusinessError } from '@kit.BasicServicesKit'; 9708 9709function setWhiteBalanceMode(session: camera.PhotoSession | camera.VideoSession): void { 9710 try { 9711 session.setWhiteBalanceMode(camera.WhiteBalanceMode.DAYLIGHT); 9712 } catch (error) { 9713 let err = error as BusinessError; 9714 console.error(`The setWhiteBalanceMode call failed. error code: ${err.code}`); 9715 } 9716} 9717``` 9718 9719### getWhiteBalanceMode<sup>20+</sup> 9720 9721getWhiteBalanceMode(): WhiteBalanceMode 9722 9723获取当前白平衡模式。 9724 9725**原子化服务API:** 从API version 20开始,该接口支持在原子化服务中使用。 9726 9727**系统能力:** SystemCapability.Multimedia.Camera.Core 9728 9729**返回值:** 9730 9731| 类型 | 说明 | 9732|-----------------------------------------| ----------------------------- | 9733| [WhiteBalanceMode](#whitebalancemode20) | 获取当前白平衡模式。 | 9734 9735**错误码:** 9736 9737以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 9738 9739| 错误码ID | 错误信息 | 9740| --------------- | --------------- | 9741| 7400103 | Session not config. | 9742 9743**示例:** 9744 9745```ts 9746import { BusinessError } from '@kit.BasicServicesKit'; 9747 9748function getWhiteBalanceMode(session: camera.PhotoSession | camera.VideoSession): camera.WhiteBalanceMode | undefined { 9749 let whiteBalanceMode: camera.WhiteBalanceMode | undefined = undefined; 9750 try { 9751 whiteBalanceMode = session.getWhiteBalanceMode(); 9752 } catch (error) { 9753 let err = error as BusinessError; 9754 console.error(`The getWhiteBalanceMode call failed. error code: ${err.code}`); 9755 } 9756 return whiteBalanceMode; 9757} 9758``` 9759 9760### setWhiteBalance<sup>20+</sup> 9761setWhiteBalance(whiteBalance: number): void 9762 9763设置手动白平衡值。 9764 9765**原子化服务API:** 从API version 20开始,该接口支持在原子化服务中使用。 9766 9767**系统能力:** SystemCapability.Multimedia.Camera.Core 9768 9769**参数:** 9770 9771| 参数名 | 类型 | 必填 | 说明 | 9772| -------- | ----------------------- | ---- | ------------------- | 9773| whiteBalance | number | 是 | 设置手动白平衡值。 | 9774 9775**错误码:** 9776 9777以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 9778 9779| 错误码ID | 错误信息 | 9780| --------------- | --------------- | 9781| 7400101 | Parameter missing or parameter type incorrect. | 9782| 7400103 | Session not config. | 9783 9784**示例:** 9785 9786```ts 9787import { BusinessError } from '@kit.BasicServicesKit'; 9788 9789function setWhiteBalance(session: camera.PhotoSession | camera.VideoSession): void { 9790 try { 9791 let whiteBalance: number = 1000; 9792 session.setWhiteBalance(whiteBalance); 9793 } catch (error) { 9794 let err = error as BusinessError; 9795 console.error(`The setWhiteBalance call failed. error code: ${err.code}`); 9796 } 9797} 9798``` 9799 9800### getWhiteBalance<sup>20+</sup> 9801 9802getWhiteBalance(): number 9803 9804获取当前手动白平衡的值。 9805 9806**原子化服务API:** 从API version 20开始,该接口支持在原子化服务中使用。 9807 9808**系统能力:** SystemCapability.Multimedia.Camera.Core 9809 9810**返回值:** 9811 9812| 类型 | 说明 | 9813| ---------- | ----------------------------- | 9814| number | 返回当前白平衡值。 | 9815 9816**错误码:** 9817 9818以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 9819 9820| 错误码ID | 错误信息 | 9821| --------------- | --------------- | 9822| 7400103 | Session not config. | 9823 9824**示例:** 9825 9826```ts 9827import { BusinessError } from '@kit.BasicServicesKit'; 9828 9829function getWhiteBalance(session: camera.PhotoSession | camera.VideoSession): number { 9830 let whiteBalance: number = 0; 9831 try { 9832 whiteBalance = session.getWhiteBalance(); 9833 } catch (error) { 9834 let err = error as BusinessError; 9835 console.error(`The getWhiteBalance call failed. error code: ${err.code}`); 9836 } 9837 return whiteBalance; 9838} 9839``` 9840