• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.multimedia.camera (相机管理)
2
3本模块为开发者提供一套简单且易于理解的相机服务接口,开发者通过调用接口可以开发相机应用。应用通过访问和操作相机硬件,实现基础操作,如预览、拍照和录像;还可以通过接口组合完成更多操作,如控制闪光灯和曝光时间、对焦或调焦等。
4
5> **说明:**
6>
7> 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8
9## 导入模块
10
11```ts
12import { camera } from '@kit.CameraKit';
13```
14
15## camera.getCameraManager
16
17getCameraManager(context: Context): CameraManager
18
19获取相机管理器实例,同步返回结果。
20
21**系统能力:** SystemCapability.Multimedia.Camera.Core
22
23**参数:**
24
25| 参数名     | 类型                                             | 必填 | 说明                           |
26| -------- | ----------------------------------------------- | ---- | ---------------------------- |
27| context  | [Context](../apis-ability-kit/js-apis-inner-application-baseContext.md)      | 是   | 应用上下文。                   |
28
29**返回值:**
30
31| 类型                                             | 说明                           |
32| ----------------------------------------------- | ---------------------------- |
33| [CameraManager](#cameramanager)           | 相机管理器。                   |
34
35**错误码:**
36
37以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
38
39| 错误码ID         | 错误信息        |
40| --------------- | --------------- |
41| 7400101                |  Parameter missing or parameter type incorrect.               |
42| 7400201                |  Camera service fatal error.                                  |
43
44**示例:**
45
46```ts
47import { common } from '@kit.AbilityKit';
48import { BusinessError } from '@kit.BasicServicesKit';
49
50function getCameraManager(context: common.BaseContext): camera.CameraManager | undefined {
51  let cameraManager: camera.CameraManager | undefined = undefined;
52  try {
53    cameraManager = camera.getCameraManager(context);
54  } catch (error) {
55    let err = error as BusinessError;
56    console.error(`The getCameraManager call failed. error code: ${err.code}`);
57  }
58  return cameraManager;
59}
60```
61
62## CameraDevice
63
64相机设备信息。
65
66**系统能力:** SystemCapability.Multimedia.Camera.Core
67
68| 名称                              | 类型                                  | 只读 | 可选 | 说明        |
69|---------------------------------|-------------------------------------| ---- |----|---------- |
70| cameraId                        | string                              | 是   | 否  | 相机id。|
71| cameraPosition                  | [CameraPosition](#cameraposition)   | 是   | 否  | 相机位置。    |
72| cameraType                      | [CameraType](#cameratype)           | 是   | 否  | 相机类型。    |
73| connectionType                  | [ConnectionType](#connectiontype)   | 是   | 否  | 相机连接类型。 |
74| cameraOrientation<sup>12+</sup> | number                              | 是   | 否  | 镜头的安装角度,不会随着屏幕旋转而改变,取值范围为0°-360°。 |
75| hostDeviceName<sup>15+</sup>    | string                              | 是   | 否  | 远端设备名称。 |
76| hostDeviceType<sup>15+</sup>    | [HostDeviceType](#hostdevicetype15) | 是   | 否  | 远端设备类型。 |
77
78## CameraPosition
79
80枚举,相机位置。
81
82**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
83
84**系统能力:** SystemCapability.Multimedia.Camera.Core
85
86| 名称                         | 值   | 说明                                                              |
87| --------------------------- | ---- |-----------------------------------------------------------------|
88| CAMERA_POSITION_UNSPECIFIED | 0    | 相对于设备屏幕没有固定的朝向的相机。                                                        |
89| CAMERA_POSITION_BACK        | 1    | 后置相机。                                                           |
90| CAMERA_POSITION_FRONT       | 2    | 前置相机。                                                           |
91| CAMERA_POSITION_FOLD_INNER<sup>(deprecated)</sup>  | 3    | 折叠态相机。<br/> 从API version 11开始支持,从API version 12开始废弃。 |
92
93## CameraType
94
95枚举,相机类型。
96
97**系统能力:** SystemCapability.Multimedia.Camera.Core
98
99| 名称                     | 值   | 说明            |
100| ----------------------- | ---- | -------------- |
101| CAMERA_TYPE_DEFAULT     | 0    | 相机类型未指定。  |
102| CAMERA_TYPE_WIDE_ANGLE  | 1    | 广角相机。       |
103| CAMERA_TYPE_ULTRA_WIDE  | 2    | 超广角相机。     |
104| CAMERA_TYPE_TELEPHOTO   | 3    | 长焦相机。       |
105| CAMERA_TYPE_TRUE_DEPTH  | 4    | 带景深信息的相机。 |
106
107## ConnectionType
108
109枚举,相机连接类型。
110
111**系统能力:** SystemCapability.Multimedia.Camera.Core
112
113| 名称                          | 值   | 说明           |
114| ---------------------------- | ---- | ------------- |
115| CAMERA_CONNECTION_BUILT_IN   | 0    | 内置相机。      |
116| CAMERA_CONNECTION_USB_PLUGIN | 1    | USB连接的相机。 |
117| CAMERA_CONNECTION_REMOTE     | 2    | 远程连接的相机。 |
118
119## HostDeviceType<sup>15+</sup>
120
121枚举,远端相机设备类型。
122
123**系统能力:** SystemCapability.Multimedia.Camera.Core
124
125| 名称                          | 值       | 说明      |
126| ---------------------------- | ----     |---------|
127| UNKNOWN_TYPE                 | 0        | 未知设备类型。 |
128| PHONE                        | 0x0E     | 手机设备。   |
129| TABLET                       | 0x11     | 平板设备。   |
130
131## CameraStatus
132
133枚举,相机状态。
134
135**系统能力:** SystemCapability.Multimedia.Camera.Core
136
137| 名称                       | 值   | 说明            |
138| ------------------------- | ---- | ------------    |
139| CAMERA_STATUS_APPEAR      | 0    | 新的相机出现。   |
140| CAMERA_STATUS_DISAPPEAR   | 1    | 相机被移除。     |
141| CAMERA_STATUS_AVAILABLE   | 2    | 相机可用。       |
142| CAMERA_STATUS_UNAVAILABLE | 3    | 相机不可用。     |
143
144## FoldStatus<sup>12+</sup>
145
146枚举,折叠机折叠状态。
147
148**系统能力:** SystemCapability.Multimedia.Camera.Core
149
150| 名称                       | 值   | 说明            |
151| ------------------------- | ---- | ------------    |
152| NON_FOLDABLE      | 0    | 表示当前设备不可折叠。   |
153| EXPANDED   | 1    | 表示当前设备折叠状态为完全展开。 |
154| FOLDED   | 2    | 表示当前设备折叠状态为折叠。       |
155
156## CameraStatusInfo
157
158相机管理器回调返回的接口实例,表示相机状态信息。
159
160**系统能力:** SystemCapability.Multimedia.Camera.Core
161
162| 名称   | 类型                           |    只读   |     可选     | 说明       |
163| ------ | ----------------------------- | --------- |------------ | ---------- |
164| camera | [CameraDevice](#cameradevice) |     否    |       否     | 相机信息。 |
165| status | [CameraStatus](#camerastatus) |     否    |       否     | 相机状态。 |
166
167## FoldStatusInfo<sup>12+</sup>
168
169相机管理器回调返回的接口实例,表示折叠机折叠状态信息。
170
171**系统能力:** SystemCapability.Multimedia.Camera.Core
172
173| 名称   | 类型                           |    只读   |     可选     | 说明       |
174| ------ | ----------------------------- | --------- |------------ | ---------- |
175| supportedCameras | [Array<CameraDevice\>](#cameradevice) |     否    |       否     | 当前折叠状态所支持的相机信息列表。 |
176| foldStatus | [FoldStatus](#foldstatus12) |     否    |       否     | 折叠屏折叠状态。 |
177
178## Profile
179
180相机配置信息项。
181
182**系统能力:** SystemCapability.Multimedia.Camera.Core
183
184| 名称      | 类型                          | 只读 | 可选 | 说明         |
185| -------- | ----------------------------- |---- | ---- | ------------- |
186| format   | [CameraFormat](#cameraformat) | 是  |  否  | 输出格式。      |
187| size     | [Size](#size)                 | 是  |  否  | 分辨率。<br>设置的是相机分辨率宽高,非实际出图宽高。  |
188
189## FrameRateRange
190
191帧率范围。
192
193**系统能力:** SystemCapability.Multimedia.Camera.Core
194
195| 名称      | 类型                          | 只读 | 可选 | 说明            |
196| -------- | ----------------------------- |----- |---| -------------- |
197| min      | number                        |  是  | 否 | 最小帧率。      |
198| max      | number                        |  是  | 否 | 最大帧率。      |
199
200## VideoProfile
201
202视频配置信息项,继承[Profile](#profile)。
203
204**系统能力:** SystemCapability.Multimedia.Camera.Core
205
206| 名称                       | 类型                                      | 只读 | 可选 | 说明        |
207| ------------------------- | ----------------------------------------- | --- | ---- |----------- |
208| frameRateRange            | [FrameRateRange](#frameraterange)         | 是  |  否  | 帧率范围,fps(frames per second)。 |
209
210## CameraOutputCapability
211
212相机输出能力项。
213
214**系统能力:** SystemCapability.Multimedia.Camera.Core
215
216| 名称                           | 类型                                                | 只读 | 可选 | 说明                |
217| ----------------------------- | --------------------------------------------------- | ---- | ---- |-------------------|
218| previewProfiles               | Array\<[Profile](#profile)\>                        |  是  | 否 | 支持的预览配置信息集合。      |
219| photoProfiles                 | Array\<[Profile](#profile)\>                        |  是  | 否 | 支持的拍照配置信息集合。        |
220| videoProfiles                 | Array\<[VideoProfile](#videoprofile)\>              |  是  | 否 | 支持的录像配置信息集合。        |
221| supportedMetadataObjectTypes  | Array\<[MetadataObjectType](#metadataobjecttype)\>  |  是  | 否 | 支持的metadata流类型信息集合。 |
222
223## SceneMode<sup>11+</sup>
224
225枚举,相机支持模式。
226
227**系统能力:** SystemCapability.Multimedia.Camera.Core
228
229| 名称                         | 值       | 说明                                          |
230|----------------------------|---------|---------------------------------------------|
231| NORMAL_PHOTO               | 1       | 普通拍照模式。详情见[PhotoSession](#photosession11)   |
232| NORMAL_VIDEO               | 2       | 普通录像模式。详情见[VideoSession](#videosession11)   |
233| SECURE_PHOTO<sup>12+</sup> | 12      | 安全相机模式。详情见[SecureSession](#securesession12) |
234
235## CameraErrorCode
236
237相机错误码。
238
239接口使用不正确以及on接口监听error状态返回。
240
241**系统能力:** SystemCapability.Multimedia.Camera.Core
242
243| 名称                       | 值          | 说明            |
244| -------------------------  | ----       | ------------    |
245| INVALID_ARGUMENT           | 7400101    | 参数缺失或者参数类型不对。   |
246| OPERATION_NOT_ALLOWED      | 7400102    | 操作流程不对,不允许。     |
247| SESSION_NOT_CONFIG         | 7400103    | session 未配置返回。       |
248| SESSION_NOT_RUNNING        | 7400104    | session 未运行返回。    |
249| SESSION_CONFIG_LOCKED      | 7400105    | session 配置已锁定返回。     |
250| DEVICE_SETTING_LOCKED      | 7400106    | 设备设置已锁定返回。     |
251| CONFLICT_CAMERA            | 7400107    | 设备重复打开返回。     |
252| DEVICE_DISABLED            | 7400108    | 安全原因摄像头被禁用。     |
253| DEVICE_PREEMPTED           | 7400109    | 相机被抢占导致无法使用。     |
254| UNRESOLVED_CONFLICTS_WITH_CURRENT_CONFIGURATIONS<sup>12+</sup> | 7400110   | 与当前配置存在冲突。     |
255| SERVICE_FATAL_ERROR        | 7400201    | 相机服务错误返回。     |
256
257## CameraManager
258
259相机管理器类,使用前需要通过[getCameraManager](#cameragetcameramanager)获取相机管理实例。
260
261### getSupportedCameras
262
263getSupportedCameras(): Array\<CameraDevice\>
264
265获取支持指定的相机设备对象,同步返回结果。
266
267**系统能力:** SystemCapability.Multimedia.Camera.Core
268
269**返回值:**
270
271| 类型                                             | 说明                           |
272| ----------------------------------------------- | ---------------------------- |
273|  Array\<[CameraDevice](#cameradevice)>            | 相机设备列表。                   |
274
275**示例:**
276
277```ts
278import { BusinessError } from '@kit.BasicServicesKit';
279
280function getSupportedCameras(cameraManager: camera.CameraManager): Array<camera.CameraDevice> {
281  let cameras: Array<camera.CameraDevice> = [];
282  try {
283    cameras = cameraManager.getSupportedCameras();
284  } catch (error) {
285    let err = error as BusinessError;
286    console.error(`The getSupportedCameras call failed. error code: ${err.code}`);
287  }
288  return cameras;
289}
290```
291
292### getSupportedSceneModes<sup>11+</sup>
293
294getSupportedSceneModes(camera: CameraDevice): Array\<SceneMode\>
295
296获取指定的相机设备对象支持的模式,同步返回结果。
297
298**系统能力:** SystemCapability.Multimedia.Camera.Core
299
300**参数:**
301
302| 参数名         | 类型                                                            | 必填 | 说明                      |
303| ------------ |--------------------------------------------------------------- | -- | -------------------------- |
304| camera | [CameraDevice](#cameradevice)                              | 是 | 相机设备,通过 [getSupportedCameras](#getsupportedcameras) 接口获取。传参异常时,会返回错误码。       |
305
306**返回值:**
307
308| 类型                                             | 说明                           |
309| ----------------------------------------------- | ---------------------------- |
310|  Array\<[SceneMode](#scenemode11)>            | 相机支持的模式列表。                   |
311
312**示例:**
313
314```ts
315import { BusinessError } from '@kit.BasicServicesKit';
316
317function getSupportedSceneModes(cameraManager: camera.CameraManager, camera: camera.CameraDevice): Array<camera.SceneMode> {
318  let modes: Array<camera.SceneMode> = [];
319  try {
320    modes = cameraManager.getSupportedSceneModes(camera);
321  } catch (error) {
322    let err = error as BusinessError;
323    console.error(`The getSupportedSceneModes call failed. error code: ${err.code}`);
324  }
325  return modes;
326}
327```
328
329### getSupportedOutputCapability<sup>(deprecated)</sup>
330
331getSupportedOutputCapability(camera: CameraDevice): CameraOutputCapability
332
333查询相机设备支持的输出能力,同步返回结果。
334
335> **说明:**
336> 从 API version 10开始支持,从API version 11开始废弃。建议使用[getSupportedOutputCapability](#getsupportedoutputcapability11)替代。
337
338**系统能力:** SystemCapability.Multimedia.Camera.Core
339
340**参数:**
341
342| 参数名         | 类型                                                            | 必填 | 说明                      |
343| ------------ |--------------------------------------------------------------- | -- | -------------------------- |
344| camera | [CameraDevice](#cameradevice)                              | 是 | 相机设备,通过 [getSupportedCameras](#getsupportedcameras) 接口获取。传参异常时,会返回错误码。      |
345
346**返回值:**
347
348| 类型                                             | 说明                           |
349| ----------------------------------------------- | ---------------------------- |
350| [CameraOutputCapability](#cameraoutputcapability)            | 相机输出能力。                   |
351
352**示例:**
353
354```ts
355function getSupportedOutputCapability(camera: camera.CameraDevice, cameraManager: camera.CameraManager): camera.CameraOutputCapability {
356  let cameraOutputCapability: camera.CameraOutputCapability = cameraManager.getSupportedOutputCapability(camera);
357  return cameraOutputCapability;
358}
359```
360
361### getSupportedOutputCapability<sup>11+</sup>
362
363getSupportedOutputCapability(camera: CameraDevice, mode: SceneMode): CameraOutputCapability
364
365查询相机设备在模式下支持的输出能力,同步返回结果。
366
367**系统能力:** SystemCapability.Multimedia.Camera.Core
368
369**参数:**
370
371| 参数名         | 类型                                                            | 必填 | 说明                      |
372| ------------ |--------------------------------------------------------------- | -- | -------------------------- |
373| camera | [CameraDevice](#cameradevice)                              | 是 | 相机设备,通过 [getSupportedCameras](#getsupportedcameras) 接口获取。       |
374| mode | [SceneMode](#scenemode11)                              | 是 | 相机模式,通过 [getSupportedSceneModes](#getsupportedscenemodes11) 接口获取。       |
375
376**返回值:**
377
378| 类型                                             | 说明                           |
379| ----------------------------------------------- | ---------------------------- |
380| [CameraOutputCapability](#cameraoutputcapability)            | 相机输出能力。                   |
381
382**示例:**
383
384```ts
385function getSupportedOutputCapability(camera: camera.CameraDevice, cameraManager: camera.CameraManager, sceneMode: camera.SceneMode): camera.CameraOutputCapability {
386  let cameraOutputCapability: camera.CameraOutputCapability = cameraManager.getSupportedOutputCapability(camera, sceneMode);
387  return cameraOutputCapability;
388}
389```
390
391### isCameraMuted
392
393isCameraMuted(): boolean
394
395查询相机当前的禁用状态(禁用/未禁用)。
396
397**系统能力:** SystemCapability.Multimedia.Camera.Core
398
399**返回值:**
400
401| 类型        | 说明                                         |
402| ---------- | -------------------------------------------- |
403| boolean    | 返回true表示相机被禁用,返回false表示相机未被禁用。 |
404
405**示例:**
406
407```ts
408function isCameraMuted(cameraManager: camera.CameraManager): boolean {
409  let isMuted: boolean = cameraManager.isCameraMuted();
410  return isMuted;
411}
412```
413
414### createCameraInput
415
416createCameraInput(camera: CameraDevice): CameraInput
417
418使用CameraDevice对象创建CameraInput实例,同步返回结果。
419
420**需要权限:** ohos.permission.CAMERA
421
422**系统能力:** SystemCapability.Multimedia.Camera.Core
423
424**参数:**
425
426| 参数名     | 类型                                         | 必填 | 说明                                               |
427| -------- | ------------------------------------------- | ---- |--------------------------------------------------|
428| camera  | [CameraDevice](#cameradevice)         | 是   | CameraDevice对象,通过 [getSupportedCameras](#getsupportedcameras) 接口获取。 |
429
430**返回值:**
431
432| 类型        | 说明                          |
433| ---------- | ----------------------------- |
434| [CameraInput](#camerainput)    | CameraInput实例。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
435
436**错误码:**
437
438以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
439
440| 错误码ID         | 错误信息        |
441| --------------- | --------------- |
442| 7400101                |  Parameter missing or parameter type incorrect.               |
443| 7400102                |  Operation not allowed.               |
444| 7400201                |  Camera service fatal error.               |
445
446**示例:**
447
448```ts
449import { BusinessError } from '@kit.BasicServicesKit';
450
451function createCameraInput(camera: camera.CameraDevice, cameraManager: camera.CameraManager): camera.CameraInput | undefined {
452  let cameraInput: camera.CameraInput | undefined = undefined;
453  try {
454    cameraInput = cameraManager.createCameraInput(camera);
455  } catch (error) {
456    // 失败返回错误码error.code并处理。
457    let err = error as BusinessError;
458    console.error(`The createCameraInput call failed. error code: ${err.code}`);
459  }
460  return cameraInput;
461}
462```
463
464### createCameraInput
465
466createCameraInput(position: CameraPosition, type: CameraType): CameraInput
467
468根据相机位置和类型创建CameraInput实例,同步返回结果。
469
470**需要权限:** ohos.permission.CAMERA
471
472**系统能力:** SystemCapability.Multimedia.Camera.Core
473
474**参数:**
475
476| 参数名     | 类型                                        | 必填 | 说明                                |
477| -------- | ------------------------------------------- | ---- | --------------------------------- |
478| position | [CameraPosition](#cameraposition)           | 是   | 相机位置,通过 [getSupportedCameras](#getsupportedcameras) 接口获取设备,然后获取设备位置信息。  |
479| type     | [CameraType](#cameratype)                   | 是   | 相机类型,通过 [getSupportedCameras](#getsupportedcameras) 接口获取设备,然后获取设备类型信息。 |
480
481**返回值:**
482
483| 类型        | 说明                          |
484| ---------- | ----------------------------- |
485| [CameraInput](#camerainput)    | CameraInput实例。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
486
487**错误码:**
488
489以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
490
491| 错误码ID         | 错误信息        |
492| --------------- | --------------- |
493| 7400101                |  Parameter missing or parameter type incorrect.               |
494| 7400102                |  Operation not allowed.               |
495| 7400201                |  Camera service fatal error.               |
496
497**示例:**
498
499```ts
500import { BusinessError } from '@kit.BasicServicesKit';
501
502function createCameraInput(camera: camera.CameraDevice, cameraManager: camera.CameraManager): camera.CameraInput | undefined {
503  let position: camera.CameraPosition = camera.cameraPosition;
504  let type: camera.CameraType = camera.cameraType;
505  let cameraInput: camera.CameraInput | undefined = undefined;
506  try {
507    cameraInput = cameraManager.createCameraInput(position, type);
508  } catch (error) {
509    // 失败返回错误码error.code并处理。
510    let err = error as BusinessError;
511    console.error(`The createCameraInput call failed. error code: ${err.code}`);
512  }
513  return cameraInput;
514}
515```
516
517### createPreviewOutput
518
519createPreviewOutput(profile: Profile, surfaceId: string): PreviewOutput
520
521创建预览输出对象,同步返回结果。
522
523**系统能力:** SystemCapability.Multimedia.Camera.Core
524
525**参数:**
526
527| 参数名     | 类型                                             | 必填 | 说明                              |
528| -------- | ----------------------------------------------- | ---- | ------------------------------- |
529| profile  | [Profile](#profile)                             | 是   | 支持的预览配置信息,通过[getSupportedOutputCapability](#getsupportedoutputcapability11)接口获取。|
530| surfaceId| string | 是   | 从[XComponent](../apis-arkui/arkui-ts/ts-basic-components-xcomponent.md)或者[ImageReceiver](../apis-image-kit/js-apis-image.md#imagereceiver9)组件获取的surfaceId。|
531
532**返回值:**
533
534| 类型        | 说明                          |
535| ---------- | ----------------------------- |
536| [PreviewOutput](#previewoutput)    | PreviewOutput实例。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
537
538**错误码:**
539
540以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
541
542| 错误码ID         | 错误信息        |
543| --------------- | --------------- |
544| 7400101                |  Parameter missing or parameter type incorrect.               |
545| 7400201                |  Camera service fatal error.               |
546
547**示例:**
548
549```ts
550import { BusinessError } from '@kit.BasicServicesKit';
551
552function createPreviewOutput(cameraOutputCapability: camera.CameraOutputCapability, cameraManager: camera.CameraManager, surfaceId: string): camera.PreviewOutput | undefined {
553  let profile: camera.Profile = cameraOutputCapability.previewProfiles[0];
554  let previewOutput: camera.PreviewOutput | undefined = undefined;
555  try {
556    previewOutput = cameraManager.createPreviewOutput(profile, surfaceId);
557  } catch (error) {
558    // 失败返回错误码error.code并处理。
559    let err = error as BusinessError;
560    console.error(`The createPreviewOutput call failed. error code: ${err.code}`);
561  }
562  return previewOutput;
563}
564```
565
566### createPreviewOutput<sup>12+</sup>
567
568createPreviewOutput(surfaceId: string): PreviewOutput
569
570创建无配置信息的预览输出对象,同步返回结果。该接口需配合[preconfig](#preconfig12)一起使用。
571
572**系统能力:** SystemCapability.Multimedia.Camera.Core
573
574**参数:**
575
576| 参数名     | 类型                                             | 必填 | 说明                              |
577| -------- | ----------------------------------------------- | ---- | ------------------------------- |
578| surfaceId| string | 是   | 从[XComponent](../apis-arkui/arkui-ts/ts-basic-components-xcomponent.md)或者[ImageReceiver](../apis-image-kit/js-apis-image.md#imagereceiver9)组件获取的surfaceId。|
579
580**返回值:**
581
582| 类型        | 说明                          |
583| ---------- | ----------------------------- |
584| [PreviewOutput](#previewoutput)    | PreviewOutput实例。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
585
586**错误码:**
587
588以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
589
590| 错误码ID   | 错误信息                                           |
591|---------|------------------------------------------------|
592| 7400101 | Parameter missing or parameter type incorrect. |
593| 7400201 | Camera service fatal error.                    |
594
595**示例:**
596
597```ts
598import { BusinessError } from '@kit.BasicServicesKit';
599
600function createPreviewOutput(cameraManager: camera.CameraManager, surfaceId: string): camera.PreviewOutput | undefined {
601  let previewOutput: camera.PreviewOutput | undefined = undefined;
602  try {
603    previewOutput = cameraManager.createPreviewOutput(surfaceId);
604  } catch (error) {
605    // 失败返回错误码error.code并处理。
606    let err = error as BusinessError;
607    console.error(`The createPreviewOutput call failed. error code: ${err.code}`);
608  }
609  return previewOutput;
610}
611```
612
613### createPhotoOutput<sup>(deprecated)</sup>
614
615createPhotoOutput(profile: Profile, surfaceId: string): PhotoOutput
616
617创建拍照输出对象,同步返回结果。
618
619> **说明:**
620> 从 API version 10开始支持,从API version 11开始废弃。建议使用[createPhotoOutput](#createphotooutput11)替代。
621
622**系统能力:** SystemCapability.Multimedia.Camera.Core
623
624**参数:**
625
626| 参数名     | 类型                                         | 必填 | 说明                                  |
627| -------- | ------------------------------------------- | ---- | ----------------------------------- |
628| profile  | [Profile](#profile)                         | 是   | 支持的拍照配置信息,通过[getSupportedOutputCapability](#getsupportedoutputcapability11)接口获取。|
629| surfaceId| string            | 是   | 从[ImageReceiver](../apis-image-kit/js-apis-image.md#imagereceiver9)获取的surfaceId。|
630
631**返回值:**
632
633| 类型        | 说明                          |
634| ---------- | ----------------------------- |
635| [PhotoOutput](#photooutput)   | PhotoOutput实例。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
636
637**错误码:**
638
639以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
640
641| 错误码ID         | 错误信息        |
642| --------------- | --------------- |
643| 7400101                |  Parameter missing or parameter type incorrect.               |
644
645```ts
646import { BusinessError } from '@kit.BasicServicesKit';
647
648function createPhotoOutput(cameraOutputCapability: camera.CameraOutputCapability, cameraManager: camera.CameraManager, surfaceId: string): camera.PhotoOutput | undefined {
649  let profile: camera.Profile = cameraOutputCapability.photoProfiles[0];
650  let photoOutput: camera.PhotoOutput | undefined = undefined;
651  try {
652    photoOutput = cameraManager.createPhotoOutput(profile, surfaceId);
653  } catch (error) {
654    // 失败返回错误码error.code并处理。
655    let err = error as BusinessError;
656    console.error(`The createPhotoOutput call failed. error code: ${err.code}`);
657  }
658  return photoOutput;
659}
660```
661
662### createPhotoOutput<sup>11+</sup>
663
664createPhotoOutput(profile?: Profile): PhotoOutput
665
666创建拍照输出对象,同步返回结果。
667
668**系统能力:** SystemCapability.Multimedia.Camera.Core
669
670**参数:**
671
672| 参数名     | 类型                                         | 必填 | 说明                                  |
673| -------- | ------------------------------------------- |----| ----------------------------------- |
674| profile  | [Profile](#profile)                         | 否  | 支持的拍照配置信息,通过[getSupportedOutputCapability](#getsupportedoutputcapability11)接口获取。<br>API 11时,该参数必填;从API version 12开始,如果使用[preconfig](#preconfig12)进行预配置,传入profile参数会覆盖preconfig的预配置参数。|
675
676**返回值:**
677
678| 类型        | 说明                          |
679| ---------- | ----------------------------- |
680| [PhotoOutput](#photooutput)   | PhotoOutput实例。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
681
682**错误码:**
683
684以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
685
686| 错误码ID    | 错误信息                                           |
687|----------|------------------------------------------------|
688| 7400101  | Parameter missing or parameter type incorrect. |
689| 7400201  | Camera service fatal error.                    |
690
691**示例:**
692
693```ts
694import { BusinessError } from '@kit.BasicServicesKit';
695
696function createPhotoOutput(cameraOutputCapability: camera.CameraOutputCapability, cameraManager: camera.CameraManager): camera.PhotoOutput | undefined {
697  let profile: camera.Profile = cameraOutputCapability.photoProfiles[0];
698  let photoOutput: camera.PhotoOutput | undefined = undefined;
699  try {
700    photoOutput = cameraManager.createPhotoOutput(profile);
701  } catch (error) {
702    // 失败返回错误码error.code并处理。
703    let err = error as BusinessError;
704    console.error(`The createPhotoOutput call failed. error code: ${err.code}`);
705  }
706  return photoOutput;
707}
708```
709
710### createVideoOutput
711
712createVideoOutput(profile: VideoProfile, surfaceId: string): VideoOutput
713
714创建录像输出对象,同步返回结果。
715
716**系统能力:** SystemCapability.Multimedia.Camera.Core
717
718**参数:**
719
720| 参数名     | 类型                                        | 必填 | 说明                              |
721| -------- | ------------------------------------------- | ---- | ------------------------------ |
722| profile  | [VideoProfile](#videoprofile)               | 是   | 支持的录像配置信息,通过[getSupportedOutputCapability](#getsupportedoutputcapability11)接口获取。 |
723| surfaceId| string          | 是   | 从[AVRecorder](../apis-media-kit/js-apis-media.md#avrecorder9)获取的surfaceId。|
724
725**返回值:**
726
727| 类型        | 说明                          |
728| ---------- | ----------------------------- |
729| [VideoOutput](#videooutput)   | VideoOutput实例。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
730
731**错误码:**
732
733以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
734
735| 错误码ID         | 错误信息        |
736| --------------- | --------------- |
737| 7400101                |  Parameter missing or parameter type incorrect.               |
738| 7400201                |  Camera service fatal error.               |
739
740**示例:**
741
742```ts
743import { BusinessError } from '@kit.BasicServicesKit';
744
745function createVideoOutput(cameraOutputCapability: camera.CameraOutputCapability, cameraManager: camera.CameraManager, surfaceId: string): camera.VideoOutput | undefined {
746  let profile: camera.VideoProfile = cameraOutputCapability.videoProfiles[0];
747  let videoOutput: camera.VideoOutput | undefined = undefined;
748  try {
749    videoOutput = cameraManager.createVideoOutput(profile, surfaceId);
750  } catch (error) {
751    // 失败返回错误码error.code并处理。
752    let err = error as BusinessError;
753    console.error(`The createVideoOutput call failed. error code: ${err.code}`);
754  }
755  return videoOutput;
756}
757```
758
759### createVideoOutput<sup>12+</sup>
760
761createVideoOutput(surfaceId: string): VideoOutput
762
763创建无配置信息的录像输出对象,同步返回结果。该接口需配合[preconfig](#preconfig12-1)功能一起使用。
764
765**系统能力:** SystemCapability.Multimedia.Camera.Core
766
767**参数:**
768
769| 参数名       | 类型     | 必填    | 说明                                                                         |
770|-----------|--------|-------|----------------------------------------------------------------------------|
771| surfaceId | string | 是     | 从[AVRecorder](../apis-media-kit/js-apis-media.md#avrecorder9)获取的surfaceId。 |
772
773**返回值:**
774
775| 类型        | 说明                          |
776| ---------- | ----------------------------- |
777| [VideoOutput](#videooutput)   | VideoOutput实例。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
778
779**错误码:**
780
781以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
782
783| 错误码ID    | 错误信息                                           |
784|----------|------------------------------------------------|
785| 7400101  | Parameter missing or parameter type incorrect. |
786| 7400201  | Camera service fatal error.                    |
787
788**示例:**
789
790```ts
791import { BusinessError } from '@kit.BasicServicesKit';
792
793function createVideoOutput(cameraManager: camera.CameraManager, surfaceId: string): camera.VideoOutput | undefined {
794  let videoOutput: camera.VideoOutput | undefined = undefined;
795  try {
796    videoOutput = cameraManager.createVideoOutput(surfaceId);
797  } catch (error) {
798    // 失败返回错误码error.code并处理。
799    let err = error as BusinessError;
800    console.error(`The createVideoOutput call failed. error code: ${err.code}`);
801  }
802  return videoOutput;
803}
804```
805
806### createMetadataOutput
807
808createMetadataOutput(metadataObjectTypes: Array\<MetadataObjectType\>): MetadataOutput
809
810创建metadata流输出对象,同步返回结果。
811
812**系统能力:** SystemCapability.Multimedia.Camera.Core
813
814**参数:**
815
816| 参数名                  | 类型                                               | 必填 | 说明                          |
817| -------------------- | -------------------------------------------------- | --- | ---------------------------- |
818| metadataObjectTypes  | Array\<[MetadataObjectType](#metadataobjecttype)\>  | 是  | metadata流类型信息,通过[getSupportedOutputCapability](#getsupportedoutputcapability11)接口获取。 |
819
820**返回值:**
821
822| 类型        | 说明                          |
823| ---------- | ----------------------------- |
824| [MetadataOutput](#metadataoutput)   | MetadataOutput实例。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
825
826**错误码:**
827
828以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
829
830| 错误码ID         | 错误信息        |
831| --------------- | --------------- |
832| 7400101                |  Parameter missing or parameter type incorrect.               |
833| 7400201                |  Camera service fatal error.               |
834
835**示例:**
836
837```ts
838import { BusinessError } from '@kit.BasicServicesKit';
839
840function createMetadataOutput(cameraManager: camera.CameraManager, cameraOutputCapability: camera.CameraOutputCapability): void {
841  let metadataObjectTypes: Array<camera.MetadataObjectType> = cameraOutputCapability.supportedMetadataObjectTypes;
842  let metadataOutput: camera.MetadataOutput | undefined = undefined;
843  try {
844    metadataOutput = cameraManager.createMetadataOutput(metadataObjectTypes);
845  } catch (error) {
846    // 失败返回错误码error.code并处理。
847    let err = error as BusinessError;
848    console.error(`createMetadataOutput error. error code: ${err.code}`);
849  }
850}
851```
852
853### createCaptureSession<sup>(deprecated)</sup>
854
855createCaptureSession(): CaptureSession
856
857创建CaptureSession实例,同步返回结果。
858
859> **说明:**
860>从 API version 10开始支持,从API version 11开始废弃。建议使用[createSession](#createsession11)替代。
861
862**系统能力:** SystemCapability.Multimedia.Camera.Core
863
864**返回值:**
865
866| 类型        | 说明                          |
867| ---------- | ----------------------------- |
868| [CaptureSession](#capturesessiondeprecated)   | CaptureSession实例。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
869
870**错误码:**
871
872以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
873
874| 错误码ID         | 错误信息        |
875| --------------- | --------------- |
876| 7400201                |  Camera service fatal error.               |
877
878**示例:**
879
880```ts
881import { BusinessError } from '@kit.BasicServicesKit';
882
883function createCaptureSession(cameraManager: camera.CameraManager): camera.CaptureSession | undefined {
884  let captureSession: camera.CaptureSession | undefined = undefined;
885  try {
886    captureSession = cameraManager.createCaptureSession();
887  } catch (error) {
888    // 失败返回错误码error.code并处理。
889    let err = error as BusinessError;
890    console.error(`createCaptureSession error. error code: ${err.code}`);
891  }
892  return captureSession;
893}
894```
895
896### createSession<sup>11+</sup>
897
898createSession\<T extends Session\>(mode: SceneMode): T
899
900创建指定SceneMode的Session实例,同步返回结果。
901
902**系统能力:** SystemCapability.Multimedia.Camera.Core
903
904**参数:**
905
906| 参数名   | 类型              | 必填 | 说明       |
907| -------- | -----------------| ---- | --------- |
908| mode     | [SceneMode](#scenemode11)     | 是   | 相机支持的模式。传参异常(如超出范围、传入null、未定义等),实际接口不会生效。 |
909
910**返回值:**
911
912| 类型        | 说明                          |
913| ---------- | ----------------------------- |
914| [T extends Session](#session11)   | Session实例。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
915
916**错误码:**
917
918以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
919
920| 错误码ID         | 错误信息                                                                                                                                           |
921| --------------- |------------------------------------------------------------------------------------------------------------------------------------------------|
922| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3.Parameter verification failed. |
923| 7400201                | Camera service fatal error.                                                                                                                    |
924
925**示例:**
926
927```ts
928import { BusinessError } from '@kit.BasicServicesKit';
929
930function createSession(cameraManager: camera.CameraManager, mode: camera.SceneMode): camera.Session | undefined {
931  let photoSession: camera.PhotoSession | undefined = undefined;
932  try {
933    photoSession = cameraManager.createSession(mode) as camera.PhotoSession;
934  } catch (error) {
935    // 失败返回错误码error.code并处理。
936    let err = error as BusinessError;
937    console.error(`createCaptureSession error. error code: ${err.code}`);
938  }
939  return photoSession;
940}
941```
942
943### on('cameraStatus')
944
945on(type: 'cameraStatus', callback: AsyncCallback\<CameraStatusInfo\>): void
946
947相机设备状态回调,通过注册回调函数获取相机的状态变化。使用callback异步回调。
948
949> **说明:**
950>
951> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
952
953**系统能力:** SystemCapability.Multimedia.Camera.Core
954
955**参数:**
956
957| 参数名     | 类型            | 必填 | 说明       |
958| -------- | -----------------| ---- | --------- |
959| type     | string           | 是   | 监听事件,固定为'cameraStatus'。cameraManager对象获取成功后可监听。目前只支持对设备打开或者关闭会触发该事件并返回对应信息。 |
960| callback | AsyncCallback\<[CameraStatusInfo](#camerastatusinfo)\> | 是   | 回调函数,用于获取镜头状态变化信息。 |                 |
961
962**示例:**
963
964```ts
965import { BusinessError } from '@kit.BasicServicesKit';
966
967function callback(err: BusinessError, cameraStatusInfo: camera.CameraStatusInfo): void {
968  if (err !== undefined && err.code !== 0) {
969    console.error('cameraStatus with errorCode = ' + err.code);
970    return;
971  }
972  console.info(`camera : ${cameraStatusInfo.camera.cameraId}`);
973  console.info(`status: ${cameraStatusInfo.status}`);
974}
975
976function registerCameraStatus(cameraManager: camera.CameraManager): void {
977  cameraManager.on('cameraStatus', callback);
978}
979```
980
981### off('cameraStatus')
982
983off(type: 'cameraStatus', callback?: AsyncCallback\<CameraStatusInfo\>): void
984
985相机设备状态注销回调,通过注销回调函数取消获取相机的状态变化。
986
987**系统能力:** SystemCapability.Multimedia.Camera.Core
988
989**参数:**
990
991| 参数名     | 类型            | 必填 | 说明       |
992| -------- | -----------------| ---- | --------- |
993| type     | string           | 是   | 监听事件,固定为'cameraStatus'。cameraManager对象获取成功后可监听。 |
994| callback | AsyncCallback\<[CameraStatusInfo](#camerastatusinfo)\> | 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
995
996**示例:**
997
998```ts
999function unregisterCameraStatus(cameraManager: camera.CameraManager): void {
1000  cameraManager.off('cameraStatus');
1001}
1002```
1003
1004### on('foldStatusChange')<sup>12+</sup>
1005
1006on(type: 'foldStatusChange', callback: AsyncCallback\<FoldStatusInfo\>): void
1007
1008开启折叠设备折叠状态变化的监听。使用callback异步回调。
1009
1010> **说明:**
1011>
1012> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
1013
1014**系统能力:** SystemCapability.Multimedia.Camera.Core
1015
1016**参数:**
1017
1018| 参数名     | 类型            | 必填 | 说明       |
1019| -------- | -----------------| ---- | --------- |
1020| type     | string           | 是   | 监听事件,固定为'foldStatusChange'。表示折叠设备折叠状态发生变化。 |
1021| callback | AsyncCallback\<[FoldStatusInfo](#foldstatusinfo12)\> | 是   | 回调函数。返回折叠设备折叠信息。 |
1022
1023**示例:**
1024
1025```ts
1026import { BusinessError } from '@kit.BasicServicesKit';
1027
1028function callback(err: BusinessError, foldStatusInfo: camera.FoldStatusInfo): void {
1029  if (err !== undefined && err.code !== 0) {
1030    console.error('foldStatusChange with errorCode = ' + err.code);
1031    return;
1032  }
1033  console.info(`camera length: ${foldStatusInfo.supportedCameras.length}`);
1034  console.info(`foldStatus: ${foldStatusInfo.foldStatus}`);
1035}
1036
1037function registerFoldStatusChange(cameraManager: camera.CameraManager): void {
1038  cameraManager.on('foldStatusChange', callback);
1039}
1040```
1041
1042### off('foldStatusChange')<sup>12+</sup>
1043
1044off(type: 'foldStatusChange', callback?: AsyncCallback\<FoldStatusInfo\>): void
1045
1046关闭折叠设备折叠状态变化的监听。
1047
1048**系统能力:** SystemCapability.Multimedia.Camera.Core
1049
1050**参数:**
1051
1052| 参数名     | 类型            | 必填 | 说明       |
1053| -------- | -----------------| ---- | --------- |
1054| type     | string           | 是   | 监听事件,固定为'foldStatusChange'。表示折叠设备折叠状态发生变化。 |
1055| callback | AsyncCallback\<[FoldStatusInfo](#foldstatusinfo12)\> | 否   | 回调函数,返回折叠设备折叠信息。如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
1056
1057**示例:**
1058
1059```ts
1060function unregisterFoldStatusChange(cameraManager: camera.CameraManager): void {
1061  cameraManager.off('foldStatusChange');
1062}
1063```
1064
1065### isTorchSupported<sup>11+</sup>
1066
1067isTorchSupported(): boolean
1068
1069检测设备是否支持手电筒。
1070
1071**系统能力:** SystemCapability.Multimedia.Camera.Core
1072
1073**返回值:**
1074
1075| 类型        | 说明                          |
1076| ---------- | ----------------------------- |
1077| boolean    | 返回true表示设备支持手电筒。 |
1078
1079**示例:**
1080
1081```ts
1082function isTorchSupported(cameraManager: camera.CameraManager): boolean {
1083  let isSupported = cameraManager.isTorchSupported();
1084  return isSupported;
1085}
1086```
1087
1088### isTorchModeSupported<sup>11+</sup>
1089
1090isTorchModeSupported(mode: TorchMode): boolean
1091
1092检测是否支持设置的手电筒模式。
1093
1094**系统能力:** SystemCapability.Multimedia.Camera.Core
1095
1096**参数:**
1097
1098| 参数名     | 类型             | 必填 | 说明       |
1099| -------- | --------------- | ---- | --------- |
1100| mode | [TorchMode](#torchmode11) | 是 | 手电筒模式。传参为null或者undefined,作为0处理,手电筒关闭。 |
1101
1102**返回值:**
1103
1104| 类型        | 说明                          |
1105| ---------- | ----------------------------- |
1106| boolean    | 返回true表示设备支持设置的手电筒模式。 |
1107
1108**示例:**
1109
1110```ts
1111function isTorchModeSupported(cameraManager: camera.CameraManager, torchMode: camera.TorchMode): boolean {
1112  let isSupported = cameraManager.isTorchModeSupported(torchMode);
1113  return isSupported;
1114}
1115```
1116
1117### getTorchMode<sup>11+</sup>
1118
1119getTorchMode(): TorchMode
1120
1121获取当前设备手电筒模式。
1122
1123**系统能力:** SystemCapability.Multimedia.Camera.Core
1124
1125**返回值:**
1126
1127| 类型        | 说明                          |
1128| ---------- | ----------------------------- |
1129| [TorchMode](#torchmode11)    | 返回设备当前手电筒模式。 |
1130
1131**示例:**
1132
1133```ts
1134function getTorchMode(cameraManager: camera.CameraManager): camera.TorchMode | undefined {
1135  let torchMode: camera.TorchMode | undefined = undefined;
1136  torchMode = cameraManager.getTorchMode();
1137  return torchMode;
1138}
1139```
1140
1141### setTorchMode<sup>11+</sup>
1142
1143setTorchMode(mode: TorchMode): void
1144
1145设置设备手电筒模式。
1146
1147**系统能力:** SystemCapability.Multimedia.Camera.Core
1148
1149**参数:**
1150
1151| 参数名     | 类型             | 必填 | 说明       |
1152| -------- | --------------- | ---- | --------- |
1153| mode | [TorchMode](#torchmode11) | 是 | 手电筒模式。传参为null或者undefined,作为0处理,手电筒关闭。 |
1154
1155**错误码:**
1156
1157以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
1158
1159| 错误码ID         | 错误信息        |
1160| --------------- | --------------- |
1161| 7400101 | Parameter missing or parameter type incorrect. |
1162| 7400102 | Operation not allowed. |
1163| 7400201 | Camera service fatal error. |
1164
1165**示例:**
1166
1167```ts
1168import { BusinessError } from '@kit.BasicServicesKit';
1169
1170function setTorchMode(cameraManager: camera.CameraManager, torchMode: camera.TorchMode): void {
1171  try {
1172    cameraManager.setTorchMode(torchMode);
1173  } catch (error) {
1174    // 失败返回错误码error.code并处理。
1175    let err = error as BusinessError;
1176    console.error(`The setTorchMode call failed. error code: ${err.code}`);
1177  }
1178}
1179```
1180
1181### on('torchStatusChange')<sup>11+</sup>
1182
1183on(type: 'torchStatusChange', callback: AsyncCallback\<TorchStatusInfo\>): void
1184
1185手电筒状态变化回调,通过注册回调函数获取手电筒状态变化。使用callback异步回调。
1186
1187> **说明:**
1188>
1189> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
1190
1191**系统能力:** SystemCapability.Multimedia.Camera.Core
1192
1193**参数:**
1194
1195| 参数名     | 类型             | 必填 | 说明       |
1196| -------- | --------------- | ---- | --------- |
1197| type     | string          | 是   | 监听事件,固定为'torchStatusChange'。cameraManager对象获取成功后可监听。目前只支持手电筒打开,手电筒关闭,手电筒不可用,手电筒恢复可用会触发该事件并返回对应信息。 |
1198| callback | AsyncCallback\<TorchStatusInfo> | 是   | 回调函数,用于获取手电筒状态变化信息。               |
1199
1200**示例:**
1201
1202```ts
1203import { BusinessError } from '@kit.BasicServicesKit';
1204
1205function callback(err: BusinessError, torchStatusInfo: camera.TorchStatusInfo): void {
1206  if (err !== undefined && err.code !== 0) {
1207    console.error(`Callback Error, errorCode: ${err.code}`);
1208    return;
1209  }
1210  console.info(`onTorchStatusChange, isTorchAvailable: ${torchStatusInfo.isTorchAvailable}, isTorchActive: ${torchStatusInfo.isTorchActive}, level: ${torchStatusInfo.torchLevel}`);
1211}
1212
1213function registerTorchStatusChange(cameraManager: camera.CameraManager): void {
1214  cameraManager.on('torchStatusChange', callback);
1215}
1216```
1217
1218### off('torchStatusChange')<sup>11+</sup>
1219
1220off(type: 'torchStatusChange', callback?: AsyncCallback\<TorchStatusInfo\>): void
1221
1222手电筒状态变化注销回调,通过注销回调函数取消获取手电筒状态变化。
1223
1224**系统能力:** SystemCapability.Multimedia.Camera.Core
1225
1226**参数:**
1227
1228| 参数名     | 类型             | 必填 | 说明       |
1229| -------- | --------------- | ---- | --------- |
1230| type     | string          | 是   | 监听事件,固定为'torchStatusChange'。cameraManager对象获取成功后可监听。 |
1231| callback | AsyncCallback\<TorchStatusInfo> | 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
1232
1233**示例:**
1234
1235```ts
1236function unregisterTorchStatusChange(cameraManager: camera.CameraManager): void {
1237  cameraManager.off('torchStatusChange');
1238}
1239```
1240
1241## TorchMode<sup>11+</sup>
1242
1243枚举,手电筒模式。
1244
1245**系统能力:** SystemCapability.Multimedia.Camera.Core
1246
1247| 名称                          | 值   | 说明           |
1248| ---------------------------- | ---- | ------------- |
1249| OFF    | 0    | 常关模式。      |
1250| ON  | 1    | 常开模式。 |
1251| AUTO      | 2    | 自动模式。 |
1252
1253## TorchStatusInfo<sup>11+</sup>
1254
1255手电筒回调返回的接口实例,表示手电筒状态信息。
1256
1257**系统能力:** SystemCapability.Multimedia.Camera.Core
1258
1259| 名称              | 类型       | 只读 | 可选 | 说明        |
1260| ---------------- | ---------- | ---- | ---- | ----------- |
1261| isTorchAvailable | boolean    | 是   | 否   | 手电筒是否可用。|
1262| isTorchActive    | boolean    | 是   | 否   | 手电筒是否被激活。    |
1263| torchLevel       | number     | 是   | 否   | 手电筒亮度等级。取值范围为[0,1],越靠近1,亮度越大。    |
1264
1265## Size
1266
1267输出能力查询。
1268
1269**系统能力:** SystemCapability.Multimedia.Camera.Core
1270
1271| 名称   | 类型    | 只读 | 可选  | 说明         |
1272| ------ | ------ | ---- |-----| ------------ |
1273| height | number | 否   | 否   | 图像尺寸高(像素)。 |
1274| width  | number | 否   | 否   | 图像尺寸宽(像素)。 |
1275
1276## Point
1277
1278点坐标用于对焦、曝光配置。
1279
1280**系统能力:** SystemCapability.Multimedia.Camera.Core
1281
1282| 名称    | 类型   | 只读   | 可选   | 说明         |
1283| ------ | ------ | ------ | ------ | ------------ |
1284| x      | number | 否     | 否     | 点的x坐标。   |
1285| y      | number | 否     | 否     | 点的y坐标。   |
1286
1287## CameraFormat
1288
1289枚举,输出格式。
1290
1291**系统能力:** SystemCapability.Multimedia.Camera.Core
1292
1293| 名称                     | 值        | 说明         |
1294| ----------------------- | --------- | ------------ |
1295| CAMERA_FORMAT_RGBA_8888 | 3         | RGBA_888格式的图片。        |
1296| CAMERA_FORMAT_YUV_420_SP| 1003      | YUV_420_SP格式的图片。      |
1297| CAMERA_FORMAT_JPEG      | 2000      | JPEG格式的图片。            |
1298| CAMERA_FORMAT_YCBCR_P010<sup>11+</sup> |   2001    | YCBCR_P010格式的图片。      |
1299| CAMERA_FORMAT_YCRCB_P010<sup>11+</sup> |   2002    | YCRCB_P010格式的图片。      |
1300| CAMERA_FORMAT_HEIC<sup>13+</sup>       |   2003    | HEIF格式的图片。            |
1301
1302## VideoCodecType<sup>13+</sup>
1303
1304枚举,视频编码类型。
1305
1306**系统能力:** SystemCapability.Multimedia.Camera.Core
1307
1308| 名称   | 值    | 说明          |
1309|------|------|-------------|
1310| AVC  | 0    | 视频编码类型AVC。  |
1311| HEVC | 1 | 视频编码类型HEVC。 |
1312
1313## CameraInput
1314
1315相机设备输入对象。
1316
1317会话中[Session](#session11)使用的相机信息。
1318
1319### open
1320
1321open(callback: AsyncCallback\<void\>): void
1322
1323打开相机,通过注册回调函数获取状态。使用callback异步回调。
1324
1325**系统能力:** SystemCapability.Multimedia.Camera.Core
1326
1327**参数:**
1328
1329| 参数名     | 类型                  | 必填 | 说明                  |
1330| -------- | -------------------- | ---- | ------------------- |
1331| callback | AsyncCallback\<void\> | 是   | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode),比如预览流与录像输出流的分辨率的宽高比不一致,会返回7400201。 |
1332
1333**错误码:**
1334
1335以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
1336
1337| 错误码ID         | 错误信息        |
1338| --------------- | --------------- |
1339| 7400107                |  Can not use camera cause of conflict.               |
1340| 7400108                |  Camera disabled cause of security reason.                                  |
1341| 7400201                |  Camera service fatal error.                                  |
1342
1343**示例:**
1344
1345```ts
1346import { BusinessError } from '@kit.BasicServicesKit';
1347
1348function openCameraInput(cameraInput: camera.CameraInput): void {
1349  cameraInput.open((err: BusinessError) => {
1350    if (err) {
1351      console.error(`Failed to open the camera, error code: ${err.code}.`);
1352      return;
1353    }
1354    console.info('Callback returned with camera opened.');
1355  });
1356}
1357```
1358
1359### open
1360
1361open(): Promise\<void\>
1362
1363打开相机,通过Promise获取相机的状态。
1364
1365**系统能力:** SystemCapability.Multimedia.Camera.Core
1366
1367**返回值:**
1368
1369| 类型           | 说明                      |
1370| -------------- | ----------------------- |
1371| Promise\<void\> | 无返回结果的Promise对象。 |
1372
1373**错误码:**
1374
1375以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
1376
1377| 错误码ID   | 错误信息                                      |
1378|---------|-------------------------------------------|
1379| 7400102 | Operation not allowed.                    |
1380| 7400107 | Can not use camera cause of conflict.     |
1381| 7400108 | Camera disabled cause of security reason. |
1382| 7400201 | Camera service fatal error.               |
1383
1384**示例:**
1385
1386```ts
1387import { BusinessError } from '@kit.BasicServicesKit';
1388
1389function openCameraInput(cameraInput: camera.CameraInput): void {
1390  cameraInput.open().then(() => {
1391    console.info('Promise returned with camera opened.');
1392  }).catch((error: BusinessError) => {
1393    console.error(`Failed to open the camera, error code: ${error.code}.`);
1394  });
1395}
1396```
1397
1398### open<sup>12+</sup>
1399
1400open(isSecureEnabled: boolean): Promise\<bigint\>
1401
1402打开相机,获取安全相机的句柄。
1403
1404**系统能力:** SystemCapability.Multimedia.Camera.Core
1405
1406**参数:**
1407
1408| 参数名     | 类型                  | 必填 | 说明                                                                      |
1409| -------- | -------------------- | ---- |-------------------------------------------------------------------------|
1410| isSecureEnabled | boolean | 是   | 是否使能以安全的方式打开相机。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
1411
1412**返回值:**
1413
1414| 类型           | 说明                      |
1415| -------------- | ----------------------- |
1416| Promise\<bigint\> | 使用Promise的方式获取打开相机句柄。 |
1417
1418**错误码:**
1419
1420以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
1421
1422| 错误码ID         | 错误信息        |
1423| --------------- | --------------- |
1424| 7400107                |  Can not use camera cause of conflict.               |
1425| 7400108                |  Camera disabled cause of security reason.                                  |
1426| 7400201                |  Camera service fatal error.                                  |
1427
1428**示例:**
1429
1430```ts
1431import { BusinessError } from '@kit.BasicServicesKit';
1432
1433function openCameraInput(cameraInput: camera.CameraInput): void {
1434  cameraInput.open(true).then(() => {
1435    console.info('Promise returned with camera opened.');
1436  }).catch((error: BusinessError) => {
1437    console.error(`Failed to open the camera, error code: ${error.code}.`);
1438  });
1439}
1440```
1441
1442### close
1443
1444close(callback: AsyncCallback\<void\>\): void
1445
1446关闭相机,通过注册回调函数获取状态。使用callback异步回调。
1447
1448**系统能力:** SystemCapability.Multimedia.Camera.Core
1449
1450**参数:**
1451
1452| 参数名     | 类型                   | 必填 | 说明                  |
1453| -------- | -------------------- | ---- | -------------------- |
1454| callback | AsyncCallback\<void\> | 是   | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
1455
1456**错误码:**
1457
1458以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
1459
1460| 错误码ID         | 错误信息        |
1461| --------------- | --------------- |
1462| 7400201                |  Camera service fatal error.                                  |
1463
1464**示例:**
1465
1466```ts
1467import { BusinessError } from '@kit.BasicServicesKit';
1468
1469function closeCameraInput(cameraInput: camera.CameraInput): void {
1470  cameraInput.close((err: BusinessError) => {
1471    if (err) {
1472      console.error(`Failed to close the cameras, error code: ${err.code}.`);
1473      return;
1474    }
1475    console.info('Callback returned with camera closed.');
1476  });
1477}
1478```
1479
1480### close
1481
1482close(): Promise\<void\>
1483
1484关闭相机,通过Promise获取状态。
1485
1486**系统能力:** SystemCapability.Multimedia.Camera.Core
1487
1488**返回值:**
1489
1490| 类型           | 说明                      |
1491| -------------- | ----------------------- |
1492| Promise\<void\> | 无返回结果的Promise对象。 |
1493
1494**错误码:**
1495
1496以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
1497
1498| 错误码ID         | 错误信息        |
1499| --------------- | --------------- |
1500| 7400201                |  Camera service fatal error.                                  |
1501
1502**示例:**
1503
1504```ts
1505import { BusinessError } from '@kit.BasicServicesKit';
1506
1507function closeCameraInput(cameraInput: camera.CameraInput): void {
1508  cameraInput.close().then(() => {
1509    console.info('Promise returned with camera closed.');
1510  }).catch((error: BusinessError) => {
1511    console.error(`Failed to close the cameras, error code: ${error.code}.`);
1512  });
1513}
1514```
1515
1516### on('error')
1517
1518on(type: 'error', camera: CameraDevice, callback: ErrorCallback): void
1519
1520监听CameraInput的错误事件,通过注册回调函数获取结果。使用callback异步回调。
1521
1522> **说明:**
1523>
1524> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
1525
1526**系统能力:** SystemCapability.Multimedia.Camera.Core
1527
1528**参数:**
1529
1530| 参数名     | 类型                              | 必填 | 说明                                          |
1531| -------- | -------------------------------- | --- | ------------------------------------------- |
1532| type     | string                           | 是   | 监听事件,固定为'error',CameraInput对象创建成功可监听。相机设备出错情况下可触发该事件并返回结果,比如设备不可用或者冲突等返回对应错误信息。 |
1533| camera   | [CameraDevice](#cameradevice)    | 是   | CameraDevice对象。 |
1534| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | 是   | 回调函数,用于获取结果。返回错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。  |
1535
1536**示例:**
1537
1538```ts
1539import { BusinessError } from '@kit.BasicServicesKit';
1540
1541function callback(err: BusinessError): void {
1542  console.error(`Camera input error code: ${err.code}`);
1543}
1544
1545function registerCameraInputError(cameraInput: camera.CameraInput, camera: camera.CameraDevice): void {
1546  cameraInput.on('error', camera, callback);
1547}
1548```
1549
1550### off('error')
1551
1552off(type: 'error', camera: CameraDevice, callback?: ErrorCallback): void
1553
1554注销监听CameraInput的错误事件。
1555
1556**系统能力:** SystemCapability.Multimedia.Camera.Core
1557
1558**参数:**
1559
1560| 参数名     | 类型                              | 必填 | 说明                                          |
1561| -------- | -------------------------------- | --- | ------------------------------------------- |
1562| type     | string                           | 是   | 监听事件,固定为'error',CameraInput对象创建成功可监听。相机设备出错情况下可触发该事件并返回结果,比如设备不可用或者冲突等返回对应错误信息。 |
1563| camera   | [CameraDevice](#cameradevice)    | 是   | CameraDevice对象。 |
1564| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
1565
1566**示例:**
1567
1568```ts
1569function unregisterCameraInputError(cameraInput: camera.CameraInput, camera: camera.CameraDevice): void {
1570  cameraInput.off('error', camera);
1571}
1572```
1573
1574## CameraOutput
1575
1576会话中[Session](#session11)使用的输出信息,output的基类。
1577
1578### release
1579
1580release(callback: AsyncCallback\<void\>): void
1581
1582释放输出资源,通过注册回调函数获取结果。使用callback异步回调。
1583
1584**系统能力:** SystemCapability.Multimedia.Camera.Core
1585
1586**参数:**
1587
1588| 参数名      | 类型                  | 必填 | 说明                 |
1589| -------- | -------------------- | ---- | ------------------- |
1590| callback | AsyncCallback\<void\> | 是   | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
1591
1592**错误码:**
1593
1594以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
1595
1596| 错误码ID         | 错误信息        |
1597| --------------- | --------------- |
1598| 7400201                |  Camera service fatal error.                           |
1599
1600**示例:**
1601
1602```ts
1603import { BusinessError } from '@kit.BasicServicesKit';
1604
1605function releasePreviewOutput(previewOutput: camera.PreviewOutput): void {
1606  previewOutput.release((err: BusinessError) => {
1607    if (err) {
1608      console.error(`Failed to release the Preview output instance ${err.code}`);
1609      return;
1610    }
1611    console.info('Callback invoked to indicate that the preview output instance is released successfully.');
1612  });
1613}
1614
1615function releaseVideoOutput(videoOutput: camera.VideoOutput): void {
1616  videoOutput.release((err: BusinessError) => {
1617    if (err) {
1618      console.error(`Failed to release the video output instance ${err.code}`);
1619      return;
1620    }
1621    console.info('Callback invoked to indicate that the video output instance is released successfully.');
1622  });
1623}
1624```
1625
1626### release
1627
1628release(): Promise\<void\>
1629
1630释放输出资源,通过Promise获取结果。
1631
1632**系统能力:** SystemCapability.Multimedia.Camera.Core
1633
1634**返回值:**
1635
1636| 类型            | 说明                     |
1637| -------------- | ----------------------- |
1638| Promise\<void\> | 无返回结果的Promise对象。 |
1639
1640**错误码:**
1641
1642以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
1643
1644| 错误码ID         | 错误信息        |
1645| --------------- | --------------- |
1646| 7400201                |  Camera service fatal error.                           |
1647
1648**示例:**
1649
1650```ts
1651import { BusinessError } from '@kit.BasicServicesKit';
1652
1653function releasePreviewOutput(previewOutput: camera.PreviewOutput): void {
1654  previewOutput.release().then(() => {
1655    console.info('Promise returned to indicate that the preview output instance is released successfully.');
1656  }).catch((error: BusinessError) => {
1657    console.error(`Failed to preview output release, error code: ${error.code}`);
1658  });
1659}
1660
1661function releaseVideoOutput(videoOutput: camera.VideoOutput): void {
1662  videoOutput.release().then(() => {
1663    console.info('Promise returned to indicate that the video output instance is released successfully.');
1664  }).catch((error: BusinessError) => {
1665    console.error(`Failed to video output release, error code: ${error.code}`);
1666  });
1667}
1668```
1669
1670## PreviewOutput
1671
1672预览输出类。继承[CameraOutput](#cameraoutput)。
1673
1674### start<sup>(deprecated)</sup>
1675
1676start(callback: AsyncCallback\<void\>): void
1677
1678开始输出预览流,通过注册回调函数获取结果。使用callback异步回调。
1679
1680> **说明:**
1681>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.start](#start11)替代。
1682
1683**系统能力:** SystemCapability.Multimedia.Camera.Core
1684
1685**参数:**
1686
1687| 参数名      | 类型                  | 必填 | 说明                 |
1688| -------- | -------------------- | ---- | -------------------- |
1689| callback | AsyncCallback\<void\> | 是   | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
1690
1691**错误码:**
1692
1693以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
1694
1695| 错误码ID         | 错误信息        |
1696| --------------- | --------------- |
1697| 7400103                |  Session not config.                                   |
1698
1699**示例:**
1700
1701```ts
1702import { BusinessError } from '@kit.BasicServicesKit';
1703
1704function startPreviewOutput(previewOutput: camera.PreviewOutput): void {
1705  previewOutput.start((err: BusinessError) => {
1706    if (err) {
1707      console.error(`Failed to start the preview output, error code: ${err.code}.`);
1708      return;
1709    }
1710    console.info('Callback returned with preview output started.');
1711  });
1712}
1713```
1714
1715### start<sup>(deprecated)</sup>
1716
1717start(): Promise\<void\>
1718
1719开始输出预览流,通过Promise获取结果。
1720
1721> **说明:**
1722>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.start](#start11-1)替代。
1723
1724**系统能力:** SystemCapability.Multimedia.Camera.Core
1725
1726**返回值:**
1727
1728| 类型            | 说明                |
1729| -------------- |-------------------|
1730| Promise\<void\> | 无返回结果的Promise对象。  |
1731
1732**错误码:**
1733
1734以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
1735
1736| 错误码ID         | 错误信息        |
1737| --------------- | --------------- |
1738| 7400103                |  Session not config.                                   |
1739
1740**示例:**
1741
1742```ts
1743import { BusinessError } from '@kit.BasicServicesKit';
1744
1745function startPreviewOutput(previewOutput: camera.PreviewOutput): void {
1746  previewOutput.start().then(() => {
1747    console.info('Promise returned with preview output started.');
1748  }).catch((error: BusinessError) => {
1749    console.error(`Failed to preview output start, error code: ${error.code}.`);
1750  });
1751}
1752```
1753
1754### stop<sup>(deprecated)</sup>
1755
1756stop(callback: AsyncCallback\<void\>): void
1757
1758停止输出预览流,通过注册回调函数获取结果。使用callback异步回调。
1759
1760> **说明:**
1761>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.stop](#stop11)替代。
1762
1763**系统能力:** SystemCapability.Multimedia.Camera.Core
1764
1765**参数:**
1766
1767| 参数名      | 类型                  | 必填 | 说明                 |
1768| -------- | -------------------- | ---- | -------------------- |
1769| callback | AsyncCallback\<void\> | 是   | 回调函数,用于获取结果。 |
1770
1771**示例:**
1772
1773```ts
1774import { BusinessError } from '@kit.BasicServicesKit';
1775
1776function stopPreviewOutput(previewOutput: camera.PreviewOutput): void {
1777  previewOutput.stop((err: BusinessError) => {
1778    if (err) {
1779      console.error(`Failed to stop the preview output, error code: ${err.code}.`);
1780      return;
1781    }
1782    console.info('Returned with preview output stopped.');
1783  })
1784}
1785```
1786
1787### stop<sup>(deprecated)</sup>
1788
1789stop(): Promise\<void\>
1790
1791停止输出预览流,通过Promise获取结果。
1792
1793> **说明:**
1794>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.stop](#stop11-1)替代。
1795
1796**系统能力:** SystemCapability.Multimedia.Camera.Core
1797
1798**返回值:**
1799
1800| 类型            | 说明                     |
1801| -------------- | ------------------------ |
1802| Promise\<void\> | 无返回结果的Promise对象。 |
1803
1804**示例:**
1805
1806```ts
1807import { BusinessError } from '@kit.BasicServicesKit';
1808
1809function stopPreviewOutput(previewOutput: camera.PreviewOutput): void {
1810  previewOutput.stop().then(() => {
1811    console.info('Callback returned with preview output stopped.');
1812  }).catch((error: BusinessError) => {
1813    console.error(`Failed to preview output stop, error code: ${error.code}.`);
1814  });
1815}
1816```
1817
1818### on('frameStart')
1819
1820on(type: 'frameStart', callback: AsyncCallback\<void\>): void
1821
1822监听预览帧启动,通过注册回调函数获取结果。使用callback异步回调。
1823
1824> **说明:**
1825>
1826> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
1827
1828**系统能力:** SystemCapability.Multimedia.Camera.Core
1829
1830**参数:**
1831
1832| 参数名      | 类型                  | 必填 | 说明                                     |
1833| -------- | -------------------- | ---- | --------------------------------------- |
1834| type     | string               | 是   | 监听事件,固定为'frameStart',previewOutput创建成功可监听。底层第一次开始曝光时触发该事件并返回。 |
1835| callback | AsyncCallback\<void\> | 是   | 回调函数,用于获取结果。只要有该事件返回就证明预览开始。                    |
1836
1837**示例:**
1838
1839```ts
1840import { BusinessError } from '@kit.BasicServicesKit';
1841
1842function callback(err: BusinessError): void {
1843  if (err !== undefined && err.code !== 0) {
1844    console.error(`Callback Error, errorCode: ${err.code}`);
1845    return;
1846  }
1847  console.info('Preview frame started');
1848}
1849
1850function registerPreviewOutputFrameStart(previewOutput: camera.PreviewOutput): void {
1851  previewOutput.on('frameStart', callback);
1852}
1853```
1854
1855### off('frameStart')
1856
1857off(type: 'frameStart', callback?: AsyncCallback\<void\>): void
1858
1859注销监听预览帧启动。
1860
1861**系统能力:** SystemCapability.Multimedia.Camera.Core
1862
1863**参数:**
1864
1865| 参数名      | 类型                  | 必填 | 说明                                     |
1866| -------- | -------------------- | ---- | --------------------------------------- |
1867| type     | string               | 是   | 监听事件,固定为'frameStart',previewOutput创建成功可监听。 |
1868| callback | AsyncCallback\<void\> | 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
1869
1870**示例:**
1871
1872```ts
1873function unregisterPreviewOutputFrameStart(previewOutput: camera.PreviewOutput): void {
1874  previewOutput.off('frameStart');
1875}
1876```
1877
1878### on('frameEnd')
1879
1880on(type: 'frameEnd', callback: AsyncCallback\<void\>): void
1881
1882监听预览帧结束,通过注册回调函数获取结果。使用callback异步回调。
1883
1884> **说明:**
1885>
1886> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
1887
1888**系统能力:** SystemCapability.Multimedia.Camera.Core
1889
1890**参数:**
1891
1892| 参数名      | 类型                  | 必填 | 说明                                  |
1893| -------- | -------------------- | ---- | ------------------------------------- |
1894| type     | string               | 是   | 监听事件,固定为'frameEnd',previewOutput创建成功可监听。预览完全结束最后一帧时触发该事件并返回。 |
1895| callback | AsyncCallback\<void\> | 是   | 回调函数,用于获取结果。只要有该事件返回就证明预览结束。                |
1896
1897**示例:**
1898
1899```ts
1900import { BusinessError } from '@kit.BasicServicesKit';
1901
1902function callback(err: BusinessError): void {
1903  if (err !== undefined && err.code !== 0) {
1904    console.error(`Callback Error, errorCode: ${err.code}`);
1905    return;
1906  }
1907  console.info('Preview frame ended');
1908}
1909
1910function registerPreviewOutputFrameEnd(previewOutput: camera.PreviewOutput): void {
1911  previewOutput.on('frameEnd', callback);
1912}
1913```
1914
1915### off('frameEnd')
1916
1917off(type: 'frameEnd', callback?: AsyncCallback\<void\>): void
1918
1919注销监听预览帧结束。
1920
1921**系统能力:** SystemCapability.Multimedia.Camera.Core
1922
1923**参数:**
1924
1925| 参数名      | 类型                  | 必填 | 说明                                  |
1926| -------- | -------------------- | ---- | ------------------------------------- |
1927| type     | string               | 是   | 监听事件,固定为'frameEnd',previewOutput创建成功可监听。 |
1928| callback | AsyncCallback\<void\> | 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
1929
1930**示例:**
1931
1932```ts
1933function unregisterPreviewOutputFrameEnd(previewOutput: camera.PreviewOutput): void {
1934  previewOutput.off('frameEnd');
1935}
1936```
1937
1938### on('error')
1939
1940on(type: 'error', callback: ErrorCallback): void
1941
1942监听预览输出的错误事件,通过注册回调函数获取结果。使用callback异步回调。
1943
1944> **说明:**
1945>
1946> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
1947
1948**系统能力:** SystemCapability.Multimedia.Camera.Core
1949
1950**参数:**
1951
1952| 参数名     | 类型         | 必填 | 说明                       |
1953| -------- | --------------| ---- | ------------------------ |
1954| type     | string        | 是   | 监听事件,固定为'error',previewOutput创建成功可监听。预览接口使用错误时触发该事件,比如调用[Session.start](#start11-1),[CameraOutput.release](#release-1)等接口发生错误时返回对应错误信息。 |
1955| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | 是   | 回调函数,用于获取错误信息。返回错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。  |
1956
1957**示例:**
1958
1959```ts
1960import { BusinessError } from '@kit.BasicServicesKit';
1961
1962function callback(previewOutputError: BusinessError): void {
1963  console.error(`Preview output error code: ${previewOutputError.code}`);
1964}
1965
1966function registerPreviewOutputError(previewOutput: camera.PreviewOutput): void {
1967  previewOutput.on('error', callback)
1968}
1969```
1970
1971### off('error')
1972
1973off(type: 'error', callback?: ErrorCallback): void
1974
1975注销监听预览输出的错误事件。
1976
1977**系统能力:** SystemCapability.Multimedia.Camera.Core
1978
1979**参数:**
1980
1981| 参数名     | 类型         | 必填 | 说明                       |
1982| -------- | --------------| ---- | ------------------------ |
1983| type     | string        | 是   | 监听事件,固定为'error',previewOutput创建成功可监听。 |
1984| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
1985
1986**示例:**
1987
1988```ts
1989function unregisterPreviewOutputError(previewOutput: camera.PreviewOutput): void {
1990  previewOutput.off('error');
1991}
1992```
1993
1994### getSupportedFrameRates<sup>12+</sup>
1995
1996 getSupportedFrameRates(): Array\<FrameRateRange\>
1997
1998查询支持的帧率范围。
1999
2000**系统能力:** SystemCapability.Multimedia.Camera.Core
2001
2002**返回值:**
2003|      类型      |     说明     |
2004| -------------  | ------------ |
2005| Array<[FrameRateRange](#frameraterange)> | 支持的帧率范围列表 |
2006
2007**示例:**
2008
2009```ts
2010function getSupportedFrameRates(previewOutput: camera.PreviewOutput): Array<camera.FrameRateRange> {
2011  let supportedFrameRatesArray: Array<camera.FrameRateRange> = previewOutput.getSupportedFrameRates();
2012  return supportedFrameRatesArray;
2013}
2014```
2015
2016### setFrameRate<sup>12+</sup>
2017
2018setFrameRate(minFps: number, maxFps: number): void
2019
2020设置预览流帧率范围,设置的范围必须在支持的帧率范围内。
2021进行设置前,可通过[getSupportedFrameRates](#getsupportedframerates12)查询支持的帧率范围。
2022
2023> **说明:**
2024> 仅在[PhotoSession](#photosession11)或[VideoSession](#videosession11)模式下支持。
2025
2026**系统能力:** SystemCapability.Multimedia.Camera.Core
2027
2028**参数:**
2029
2030| 参数名     | 类型         | 必填 | 说明                       |
2031| -------- | --------------| ---- | ------------------------ |
2032| minFps   | number        | 是   | 最小帧率。 |
2033| maxFps   | number        | 是   | 最大帧率,当传入的最小值大于最大值时,传参异常,接口不生效。|
2034
2035**错误码:**
2036
2037以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
2038
2039| 错误码ID        | 错误信息        |
2040| --------------- | --------------- |
2041| 7400101                |  Parameter missing or parameter type incorrect.        |
2042| 7400110                |  Unresolved conflicts with current configurations.     |
2043
2044**示例:**
2045
2046```ts
2047function setFrameRateRange(previewOutput: camera.PreviewOutput, frameRateRange: Array<number>): void {
2048  previewOutput.setFrameRate(frameRateRange[0], frameRateRange[1]);
2049}
2050```
2051
2052### getActiveFrameRate<sup>12+</sup>
2053
2054getActiveFrameRate(): FrameRateRange
2055
2056获取已设置的帧率范围。
2057
2058使用[setFrameRate](#setframerate12)对预览流设置过帧率后可查询。
2059
2060**系统能力:** SystemCapability.Multimedia.Camera.Core
2061
2062**返回值:**
2063
2064|      类型      |     说明     |
2065| -------------  | ------------ |
2066| [FrameRateRange](#frameraterange) | 帧率范围 |
2067
2068**示例:**
2069
2070```ts
2071function getActiveFrameRate(previewOutput: camera.PreviewOutput): camera.FrameRateRange {
2072  let activeFrameRate: camera.FrameRateRange = previewOutput.getActiveFrameRate();
2073  return activeFrameRate;
2074}
2075```
2076
2077### getActiveProfile<sup>12+</sup>
2078
2079getActiveProfile(): Profile
2080
2081获取当前生效的配置信息。
2082
2083**系统能力:** SystemCapability.Multimedia.Camera.Core
2084
2085**返回值:**
2086
2087|      类型      | 说明        |
2088| -------------  |-----------|
2089| [Profile](#profile) | 当前生效的配置信息 |
2090
2091**错误码:**
2092
2093以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
2094
2095| 错误码ID   | 错误信息                         |
2096|---------|------------------------------|
2097| 7400201 | Camera service fatal error.  |
2098
2099**示例:**
2100
2101```ts
2102function testGetActiveProfile(previewOutput: camera.PreviewOutput): camera.Profile | undefined {
2103  let activeProfile: camera.Profile | undefined = undefined;
2104  try {
2105    activeProfile = previewOutput.getActiveProfile();
2106  } catch (error) {
2107    // 失败返回错误码error.code并处理。
2108    let err = error as BusinessError;
2109    console.error(`The previewOutput.getActiveProfile call failed. error code: ${err.code}`);
2110  }
2111  return activeProfile;
2112}
2113```
2114
2115### getPreviewRotation<sup>12+</sup>
2116
2117getPreviewRotation(displayRotation: number): ImageRotation
2118
2119获取预览旋转角度。
2120
2121- 设备自然方向:设备默认使用方向,手机为竖屏(充电口向下)。
2122- 相机镜头角度:值等于相机图像顺时针旋转到设备自然方向的角度,手机后置相机传感器是横屏安装的,所以需要顺时针旋转90度到设备自然方向。
2123- 屏幕显示方向:需要屏幕显示的图片左上角为第一个像素点为坐标原点。锁屏时与自然方向一致。
2124
2125**系统能力:** SystemCapability.Multimedia.Camera.Core
2126
2127**参数:**
2128
2129| 参数名     | 类型         | 必填 | 说明                       |
2130| -------- | --------------| ---- | ------------------------ |
2131| displayRotation | number  | 是   | 显示设备的屏幕旋转角度,通过[display.getDefaultDisplaySync](../apis-arkui/js-apis-display.md#displaygetdefaultdisplaysync9)获得。 |
2132
2133**返回值:**
2134
2135|      类型      | 说明        |
2136| -------------  |-----------|
2137| [ImageRotation](#imagerotation) | 获取预览旋转角度。 |
2138
2139**错误码:**
2140
2141以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
2142
2143| 错误码ID   | 错误信息                         |
2144|---------|------------------------------|
2145| 7400101 | Parameter missing or parameter type incorrect.  |
2146| 7400201 | Camera service fatal error.  |
2147
2148**示例:**
2149
2150```ts
2151function testGetPreviewRotation(previewOutput: camera.PreviewOutput, imageRotation : camera.ImageRotation): camera.ImageRotation {
2152  let previewRotation: camera.ImageRotation = camera.ImageRotation.ROTATION_0;
2153  try {
2154    previewRotation = previewOutput.getPreviewRotation(imageRotation);
2155    console.log(`Preview rotation is: ${previewRotation}`);
2156  } catch (error) {
2157    // 失败返回错误码error.code并处理。
2158    let err = error as BusinessError;
2159    console.error(`The previewOutput.getPreviewRotation call failed. error code: ${err.code}`);
2160  }
2161  return previewRotation;
2162}
2163```
2164### setPreviewRotation<sup>12+</sup>
2165setPreviewRotation(previewRotation: ImageRotation, isDisplayLocked?: boolean): void
2166
2167设置预览旋转角度。
2168
2169**系统能力:** SystemCapability.Multimedia.Camera.Core
2170
2171**参数:**
2172
2173| 参数名     | 类型         | 必填 | 说明                       |
2174| -------- | --------------| ---- | ------------------------ |
2175| previewRotation | [ImageRotation](#imagerotation)  | 是   | 预览旋转角度 |
2176| isDisplayLocked | boolean  | 否   | 是否旋转锁定 |
2177
2178**错误码:**
2179
2180以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
2181
2182| 错误码ID   | 错误信息                         |
2183|---------|------------------------------|
2184| 7400101 | Parameter missing or parameter type incorrect.  |
2185| 7400201 | Camera service fatal error.  |
2186
2187**示例:**
2188
2189```ts
2190function testSetPreviewRotation(previewOutput: camera.PreviewOutput, previewRotation : camera.ImageRotation, isDisplayLocked: boolean): void {
2191  try {
2192    previewOutput.setPreviewRotation(previewRotation, isDisplayLocked);
2193  } catch (error) {
2194    // 失败返回错误码error.code并处理。
2195    let err = error as BusinessError;
2196    console.error(`The previewOutput.setPreviewRotation call failed. error code: ${err.code}`);
2197  }
2198  return;
2199}
2200```
2201## ImageRotation
2202
2203枚举,图片旋转角度。
2204
2205**系统能力:** SystemCapability.Multimedia.Camera.Core
2206
2207| 名称          | 值   | 说明           |
2208| ------------ | ---- | ------------- |
2209| ROTATION_0   | 0    | 图片旋转0度。   |
2210| ROTATION_90  | 90   | 图片旋转90度。  |
2211| ROTATION_180 | 180  | 图片旋转180度。 |
2212| ROTATION_270 | 270  | 图片旋转270度。 |
2213
2214## Location
2215
2216图片地理位置信息。
2217
2218**系统能力:** SystemCapability.Multimedia.Camera.Core
2219
2220| 名称          | 类型   | 只读 | 可选  |说明         |
2221| ------------ | ------ | ---- |-----|------------ |
2222| latitude     | number |  否  | 否   |纬度(度)。    |
2223| longitude    | number |  否  | 否   |经度(度)。    |
2224| altitude     | number |  否  | 否   |海拔(米)。    |
2225
2226## QualityLevel
2227
2228枚举,图片质量。
2229
2230**系统能力:** SystemCapability.Multimedia.Camera.Core
2231
2232| 名称                  | 值   | 说明         |
2233| -------------------- | ---- | ------------ |
2234| QUALITY_LEVEL_HIGH   | 0    | 图片质量高。   |
2235| QUALITY_LEVEL_MEDIUM | 1    | 图片质量中等。 |
2236| QUALITY_LEVEL_LOW    | 2    | 图片质量差。   |
2237
2238
2239## PhotoCaptureSetting
2240
2241拍摄照片的设置。
2242
2243**系统能力:** SystemCapability.Multimedia.Camera.Core
2244
2245| 名称      | 类型                            | 只读 | 可选 | 说明                                                                   |
2246| -------- | ------------------------------- | ---- | ---- |----------------------------------------------------------------------|
2247| quality  | [QualityLevel](#qualitylevel)   | 否   | 是   | 图片质量(默认低)。                                                           |
2248| rotation | [ImageRotation](#imagerotation) | 否   | 是   | 图片旋转角度(默认0度,顺时针旋转)。                                                  |
2249| location | [Location](#location)           | 否   | 是   | 图片地理位置信息(默认以设备硬件信息为准)。                                               |
2250| mirror   | boolean                         | 否   | 是   | 镜像使能开关(默认关)。使用之前需要使用[isMirrorSupported](#ismirrorsupported)进行判断是否支持。 |
2251
2252## Photo<sup>11+</sup>
2253
2254全质量图对象。
2255
2256### 属性
2257
2258**系统能力:** SystemCapability.Multimedia.Camera.Core
2259
2260| 名称   | 类型                            |     必填     | 说明       |
2261| ------ | ----------------------------- | -------------- | ---------- |
2262| main<sup>11+</sup> | [image.Image](../apis-image-kit/js-apis-image.md#image9) |        是       | 全质量图Image。 |
2263
2264### release<sup>11+</sup>
2265
2266release(): Promise\<void\>
2267
2268释放输出资源,通过Promise获取结果。
2269
2270**系统能力:** SystemCapability.Multimedia.Camera.Core
2271
2272**返回值:**
2273
2274| 类型            | 说明                     |
2275| -------------- | ----------------------- |
2276| Promise\<void\> | 无返回结果的Promise对象。 |
2277
2278**示例:**
2279
2280```ts
2281async function releasePhoto(photo: camera.Photo): Promise<void> {
2282  await photo.release();
2283}
2284```
2285
2286## PhotoOutput
2287
2288拍照会话中使用的输出信息,继承[CameraOutput](#cameraoutput)。
2289
2290### capture
2291
2292capture(callback: AsyncCallback\<void\>): void
2293
2294以默认设置触发一次拍照,通过注册回调函数获取结果。使用callback异步回调。
2295
2296**系统能力:** SystemCapability.Multimedia.Camera.Core
2297
2298**参数:**
2299
2300| 参数名      | 类型                  | 必填 | 说明                 |
2301| -------- | -------------------- | ---- | ------------------- |
2302| callback | AsyncCallback\<void\> | 是   | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
2303
2304**错误码:**
2305
2306以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
2307
2308| 错误码ID         | 错误信息        |
2309| --------------- | --------------- |
2310| 7400104                |  Session not running.                                  |
2311| 7400201                |  Camera service fatal error.                           |
2312
2313**示例:**
2314
2315```ts
2316import { BusinessError } from '@kit.BasicServicesKit';
2317
2318function capture(photoOutput: camera.PhotoOutput): void {
2319  photoOutput.capture((err: BusinessError) => {
2320    if (err) {
2321      console.error(`Failed to capture the photo, error code: ${err.code}.`);
2322      return;
2323    }
2324    console.info('Callback invoked to indicate the photo capture request success.');
2325  });
2326}
2327```
2328
2329### capture
2330
2331capture(): Promise\<void\>
2332
2333以默认设置触发一次拍照,通过Promise获取结果。
2334
2335**系统能力:** SystemCapability.Multimedia.Camera.Core
2336
2337**返回值:**
2338
2339| 类型            | 说明                     |
2340| -------------- | ------------------------ |
2341| Promise\<void\> | 无返回结果的Promise对象。 |
2342
2343**错误码:**
2344
2345以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
2346
2347| 错误码ID         | 错误信息        |
2348| --------------- | --------------- |
2349| 7400104                |  Session not running.                                  |
2350| 7400201                |  Camera service fatal error.                           |
2351
2352**示例:**
2353
2354```ts
2355import { BusinessError } from '@kit.BasicServicesKit';
2356
2357function capture(photoOutput: camera.PhotoOutput): void {
2358  photoOutput.capture().then(() => {
2359    console.info('Promise returned to indicate that photo capture request success.');
2360  }).catch((error: BusinessError) => {
2361    console.error(`Failed to photo output capture, error code: ${error.code}.`);
2362  });
2363}
2364```
2365
2366### capture
2367
2368capture(setting: PhotoCaptureSetting, callback: AsyncCallback\<void\>): void
2369
2370以指定参数触发一次拍照,通过注册回调函数获取结果。使用callback异步回调。
2371
2372**系统能力:** SystemCapability.Multimedia.Camera.Core
2373
2374**参数:**
2375
2376| 参数名      | 类型                                         | 必填 | 说明                  |
2377| -------- | ------------------------------------------- | ---- | -------------------- |
2378| setting  | [PhotoCaptureSetting](#photocapturesetting) | 是   | 拍照设置。             |
2379| callback | AsyncCallback\<void\>                        | 是   | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。  |
2380
2381**错误码:**
2382
2383以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
2384
2385| 错误码ID         | 错误信息        |
2386| --------------- | --------------- |
2387| 7400101                |  Parameter missing or parameter type incorrect.        |
2388| 7400104                |  Session not running.                                  |
2389| 7400201                |  Camera service fatal error.                           |
2390
2391**示例:**
2392
2393```ts
2394import { BusinessError } from '@kit.BasicServicesKit';
2395
2396function capture(photoOutput: camera.PhotoOutput): void {
2397  let captureLocation: camera.Location = {
2398    latitude: 0,
2399    longitude: 0,
2400    altitude: 0
2401  }
2402  let settings: camera.PhotoCaptureSetting = {
2403    quality: camera.QualityLevel.QUALITY_LEVEL_LOW,
2404    rotation: camera.ImageRotation.ROTATION_0,
2405    location: captureLocation,
2406    mirror: false
2407  }
2408  photoOutput.capture(settings, (err: BusinessError) => {
2409    if (err) {
2410      console.error(`Failed to capture the photo, error code: ${err.code}.`);
2411      return;
2412    }
2413    console.info('Callback invoked to indicate the photo capture request success.');
2414  });
2415}
2416```
2417
2418### capture
2419
2420capture(setting: PhotoCaptureSetting): Promise\<void\>
2421
2422以指定参数触发一次拍照,通过Promise获取结果。
2423
2424**系统能力:** SystemCapability.Multimedia.Camera.Core
2425
2426**参数:**
2427
2428| 参数名     | 类型                                         | 必填 | 说明      |
2429| ------- | ------------------------------------------- | ---- | -------- |
2430| setting | [PhotoCaptureSetting](#photocapturesetting) | 是   | 拍照设置,传入undefined类型数据按默认无参处理。 |
2431
2432**返回值:**
2433
2434| 类型            | 说明                     |
2435| -------------- | ------------------------ |
2436| Promise\<void\> | 无返回结果的Promise对象。 |
2437
2438**错误码:**
2439
2440以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
2441
2442| 错误码ID         | 错误信息        |
2443| --------------- | --------------- |
2444| 7400101                |  Parameter missing or parameter type incorrect.        |
2445| 7400104                |  Session not running.                                  |
2446| 7400201                |  Camera service fatal error.                           |
2447
2448**示例:**
2449
2450```ts
2451import { BusinessError } from '@kit.BasicServicesKit';
2452
2453function capture(photoOutput: camera.PhotoOutput): void {
2454  let captureLocation: camera.Location = {
2455    latitude: 0,
2456    longitude: 0,
2457    altitude: 0
2458  }
2459  let settings: camera.PhotoCaptureSetting = {
2460    quality: camera.QualityLevel.QUALITY_LEVEL_LOW,
2461    rotation: camera.ImageRotation.ROTATION_0,
2462    location: captureLocation,
2463    mirror: false
2464  }
2465  photoOutput.capture(settings).then(() => {
2466    console.info('Promise returned to indicate that photo capture request success.');
2467  }).catch((error: BusinessError) => {
2468    console.error(`Failed to photo output capture, error code: ${error.code}.`);
2469  });
2470}
2471```
2472
2473### on('photoAvailable')<sup>11+</sup>
2474
2475on(type: 'photoAvailable', callback: AsyncCallback\<Photo\>): void
2476
2477注册监听全质量图上报。使用callback异步回调。
2478
2479> **说明:**
2480>
2481> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
2482
2483**系统能力:** SystemCapability.Multimedia.Camera.Core
2484
2485**参数:**
2486
2487| 参数名     | 类型      | 必填 | 说明                                  |
2488| -------- | ---------- | --- | ------------------------------------ |
2489| type     | string     | 是   | 监听事件,固定为'photoAvailable',photoOutput创建成功后可监听。 |
2490| callback | AsyncCallback\<[Photo](#photo11)\> | 是   | 回调函数,用于监听全质量图上报。 |
2491
2492**示例:**
2493
2494```ts
2495import { BusinessError } from '@kit.BasicServicesKit';
2496import { image } from '@kit.ImageKit';
2497
2498function callback(err: BusinessError, photo: camera.Photo): void {
2499  if (err !== undefined && err.code !== 0) {
2500    console.error(`Callback Error, errorCode: ${err.code}`);
2501    return;
2502  }
2503  let mainImage: image.Image = photo.main;
2504}
2505
2506function registerPhotoOutputPhotoAvailable(photoOutput: camera.PhotoOutput): void {
2507  photoOutput.on('photoAvailable', callback);
2508}
2509```
2510
2511### off('photoAvailable')<sup>11+</sup>
2512
2513off(type: 'photoAvailable', callback?: AsyncCallback\<Photo\>): void
2514
2515注销监听全质量图上报。
2516
2517**系统能力:** SystemCapability.Multimedia.Camera.Core
2518
2519**参数:**
2520
2521| 参数名      | 类型                    | 必填 | 说明                                       |
2522| -------- | ---------------------- | ---- | ------------------------------------------ |
2523| type     | string                 | 是   | 监听事件,固定为'photoAvailable',photoOutput创建成功后可监听。 |
2524| callback | AsyncCallback\<[Photo](#photo11)\> | 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
2525
2526**示例:**
2527
2528```ts
2529import { BusinessError } from '@kit.BasicServicesKit';
2530import { image } from '@kit.ImageKit';
2531
2532function callback(err: BusinessError, photo: camera.Photo): void {
2533  if (err !== undefined && err.code !== 0) {
2534    console.error(`Callback Error, errorCode: ${err.code}`);
2535    return;
2536  }
2537  let mainImage: image.Image = photo.main;
2538}
2539
2540function unRegisterPhotoOutputPhotoAvailable(photoOutput: camera.PhotoOutput): void {
2541  photoOutput.off('photoAvailable', callback);
2542}
2543```
2544
2545### on('captureStartWithInfo')<sup>11+</sup>
2546
2547on(type: 'captureStartWithInfo', callback: AsyncCallback\<CaptureStartInfo\>): void
2548
2549监听拍照开始,通过注册回调函数获取[CaptureStartInfo](#capturestartinfo11)。使用callback异步回调。
2550
2551> **说明:**
2552>
2553> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
2554
2555**系统能力:** SystemCapability.Multimedia.Camera.Core
2556
2557**参数:**
2558
2559| 参数名     | 类型      | 必填 | 说明                                  |
2560| -------- | ---------- | --- | ------------------------------------ |
2561| type     | string     | 是   | 监听事件,固定为'captureStartWithInfo',photoOutput创建成功后可监听。 |
2562| callback | AsyncCallback\<[CaptureStartInfo](#capturestartinfo11)\> | 是   | 使用callback的方式获取Capture ID。|
2563
2564**示例:**
2565
2566```ts
2567import { BusinessError } from '@kit.BasicServicesKit';
2568
2569function callback(err: BusinessError, captureStartInfo: camera.CaptureStartInfo): void {
2570  if (err !== undefined && err.code !== 0) {
2571    console.error(`Callback Error, errorCode: ${err.code}`);
2572    return;
2573  }
2574  console.info(`photo capture started, captureStartInfo : ${captureStartInfo}`);
2575}
2576
2577function registerCaptureStartWithInfo(photoOutput: camera.PhotoOutput): void {
2578  photoOutput.on('captureStartWithInfo', callback);
2579}
2580```
2581
2582### off('captureStartWithInfo')<sup>11+</sup>
2583
2584off(type: 'captureStartWithInfo', callback?: AsyncCallback\<CaptureStartInfo\>): void
2585
2586注销监听拍照。
2587
2588**系统能力:** SystemCapability.Multimedia.Camera.Core
2589
2590**参数:**
2591
2592| 参数名      | 类型                    | 必填 | 说明                                       |
2593| -------- | ---------------------- | ---- | ------------------------------------------ |
2594| type     | string                 | 是   | 监听事件,固定为'captureStartWithInfo',photoOutput创建成功后可监听。 |
2595| callback | AsyncCallback\<[CaptureStartInfo](#capturestartinfo11)\> | 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
2596
2597**示例:**
2598
2599```ts
2600import { BusinessError } from '@kit.BasicServicesKit';
2601
2602function unRegisterCaptureStartWithInfo(photoOutput: camera.PhotoOutput): void {
2603  photoOutput.off('captureStartWithInfo');
2604}
2605```
2606
2607### isMovingPhotoSupported<sup>12+</sup>
2608
2609isMovingPhotoSupported(): boolean
2610
2611查询是否支持动态照片拍摄。
2612
2613**系统能力:** SystemCapability.Multimedia.Camera.Core
2614
2615**返回值:**
2616
2617| 类型            | 说明                     |
2618| -------------- | ----------------------- |
2619| boolean | 返回是否支持动态照片拍照,true表示支持,false表示不支持。 |
2620
2621**错误码:**
2622
2623以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
2624
2625| 错误码ID       | 错误信息       |
2626| -------------- | --------------- |
2627| 7400201 |  Camera service fatal error. |
2628
2629**示例:**
2630
2631```ts
2632import { BusinessError } from '@kit.BasicServicesKit';
2633
2634function isMovingPhotoSupported(photoOutput: camera.PhotoOutput): boolean {
2635  let isSupported: boolean = false;
2636  try {
2637    isSupported = photoOutput.isMovingPhotoSupported();
2638  } catch (error) {
2639    // 失败返回错误码error.code并处理。
2640    let err = error as BusinessError;
2641    console.error(`The isMovingPhotoSupported call failed. error code: ${err.code}`);
2642  }
2643  return isSupported;
2644}
2645```
2646
2647### enableMovingPhoto<sup>12+</sup>
2648
2649enableMovingPhoto(enabled: boolean): void
2650
2651使能动态照片拍照。
2652
2653**需要权限:** ohos.permission.MICROPHONE
2654
2655**系统能力:** SystemCapability.Multimedia.Camera.Core
2656
2657**参数:**
2658
2659| 参数名      | 类型                    | 必填 | 说明                                       |
2660| -------- | ---------------------- | ---- | ------------------------------------------ |
2661| enabled  | boolean                | 是   | true为开启动态照片,false为关闭动态照片。     |
2662
2663**错误码:**
2664
2665以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
2666
2667| 错误码ID    | 错误信息                                           |
2668| -------- |------------------------------------------------|
2669| 201      | permission denied.                             |
2670| 7400101  | Parameter missing or parameter type incorrect. |
2671| 7400201  | Camera service fatal error.                    |
2672
2673**示例:**
2674
2675```ts
2676import { BusinessError } from '@kit.BasicServicesKit';
2677
2678function enableMovingPhoto(photoOutput: camera.PhotoOutput): void {
2679  try {
2680    photoOutput.enableMovingPhoto(true);
2681  } catch (error) {
2682    // 失败返回错误码error.code并处理。
2683    let err = error as BusinessError;
2684    console.error(`The enableMovingPhoto call failed. error code: ${err.code}`);
2685  }
2686}
2687```
2688
2689### on('photoAssetAvailable')<sup>12+</sup>
2690
2691on(type: 'photoAssetAvailable', callback: AsyncCallback\<photoAccessHelper.PhotoAsset\>): void
2692
2693注册监听photoAsset上报。使用callback异步回调。
2694
2695> **说明:**
2696>
2697> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
2698
2699**系统能力:** SystemCapability.Multimedia.Camera.Core
2700
2701**参数:**
2702
2703| 参数名     | 类型      | 必填 | 说明                                  |
2704| -------- | ---------- | --- | ------------------------------------ |
2705| type     | string     | 是   | 监听事件,固定为'photoAssetAvailable',photoOutput创建成功后可监听。 |
2706| callback | AsyncCallback\<[photoAccessHelper.PhotoAsset](../apis-media-library-kit/js-apis-photoAccessHelper.md#photoasset)\> | 是   | 回调函数,用于监听photoAsset上报。 |
2707
2708**示例:**
2709
2710```ts
2711import { BusinessError } from '@kit.BasicServicesKit';
2712import { photoAccessHelper } from '@kit.MediaLibraryKit';
2713
2714function photoAssetAvailableCallback(err: BusinessError, photoAsset: photoAccessHelper.PhotoAsset): void {
2715  if (err) {
2716    console.info(`photoAssetAvailable error: ${JSON.stringify(err)}.`);
2717    return;
2718  }
2719  console.info('photoOutPutCallBack photoAssetAvailable');
2720  // 开发者可通过photoAsset获取图片相关信息。
2721}
2722
2723function onPhotoOutputPhotoAssetAvailable(photoOutput: camera.PhotoOutput): void {
2724  photoOutput.on('photoAssetAvailable', photoAssetAvailableCallback);
2725}
2726```
2727
2728### off('photoAssetAvailable')<sup>12+</sup>
2729
2730off(type: 'photoAssetAvailable', callback?: AsyncCallback\<photoAccessHelper.PhotoAsset\>): void
2731
2732解注册photoAsset上报。
2733
2734**系统能力:** SystemCapability.Multimedia.Camera.Core
2735
2736**参数:**
2737
2738| 参数名     | 类型      | 必填  | 说明                                                                         |
2739| -------- | ---------- |-----|----------------------------------------------------------------------------|
2740| type     | string     | 是   | 监听事件,固定为'photoAssetAvailable',photoOutput创建成功后可监听。                         |
2741| callback | AsyncCallback\<[photoAccessHelper.PhotoAsset](../apis-media-library-kit/js-apis-photoAccessHelper.md#photoasset)\> | 否   | 需要解监听的回调方法。如果callback不为空且与此对应的监听方法一致,不为匿名方法,则解注册该方法;如果callback为空,则解监听所有回调。 |
2742
2743**示例:**
2744
2745```ts
2746function offPhotoOutputPhotoAssetAvailable(photoOutput: camera.PhotoOutput): void {
2747  photoOutput.off('photoAssetAvailable');
2748}
2749```
2750
2751### isMirrorSupported
2752
2753isMirrorSupported(): boolean
2754
2755查询是否支持镜像拍照。
2756
2757**系统能力:** SystemCapability.Multimedia.Camera.Core
2758
2759**返回值:**
2760
2761| 类型            | 说明                     |
2762| -------------- | ----------------------- |
2763| boolean | 返回是否支持镜像拍照,true表示支持,false表示不支持。 |
2764
2765**示例:**
2766
2767```ts
2768function isMirrorSupported(photoOutput: camera.PhotoOutput): boolean {
2769  let isSupported: boolean = photoOutput.isMirrorSupported();
2770  return isSupported;
2771}
2772```
2773
2774### enableMirror<sup>13+</sup>
2775
2776enableMirror(enabled: boolean): void
2777
2778是否启用镜像拍照。
2779
2780**系统能力:** SystemCapability.Multimedia.Camera.Core
2781
2782**参数:**
2783
2784| 参数名      | 类型                    | 必填 | 说明                        |
2785|----------| ---------------------- | ---- |---------------------------|
2786| enabled | boolean                | 是   | true为开启镜像拍照,false为关闭镜像拍照。 |
2787
2788**错误码:**
2789
2790以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
2791
2792| 错误码ID    | 错误信息                                           |
2793| -------- |------------------------------------------------|
2794| 7400101  | Parameter missing or parameter type incorrect. |
2795| 7400103  | Session not config.                    |
2796| 7400201  | Camera service fatal error.            |
2797
2798
2799**示例:**
2800
2801```ts
2802import { BusinessError } from '@kit.BasicServicesKit';
2803
2804function enableMirror(photoOutput: camera.PhotoOutput): void {
2805  try {
2806    photoOutput.enableMirror(true);
2807  } catch (error) {
2808    // 失败返回错误码error.code并处理。
2809    let err = error as BusinessError;
2810    console.error(`The enableMirror call failed. error code: ${err.code}`);
2811  }
2812}
2813```
2814
2815### getSupportedMovingPhotoVideoCodecTypes<sup>13+</sup>
2816
2817getSupportedMovingPhotoVideoCodecTypes(): Array\<VideoCodecType\>
2818
2819查询支持的动态照片短视频编码类型。
2820
2821**系统能力:** SystemCapability.Multimedia.Camera.Core
2822
2823**返回值:**
2824
2825| 类型            | 说明                |
2826| -------------- |-------------------|
2827| Array\<[VideoCodecType](#videocodectype13)\> | 支持的动态照片短视频编码类型列表。 |
2828
2829**错误码:**
2830
2831以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
2832
2833| 错误码ID        | 错误信息                      |
2834| --------------- | ---------------               |
2835| 7400201         |  Camera service fatal error.  |
2836
2837**示例:**
2838
2839```ts
2840function getSupportedMovingPhotoVideoCodecType(photoOutput: camera.PhotoOutput): Array<camera.VideoCodecType> {
2841  let supportedVideoCodecTypesArray: Array<camera.VideoCodecType> = photoOutput.getSupportedMovingPhotoVideoCodecTypes();
2842  return supportedVideoCodecTypesArray;
2843}
2844```
2845
2846### setMovingPhotoVideoCodecType<sup>13+</sup>
2847
2848setMovingPhotoVideoCodecType(codecType: VideoCodecType): void
2849
2850设置动态照片短视频编码类型。
2851
2852**系统能力:** SystemCapability.Multimedia.Camera.Core
2853
2854**参数:**
2855
2856| 参数名        | 类型                                  | 必填 |  说明                |
2857| ------------- |-------------------------------------|-------| ------------        |
2858| codecType     | [VideoCodecType](#videocodectype13) |  是    |获取动态照片短视频编码类型  |
2859
2860**错误码:**
2861
2862以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
2863
2864| 错误码ID        | 错误信息                      |
2865| --------------- | ---------------               |
2866| 7400201         |  Camera service fatal error.  |
2867
2868**示例:**
2869
2870```ts
2871function setMovingPhotoVideoCodecTypes(photoOutput: camera.PhotoOutput, videoCodecType: camera.VideoCodecType): void {
2872   photoOutput.setMovingPhotoVideoCodecType(videoCodecType);
2873}
2874```
2875
2876### on('captureStart')<sup>(deprecated)</sup>
2877
2878on(type: 'captureStart', callback: AsyncCallback\<number\>): void
2879
2880监听拍照开始,通过注册回调函数获取Capture ID。使用callback异步回调。
2881
2882> **说明:**
2883> 从 API version 10开始支持,从API version 11开始废弃。建议使用[on('captureStartWithInfo')](#oncapturestartwithinfo11)替代。
2884>
2885> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
2886
2887**系统能力:** SystemCapability.Multimedia.Camera.Core
2888
2889**参数:**
2890
2891| 参数名      | 类型                    | 必填 | 说明                                       |
2892| -------- | ---------------------- | ---- | ------------------------------------------ |
2893| type     | string                 | 是   | 监听事件,固定为'captureStart',photoOutput创建成功后可监听。每次拍照,底层开始曝光时触发该事件并返回。 |
2894| callback | AsyncCallback\<number\> | 是   | 使用callback的方式获取Capture ID。            |
2895
2896**示例:**
2897
2898```ts
2899import { BusinessError } from '@kit.BasicServicesKit';
2900
2901function callback(err: BusinessError, captureId: number): void {
2902  if (err !== undefined && err.code !== 0) {
2903    console.error(`Callback Error, errorCode: ${err.code}`);
2904    return;
2905  }
2906  console.info(`photo capture started, captureId : ${captureId}`);
2907}
2908
2909function registerPhotoOutputCaptureStart(photoOutput: camera.PhotoOutput): void {
2910  photoOutput.on('captureStart', callback);
2911}
2912```
2913
2914### off('captureStart')<sup>(deprecated)</sup>
2915
2916off(type: 'captureStart', callback?: AsyncCallback\<number\>): void
2917
2918注销监听拍照开始。
2919
2920> **说明:**
2921> 从 API version 10开始支持,从API version 11开始废弃。建议使用[off('captureStartWithInfo')](#offcapturestartwithinfo11)替代。
2922>
2923> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
2924
2925**系统能力:** SystemCapability.Multimedia.Camera.Core
2926
2927**参数:**
2928
2929| 参数名      | 类型                    | 必填 | 说明                                       |
2930| -------- | ---------------------- | ---- | ------------------------------------------ |
2931| type     | string                 | 是   | 监听事件,固定为'captureStart',photoOutput创建成功后可监听。 |
2932| callback | AsyncCallback\<number\> | 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
2933
2934**示例:**
2935
2936```ts
2937function unregisterPhotoOutputCaptureStart(photoOutput: camera.PhotoOutput): void {
2938  photoOutput.off('captureStart');
2939}
2940```
2941
2942### on('frameShutter')
2943
2944on(type: 'frameShutter', callback: AsyncCallback\<FrameShutterInfo\>): void
2945
2946监听拍照帧输出捕获,通过注册回调函数获取结果。使用callback异步回调。
2947
2948**系统能力:** SystemCapability.Multimedia.Camera.Core
2949
2950**参数:**
2951
2952| 参数名     | 类型      | 必填 | 说明                                  |
2953| -------- | ---------- | --- | ------------------------------------ |
2954| type     | string     | 是   | 监听事件,固定为'frameShutter',photoOutput创建成功后可监听。 |
2955| callback | AsyncCallback\<[FrameShutterInfo](#frameshutterinfo)\> | 是   | 回调函数,用于获取相关信息。该回调返回意味着可以再次下发拍照请求。             |
2956
2957**示例:**
2958
2959```ts
2960import { BusinessError } from '@kit.BasicServicesKit';
2961
2962function callback(err: BusinessError, frameShutterInfo: camera.FrameShutterInfo): void {
2963  if (err !== undefined && err.code !== 0) {
2964    console.error(`Callback Error, errorCode: ${err.code}`);
2965    return;
2966  }
2967  console.info(`CaptureId for frame : ${frameShutterInfo.captureId}`);
2968  console.info(`Timestamp for frame : ${frameShutterInfo.timestamp}`);
2969}
2970
2971function registerPhotoOutputFrameShutter(photoOutput: camera.PhotoOutput): void {
2972  photoOutput.on('frameShutter', callback);
2973}
2974```
2975
2976### off('frameShutter')
2977
2978off(type: 'frameShutter', callback?: AsyncCallback\<FrameShutterInfo\>): void
2979
2980注销监听拍照帧输出捕获。
2981
2982**系统能力:** SystemCapability.Multimedia.Camera.Core
2983
2984**参数:**
2985
2986| 参数名     | 类型      | 必填 | 说明                                  |
2987| -------- | ---------- | --- | ------------------------------------ |
2988| type     | string     | 是   | 监听事件,固定为'frameShutter',photoOutput创建成功后可监听。 |
2989| callback | AsyncCallback\<[FrameShutterInfo](#frameshutterinfo)\> | 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
2990
2991**示例:**
2992
2993```ts
2994function unregisterPhotoOutputFrameShutter(photoOutput: camera.PhotoOutput): void {
2995  photoOutput.off('frameShutter');
2996}
2997```
2998
2999### on('captureEnd')
3000
3001on(type: 'captureEnd', callback: AsyncCallback\<CaptureEndInfo\>): void
3002
3003监听拍照结束,通过注册回调函数获取结果。使用callback异步回调。
3004
3005> **说明:**
3006>
3007> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
3008
3009**系统能力:** SystemCapability.Multimedia.Camera.Core
3010
3011**参数:**
3012
3013| 参数名     | 类型           | 必填 | 说明                                       |
3014| -------- | --------------- | ---- | ---------------------------------------- |
3015| type     | string          | 是   | 监听事件,固定为'captureEnd',photoOutput创建成功后可监听。拍照完全结束可触发该事件发生并返回相应信息。 |
3016| callback | AsyncCallback\<[CaptureEndInfo](#captureendinfo)\> | 是   | 回调函数,用于获取相关信息。                  |
3017
3018**示例:**
3019
3020```ts
3021import { BusinessError } from '@kit.BasicServicesKit';
3022
3023function callback(err: BusinessError, captureEndInfo: camera.CaptureEndInfo): void {
3024  if (err !== undefined && err.code !== 0) {
3025    console.error(`Callback Error, errorCode: ${err.code}`);
3026    return;
3027  }
3028  console.info(`photo capture end, captureId : ${captureEndInfo.captureId}`);
3029  console.info(`frameCount : ${captureEndInfo.frameCount}`);
3030}
3031
3032function registerPhotoOutputCaptureEnd(photoOutput: camera.PhotoOutput): void {
3033  photoOutput.on('captureEnd', callback);
3034}
3035```
3036
3037### off('captureEnd')
3038
3039off(type: 'captureEnd', callback?: AsyncCallback\<CaptureEndInfo\>): void
3040
3041注销监听拍照结束。
3042
3043**系统能力:** SystemCapability.Multimedia.Camera.Core
3044
3045**参数:**
3046
3047| 参数名     | 类型           | 必填 | 说明                                       |
3048| -------- | --------------- | ---- | ---------------------------------------- |
3049| type     | string          | 是   | 监听事件,固定为'captureEnd',photoOutput创建成功后可监听。 |
3050| callback | AsyncCallback\<[CaptureEndInfo](#captureendinfo)\> | 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
3051
3052**示例:**
3053
3054```ts
3055function unregisterPhotoOutputCaptureEnd(photoOutput: camera.PhotoOutput): void {
3056  photoOutput.off('captureEnd');
3057}
3058```
3059
3060### on('frameShutterEnd')<sup>12+</sup>
3061
3062on(type: 'frameShutterEnd', callback: AsyncCallback\<FrameShutterEndInfo\>): void
3063
3064监听拍照曝光结束捕获,通过注册回调函数获取结果。使用callback异步回调。
3065
3066> **说明:**
3067>
3068> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
3069
3070**系统能力:** SystemCapability.Multimedia.Camera.Core
3071
3072**参数:**
3073
3074| 参数名   | 类型                                                         | 必填 | 说明                                                         |
3075| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
3076| type     | string                                                       | 是   | 监听事件,固定为'frameShutterEnd',photoOutput创建成功后可监听。 |
3077| callback | AsyncCallback\<[FrameShutterEndInfo](#frameshutterendinfo12)\> | 是   | 回调函数,用于获取相关信息。该回调返回表示拍照曝光结束。   |
3078
3079**示例:**
3080
3081```ts
3082import { BusinessError } from '@kit.BasicServicesKit';
3083
3084function callback(err: BusinessError, frameShutterEndInfo: camera.FrameShutterEndInfo): void {
3085  if (err !== undefined && err.code !== 0) {
3086    console.error(`Callback Error, errorCode: ${err.code}`);
3087    return;
3088  }
3089  console.info(`CaptureId for frame : ${frameShutterEndInfo.captureId}`);
3090}
3091
3092function registerPhotoOutputFrameShutterEnd(photoOutput: camera.PhotoOutput): void {
3093  photoOutput.on('frameShutterEnd', callback);
3094}
3095```
3096
3097### off('frameShutterEnd')<sup>12+</sup>
3098
3099off(type: 'frameShutterEnd', callback?: AsyncCallback\<FrameShutterEndInfo\>): void
3100
3101注销监听拍照帧输出捕获。
3102
3103**系统能力:** SystemCapability.Multimedia.Camera.Core
3104
3105**参数:**
3106
3107| 参数名   | 类型                                                         | 必填 | 说明                                                         |
3108| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
3109| type     | string                                                       | 是   | 监听事件,固定为'frameShutterEnd',photoOutput创建成功后可监听。 |
3110| callback | AsyncCallback\<[FrameShutterEndInfo](#frameshutterendinfo12)\> | 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
3111
3112**示例:**
3113
3114```ts
3115function unregisterPhotoOutputFrameShutterEnd(photoOutput: camera.PhotoOutput): void {
3116  photoOutput.off('frameShutterEnd');
3117}
3118```
3119
3120### on('captureReady')<sup>12+</sup>
3121
3122on(type: 'captureReady', callback: AsyncCallback\<void\>): void
3123
3124监听可拍下一张,通过注册回调函数获取结果。使用callback异步回调。
3125
3126> **说明:**
3127>
3128> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
3129
3130**系统能力:** SystemCapability.Multimedia.Camera.Core
3131
3132**参数:**
3133
3134| 参数名   | 类型                  | 必填 | 说明                                                         |
3135| -------- | --------------------- | ---- | ------------------------------------------------------------ |
3136| type     | string                | 是   | 监听事件,固定为'captureReady',photoOutput创建成功后可监听。当下一张可拍时可触发该事件发生并返回相应信息。 |
3137| callback | AsyncCallback\<void\> | 是   | 回调函数,用于获取相关信息。                                 |
3138
3139**示例:**
3140
3141```ts
3142import { BusinessError } from '@kit.BasicServicesKit';
3143
3144function callback(err: BusinessError): void {
3145  if (err !== undefined && err.code !== 0) {
3146    console.error(`Callback Error, errorCode: ${err.code}`);
3147    return;
3148  }
3149  console.info(`photo capture ready`);
3150}
3151
3152function registerPhotoOutputCaptureReady(photoOutput: camera.PhotoOutput): void {
3153  photoOutput.on('captureReady', callback);
3154}
3155```
3156
3157### off('captureReady')<sup>12+</sup>
3158
3159off(type: 'captureReady', callback?: AsyncCallback\<void\>): void
3160
3161注销监听可拍下一张。
3162
3163**系统能力:** SystemCapability.Multimedia.Camera.Core
3164
3165**参数:**
3166
3167| 参数名   | 类型                                                 | 必填 | 说明                                                         |
3168| -------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------ |
3169| type     | string                                               | 是   | 监听事件,固定为'captureReady',photoOutput创建成功后可监听。 |
3170| callback | AsyncCallback\<[CaptureReadyInfo](#captureendinfo)\> | 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
3171
3172**示例:**
3173
3174```ts
3175function unregisterPhotoOutputCaptureReady(photoOutput: camera.PhotoOutput): void {
3176  photoOutput.off('captureReady');
3177}
3178```
3179
3180### on('estimatedCaptureDuration')<sup>12+</sup>
3181
3182on(type: 'estimatedCaptureDuration', callback: AsyncCallback\<number\>): void
3183
3184监听预估的拍照时间,通过注册回调函数获取结果。使用callback异步回调。
3185
3186> **说明:**
3187>
3188> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
3189
3190**系统能力:** SystemCapability.Multimedia.Camera.Core
3191
3192**参数:**
3193
3194| 参数名   | 类型                   | 必填 | 说明                                                         |
3195| -------- | ---------------------- | ---- | ------------------------------------------------------------ |
3196| type     | string                 | 是   | 监听事件,固定为'estimatedCaptureDuration',photoOutput创建成功后可监听。拍照完全结束可触发该事件发生并返回相应信息。 |
3197| callback | AsyncCallback\<number> | 是   | 回调函数,用于获取预估的单次拍照底层出sensor采集帧时间,如果上报-1,代表没有预估时间。                                 |
3198
3199**示例:**
3200
3201```ts
3202import { BusinessError } from '@kit.BasicServicesKit';
3203
3204function callback(err: BusinessError, duration: number): void {
3205  if (err !== undefined && err.code !== 0) {
3206    console.error(`Callback Error, errorCode: ${err.code}`);
3207    return;
3208  }
3209  console.info(`photo estimated capture duration : ${duration}`);
3210}
3211
3212function registerPhotoOutputEstimatedCaptureDuration(photoOutput: camera.PhotoOutput): void {
3213  photoOutput.on('estimatedCaptureDuration', callback);
3214}
3215```
3216
3217### off('estimatedCaptureDuration')<sup>12+</sup>
3218
3219off(type: 'estimatedCaptureDuration', callback?: AsyncCallback\<number\>): void
3220
3221注销监听预估的拍照时间。
3222
3223**系统能力:** SystemCapability.Multimedia.Camera.Core
3224
3225**参数:**
3226
3227| 参数名   | 类型                    | 必填 | 说明                                                         |
3228| -------- | ----------------------- | ---- | ------------------------------------------------------------ |
3229| type     | string                  | 是   | 监听事件,固定为'estimatedCaptureDuration',photoOutput创建成功后可监听。 |
3230| callback | AsyncCallback\<number\> | 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
3231
3232**示例:**
3233
3234```ts
3235function unregisterPhotoOutputEstimatedCaptureDuration(photoOutput: camera.PhotoOutput): void {
3236  photoOutput.off('estimatedCaptureDuration');
3237}
3238```
3239
3240### on('error')
3241
3242on(type: 'error', callback: ErrorCallback): void
3243
3244监听拍照输出发生错误,通过注册回调函数获取结果。使用callback异步回调。
3245
3246> **说明:**
3247>
3248> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
3249
3250**系统能力:** SystemCapability.Multimedia.Camera.Core
3251
3252**参数:**
3253
3254| 参数名     | 类型         | 必填 | 说明                                 |
3255| -------- | ------------- | ---- | ----------------------------------- |
3256| type     | string       | 是   | 监听事件,固定为'error',photoOutput创建成功后可监听。拍照接口调用时出现错误触发该事件并返回错误信息。 |
3257| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | 是   | 回调函数,用于获取错误信息。返回错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。             |
3258
3259**示例:**
3260
3261```ts
3262import { BusinessError } from '@kit.BasicServicesKit';
3263
3264function callback(err: BusinessError): void {
3265  console.error(`Photo output error code: ${err.code}`);
3266}
3267
3268function registerPhotoOutputError(photoOutput: camera.PhotoOutput): void {
3269  photoOutput.on('error', callback);
3270}
3271```
3272
3273### off('error')
3274
3275off(type: 'error', callback?: ErrorCallback): void
3276
3277注销监听拍照输出发生错误。
3278
3279**系统能力:** SystemCapability.Multimedia.Camera.Core
3280
3281**参数:**
3282
3283| 参数名     | 类型         | 必填 | 说明                                 |
3284| -------- | ------------- | ---- | ----------------------------------- |
3285| type     | string       | 是   | 监听事件,固定为'error',photoOutput创建成功后可监听。 |
3286| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
3287
3288**示例:**
3289
3290```ts
3291function unregisterPhotoOutputError(photoOutput: camera.PhotoOutput): void {
3292  photoOutput.off('error');
3293}
3294```
3295
3296### getActiveProfile<sup>12+</sup>
3297
3298getActiveProfile(): Profile
3299
3300获取当前生效的配置信息。
3301
3302**系统能力:** SystemCapability.Multimedia.Camera.Core
3303
3304**返回值:**
3305
3306|      类型      | 说明        |
3307| -------------  |-----------|
3308| [Profile](#profile) | 当前生效的配置信息 |
3309
3310**错误码:**
3311
3312以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
3313
3314| 错误码ID   | 错误信息                         |
3315|---------|------------------------------|
3316| 7400201 | Camera service fatal error.  |
3317
3318**示例:**
3319
3320```ts
3321function testGetActiveProfile(photoOutput: camera.PhotoOutput): camera.Profile | undefined {
3322  let activeProfile: camera.Profile | undefined = undefined;
3323  try {
3324    activeProfile = photoOutput.getActiveProfile();
3325  } catch (error) {
3326    // 失败返回错误码error.code并处理。
3327    let err = error as BusinessError;
3328    console.error(`The photoOutput.getActiveProfile call failed. error code: ${err.code}`);
3329  }
3330  return activeProfile;
3331}
3332```
3333### getPhotoRotation<sup>12+</sup>
3334
3335getPhotoRotation(deviceDegree: number): ImageRotation
3336
3337获取拍照旋转角度。
3338
3339- 设备自然方向:设备默认使用方向,手机为竖屏(充电口向下)。
3340- 相机镜头角度:值等于相机图像顺时针旋转到设备自然方向的角度,手机后置相机传感器是横屏安装的,所以需要顺时针旋转90度到设备自然方向。
3341- 屏幕显示方向:需要屏幕显示的图片左上角为第一个像素点为坐标原点。锁屏时与自然方向一致。
3342
3343**系统能力:** SystemCapability.Multimedia.Camera.Core
3344
3345**参数:**
3346
3347| 参数名     | 类型         | 必填 | 说明                       |
3348| -------- | --------------| ---- | ------------------------ |
3349| deviceDegree | number | 是   | 设备旋转角度 |
3350
3351**返回值:**
3352
3353|      类型      | 说明        |
3354| -------------  |-----------|
3355| [ImageRotation](#imagerotation) | 获取拍照旋转角度。 |
3356
3357**错误码:**
3358
3359以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
3360
3361| 错误码ID   | 错误信息                         |
3362|---------|------------------------------|
3363| 7400101 | Parameter missing or parameter type incorrect.  |
3364| 7400201 | Camera service fatal error.  |
3365
3366**示例:**
3367
3368```ts
3369function testGetPhotoRotation(photoOutput: camera.PhotoOutput, deviceDegree : number): camera.ImageRotation {
3370  let photoRotation: camera.ImageRotation = camera.ImageRotation.ROTATION_0;
3371  try {
3372    photoRotation = photoOutput.getPhotoRotation(deviceDegree);
3373    console.log(`Photo rotation is: ${photoRotation}`);
3374  } catch (error) {
3375    // 失败返回错误码error.code并处理。
3376    let err = error as BusinessError;
3377    console.error(`The photoOutput.getPhotoRotation call failed. error code: ${err.code}`);
3378  }
3379  return photoRotation;
3380}
3381```
3382
3383## FrameShutterInfo
3384
3385拍照帧输出信息。
3386
3387**系统能力:** SystemCapability.Multimedia.Camera.Core
3388
3389| 名称       | 类型   | 只读 | 可选 | 说明        |
3390| --------- | ------ | ---- | ---- | ---------- |
3391| captureId | number | 否   | 否   | 拍照的ID。  |
3392| timestamp | number | 否   | 否   | 快门时间戳。 |
3393
3394## FrameShutterEndInfo<sup>12+</sup>
3395
3396拍照曝光结束信息。
3397
3398**系统能力:** SystemCapability.Multimedia.Camera.Core
3399
3400| 名称      | 类型   | 只读 | 可选 | 说明       |
3401| --------- | ------ | ---- | ---- | ---------- |
3402| captureId | number | 否   | 否   | 拍照的ID。 |
3403
3404## CaptureStartInfo<sup>11+</sup>
3405
3406拍照开始信息。
3407
3408**系统能力:** SystemCapability.Multimedia.Camera.Core
3409
3410| 名称       | 类型    | 只读 | 可选 | 说明       |
3411| ---------- | ------ | ---- | ---- | --------- |
3412| captureId  | number | 否   | 否   | 拍照的ID。 |
3413| time       | number | 否   | 否   | 预估的单次拍照底层出sensor采集帧时间,如果上报-1,代表没有预估时间。    |
3414
3415## CaptureEndInfo
3416
3417拍照停止信息。
3418
3419**系统能力:** SystemCapability.Multimedia.Camera.Core
3420
3421| 名称       | 类型    | 只读 | 可选 | 说明       |
3422| ---------- | ------ | ---- | ---- | ---------|
3423| captureId  | number | 否   | 否   | 拍照的ID。 |
3424| frameCount | number | 否   | 否   | 帧数。    |
3425
3426## AutoDeviceSwitchStatus<sup>13+</sup>
3427
3428自动切换镜头状态信息。
3429
3430**系统能力:** SystemCapability.Multimedia.Camera.Core
3431
3432| 名称       | 类型      | 只读 | 可选 | 说明                      |
3433| ---------- |---------| ---- | ---- |-------------------------|
3434| isDeviceSwitched  | boolean | 否   | 否   | 自动切换镜头是否成功。             |
3435| isDeviceCapabilityChanged | boolean  | 否   | 否   | 自动切换镜头成功后,其镜头能力值是否发生改变。 |
3436
3437## VideoOutput
3438
3439录像会话中使用的输出信息,继承[CameraOutput](#cameraoutput)。
3440
3441### start
3442
3443start(callback: AsyncCallback\<void\>): void
3444
3445启动录制,通过注册回调函数获取结果。使用callback异步回调。
3446
3447**系统能力:** SystemCapability.Multimedia.Camera.Core
3448
3449**参数:**
3450
3451| 参数名      | 类型                  | 必填 | 说明                 |
3452| -------- | -------------------- | ---- | -------------------- |
3453| callback | AsyncCallback\<void\> | 是   | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
3454
3455**错误码:**
3456
3457以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
3458
3459| 错误码ID         | 错误信息        |
3460| --------------- | --------------- |
3461| 7400103                |  Session not config.                                   |
3462| 7400201                |  Camera service fatal error.                           |
3463
3464**示例:**
3465
3466```ts
3467import { BusinessError } from '@kit.BasicServicesKit';
3468
3469function startVideoOutput(videoOutput: camera.VideoOutput): void {
3470  videoOutput.start((err: BusinessError) => {
3471    if (err) {
3472      console.error(`Failed to start the video output, error code: ${err.code}.`);
3473      return;
3474    }
3475    console.info('Callback invoked to indicate the video output start success.');
3476  });
3477}
3478```
3479
3480### start
3481
3482start(): Promise\<void\>
3483
3484启动录制,通过Promise获取结果。
3485
3486**系统能力:** SystemCapability.Multimedia.Camera.Core
3487
3488**返回值:**
3489
3490| 类型            | 说明                     |
3491| -------------- | ----------------------- |
3492| Promise\<void\> | 无返回结果的Promise对象。 |
3493
3494**错误码:**
3495
3496以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
3497
3498| 错误码ID         | 错误信息        |
3499| --------------- | --------------- |
3500| 7400103                |  Session not config.                                   |
3501| 7400201                |  Camera service fatal error.                           |
3502
3503**示例:**
3504
3505```ts
3506import { BusinessError } from '@kit.BasicServicesKit';
3507
3508function startVideoOutput(videoOutput: camera.VideoOutput): void {
3509  videoOutput.start().then(() => {
3510    console.info('Promise returned to indicate that start method execution success.');
3511  }).catch((error: BusinessError) => {
3512    console.error(`Failed to video output start, error code: ${error.code}.`);
3513  });
3514}
3515```
3516
3517### stop
3518
3519stop(callback: AsyncCallback\<void\>): void
3520
3521结束录制,通过注册回调函数获取结果。使用callback异步回调。
3522
3523**系统能力:** SystemCapability.Multimedia.Camera.Core
3524
3525**参数:**
3526
3527| 参数名     | 类型                 | 必填 | 说明                     |
3528| -------- | -------------------- | ---- | ------------------------ |
3529| callback | AsyncCallback\<void\> | 是   | 回调函数,用于获取结果。 |
3530
3531**示例:**
3532
3533```ts
3534import { BusinessError } from '@kit.BasicServicesKit';
3535
3536function stopVideoOutput(videoOutput: camera.VideoOutput): void {
3537  videoOutput.stop((err: BusinessError) => {
3538    if (err) {
3539      console.error(`Failed to stop the video output, error code: ${err.code}.`);
3540      return;
3541    }
3542    console.info('Callback invoked to indicate the video output stop success.');
3543  });
3544}
3545```
3546
3547### stop
3548
3549stop(): Promise\<void\>
3550
3551结束录制,通过Promise获取结果。
3552
3553**系统能力:** SystemCapability.Multimedia.Camera.Core
3554
3555**返回值:**
3556
3557| 类型            | 说明                     |
3558| -------------- | ----------------------- |
3559| Promise\<void\> | 无返回结果的Promise对象。 |
3560
3561**示例:**
3562
3563```ts
3564import { BusinessError } from '@kit.BasicServicesKit';
3565
3566function stopVideoOutput(videoOutput: camera.VideoOutput): void {
3567  videoOutput.stop().then(() => {
3568    console.info('Promise returned to indicate that stop method execution success.');
3569  }).catch((error: BusinessError) => {
3570    console.error(`Failed to video output stop, error code: ${error.code}.`);
3571  });
3572}
3573```
3574
3575### on('frameStart')
3576
3577on(type: 'frameStart', callback: AsyncCallback\<void\>): void
3578
3579监听录像开始,通过注册回调函数获取结果。使用callback异步回调。
3580
3581> **说明:**
3582>
3583> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
3584
3585**系统能力:** SystemCapability.Multimedia.Camera.Core
3586
3587**参数:**
3588
3589| 参数名      | 类型                  | 必填 | 说明                                       |
3590| -------- | -------------------- | ---- | ----------------------------------------- |
3591| type     | string               | 是   | 监听事件,固定为'frameStart',videoOutput创建成功后可监听。底层第一次曝光时触发该事件并返回。 |
3592| callback | AsyncCallback\<void\> | 是   | 回调函数,用于获取结果。  只要有该事件返回就证明录像开始。                     |
3593
3594**示例:**
3595
3596```ts
3597import { BusinessError } from '@kit.BasicServicesKit';
3598
3599function callback(err: BusinessError): void {
3600  if (err !== undefined && err.code !== 0) {
3601    console.error(`Callback Error, errorCode: ${err.code}`);
3602    return;
3603  }
3604  console.info('Video frame started');
3605}
3606
3607function registerVideoOutputFrameStart(videoOutput: camera.VideoOutput): void {
3608  videoOutput.on('frameStart', callback);
3609}
3610```
3611
3612### off('frameStart')
3613
3614off(type: 'frameStart', callback?: AsyncCallback\<void\>): void
3615
3616注销监听录像开始。
3617
3618> **说明:**
3619>
3620> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
3621
3622**系统能力:** SystemCapability.Multimedia.Camera.Core
3623
3624**参数:**
3625
3626| 参数名      | 类型                  | 必填 | 说明                                       |
3627| -------- | -------------------- | ---- | ----------------------------------------- |
3628| type     | string               | 是   | 监听事件,固定为'frameStart',videoOutput创建成功后可监听。 |
3629| callback | AsyncCallback\<void\> | 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
3630
3631**示例:**
3632
3633```ts
3634function unregisterVideoOutputFrameStart(videoOutput: camera.VideoOutput): void {
3635  videoOutput.off('frameStart');
3636}
3637
3638```
3639
3640### on('frameEnd')
3641
3642on(type: 'frameEnd', callback: AsyncCallback\<void\>): void
3643
3644监听录像结束,通过注册回调函数获取结果。使用callback异步回调。
3645
3646**系统能力:** SystemCapability.Multimedia.Camera.Core
3647
3648**参数:**
3649
3650| 参数名      | 类型                  | 必填 | 说明                                       |
3651| -------- | -------------------- | ---- | ------------------------------------------ |
3652| type     | string               | 是   | 监听事件,固定为'frameEnd',videoOutput创建成功后可监听。录像完全结束最后一帧时触发该事件并返回。 |
3653| callback | AsyncCallback\<void\> | 是   | 回调函数,用于获取结果。 只要有该事件返回就证明录像结束。                      |
3654
3655**示例:**
3656
3657```ts
3658import { BusinessError } from '@kit.BasicServicesKit';
3659
3660function callback(err: BusinessError): void {
3661  if (err !== undefined && err.code !== 0) {
3662    console.error(`Callback Error, errorCode: ${err.code}`);
3663    return;
3664  }
3665  console.info('Video frame ended');
3666}
3667
3668function registerVideoOutputFrameEnd(videoOutput: camera.VideoOutput): void {
3669  videoOutput.on('frameEnd', callback);
3670}
3671```
3672
3673### off('frameEnd')
3674
3675off(type: 'frameEnd', callback?: AsyncCallback\<void\>): void
3676
3677注销监听录像结束。
3678
3679**系统能力:** SystemCapability.Multimedia.Camera.Core
3680
3681**参数:**
3682
3683| 参数名      | 类型                  | 必填 | 说明                                       |
3684| -------- | -------------------- | ---- | ------------------------------------------ |
3685| type     | string               | 是   | 监听事件,固定为'frameEnd',videoOutput创建成功后可监听。 |
3686| callback | AsyncCallback\<void\> | 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
3687
3688**示例:**
3689
3690```ts
3691function unregisterVideoOutputFrameEnd(videoOutput: camera.VideoOutput): void {
3692  videoOutput.off('frameEnd');
3693}
3694```
3695
3696### on('error')
3697
3698on(type: 'error', callback: ErrorCallback): void
3699
3700监听录像输出发生错误,通过注册回调函数获取结果。使用callback异步回调。
3701
3702> **说明:**
3703>
3704> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
3705
3706**系统能力:** SystemCapability.Multimedia.Camera.Core
3707
3708**参数:**
3709
3710| 参数名     | 类型       | 必填 | 说明                                    |
3711| -------- | ----------- | ---- | -------------------------------------- |
3712| type     | string      | 是   | 监听事件,固定为'error',videoOutput创建成功后可监听。录像接口调用出现错误时触发该事件并返回对应错误码,比如调用[start](#start-1),[CameraOutput.release](#release-1)接口时出现错误返回对应错误信息。 |
3713| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | 是   | 回调函数,用于获取错误信息。返回错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。                 |
3714
3715**示例:**
3716
3717```ts
3718import { BusinessError } from '@kit.BasicServicesKit';
3719
3720function callback(err: BusinessError): void {
3721  console.error(`Video output error code: ${err.code}`);
3722}
3723
3724function registerVideoOutputError(videoOutput: camera.VideoOutput): void {
3725  videoOutput.on('error', callback);
3726}
3727```
3728
3729### off('error')
3730
3731off(type: 'error', callback?: ErrorCallback): void
3732
3733注销监听录像输出发生错误。
3734
3735**系统能力:** SystemCapability.Multimedia.Camera.Core
3736
3737**参数:**
3738
3739| 参数名     | 类型         | 必填 | 说明                                 |
3740| -------- | ------------- | ---- | ----------------------------------- |
3741| type     | string       | 是   | 监听事件,固定为'error',photoOutput创建成功后可监听。 |
3742| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
3743
3744**示例:**
3745
3746```ts
3747function unregisterVideoOutputError(videoOutput: camera.VideoOutput): void {
3748  videoOutput.off('error');
3749}
3750```
3751
3752### getSupportedFrameRates<sup>12+</sup>
3753
3754getSupportedFrameRates(): Array\<FrameRateRange\>
3755
3756查询支持的帧率范围。
3757
3758**系统能力:** SystemCapability.Multimedia.Camera.Core
3759
3760**返回值:**
3761
3762|      类型      |     说明     |
3763| -------------  | ------------ |
3764| Array<[FrameRateRange](#frameraterange)> | 支持的帧率范围列表 |
3765
3766**示例:**
3767
3768```ts
3769function getSupportedFrameRates(videoOutput: camera.VideoOutput): Array<camera.FrameRateRange> {
3770  let supportedFrameRatesArray: Array<camera.FrameRateRange> = videoOutput.getSupportedFrameRates();
3771  return supportedFrameRatesArray;
3772}
3773```
3774
3775### setFrameRate<sup>12+</sup>
3776
3777setFrameRate(minFps: number, maxFps: number): void
3778
3779设置录像流帧率范围,设置的范围必须在支持的帧率范围内。
3780
3781进行设置前,可通过[getSupportedFrameRates](#getsupportedframerates12-1)查询支持的帧率范围。
3782
3783> **说明:**
3784> 仅在[PhotoSession](#photosession11)或[VideoSession](#videosession11)模式下支持。
3785
3786**系统能力:** SystemCapability.Multimedia.Camera.Core
3787
3788**参数:**
3789
3790| 参数名     | 类型         | 必填 | 说明                       |
3791| -------- | --------------| ---- | ------------------------ |
3792| minFps   | number        | 是   | 最小帧率。 |
3793| maxFps   | number        | 是   | 最大帧率。当传入的最小值大于最大值时,传参异常,接口不生效。 |
3794
3795**错误码:**
3796
3797以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
3798
3799| 错误码ID        | 错误信息        |
3800| --------------- | --------------- |
3801| 7400101                |  Parameter missing or parameter type incorrect.        |
3802| 7400110                |  Unresolved conflicts with current configurations.     |
3803
3804**示例:**
3805
3806```ts
3807function setFrameRateRange(videoOutput: camera.VideoOutput, frameRateRange: Array<number>): void {
3808  videoOutput.setFrameRate(frameRateRange[0], frameRateRange[1]);
3809}
3810```
3811
3812### getActiveFrameRate<sup>12+</sup>
3813
3814getActiveFrameRate(): FrameRateRange
3815
3816获取已设置的帧率范围。
3817
3818使用[setFrameRate](#setframerate12-1)对录像流设置过帧率后可查询。
3819
3820**系统能力:** SystemCapability.Multimedia.Camera.Core
3821
3822**返回值:**
3823
3824|      类型      |     说明     |
3825| -------------  | ------------ |
3826| [FrameRateRange](#frameraterange) | 帧率范围 |
3827
3828**示例:**
3829
3830```ts
3831function getActiveFrameRate(videoOutput: camera.VideoOutput): camera.FrameRateRange {
3832  let activeFrameRate: camera.FrameRateRange = videoOutput.getActiveFrameRate();
3833  return activeFrameRate;
3834}
3835```
3836
3837### getActiveProfile<sup>12+</sup>
3838
3839getActiveProfile(): VideoProfile
3840
3841获取当前生效的配置信息。
3842
3843**系统能力:** SystemCapability.Multimedia.Camera.Core
3844
3845**返回值:**
3846
3847|      类型      | 说明        |
3848| -------------  |-----------|
3849| [VideoProfile](#videoprofile) | 当前生效的配置信息 |
3850
3851**错误码:**
3852
3853以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
3854
3855| 错误码ID   | 错误信息                         |
3856|---------|------------------------------|
3857| 7400201 | Camera service fatal error.  |
3858
3859**示例:**
3860
3861```ts
3862function testGetActiveProfile(videoOutput: camera.VideoOutput): camera.Profile | undefined {
3863  let activeProfile: camera.VideoProfile | undefined = undefined;
3864  try {
3865    activeProfile = videoOutput.getActiveProfile();
3866  } catch (error) {
3867    // 失败返回错误码error.code并处理。
3868    let err = error as BusinessError;
3869    console.error(`The videoOutput.getActiveProfile call failed. error code: ${err.code}`);
3870  }
3871  return activeProfile;
3872}
3873```
3874
3875### isMirrorSupported<sup>15+</sup>
3876
3877isMirrorSupported(): boolean
3878
3879查询是否支持镜像录像。
3880
3881**系统能力:** SystemCapability.Multimedia.Camera.Core
3882
3883**返回值:**
3884
3885| 类型            | 说明                              |
3886| -------------- |---------------------------------|
3887| boolean | 返回是否支持镜像录像,true表示支持,false表示不支持。 |
3888
3889**示例:**
3890
3891```ts
3892function testIsMirrorSupported(videoOutput: camera.VideoOutput): boolean {
3893  let isSupported: boolean = videoOutput.isMirrorSupported();
3894  return isSupported;
3895}
3896```
3897### enableMirror<sup>15+</sup>
3898
3899enableMirror(enabled: boolean): void
3900
3901启用/关闭镜像录像。
3902- 调用该接口前,需要通过[isMirrorSupported](#ismirrorsupported15)查询是否支录像镜像功能。
3903
3904- 启用/关闭录像镜像后,需要通过[getVideoRotation](#getvideorotation12)以及[updateRotation](../apis-media-kit/js-apis-media.md#updaterotation12)更新旋转角度。
3905
3906**系统能力:** SystemCapability.Multimedia.Camera.Core
3907
3908**参数:**
3909
3910| 参数名      | 类型                    | 必填 | 说明                        |
3911|----------| ---------------------- | ---- |---------------------------|
3912| enabled | boolean                | 是   | true为开启镜像录像,false为关闭镜像录像。 |
3913
3914**错误码:**
3915
3916以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
3917
3918| 错误码ID    | 错误信息                                           |
3919| -------- |------------------------------------------------|
3920| 7400101  | Parameter missing or parameter type incorrect. |
3921| 7400103  | Session not config.                    |
3922
3923
3924**示例:**
3925
3926```ts
3927import { camera } from '@kit.CameraKit';
3928import { media } from '@kit.MediaKit';
3929import { BusinessError } from '@kit.BasicServicesKit';
3930
3931function enableMirror(videoOutput: camera.VideoOutput, mirrorMode: boolean, aVRecorder: media.AVRecorder, deviceDegree : number): void {
3932    try {
3933        videoOutput.enableMirror(mirrorMode);
3934        aVRecorder.updateRotation(videoOutput.getVideoRotation(deviceDegree));
3935    } catch (error) {
3936        let err = error as BusinessError;
3937    }
3938}
3939```
3940
3941### getVideoRotation<sup>12+</sup>
3942
3943getVideoRotation(deviceDegree: number): ImageRotation
3944
3945获取录像旋转角度。
3946
3947- 设备自然方向:设备默认使用方向,手机为竖屏(充电口向下)。
3948- 相机镜头角度:值等于相机图像顺时针旋转到设备自然方向的角度,手机后置相机传感器是横屏安装的,所以需要顺时针旋转90度到设备自然方向。
3949- 屏幕显示方向:需要屏幕显示的图片左上角为第一个像素点为坐标原点。锁屏时与自然方向一致。
3950
3951**系统能力:** SystemCapability.Multimedia.Camera.Core
3952
3953**参数:**
3954
3955| 参数名     | 类型         | 必填 | 说明                       |
3956| -------- | --------------| ---- | ------------------------ |
3957| deviceDegree | number | 是   | 设备旋转角度 |
3958
3959**返回值:**
3960
3961|      类型      | 说明        |
3962| -------------  |-----------|
3963| [ImageRotation](#imagerotation) | 获取录像旋转角度。 |
3964
3965**错误码:**
3966
3967以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
3968
3969| 错误码ID   | 错误信息                         |
3970|---------|------------------------------|
3971| 7400101 | Parameter missing or parameter type incorrect.  |
3972| 7400201 | Camera service fatal error.  |
3973
3974**示例:**
3975
3976```ts
3977import { camera } from '@kit.CameraKit';
3978import { Decimal } from '@kit.ArkTS';
3979import { sensor } from '@kit.SensorServiceKit';
3980import { BusinessError } from '@kit.BasicServicesKit';
3981
3982function getVideoRotation(videoOutput: camera.VideoOutput): camera.ImageRotation {
3983    let videoRotation: camera.ImageRotation = camera.ImageRotation.ROTATION_0;
3984    try {
3985        videoRotation = videoOutput.getVideoRotation(getDeviceDegree());
3986    } catch (error) {
3987        let err = error as BusinessError;
3988    }
3989    return videoRotation;
3990}
3991
3992//获取deviceDegree。
3993function getDeviceDegree(): number {
3994    let deviceDegree: number = -1;
3995    try {
3996        sensor.once(sensor.SensorId.GRAVITY, (data: sensor.GravityResponse) => {
3997            console.info('Succeeded in invoking once. X-coordinate component: ' + data.x);
3998            console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y);
3999            console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z);
4000            let x = data.x;
4001            let y = data.y;
4002            let z = data.z;
4003            if ((x * x + y * y) * 3 < z * z) {
4004                deviceDegree = -1;
4005            } else {
4006                let sd: Decimal = Decimal.atan2(y, -x);
4007                let sc: Decimal = Decimal.round(Number(sd) / 3.141592653589 * 180)
4008                deviceDegree = 90 - Number(sc);
4009                deviceDegree = deviceDegree >= 0 ? deviceDegree% 360 : deviceDegree% 360 + 360;
4010            }
4011        });
4012    } catch (error) {
4013        let err: BusinessError = error as BusinessError;
4014    }
4015    return deviceDegree;
4016}
4017```
4018
4019## MetadataOutput
4020
4021metadata流。继承[CameraOutput](#cameraoutput)。
4022
4023### start
4024
4025start(callback: AsyncCallback\<void\>): void
4026
4027开始输出metadata,通过注册回调函数获取结果。使用callback异步回调。
4028
4029**系统能力:** SystemCapability.Multimedia.Camera.Core
4030
4031**参数:**
4032
4033| 参数名     | 类型                                                         | 必填 | 说明                 |
4034| -------- | -------------------------- | ---- | ------------------- |
4035| callback | AsyncCallback\<void\>       | 是   | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
4036
4037**错误码:**
4038
4039以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
4040
4041| 错误码ID         | 错误信息        |
4042| --------------- | --------------- |
4043| 7400103                |  Session not config.                                   |
4044| 7400201                |  Camera service fatal error.                           |
4045
4046**示例:**
4047
4048```ts
4049import { BusinessError } from '@kit.BasicServicesKit';
4050
4051function startMetadataOutput(metadataOutput: camera.MetadataOutput): void {
4052  metadataOutput.start((err: BusinessError) => {
4053    if (err) {
4054      console.error(`Failed to start metadata output, error code: ${err.code}.`);
4055      return;
4056    }
4057    console.info('Callback returned with metadata output started.');
4058  });
4059}
4060```
4061
4062### start
4063
4064start(): Promise\<void\>
4065
4066开始输出metadata,通过Promise获取结果。
4067
4068**系统能力:** SystemCapability.Multimedia.Camera.Core
4069
4070**返回值:**
4071
4072| 类型                     | 说明                     |
4073| ----------------------  | ------------------------ |
4074| Promise\<void\>          | 无返回结果的Promise对象。 |
4075
4076**错误码:**
4077
4078以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
4079
4080| 错误码ID         | 错误信息        |
4081| --------------- | --------------- |
4082| 7400103                |  Session not config.                                   |
4083| 7400201                |  Camera service fatal error.                           |
4084
4085**示例:**
4086
4087```ts
4088import { BusinessError } from '@kit.BasicServicesKit';
4089
4090function startMetadataOutput(metadataOutput: camera.MetadataOutput): void {
4091  metadataOutput.start().then(() => {
4092    console.info('Callback returned with metadata output started.');
4093  }).catch((error: BusinessError) => {
4094    console.error(`Failed to metadata output stop, error code: ${error.code}`);
4095  });
4096}
4097```
4098
4099### stop
4100
4101stop(callback: AsyncCallback\<void\>): void
4102
4103停止输出metadata,通过注册回调函数获取结果。使用callback异步回调。
4104
4105**系统能力:** SystemCapability.Multimedia.Camera.Core
4106
4107**参数:**
4108
4109| 参数名     | 类型                         | 必填 | 说明                  |
4110| -------- | -------------------------- | ---- | ------------------- |
4111| callback | AsyncCallback\<void\>       | 是   | 回调函数,用于获取结果。 |
4112
4113**示例:**
4114
4115```ts
4116import { BusinessError } from '@kit.BasicServicesKit';
4117
4118function stopMetadataOutput(metadataOutput: camera.MetadataOutput): void {
4119  metadataOutput.stop((err: BusinessError) => {
4120    if (err) {
4121      console.error(`Failed to stop the metadata output, error code: ${err.code}.`);
4122      return;
4123    }
4124    console.info('Callback returned with metadata output stopped.');
4125  })
4126}
4127```
4128
4129### stop
4130
4131stop(): Promise\<void\>
4132
4133停止输出metadata,通过Promise获取结果。
4134
4135**系统能力:** SystemCapability.Multimedia.Camera.Core
4136
4137**返回值:**
4138
4139| 类型                    | 说明                        |
4140| ----------------------  | --------------------------- |
4141| Promise\<void\>         | 无返回结果的Promise对象。 |
4142
4143**示例:**
4144
4145```ts
4146import { BusinessError } from '@kit.BasicServicesKit';
4147
4148function stopMetadataOutput(metadataOutput: camera.MetadataOutput): void {
4149  metadataOutput.stop().then(() => {
4150    console.info('Callback returned with metadata output stopped.');
4151  }).catch((error: BusinessError) => {
4152    console.error(`Failed to metadata output stop, error code: ${error.code}`);
4153  });
4154}
4155```
4156
4157### on('metadataObjectsAvailable')
4158
4159on(type: 'metadataObjectsAvailable', callback: AsyncCallback\<Array\<MetadataObject\>\>): void
4160
4161监听检测到的metadata对象,通过注册回调函数获取结果。使用callback异步回调。
4162
4163> **说明:**
4164>
4165> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
4166
4167**系统能力:** SystemCapability.Multimedia.Camera.Core
4168
4169**参数:**
4170
4171| 参数名      | 类型         | 必填 | 说明                                  |
4172| -------- | -------------- | ---- | ------------------------------------ |
4173| type     | string         | 是   | 监听事件,固定为'metadataObjectsAvailable',metadataOutput创建成功后可监听。检测到有效的metadata数据时触发该事件发生并返回相应的metadata数据。 |
4174| callback | AsyncCallback\<Array\<[MetadataObject](#metadataobject)\>\> | 是   | 回调函数,用于获取metadata数据。 |
4175
4176**示例:**
4177
4178```ts
4179import { BusinessError } from '@kit.BasicServicesKit';
4180
4181function callback(err: BusinessError, metadataObjectArr: Array<camera.MetadataObject>): void {
4182  if (err !== undefined && err.code !== 0) {
4183    console.error(`Callback Error, errorCode: ${err.code}`);
4184    return;
4185  }
4186  console.info('metadata output metadataObjectsAvailable');
4187}
4188
4189function registerMetadataObjectsAvailable(metadataOutput: camera.MetadataOutput): void {
4190  metadataOutput.on('metadataObjectsAvailable', callback);
4191}
4192```
4193
4194### off('metadataObjectsAvailable')
4195
4196off(type: 'metadataObjectsAvailable', callback?: AsyncCallback\<Array\<MetadataObject\>\>): void
4197
4198注销监听检测到的metadata对象。
4199
4200**系统能力:** SystemCapability.Multimedia.Camera.Core
4201
4202**参数:**
4203
4204| 参数名      | 类型         | 必填 | 说明                                  |
4205| -------- | -------------- | ---- | ------------------------------------ |
4206| type     | string         | 是   | 监听事件,固定为'metadataObjectsAvailable',metadataOutput创建成功后可监听。 |
4207| callback | AsyncCallback\<Array\<[MetadataObject](#metadataobject)\>\> | 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
4208
4209**示例:**
4210
4211```ts
4212function unregisterMetadataObjectsAvailable(metadataOutput: camera.MetadataOutput): void {
4213  metadataOutput.off('metadataObjectsAvailable');
4214}
4215```
4216
4217### on('error')
4218
4219on(type: 'error', callback: ErrorCallback): void
4220
4221监听metadata流的错误,通过注册回调函数获取结果。使用callback异步回调。
4222
4223> **说明:**
4224>
4225> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
4226
4227**系统能力:** SystemCapability.Multimedia.Camera.Core
4228
4229**参数:**
4230
4231| 参数名     | 类型         | 必填 | 说明                                     |
4232| -------- | ------------- | ---- | --------------------------------------- |
4233| type     | string        | 是   | 监听事件,固定为'error',metadataOutput创建成功后可监听。metadata接口使用错误时触发该事件并返回对应错误码,比如调用[start](#start-3),[CameraOutput.release](#release-1)接口时发生错误返回对应错误信息。 |
4234| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | 是   | 回调函数,用于获取错误信息。返回错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。            |
4235
4236**示例:**
4237
4238```ts
4239import { BusinessError } from '@kit.BasicServicesKit';
4240
4241function callback(metadataOutputError: BusinessError): void {
4242  console.error(`Metadata output error code: ${metadataOutputError.code}`);
4243}
4244
4245function registerMetadataOutputError(metadataOutput: camera.MetadataOutput): void {
4246  metadataOutput.on('error', callback);
4247}
4248```
4249
4250### off('error')
4251
4252off(type: 'error', callback?: ErrorCallback): void
4253
4254注销监听metadata流的错误。
4255
4256**系统能力:** SystemCapability.Multimedia.Camera.Core
4257
4258**参数:**
4259
4260| 参数名     | 类型         | 必填 | 说明                                     |
4261| -------- | ------------- | ---- | --------------------------------------- |
4262| type     | string        | 是   | 监听事件,固定为'error',metadataOutput创建成功后可监听。 |
4263| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
4264
4265**示例:**
4266
4267```ts
4268function unregisterMetadataOutputError(metadataOutput: camera.MetadataOutput): void {
4269  metadataOutput.off('error');
4270}
4271```
4272
4273## MetadataObjectType
4274
4275枚举,metadata流。
4276
4277**系统能力:** SystemCapability.Multimedia.Camera.Core
4278
4279| 名称                       | 值   | 说明              |
4280| ------------------------- | ---- | ----------------- |
4281| FACE_DETECTION            | 0    | metadata对象类型,用于人脸检测。<br> 检测点应在0-1坐标系内,该坐标系左上角为(0,0),右下角为(1,1)。<br> 此坐标系以设备充电口在右侧时的横向设备方向为基准。<br>例如应用的预览界面布局以设备充电口在下侧时的竖向方向为基准,<br>布局宽高为(w,h), 返回点为(x,y),则转换后的坐标点为(1-y,x)。 |
4282
4283## Rect
4284
4285矩形定义。
4286
4287**系统能力:** SystemCapability.Multimedia.Camera.Core
4288
4289| 名称      | 类型   |  只读  | 可选  |           说明         |
4290| -------- | ------ | ------ |-----| --------------------- |
4291| topLeftX | number |   否   | 否   | 矩形区域左上角x坐标。   |
4292| topLeftY | number |   否   | 否   | 矩形区域左上角y坐标。   |
4293| width    | number |   否   | 否   | 矩形宽,相对值,范围[0, 1]。  |
4294| height   | number |   否   | 否   | 矩形高,相对值,范围[0, 1]。  |
4295
4296## MetadataObject
4297
4298相机元能力信息,[CameraInput](#camerainput)相机信息中的数据来源,通过metadataOutput.on('metadataObjectsAvailable')接口获取。
4299
4300**系统能力:** SystemCapability.Multimedia.Camera.Core
4301
4302| 名称         | 类型                                        | 只读 | 可选 |说明                |
4303| ----------- | ------------------------------------------- | ---- | ---- | ----------------- |
4304| type        | [MetadataObjectType](#metadataobjecttype)   |  是  |  否  | metadata 类型。    |
4305| timestamp   | number                                      |  是  |  否  | 当前时间戳(毫秒)。|
4306| boundingBox | [Rect](#rect)                               |  是  |  否  | metadata 区域框。  |
4307
4308## FlashMode
4309
4310枚举,闪光灯模式。
4311
4312**系统能力:** SystemCapability.Multimedia.Camera.Core
4313
4314| 名称                    | 值   | 说明        |
4315| ---------------------- | ---- | ---------- |
4316| FLASH_MODE_CLOSE       | 0    | 闪光灯关闭。 |
4317| FLASH_MODE_OPEN        | 1    | 闪光灯打开。 |
4318| FLASH_MODE_AUTO        | 2    | 自动闪光灯。 |
4319| FLASH_MODE_ALWAYS_OPEN | 3    | 闪光灯常亮。 |
4320
4321## ExposureMode
4322
4323枚举,曝光模式。
4324
4325**系统能力:** SystemCapability.Multimedia.Camera.Core
4326
4327| 名称                           | 值   | 说明         |
4328| ----------------------------- | ---- | ----------- |
4329| EXPOSURE_MODE_LOCKED          | 0    | 锁定曝光模式。不支持曝光区域中心点设置。 |
4330| EXPOSURE_MODE_AUTO            | 1    | 自动曝光模式。支持曝光区域中心点设置,可以使用[AutoExposure.setMeteringPoint](#setmeteringpoint11)设置曝光区域中心点。 |
4331| EXPOSURE_MODE_CONTINUOUS_AUTO | 2    | 连续自动曝光。不支持曝光区域中心点设置。 |
4332
4333## FocusMode
4334
4335枚举,焦距模式。
4336
4337**系统能力:** SystemCapability.Multimedia.Camera.Core
4338
4339| 名称                        | 值   | 说明          |
4340| -------------------------- | ---- | ------------ |
4341| FOCUS_MODE_MANUAL          | 0    | 手动对焦。通过手动修改相机焦距来改变对焦位置,不支持对焦点设置。     |
4342| FOCUS_MODE_CONTINUOUS_AUTO | 1    | 连续自动对焦。不支持对焦点设置。 |
4343| FOCUS_MODE_AUTO            | 2    | 自动对焦。支持对焦点设置,可以使用[Focus.setFocusPoint](#setfocuspoint11)设置对焦点,根据对焦点执行一次自动对焦。    |
4344| FOCUS_MODE_LOCKED          | 3    | 对焦锁定。不支持对焦点设置。     |
4345
4346## FocusState
4347
4348枚举,焦距状态。
4349
4350**系统能力:** SystemCapability.Multimedia.Camera.Core
4351
4352| 名称                   | 值   | 说明       |
4353| --------------------- | ---- | --------- |
4354| FOCUS_STATE_SCAN      | 0    | 触发对焦。  |
4355| FOCUS_STATE_FOCUSED   | 1    | 对焦成功。  |
4356| FOCUS_STATE_UNFOCUSED | 2    | 未完成对焦。 |
4357
4358## VideoStabilizationMode
4359
4360枚举,视频防抖模式。
4361
4362**系统能力:** SystemCapability.Multimedia.Camera.Core
4363
4364| 名称       | 值   | 说明         |
4365| --------- | ---- | ------------ |
4366| OFF       | 0    | 关闭视频防抖功能。   |
4367| LOW       | 1    | 使用基础防抖算法。   |
4368| MIDDLE    | 2    | 使用防抖效果一般的防抖算法,防抖效果优于LOW类型。   |
4369| HIGH      | 3    | 使用防抖效果最好的防抖算法,防抖效果优于MIDDLE类型。   |
4370| AUTO      | 4    | 自动进行选择。   |
4371
4372## Session<sup>11+</sup>
4373
4374会话类,保存一次相机运行所需要的所有资源[CameraInput](#camerainput)、[CameraOutput](#cameraoutput),并向相机设备申请完成相机功能(录像,拍照)。
4375
4376### beginConfig<sup>11+</sup>
4377
4378beginConfig(): void
4379
4380开始配置会话。
4381
4382**系统能力:** SystemCapability.Multimedia.Camera.Core
4383
4384**错误码:**
4385
4386以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
4387
4388| 错误码ID         | 错误信息        |
4389| --------------- | --------------- |
4390| 7400105                |  Session config locked.               |
4391| 7400201                |  Camera service fatal error.               |
4392
4393**示例:**
4394
4395```ts
4396import { BusinessError } from '@kit.BasicServicesKit';
4397
4398function beginConfig(session: camera.Session): void {
4399  try {
4400    session.beginConfig();
4401  } catch (error) {
4402    // 失败返回错误码error.code并处理。
4403    let err = error as BusinessError;
4404    console.error(`The beginConfig call failed. error code: ${err.code}`);
4405  }
4406}
4407```
4408
4409### commitConfig<sup>11+</sup>
4410
4411commitConfig(callback: AsyncCallback\<void\>): void
4412
4413提交配置信息,通过注册回调函数获取结果。使用callback异步回调。
4414
4415**系统能力:** SystemCapability.Multimedia.Camera.Core
4416
4417**参数:**
4418
4419| 参数名     | 类型                   | 必填 | 说明                  |
4420| -------- | -------------------- | ---- | -------------------- |
4421| callback | AsyncCallback\<void\> | 是   | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
4422
4423**错误码:**
4424
4425以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
4426
4427| 错误码ID         | 错误信息        |
4428| --------------- | --------------- |
4429| 7400102                |  Operation not allowed.                                  |
4430| 7400201                |  Camera service fatal error.                           |
4431
4432**示例:**
4433
4434```ts
4435import { BusinessError } from '@kit.BasicServicesKit';
4436
4437function commitConfig(session: camera.Session): void {
4438  session.commitConfig((err: BusinessError) => {
4439    if (err) {
4440      console.error(`The commitConfig call failed. error code: ${err.code}`);
4441      return;
4442    }
4443    console.info('Callback invoked to indicate the commit config success.');
4444  });
4445}
4446```
4447
4448### commitConfig<sup>11+</sup>
4449
4450commitConfig(): Promise\<void\>
4451
4452提交配置信息,通过Promise获取结果。
4453
4454**系统能力:** SystemCapability.Multimedia.Camera.Core
4455
4456**返回值:**
4457
4458| 类型            | 说明                     |
4459| -------------- | ------------------------ |
4460| Promise\<void\> | 无返回结果的Promise对象。 |
4461
4462**错误码:**
4463
4464以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
4465
4466| 错误码ID         | 错误信息        |
4467| --------------- | --------------- |
4468| 7400102                |  Operation not allowed.                                  |
4469| 7400201                |  Camera service fatal error.                           |
4470
4471**示例:**
4472
4473```ts
4474import { BusinessError } from '@kit.BasicServicesKit';
4475
4476function commitConfig(session: camera.Session): void {
4477  session.commitConfig().then(() => {
4478    console.info('Promise returned to indicate the commit config success.');
4479  }).catch((error: BusinessError) => {
4480    // 失败返回错误码error.code并处理。
4481    console.error(`The commitConfig call failed. error code: ${error.code}`);
4482  });
4483}
4484```
4485
4486### canAddInput<sup>11+</sup>
4487
4488canAddInput(cameraInput: CameraInput): boolean
4489
4490判断当前cameraInput是否可以添加到session中。当前函数需要在[beginConfig](#beginconfig11)和[commitConfig](#commitconfig11-1)之间生效。
4491
4492**系统能力:** SystemCapability.Multimedia.Camera.Core
4493
4494**参数:**
4495
4496| 参数名        | 类型                          | 必填 | 说明                     |
4497| ----------- | --------------------------- | ---- | ------------------------ |
4498| cameraInput | [CameraInput](#camerainput) | 是   | 需要添加的CameraInput实例。传参异常(如超出范围、传入null、未定义等),实际接口不会生效。 |
4499
4500**返回值:**
4501
4502| 类型            | 说明                     |
4503| -------------- | ------------------------ |
4504| boolean | 返回true表示支持添加当前cameraInput,返回false表示不支持添加。 |
4505
4506**示例:**
4507
4508```ts
4509import { BusinessError } from '@kit.BasicServicesKit';
4510
4511function canAddInput(session: camera.Session, cameraInput: camera.CameraInput): void {
4512  let canAdd: boolean = session.canAddInput(cameraInput);
4513  console.info(`The input canAddInput: ${canAdd}`);
4514}
4515```
4516
4517### addInput<sup>11+</sup>
4518
4519addInput(cameraInput: CameraInput): void
4520
4521把[CameraInput](#camerainput)加入到会话。
4522
4523**系统能力:** SystemCapability.Multimedia.Camera.Core
4524
4525**参数:**
4526
4527| 参数名        | 类型                          | 必填 | 说明                     |
4528| ----------- | --------------------------- | ---- | ------------------------ |
4529| cameraInput | [CameraInput](#camerainput) | 是   | 需要添加的CameraInput实例。 |
4530
4531**错误码:**
4532
4533以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
4534
4535| 错误码ID         | 错误信息        |
4536| --------------- | --------------- |
4537| 7400101                |  Parameter missing or parameter type incorrect.        |
4538| 7400102                |  Operation not allowed.                                  |
4539| 7400103                |  Session not config.                                   |
4540| 7400201                |  Camera service fatal error.                                   |
4541
4542**示例:**
4543
4544```ts
4545import { BusinessError } from '@kit.BasicServicesKit';
4546
4547function addInput(session: camera.Session, cameraInput: camera.CameraInput): void {
4548  try {
4549    session.addInput(cameraInput);
4550  } catch (error) {
4551    // 失败返回错误码error.code并处理。
4552    let err = error as BusinessError;
4553    console.error(`The addInput call failed. error code: ${err.code}`);
4554  }
4555}
4556```
4557
4558### removeInput<sup>11+</sup>
4559
4560removeInput(cameraInput: CameraInput): void
4561
4562移除[CameraInput](#camerainput)。当前函数需要在[beginConfig](#beginconfig11)和[commitConfig](#commitconfig11-1)之间生效。
4563
4564**系统能力:** SystemCapability.Multimedia.Camera.Core
4565
4566**参数:**
4567
4568| 参数名        | 类型                          | 必填 | 说明                      |
4569| ----------- | --------------------------- | ---- | ------------------------ |
4570| cameraInput | [CameraInput](#camerainput) | 是   | 需要移除的CameraInput实例。 |
4571
4572**错误码:**
4573
4574以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
4575
4576| 错误码ID         | 错误信息        |
4577| --------------- | --------------- |
4578| 7400101                |  Parameter missing or parameter type incorrect.        |
4579| 7400102                |  Operation not allowed.                                  |
4580| 7400103                |  Session not config.                                   |
4581| 7400201                |  Camera service fatal error.                                   |
4582
4583**示例:**
4584
4585```ts
4586import { BusinessError } from '@kit.BasicServicesKit';
4587
4588function removeInput(session: camera.Session, cameraInput: camera.CameraInput): void {
4589  try {
4590    session.removeInput(cameraInput);
4591  } catch (error) {
4592    // 失败返回错误码error.code并处理。
4593    let err = error as BusinessError;
4594    console.error(`The removeInput call failed. error code: ${err.code}`);
4595  }
4596}
4597```
4598
4599### canAddOutput<sup>11+</sup>
4600
4601canAddOutput(cameraOutput: CameraOutput): boolean
4602
4603判断当前cameraOutput是否可以添加到session中。当前函数需要在[addInput](#addinput11)和[commitConfig](#commitconfig11-1)之间生效。
4604
4605**系统能力:** SystemCapability.Multimedia.Camera.Core
4606
4607**参数:**
4608
4609| 参数名        | 类型                          | 必填 | 说明                     |
4610| ----------- | --------------------------- | ---- | ------------------------ |
4611| cameraOutput | [CameraOutput](#cameraoutput) | 是   | 需要添加的CameraOutput实例。传参异常(如超出范围、传入null、未定义等),实际接口不会生效。 |
4612
4613**返回值:**
4614
4615| 类型            | 说明                     |
4616| -------------- | ------------------------ |
4617| boolean | 是否可以添加当前cameraOutput到session中。 |
4618
4619**示例:**
4620
4621```ts
4622import { BusinessError } from '@kit.BasicServicesKit';
4623
4624function canAddOutput(session: camera.Session, cameraOutput: camera.CameraOutput): void {
4625  let canAdd: boolean = session.canAddOutput(cameraOutput);
4626  console.info(`This addOutput can add: ${canAdd}`);
4627}
4628```
4629
4630### addOutput<sup>11+</sup>
4631
4632addOutput(cameraOutput: CameraOutput): void
4633
4634把[CameraOutput](#cameraoutput)加入到会话。
4635
4636**系统能力:** SystemCapability.Multimedia.Camera.Core
4637
4638**参数:**
4639
4640| 参数名           | 类型                             | 必填 | 说明                      |
4641| ------------- | ------------------------------- | ---- | ------------------------ |
4642| cameraOutput  | [CameraOutput](#cameraoutput)   | 是   | 需要添加的CameraOutput实例。 |
4643
4644**错误码:**
4645
4646以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
4647
4648| 错误码ID         | 错误信息        |
4649| --------------- | --------------- |
4650| 7400101                |  Parameter missing or parameter type incorrect.        |
4651| 7400102                |  Operation not allowed.                                  |
4652| 7400103                |  Session not config.                                   |
4653| 7400201                |  Camera service fatal error.                                   |
4654
4655**示例:**
4656
4657```ts
4658import { BusinessError } from '@kit.BasicServicesKit';
4659
4660function addOutput(session: camera.Session, cameraOutput: camera.CameraOutput): void {
4661  try {
4662    session.addOutput(cameraOutput);
4663  } catch (error) {
4664    // 失败返回错误码error.code并处理。
4665    let err = error as BusinessError;
4666    console.error(`The addOutput call failed. error code: ${err.code}`);
4667  }
4668}
4669```
4670
4671### removeOutput<sup>11+</sup>
4672
4673removeOutput(cameraOutput: CameraOutput): void
4674
4675从会话中移除[CameraOutput](#cameraoutput)。
4676
4677**系统能力:** SystemCapability.Multimedia.Camera.Core
4678
4679**参数:**
4680
4681| 参数名           | 类型                             | 必填 | 说明                      |
4682| ------------- | ------------------------------- | ---- | ------------------------ |
4683| cameraOutput  | [CameraOutput](#cameraoutput)   | 是   | 需要移除的CameraOutput实例。 |
4684
4685**错误码:**
4686
4687以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
4688
4689| 错误码ID         | 错误信息        |
4690| --------------- | --------------- |
4691| 7400101                |  Parameter missing or parameter type incorrect.        |
4692| 7400102                |  Operation not allowed.                                  |
4693| 7400103                |  Session not config.                                   |
4694| 7400201                |  Camera service fatal error.                                   |
4695
4696**示例:**
4697
4698```ts
4699import { BusinessError } from '@kit.BasicServicesKit';
4700
4701function removeOutput(session: camera.Session, previewOutput: camera.PreviewOutput): void {
4702  try {
4703    session.removeOutput(previewOutput);
4704  } catch (error) {
4705    // 失败返回错误码error.code并处理。
4706    let err = error as BusinessError;
4707    console.error(`The removeOutput call failed. error code: ${err.code}`);
4708  }
4709}
4710```
4711
4712### start<sup>11+</sup>
4713
4714start(callback: AsyncCallback\<void\>): void
4715
4716开始会话工作,通过注册回调函数获取结果。使用callback异步回调。
4717
4718**系统能力:** SystemCapability.Multimedia.Camera.Core
4719
4720**参数:**
4721
4722| 参数名      | 类型                  | 必填 | 说明                 |
4723| -------- | -------------------- | ---- | -------------------- |
4724| callback | AsyncCallback\<void\> | 是   | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
4725
4726**错误码:**
4727
4728以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
4729
4730| 错误码ID         | 错误信息        |
4731| --------------- | --------------- |
4732| 7400102                |  Operation not allowed.                                |
4733| 7400103                |  Session not config.                                   |
4734| 7400201                |  Camera service fatal error.                           |
4735
4736**示例:**
4737
4738```ts
4739import { BusinessError } from '@kit.BasicServicesKit';
4740
4741function startCaptureSession(session: camera.Session): void {
4742  session.start((err: BusinessError) => {
4743    if (err) {
4744      console.error(`Failed to start the session, error code: ${err.code}.`);
4745      return;
4746    }
4747    console.info('Callback invoked to indicate the session start success.');
4748  });
4749}
4750```
4751
4752### start<sup>11+</sup>
4753
4754start(): Promise\<void\>
4755
4756开始会话工作,通过Promise获取结果。
4757
4758**系统能力:** SystemCapability.Multimedia.Camera.Core
4759
4760**返回值:**
4761
4762| 类型            | 说明                     |
4763| -------------- | ------------------------ |
4764| Promise\<void\> | 无返回结果的Promise对象。 |
4765
4766**错误码:**
4767
4768以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
4769
4770| 错误码ID         | 错误信息        |
4771| --------------- | --------------- |
4772| 7400102                |  Operation not allowed.                                |
4773| 7400103                |  Session not config.                                   |
4774| 7400201                |  Camera service fatal error.                           |
4775
4776**示例:**
4777
4778```ts
4779import { BusinessError } from '@kit.BasicServicesKit';
4780
4781function startCaptureSession(session: camera.Session): void {
4782  session.start().then(() => {
4783    console.info('Promise returned to indicate the session start success.');
4784  }).catch((error: BusinessError) => {
4785    console.error(`Failed to start the session, error code: ${error.code}.`);
4786  });
4787}
4788```
4789
4790### stop<sup>11+</sup>
4791
4792stop(callback: AsyncCallback\<void\>): void
4793
4794停止会话工作,通过注册回调函数获取结果。使用callback异步回调。
4795
4796**系统能力:** SystemCapability.Multimedia.Camera.Core
4797
4798**参数:**
4799
4800| 参数名      | 类型                  | 必填 | 说明                 |
4801| -------- | -------------------- | ---- | ------------------- |
4802| callback | AsyncCallback\<void\> | 是   | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
4803
4804**错误码:**
4805
4806以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
4807
4808| 错误码ID         | 错误信息        |
4809| --------------- | --------------- |
4810| 7400201                |  Camera service fatal error.                           |
4811
4812**示例:**
4813
4814```ts
4815import { BusinessError } from '@kit.BasicServicesKit';
4816
4817function stopCaptureSession(session: camera.Session): void {
4818  session.stop((err: BusinessError) => {
4819    if (err) {
4820      console.error(`Failed to stop the session, error code: ${err.code}.`);
4821      return;
4822    }
4823    console.info('Callback invoked to indicate the session stop success.');
4824  });
4825}
4826```
4827
4828### stop<sup>11+</sup>
4829
4830stop(): Promise\<void\>
4831
4832停止会话工作,通过Promise获取结果。
4833
4834**系统能力:** SystemCapability.Multimedia.Camera.Core
4835
4836**返回值:**
4837
4838| 类型            | 说明                |
4839| -------------- |-------------------|
4840| Promise\<void\> | 无返回结果的Promise对象。  |
4841
4842**错误码:**
4843
4844以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
4845
4846| 错误码ID         | 错误信息        |
4847| --------------- | --------------- |
4848| 7400201                |  Camera service fatal error.                           |
4849
4850**示例:**
4851
4852```ts
4853import { BusinessError } from '@kit.BasicServicesKit';
4854
4855function stopCaptureSession(session: camera.Session): void {
4856  session.stop().then(() => {
4857    console.info('Promise returned to indicate the session stop success.');
4858  }).catch((error: BusinessError) => {
4859    console.error(`Failed to stop the session, error code: ${error.code}.`);
4860  });
4861}
4862```
4863
4864### release<sup>11+</sup>
4865
4866release(callback: AsyncCallback\<void\>): void
4867
4868释放会话资源,通过注册回调函数获取结果。使用callback异步回调。
4869
4870**系统能力:** SystemCapability.Multimedia.Camera.Core
4871
4872**参数:**
4873
4874| 参数名      | 类型                  | 必填 | 说明                 |
4875| -------- | -------------------- | ---- | -------------------- |
4876| callback | AsyncCallback\<void\> | 是   | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
4877
4878**错误码:**
4879
4880以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
4881
4882| 错误码ID         | 错误信息        |
4883| --------------- | --------------- |
4884| 7400201                |  Camera service fatal error.                           |
4885
4886**示例:**
4887
4888```ts
4889import { BusinessError } from '@kit.BasicServicesKit';
4890
4891function releaseCaptureSession(session: camera.Session): void {
4892  session.release((err: BusinessError) => {
4893    if (err) {
4894      console.error(`Failed to release the session instance, error code: ${err.code}.`);
4895      return;
4896    }
4897    console.info('Callback invoked to indicate that the session instance is released successfully.');
4898  });
4899}
4900```
4901
4902### release<sup>11+</sup>
4903
4904release(): Promise\<void\>
4905
4906释放会话资源,通过Promise获取结果。
4907
4908**系统能力:** SystemCapability.Multimedia.Camera.Core
4909
4910**返回值:**
4911
4912| 类型            | 说明                     |
4913| -------------- | ------------------------ |
4914| Promise\<void\> | 无返回结果的Promise对象。 |
4915
4916**错误码:**
4917
4918以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
4919
4920| 错误码ID         | 错误信息        |
4921| --------------- | --------------- |
4922| 7400201                |  Camera service fatal error.                           |
4923
4924**示例:**
4925
4926```ts
4927import { BusinessError } from '@kit.BasicServicesKit';
4928
4929function releaseCaptureSession(session: camera.Session): void {
4930  session.release().then(() => {
4931    console.info('Promise returned to indicate that the session instance is released successfully.');
4932  }).catch((error: BusinessError) => {
4933    console.error(`Failed to release the session instance, error code: ${error.code}.`);
4934  });
4935}
4936```
4937
4938## Flash<sup>11+</sup>
4939
4940Flash extends [FlashQuery](#flashquery12)
4941
4942闪光灯类,对设备闪光灯操作。
4943
4944### setFlashMode<sup>11+</sup>
4945
4946setFlashMode(flashMode: FlashMode): void
4947
4948设置闪光灯模式。
4949
4950进行设置之前,需要先检查:
4951
49521. 设备是否支持闪光灯,可使用方法[hasFlash](#hasflash11)。
49532. 设备是否支持指定的闪光灯模式,可使用方法[isFlashModeSupported](#isflashmodesupported11)。
4954
4955**系统能力:** SystemCapability.Multimedia.Camera.Core
4956
4957**参数:**
4958
4959| 参数名       | 类型                     | 必填 | 说明                  |
4960| --------- | ----------------------- | ---- | --------------------- |
4961| flashMode | [FlashMode](#flashmode) | 是   | 指定闪光灯模式。传参为null或者undefined,作为0处理,闪光灯关闭。       |
4962
4963**错误码:**
4964
4965以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
4966
4967| 错误码ID         | 错误信息        |
4968| --------------- | --------------- |
4969| 7400103                |  Session not config.                                   |
4970
4971**示例:**
4972
4973```ts
4974import { BusinessError } from '@kit.BasicServicesKit';
4975
4976function setFlashMode(photoSession: camera.PhotoSession): void {
4977  try {
4978    photoSession.setFlashMode(camera.FlashMode.FLASH_MODE_AUTO);
4979  } catch (error) {
4980    // 失败返回错误码error.code并处理。
4981    let err = error as BusinessError;
4982    console.error(`The setFlashMode call failed. error code: ${err.code}`);
4983  }
4984}
4985```
4986
4987### getFlashMode<sup>11+</sup>
4988
4989getFlashMode(): FlashMode
4990
4991获取当前设备的闪光灯模式。
4992
4993**系统能力:** SystemCapability.Multimedia.Camera.Core
4994
4995**返回值:**
4996
4997| 类型        | 说明                          |
4998| ---------- | ----------------------------- |
4999| [FlashMode](#flashmode)    | 获取当前设备的闪光灯模式。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
5000
5001**错误码:**
5002
5003以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
5004
5005| 错误码ID         | 错误信息        |
5006| --------------- | --------------- |
5007| 7400103                |  Session not config.                                   |
5008
5009**示例:**
5010
5011```ts
5012import { BusinessError } from '@kit.BasicServicesKit';
5013
5014function getFlashMode(photoSession: camera.PhotoSession): camera.FlashMode | undefined {
5015  let flashMode: camera.FlashMode | undefined = undefined;
5016  try {
5017    flashMode = photoSession.getFlashMode();
5018  } catch (error) {
5019    // 失败返回错误码error.code并处理。
5020    let err = error as BusinessError;
5021    console.error(`The getFlashMode call failed.error code: ${err.code}`);
5022  }
5023  return flashMode;
5024}
5025```
5026
5027## FlashQuery<sup>12+</sup>
5028
5029提供了查询设备的闪光灯状态和模式的能力。
5030
5031### hasFlash<sup>11+</sup>
5032
5033hasFlash(): boolean
5034
5035检测是否有闪光灯,通过注册回调函数获取结果。
5036
5037**系统能力:** SystemCapability.Multimedia.Camera.Core
5038
5039**返回值:**
5040
5041| 类型        | 说明                          |
5042| ---------- | ----------------------------- |
5043| boolean    | 返回true表示设备支持闪光灯,false表示不支持。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
5044
5045**错误码:**
5046
5047以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
5048
5049| 错误码ID         | 错误信息        |
5050| --------------- | --------------- |
5051| 7400103                |  Session not config, only throw in session usage.       |
5052
5053**示例:**
5054
5055```ts
5056import { BusinessError } from '@kit.BasicServicesKit';
5057
5058function hasFlash(photoSession: camera.PhotoSession): boolean {
5059  let status: boolean = false;
5060  try {
5061    status = photoSession.hasFlash();
5062  } catch (error) {
5063    // 失败返回错误码error.code并处理。
5064    let err = error as BusinessError;
5065    console.error(`The hasFlash call failed. error code: ${err.code}`);
5066  }
5067  return status;
5068}
5069```
5070
5071### isFlashModeSupported<sup>11+</sup>
5072
5073isFlashModeSupported(flashMode: FlashMode): boolean
5074
5075检测闪光灯模式是否支持。
5076
5077**系统能力:** SystemCapability.Multimedia.Camera.Core
5078
5079**参数:**
5080
5081| 参数名       | 类型                     | 必填 | 说明                               |
5082| --------- | ----------------------- | ---- | --------------------------------- |
5083| flashMode | [FlashMode](#flashmode) | 是   | 指定闪光灯模式。传参为null或者undefined,作为0处理,闪光灯关闭。             |
5084
5085**返回值:**
5086
5087| 类型        | 说明                          |
5088| ---------- | ----------------------------- |
5089| boolean    | 返回true表示支持该闪光灯模式,false表示不支持。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
5090
5091**错误码:**
5092
5093以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
5094
5095| 错误码ID         | 错误信息        |
5096| --------------- | --------------- |
5097| 7400103                |  Session not config, only throw in session usage.             |
5098
5099**示例:**
5100
5101```ts
5102import { BusinessError } from '@kit.BasicServicesKit';
5103
5104function isFlashModeSupported(photoSession: camera.PhotoSession): boolean {
5105  let status: boolean = false;
5106  try {
5107    status = photoSession.isFlashModeSupported(camera.FlashMode.FLASH_MODE_AUTO);
5108  } catch (error) {
5109    // 失败返回错误码error.code并处理。
5110    let err = error as BusinessError;
5111    console.error(`The isFlashModeSupported call failed. error code: ${err.code}`);
5112  }
5113  return status;
5114}
5115```
5116
5117## AutoExposure<sup>11+</sup>
5118
5119AutoExposure extends [AutoExposureQuery](#autoexposurequery12)
5120
5121自动曝光类,对设备自动曝光(AE)操作。
5122
5123### getExposureMode<sup>11+</sup>
5124
5125getExposureMode(): ExposureMode
5126
5127获取当前曝光模式。
5128
5129**系统能力:** SystemCapability.Multimedia.Camera.Core
5130
5131**返回值:**
5132
5133| 类型        | 说明                          |
5134| ---------- | ----------------------------- |
5135| [ExposureMode](#exposuremode)    | 获取当前曝光模式。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
5136
5137**错误码:**
5138
5139以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
5140
5141| 错误码ID         | 错误信息        |
5142| --------------- | --------------- |
5143| 7400103                |  Session not config.                                   |
5144
5145**示例:**
5146
5147```ts
5148import { BusinessError } from '@kit.BasicServicesKit';
5149
5150function getExposureMode(photoSession: camera.PhotoSession): camera.ExposureMode | undefined {
5151  let exposureMode: camera.ExposureMode | undefined = undefined;
5152  try {
5153    exposureMode = photoSession.getExposureMode();
5154  } catch (error) {
5155    // 失败返回错误码error.code并处理。
5156    let err = error as BusinessError;
5157    console.error(`The getExposureMode call failed. error code: ${err.code}`);
5158  }
5159  return exposureMode;
5160}
5161```
5162
5163### setExposureMode<sup>11+</sup>
5164
5165setExposureMode(aeMode: ExposureMode): void
5166
5167设置曝光模式。进行设置之前,需要先检查设备是否支持指定的曝光模式,可使用方法[isExposureModeSupported](#isexposuremodesupported11)。
5168
5169**系统能力:** SystemCapability.Multimedia.Camera.Core
5170
5171**参数:**
5172
5173| 参数名      | 类型                            | 必填 | 说明                    |
5174| -------- | -------------------------------| ---- | ----------------------- |
5175| aeMode   | [ExposureMode](#exposuremode)  | 是   | 曝光模式。传参为null或者undefined,作为0处理,曝光锁定。                |
5176
5177**错误码:**
5178
5179以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
5180
5181| 错误码ID         | 错误信息        |
5182| --------------- | --------------- |
5183| 7400103                |  Session not config.                                   |
5184
5185**示例:**
5186
5187```ts
5188import { BusinessError } from '@kit.BasicServicesKit';
5189
5190function setExposureMode(photoSession: camera.PhotoSession): void {
5191  try {
5192    photoSession.setExposureMode(camera.ExposureMode.EXPOSURE_MODE_LOCKED);
5193  } catch (error) {
5194    // 失败返回错误码error.code并处理。
5195    let err = error as BusinessError;
5196    console.error(`The setExposureMode call failed. error code: ${err.code}`);
5197  }
5198}
5199```
5200
5201### getMeteringPoint<sup>11+</sup>
5202
5203getMeteringPoint(): Point
5204
5205查询曝光区域中心点。
5206
5207**系统能力:** SystemCapability.Multimedia.Camera.Core
5208
5209**返回值:**
5210
5211| 类型        | 说明                          |
5212| ---------- | ----------------------------- |
5213| [Point](#point)    | 获取当前曝光点。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
5214
5215**错误码:**
5216
5217以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
5218
5219| 错误码ID         | 错误信息        |
5220| --------------- | --------------- |
5221| 7400103                |  Session not config.                                   |
5222
5223**示例:**
5224
5225```ts
5226import { BusinessError } from '@kit.BasicServicesKit';
5227
5228function getMeteringPoint(photoSession: camera.PhotoSession): camera.Point | undefined {
5229  let exposurePoint: camera.Point | undefined = undefined;
5230  try {
5231    exposurePoint = photoSession.getMeteringPoint();
5232  } catch (error) {
5233    // 失败返回错误码error.code并处理。
5234    let err = error as BusinessError;
5235    console.error(`The getMeteringPoint call failed. error code: ${err.code}`);
5236  }
5237  return exposurePoint;
5238}
5239```
5240
5241### setMeteringPoint<sup>11+</sup>
5242
5243setMeteringPoint(point: Point): void
5244
5245设置曝光区域中心点,曝光点应在0-1坐标系内,该坐标系左上角为{0,0},右下角为{1,1}。<br>此坐标系是以设备充电口在右侧时的横向设备方向为基准的,例如应用的预览界面布局以<br>设备充电口在下侧时的竖向方向为基准,布局宽高为{w,h},且触碰点为{x,y},<br>则转换后的坐标点为{y/h,1-x/w}。
5246
5247**系统能力:** SystemCapability.Multimedia.Camera.Core
5248
5249**参数:**
5250
5251| 参数名           | 类型                            | 必填 | 说明                 |
5252| ------------- | -------------------------------| ---- | ------------------- |
5253| point | [Point](#point)                | 是   | 曝光点,x、y设置范围应在[0,1]之内,超过范围,如果小于0设置0,大于1设置1。             |
5254
5255**错误码:**
5256
5257以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
5258
5259| 错误码ID         | 错误信息        |
5260| --------------- | --------------- |
5261| 7400103                |  Session not config.                                   |
5262
5263**示例:**
5264
5265```ts
5266import { BusinessError } from '@kit.BasicServicesKit';
5267
5268function setMeteringPoint(photoSession: camera.PhotoSession): void {
5269  const point: camera.Point = {x: 1, y: 1};
5270  try {
5271    photoSession.setMeteringPoint(point);
5272  } catch (error) {
5273    // 失败返回错误码error.code并处理。
5274    let err = error as BusinessError;
5275    console.error(`The setMeteringPoint call failed. error code: ${err.code}`);
5276  }
5277}
5278```
5279
5280### getExposureBiasRange<sup>11+</sup>
5281
5282getExposureBiasRange(): Array\<number\>
5283
5284查询曝光补偿范围。
5285
5286**系统能力:** SystemCapability.Multimedia.Camera.Core
5287
5288**返回值:**
5289
5290| 类型        | 说明                          |
5291| ---------- | ----------------------------- |
5292| Array\<number\>   | 获取补偿范围的数组。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
5293
5294**错误码:**
5295
5296以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
5297
5298| 错误码ID         | 错误信息        |
5299| --------------- | --------------- |
5300| 7400103                |  Session not config, only throw in session usage.               |
5301
5302**示例:**
5303
5304```ts
5305import { BusinessError } from '@kit.BasicServicesKit';
5306
5307function getExposureBiasRange(photoSession: camera.PhotoSession): Array<number> {
5308  let biasRangeArray: Array<number> = [];
5309  try {
5310    biasRangeArray = photoSession.getExposureBiasRange();
5311  } catch (error) {
5312    // 失败返回错误码error.code并处理。
5313    let err = error as BusinessError;
5314    console.error(`The getExposureBiasRange call failed. error code: ${err.code}`);
5315  }
5316  return biasRangeArray;
5317}
5318```
5319
5320### setExposureBias<sup>11+</sup>
5321
5322setExposureBias(exposureBias: number): void
5323
5324设置曝光补偿,曝光补偿值(EV)。
5325
5326进行设置之前,建议先通过方法[getExposureBiasRange](#getexposurebiasrange11)查询支持的范围。
5327
5328**系统能力:** SystemCapability.Multimedia.Camera.Core
5329
5330**参数:**
5331
5332| 参数名     | 类型                            | 必填 | 说明                                                                                                                                                                                            |
5333| -------- | -------------------------------| ---- |-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
5334| exposureBias   | number                   | 是   | 曝光补偿,[getExposureBiasRange](#getexposurebiasrange11)查询支持的范围,如果设置超过支持范围的值,自动匹配到就近临界点。<br>曝光补偿存在步长,如步长为0.5。则设置1.2时,获取到实际生效曝光补偿为1.0。<br>接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
5335
5336**错误码:**
5337
5338以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
5339
5340| 错误码ID         | 错误信息        |
5341| --------------- | --------------- |
5342| 7400102                |  Operation not allowed.                                |
5343| 7400103                |  Session not config.                                   |
5344
5345**示例:**
5346
5347```ts
5348import { BusinessError } from '@kit.BasicServicesKit';
5349
5350function setExposureBias(photoSession: camera.PhotoSession, biasRangeArray: Array<number>): void {
5351  if (biasRangeArray && biasRangeArray.length > 0) {
5352    let exposureBias = biasRangeArray[0];
5353    try {
5354      photoSession.setExposureBias(exposureBias);
5355    } catch (error) {
5356      // 失败返回错误码error.code并处理。
5357      let err = error as BusinessError;
5358      console.error(`The setExposureBias call failed. error code: ${err.code}`);
5359    }
5360  }
5361}
5362```
5363
5364### getExposureValue<sup>11+</sup>
5365
5366getExposureValue(): number
5367
5368查询当前曝光值。
5369
5370**系统能力:** SystemCapability.Multimedia.Camera.Core
5371
5372**返回值:**
5373
5374| 类型        | 说明                          |
5375| ---------- | ----------------------------- |
5376| number    | 获取曝光值。曝光补偿存在步长,如步长为0.5。则设置1.2时,获取到实际生效曝光补偿为1.0。<br>接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
5377
5378**错误码:**
5379
5380以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
5381
5382| 错误码ID         | 错误信息        |
5383| --------------- | --------------- |
5384| 7400103                |  Session not config.                                   |
5385
5386**示例:**
5387
5388```ts
5389import { BusinessError } from '@kit.BasicServicesKit';
5390
5391function getExposureValue(photoSession: camera.PhotoSession): number {
5392  const invalidValue: number = -1;
5393  let exposureValue: number = invalidValue;
5394  try {
5395    exposureValue = photoSession.getExposureValue();
5396  } catch (error) {
5397    // 失败返回错误码error.code并处理。
5398    let err = error as BusinessError;
5399    console.error(`The getExposureValue call failed. error code: ${err.code}`);
5400  }
5401  return exposureValue;
5402}
5403```
5404
5405## AutoExposureQuery<sup>12+</sup>
5406
5407提供了针对设备的自动曝光特性提供了一系列查询功能。
5408
5409### isExposureModeSupported<sup>11+</sup>
5410
5411isExposureModeSupported(aeMode: ExposureMode): boolean
5412
5413检测曝光模式是否支持。
5414
5415**系统能力:** SystemCapability.Multimedia.Camera.Core
5416
5417**参数:**
5418
5419| 参数名      | 类型                           | 必填  | 说明                           |
5420| -------- | -------------------------------| ---- | ----------------------------- |
5421| aeMode   | [ExposureMode](#exposuremode)  | 是   | 曝光模式。传参为null或者undefined,作为0处理,曝光锁定。                 |
5422
5423**返回值:**
5424
5425| 类型        | 说明                          |
5426| ---------- | ----------------------------- |
5427| boolean    | 获取是否支持曝光模式。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
5428
5429**错误码:**
5430
5431以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
5432
5433| 错误码ID         | 错误信息        |
5434| --------------- | --------------- |
5435| 7400103                |  Session not config, only throw in session usage.          |
5436
5437**示例:**
5438
5439```ts
5440import { BusinessError } from '@kit.BasicServicesKit';
5441
5442function isExposureModeSupported(photoSession: camera.PhotoSession): boolean {
5443  let isSupported: boolean = false;
5444  try {
5445    isSupported = photoSession.isExposureModeSupported(camera.ExposureMode.EXPOSURE_MODE_LOCKED);
5446  } catch (error) {
5447    // 失败返回错误码error.code并处理。
5448    let err = error as BusinessError;
5449    console.error(`The isExposureModeSupported call failed. error code: ${err.code}`);
5450  }
5451  return isSupported;
5452}
5453```
5454
5455### getExposureBiasRange<sup>11+</sup>
5456
5457getExposureBiasRange(): Array\<number\>
5458
5459查询曝光补偿范围。
5460
5461**系统能力:** SystemCapability.Multimedia.Camera.Core
5462
5463**返回值:**
5464
5465| 类型        | 说明                          |
5466| ---------- | ----------------------------- |
5467| Array\<number\>   | 获取补偿范围的数组。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
5468
5469**错误码:**
5470
5471以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
5472
5473| 错误码ID         | 错误信息        |
5474| --------------- | --------------- |
5475| 7400103                |  Session not config, only throw in session usage.               |
5476
5477**示例:**
5478
5479```ts
5480import { BusinessError } from '@kit.BasicServicesKit';
5481
5482function getExposureBiasRange(photoSession: camera.PhotoSession): Array<number> {
5483  let biasRangeArray: Array<number> = [];
5484  try {
5485    biasRangeArray = photoSession.getExposureBiasRange();
5486  } catch (error) {
5487    // 失败返回错误码error.code并处理。
5488    let err = error as BusinessError;
5489    console.error(`The getExposureBiasRange call failed. error code: ${err.code}`);
5490  }
5491  return biasRangeArray;
5492}
5493```
5494
5495## Focus<sup>11+</sup>
5496
5497Focus extends [FocusQuery](#focusquery12)
5498
5499对焦类,对设备对焦操作。
5500
5501### setFocusMode<sup>11+</sup>
5502
5503setFocusMode(afMode: FocusMode): void
5504
5505设置对焦模式。
5506
5507进行设置之前,需要先检查设备是否支持指定的焦距模式,可使用方法[isFocusModeSupported](#isfocusmodesupported11)。
5508
5509**系统能力:** SystemCapability.Multimedia.Camera.Core
5510
5511**参数:**
5512
5513| 参数名      | 类型                     | 必填 | 说明                 |
5514| -------- | ----------------------- | ---- | ------------------- |
5515| afMode   | [FocusMode](#focusmode) | 是   | 指定的焦距模式。传参为null或者undefined,作为0处理,手动对焦模式。       |
5516
5517**错误码:**
5518
5519以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
5520
5521| 错误码ID         | 错误信息        |
5522| --------------- | --------------- |
5523| 7400103                |  Session not config.                                   |
5524
5525**示例:**
5526
5527```ts
5528import { BusinessError } from '@kit.BasicServicesKit';
5529
5530function setFocusMode(photoSession: camera.PhotoSession): void {
5531  try {
5532    photoSession.setFocusMode(camera.FocusMode.FOCUS_MODE_AUTO);
5533  } catch (error) {
5534    // 失败返回错误码error.code并处理。
5535    let err = error as BusinessError;
5536    console.error(`The setFocusMode call failed. error code: ${err.code}`);
5537  }
5538}
5539```
5540
5541### getFocusMode<sup>11+</sup>
5542
5543getFocusMode(): FocusMode
5544
5545获取当前的对焦模式。
5546
5547**系统能力:** SystemCapability.Multimedia.Camera.Core
5548
5549**返回值:**
5550
5551| 类型        | 说明                          |
5552| ---------- | ----------------------------- |
5553| [FocusMode](#focusmode)   | 获取当前设备的焦距模式。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
5554
5555**错误码:**
5556
5557以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
5558
5559| 错误码ID         | 错误信息        |
5560| --------------- | --------------- |
5561| 7400103                |  Session not config.                                   |
5562
5563**示例:**
5564
5565```ts
5566import { BusinessError } from '@kit.BasicServicesKit';
5567
5568function getFocusMode(photoSession: camera.PhotoSession): camera.FocusMode | undefined {
5569  let afMode: camera.FocusMode | undefined = undefined;
5570  try {
5571    afMode = photoSession.getFocusMode();
5572  } catch (error) {
5573    // 失败返回错误码error.code并处理。
5574    let err = error as BusinessError;
5575    console.error(`The getFocusMode call failed. error code: ${err.code}`);
5576  }
5577  return afMode;
5578}
5579```
5580
5581### setFocusPoint<sup>11+</sup>
5582
5583setFocusPoint(point: Point): void
5584
5585设置焦点,焦点应在0-1坐标系内,该坐标系左上角为{0,0},右下角为{1,1}。<br>此坐标系是以设备充电口在右侧时的横向设备方向为基准的,例如应用的预览界面布局以<br>设备充电口在下侧时的竖向方向为基准,布局宽高为{w,h},且触碰点为{x,y},<br>则转换后的坐标点为{y/h,1-x/w}。
5586
5587**系统能力:** SystemCapability.Multimedia.Camera.Core
5588
5589**参数:**
5590
5591| 参数名      | 类型                     | 必填 | 说明                 |
5592| -------- | ----------------------- | ---- | ------------------- |
5593| point    | [Point](#point)         | 是   | 焦点。x、y设置范围应在[0,1]之内,超过范围,如果小于0设置0,大于1设置1。   |
5594
5595**错误码:**
5596
5597以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
5598
5599| 错误码ID         | 错误信息        |
5600| --------------- | --------------- |
5601| 7400103                |  Session not config.                                   |
5602
5603**示例:**
5604
5605```ts
5606import { BusinessError } from '@kit.BasicServicesKit';
5607
5608function setFocusPoint(photoSession: camera.PhotoSession): void {
5609  const focusPoint: camera.Point = {x: 1, y: 1};
5610  try {
5611    photoSession.setFocusPoint(focusPoint);
5612  } catch (error) {
5613    // 失败返回错误码error.code并处理。
5614    let err = error as BusinessError;
5615    console.error(`The setFocusPoint call failed. error code: ${err.code}`);
5616  }
5617}
5618```
5619
5620### getFocusPoint<sup>11+</sup>
5621
5622getFocusPoint(): Point
5623
5624查询焦点。
5625
5626**系统能力:** SystemCapability.Multimedia.Camera.Core
5627
5628**返回值:**
5629
5630| 类型        | 说明                          |
5631| ---------- | ----------------------------- |
5632| [Point](#point)    | 用于获取当前焦点。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
5633
5634**错误码:**
5635
5636以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
5637
5638| 错误码ID         | 错误信息        |
5639| --------------- | --------------- |
5640| 7400103                |  Session not config.                                   |
5641
5642**示例:**
5643
5644```ts
5645import { BusinessError } from '@kit.BasicServicesKit';
5646
5647function getFocusPoint(photoSession: camera.PhotoSession): camera.Point | undefined {
5648  let point: camera.Point | undefined = undefined;
5649  try {
5650    point = photoSession.getFocusPoint();
5651  } catch (error) {
5652    // 失败返回错误码error.code并处理。
5653    let err = error as BusinessError;
5654    console.error(`The getFocusPoint call failed. error code: ${err.code}`);
5655  }
5656  return point;
5657}
5658```
5659
5660### getFocalLength<sup>11+</sup>
5661
5662getFocalLength(): number
5663
5664查询焦距值。
5665
5666**系统能力:** SystemCapability.Multimedia.Camera.Core
5667
5668**返回值:**
5669
5670| 类型        | 说明                          |
5671| ---------- | ----------------------------- |
5672| number    | 用于获取当前焦距,单位mm。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
5673
5674**错误码:**
5675
5676以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
5677
5678| 错误码ID         | 错误信息        |
5679| --------------- | --------------- |
5680| 7400103                |  Session not config.                                   |
5681
5682**示例:**
5683
5684```ts
5685import { BusinessError } from '@kit.BasicServicesKit';
5686
5687function getFocalLength(photoSession: camera.PhotoSession): number {
5688  const invalidValue: number = -1;
5689  let focalLength: number = invalidValue;
5690  try {
5691    focalLength = photoSession.getFocalLength();
5692  } catch (error) {
5693    // 失败返回错误码error.code并处理。
5694    let err = error as BusinessError;
5695    console.error(`The getFocalLength call failed. error code: ${err.code}`);
5696  }
5697  return focalLength;
5698}
5699```
5700
5701## FocusQuery<sup>12+</sup>
5702
5703提供了查询是否支持当前对焦模式的方法。
5704
5705### isFocusModeSupported<sup>11+</sup>
5706
5707isFocusModeSupported(afMode: FocusMode): boolean
5708
5709检测对焦模式是否支持。
5710
5711**系统能力:** SystemCapability.Multimedia.Camera.Core
5712
5713**参数:**
5714
5715| 参数名      | 类型                     | 必填 | 说明                              |
5716| -------- | ----------------------- | ---- | -------------------------------- |
5717| afMode   | [FocusMode](#focusmode) | 是   | 指定的焦距模式。传参为null或者undefined,作为0处理,手动对焦模式。                    |
5718
5719**返回值:**
5720
5721| 类型        | 说明                          |
5722| ---------- | ----------------------------- |
5723| boolean    | 返回true表示支持该焦距模式,false表示不支持。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
5724
5725**错误码:**
5726
5727以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
5728
5729| 错误码ID         | 错误信息        |
5730| --------------- | --------------- |
5731| 7400103                |  Session not config, only throw in session usage.          |
5732
5733**示例:**
5734
5735```ts
5736import { BusinessError } from '@kit.BasicServicesKit';
5737
5738function isFocusModeSupported(photoSession: camera.PhotoSession): boolean {
5739  let status: boolean = false;
5740  try {
5741    status = photoSession.isFocusModeSupported(camera.FocusMode.FOCUS_MODE_AUTO);
5742  } catch (error) {
5743    // 失败返回错误码error.code并处理。
5744    let err = error as BusinessError;
5745    console.error(`The isFocusModeSupported call failed. error code: ${err.code}`);
5746  }
5747  return status;
5748}
5749```
5750
5751## SmoothZoomMode<sup>11+</sup>
5752
5753平滑变焦模式。
5754
5755**系统能力:** SystemCapability.Multimedia.Camera.Core
5756
5757| 名称         | 值   | 说明            |
5758| ------------ | ---- | -------------- |
5759| NORMAL       | 0    | 贝塞尔曲线模式。  |
5760
5761## SmoothZoomInfo<sup>11+</sup>
5762
5763平滑变焦参数信息。
5764
5765**系统能力:** SystemCapability.Multimedia.Camera.Core
5766
5767| 名称     | 类型        |   只读   |   可选   | 说明       |
5768| -------- | ---------- | -------- | -------- | ---------- |
5769| duration |   number   |   否     |    否    | 平滑变焦总时长,单位ms。 |
5770
5771## Zoom<sup>11+</sup>
5772
5773Zoom extends [ZoomQuery](#zoomquery12)
5774
5775变焦类,对设备变焦操作。
5776
5777### setZoomRatio<sup>11+</sup>
5778
5779setZoomRatio(zoomRatio: number): void
5780
5781设置变焦比,变焦精度最高为小数点后两位,如果设置超过支持的精度范围,则只保留精度范围内数值。
5782
5783**系统能力:** SystemCapability.Multimedia.Camera.Core
5784
5785**参数:**
5786
5787| 参数名       | 类型                  | 必填 | 说明                                                                                                                              |
5788| --------- | -------------------- | ---- |---------------------------------------------------------------------------------------------------------------------------------|
5789| zoomRatio | number               | 是   | 可变焦距比,通过[getZoomRatioRange](#getzoomratiorange11)获取支持的变焦范围,如果设置超过支持范围的值,则只保留精度范围内数值。<br>设置可变焦距比到底层生效需要一定时间,获取正确设置的可变焦距比需要等待1~2帧的时间。 |
5790
5791**错误码:**
5792
5793以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
5794
5795| 错误码ID         | 错误信息        |
5796| --------------- | --------------- |
5797| 7400103                |  Session not config.                                   |
5798
5799**示例:**
5800
5801```ts
5802import { BusinessError } from '@kit.BasicServicesKit';
5803
5804function setZoomRatio(photoSession: camera.PhotoSession, zoomRatioRange: Array<number>): void {
5805  if (zoomRatioRange === undefined || zoomRatioRange.length <= 0) {
5806    return;
5807  }
5808  let zoomRatio = zoomRatioRange[0];
5809  try {
5810    photoSession.setZoomRatio(zoomRatio);
5811  } catch (error) {
5812    // 失败返回错误码error.code并处理。
5813    let err = error as BusinessError;
5814    console.error(`The setZoomRatio call failed. error code: ${err.code}`);
5815  }
5816}
5817```
5818
5819### getZoomRatio<sup>11+</sup>
5820
5821getZoomRatio(): number
5822
5823获取当前的变焦比。
5824
5825**系统能力:** SystemCapability.Multimedia.Camera.Core
5826
5827**返回值:**
5828
5829| 类型        | 说明                          |
5830| ---------- | ----------------------------- |
5831| number    | 获取当前的变焦比结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
5832
5833**错误码:**
5834
5835以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
5836
5837| 错误码ID         | 错误信息        |
5838| --------------- | --------------- |
5839| 7400103                |  Session not config.                                   |
5840| 7400201                |  Camera service fatal error.                           |
5841
5842**示例:**
5843
5844```ts
5845import { BusinessError } from '@kit.BasicServicesKit';
5846
5847function getZoomRatio(photoSession: camera.PhotoSession): number {
5848  const invalidValue: number = -1;
5849  let zoomRatio: number = invalidValue;
5850  try {
5851    zoomRatio = photoSession.getZoomRatio();
5852  } catch (error) {
5853    // 失败返回错误码error.code并处理。
5854    let err = error as BusinessError;
5855    console.error(`The getZoomRatio call failed. error code: ${err.code}`);
5856  }
5857  return zoomRatio;
5858}
5859```
5860
5861### setSmoothZoom<sup>11+</sup>
5862
5863setSmoothZoom(targetRatio: number, mode?: SmoothZoomMode): void
5864
5865触发平滑变焦。
5866
5867**系统能力:** SystemCapability.Multimedia.Camera.Core
5868
5869**参数:**
5870
5871| 参数名       | 类型            | 必填 | 说明               |
5872| ------------ | -------------- | ---- | ----------------- |
5873| targetRatio  | number         | 是   | 目标值。      |
5874| mode         | [SmoothZoomMode](#smoothzoommode11) | 否   | 模式。      |
5875
5876**错误码:**
5877
5878以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
5879
5880| 错误码ID         | 错误信息        |
5881| --------------- | --------------- |
5882| 7400103                |  Session not config.                                   |
5883
5884**示例:**
5885
5886```ts
5887import { BusinessError } from '@kit.BasicServicesKit';
5888
5889function setSmoothZoom(sessionExtendsZoom: camera.Zoom, targetZoomRatio: number, mode: camera.SmoothZoomMode): void {
5890  try {
5891    sessionExtendsZoom.setSmoothZoom(targetZoomRatio, mode);
5892  } catch (error) {
5893    // 失败返回错误码error.code并处理。
5894    let err = error as BusinessError;
5895    console.error(`The setSmoothZoom call failed. error code: ${err.code}`);
5896  }
5897}
5898```
5899
5900## ZoomQuery<sup>12+</sup>
5901
5902提供了与设备的缩放相关的查询功能,包括获取支持的缩放比例范围。
5903
5904### getZoomRatioRange<sup>11+</sup>
5905
5906getZoomRatioRange(): Array\<number\>
5907
5908获取支持的变焦范围。
5909
5910**系统能力:** SystemCapability.Multimedia.Camera.Core
5911
5912**返回值:**
5913
5914| 类型        | 说明                          |
5915| ---------- | ----------------------------- |
5916| Array\<number\>   | 用于获取可变焦距比范围,返回的数组包括其最小值和最大值。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
5917
5918**错误码:**
5919
5920以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
5921
5922| 错误码ID         | 错误信息        |
5923| --------------- | --------------- |
5924| 7400103                |  Session not config, only throw in session usage.            |
5925
5926**示例:**
5927
5928```ts
5929import { BusinessError } from '@kit.BasicServicesKit';
5930
5931function getZoomRatioRange(photoSession: camera.PhotoSession): Array<number> {
5932  let zoomRatioRange: Array<number> = [];
5933  try {
5934    zoomRatioRange = photoSession.getZoomRatioRange();
5935  } catch (error) {
5936    // 失败返回错误码error.code并处理。
5937    let err = error as BusinessError;
5938    console.error(`The getZoomRatioRange call failed. error code: ${err.code}`);
5939  }
5940  return zoomRatioRange;
5941}
5942```
5943
5944## Stabilization<sup>11+</sup>
5945
5946Stabilization extends [StabilizationQuery](#stabilizationquery12)
5947
5948提供设备在录像模式下设置视频防抖的操作。
5949
5950 > **说明:**
5951 >
5952 > 需要会话中有录像流([VideoOutput](#videooutput))的前提下,才可以对视频进行防抖设置,
5953 > 其中[VideoStabilizationMode](#videostabilizationmode)中的枚举HIGH需要在[Profile](#profile)的分辨率为1920*1080的场景下生效。
5954
5955### getActiveVideoStabilizationMode<sup>11+</sup>
5956
5957getActiveVideoStabilizationMode(): VideoStabilizationMode
5958
5959查询当前正在使用的视频防抖模式。
5960
5961**系统能力:** SystemCapability.Multimedia.Camera.Core
5962
5963**返回值:**
5964
5965| 类型        | 说明          |
5966| ---------- |-------------|
5967| [VideoStabilizationMode](#videostabilizationmode)    | 视频防抖是否正在使用。 |
5968
5969**错误码:**
5970
5971以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
5972
5973| 错误码ID         | 错误信息        |
5974| --------------- | --------------- |
5975| 7400103                |  Session not config.                                   |
5976
5977**示例:**
5978
5979```ts
5980import { BusinessError } from '@kit.BasicServicesKit';
5981
5982function getActiveVideoStabilizationMode(videoSession: camera.VideoSession): camera.VideoStabilizationMode | undefined {
5983  let vsMode: camera.VideoStabilizationMode | undefined = undefined;
5984  try {
5985    vsMode = videoSession.getActiveVideoStabilizationMode();
5986  } catch (error) {
5987    // 失败返回错误码error.code并处理。
5988    let err = error as BusinessError;
5989    console.error(`The getActiveVideoStabilizationMode call failed. error code: ${err.code}`);
5990  }
5991  return vsMode;
5992}
5993```
5994
5995### setVideoStabilizationMode<sup>11+</sup>
5996
5997setVideoStabilizationMode(mode: VideoStabilizationMode): void
5998
5999设置视频防抖模式。需要先检查设备是否支持对应的防抖模式,可以通过[isVideoStabilizationModeSupported](#isvideostabilizationmodesupported11)方法判断所设置的模式是否支持。
6000
6001**系统能力:** SystemCapability.Multimedia.Camera.Core
6002
6003**参数:**
6004
6005| 参数名      | 类型                                              | 必填 | 说明                    |
6006| -------- | ------------------------------------------------- | ---- | --------------------- |
6007| mode     | [VideoStabilizationMode](#videostabilizationmode) | 是   | 需要设置的视频防抖模式。   |
6008
6009**错误码:**
6010
6011以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
6012
6013| 错误码ID         | 错误信息        |
6014| --------------- | --------------- |
6015| 7400103                |  Session not config.                                   |
6016
6017**示例:**
6018
6019```ts
6020import { BusinessError } from '@kit.BasicServicesKit';
6021
6022function setVideoStabilizationMode(videoSession: camera.VideoSession): void {
6023  try {
6024    videoSession.setVideoStabilizationMode(camera.VideoStabilizationMode.OFF);
6025  } catch (error) {
6026    // 失败返回错误码error.code并处理。
6027    let err = error as BusinessError;
6028    console.error(`The setVideoStabilizationMode call failed. error code: ${err.code}`);
6029  }
6030}
6031```
6032
6033## StabilizationQuery<sup>12+</sup>
6034
6035提供了查询设备在录像模式下是否支持对应的视频防抖模式的能力。
6036
6037### isVideoStabilizationModeSupported<sup>11+</sup>
6038
6039isVideoStabilizationModeSupported(vsMode: VideoStabilizationMode): boolean
6040
6041查询是否支持指定的视频防抖模式。
6042
6043**系统能力:** SystemCapability.Multimedia.Camera.Core
6044
6045**参数:**
6046
6047| 参数名      | 类型                                              | 必填 | 说明                             |
6048| -------- | ------------------------------------------------- | ---- | ------------------------------ |
6049| vsMode   | [VideoStabilizationMode](#videostabilizationmode) | 是   | 视频防抖模式。                    |
6050
6051**返回值:**
6052
6053| 类型        | 说明                          |
6054| ---------- | ----------------------------- |
6055| boolean    | 返回视频防抖模式是否支持,true表示支持,false表示不支持。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
6056
6057**错误码:**
6058
6059以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
6060
6061| 错误码ID         | 错误信息        |
6062| --------------- | --------------- |
6063| 7400103                |  Session not config, only throw in session usage.             |
6064
6065**示例:**
6066
6067```ts
6068import { BusinessError } from '@kit.BasicServicesKit';
6069
6070function isVideoStabilizationModeSupported(videoSession: camera.VideoSession): boolean {
6071  let isSupported: boolean = false;
6072  try {
6073    isSupported = videoSession.isVideoStabilizationModeSupported(camera.VideoStabilizationMode.OFF);
6074  } catch (error) {
6075    // 失败返回错误码error.code并处理。
6076    let err = error as BusinessError;
6077    console.error(`The isVideoStabilizationModeSupported call failed. error code: ${err.code}`);
6078  }
6079  return isSupported;
6080}
6081```
6082
6083## CaptureSession<sup>(deprecated)</sup>
6084
6085拍照会话类,保存一次相机运行所需要的所有资源[CameraInput](#camerainput)、[CameraOutput](#cameraoutput),并向相机设备申请完成相机功能(录像,拍照)。
6086
6087> **说明:**
6088>从 API version 10开始支持,从API version 11开始废弃。建议使用[PhotoSession](#photosession11)、[VideoSession](#videosession11)替代。
6089
6090### beginConfig<sup>(deprecated)</sup>
6091
6092beginConfig(): void
6093
6094开始配置会话。
6095
6096> **说明:**
6097>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.beginConfig](#beginconfig11)替代。
6098
6099**系统能力:** SystemCapability.Multimedia.Camera.Core
6100
6101**错误码:**
6102
6103以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
6104
6105| 错误码ID         | 错误信息        |
6106| --------------- | --------------- |
6107| 7400105         |  Session config locked.               |
6108
6109**示例:**
6110
6111```ts
6112import { BusinessError } from '@kit.BasicServicesKit';
6113
6114function beginConfig(captureSession: camera.CaptureSession): void {
6115  try {
6116    captureSession.beginConfig();
6117  } catch (error) {
6118    // 失败返回错误码error.code并处理。
6119    let err = error as BusinessError;
6120    console.error(`The beginConfig call failed. error code: ${err.code}`);
6121  }
6122}
6123```
6124
6125### commitConfig<sup>(deprecated)</sup>
6126
6127commitConfig(callback: AsyncCallback\<void\>): void
6128
6129提交配置信息,通过注册回调函数获取结果。使用callback异步回调。
6130
6131> **说明:**
6132>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.commitConfig](#commitconfig11)替代。
6133
6134**系统能力:** SystemCapability.Multimedia.Camera.Core
6135
6136**参数:**
6137
6138| 参数名     | 类型                   | 必填 | 说明                  |
6139| -------- | -------------------- | ---- | -------------------- |
6140| callback | AsyncCallback\<void\> | 是   | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
6141
6142**错误码:**
6143
6144以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
6145
6146| 错误码ID         | 错误信息        |
6147| --------------- | --------------- |
6148| 7400102                |  Operation not allowed.                                  |
6149| 7400201                |  Camera service fatal error.                           |
6150
6151**示例:**
6152
6153```ts
6154import { BusinessError } from '@kit.BasicServicesKit';
6155
6156function commitConfig(captureSession: camera.CaptureSession): void {
6157  captureSession.commitConfig((err: BusinessError) => {
6158    if (err) {
6159      console.error(`The commitConfig call failed. error code: ${err.code}`);
6160      return;
6161    }
6162    console.info('Callback invoked to indicate the commit config success.');
6163  });
6164}
6165```
6166
6167### commitConfig<sup>(deprecated)</sup>
6168
6169commitConfig(): Promise\<void\>
6170
6171提交配置信息,通过Promise获取结果。
6172
6173> **说明:**
6174>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.commitConfig](#commitconfig11-1)替代。
6175
6176**系统能力:** SystemCapability.Multimedia.Camera.Core
6177
6178**返回值:**
6179
6180| 类型            | 说明                |
6181| -------------- |-------------------|
6182| Promise\<void\> | 无返回结果的Promise对象。 |
6183
6184**错误码:**
6185
6186以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
6187
6188| 错误码ID         | 错误信息        |
6189| --------------- | --------------- |
6190| 7400102                |  Operation not allowed.                                  |
6191| 7400201                |  Camera service fatal error.                           |
6192
6193**示例:**
6194
6195```ts
6196import { BusinessError } from '@kit.BasicServicesKit';
6197
6198function commitConfig(captureSession: camera.CaptureSession): void {
6199  captureSession.commitConfig().then(() => {
6200    console.info('Promise returned to indicate the commit config success.');
6201  }).catch((error: BusinessError) => {
6202    // 失败返回错误码error.code并处理。
6203    console.error(`The commitConfig call failed. error code: ${error.code}`);
6204  });
6205}
6206```
6207
6208### addInput<sup>(deprecated)</sup>
6209
6210addInput(cameraInput: CameraInput): void
6211
6212把[CameraInput](#camerainput)加入到会话。
6213
6214> **说明:**
6215>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.addInput](#addinput11)替代。
6216
6217**系统能力:** SystemCapability.Multimedia.Camera.Core
6218
6219**参数:**
6220
6221| 参数名        | 类型                          | 必填 | 说明                     |
6222| ----------- | --------------------------- | ---- | ------------------------ |
6223| cameraInput | [CameraInput](#camerainput) | 是   | 需要添加的CameraInput实例。 |
6224
6225**错误码:**
6226
6227以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
6228
6229| 错误码ID   | 错误信息                                          |
6230|---------|-----------------------------------------------|
6231| 7400101 | Parameter missing or parameter type incorrect. |
6232| 7400102 | Operation not allowed.                           |
6233
6234**示例:**
6235
6236```ts
6237import { BusinessError } from '@kit.BasicServicesKit';
6238
6239function addInput(captureSession: camera.CaptureSession, cameraInput: camera.CameraInput): void {
6240  try {
6241    captureSession.addInput(cameraInput);
6242  } catch (error) {
6243    // 失败返回错误码error.code并处理。
6244    let err = error as BusinessError;
6245    console.error(`The addInput call failed. error code: ${err.code}`);
6246  }
6247}
6248```
6249
6250### removeInput<sup>(deprecated)</sup>
6251
6252removeInput(cameraInput: CameraInput): void
6253
6254移除[CameraInput](#camerainput)。
6255
6256> **说明:**
6257>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.removeInput](#removeinput11)替代。
6258
6259**系统能力:** SystemCapability.Multimedia.Camera.Core
6260
6261**参数:**
6262
6263| 参数名        | 类型                          | 必填 | 说明                      |
6264| ----------- | --------------------------- | ---- | ------------------------ |
6265| cameraInput | [CameraInput](#camerainput) | 是   | 需要移除的CameraInput实例。 |
6266
6267**错误码:**
6268
6269以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
6270
6271| 错误码ID         | 错误信息        |
6272| --------------- | --------------- |
6273| 7400101                |  Parameter missing or parameter type incorrect.        |
6274| 7400102                |  Operation not allowed.                                  |
6275
6276**示例:**
6277
6278```ts
6279import { BusinessError } from '@kit.BasicServicesKit';
6280
6281function removeInput(captureSession: camera.CaptureSession, cameraInput: camera.CameraInput): void {
6282  try {
6283    captureSession.removeInput(cameraInput);
6284  } catch (error) {
6285    // 失败返回错误码error.code并处理。
6286    let err = error as BusinessError;
6287    console.error(`The removeInput call failed. error code: ${err.code}`);
6288  }
6289}
6290```
6291
6292### addOutput<sup>(deprecated)</sup>
6293
6294addOutput(cameraOutput: CameraOutput): void
6295
6296把[CameraOutput](#cameraoutput)加入到会话。
6297
6298> **说明:**
6299>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.addOutput](#addoutput11)替代。
6300
6301**系统能力:** SystemCapability.Multimedia.Camera.Core
6302
6303**参数:**
6304
6305| 参数名           | 类型                             | 必填 | 说明                      |
6306| ------------- | ------------------------------- | ---- | ------------------------ |
6307| cameraOutput  | [CameraOutput](#cameraoutput)   | 是   | 需要添加的CameraOutput实例。 |
6308
6309**错误码:**
6310
6311以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
6312
6313| 错误码ID         | 错误信息        |
6314| --------------- | --------------- |
6315| 7400101                |  Parameter missing or parameter type incorrect.        |
6316| 7400102                |  Operation not allowed.                                  |
6317
6318**示例:**
6319
6320```ts
6321import { BusinessError } from '@kit.BasicServicesKit';
6322
6323function addOutput(captureSession: camera.CaptureSession, cameraOutput: camera.CameraOutput): void {
6324  try {
6325    captureSession.addOutput(cameraOutput);
6326  } catch (error) {
6327    // 失败返回错误码error.code并处理。
6328    let err = error as BusinessError;
6329    console.error(`The addOutput call failed. error code: ${err.code}`);
6330  }
6331}
6332```
6333
6334### removeOutput<sup>(deprecated)</sup>
6335
6336removeOutput(cameraOutput: CameraOutput): void
6337
6338从会话中移除[CameraOutput](#cameraoutput)。
6339
6340> **说明:**
6341>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.removeOutput](#removeoutput11)替代。
6342
6343**系统能力:** SystemCapability.Multimedia.Camera.Core
6344
6345**参数:**
6346
6347| 参数名           | 类型                             | 必填 | 说明                      |
6348| ------------- | ------------------------------- | ---- | ------------------------ |
6349| cameraOutput  | [CameraOutput](#cameraoutput)   | 是   | 需要移除的CameraOutput实例。 |
6350
6351**错误码:**
6352
6353以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
6354
6355| 错误码ID         | 错误信息        |
6356| --------------- | --------------- |
6357| 7400101                |  Parameter missing or parameter type incorrect.        |
6358| 7400102                |  Operation not allowed.                                  |
6359
6360**示例:**
6361
6362```ts
6363import { BusinessError } from '@kit.BasicServicesKit';
6364
6365function removeOutput(captureSession: camera.CaptureSession, previewOutput: camera.PreviewOutput): void {
6366  try {
6367    captureSession.removeOutput(previewOutput);
6368  } catch (error) {
6369    // 失败返回错误码error.code并处理。
6370    let err = error as BusinessError;
6371    console.error(`The removeOutput call failed. error code: ${err.code}`);
6372  }
6373}
6374```
6375
6376### start<sup>(deprecated)</sup>
6377
6378start(callback: AsyncCallback\<void\>): void
6379
6380开始会话工作,通过注册回调函数获取结果。使用callback异步回调。
6381
6382> **说明:**
6383>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.start](#start11)替代。
6384
6385**系统能力:** SystemCapability.Multimedia.Camera.Core
6386
6387**参数:**
6388
6389| 参数名      | 类型                  | 必填 | 说明                 |
6390| -------- | -------------------- | ---- | -------------------- |
6391| callback | AsyncCallback\<void\> | 是   | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
6392
6393**错误码:**
6394
6395以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
6396
6397| 错误码ID         | 错误信息        |
6398| --------------- | --------------- |
6399| 7400103                |  Session not config.                                   |
6400| 7400201                |  Camera service fatal error.                           |
6401
6402**示例:**
6403
6404```ts
6405import { BusinessError } from '@kit.BasicServicesKit';
6406
6407function startCaptureSession(captureSession: camera.CaptureSession): void {
6408  captureSession.start((err: BusinessError) => {
6409    if (err) {
6410      console.error(`Failed to start the session, error code: ${err.code}.`);
6411      return;
6412    }
6413    console.info('Callback invoked to indicate the session start success.');
6414  });
6415}
6416```
6417
6418### start<sup>(deprecated)</sup>
6419
6420start(): Promise\<void\>
6421
6422开始会话工作,通过Promise获取结果。
6423
6424> **说明:**
6425>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.start](#start11-1)替代。
6426
6427**系统能力:** SystemCapability.Multimedia.Camera.Core
6428
6429**返回值:**
6430
6431| 类型            | 说明                     |
6432| -------------- | ------------------------ |
6433| Promise\<void\> | 无返回结果的Promise对象。 |
6434
6435**错误码:**
6436
6437以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
6438
6439| 错误码ID         | 错误信息        |
6440| --------------- | --------------- |
6441| 7400103                |  Session not config.                                   |
6442| 7400201                |  Camera service fatal error.                           |
6443
6444**示例:**
6445
6446```ts
6447import { BusinessError } from '@kit.BasicServicesKit';
6448
6449function startCaptureSession(captureSession: camera.CaptureSession): void {
6450  captureSession.start().then(() => {
6451    console.info('Promise returned to indicate the session start success.');
6452  }).catch((err: BusinessError) => {
6453    console.error(`Failed to start the session, error code: ${err.code}.`);
6454  });
6455}
6456```
6457
6458### stop<sup>(deprecated)</sup>
6459
6460stop(callback: AsyncCallback\<void\>): void
6461
6462停止会话工作,通过注册回调函数获取结果。使用callback异步回调。
6463
6464> **说明:**
6465>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.stop](#stop11)替代。
6466
6467**系统能力:** SystemCapability.Multimedia.Camera.Core
6468
6469**参数:**
6470
6471| 参数名      | 类型                  | 必填 | 说明                 |
6472| -------- | -------------------- | ---- | ------------------- |
6473| callback | AsyncCallback\<void\> | 是   | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
6474
6475**错误码:**
6476
6477以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
6478
6479| 错误码ID         | 错误信息        |
6480| --------------- | --------------- |
6481| 7400201                |  Camera service fatal error.                           |
6482
6483**示例:**
6484
6485```ts
6486import { BusinessError } from '@kit.BasicServicesKit';
6487
6488function stopCaptureSession(captureSession: camera.CaptureSession): void {
6489  captureSession.stop((err: BusinessError) => {
6490    if (err) {
6491      console.error(`Failed to stop the session, error code: ${err.code}.`);
6492      return;
6493    }
6494    console.info('Callback invoked to indicate the session stop success.');
6495  });
6496}
6497```
6498
6499### stop<sup>(deprecated)</sup>
6500
6501stop(): Promise\<void\>
6502
6503停止会话工作,通过Promise获取结果。
6504
6505> **说明:**
6506>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.stop](#stop11-1)替代。
6507
6508**系统能力:** SystemCapability.Multimedia.Camera.Core
6509
6510**返回值:**
6511
6512| 类型            | 说明                     |
6513| -------------- | ----------------------- |
6514| Promise\<void\> | 无返回结果的Promise对象。。 |
6515
6516**错误码:**
6517
6518以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
6519
6520| 错误码ID         | 错误信息        |
6521| --------------- | --------------- |
6522| 7400201                |  Camera service fatal error.                           |
6523
6524**示例:**
6525
6526```ts
6527import { BusinessError } from '@kit.BasicServicesKit';
6528
6529function stopCaptureSession(captureSession: camera.CaptureSession): void {
6530  captureSession.stop().then(() => {
6531    console.info('Promise returned to indicate the session stop success.');
6532  }).catch((err: BusinessError) => {
6533    console.error(`Failed to stop the session, error code: ${err.code}.`);
6534  });
6535}
6536```
6537
6538### release<sup>(deprecated)</sup>
6539
6540release(callback: AsyncCallback\<void\>): void
6541
6542释放会话资源,通过注册回调函数获取结果。使用callback异步回调。
6543
6544> **说明:**
6545>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.release](#release11-1)替代。
6546
6547**系统能力:** SystemCapability.Multimedia.Camera.Core
6548
6549**参数:**
6550
6551| 参数名      | 类型                  | 必填 | 说明                 |
6552| -------- | -------------------- | ---- | -------------------- |
6553| callback | AsyncCallback\<void\> | 是   | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
6554
6555**错误码:**
6556
6557以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
6558
6559| 错误码ID         | 错误信息        |
6560| --------------- | --------------- |
6561| 7400201                |  Camera service fatal error.                           |
6562
6563**示例:**
6564
6565```ts
6566import { BusinessError } from '@kit.BasicServicesKit';
6567
6568function releaseCaptureSession(captureSession: camera.CaptureSession): void {
6569  captureSession.release((err: BusinessError) => {
6570    if (err) {
6571      console.error(`Failed to release the CaptureSession instance, error code: ${err.code}.`);
6572      return;
6573    }
6574    console.info('Callback invoked to indicate that the CaptureSession instance is released successfully.');
6575  });
6576}
6577```
6578
6579### release<sup>(deprecated)</sup>
6580
6581release(): Promise\<void\>
6582
6583释放会话资源,通过Promise获取结果。
6584
6585> **说明:**
6586>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.release](#release11-2)替代。
6587
6588**系统能力:** SystemCapability.Multimedia.Camera.Core
6589
6590**返回值:**
6591
6592| 类型            | 说明                     |
6593| -------------- | ------------------------ |
6594| Promise\<void\> | 无返回结果的Promise对象。 |
6595
6596**错误码:**
6597
6598以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
6599
6600| 错误码ID         | 错误信息        |
6601| --------------- | --------------- |
6602| 7400201                |  Camera service fatal error.                           |
6603
6604**示例:**
6605
6606```ts
6607import { BusinessError } from '@kit.BasicServicesKit';
6608
6609function releaseCaptureSession(captureSession: camera.CaptureSession): void {
6610  captureSession.release().then(() => {
6611    console.info('Promise returned to indicate that the CaptureSession instance is released successfully.');
6612  }).catch((err: BusinessError) => {
6613    console.error(`Failed to release the CaptureSession instance, error code: ${err.code}.`);
6614  });
6615}
6616```
6617
6618### hasFlash<sup>(deprecated)</sup>
6619
6620hasFlash(): boolean
6621
6622检测是否有闪光灯。
6623
6624> **说明:**
6625>从 API version 10开始支持,从API version 11开始废弃。建议使用[Flash.hasFlash](#hasflash11)替代。
6626
6627**系统能力:** SystemCapability.Multimedia.Camera.Core
6628
6629**返回值:**
6630
6631| 类型        | 说明                          |
6632| ---------- | ----------------------------- |
6633| boolean    | 返回true表示设备支持闪光灯,false表示不支持。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
6634
6635**错误码:**
6636
6637以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
6638
6639| 错误码ID         | 错误信息        |
6640| --------------- | --------------- |
6641| 7400103                |  Session not config.                                   |
6642
6643**示例:**
6644
6645```ts
6646import { BusinessError } from '@kit.BasicServicesKit';
6647
6648function hasFlash(captureSession: camera.CaptureSession): boolean {
6649  let status: boolean = false;
6650  try {
6651    status = captureSession.hasFlash();
6652  } catch (error) {
6653    // 失败返回错误码error.code并处理。
6654    let err = error as BusinessError;
6655    console.error(`The hasFlash call failed. error code: ${err.code}`);
6656  }
6657  return status;
6658}
6659```
6660
6661### isFlashModeSupported<sup>(deprecated)</sup>
6662
6663isFlashModeSupported(flashMode: FlashMode): boolean
6664
6665检测闪光灯模式是否支持。
6666
6667> **说明:**
6668>从 API version 10开始支持,从API version 11开始废弃。建议使用[Flash.isFlashModeSupported](#isflashmodesupported11)替代。
6669
6670**系统能力:** SystemCapability.Multimedia.Camera.Core
6671
6672**参数:**
6673
6674| 参数名       | 类型                     | 必填 | 说明                               |
6675| --------- | ----------------------- | ---- | --------------------------------- |
6676| flashMode | [FlashMode](#flashmode) | 是   | 指定闪光灯模式。                     |
6677
6678**返回值:**
6679
6680| 类型        | 说明                          |
6681| ---------- | ----------------------------- |
6682| boolean    | 返回true表示支持该闪光灯模式,false表示不支持。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
6683
6684**错误码:**
6685
6686以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
6687
6688| 错误码ID         | 错误信息        |
6689| --------------- | --------------- |
6690| 7400103                |  Session not config.                                   |
6691
6692**示例:**
6693
6694```ts
6695import { BusinessError } from '@kit.BasicServicesKit';
6696
6697function isFlashModeSupported(captureSession: camera.CaptureSession): boolean {
6698  let status: boolean = false;
6699  try {
6700    status = captureSession.isFlashModeSupported(camera.FlashMode.FLASH_MODE_AUTO);
6701  } catch (error) {
6702    // 失败返回错误码error.code并处理。
6703    let err = error as BusinessError;
6704    console.error(`The isFlashModeSupported call failed. error code: ${err.code}`);
6705  }
6706  return status;
6707}
6708```
6709
6710### setFlashMode<sup>(deprecated)</sup>
6711
6712setFlashMode(flashMode: FlashMode): void
6713
6714设置闪光灯模式。
6715
6716进行设置之前,需要先检查:
6717
67181. 设备是否支持闪光灯,可使用方法[hasFlash](#hasflashdeprecated)。
67192. 设备是否支持指定的闪光灯模式,可使用方法[isFlashModeSupported](#isflashmodesupporteddeprecated)。
6720
6721> **说明:**
6722>从 API version 10开始支持,从API version 11开始废弃。建议使用[Flash.setFlashMode](#setflashmode11)替代。
6723
6724**系统能力:** SystemCapability.Multimedia.Camera.Core
6725
6726**参数:**
6727
6728| 参数名     | 类型                    | 必填 | 说明                 |
6729| --------- | ----------------------- | ---- | -------------------- |
6730| flashMode | [FlashMode](#flashmode) | 是   | 指定闪光灯模式。       |
6731
6732**错误码:**
6733
6734以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
6735
6736| 错误码ID         | 错误信息        |
6737| --------------- | --------------- |
6738| 7400103                |  Session not config.                                   |
6739
6740**示例:**
6741
6742```ts
6743import { BusinessError } from '@kit.BasicServicesKit';
6744
6745function setFlashMode(captureSession: camera.CaptureSession): void {
6746  try {
6747    captureSession.setFlashMode(camera.FlashMode.FLASH_MODE_AUTO);
6748  } catch (error) {
6749    // 失败返回错误码error.code并处理。
6750    let err = error as BusinessError;
6751    console.error(`The setFlashMode call failed. error code: ${err.code}`);
6752  }
6753}
6754```
6755
6756### getFlashMode<sup>(deprecated)</sup>
6757
6758getFlashMode(): FlashMode
6759
6760获取当前设备的闪光灯模式。
6761
6762> **说明:**
6763>从 API version 10开始支持,从API version 11开始废弃。建议使用[Flash.getFlashMode](#getflashmode11)替代。
6764
6765**系统能力:** SystemCapability.Multimedia.Camera.Core
6766
6767**返回值:**
6768
6769| 类型        | 说明                          |
6770| ---------- | ----------------------------- |
6771| [FlashMode](#flashmode)    | 获取当前设备的闪光灯模式。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
6772
6773**错误码:**
6774
6775以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
6776
6777| 错误码ID         | 错误信息        |
6778| --------------- | --------------- |
6779| 7400103                |  Session not config.                                   |
6780
6781**示例:**
6782
6783```ts
6784import { BusinessError } from '@kit.BasicServicesKit';
6785
6786function getFlashMode(captureSession: camera.CaptureSession): camera.FlashMode | undefined {
6787  let flashMode: camera.FlashMode | undefined = undefined;
6788  try {
6789    flashMode = captureSession.getFlashMode();
6790  } catch (error) {
6791    // 失败返回错误码error.code并处理。
6792    let err = error as BusinessError;
6793    console.error(`The getFlashMode call failed.error code: ${err.code}`);
6794  }
6795  return flashMode;
6796}
6797```
6798
6799### isExposureModeSupported<sup>(deprecated)</sup>
6800
6801isExposureModeSupported(aeMode: ExposureMode): boolean
6802
6803检测曝光模式是否支持。
6804
6805> **说明:**
6806>从 API version 10开始支持,从API version 11开始废弃。建议使用[AutoExposure.isExposureModeSupported](#isexposuremodesupported11)替代。
6807
6808**系统能力:** SystemCapability.Multimedia.Camera.Core
6809
6810**参数:**
6811
6812| 参数名      | 类型                           | 必填  | 说明                           |
6813| -------- | -------------------------------| ---- | ----------------------------- |
6814| aeMode   | [ExposureMode](#exposuremode)  | 是   | 曝光模式。                      |
6815
6816**返回值:**
6817
6818| 类型        | 说明                          |
6819| ---------- | ----------------------------- |
6820| boolean    | 获取是否支持曝光模式。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
6821
6822**错误码:**
6823
6824以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
6825
6826| 错误码ID         | 错误信息        |
6827| --------------- | --------------- |
6828| 7400103                |  Session not config.                                   |
6829
6830**示例:**
6831
6832```ts
6833import { BusinessError } from '@kit.BasicServicesKit';
6834
6835function isExposureModeSupported(captureSession: camera.CaptureSession): boolean {
6836  let isSupported: boolean = false;
6837  try {
6838    isSupported = captureSession.isExposureModeSupported(camera.ExposureMode.EXPOSURE_MODE_LOCKED);
6839  } catch (error) {
6840    // 失败返回错误码error.code并处理。
6841    let err = error as BusinessError;
6842    console.error(`The isExposureModeSupported call failed. error code: ${err.code}`);
6843  }
6844  return isSupported;
6845}
6846```
6847
6848### getExposureMode<sup>(deprecated)</sup>
6849
6850getExposureMode(): ExposureMode
6851
6852获取当前曝光模式。
6853
6854> **说明:**
6855>从 API version 10开始支持,从API version 11开始废弃。建议使用[AutoExposure.getExposureMode](#getexposuremode11)替代。
6856
6857**系统能力:** SystemCapability.Multimedia.Camera.Core
6858
6859**返回值:**
6860
6861| 类型        | 说明                          |
6862| ---------- | ----------------------------- |
6863| [ExposureMode](#exposuremode)    | 获取当前曝光模式。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
6864
6865**错误码:**
6866
6867以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
6868
6869| 错误码ID         | 错误信息        |
6870| --------------- | --------------- |
6871| 7400103                |  Session not config.                                   |
6872
6873**示例:**
6874
6875```ts
6876import { BusinessError } from '@kit.BasicServicesKit';
6877
6878function getExposureMode(captureSession: camera.CaptureSession): camera.ExposureMode | undefined {
6879  let exposureMode: camera.ExposureMode | undefined = undefined;
6880  try {
6881    exposureMode = captureSession.getExposureMode();
6882  } catch (error) {
6883    // 失败返回错误码error.code并处理。
6884    let err = error as BusinessError;
6885    console.error(`The getExposureMode call failed. error code: ${err.code}`);
6886  }
6887  return exposureMode;
6888}
6889```
6890
6891### setExposureMode<sup>(deprecated)</sup>
6892
6893setExposureMode(aeMode: ExposureMode): void
6894
6895设置曝光模式。进行设置之前,需要先检查设备是否支持指定的曝光模式,可使用方法[isExposureModeSupported](#isexposuremodesupporteddeprecated)。
6896
6897> **说明:**
6898>从 API version 10开始支持,从API version 11开始废弃。建议使用[AutoExposure.setExposureMode](#setexposuremode11)替代。
6899
6900**系统能力:** SystemCapability.Multimedia.Camera.Core
6901
6902**参数:**
6903
6904| 参数名      | 类型                            | 必填 | 说明                    |
6905| -------- | -------------------------------| ---- | ----------------------- |
6906| aeMode   | [ExposureMode](#exposuremode)  | 是   | 曝光模式。                |
6907
6908**错误码:**
6909
6910以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
6911
6912| 错误码ID         | 错误信息        |
6913| --------------- | --------------- |
6914| 7400103                |  Session not config.                                   |
6915
6916**示例:**
6917
6918```ts
6919import { BusinessError } from '@kit.BasicServicesKit';
6920
6921function setExposureMode(captureSession: camera.CaptureSession): void {
6922  try {
6923    captureSession.setExposureMode(camera.ExposureMode.EXPOSURE_MODE_LOCKED);
6924  } catch (error) {
6925    // 失败返回错误码error.code并处理。
6926    let err = error as BusinessError;
6927    console.error(`The setExposureMode call failed. error code: ${err.code}`);
6928  }
6929}
6930```
6931
6932### getMeteringPoint<sup>(deprecated)</sup>
6933
6934getMeteringPoint(): Point
6935
6936查询曝光区域中心点。
6937
6938> **说明:**
6939>从 API version 10开始支持,从API version 11开始废弃。建议使用[AutoExposure.getMeteringPoint](#getmeteringpoint11)替代。
6940
6941**系统能力:** SystemCapability.Multimedia.Camera.Core
6942
6943**返回值:**
6944
6945| 类型        | 说明                          |
6946| ---------- | ----------------------------- |
6947| [Point](#point)    | 获取当前曝光点。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
6948
6949**错误码:**
6950
6951以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
6952
6953| 错误码ID         | 错误信息        |
6954| --------------- | --------------- |
6955| 7400103                |  Session not config.                                   |
6956
6957**示例:**
6958
6959```ts
6960import { BusinessError } from '@kit.BasicServicesKit';
6961
6962function getMeteringPoint(captureSession: camera.CaptureSession): camera.Point | undefined {
6963  let exposurePoint: camera.Point | undefined = undefined;
6964  try {
6965    exposurePoint = captureSession.getMeteringPoint();
6966  } catch (error) {
6967    // 失败返回错误码error.code并处理。
6968    let err = error as BusinessError;
6969    console.error(`The getMeteringPoint call failed. error code: ${err.code}`);
6970  }
6971  return exposurePoint;
6972}
6973```
6974
6975### setMeteringPoint<sup>(deprecated)</sup>
6976
6977setMeteringPoint(point: Point): void
6978
6979设置曝光区域中心点,曝光点应在0-1坐标系内,该坐标系左上角为{0,0},右下角为{1,1}。
6980此坐标系是以设备充电口在右侧时的横向设备方向为基准的,例如应用的预览界面布局以
6981设备充电口在下侧时的竖向方向为基准,布局宽高为{w,h},且触碰点为{x,y},
6982则转换后的坐标点为{y/h,1-x/w}。
6983
6984> **说明:**
6985>从 API version 10开始支持,从API version 11开始废弃。建议使用[AutoExposure.setMeteringPoint](#setmeteringpoint11)替代。
6986
6987**系统能力:** SystemCapability.Multimedia.Camera.Core
6988
6989**参数:**
6990
6991| 参数名           | 类型                            | 必填 | 说明                 |
6992| ------------- | -------------------------------| ---- | ------------------- |
6993| point | [Point](#point)                | 是   | 曝光点,x,y设置范围应在[0,1]之内,超过范围,如果小于0设置0,大于1设置1。             |
6994
6995**错误码:**
6996
6997以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
6998
6999| 错误码ID         | 错误信息        |
7000| --------------- | --------------- |
7001| 7400103                |  Session not config.                                   |
7002
7003**示例:**
7004
7005```ts
7006import { BusinessError } from '@kit.BasicServicesKit';
7007
7008function setMeteringPoint(captureSession: camera.CaptureSession): void {
7009  const point: camera.Point = {x: 1, y: 1};
7010  try {
7011    captureSession.setMeteringPoint(point);
7012  } catch (error) {
7013    // 失败返回错误码error.code并处理。
7014    let err = error as BusinessError;
7015    console.error(`The setMeteringPoint call failed. error code: ${err.code}`);
7016  }
7017}
7018```
7019
7020### getExposureBiasRange<sup>(deprecated)</sup>
7021
7022getExposureBiasRange(): Array\<number\>
7023
7024查询曝光补偿范围。
7025
7026> **说明:**
7027>从 API version 10开始支持,从API version 11开始废弃。建议使用[AutoExposure.getExposureBiasRange](#getexposurebiasrange11)替代。
7028
7029**系统能力:** SystemCapability.Multimedia.Camera.Core
7030
7031**返回值:**
7032
7033| 类型        | 说明                          |
7034| ---------- | ----------------------------- |
7035| Array\<number\>   | 获取补偿范围的数组。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
7036
7037**错误码:**
7038
7039以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
7040
7041| 错误码ID         | 错误信息        |
7042| --------------- | --------------- |
7043| 7400103                |  Session not config.                                   |
7044
7045**示例:**
7046
7047```ts
7048import { BusinessError } from '@kit.BasicServicesKit';
7049
7050function getExposureBiasRange(captureSession: camera.CaptureSession): Array<number> {
7051  let biasRangeArray: Array<number> = [];
7052  try {
7053    biasRangeArray = captureSession.getExposureBiasRange();
7054  } catch (error) {
7055    // 失败返回错误码error.code并处理。
7056    let err = error as BusinessError;
7057    console.error(`The getExposureBiasRange call failed. error code: ${err.code}`);
7058  }
7059  return biasRangeArray;
7060}
7061```
7062
7063### setExposureBias<sup>(deprecated)</sup>
7064
7065setExposureBias(exposureBias: number): void
7066
7067设置曝光补偿,曝光补偿值(EV)。
7068
7069进行设置之前,建议先通过方法[getExposureBiasRange](#getexposurebiasrangedeprecated)查询支持的范围。
7070
7071> **说明:**
7072>从 API version 10开始支持,从API version 11开始废弃。建议使用[AutoExposure.setExposureBias](#setexposurebias11)替代。
7073
7074**系统能力:** SystemCapability.Multimedia.Camera.Core
7075
7076**参数:**
7077
7078| 参数名     | 类型                            | 必填  | 说明                                                                                                                                                                                    |
7079| -------- | -------------------------------|-----|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
7080| exposureBias   | number                   | 是  | 曝光补偿,[getExposureBiasRange](#getexposurebiasrange11)查询支持的范围,如果设置超过支持范围的值,自动匹配到就近临界点。曝光补偿存在步长,如步长为0.5。则设置1.2时,获取到实际生效曝光补偿为1.0。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。传参为null或者undefined,作为0处理,曝光补偿设置0。 |
7081
7082**错误码:**
7083
7084以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
7085
7086| 错误码ID         | 错误信息        |
7087| --------------- | --------------- |
7088| 7400103                |  Session not config.                                   |
7089
7090**示例:**
7091
7092```ts
7093import { BusinessError } from '@kit.BasicServicesKit';
7094
7095function setExposureBias(captureSession: camera.CaptureSession, biasRangeArray: Array<number>): void {
7096  if (biasRangeArray && biasRangeArray.length > 0) {
7097    let exposureBias = biasRangeArray[0];
7098    try {
7099      captureSession.setExposureBias(exposureBias);
7100    } catch (error) {
7101      // 失败返回错误码error.code并处理。
7102      let err = error as BusinessError;
7103      console.error(`The setExposureBias call failed. error code: ${err.code}`);
7104    }
7105  }
7106}
7107```
7108
7109### getExposureValue<sup>(deprecated)</sup>
7110
7111getExposureValue(): number
7112
7113查询当前曝光值。
7114
7115> **说明:**
7116>从 API version 10开始支持,从API version 11开始废弃。建议使用[AutoExposure.getExposureValue](#getexposurevalue11)替代。
7117
7118**系统能力:** SystemCapability.Multimedia.Camera.Core
7119
7120**返回值:**
7121
7122| 类型        | 说明                          |
7123| ---------- | ----------------------------- |
7124| number    | 获取曝光值。曝光补偿存在步长,如步长为0.5。则设置1.2时,获取到实际生效曝光补偿为1.0。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
7125
7126**错误码:**
7127
7128以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
7129
7130| 错误码ID         | 错误信息        |
7131| --------------- | --------------- |
7132| 7400103                |  Session not config.                                   |
7133
7134**示例:**
7135
7136```ts
7137import { BusinessError } from '@kit.BasicServicesKit';
7138
7139function getExposureValue(captureSession: camera.CaptureSession): number {
7140  const invalidValue: number = -1;
7141  let exposureValue: number = invalidValue;
7142  try {
7143    exposureValue = captureSession.getExposureValue();
7144  } catch (error) {
7145    // 失败返回错误码error.code并处理。
7146    let err = error as BusinessError;
7147    console.error(`The getExposureValue call failed. error code: ${err.code}`);
7148  }
7149  return exposureValue;
7150}
7151```
7152
7153### isFocusModeSupported<sup>(deprecated)</sup>
7154
7155isFocusModeSupported(afMode: FocusMode): boolean
7156
7157检测对焦模式是否支持。
7158
7159> **说明:**
7160>从 API version 10开始支持,从API version 11开始废弃。建议使用[Focus.isFocusModeSupported](#isfocusmodesupported11)替代。
7161
7162**系统能力:** SystemCapability.Multimedia.Camera.Core
7163
7164**参数:**
7165
7166| 参数名      | 类型                     | 必填 | 说明                              |
7167| -------- | ----------------------- | ---- | -------------------------------- |
7168| afMode   | [FocusMode](#focusmode) | 是   | 指定的焦距模式。                    |
7169
7170**返回值:**
7171
7172| 类型        | 说明                          |
7173| ---------- | ----------------------------- |
7174| boolean    | 返回true表示支持该焦距模式,false表示不支持。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
7175
7176**错误码:**
7177
7178以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
7179
7180| 错误码ID         | 错误信息        |
7181| --------------- | --------------- |
7182| 7400103                |  Session not config.                                   |
7183
7184**示例:**
7185
7186```ts
7187import { BusinessError } from '@kit.BasicServicesKit';
7188
7189function isFocusModeSupported(captureSession: camera.CaptureSession): boolean {
7190  let status: boolean = false;
7191  try {
7192    status = captureSession.isFocusModeSupported(camera.FocusMode.FOCUS_MODE_AUTO);
7193  } catch (error) {
7194    // 失败返回错误码error.code并处理。
7195    let err = error as BusinessError;
7196    console.error(`The isFocusModeSupported call failed. error code: ${err.code}`);
7197  }
7198  return status;
7199}
7200```
7201
7202### setFocusMode<sup>(deprecated)</sup>
7203
7204setFocusMode(afMode: FocusMode): void
7205
7206设置对焦模式。
7207
7208进行设置之前,需要先检查设备是否支持指定的焦距模式,可使用方法[isFocusModeSupported](#isfocusmodesupporteddeprecated)。
7209
7210> **说明:**
7211>从 API version 10开始支持,从API version 11开始废弃。建议使用[Focus.setFocusMode](#setfocusmode11)替代。
7212
7213**系统能力:** SystemCapability.Multimedia.Camera.Core
7214
7215**参数:**
7216
7217| 参数名      | 类型                     | 必填 | 说明                 |
7218| -------- | ----------------------- | ---- | ------------------- |
7219| afMode   | [FocusMode](#focusmode) | 是   | 指定的焦距模式。       |
7220
7221**错误码:**
7222
7223以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
7224
7225| 错误码ID         | 错误信息        |
7226| --------------- | --------------- |
7227| 7400103                |  Session not config.                                   |
7228
7229**示例:**
7230
7231```ts
7232import { BusinessError } from '@kit.BasicServicesKit';
7233
7234function setFocusMode(captureSession: camera.CaptureSession): void {
7235  try {
7236    captureSession.setFocusMode(camera.FocusMode.FOCUS_MODE_AUTO);
7237  } catch (error) {
7238    // 失败返回错误码error.code并处理。
7239    let err = error as BusinessError;
7240    console.error(`The setFocusMode call failed. error code: ${err.code}`);
7241  }
7242}
7243```
7244
7245### getFocusMode<sup>(deprecated)</sup>
7246
7247getFocusMode(): FocusMode
7248
7249获取当前的对焦模式。
7250
7251> **说明:**
7252>从 API version 10开始支持,从API version 11开始废弃。建议使用[Focus.getFocusMode](#getfocusmode11)替代。
7253
7254**系统能力:** SystemCapability.Multimedia.Camera.Core
7255
7256**返回值:**
7257
7258| 类型        | 说明                          |
7259| ---------- | ----------------------------- |
7260| [FocusMode](#focusmode)   | 获取当前设备的焦距模式。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
7261
7262**错误码:**
7263
7264以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
7265
7266| 错误码ID         | 错误信息        |
7267| --------------- | --------------- |
7268| 7400103                |  Session not config.                                   |
7269
7270**示例:**
7271
7272```ts
7273import { BusinessError } from '@kit.BasicServicesKit';
7274
7275function getFocusMode(captureSession: camera.CaptureSession): camera.FocusMode | undefined {
7276  let afMode: camera.FocusMode | undefined = undefined;
7277  try {
7278    afMode = captureSession.getFocusMode();
7279  } catch (error) {
7280    // 失败返回错误码error.code并处理。
7281    let err = error as BusinessError;
7282    console.error(`The getFocusMode call failed. error code: ${err.code}`);
7283  }
7284  return afMode;
7285}
7286```
7287
7288### setFocusPoint<sup>(deprecated)</sup>
7289
7290setFocusPoint(point: Point): void
7291
7292设置焦点,焦点应在0-1坐标系内,该坐标系左上角为{0,0},右下角为{1,1}。
7293此坐标系是以设备充电口在右侧时的横向设备方向为基准的,例如应用的预览界面布局以
7294设备充电口在下侧时的竖向方向为基准,布局宽高为{w,h},且触碰点为{x,y},
7295则转换后的坐标点为{y/h,1-x/w}。
7296
7297> **说明:**
7298>从 API version 10开始支持,从API version 11开始废弃。建议使用[Focus.setFocusPoint](#setfocuspoint11)替代。
7299
7300**系统能力:** SystemCapability.Multimedia.Camera.Core
7301
7302**参数:**
7303
7304| 参数名   | 类型                     | 必填  | 说明                 |
7305|-------| ----------------------- |-----| ------------------- |
7306| point | [Point](#point)         | 是  | 焦点。x,y设置范围应在[0,1]之内,超过范围,如果小于0设置0,大于1设置1。   |
7307
7308**错误码:**
7309
7310以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
7311
7312| 错误码ID         | 错误信息        |
7313| --------------- | --------------- |
7314| 7400103                |  Session not config.                                   |
7315
7316**示例:**
7317
7318```ts
7319import { BusinessError } from '@kit.BasicServicesKit';
7320
7321function setFocusPoint(captureSession: camera.CaptureSession): void {
7322  const focusPoint: camera.Point = {x: 1, y: 1};
7323  try {
7324    captureSession.setFocusPoint(focusPoint);
7325  } catch (error) {
7326    // 失败返回错误码error.code并处理。
7327    let err = error as BusinessError;
7328    console.error(`The setFocusPoint call failed. error code: ${err.code}`);
7329  }
7330}
7331```
7332
7333### getFocusPoint<sup>(deprecated)</sup>
7334
7335getFocusPoint(): Point
7336
7337查询焦点。
7338
7339> **说明:**
7340>从 API version 10开始支持,从API version 11开始废弃。建议使用[Focus.getFocusPoint](#getfocuspoint11)替代。
7341
7342**系统能力:** SystemCapability.Multimedia.Camera.Core
7343
7344**返回值:**
7345
7346| 类型        | 说明                          |
7347| ---------- | ----------------------------- |
7348| [Point](#point)    | 用于获取当前焦点。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
7349
7350**错误码:**
7351
7352以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
7353
7354| 错误码ID         | 错误信息        |
7355| --------------- | --------------- |
7356| 7400103                |  Session not config.                                   |
7357
7358**示例:**
7359
7360```ts
7361import { BusinessError } from '@kit.BasicServicesKit';
7362
7363function getFocusPoint(captureSession: camera.CaptureSession): camera.Point | undefined {
7364  let point: camera.Point | undefined = undefined;
7365  try {
7366    point = captureSession.getFocusPoint();
7367  } catch (error) {
7368    // 失败返回错误码error.code并处理。
7369    let err = error as BusinessError;
7370    console.error(`The getFocusPoint call failed. error code: ${err.code}`);
7371  }
7372  return point;
7373}
7374```
7375
7376### getFocalLength<sup>(deprecated)</sup>
7377
7378getFocalLength(): number
7379
7380查询焦距值。
7381
7382> **说明:**
7383>从 API version 10开始支持,从API version 11开始废弃。建议使用[Focus.getFocalLength](#getfocallength11)替代。
7384
7385**系统能力:** SystemCapability.Multimedia.Camera.Core
7386
7387**返回值:**
7388
7389| 类型        | 说明                          |
7390| ---------- | ----------------------------- |
7391| number    | 用于获取当前焦距。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
7392
7393**错误码:**
7394
7395以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
7396
7397| 错误码ID         | 错误信息        |
7398| --------------- | --------------- |
7399| 7400103                |  Session not config.                                   |
7400
7401**示例:**
7402
7403```ts
7404import { BusinessError } from '@kit.BasicServicesKit';
7405
7406function getFocalLength(captureSession: camera.CaptureSession): number {
7407  const invalidValue: number = -1;
7408  let focalLength: number = invalidValue;
7409  try {
7410    focalLength = captureSession.getFocalLength();
7411  } catch (error) {
7412    // 失败返回错误码error.code并处理。
7413    let err = error as BusinessError;
7414    console.error(`The getFocalLength call failed. error code: ${err.code}`);
7415  }
7416  return focalLength;
7417}
7418```
7419
7420### getZoomRatioRange<sup>(deprecated)</sup>
7421
7422getZoomRatioRange(): Array\<number\>
7423
7424获取支持的变焦范围。
7425
7426> **说明:**
7427>从 API version 10开始支持,从API version 11开始废弃。建议使用[Zoom.getZoomRatioRange](#getzoomratiorange11)替代。
7428
7429**系统能力:** SystemCapability.Multimedia.Camera.Core
7430
7431**返回值:**
7432
7433| 类型        | 说明                          |
7434| ---------- | ----------------------------- |
7435| Array\<number\>   | 用于获取可变焦距比范围,返回的数组包括其最小值和最大值。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
7436
7437**错误码:**
7438
7439以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
7440
7441| 错误码ID         | 错误信息        |
7442| --------------- | --------------- |
7443| 7400103                |  Session not config.                                   |
7444
7445**示例:**
7446
7447```ts
7448import { BusinessError } from '@kit.BasicServicesKit';
7449
7450function getZoomRatioRange(captureSession: camera.CaptureSession): Array<number> {
7451  let zoomRatioRange: Array<number> = [];
7452  try {
7453    zoomRatioRange = captureSession.getZoomRatioRange();
7454  } catch (error) {
7455    // 失败返回错误码error.code并处理。
7456    let err = error as BusinessError;
7457    console.error(`The getZoomRatioRange call failed. error code: ${err.code}`);
7458  }
7459  return zoomRatioRange;
7460}
7461```
7462
7463### setZoomRatio<sup>(deprecated)</sup>
7464
7465setZoomRatio(zoomRatio: number): void
7466
7467设置变焦比,变焦精度最高为小数点后两位,如果设置超过支持的精度范围,则只保留精度范围内数值。
7468
7469> **说明:**
7470>从 API version 10开始支持,从API version 11开始废弃。建议使用[Zoom.setZoomRatio](#setzoomratio11)替代。
7471
7472**系统能力:** SystemCapability.Multimedia.Camera.Core
7473
7474**参数:**
7475
7476| 参数名       | 类型                  | 必填  | 说明                 |
7477| --------- | -------------------- |-----| ------------------- |
7478| zoomRatio | number               | 是  | 可变焦距比,通过[getZoomRatioRange](#getzoomratiorange11)获取支持的变焦范围,如果设置超过支持范围的值,则只保留精度范围内数值。传参为null或者undefined,作为0处理,变焦设置最小值。 |
7479
7480**错误码:**
7481
7482以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
7483
7484| 错误码ID         | 错误信息        |
7485| --------------- | --------------- |
7486| 7400103                |  Session not config.                                   |
7487
7488**示例:**
7489
7490```ts
7491import { BusinessError } from '@kit.BasicServicesKit';
7492
7493function setZoomRatio(captureSession: camera.CaptureSession, zoomRatioRange: Array<number>): void {
7494  if (zoomRatioRange === undefined || zoomRatioRange.length <= 0) {
7495    return;
7496  }
7497  let zoomRatio = zoomRatioRange[0];
7498  try {
7499    captureSession.setZoomRatio(zoomRatio);
7500  } catch (error) {
7501    // 失败返回错误码error.code并处理。
7502    let err = error as BusinessError;
7503    console.error(`The setZoomRatio call failed. error code: ${err.code}`);
7504  }
7505}
7506```
7507
7508### getZoomRatio<sup>(deprecated)</sup>
7509
7510getZoomRatio(): number
7511
7512获取当前的变焦比。
7513
7514> **说明:**
7515>从 API version 10开始支持,从API version 11开始废弃。建议使用[Zoom.getZoomRatio](#getzoomratio11)替代。
7516
7517**系统能力:** SystemCapability.Multimedia.Camera.Core
7518
7519**返回值:**
7520
7521| 类型        | 说明                          |
7522| ---------- | ----------------------------- |
7523| number    | 获取当前的变焦比结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
7524
7525**错误码:**
7526
7527以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
7528
7529| 错误码ID         | 错误信息        |
7530| --------------- | --------------- |
7531| 7400103                |  Session not config.                                   |
7532
7533**示例:**
7534
7535```ts
7536import { BusinessError } from '@kit.BasicServicesKit';
7537
7538function getZoomRatio(captureSession: camera.CaptureSession): number {
7539  const invalidValue: number = -1;
7540  let zoomRatio: number = invalidValue;
7541  try {
7542    zoomRatio = captureSession.getZoomRatio();
7543  } catch (error) {
7544    // 失败返回错误码error.code并处理。
7545    let err = error as BusinessError;
7546    console.error(`The getZoomRatio call failed. error code: ${err.code}`);
7547  }
7548  return zoomRatio;
7549}
7550```
7551
7552### isVideoStabilizationModeSupported<sup>(deprecated)</sup>
7553
7554isVideoStabilizationModeSupported(vsMode: VideoStabilizationMode): boolean
7555
7556查询是否支持指定的视频防抖模式。
7557
7558> **说明:**
7559>从 API version 10开始支持,从API version 11开始废弃。建议使用[Stabilization.isVideoStabilizationModeSupported](#isvideostabilizationmodesupported11)替代。
7560
7561**系统能力:** SystemCapability.Multimedia.Camera.Core
7562
7563**参数:**
7564
7565| 参数名      | 类型                                              | 必填 | 说明                             |
7566| -------- | ------------------------------------------------- | ---- | ------------------------------ |
7567| vsMode   | [VideoStabilizationMode](#videostabilizationmode) | 是   | 视频防抖模式。传参为null或者undefined,作为0处理,超级防抖模式关闭。              |
7568
7569**返回值:**
7570
7571| 类型        | 说明                          |
7572| ---------- | ----------------------------- |
7573| boolean    | 返回视频防抖模式是否支持,true表示支持,false表示不支持。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
7574
7575**错误码:**
7576
7577以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
7578
7579| 错误码ID         | 错误信息        |
7580| --------------- | --------------- |
7581| 7400103                |  Session not config.                                   |
7582
7583**示例:**
7584
7585```ts
7586import { BusinessError } from '@kit.BasicServicesKit';
7587
7588function isVideoStabilizationModeSupported(captureSession: camera.CaptureSession): boolean {
7589  let isSupported: boolean = false;
7590  try {
7591    isSupported = captureSession.isVideoStabilizationModeSupported(camera.VideoStabilizationMode.OFF);
7592  } catch (error) {
7593    // 失败返回错误码error.code并处理。
7594    let err = error as BusinessError;
7595    console.error(`The isVideoStabilizationModeSupported call failed. error code: ${err.code}`);
7596  }
7597  return isSupported;
7598}
7599```
7600
7601### getActiveVideoStabilizationMode<sup>(deprecated)</sup>
7602
7603getActiveVideoStabilizationMode(): VideoStabilizationMode
7604
7605查询当前正在使用的视频防抖模式。
7606
7607> **说明:**
7608>从 API version 10开始支持,从API version 11开始废弃。建议使用[Stabilization.getActiveVideoStabilizationMode](#getactivevideostabilizationmode11)替代。
7609
7610**系统能力:** SystemCapability.Multimedia.Camera.Core
7611
7612**返回值:**
7613
7614| 类型        | 说明                          |
7615| ---------- | ----------------------------- |
7616| [VideoStabilizationMode](#videostabilizationmode)    | 视频防抖是否正在使用。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
7617
7618**错误码:**
7619
7620以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
7621
7622| 错误码ID         | 错误信息        |
7623| --------------- | --------------- |
7624| 7400103                |  Session not config.                                   |
7625
7626**示例:**
7627
7628```ts
7629import { BusinessError } from '@kit.BasicServicesKit';
7630
7631function getActiveVideoStabilizationMode(captureSession: camera.CaptureSession): camera.VideoStabilizationMode | undefined {
7632  let vsMode: camera.VideoStabilizationMode | undefined = undefined;
7633  try {
7634    vsMode = captureSession.getActiveVideoStabilizationMode();
7635  } catch (error) {
7636    // 失败返回错误码error.code并处理。
7637    let err = error as BusinessError;
7638    console.error(`The getActiveVideoStabilizationMode call failed. error code: ${err.code}`);
7639  }
7640  return vsMode;
7641}
7642```
7643
7644### setVideoStabilizationMode<sup>(deprecated)</sup>
7645
7646setVideoStabilizationMode(mode: VideoStabilizationMode): void
7647
7648设置视频防抖模式。需要先检查设备是否支持对应的防抖模式,可以通过[isVideoStabilizationModeSupported](#isvideostabilizationmodesupporteddeprecated)方法判断所设置的模式是否支持。
7649
7650> **说明:**
7651>从 API version 10开始支持,从API version 11开始废弃。建议使用[Stabilization.setVideoStabilizationMode](#setvideostabilizationmode11)替代。
7652
7653**系统能力:** SystemCapability.Multimedia.Camera.Core
7654
7655**参数:**
7656
7657| 参数名      | 类型                                              | 必填 | 说明                    |
7658| -------- | ------------------------------------------------- | ---- | --------------------- |
7659| mode     | [VideoStabilizationMode](#videostabilizationmode) | 是   | 需要设置的视频防抖模式。传参为null或者undefined,作为0处理,超级防抖模式关闭。   |
7660
7661**错误码:**
7662
7663以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
7664
7665| 错误码ID         | 错误信息        |
7666| --------------- | --------------- |
7667| 7400103                |  Session not config.                                   |
7668
7669**示例:**
7670
7671```ts
7672import { BusinessError } from '@kit.BasicServicesKit';
7673
7674function setVideoStabilizationMode(captureSession: camera.CaptureSession): void {
7675  try {
7676    captureSession.setVideoStabilizationMode(camera.VideoStabilizationMode.OFF);
7677  } catch (error) {
7678    // 失败返回错误码error.code并处理。
7679    let err = error as BusinessError;
7680    console.error(`The setVideoStabilizationMode call failed. error code: ${err.code}`);
7681  }
7682}
7683```
7684
7685### on('focusStateChange')<sup>(deprecated)</sup>
7686
7687on(type: 'focusStateChange', callback: AsyncCallback\<FocusState\>): void
7688
7689监听相机聚焦的状态变化,通过注册回调函数获取结果。使用callback异步回调。
7690
7691> **说明:**
7692> 从 API version 10开始支持,从API version 11开始废弃。建议使用[VideoSession.on('focusStateChange')](#onfocusstatechange11-1)替代。
7693>
7694> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
7695
7696**系统能力:** SystemCapability.Multimedia.Camera.Core
7697
7698**参数:**
7699
7700| 参数名     | 类型                                      | 必填 | 说明                       |
7701| -------- | ----------------------------------------- | ---- | ------------------------ |
7702| type     | string                                    | 是   | 监听事件,固定为'focusStateChange',session 创建成功可监听。仅当自动对焦模式时,且相机对焦状态发生改变时可触发该事件。 |
7703| callback | AsyncCallback\<[FocusState](#focusstate)\> | 是   | 回调函数,用于获取当前对焦状态。  |
7704
7705**示例:**
7706
7707```ts
7708import { BusinessError } from '@kit.BasicServicesKit';
7709
7710function registerFocusStateChange(captureSession: camera.CaptureSession): void {
7711  captureSession.on('focusStateChange', (err: BusinessError, focusState: camera.FocusState) => {
7712    if (err !== undefined && err.code !== 0) {
7713      console.error(`Callback Error, errorCode: ${err.code}`);
7714      return;
7715    }
7716    console.info(`Focus state: ${focusState}`);
7717  });
7718}
7719```
7720
7721### off('focusStateChange')<sup>(deprecated)</sup>
7722
7723off(type: 'focusStateChange', callback?: AsyncCallback\<FocusState\>): void
7724
7725注销监听相机聚焦的状态变化。
7726
7727> **说明:**
7728>从 API version 10开始支持,从API version 11开始废弃。建议使用[VideoSession.off('focusStateChange')](#offfocusstatechange11-1)替代。
7729
7730**系统能力:** SystemCapability.Multimedia.Camera.Core
7731
7732**参数:**
7733
7734| 参数名     | 类型                                      | 必填 | 说明                       |
7735| -------- | ----------------------------------------- | ---- | ------------------------ |
7736| type     | string                                    | 是   | 监听事件,固定为'focusStateChange',session 创建成功可监听。|
7737| callback | AsyncCallback\<[FocusState](#focusstate)\> | 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
7738
7739**示例:**
7740
7741```ts
7742function unregisterFocusStateChange(captureSession: camera.CaptureSession): void {
7743  captureSession.off('focusStateChange');
7744}
7745```
7746
7747### on('error')<sup>(deprecated)</sup>
7748
7749on(type: 'error', callback: ErrorCallback): void
7750
7751监听拍照会话的错误事件,通过注册回调函数获取结果。使用callback异步回调。
7752
7753> **说明:**
7754>
7755> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
7756
7757> **说明:**
7758>从 API version 10开始支持,从API version 11开始废弃。建议使用[VideoSession.on('error')](#onerror11-1)替代。
7759
7760**系统能力:** SystemCapability.Multimedia.Camera.Core
7761
7762**参数:**
7763
7764| 参数名     | 类型                                                                       | 必填 | 说明                           |
7765| -------- |--------------------------------------------------------------------------| ---- | ------------------------------ |
7766| type     | string                                                                   | 是   | 监听事件,固定为'error',session创建成功之后可监听该接口。session调用相关接口出现错误时会触发该事件,比如调用[beginConfig](#beginconfigdeprecated),[commitConfig](#commitconfigdeprecated-1),[addInput](#addinputdeprecated)等接口发生错误时返回错误信息。 |
7767| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | 是   | 回调函数,用于获取错误信息。返回错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。        |
7768
7769**示例:**
7770
7771```ts
7772import { BusinessError } from '@kit.BasicServicesKit';
7773
7774function registerCaptureSessionError(captureSession: camera.CaptureSession): void {
7775  captureSession.on('error', (error: BusinessError) => {
7776    console.error(`Capture session error code: ${error.code}`);
7777  });
7778}
7779```
7780
7781### off('error')<sup>(deprecated)</sup>
7782
7783off(type: 'error', callback?: ErrorCallback): void
7784
7785注销监听拍照会话的错误事件,通过注册回调函数获取结果。
7786
7787> **说明:**
7788>从 API version 10开始支持,从API version 11开始废弃。建议使用[VideoSession.off('error')](#offerror11-1)替代。
7789
7790**系统能力:** SystemCapability.Multimedia.Camera.Core
7791
7792**参数:**
7793
7794| 参数名     | 类型                                                          | 必填 | 说明                           |
7795| -------- | ----------------------------------------------------------- | ---- | ------------------------------ |
7796| type     | string                                                      | 是   | 监听事件,固定为'error',session创建成功之后可监听该接口。 |
7797| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback)| 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
7798
7799**示例:**
7800
7801```ts
7802function unregisterCaptureSessionError(captureSession: camera.CaptureSession): void {
7803  captureSession.off('error');
7804}
7805```
7806## ColorManagementQuery<sup>12+</sup>
7807
7808色彩管理类,用于查询色彩空间参数。
7809
7810### getSupportedColorSpaces<sup>12+</sup>
7811
7812getSupportedColorSpaces(): Array\<colorSpaceManager.ColorSpace\>
7813
7814获取支持的色彩空间列表。
7815
7816**系统能力:** SystemCapability.Multimedia.Camera.Core
7817
7818**返回值:**
7819
7820| 类型                                             | 说明                           |
7821| ----------------------------------------------- | ---------------------------- |
7822| Array<[colorSpaceManager.ColorSpace](../apis-arkgraphics2d/js-apis-colorSpaceManager.md#colorspace)>| 支持的色彩空间列表。     |
7823
7824**错误码:**
7825
7826以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
7827
7828| 错误码ID         | 错误信息        |
7829| --------------- | --------------- |
7830| 7400103         |  Session not config, only throw in session usage.                       |
7831
7832**示例:**
7833
7834```ts
7835import { BusinessError } from '@kit.BasicServicesKit';
7836import { colorSpaceManager } from '@kit.ArkGraphics2D';
7837
7838function getSupportedColorSpaces(session: camera.PhotoSession): Array<colorSpaceManager.ColorSpace> {
7839  let colorSpaces: Array<colorSpaceManager.ColorSpace> = [];
7840  try {
7841    colorSpaces = session.getSupportedColorSpaces();
7842  } catch (error) {
7843    let err = error as BusinessError;
7844    console.error(`The getSupportedColorSpaces call failed. error code: ${err.code}`);
7845  }
7846  return colorSpaces;
7847}
7848```
7849## ColorManagement<sup>12+</sup>
7850
7851ColorManagement extends [ColorManagementQuery](#colormanagementquery12)
7852
7853色彩管理类,继承自[ColorManagementQuery](#colormanagementquery12),用于设置色彩空间参数。
7854
7855### setColorSpace<sup>12+</sup>
7856
7857setColorSpace(colorSpace: colorSpaceManager.ColorSpace): void
7858
7859设置色彩空间。可以先通过[getSupportedColorSpaces](#getsupportedcolorspaces12)获取当前设备所支持的ColorSpaces。
7860
7861**P3广色域与HDR高动态范围成像**
7862
7863应用可以下发不同的色彩空间(ColorSpace)参数来支持P3广色域以及HDR的功能。
7864当应用不主动设置色彩空间时,拍照以及录像模式默认为HDR拍摄效果。
7865在拍照模式下设置HDR高显效果可直接支持P3色域。
7866应用针对不同模式使能HDR效果以及设置的色彩空间可参考下表。
7867
7868**录像模式:**
7869
7870| SDR/HRD拍摄         | CameraFormat             | ColorSpace       |
7871|--------------------|--------------------------|------------------|
7872| SDR                | CAMERA_FORMAT_YUV_420_SP | BT709_LIMIT      |
7873| HDR_VIVID(Default) | CAMERA_FORMAT_YCRCB_P010 | BT2020_HLG_LIMIT |
7874
7875**拍照模式:**
7876
7877| SDR/HRD拍摄    | ColorSpace |
7878|--------------|------------|
7879| SDR          | SRGB       |
7880| HDR(Default) | DISPLAY_P3 |
7881
7882**系统能力:** SystemCapability.Multimedia.Camera.Core
7883
7884**参数:**
7885
7886| 参数名         | 类型                 | 必填 | 说明                      |
7887| ------------ |---------------------- | -- | -------------------------- |
7888| colorSpace | [colorSpaceManager.ColorSpace](../apis-arkgraphics2d/js-apis-colorSpaceManager.md#colorspace)  | 是 | 色彩空间,通过[getSupportedColorSpaces](#getsupportedcolorspaces12)接口获取。   |
7889
7890**错误码:**
7891
7892以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
7893
7894| 错误码ID         | 错误信息        |
7895| --------------- | --------------- |
7896| 7400101         |  Parameter missing or parameter type incorrect.     |
7897| 7400102         |  The colorSpace does not match the format.     |
7898| 7400103         |  Session not config.                           |
7899| 7400201         |  Camera service fatal error.                   |
7900
7901**示例:**
7902
7903```ts
7904import { BusinessError } from '@kit.BasicServicesKit';
7905import { colorSpaceManager } from '@kit.ArkGraphics2D';
7906
7907function setColorSpace(session: camera.PhotoSession, colorSpaces: Array<colorSpaceManager.ColorSpace>): void {
7908  if (colorSpaces === undefined || colorSpaces.length <= 0) {
7909    return;
7910  }
7911  try {
7912    session.setColorSpace(colorSpaces[0]);
7913  } catch (error) {
7914    let err = error as BusinessError;
7915    console.error(`The setColorSpace call failed, error code: ${err.code}`);
7916  }
7917}
7918```
7919
7920### getActiveColorSpace<sup>12+</sup>
7921
7922getActiveColorSpace(): colorSpaceManager.ColorSpace
7923
7924获取当前设置的色彩空间。
7925
7926**系统能力:** SystemCapability.Multimedia.Camera.Core
7927
7928**返回值:**
7929
7930| 类型                                             | 说明                           |
7931| ----------------------------------------------- | ---------------------------- |
7932| [colorSpaceManager.ColorSpace](../apis-arkgraphics2d/js-apis-colorSpaceManager.md#colorspace)               | 当前设置的色彩空间。                |
7933
7934**错误码:**
7935
7936以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
7937
7938| 错误码ID         | 错误信息        |
7939| --------------- | --------------- |
7940| 7400103                |  Session not config.                                   |
7941
7942**示例:**
7943
7944```ts
7945import { BusinessError } from '@kit.BasicServicesKit';
7946import { colorSpaceManager } from '@kit.ArkGraphics2D';
7947
7948function getActiveColorSpace(session: camera.PhotoSession): colorSpaceManager.ColorSpace | undefined {
7949  let colorSpace: colorSpaceManager.ColorSpace | undefined = undefined;
7950  try {
7951    colorSpace = session.getActiveColorSpace();
7952  } catch (error) {
7953    let err = error as BusinessError;
7954    console.error(`The getActiveColorSpace call failed. error code: ${err.code}`);
7955  }
7956  return colorSpace;
7957}
7958```
7959
7960## AutoDeviceSwitchQuery<sup>13+</sup>
7961
7962自动切换镜头查询类,用于查询设备是否支持自动切换镜头。
7963
7964### isAutoDeviceSwitchSupported<sup>13+</sup>
7965
7966isAutoDeviceSwitchSupported(): boolean
7967
7968查询设备是否支持自动切换镜头能力。
7969
7970**系统能力:** SystemCapability.Multimedia.Camera.Core
7971
7972**返回值:**
7973
7974| 类型                                             | 说明          |
7975| ----------------------------------------------- |-------------|
7976| boolean               | 是否支持自动切换镜头。 |
7977
7978**错误码:**
7979
7980以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
7981
7982| 错误码ID         | 错误信息                                              |
7983| --------------- |---------------------------------------------------|
7984| 7400103         | Session not config, only throw in session usage.  |
7985
7986**示例:**
7987
7988```ts
7989import { BusinessError } from '@kit.BasicServicesKit';
7990
7991function isAutoDeviceSwitchSupported(session: camera.PhotoSession): boolean {
7992  let isSupported = false;
7993  try {
7994    isSupported = session.isAutoDeviceSwitchSupported();
7995  } catch (error) {
7996    let err = error as BusinessError;
7997    console.error(`The isAutoDeviceSwitchSupported call failed, error code: ${err.code}`);
7998  }
7999  return isSupported;
8000}
8001```
8002
8003## AutoDeviceSwitch<sup>13+</sup>
8004
8005AutoDeviceSwitch extends [AutoDeviceSwitchQuery](#autodeviceswitchquery13)
8006
8007自动切换镜头类,继承自[AutoDeviceSwitchQuery](#autodeviceswitchquery13),用于使能或去使能自动切换镜头。
8008
8009使用建议:自动切换镜头功能由系统自动完成输入设备切换、会话配置和参数接续,
8010如系统发现镜头切换时,两颗镜头的变焦范围不一致,则会通过[AutoDeviceSwitchStatus](#autodeviceswitchstatus13)中的isDeviceCapabilityChanged字段告知应用,
8011但仍需要应用自己处理UX的变更(如变焦范围的调整,需要重新通过[getZoomRatioRange](#getzoomratiorange11)接口获取数据并更新UX),
8012因此更适用于极简UX交换的场景。
8013
8014### enableAutoDeviceSwitch<sup>13+</sup>
8015
8016enableAutoDeviceSwitch(enabled: boolean): void
8017
8018使能或去使能自动切换镜头。可以先通过[isAutoDeviceSwitchSupported](#isautodeviceswitchsupported13)获取当前设备是否支持自动切换镜头。
8019
8020> **说明:**
8021> 该接口仅用于有多个前置镜头的折叠设备,在不同的折叠状态下可自动切换到当前可使用的前置镜头。无法实现前后置镜头的切换。
8022
8023**系统能力:** SystemCapability.Multimedia.Camera.Core
8024
8025**参数:**
8026
8027| 参数名         | 类型  | 必填 | 说明  |
8028| ----------- |---------------------- |---| -------------------------- |
8029| enabled | boolean  | 是 | 使能或去使能自动切换镜头。   |
8030
8031**错误码:**
8032
8033以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
8034
8035| 错误码ID   | 错误信息                                                                                                                                       |
8036|----------|------------------------------------------------------------------------------------------------------------------------------------------------|
8037| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameters verification failed. |
8038| 7400102  | Operation not allowed.                                                                                                                         |
8039| 7400103  | Session not config.                                                                                                                            |
8040| 7400201  | Camera service fatal error.                                                                                                                    |
8041
8042**示例:**
8043
8044```ts
8045import { BusinessError } from '@kit.BasicServicesKit';
8046
8047function enableAutoDeviceSwitch(session: camera.PhotoSession, isEnable: boolean): void {
8048  try {
8049    session.enableAutoDeviceSwitch(isEnable);
8050  } catch (error) {
8051    let err = error as BusinessError;
8052    console.error(`The enableAutoDeviceSwitch call failed, error code: ${err.code}`);
8053  }
8054}
8055```
8056
8057## PreconfigType<sup>12+</sup>
8058
8059枚举,提供预配置的类型。
8060
8061**系统能力:** SystemCapability.Multimedia.Camera.Core
8062
8063| 名称                      | 值 | 说明         |
8064|-------------------------|---|------------|
8065| PRECONFIG_720P          | 0 | 720P预配置。   |
8066| PRECONFIG_1080P         | 1 | 1080P预配置。  |
8067| PRECONFIG_4K            | 2 | 4K预配置。     |
8068| PRECONFIG_HIGH_QUALITY  | 3 | 高质量预配置。    |
8069
8070## PreconfigRatio<sup>12+</sup>
8071
8072枚举,提供预配置的分辨率比例。
8073
8074**系统能力:** SystemCapability.Multimedia.Camera.Core
8075
8076| 名称                       | 值 | 说明      |
8077|--------------------------|---|---------|
8078| PRECONFIG_RATIO_1_1      | 0 | 1:1画幅。  |
8079| PRECONFIG_RATIO_4_3      | 1 | 4:3画幅。  |
8080| PRECONFIG_RATIO_16_9     | 2 | 16:9画幅。 |
8081
8082## PhotoSession<sup>11+</sup>
8083
8084PhotoSession extends [Session](#session11), [Flash](#flash11), [AutoExposure](#autoexposure11), [Focus](#focus11), [Zoom](#zoom11), [ColorManagement](#colormanagement12), [AutoDeviceSwitch](#autodeviceswitch13)
8085
8086普通拍照模式会话类,提供了对闪光灯、曝光、对焦、变焦、色彩空间的操作。
8087
8088> **说明:**
8089>
8090> 默认的拍照模式,用于拍摄标准照片。支持多种照片格式和分辨率,适合大多数日常拍摄场景。
8091
8092### canPreconfig<sup>12+</sup>
8093
8094canPreconfig(preconfigType: PreconfigType, preconfigRatio?: PreconfigRatio): boolean
8095
8096查询当前Session是否支持指定的预配置类型。
8097
8098**系统能力:** SystemCapability.Multimedia.Camera.Core
8099
8100**参数:**
8101
8102| 参数名            | 类型                                  | 必填  | 说明              |
8103|----------------|-------------------------------------|-----|-----------------|
8104| preconfigType  | [PreconfigType](#preconfigtype12)   | 是   | 指定配置预期分辨率。      |
8105| preconfigRatio | [PreconfigRatio](#preconfigratio12) | 否   | 可选画幅比例,默认为4:3。  |
8106
8107**返回值:**
8108
8109| 类型      | 说明                                      |
8110|---------|-----------------------------------------|
8111| boolean | true: 支持指定预配值类型。<br/>false: 不支持指定预配值类型。 |
8112
8113**错误码:**
8114
8115以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
8116
8117| 错误码ID   | 错误信息                        |
8118|---------|-----------------------------|
8119| 7400201 | Camera service fatal error. |
8120
8121**示例:**
8122
8123```ts
8124function testCanPreconfig(photoSession: camera.PhotoSession, preconfigType: camera.PreconfigType,
8125  preconfigRatio: camera.PreconfigRatio): void {
8126  try {
8127    let result = photoSession.canPreconfig(preconfigType, preconfigRatio);
8128    console.info(`canPreconfig ${preconfigType} ${preconfigRatio} result is : ${result}`);
8129  } catch (error) {
8130    let err = error as BusinessError;
8131    console.error(`The canPreconfig call failed. error code: ${err.code}`);
8132  }
8133}
8134```
8135
8136### preconfig<sup>12+</sup>
8137
8138preconfig(preconfigType: PreconfigType, preconfigRatio?: PreconfigRatio): void
8139
8140对当前Session进行预配置。
8141
8142**系统能力:** SystemCapability.Multimedia.Camera.Core
8143
8144**参数:**
8145
8146| 参数名            | 类型                                  | 必填  | 说明              |
8147|----------------|-------------------------------------|-----|-----------------|
8148| preconfigType  | [PreconfigType](#preconfigtype12)   | 是   | 指定配置预期分辨率。      |
8149| preconfigRatio | [PreconfigRatio](#preconfigratio12) | 否   | 可选画幅比例,默认为4:3。  |
8150
8151**错误码:**
8152
8153以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
8154
8155| 错误码ID   | 错误信息                        |
8156|---------|-----------------------------|
8157| 7400201 | Camera service fatal error. |
8158
8159**示例:**
8160
8161```ts
8162function testPreconfig(photoSession: camera.PhotoSession, preconfigType: camera.PreconfigType,
8163  preconfigRatio: camera.PreconfigRatio): void {
8164  try {
8165    photoSession.preconfig(preconfigType, preconfigRatio);
8166    console.info(`preconfig ${preconfigType} ${preconfigRatio} success`);
8167  } catch (error) {
8168    let err = error as BusinessError;
8169    console.error(`The preconfig call failed. error code: ${err.code}`);
8170  }
8171}
8172```
8173
8174### on('error')<sup>11+</sup>
8175
8176on(type: 'error', callback: ErrorCallback): void
8177
8178监听普通拍照会话的错误事件,通过注册回调函数获取结果。使用callback异步回调。
8179
8180> **说明:**
8181>
8182> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
8183
8184**系统能力:** SystemCapability.Multimedia.Camera.Core
8185
8186**参数:**
8187
8188| 参数名     | 类型                                                          | 必填 | 说明                           |
8189| -------- | ----------------------------------------------------------- | ---- | ------------------------------ |
8190| type     | string                                                      | 是   | 监听事件,固定为'error',session创建成功之后可监听该接口。session调用相关接口出现错误时会触发该事件,比如调用[beginConfig](#beginconfig11),[commitConfig](#commitconfig11-1),[addInput](#addinput11)等接口发生错误时返回错误信息。 |
8191| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback)| 是   | 回调函数,用于获取错误信息。返回错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。        |
8192
8193**示例:**
8194
8195```ts
8196import { BusinessError } from '@kit.BasicServicesKit';
8197
8198function callback(err: BusinessError): void {
8199  console.error(`Photo session error code: ${err.code}`);
8200}
8201
8202function registerSessionError(photoSession: camera.PhotoSession): void {
8203  photoSession.on('error', callback);
8204}
8205```
8206
8207### off('error')<sup>11+</sup>
8208
8209off(type: 'error', callback?: ErrorCallback): void
8210
8211注销监听普通拍照会话的错误事件,通过注册回调函数获取结果。
8212
8213**系统能力:** SystemCapability.Multimedia.Camera.Core
8214
8215**参数:**
8216
8217| 参数名     | 类型                            | 必填 | 说明                           |
8218| -------- | -------------------------------- | ---- | ------------------------------ |
8219| type     | string                           | 是   | 监听事件,固定为'error',session创建成功之后可监听该接口。 |
8220| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback)| 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
8221
8222**示例:**
8223
8224```ts
8225function unregisterSessionError(photoSession: camera.PhotoSession): void {
8226  photoSession.off('error');
8227}
8228```
8229
8230### on('focusStateChange')<sup>11+</sup>
8231
8232on(type: 'focusStateChange', callback: AsyncCallback\<FocusState\>): void
8233
8234监听相机聚焦的状态变化,通过注册回调函数获取结果。使用callback异步回调。
8235
8236> **说明:**
8237>
8238> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
8239
8240**系统能力:** SystemCapability.Multimedia.Camera.Core
8241
8242**参数:**
8243
8244| 参数名     | 类型                    | 必填 | 说明                       |
8245| -------- | ---------------- | ---- | ------------------------ |
8246| type     | string                                    | 是   | 监听事件,固定为'focusStateChange',session创建成功可监听。仅当自动对焦模式时,且相机对焦状态发生改变时可触发该事件。 |
8247| callback | AsyncCallback\<[FocusState](#focusstate)\> | 是   | 回调函数,用于获取当前对焦状态。  |
8248
8249**示例:**
8250
8251```ts
8252import { BusinessError } from '@kit.BasicServicesKit';
8253
8254function callback(err: BusinessError, focusState: camera.FocusState): void {
8255  if (err !== undefined && err.code !== 0) {
8256    console.error(`Callback Error, errorCode: ${err.code}`);
8257    return;
8258  }
8259  console.info(`Focus state: ${focusState}`);
8260}
8261
8262function registerFocusStateChange(photoSession: camera.PhotoSession): void {
8263  photoSession.on('focusStateChange', callback);
8264}
8265```
8266
8267### off('focusStateChange')<sup>11+</sup>
8268
8269off(type: 'focusStateChange', callback?: AsyncCallback\<FocusState\>): void
8270
8271注销监听相机聚焦的状态变化。
8272
8273**系统能力:** SystemCapability.Multimedia.Camera.Core
8274
8275**参数:**
8276
8277| 参数名     | 类型                                      | 必填 | 说明                       |
8278| -------- | ----------------------------------------- | ---- | ------------------------ |
8279| type     | string                                    | 是   | 监听事件,固定为'focusStateChange',session创建成功可监听。 |
8280| callback | AsyncCallback\<[FocusState](#focusstate)\> | 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
8281
8282**示例:**
8283
8284```ts
8285function unregisterFocusStateChange(photoSession: camera.PhotoSession): void {
8286  photoSession.off('focusStateChange');
8287}
8288```
8289
8290### on('smoothZoomInfoAvailable')<sup>11+</sup>
8291
8292on(type: 'smoothZoomInfoAvailable', callback: AsyncCallback\<SmoothZoomInfo\>): void
8293
8294监听相机平滑变焦的状态变化,通过注册回调函数获取结果。使用callback异步回调。
8295
8296> **说明:**
8297>
8298> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
8299
8300**系统能力:** SystemCapability.Multimedia.Camera.Core
8301
8302**参数:**
8303
8304| 参数名     | 类型                   | 必填 | 说明                       |
8305| -------- | ----------------------- | ---- | ------------------------ |
8306| type     | string                  | 是   | 监听事件,固定为'smoothZoomInfoAvailable',session创建成功可监听。|
8307| callback | AsyncCallback\<[SmoothZoomInfo](#smoothzoominfo11)\> | 是   | 回调函数,用于获取当前平滑变焦状态。  |
8308
8309**示例:**
8310
8311```ts
8312import { BusinessError } from '@kit.BasicServicesKit';
8313
8314function callback(err: BusinessError, smoothZoomInfo: camera.SmoothZoomInfo): void {
8315  if (err !== undefined && err.code !== 0) {
8316    console.error(`Callback Error, errorCode: ${err.code}`);
8317    return;
8318  }
8319  console.info(`The duration of smooth zoom: ${smoothZoomInfo.duration}`);
8320}
8321
8322function registerSmoothZoomInfo(photoSession: camera.PhotoSession): void {
8323  photoSession.on('smoothZoomInfoAvailable', callback);
8324}
8325```
8326
8327### off('smoothZoomInfoAvailable')<sup>11+</sup>
8328
8329off(type: 'smoothZoomInfoAvailable', callback?: AsyncCallback\<SmoothZoomInfo\>): void
8330
8331注销监听相机平滑变焦的状态变化。
8332
8333**系统能力:** SystemCapability.Multimedia.Camera.Core
8334
8335**参数:**
8336
8337| 参数名     | 类型                                      | 必填 | 说明                       |
8338| -------- | ----------------------------------------- | ---- | ------------------------ |
8339| type     | string              | 是   | 监听事件,固定为'smoothZoomInfoAvailable',session创建成功可监听。|
8340| callback | AsyncCallback\<[SmoothZoomInfo](#smoothzoominfo11)\> | 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
8341
8342**示例:**
8343
8344```ts
8345function unregisterSmoothZoomInfo(photoSession: camera.PhotoSession): void {
8346  photoSession.off('smoothZoomInfoAvailable');
8347}
8348```
8349
8350### on('autoDeviceSwitchStatusChange')<sup>13+</sup>
8351
8352on(type: 'autoDeviceSwitchStatusChange', callback: AsyncCallback\<AutoDeviceSwitchStatus\>): void
8353
8354监听相机自动切换镜头状态变化,通过注册回调函数获取结果。使用callback异步回调。
8355
8356> **说明:**
8357>
8358> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
8359
8360**系统能力:** SystemCapability.Multimedia.Camera.Core
8361
8362**参数:**
8363
8364| 参数名     | 类型                                                                   | 必填 | 说明                                                     |
8365| -------- |----------------------------------------------------------------------| ---- |--------------------------------------------------------|
8366| type     | string                                                               | 是   | 监听事件,固定为'autoDeviceSwitchStatusChange',session创建成功可监听。 |
8367| callback | AsyncCallback\<[AutoDeviceSwitchStatus](#autodeviceswitchstatus13)\> | 是   | 回调函数,用于获取当前自动切换镜头的状态。                                  |
8368
8369**示例:**
8370
8371```ts
8372import { BusinessError } from '@kit.BasicServicesKit';
8373
8374function callback(err: BusinessError, autoDeviceSwitchStatus: camera.AutoDeviceSwitchStatus): void {
8375  if (err !== undefined && err.code !== 0) {
8376    console.error(`Callback Error, errorCode: ${err.code}`);
8377    return;
8378  }
8379  console.info(`isDeviceSwitched: ${autoDeviceSwitchStatus.isDeviceSwitched}, isDeviceCapabilityChanged: ${autoDeviceSwitchStatus.isDeviceCapabilityChanged}`);
8380}
8381
8382function registerAutoDeviceSwitchStatus(photoSession: camera.PhotoSession): void {
8383  photoSession.on('autoDeviceSwitchStatusChange', callback);
8384}
8385```
8386
8387### off('autoDeviceSwitchStatusChange')<sup>13+</sup>
8388
8389off(type: 'autoDeviceSwitchStatusChange', callback?: AsyncCallback\<AutoDeviceSwitchStatus\>): void
8390
8391注销监听相机自动切换镜头状态变化。
8392
8393**系统能力:** SystemCapability.Multimedia.Camera.Core
8394
8395**参数:**
8396
8397| 参数名     | 类型                                           | 必填 | 说明                       |
8398| -------- |----------------------------------------------| ---- | ------------------------ |
8399| type     | string                                       | 是   | 监听事件,固定为'autoDeviceSwitchStatusChange',session创建成功可监听。|
8400| callback | AsyncCallback\<[AutoDeviceSwitchStatus](#autodeviceswitchstatus13)\> | 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
8401
8402**示例:**
8403
8404```ts
8405function unregisterSmoothZoomInfo(photoSession: camera.PhotoSession): void {
8406  photoSession.off('autoDeviceSwitchStatusChange');
8407}
8408```
8409
8410## QualityPrioritization<sup>14+</sup>
8411
8412枚举,录像质量优先级。
8413
8414**系统能力:** SystemCapability.Multimedia.Camera.Core
8415
8416| 名称          | 值  | 说明       |
8417| ------------- | --- | ---------- |
8418| HIGH_QUALITY  | 0   | 高录像质量。   |
8419| POWER_BALANCE | 1   | 功耗平衡的录像质量。 |
8420
8421## VideoSession<sup>11+</sup>
8422
8423VideoSession extends [Session](#session11), [Flash](#flash11), [AutoExposure](#autoexposure11), [Focus](#focus11), [Zoom](#zoom11), [Stabilization](#stabilization11), [ColorManagement](#colormanagement12), [AutoDeviceSwitch](#autodeviceswitch13)
8424
8425普通录像模式会话类,提供了对闪光灯、曝光、对焦、变焦、视频防抖、色彩空间的操作。
8426
8427> **说明:**
8428>
8429> 默认的视频录制模式,适用于一般场景。支持720P、1080p等多种分辨率的录制,可选择不同帧率(如30fps、60fps)。
8430
8431### canPreconfig<sup>12+</sup>
8432
8433canPreconfig(preconfigType: PreconfigType, preconfigRatio?: PreconfigRatio): boolean
8434
8435查询当前Session是否支持指定的与配置类型。
8436
8437**系统能力:** SystemCapability.Multimedia.Camera.Core
8438
8439**参数:**
8440
8441| 参数名            | 类型                                  | 必填  | 说明              |
8442|----------------|-------------------------------------|-----|-----------------|
8443| preconfigType  | [PreconfigType](#preconfigtype12)   | 是   | 指定配置预期分辨率。      |
8444| preconfigRatio | [PreconfigRatio](#preconfigratio12) | 否   | 可选画幅比例,默认为16:9。 |
8445
8446**返回值:**
8447
8448| 类型      | 说明                                      |
8449|---------|-----------------------------------------|
8450| boolean | true: 支持指定预配值类型。<br/>false: 不支持指定预配值类型。 |
8451
8452**错误码:**
8453
8454以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
8455
8456| 错误码ID   | 错误信息                        |
8457|---------|-----------------------------|
8458| 7400201 | Camera service fatal error. |
8459
8460**示例:**
8461
8462```ts
8463function testCanPreconfig(videoSession: camera.VideoSession, preconfigType: camera.PreconfigType,
8464  preconfigRatio: camera.PreconfigRatio): void {
8465  try {
8466    let result = videoSession.canPreconfig(preconfigType, preconfigRatio);
8467    console.info(`canPreconfig ${preconfigType} ${preconfigRatio} result is : ${result}`);
8468  } catch (error) {
8469    let err = error as BusinessError;
8470    console.error(`The canPreconfig call failed. error code: ${err.code}`);
8471  }
8472}
8473```
8474
8475### preconfig<sup>12+</sup>
8476
8477preconfig(preconfigType: PreconfigType, preconfigRatio?: PreconfigRatio): void
8478
8479对当前Session进行预配置。
8480
8481**系统能力:** SystemCapability.Multimedia.Camera.Core
8482
8483**参数:**
8484
8485| 参数名            | 类型                                  | 必填  | 说明              |
8486|----------------|-------------------------------------|-----|-----------------|
8487| preconfigType  | [PreconfigType](#preconfigtype12)   | 是   | 指定配置预期分辨率。      |
8488| preconfigRatio | [PreconfigRatio](#preconfigratio12) | 否   | 可选画幅比例,默认为16:9。 |
8489
8490**错误码:**
8491
8492以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
8493
8494| 错误码ID   | 错误信息                        |
8495|---------|-----------------------------|
8496| 7400201 | Camera service fatal error. |
8497
8498**示例:**
8499
8500```ts
8501function testPreconfig(videoSession: camera.VideoSession, preconfigType: camera.PreconfigType,
8502  preconfigRatio: camera.PreconfigRatio): void {
8503  try {
8504    videoSession.preconfig(preconfigType, preconfigRatio);
8505    console.info(`preconfig ${preconfigType} ${preconfigRatio} success`);
8506  } catch (error) {
8507    let err = error as BusinessError;
8508    console.error(`The preconfig call failed. error code: ${err.code}`);
8509  }
8510}
8511```
8512
8513### on('error')<sup>11+</sup>
8514
8515on(type: 'error', callback: ErrorCallback): void
8516
8517监听普通录像会话的错误事件,通过注册回调函数获取结果。使用callback异步回调。
8518
8519> **说明:**
8520>
8521> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
8522
8523**系统能力:** SystemCapability.Multimedia.Camera.Core
8524
8525**参数:**
8526
8527| 参数名     | 类型              | 必填 | 说明                           |
8528| -------- | ------------------ | ---- | ------------------------------ |
8529| type     | string             | 是   | 监听事件,固定为'error',session创建成功之后可监听该接口。session调用相关接口出现错误时会触发该事件,比如调用[beginConfig](#beginconfig11),[commitConfig](#commitconfig11-1),[addInput](#addinput11)等接口发生错误时返回错误信息。 |
8530| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback)      | 是   | 回调函数,用于获取错误信息。返回错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。   |
8531
8532**示例:**
8533
8534```ts
8535import { BusinessError } from '@kit.BasicServicesKit';
8536
8537function callback(err: BusinessError): void {
8538  console.error(`Video session error code: ${err.code}`);
8539}
8540
8541function registerSessionError(videoSession: camera.VideoSession): void {
8542  videoSession.on('error', callback);
8543}
8544```
8545
8546### off('error')<sup>11+</sup>
8547
8548off(type: 'error', callback?: ErrorCallback): void
8549
8550注销监听普通录像会话的错误事件,通过注册回调函数获取结果。
8551
8552**系统能力:** SystemCapability.Multimedia.Camera.Core
8553
8554**参数:**
8555
8556| 参数名     | 类型                          | 必填 | 说明                           |
8557| -------- | --------------------------- | ---- | ------------------------------ |
8558| type     | string                    | 是   | 监听事件,固定为'error',session创建成功之后可监听该接口。 |
8559| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback)| 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
8560
8561**示例:**
8562
8563```ts
8564function unregisterSessionError(videoSession: camera.VideoSession): void {
8565  videoSession.off('error');
8566}
8567```
8568
8569### on('focusStateChange')<sup>11+</sup>
8570
8571on(type: 'focusStateChange', callback: AsyncCallback\<FocusState\>): void
8572
8573监听相机聚焦的状态变化,通过注册回调函数获取结果。使用callback异步回调。
8574
8575> **说明:**
8576>
8577> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
8578
8579**系统能力:** SystemCapability.Multimedia.Camera.Core
8580
8581**参数:**
8582
8583| 参数名     | 类型                    | 必填 | 说明                       |
8584| -------- | ---------------- | ---- | ------------------------ |
8585| type     | string                                    | 是   | 监听事件,固定为'focusStateChange',session创建成功可监听。仅当自动对焦模式时,且相机对焦状态发生改变时可触发该事件。 |
8586| callback | AsyncCallback\<[FocusState](#focusstate)\> | 是   | 回调函数,用于获取当前对焦状态。  |
8587
8588**示例:**
8589
8590```ts
8591import { BusinessError } from '@kit.BasicServicesKit';
8592
8593function callback(err: BusinessError, focusState: camera.FocusState): void {
8594  if (err !== undefined && err.code !== 0) {
8595    console.error(`Callback Error, errorCode: ${err.code}`);
8596    return;
8597  }
8598  console.info(`Focus state: ${focusState}`);
8599}
8600
8601function registerFocusStateChange(videoSession: camera.VideoSession): void {
8602  videoSession.on('focusStateChange', callback);
8603}
8604```
8605
8606### off('focusStateChange')<sup>11+</sup>
8607
8608off(type: 'focusStateChange', callback?: AsyncCallback\<FocusState\>): void
8609
8610注销监听相机聚焦的状态变化。
8611
8612**系统能力:** SystemCapability.Multimedia.Camera.Core
8613
8614**参数:**
8615
8616| 参数名     | 类型                                      | 必填 | 说明                       |
8617| -------- | ----------------------------------------- | ---- | ------------------------ |
8618| type     | string                                    | 是   | 监听事件,固定为'focusStateChange',session创建成功可监听。 |
8619| callback | AsyncCallback\<[FocusState](#focusstate)\> | 否  | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
8620
8621**示例:**
8622
8623```ts
8624function unregisterFocusStateChange(videoSession: camera.VideoSession): void {
8625  videoSession.off('focusStateChange');
8626}
8627```
8628
8629### on('smoothZoomInfoAvailable')<sup>11+</sup>
8630
8631on(type: 'smoothZoomInfoAvailable', callback: AsyncCallback\<SmoothZoomInfo\>): void
8632
8633监听相机平滑变焦的状态变化,通过注册回调函数获取结果。使用callback异步回调。
8634
8635> **说明:**
8636>
8637> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
8638
8639**系统能力:** SystemCapability.Multimedia.Camera.Core
8640
8641**参数:**
8642
8643| 参数名     | 类型                   | 必填 | 说明                       |
8644| -------- | ----------------------- | ---- | ------------------------ |
8645| type     | string                  | 是   | 监听事件,固定为'smoothZoomInfoAvailable',session创建成功可监听。|
8646| callback | AsyncCallback\<[SmoothZoomInfo](#smoothzoominfo11)\> | 是   | 回调函数,用于获取当前平滑变焦状态。  |
8647
8648**示例:**
8649
8650```ts
8651import { BusinessError } from '@kit.BasicServicesKit';
8652
8653function callback(err: BusinessError, smoothZoomInfo: camera.SmoothZoomInfo): void {
8654  if (err !== undefined && err.code !== 0) {
8655    console.error(`Callback Error, errorCode: ${err.code}`);
8656    return;
8657  }
8658  console.info(`The duration of smooth zoom: ${smoothZoomInfo.duration}`);
8659}
8660
8661function registerSmoothZoomInfo(videoSession: camera.VideoSession): void {
8662  videoSession.on('smoothZoomInfoAvailable', callback);
8663}
8664```
8665
8666### off('smoothZoomInfoAvailable')<sup>11+</sup>
8667
8668off(type: 'smoothZoomInfoAvailable', callback?: AsyncCallback\<SmoothZoomInfo\>): void
8669
8670注销监听相机平滑变焦的状态变化。
8671
8672**系统能力:** SystemCapability.Multimedia.Camera.Core
8673
8674**参数:**
8675
8676| 参数名     | 类型                                      | 必填 | 说明                       |
8677| -------- | ----------------------------------------- | ---- | ------------------------ |
8678| type     | string              | 是   | 监听事件,固定为'smoothZoomInfoAvailable',session创建成功可监听。|
8679| callback | AsyncCallback\<[SmoothZoomInfo](#smoothzoominfo11)\> | 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
8680
8681**示例:**
8682
8683```ts
8684function unregisterSmoothZoomInfo(videoSession: camera.VideoSession): void {
8685  videoSession.off('smoothZoomInfoAvailable');
8686}
8687```
8688
8689### on('autoDeviceSwitchStatusChange')<sup>13+</sup>
8690
8691on(type: 'autoDeviceSwitchStatusChange', callback: AsyncCallback\<AutoDeviceSwitchStatus\>): void
8692
8693监听相机自动切换镜头状态变化,通过注册回调函数获取结果。使用callback异步回调。
8694
8695> **说明:**
8696>
8697> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
8698
8699**系统能力:** SystemCapability.Multimedia.Camera.Core
8700
8701**参数:**
8702
8703| 参数名     | 类型                                                                   | 必填 | 说明                       |
8704| -------- |----------------------------------------------------------------------| ---- | ------------------------ |
8705| type     | string                                                               | 是   | 监听事件,固定为'autoDeviceSwitchStatusChange',session创建成功可监听。|
8706| callback | AsyncCallback\<[AutoDeviceSwitchStatus](#autodeviceswitchstatus13)\> | 是   | 回调函数,用于获取当前自动切换镜头的状态。  |
8707
8708**示例:**
8709
8710```ts
8711import { BusinessError } from '@kit.BasicServicesKit';
8712
8713function callback(err: BusinessError, autoDeviceSwitchStatus: camera.AutoDeviceSwitchStatus): void {
8714  if (err !== undefined && err.code !== 0) {
8715    console.error(`Callback Error, errorCode: ${err.code}`);
8716    return;
8717  }
8718  console.info(`isDeviceSwitched: ${autoDeviceSwitchStatus.isDeviceSwitched}, isDeviceCapabilityChanged: ${autoDeviceSwitchStatus.isDeviceCapabilityChanged}`);
8719}
8720
8721function registerAutoDeviceSwitchStatus(videoSession: camera.VideoSession): void {
8722  videoSession.on('autoDeviceSwitchStatusChange', callback);
8723}
8724```
8725
8726### off('autoDeviceSwitchStatusChange')<sup>13+</sup>
8727
8728off(type: 'autoDeviceSwitchStatusChange', callback?: AsyncCallback\<AutoDeviceSwitchStatus\>): void
8729
8730注销监听相机自动切换镜头状态变化。
8731
8732**系统能力:** SystemCapability.Multimedia.Camera.Core
8733
8734**参数:**
8735
8736| 参数名     | 类型                                           | 必填 | 说明                       |
8737| -------- |----------------------------------------------| ---- | ------------------------ |
8738| type     | string                                       | 是   | 监听事件,固定为'autoDeviceSwitchStatusChange',session创建成功可监听。|
8739| callback | AsyncCallback\<[AutoDeviceSwitchStatus](#autodeviceswitchstatus13)\> | 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
8740
8741**示例:**
8742
8743```ts
8744function unregisterSmoothZoomInfo(videoSession: camera.VideoSession): void {
8745  videoSession.off('autoDeviceSwitchStatusChange');
8746}
8747```
8748
8749### setQualityPrioritization<sup>14+</sup>
8750
8751setQualityPrioritization(quality : QualityPrioritization) : void;
8752
8753设置录像质量优先级。
8754
8755> **说明:**
8756> 默认为高质量,设置为功耗平衡将降低录像质量以减少功耗。实际功耗收益因平台而异。
8757
8758**系统能力:** SystemCapability.Multimedia.Camera.Core
8759
8760**参数:**
8761
8762| 参数名  | 类型                                              | 必填 | 说明                                       |
8763| ------- | ------------------------------------------------- | ---- | ------------------------------------------ |
8764| quality | [QualityPrioritization](#qualityprioritization14) | 是   | 需要设置的视频质量优先级(默认为高质量)。 |
8765
8766**错误码:**
8767
8768以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
8769
8770| 错误码ID | 错误信息                                                                                                                                        |
8771| -------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
8772| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
8773| 7400103  | Session not config. The session has not been committed or configured.                                                                           |
8774
8775**示例:**
8776
8777```ts
8778import { BusinessError } from '@kit.BasicServicesKit';
8779
8780function setQualityPrioritization(videoSession: camera.VideoSession): void {
8781  try {
8782    videoSession.setQualityPrioritization(camera.QualityPrioritization.POWER_BALANCE);
8783  } catch (error) {
8784    // 失败返回错误码error.code并处理。
8785    let err = error as BusinessError;
8786    console.error(`The setQualityPrioritization call failed. error code: ${err.code}`);
8787  }
8788}
8789```
8790
8791## SecureSession<sup>12+</sup>
8792
8793SecureSession extends [Session](#session11), [Flash](#flash11), [AutoExposure](#autoexposure11), [Focus](#focus11), [Zoom](#zoom11)
8794
8795安全模式会话类,提供了对闪光灯、曝光、对焦、变焦的操作。
8796
8797> **说明:**
8798>
8799> 通过[createSession](#createsession11)接口传入[SceneMode](#scenemode11)为SECURE_PHOTO模式创建一个安全模式的会话。该模式开放给人脸识别、银行等有安全诉求的应用,需要结合<!--RP1-->安全TA<!--RP1End-->使用,支持同时出普通预览流和安全流的业务场景。<!--RP2-->
8800> <br>安全TA:可用于图片处理,它具备验证服务器下发数据的验签能力、图片签名、解析及组装tlv逻辑的能力,还具备密钥读取、创建及操作能力。<!--RP2End-->
8801
8802### addSecureOutput<sup>12+</sup>
8803
8804addSecureOutput(previewOutput: PreviewOutput): void
8805
8806把其中一条[PreviewOutput](#previewoutput)标记成安全输出。
8807
8808**系统能力:** SystemCapability.Multimedia.Camera.Core
8809
8810**参数:**
8811
8812| 参数名           | 类型                             | 必填 | 说明            |
8813| ------------- | ------------------------------- | ---- |---------------|
8814| previewOutput  | [PreviewOutput](#previewoutput)   | 是   | 需要标记成安全输出的预览流,传参异常时,会返回错误码。 |
8815
8816**错误码:**
8817
8818以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
8819
8820| 错误码ID         | 错误信息        |
8821| --------------- | --------------- |
8822| 7400101                |  Parameter missing or parameter type incorrect.        |
8823| 7400102                |  Operation not allowed.                                  |
8824| 7400103                |  Session not config.                                   |
8825
8826**示例:**
8827
8828```ts
8829import { BusinessError } from '@kit.BasicServicesKit';
8830
8831function addSecureOutput(session: camera.SecureSession, previewOutput: camera.PreviewOutput): void {
8832  try {
8833    session.addSecureOutput(previewOutput);
8834  } catch (error) {
8835    // 失败返回错误码error.code并处理。
8836    let err = error as BusinessError;
8837    console.error(`The addOutput call failed. error code: ${err.code}`);
8838  }
8839}
8840```
8841### on('error')<sup>12+</sup>
8842
8843on(type: 'error', callback: ErrorCallback): void
8844
8845监听安全相机会话的错误事件,通过注册回调函数获取结果。使用callback异步回调。
8846
8847> **说明:**
8848>
8849> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
8850
8851**系统能力:** SystemCapability.Multimedia.Camera.Core
8852
8853**参数:**
8854
8855| 参数名     | 类型              | 必填 | 说明                           |
8856| -------- | ------------------ | ---- | ------------------------------ |
8857| type     | string             | 是   | 监听事件,固定为'error',session创建成功之后可监听该接口。session调用相关接口出现错误时会触发该事件,比如调用[beginConfig](#beginconfig11),[commitConfig](#commitconfig11-1),[addInput](#addinput11)等接口发生错误时返回错误信息。 |
8858| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback)      | 是   | 回调函数,用于获取错误信息。返回错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。   |
8859
8860**示例:**
8861
8862```ts
8863import { BusinessError } from '@kit.BasicServicesKit';
8864
8865function callback(err: BusinessError): void {
8866  console.error(`Video session error code: ${err.code}`);
8867}
8868
8869function registerSessionError(secureSession: camera.SecureSession): void {
8870  secureSession.on('error', callback);
8871}
8872```
8873
8874### off('error')<sup>12+</sup>
8875
8876off(type: 'error', callback?: ErrorCallback): void
8877
8878注销监听安全相机会话的错误事件,通过注册回调函数获取结果。
8879
8880**系统能力:** SystemCapability.Multimedia.Camera.Core
8881
8882**参数:**
8883
8884| 参数名     | 类型                          | 必填 | 说明                           |
8885| -------- | --------------------------- | ---- | ------------------------------ |
8886| type     | string                    | 是   | 监听事件,固定为'error',session创建成功之后可监听该接口。 |
8887| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback)| 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
8888
8889**示例:**
8890
8891```ts
8892function unregisterSessionError(secureSession: camera.SecureSession): void {
8893  secureSession.off('error');
8894}
8895```
8896
8897### on('focusStateChange')<sup>12+</sup>
8898
8899on(type: 'focusStateChange', callback: AsyncCallback\<FocusState\>): void
8900
8901监听相机聚焦的状态变化,通过注册回调函数获取结果。使用callback异步回调。
8902
8903> **说明:**
8904>
8905> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
8906
8907**系统能力:** SystemCapability.Multimedia.Camera.Core
8908
8909**参数:**
8910
8911| 参数名     | 类型                    | 必填 | 说明                       |
8912| -------- | ---------------- | ---- | ------------------------ |
8913| type     | string                                    | 是   | 监听事件,固定为'focusStateChange',session创建成功可监听。仅当自动对焦模式时,且相机对焦状态发生改变时可触发该事件。 |
8914| callback | AsyncCallback\<[FocusState](#focusstate)\> | 是   | 回调函数,用于获取当前对焦状态。  |
8915
8916**示例:**
8917
8918```ts
8919import { BusinessError } from '@kit.BasicServicesKit';
8920
8921function callback(err: BusinessError, focusState: camera.FocusState): void {
8922  if (err !== undefined && err.code !== 0) {
8923    console.error(`Callback Error, errorCode: ${err.code}`);
8924    return;
8925  }
8926  console.info(`Focus state: ${focusState}`);
8927}
8928
8929function registerFocusStateChange(secureSession: camera.SecureSession): void {
8930  secureSession.on('focusStateChange', callback);
8931}
8932```
8933
8934### off('focusStateChange')<sup>12+</sup>
8935
8936off(type: 'focusStateChange', callback?: AsyncCallback\<FocusState\>): void
8937
8938注销监听相机聚焦的状态变化。
8939
8940**系统能力:** SystemCapability.Multimedia.Camera.Core
8941
8942**参数:**
8943
8944| 参数名     | 类型                                      | 必填 | 说明                       |
8945| -------- | ----------------------------------------- | ---- | ------------------------ |
8946| type     | string                                    | 是   | 监听事件,固定为'focusStateChange',session创建成功可监听。 |
8947| callback | AsyncCallback\<[FocusState](#focusstate)\> | 否  | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
8948
8949**示例:**
8950
8951```ts
8952function unregisterFocusStateChange(secureSession: camera.SecureSession): void {
8953  secureSession.off('focusStateChange');
8954}
8955```