1# @ohos.multimedia.camera (相机管理)
2
3本模块为开发者提供一套简单且易于理解的相机服务接口,开发者通过调用接口可以开发相机应用。应用通过访问和操作相机硬件,实现基础操作,如预览、拍照和录像;还可以通过接口组合完成更多操作,如控制闪光灯和曝光时间、对焦或调焦等。
4
5> **说明:**
6>
7> 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8
9## 导入模块
10
11```ts
12import { camera } from '@kit.CameraKit';
13```
14
15## camera.getCameraManager
16
17getCameraManager(context: Context): CameraManager
18
19获取相机管理器实例,同步返回结果。
20
21**系统能力:** SystemCapability.Multimedia.Camera.Core
22
23**参数:**
24
25| 参数名     | 类型                                             | 必填 | 说明                           |
26| -------- | ----------------------------------------------- | ---- | ---------------------------- |
27| context  | [Context](../apis-ability-kit/js-apis-inner-application-baseContext.md)      | 是   | 应用上下文。                   |
28
29**返回值:**
30
31| 类型                                             | 说明                           |
32| ----------------------------------------------- | ---------------------------- |
33| [CameraManager](#cameramanager)           | 相机管理器。                   |
34
35**错误码:**
36
37以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
38
39| 错误码ID         | 错误信息        |
40| --------------- | --------------- |
41| 7400101                |  Parameter missing or parameter type incorrect.               |
42| 7400201                |  Camera service fatal error.                                  |
43
44**示例:**
45
46```ts
47import { common } from '@kit.AbilityKit';
48import { BusinessError } from '@kit.BasicServicesKit';
49
50function getCameraManager(context: common.BaseContext): camera.CameraManager | undefined {
51  let cameraManager: camera.CameraManager | undefined = undefined;
52  try {
53    cameraManager = camera.getCameraManager(context);
54  } catch (error) {
55    let err = error as BusinessError;
56    console.error(`The getCameraManager call failed. error code: ${err.code}`);
57  }
58  return cameraManager;
59}
60```
61
62## CameraDevice
63
64相机设备信息。
65
66**系统能力:** SystemCapability.Multimedia.Camera.Core
67
68| 名称           | 类型                               | 只读 | 可选 | 说明        |
69| -------------- | --------------------------------- | ---- | ---- |---------- |
70| cameraId       | string                            | 是   | 否   | 相机id。|
71| cameraPosition | [CameraPosition](#cameraposition) | 是   | 否   | 相机位置。    |
72| cameraType     | [CameraType](#cameratype)         | 是   | 否   | 相机类型。    |
73| connectionType | [ConnectionType](#connectiontype) | 是   | 否   | 相机连接类型。 |
74| cameraOrientation<sup>12+</sup> | number | 是   | 否   | 镜头的安装角度,不会随着屏幕旋转而改变,取值范围为0°-360°。 |
75
76## CameraPosition
77
78枚举,相机位置。
79
80**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
81
82**系统能力:** SystemCapability.Multimedia.Camera.Core
83
84| 名称                         | 值   | 说明                                                              |
85| --------------------------- | ---- |-----------------------------------------------------------------|
86| CAMERA_POSITION_UNSPECIFIED | 0    | 相对于设备屏幕没有固定的朝向的相机。                                                        |
87| CAMERA_POSITION_BACK        | 1    | 后置相机。                                                           |
88| CAMERA_POSITION_FRONT       | 2    | 前置相机。                                                           |
89| CAMERA_POSITION_FOLD_INNER<sup>(deprecated)</sup>  | 3    | 折叠态相机。<br/> 从API version 11开始支持,从API version 12开始废弃。 |
90
91## CameraType
92
93枚举,相机类型。
94
95**系统能力:** SystemCapability.Multimedia.Camera.Core
96
97| 名称                     | 值   | 说明            |
98| ----------------------- | ---- | -------------- |
99| CAMERA_TYPE_DEFAULT     | 0    | 相机类型未指定。  |
100| CAMERA_TYPE_WIDE_ANGLE  | 1    | 广角相机。       |
101| CAMERA_TYPE_ULTRA_WIDE  | 2    | 超广角相机。     |
102| CAMERA_TYPE_TELEPHOTO   | 3    | 长焦相机。       |
103| CAMERA_TYPE_TRUE_DEPTH  | 4    | 带景深信息的相机。 |
104
105## ConnectionType
106
107枚举,相机连接类型。
108
109**系统能力:** SystemCapability.Multimedia.Camera.Core
110
111| 名称                          | 值   | 说明           |
112| ---------------------------- | ---- | ------------- |
113| CAMERA_CONNECTION_BUILT_IN   | 0    | 内置相机。      |
114| CAMERA_CONNECTION_USB_PLUGIN | 1    | USB连接的相机。 |
115| CAMERA_CONNECTION_REMOTE     | 2    | 远程连接的相机。 |
116
117## CameraStatus
118
119枚举,相机状态。
120
121**系统能力:** SystemCapability.Multimedia.Camera.Core
122
123| 名称                       | 值   | 说明            |
124| ------------------------- | ---- | ------------    |
125| CAMERA_STATUS_APPEAR      | 0    | 新的相机出现。   |
126| CAMERA_STATUS_DISAPPEAR   | 1    | 相机被移除。     |
127| CAMERA_STATUS_AVAILABLE   | 2    | 相机可用。       |
128| CAMERA_STATUS_UNAVAILABLE | 3    | 相机不可用。     |
129
130## FoldStatus<sup>12+</sup>
131
132枚举,折叠机折叠状态。
133
134**系统能力:** SystemCapability.Multimedia.Camera.Core
135
136| 名称                       | 值   | 说明            |
137| ------------------------- | ---- | ------------    |
138| NON_FOLDABLE      | 0    | 表示当前设备不可折叠。   |
139| EXPANDED   | 1    | 表示当前设备折叠状态为完全展开。 |
140| FOLDED   | 2    | 表示当前设备折叠状态为折叠。       |
141
142## CameraStatusInfo
143
144相机管理器回调返回的接口实例,表示相机状态信息。
145
146**系统能力:** SystemCapability.Multimedia.Camera.Core
147
148| 名称   | 类型                           |    只读   |     可选     | 说明       |
149| ------ | ----------------------------- | --------- |------------ | ---------- |
150| camera | [CameraDevice](#cameradevice) |     否    |       否     | 相机信息。 |
151| status | [CameraStatus](#camerastatus) |     否    |       否     | 相机状态。 |
152
153## FoldStatusInfo<sup>12+</sup>
154
155相机管理器回调返回的接口实例,表示折叠机折叠状态信息。
156
157**系统能力:** SystemCapability.Multimedia.Camera.Core
158
159| 名称   | 类型                           |    只读   |     可选     | 说明       |
160| ------ | ----------------------------- | --------- |------------ | ---------- |
161| supportedCameras | [Array<CameraDevice\>](#cameradevice) |     否    |       否     | 当前折叠状态所支持的相机信息列表。 |
162| foldStatus | [FoldStatus](#foldstatus12) |     否    |       否     | 折叠屏折叠状态。 |
163
164## Profile
165
166相机配置信息项。
167
168**系统能力:** SystemCapability.Multimedia.Camera.Core
169
170| 名称      | 类型                          | 只读 | 可选 | 说明         |
171| -------- | ----------------------------- |---- | ---- | ------------- |
172| format   | [CameraFormat](#cameraformat) | 是  |  否  | 输出格式。      |
173| size     | [Size](#size)                 | 是  |  否  | 分辨率。<br>设置的是相机分辨率宽高,非实际出图宽高。  |
174
175## FrameRateRange
176
177帧率范围。
178
179**系统能力:** SystemCapability.Multimedia.Camera.Core
180
181| 名称      | 类型                          | 只读 | 可选 | 说明            |
182| -------- | ----------------------------- |----- |---| -------------- |
183| min      | number                        |  是  | 否 | 最小帧率。      |
184| max      | number                        |  是  | 否 | 最大帧率。      |
185
186## VideoProfile
187
188视频配置信息项,继承[Profile](#profile)。
189
190**系统能力:** SystemCapability.Multimedia.Camera.Core
191
192| 名称                       | 类型                                      | 只读 | 可选 | 说明        |
193| ------------------------- | ----------------------------------------- | --- | ---- |----------- |
194| frameRateRange            | [FrameRateRange](#frameraterange)         | 是  |  否  | 帧率范围,fps(frames per second)。 |
195
196## CameraOutputCapability
197
198相机输出能力项。
199
200**系统能力:** SystemCapability.Multimedia.Camera.Core
201
202| 名称                           | 类型                                                | 只读 | 可选 | 说明                |
203| ----------------------------- | --------------------------------------------------- | ---- | ---- |-------------------|
204| previewProfiles               | Array\<[Profile](#profile)\>                        |  是  | 否 | 支持的预览配置信息集合。      |
205| photoProfiles                 | Array\<[Profile](#profile)\>                        |  是  | 否 | 支持的拍照配置信息集合。        |
206| videoProfiles                 | Array\<[VideoProfile](#videoprofile)\>              |  是  | 否 | 支持的录像配置信息集合。        |
207| supportedMetadataObjectTypes  | Array\<[MetadataObjectType](#metadataobjecttype)\>  |  是  | 否 | 支持的metadata流类型信息集合。 |
208
209## SceneMode<sup>11+</sup>
210
211枚举,相机支持模式。
212
213**系统能力:** SystemCapability.Multimedia.Camera.Core
214
215| 名称                         | 值       | 说明                                          |
216|----------------------------|---------|---------------------------------------------|
217| NORMAL_PHOTO               | 1       | 普通拍照模式。详情见[PhotoSession](#photosession11)   |
218| NORMAL_VIDEO               | 2       | 普通录像模式。详情见[VideoSession](#videosession11)   |
219| SECURE_PHOTO<sup>12+</sup> | 12      | 安全相机模式。详情见[SecureSession](#securesession12) |
220
221## CameraErrorCode
222
223相机错误码。
224
225接口使用不正确以及on接口监听error状态返回。
226
227**系统能力:** SystemCapability.Multimedia.Camera.Core
228
229| 名称                       | 值          | 说明            |
230| -------------------------  | ----       | ------------    |
231| INVALID_ARGUMENT           | 7400101    | 参数缺失或者参数类型不对。   |
232| OPERATION_NOT_ALLOWED      | 7400102    | 操作流程不对,不允许。     |
233| SESSION_NOT_CONFIG         | 7400103    | session 未配置返回。       |
234| SESSION_NOT_RUNNING        | 7400104    | session 未运行返回。    |
235| SESSION_CONFIG_LOCKED      | 7400105    | session 配置已锁定返回。     |
236| DEVICE_SETTING_LOCKED      | 7400106    | 设备设置已锁定返回。     |
237| CONFLICT_CAMERA            | 7400107    | 设备重复打开返回。     |
238| DEVICE_DISABLED            | 7400108    | 安全原因摄像头被禁用。     |
239| DEVICE_PREEMPTED           | 7400109    | 相机被抢占导致无法使用。     |
240| UNRESOLVED_CONFLICTS_WITH_CURRENT_CONFIGURATIONS<sup>12+</sup> | 7400110   | 与当前配置存在冲突。     |
241| SERVICE_FATAL_ERROR        | 7400201    | 相机服务错误返回。     |
242
243## CameraManager
244
245相机管理器类,使用前需要通过[getCameraManager](#cameragetcameramanager)获取相机管理实例。
246
247### getSupportedCameras
248
249getSupportedCameras(): Array\<CameraDevice\>
250
251获取支持指定的相机设备对象,同步返回结果。
252
253**系统能力:** SystemCapability.Multimedia.Camera.Core
254
255**返回值:**
256
257| 类型                                             | 说明                           |
258| ----------------------------------------------- | ---------------------------- |
259|  Array\<[CameraDevice](#cameradevice)>            | 相机设备列表。                   |
260
261**示例:**
262
263```ts
264import { BusinessError } from '@kit.BasicServicesKit';
265
266function getSupportedCameras(cameraManager: camera.CameraManager): Array<camera.CameraDevice> {
267  let cameras: Array<camera.CameraDevice> = [];
268  try {
269    cameras = cameraManager.getSupportedCameras();
270  } catch (error) {
271    let err = error as BusinessError;
272    console.error(`The getSupportedCameras call failed. error code: ${err.code}`);
273  }
274  return cameras;
275}
276```
277
278### getSupportedSceneModes<sup>11+</sup>
279
280getSupportedSceneModes(camera: CameraDevice): Array\<SceneMode\>
281
282获取指定的相机设备对象支持的模式,同步返回结果。
283
284**系统能力:** SystemCapability.Multimedia.Camera.Core
285
286**参数:**
287
288| 参数名         | 类型                                                            | 必填 | 说明                      |
289| ------------ |--------------------------------------------------------------- | -- | -------------------------- |
290| camera | [CameraDevice](#cameradevice)                              | 是 | 相机设备,通过 [getSupportedCameras](#getsupportedcameras) 接口获取。传参异常时,会返回错误码。       |
291
292**返回值:**
293
294| 类型                                             | 说明                           |
295| ----------------------------------------------- | ---------------------------- |
296|  Array\<[SceneMode](#scenemode11)>            | 相机支持的模式列表。                   |
297
298**示例:**
299
300```ts
301import { BusinessError } from '@kit.BasicServicesKit';
302
303function getSupportedSceneModes(cameraManager: camera.CameraManager, camera: camera.CameraDevice): Array<camera.SceneMode> {
304  let modes: Array<camera.SceneMode> = [];
305  try {
306    modes = cameraManager.getSupportedSceneModes(camera);
307  } catch (error) {
308    let err = error as BusinessError;
309    console.error(`The getSupportedSceneModes call failed. error code: ${err.code}`);
310  }
311  return modes;
312}
313```
314
315### getSupportedOutputCapability<sup>(deprecated)</sup>
316
317getSupportedOutputCapability(camera: CameraDevice): CameraOutputCapability
318
319查询相机设备支持的输出能力,同步返回结果。
320
321> **说明:**
322> 从 API version 10开始支持,从API version 11开始废弃。建议使用[getSupportedOutputCapability](#getsupportedoutputcapability11)替代。
323
324**系统能力:** SystemCapability.Multimedia.Camera.Core
325
326**参数:**
327
328| 参数名         | 类型                                                            | 必填 | 说明                      |
329| ------------ |--------------------------------------------------------------- | -- | -------------------------- |
330| camera | [CameraDevice](#cameradevice)                              | 是 | 相机设备,通过 [getSupportedCameras](#getsupportedcameras) 接口获取。传参异常时,会返回错误码。      |
331
332**返回值:**
333
334| 类型                                             | 说明                           |
335| ----------------------------------------------- | ---------------------------- |
336| [CameraOutputCapability](#cameraoutputcapability)            | 相机输出能力。                   |
337
338**示例:**
339
340```ts
341function getSupportedOutputCapability(camera: camera.CameraDevice, cameraManager: camera.CameraManager): camera.CameraOutputCapability {
342  let cameraOutputCapability: camera.CameraOutputCapability = cameraManager.getSupportedOutputCapability(camera);
343  return cameraOutputCapability;
344}
345```
346
347### getSupportedOutputCapability<sup>11+</sup>
348
349getSupportedOutputCapability(camera: CameraDevice, mode: SceneMode): CameraOutputCapability
350
351查询相机设备在模式下支持的输出能力,同步返回结果。
352
353**系统能力:** SystemCapability.Multimedia.Camera.Core
354
355**参数:**
356
357| 参数名         | 类型                                                            | 必填 | 说明                      |
358| ------------ |--------------------------------------------------------------- | -- | -------------------------- |
359| camera | [CameraDevice](#cameradevice)                              | 是 | 相机设备,通过 [getSupportedCameras](#getsupportedcameras) 接口获取。       |
360| mode | [SceneMode](#scenemode11)                              | 是 | 相机模式,通过 [getSupportedSceneModes](#getsupportedscenemodes11) 接口获取。       |
361
362**返回值:**
363
364| 类型                                             | 说明                           |
365| ----------------------------------------------- | ---------------------------- |
366| [CameraOutputCapability](#cameraoutputcapability)            | 相机输出能力。                   |
367
368**示例:**
369
370```ts
371function getSupportedOutputCapability(camera: camera.CameraDevice, cameraManager: camera.CameraManager, sceneMode: camera.SceneMode): camera.CameraOutputCapability {
372  let cameraOutputCapability: camera.CameraOutputCapability = cameraManager.getSupportedOutputCapability(camera, sceneMode);
373  return cameraOutputCapability;
374}
375```
376
377### isCameraMuted
378
379isCameraMuted(): boolean
380
381查询相机当前的禁用状态(禁用/未禁用)。
382
383**系统能力:** SystemCapability.Multimedia.Camera.Core
384
385**返回值:**
386
387| 类型        | 说明                                         |
388| ---------- | -------------------------------------------- |
389| boolean    | 返回true表示相机被禁用,返回false表示相机未被禁用。 |
390
391**示例:**
392
393```ts
394function isCameraMuted(cameraManager: camera.CameraManager): boolean {
395  let isMuted: boolean = cameraManager.isCameraMuted();
396  return isMuted;
397}
398```
399
400### createCameraInput
401
402createCameraInput(camera: CameraDevice): CameraInput
403
404使用CameraDevice对象创建CameraInput实例,同步返回结果。
405
406**需要权限:** ohos.permission.CAMERA
407
408**系统能力:** SystemCapability.Multimedia.Camera.Core
409
410**参数:**
411
412| 参数名     | 类型                                         | 必填 | 说明                                               |
413| -------- | ------------------------------------------- | ---- |--------------------------------------------------|
414| camera  | [CameraDevice](#cameradevice)         | 是   | CameraDevice对象,通过 [getSupportedCameras](#getsupportedcameras) 接口获取。 |
415
416**返回值:**
417
418| 类型        | 说明                          |
419| ---------- | ----------------------------- |
420| [CameraInput](#camerainput)    | CameraInput实例。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
421
422**错误码:**
423
424以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
425
426| 错误码ID         | 错误信息        |
427| --------------- | --------------- |
428| 7400101                |  Parameter missing or parameter type incorrect.               |
429| 7400102                |  Operation not allowed.               |
430| 7400201                |  Camera service fatal error.               |
431
432**示例:**
433
434```ts
435import { BusinessError } from '@kit.BasicServicesKit';
436
437function createCameraInput(camera: camera.CameraDevice, cameraManager: camera.CameraManager): camera.CameraInput | undefined {
438  let cameraInput: camera.CameraInput | undefined = undefined;
439  try {
440    cameraInput = cameraManager.createCameraInput(camera);
441  } catch (error) {
442    // 失败返回错误码error.code并处理
443    let err = error as BusinessError;
444    console.error(`The createCameraInput call failed. error code: ${err.code}`);
445  }
446  return cameraInput;
447}
448```
449
450### createCameraInput
451
452createCameraInput(position: CameraPosition, type: CameraType): CameraInput
453
454根据相机位置和类型创建CameraInput实例,同步返回结果。
455
456**需要权限:** ohos.permission.CAMERA
457
458**系统能力:** SystemCapability.Multimedia.Camera.Core
459
460**参数:**
461
462| 参数名     | 类型                                        | 必填 | 说明                                |
463| -------- | ------------------------------------------- | ---- | --------------------------------- |
464| position | [CameraPosition](#cameraposition)           | 是   | 相机位置,通过 [getSupportedCameras](#getsupportedcameras) 接口获取设备,然后获取设备位置信息。  |
465| type     | [CameraType](#cameratype)                   | 是   | 相机类型,通过 [getSupportedCameras](#getsupportedcameras) 接口获取设备,然后获取设备类型信息。 |
466
467**返回值:**
468
469| 类型        | 说明                          |
470| ---------- | ----------------------------- |
471| [CameraInput](#camerainput)    | CameraInput实例。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
472
473**错误码:**
474
475以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
476
477| 错误码ID         | 错误信息        |
478| --------------- | --------------- |
479| 7400101                |  Parameter missing or parameter type incorrect.               |
480| 7400102                |  Operation not allowed.               |
481| 7400201                |  Camera service fatal error.               |
482
483**示例:**
484
485```ts
486import { BusinessError } from '@kit.BasicServicesKit';
487
488function createCameraInput(camera: camera.CameraDevice, cameraManager: camera.CameraManager): camera.CameraInput | undefined {
489  let position: camera.CameraPosition = camera.cameraPosition;
490  let type: camera.CameraType = camera.cameraType;
491  let cameraInput: camera.CameraInput | undefined = undefined;
492  try {
493    cameraInput = cameraManager.createCameraInput(position, type);
494  } catch (error) {
495    // 失败返回错误码error.code并处理
496    let err = error as BusinessError;
497    console.error(`The createCameraInput call failed. error code: ${err.code}`);
498  }
499  return cameraInput;
500}
501```
502
503### createPreviewOutput
504
505createPreviewOutput(profile: Profile, surfaceId: string): PreviewOutput
506
507创建预览输出对象,同步返回结果。
508
509**系统能力:** SystemCapability.Multimedia.Camera.Core
510
511**参数:**
512
513| 参数名     | 类型                                             | 必填 | 说明                              |
514| -------- | ----------------------------------------------- | ---- | ------------------------------- |
515| profile  | [Profile](#profile)                             | 是   | 支持的预览配置信息,通过[getSupportedOutputCapability](#getsupportedoutputcapability11)接口获取。|
516| surfaceId| string | 是   | 从[XComponent](../apis-arkui/arkui-ts/ts-basic-components-xcomponent.md)或者[ImageReceiver](../apis-image-kit/js-apis-image.md#imagereceiver9)组件获取的surfaceId。|
517
518**返回值:**
519
520| 类型        | 说明                          |
521| ---------- | ----------------------------- |
522| [PreviewOutput](#previewoutput)    | PreviewOutput实例。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
523
524**错误码:**
525
526以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
527
528| 错误码ID         | 错误信息        |
529| --------------- | --------------- |
530| 7400101                |  Parameter missing or parameter type incorrect.               |
531| 7400201                |  Camera service fatal error.               |
532
533**示例:**
534
535```ts
536import { BusinessError } from '@kit.BasicServicesKit';
537
538function createPreviewOutput(cameraOutputCapability: camera.CameraOutputCapability, cameraManager: camera.CameraManager, surfaceId: string): camera.PreviewOutput | undefined {
539  let profile: camera.Profile = cameraOutputCapability.previewProfiles[0];
540  let previewOutput: camera.PreviewOutput | undefined = undefined;
541  try {
542    previewOutput = cameraManager.createPreviewOutput(profile, surfaceId);
543  } catch (error) {
544    // 失败返回错误码error.code并处理
545    let err = error as BusinessError;
546    console.error(`The createPreviewOutput call failed. error code: ${err.code}`);
547  }
548  return previewOutput;
549}
550```
551
552### createPreviewOutput<sup>12+</sup>
553
554createPreviewOutput(surfaceId: string): PreviewOutput
555
556创建无配置信息的预览输出对象,同步返回结果。该接口需配合[preconfig](#preconfig12)一起使用。
557
558**系统能力:** SystemCapability.Multimedia.Camera.Core
559
560**参数:**
561
562| 参数名     | 类型                                             | 必填 | 说明                              |
563| -------- | ----------------------------------------------- | ---- | ------------------------------- |
564| surfaceId| string | 是   | 从[XComponent](../apis-arkui/arkui-ts/ts-basic-components-xcomponent.md)或者[ImageReceiver](../apis-image-kit/js-apis-image.md#imagereceiver9)组件获取的surfaceId。|
565
566**返回值:**
567
568| 类型        | 说明                          |
569| ---------- | ----------------------------- |
570| [PreviewOutput](#previewoutput)    | PreviewOutput实例。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
571
572**错误码:**
573
574以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
575
576| 错误码ID   | 错误信息                                           |
577|---------|------------------------------------------------|
578| 7400101 | Parameter missing or parameter type incorrect. |
579| 7400201 | Camera service fatal error.                    |
580
581**示例:**
582
583```ts
584import { BusinessError } from '@kit.BasicServicesKit';
585
586function createPreviewOutput(cameraManager: camera.CameraManager, surfaceId: string): camera.PreviewOutput | undefined {
587  let previewOutput: camera.PreviewOutput | undefined = undefined;
588  try {
589    previewOutput = cameraManager.createPreviewOutput(surfaceId);
590  } catch (error) {
591    // 失败返回错误码error.code并处理
592    let err = error as BusinessError;
593    console.error(`The createPreviewOutput call failed. error code: ${err.code}`);
594  }
595  return previewOutput;
596}
597```
598
599### createPhotoOutput<sup>(deprecated)</sup>
600
601createPhotoOutput(profile: Profile, surfaceId: string): PhotoOutput
602
603创建拍照输出对象,同步返回结果。
604
605> **说明:**
606> 从 API version 10开始支持,从API version 11开始废弃。建议使用[createPhotoOutput](#createphotooutput11)替代。
607
608**系统能力:** SystemCapability.Multimedia.Camera.Core
609
610**参数:**
611
612| 参数名     | 类型                                         | 必填 | 说明                                  |
613| -------- | ------------------------------------------- | ---- | ----------------------------------- |
614| profile  | [Profile](#profile)                         | 是   | 支持的拍照配置信息,通过[getSupportedOutputCapability](#getsupportedoutputcapability11)接口获取。|
615| surfaceId| string            | 是   | 从[ImageReceiver](../apis-image-kit/js-apis-image.md#imagereceiver9)获取的surfaceId。|
616
617**返回值:**
618
619| 类型        | 说明                          |
620| ---------- | ----------------------------- |
621| [PhotoOutput](#photooutput)   | PhotoOutput实例。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
622
623**错误码:**
624
625以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
626
627| 错误码ID         | 错误信息        |
628| --------------- | --------------- |
629| 7400101                |  Parameter missing or parameter type incorrect.               |
630
631```ts
632import { BusinessError } from '@kit.BasicServicesKit';
633
634function createPhotoOutput(cameraOutputCapability: camera.CameraOutputCapability, cameraManager: camera.CameraManager, surfaceId: string): camera.PhotoOutput | undefined {
635  let profile: camera.Profile = cameraOutputCapability.photoProfiles[0];
636  let photoOutput: camera.PhotoOutput | undefined = undefined;
637  try {
638    photoOutput = cameraManager.createPhotoOutput(profile, surfaceId);
639  } catch (error) {
640    // 失败返回错误码error.code并处理
641    let err = error as BusinessError;
642    console.error(`The createPhotoOutput call failed. error code: ${err.code}`);
643  }
644  return photoOutput;
645}
646```
647
648### createPhotoOutput<sup>11+</sup>
649
650createPhotoOutput(profile?: Profile): PhotoOutput
651
652创建拍照输出对象,同步返回结果。
653
654**系统能力:** SystemCapability.Multimedia.Camera.Core
655
656**参数:**
657
658| 参数名     | 类型                                         | 必填 | 说明                                  |
659| -------- | ------------------------------------------- |----| ----------------------------------- |
660| profile  | [Profile](#profile)                         | 否  | 支持的拍照配置信息,通过[getSupportedOutputCapability](#getsupportedoutputcapability11)接口获取。<br>API 11时,该参数必填;从API version 12开始,如果使用[preconfig](#preconfig12)进行预配置,传入profile参数会覆盖preconfig的预配置参数。|
661
662**返回值:**
663
664| 类型        | 说明                          |
665| ---------- | ----------------------------- |
666| [PhotoOutput](#photooutput)   | PhotoOutput实例。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
667
668**错误码:**
669
670以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
671
672| 错误码ID    | 错误信息                                           |
673|----------|------------------------------------------------|
674| 7400101  | Parameter missing or parameter type incorrect. |
675| 7400201  | Camera service fatal error.                    |
676
677**示例:**
678
679```ts
680import { BusinessError } from '@kit.BasicServicesKit';
681
682function createPhotoOutput(cameraOutputCapability: camera.CameraOutputCapability, cameraManager: camera.CameraManager): camera.PhotoOutput | undefined {
683  let profile: camera.Profile = cameraOutputCapability.photoProfiles[0];
684  let photoOutput: camera.PhotoOutput | undefined = undefined;
685  try {
686    photoOutput = cameraManager.createPhotoOutput(profile);
687  } catch (error) {
688    // 失败返回错误码error.code并处理
689    let err = error as BusinessError;
690    console.error(`The createPhotoOutput call failed. error code: ${err.code}`);
691  }
692  return photoOutput;
693}
694```
695
696### createVideoOutput
697
698createVideoOutput(profile: VideoProfile, surfaceId: string): VideoOutput
699
700创建录像输出对象,同步返回结果。
701
702**系统能力:** SystemCapability.Multimedia.Camera.Core
703
704**参数:**
705
706| 参数名     | 类型                                        | 必填 | 说明                              |
707| -------- | ------------------------------------------- | ---- | ------------------------------ |
708| profile  | [VideoProfile](#videoprofile)               | 是   | 支持的录像配置信息,通过[getSupportedOutputCapability](#getsupportedoutputcapability11)接口获取。 |
709| surfaceId| string          | 是   | 从[AVRecorder](../apis-media-kit/js-apis-media.md#avrecorder9)获取的surfaceId。|
710
711**返回值:**
712
713| 类型        | 说明                          |
714| ---------- | ----------------------------- |
715| [VideoOutput](#videooutput)   | VideoOutput实例。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
716
717**错误码:**
718
719以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
720
721| 错误码ID         | 错误信息        |
722| --------------- | --------------- |
723| 7400101                |  Parameter missing or parameter type incorrect.               |
724| 7400201                |  Camera service fatal error.               |
725
726**示例:**
727
728```ts
729import { BusinessError } from '@kit.BasicServicesKit';
730
731function createVideoOutput(cameraOutputCapability: camera.CameraOutputCapability, cameraManager: camera.CameraManager, surfaceId: string): camera.VideoOutput | undefined {
732  let profile: camera.VideoProfile = cameraOutputCapability.videoProfiles[0];
733  let videoOutput: camera.VideoOutput | undefined = undefined;
734  try {
735    videoOutput = cameraManager.createVideoOutput(profile, surfaceId);
736  } catch (error) {
737    // 失败返回错误码error.code并处理
738    let err = error as BusinessError;
739    console.error(`The createVideoOutput call failed. error code: ${err.code}`);
740  }
741  return videoOutput;
742}
743```
744
745### createVideoOutput<sup>12+</sup>
746
747createVideoOutput(surfaceId: string): VideoOutput
748
749创建无配置信息的录像输出对象,同步返回结果。该接口需配合[preconfig](#preconfig12-1)功能一起使用。
750
751**系统能力:** SystemCapability.Multimedia.Camera.Core
752
753**参数:**
754
755| 参数名       | 类型     | 必填    | 说明                                                                         |
756|-----------|--------|-------|----------------------------------------------------------------------------|
757| surfaceId | string | 是     | 从[AVRecorder](../apis-media-kit/js-apis-media.md#avrecorder9)获取的surfaceId。 |
758
759**返回值:**
760
761| 类型        | 说明                          |
762| ---------- | ----------------------------- |
763| [VideoOutput](#videooutput)   | VideoOutput实例。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
764
765**错误码:**
766
767以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
768
769| 错误码ID    | 错误信息                                           |
770|----------|------------------------------------------------|
771| 7400101  | Parameter missing or parameter type incorrect. |
772| 7400201  | Camera service fatal error.                    |
773
774**示例:**
775
776```ts
777import { BusinessError } from '@kit.BasicServicesKit';
778
779function createVideoOutput(cameraManager: camera.CameraManager, surfaceId: string): camera.VideoOutput | undefined {
780  let videoOutput: camera.VideoOutput | undefined = undefined;
781  try {
782    videoOutput = cameraManager.createVideoOutput(surfaceId);
783  } catch (error) {
784    // 失败返回错误码error.code并处理
785    let err = error as BusinessError;
786    console.error(`The createVideoOutput call failed. error code: ${err.code}`);
787  }
788  return videoOutput;
789}
790```
791
792### createMetadataOutput
793
794createMetadataOutput(metadataObjectTypes: Array\<MetadataObjectType\>): MetadataOutput
795
796创建metadata流输出对象,同步返回结果。
797
798**系统能力:** SystemCapability.Multimedia.Camera.Core
799
800**参数:**
801
802| 参数名                  | 类型                                               | 必填 | 说明                          |
803| -------------------- | -------------------------------------------------- | --- | ---------------------------- |
804| metadataObjectTypes  | Array\<[MetadataObjectType](#metadataobjecttype)\>  | 是  | metadata流类型信息,通过[getSupportedOutputCapability](#getsupportedoutputcapability11)接口获取。 |
805
806**返回值:**
807
808| 类型        | 说明                          |
809| ---------- | ----------------------------- |
810| [MetadataOutput](#metadataoutput)   | MetadataOutput实例。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
811
812**错误码:**
813
814以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
815
816| 错误码ID         | 错误信息        |
817| --------------- | --------------- |
818| 7400101                |  Parameter missing or parameter type incorrect.               |
819| 7400201                |  Camera service fatal error.               |
820
821**示例:**
822
823```ts
824import { BusinessError } from '@kit.BasicServicesKit';
825
826function createMetadataOutput(cameraManager: camera.CameraManager, cameraOutputCapability: camera.CameraOutputCapability): void {
827  let metadataObjectTypes: Array<camera.MetadataObjectType> = cameraOutputCapability.supportedMetadataObjectTypes;
828  let metadataOutput: camera.MetadataOutput | undefined = undefined;
829  try {
830    metadataOutput = cameraManager.createMetadataOutput(metadataObjectTypes);
831  } catch (error) {
832    // 失败返回错误码error.code并处理
833    let err = error as BusinessError;
834    console.error(`createMetadataOutput error. error code: ${err.code}`);
835  }
836}
837```
838
839### createCaptureSession<sup>(deprecated)</sup>
840
841createCaptureSession(): CaptureSession
842
843创建CaptureSession实例,同步返回结果。
844
845> **说明:**
846>从 API version 10开始支持,从API version 11开始废弃。建议使用[createSession](#createsession11)替代。
847
848**系统能力:** SystemCapability.Multimedia.Camera.Core
849
850**返回值:**
851
852| 类型        | 说明                          |
853| ---------- | ----------------------------- |
854| [CaptureSession](#capturesessiondeprecated)   | CaptureSession实例。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
855
856**错误码:**
857
858以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
859
860| 错误码ID         | 错误信息        |
861| --------------- | --------------- |
862| 7400201                |  Camera service fatal error.               |
863
864**示例:**
865
866```ts
867import { BusinessError } from '@kit.BasicServicesKit';
868
869function createCaptureSession(cameraManager: camera.CameraManager): camera.CaptureSession | undefined {
870  let captureSession: camera.CaptureSession | undefined = undefined;
871  try {
872    captureSession = cameraManager.createCaptureSession();
873  } catch (error) {
874    // 失败返回错误码error.code并处理
875    let err = error as BusinessError;
876    console.error(`createCaptureSession error. error code: ${err.code}`);
877  }
878  return captureSession;
879}
880```
881
882### createSession<sup>11+</sup>
883
884createSession\<T extends Session\>(mode: SceneMode): T
885
886创建指定SceneMode的Session实例,同步返回结果。
887
888**系统能力:** SystemCapability.Multimedia.Camera.Core
889
890**参数:**
891
892| 参数名   | 类型              | 必填 | 说明       |
893| -------- | -----------------| ---- | --------- |
894| mode     | [SceneMode](#scenemode11)     | 是   | 相机支持的模式。传参异常(如超出范围、传入null、未定义等),实际接口不会生效。 |
895
896**返回值:**
897
898| 类型        | 说明                          |
899| ---------- | ----------------------------- |
900| [T extends Session](#session11)   | Session实例。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
901
902**错误码:**
903
904以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
905
906| 错误码ID         | 错误信息                                                                                                                                           |
907| --------------- |------------------------------------------------------------------------------------------------------------------------------------------------|
908| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3.Parameter verification failed. |
909| 7400201                | Camera service fatal error.                                                                                                                    |
910
911**示例:**
912
913```ts
914import { BusinessError } from '@kit.BasicServicesKit';
915
916function createSession(cameraManager: camera.CameraManager, mode: camera.SceneMode): camera.Session | undefined {
917  let photoSession: camera.PhotoSession | undefined = undefined;
918  try {
919    photoSession = cameraManager.createSession(mode) as camera.PhotoSession;
920  } catch (error) {
921    // 失败返回错误码error.code并处理
922    let err = error as BusinessError;
923    console.error(`createCaptureSession error. error code: ${err.code}`);
924  }
925  return photoSession;
926}
927```
928
929### on('cameraStatus')
930
931on(type: 'cameraStatus', callback: AsyncCallback\<CameraStatusInfo\>): void
932
933相机设备状态回调,通过注册回调函数获取相机的状态变化。使用callback异步回调。
934
935> **说明:**
936>
937> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
938
939**系统能力:** SystemCapability.Multimedia.Camera.Core
940
941**参数:**
942
943| 参数名     | 类型            | 必填 | 说明       |
944| -------- | -----------------| ---- | --------- |
945| type     | string           | 是   | 监听事件,固定为'cameraStatus'。cameraManager对象获取成功后可监听。目前只支持对设备打开或者关闭会触发该事件并返回对应信息。 |
946| callback | AsyncCallback\<[CameraStatusInfo](#camerastatusinfo)\> | 是   | 回调函数,用于获取镜头状态变化信息。 |                 |
947
948**示例:**
949
950```ts
951import { BusinessError } from '@kit.BasicServicesKit';
952
953function callback(err: BusinessError, cameraStatusInfo: camera.CameraStatusInfo): void {
954  if (err !== undefined && err.code !== 0) {
955    console.error('cameraStatus with errorCode = ' + err.code);
956    return;
957  }
958  console.info(`camera : ${cameraStatusInfo.camera.cameraId}`);
959  console.info(`status: ${cameraStatusInfo.status}`);
960}
961
962function registerCameraStatus(cameraManager: camera.CameraManager): void {
963  cameraManager.on('cameraStatus', callback);
964}
965```
966
967### off('cameraStatus')
968
969off(type: 'cameraStatus', callback?: AsyncCallback\<CameraStatusInfo\>): void
970
971相机设备状态注销回调,通过注销回调函数取消获取相机的状态变化。
972
973**系统能力:** SystemCapability.Multimedia.Camera.Core
974
975**参数:**
976
977| 参数名     | 类型            | 必填 | 说明       |
978| -------- | -----------------| ---- | --------- |
979| type     | string           | 是   | 监听事件,固定为'cameraStatus'。cameraManager对象获取成功后可监听。 |
980| callback | AsyncCallback\<[CameraStatusInfo](#camerastatusinfo)\> | 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
981
982**示例:**
983
984```ts
985function unregisterCameraStatus(cameraManager: camera.CameraManager): void {
986  cameraManager.off('cameraStatus');
987}
988```
989
990### on('foldStatusChange')<sup>12+</sup>
991
992on(type: 'foldStatusChange', callback: AsyncCallback\<FoldStatusInfo\>): void
993
994开启折叠设备折叠状态变化的监听。使用callback异步回调。
995
996> **说明:**
997>
998> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
999
1000**系统能力:** SystemCapability.Multimedia.Camera.Core
1001
1002**参数:**
1003
1004| 参数名     | 类型            | 必填 | 说明       |
1005| -------- | -----------------| ---- | --------- |
1006| type     | string           | 是   | 监听事件,固定为'foldStatusChange'。表示折叠设备折叠状态发生变化。 |
1007| callback | AsyncCallback\<[FoldStatusInfo](#foldstatusinfo12)\> | 是   | 回调函数。返回折叠设备折叠信息。 |
1008
1009**示例:**
1010
1011```ts
1012import { BusinessError } from '@kit.BasicServicesKit';
1013
1014function callback(err: BusinessError, foldStatusInfo: camera.FoldStatusInfo): void {
1015  if (err !== undefined && err.code !== 0) {
1016    console.error('foldStatusChange with errorCode = ' + err.code);
1017    return;
1018  }
1019  console.info(`camera length: ${foldStatusInfo.supportedCameras.length}`);
1020  console.info(`foldStatus: ${foldStatusInfo.foldStatus}`);
1021}
1022
1023function registerFoldStatusChange(cameraManager: camera.CameraManager): void {
1024  cameraManager.on('foldStatusChange', callback);
1025}
1026```
1027
1028### off('foldStatusChange')<sup>12+</sup>
1029
1030off(type: 'foldStatusChange', callback?: AsyncCallback\<FoldStatusInfo\>): void
1031
1032关闭折叠设备折叠状态变化的监听。
1033
1034**系统能力:** SystemCapability.Multimedia.Camera.Core
1035
1036**参数:**
1037
1038| 参数名     | 类型            | 必填 | 说明       |
1039| -------- | -----------------| ---- | --------- |
1040| type     | string           | 是   | 监听事件,固定为'foldStatusChange'。表示折叠设备折叠状态发生变化。 |
1041| callback | AsyncCallback\<[FoldStatusInfo](#foldstatusinfo12)\> | 否   | 回调函数,返回折叠设备折叠信息。如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
1042
1043**示例:**
1044
1045```ts
1046function unregisterFoldStatusChange(cameraManager: camera.CameraManager): void {
1047  cameraManager.off('foldStatusChange');
1048}
1049```
1050
1051### isTorchSupported<sup>11+</sup>
1052
1053isTorchSupported(): boolean
1054
1055检测设备是否支持手电筒。
1056
1057**系统能力:** SystemCapability.Multimedia.Camera.Core
1058
1059**返回值:**
1060
1061| 类型        | 说明                          |
1062| ---------- | ----------------------------- |
1063| boolean    | 返回true表示设备支持手电筒。 |
1064
1065**示例:**
1066
1067```ts
1068function isTorchSupported(cameraManager: camera.CameraManager): boolean {
1069  let isSupported = cameraManager.isTorchSupported();
1070  return isSupported;
1071}
1072```
1073
1074### isTorchModeSupported<sup>11+</sup>
1075
1076isTorchModeSupported(mode: TorchMode): boolean
1077
1078检测是否支持设置的手电筒模式。
1079
1080**系统能力:** SystemCapability.Multimedia.Camera.Core
1081
1082**参数:**
1083
1084| 参数名     | 类型             | 必填 | 说明       |
1085| -------- | --------------- | ---- | --------- |
1086| mode | [TorchMode](#torchmode11) | 是 | 手电筒模式。传参为null或者undefined,作为0处理,手电筒关闭。 |
1087
1088**返回值:**
1089
1090| 类型        | 说明                          |
1091| ---------- | ----------------------------- |
1092| boolean    | 返回true表示设备支持设置的手电筒模式。 |
1093
1094**示例:**
1095
1096```ts
1097function isTorchModeSupported(cameraManager: camera.CameraManager, torchMode: camera.TorchMode): boolean {
1098  let isSupported = cameraManager.isTorchModeSupported(torchMode);
1099  return isSupported;
1100}
1101```
1102
1103### getTorchMode<sup>11+</sup>
1104
1105getTorchMode(): TorchMode
1106
1107获取当前设备手电筒模式。
1108
1109**系统能力:** SystemCapability.Multimedia.Camera.Core
1110
1111**返回值:**
1112
1113| 类型        | 说明                          |
1114| ---------- | ----------------------------- |
1115| [TorchMode](#torchmode11)    | 返回设备当前手电筒模式。 |
1116
1117**示例:**
1118
1119```ts
1120function getTorchMode(cameraManager: camera.CameraManager): camera.TorchMode | undefined {
1121  let torchMode: camera.TorchMode | undefined = undefined;
1122  torchMode = cameraManager.getTorchMode();
1123  return torchMode;
1124}
1125```
1126
1127### setTorchMode<sup>11+</sup>
1128
1129setTorchMode(mode: TorchMode): void
1130
1131设置设备手电筒模式。
1132
1133**系统能力:** SystemCapability.Multimedia.Camera.Core
1134
1135**参数:**
1136
1137| 参数名     | 类型             | 必填 | 说明       |
1138| -------- | --------------- | ---- | --------- |
1139| mode | [TorchMode](#torchmode11) | 是 | 手电筒模式。传参为null或者undefined,作为0处理,手电筒关闭。 |
1140
1141**错误码:**
1142
1143以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
1144
1145| 错误码ID         | 错误信息        |
1146| --------------- | --------------- |
1147| 7400101 | Parameter missing or parameter type incorrect. |
1148| 7400102 | Operation not allowed. |
1149| 7400201 | Camera service fatal error. |
1150
1151**示例:**
1152
1153```ts
1154import { BusinessError } from '@kit.BasicServicesKit';
1155
1156function setTorchMode(cameraManager: camera.CameraManager, torchMode: camera.TorchMode): void {
1157  try {
1158    cameraManager.setTorchMode(torchMode);
1159  } catch (error) {
1160    // 失败返回错误码error.code并处理
1161    let err = error as BusinessError;
1162    console.error(`The setTorchMode call failed. error code: ${err.code}`);
1163  }
1164}
1165```
1166
1167### on('torchStatusChange')<sup>11+</sup>
1168
1169on(type: 'torchStatusChange', callback: AsyncCallback\<TorchStatusInfo\>): void
1170
1171手电筒状态变化回调,通过注册回调函数获取手电筒状态变化。使用callback异步回调。
1172
1173> **说明:**
1174>
1175> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
1176
1177**系统能力:** SystemCapability.Multimedia.Camera.Core
1178
1179**参数:**
1180
1181| 参数名     | 类型             | 必填 | 说明       |
1182| -------- | --------------- | ---- | --------- |
1183| type     | string          | 是   | 监听事件,固定为'torchStatusChange'。cameraManager对象获取成功后可监听。目前只支持手电筒打开,手电筒关闭,手电筒不可用,手电筒恢复可用会触发该事件并返回对应信息。 |
1184| callback | AsyncCallback\<TorchStatusInfo> | 是   | 回调函数,用于获取手电筒状态变化信息。               |
1185
1186**示例:**
1187
1188```ts
1189import { BusinessError } from '@kit.BasicServicesKit';
1190
1191function callback(err: BusinessError, torchStatusInfo: camera.TorchStatusInfo): void {
1192  if (err !== undefined && err.code !== 0) {
1193    console.error(`Callback Error, errorCode: ${err.code}`);
1194    return;
1195  }
1196  console.info(`onTorchStatusChange, isTorchAvailable: ${torchStatusInfo.isTorchAvailable}, isTorchActive: ${torchStatusInfo.isTorchActive}, level: ${torchStatusInfo.torchLevel}`);
1197}
1198
1199function registerTorchStatusChange(cameraManager: camera.CameraManager): void {
1200  cameraManager.on('torchStatusChange', callback);
1201}
1202```
1203
1204### off('torchStatusChange')<sup>11+</sup>
1205
1206off(type: 'torchStatusChange', callback?: AsyncCallback\<TorchStatusInfo\>): void
1207
1208手电筒状态变化注销回调,通过注销回调函数取消获取手电筒状态变化。
1209
1210**系统能力:** SystemCapability.Multimedia.Camera.Core
1211
1212**参数:**
1213
1214| 参数名     | 类型             | 必填 | 说明       |
1215| -------- | --------------- | ---- | --------- |
1216| type     | string          | 是   | 监听事件,固定为'torchStatusChange'。cameraManager对象获取成功后可监听。 |
1217| callback | AsyncCallback\<TorchStatusInfo> | 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
1218
1219**示例:**
1220
1221```ts
1222function unregisterTorchStatusChange(cameraManager: camera.CameraManager): void {
1223  cameraManager.off('torchStatusChange');
1224}
1225```
1226
1227## TorchMode<sup>11+</sup>
1228
1229枚举,手电筒模式。
1230
1231**系统能力:** SystemCapability.Multimedia.Camera.Core
1232
1233| 名称                          | 值   | 说明           |
1234| ---------------------------- | ---- | ------------- |
1235| OFF    | 0    | 常关模式。      |
1236| ON  | 1    | 常开模式。 |
1237| AUTO      | 2    | 自动模式。 |
1238
1239## TorchStatusInfo<sup>11+</sup>
1240
1241手电筒回调返回的接口实例,表示手电筒状态信息。
1242
1243**系统能力:** SystemCapability.Multimedia.Camera.Core
1244
1245| 名称              | 类型       | 只读 | 可选 | 说明        |
1246| ---------------- | ---------- | ---- | ---- | ----------- |
1247| isTorchAvailable | boolean    | 是   | 否   | 手电筒是否可用。|
1248| isTorchActive    | boolean    | 是   | 否   | 手电筒是否被激活。    |
1249| torchLevel       | number     | 是   | 否   | 手电筒亮度等级。取值范围为[0,1],越靠近1,亮度越大。    |
1250
1251## Size
1252
1253输出能力查询。
1254
1255**系统能力:** SystemCapability.Multimedia.Camera.Core
1256
1257| 名称   | 类型    | 只读 | 可选  | 说明         |
1258| ------ | ------ | ---- |-----| ------------ |
1259| height | number | 否   | 否   | 图像尺寸高(像素)。 |
1260| width  | number | 否   | 否   | 图像尺寸宽(像素)。 |
1261
1262## Point
1263
1264点坐标用于对焦、曝光配置。
1265
1266**系统能力:** SystemCapability.Multimedia.Camera.Core
1267
1268| 名称    | 类型   | 只读   | 可选   | 说明         |
1269| ------ | ------ | ------ | ------ | ------------ |
1270| x      | number | 否     | 否     | 点的x坐标。   |
1271| y      | number | 否     | 否     | 点的y坐标。   |
1272
1273## CameraFormat
1274
1275枚举,输出格式。
1276
1277**系统能力:** SystemCapability.Multimedia.Camera.Core
1278
1279| 名称                     | 值        | 说明         |
1280| ----------------------- | --------- | ------------ |
1281| CAMERA_FORMAT_RGBA_8888 | 3         | RGBA_888格式的图片。        |
1282| CAMERA_FORMAT_YUV_420_SP| 1003      | YUV_420_SP格式的图片。      |
1283| CAMERA_FORMAT_JPEG      | 2000      | JPEG格式的图片。            |
1284| CAMERA_FORMAT_YCBCR_P010<sup>11+</sup> |   2001    | YCBCR_P010格式的图片。      |
1285| CAMERA_FORMAT_YCRCB_P010<sup>11+</sup> |   2002    | YCRCB_P010格式的图片。      |
1286| CAMERA_FORMAT_HEIC<sup>13+</sup>       |   2003    | HEIF格式的图片。            |
1287
1288## VideoCodecType<sup>13+</sup>
1289
1290枚举,视频编码类型。
1291
1292**系统能力:** SystemCapability.Multimedia.Camera.Core
1293
1294| 名称   | 值    | 说明          |
1295|------|------|-------------|
1296| AVC  | 0    | 视频编码类型AVC。  |
1297| HEVC | 1 | 视频编码类型HEVC。 |
1298
1299## CameraInput
1300
1301相机设备输入对象。
1302
1303会话中[Session](#session11)使用的相机信息。
1304
1305### open
1306
1307open(callback: AsyncCallback\<void\>): void
1308
1309打开相机,通过注册回调函数获取状态。使用callback异步回调。
1310
1311**系统能力:** SystemCapability.Multimedia.Camera.Core
1312
1313**参数:**
1314
1315| 参数名     | 类型                  | 必填 | 说明                  |
1316| -------- | -------------------- | ---- | ------------------- |
1317| callback | AsyncCallback\<void\> | 是   | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
1318
1319**错误码:**
1320
1321以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
1322
1323| 错误码ID         | 错误信息        |
1324| --------------- | --------------- |
1325| 7400107                |  Can not use camera cause of conflict.               |
1326| 7400108                |  Camera disabled cause of security reason.                                  |
1327| 7400201                |  Camera service fatal error.                                  |
1328
1329**示例:**
1330
1331```ts
1332import { BusinessError } from '@kit.BasicServicesKit';
1333
1334function openCameraInput(cameraInput: camera.CameraInput): void {
1335  cameraInput.open((err: BusinessError) => {
1336    if (err) {
1337      console.error(`Failed to open the camera, error code: ${err.code}.`);
1338      return;
1339    }
1340    console.info('Callback returned with camera opened.');
1341  });
1342}
1343```
1344
1345### open
1346
1347open(): Promise\<void\>
1348
1349打开相机,通过Promise获取相机的状态。
1350
1351**系统能力:** SystemCapability.Multimedia.Camera.Core
1352
1353**返回值:**
1354
1355| 类型           | 说明                      |
1356| -------------- | ----------------------- |
1357| Promise\<void\> | 无返回结果的Promise对象。 |
1358
1359**错误码:**
1360
1361以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
1362
1363| 错误码ID   | 错误信息                                      |
1364|---------|-------------------------------------------|
1365| 7400102 | Operation not allowed.                    |
1366| 7400107 | Can not use camera cause of conflict.     |
1367| 7400108 | Camera disabled cause of security reason. |
1368| 7400201 | Camera service fatal error.               |
1369
1370**示例:**
1371
1372```ts
1373import { BusinessError } from '@kit.BasicServicesKit';
1374
1375function openCameraInput(cameraInput: camera.CameraInput): void {
1376  cameraInput.open().then(() => {
1377    console.info('Promise returned with camera opened.');
1378  }).catch((error: BusinessError) => {
1379    console.error(`Failed to open the camera, error code: ${error.code}.`);
1380  });
1381}
1382```
1383
1384### open<sup>12+</sup>
1385
1386open(isSecureEnabled: boolean): Promise\<bigint\>
1387
1388打开相机,获取安全相机的句柄。
1389
1390**系统能力:** SystemCapability.Multimedia.Camera.Core
1391
1392**参数:**
1393
1394| 参数名     | 类型                  | 必填 | 说明                                                                      |
1395| -------- | -------------------- | ---- |-------------------------------------------------------------------------|
1396| isSecureEnabled | boolean | 是   | 是否使能以安全的方式打开相机。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
1397
1398**返回值:**
1399
1400| 类型           | 说明                      |
1401| -------------- | ----------------------- |
1402| Promise\<bigint\> | 使用Promise的方式获取打开相机句柄。 |
1403
1404**错误码:**
1405
1406以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
1407
1408| 错误码ID         | 错误信息        |
1409| --------------- | --------------- |
1410| 7400107                |  Can not use camera cause of conflict.               |
1411| 7400108                |  Camera disabled cause of security reason.                                  |
1412| 7400201                |  Camera service fatal error.                                  |
1413
1414**示例:**
1415
1416```ts
1417import { BusinessError } from '@kit.BasicServicesKit';
1418
1419function openCameraInput(cameraInput: camera.CameraInput): void {
1420  cameraInput.open(true).then(() => {
1421    console.info('Promise returned with camera opened.');
1422  }).catch((error: BusinessError) => {
1423    console.error(`Failed to open the camera, error code: ${error.code}.`);
1424  });
1425}
1426```
1427
1428### close
1429
1430close(callback: AsyncCallback\<void\>\): void
1431
1432关闭相机,通过注册回调函数获取状态。使用callback异步回调。
1433
1434**系统能力:** SystemCapability.Multimedia.Camera.Core
1435
1436**参数:**
1437
1438| 参数名     | 类型                   | 必填 | 说明                  |
1439| -------- | -------------------- | ---- | -------------------- |
1440| callback | AsyncCallback\<void\> | 是   | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
1441
1442**错误码:**
1443
1444以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
1445
1446| 错误码ID         | 错误信息        |
1447| --------------- | --------------- |
1448| 7400201                |  Camera service fatal error.                                  |
1449
1450**示例:**
1451
1452```ts
1453import { BusinessError } from '@kit.BasicServicesKit';
1454
1455function closeCameraInput(cameraInput: camera.CameraInput): void {
1456  cameraInput.close((err: BusinessError) => {
1457    if (err) {
1458      console.error(`Failed to close the cameras, error code: ${err.code}.`);
1459      return;
1460    }
1461    console.info('Callback returned with camera closed.');
1462  });
1463}
1464```
1465
1466### close
1467
1468close(): Promise\<void\>
1469
1470关闭相机,通过Promise获取状态。
1471
1472**系统能力:** SystemCapability.Multimedia.Camera.Core
1473
1474**返回值:**
1475
1476| 类型           | 说明                      |
1477| -------------- | ----------------------- |
1478| Promise\<void\> | 无返回结果的Promise对象。 |
1479
1480**错误码:**
1481
1482以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
1483
1484| 错误码ID         | 错误信息        |
1485| --------------- | --------------- |
1486| 7400201                |  Camera service fatal error.                                  |
1487
1488**示例:**
1489
1490```ts
1491import { BusinessError } from '@kit.BasicServicesKit';
1492
1493function closeCameraInput(cameraInput: camera.CameraInput): void {
1494  cameraInput.close().then(() => {
1495    console.info('Promise returned with camera closed.');
1496  }).catch((error: BusinessError) => {
1497    console.error(`Failed to close the cameras, error code: ${error.code}.`);
1498  });
1499}
1500```
1501
1502### on('error')
1503
1504on(type: 'error', camera: CameraDevice, callback: ErrorCallback): void
1505
1506监听CameraInput的错误事件,通过注册回调函数获取结果。使用callback异步回调。
1507
1508> **说明:**
1509>
1510> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
1511
1512**系统能力:** SystemCapability.Multimedia.Camera.Core
1513
1514**参数:**
1515
1516| 参数名     | 类型                              | 必填 | 说明                                          |
1517| -------- | -------------------------------- | --- | ------------------------------------------- |
1518| type     | string                           | 是   | 监听事件,固定为'error',CameraInput对象创建成功可监听。相机设备出错情况下可触发该事件并返回结果,比如设备不可用或者冲突等返回对应错误信息。 |
1519| camera   | [CameraDevice](#cameradevice)    | 是   | CameraDevice对象。 |
1520| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | 是   | 回调函数,用于获取结果。返回错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。  |
1521
1522**示例:**
1523
1524```ts
1525import { BusinessError } from '@kit.BasicServicesKit';
1526
1527function callback(err: BusinessError): void {
1528  console.error(`Camera input error code: ${err.code}`);
1529}
1530
1531function registerCameraInputError(cameraInput: camera.CameraInput, camera: camera.CameraDevice): void {
1532  cameraInput.on('error', camera, callback);
1533}
1534```
1535
1536### off('error')
1537
1538off(type: 'error', camera: CameraDevice, callback?: ErrorCallback): void
1539
1540注销监听CameraInput的错误事件。
1541
1542**系统能力:** SystemCapability.Multimedia.Camera.Core
1543
1544**参数:**
1545
1546| 参数名     | 类型                              | 必填 | 说明                                          |
1547| -------- | -------------------------------- | --- | ------------------------------------------- |
1548| type     | string                           | 是   | 监听事件,固定为'error',CameraInput对象创建成功可监听。相机设备出错情况下可触发该事件并返回结果,比如设备不可用或者冲突等返回对应错误信息。 |
1549| camera   | [CameraDevice](#cameradevice)    | 是   | CameraDevice对象。 |
1550| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
1551
1552**示例:**
1553
1554```ts
1555function unregisterCameraInputError(cameraInput: camera.CameraInput, camera: camera.CameraDevice): void {
1556  cameraInput.off('error', camera);
1557}
1558```
1559
1560## CameraOutput
1561
1562会话中[Session](#session11)使用的输出信息,output的基类。
1563
1564### release
1565
1566release(callback: AsyncCallback\<void\>): void
1567
1568释放输出资源,通过注册回调函数获取结果。使用callback异步回调。
1569
1570**系统能力:** SystemCapability.Multimedia.Camera.Core
1571
1572**参数:**
1573
1574| 参数名      | 类型                  | 必填 | 说明                 |
1575| -------- | -------------------- | ---- | ------------------- |
1576| callback | AsyncCallback\<void\> | 是   | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
1577
1578**错误码:**
1579
1580以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
1581
1582| 错误码ID         | 错误信息        |
1583| --------------- | --------------- |
1584| 7400201                |  Camera service fatal error.                           |
1585
1586**示例:**
1587
1588```ts
1589import { BusinessError } from '@kit.BasicServicesKit';
1590
1591function releasePreviewOutput(previewOutput: camera.PreviewOutput): void {
1592  previewOutput.release((err: BusinessError) => {
1593    if (err) {
1594      console.error(`Failed to release the Preview output instance ${err.code}`);
1595      return;
1596    }
1597    console.info('Callback invoked to indicate that the preview output instance is released successfully.');
1598  });
1599}
1600
1601function releaseVideoOutput(videoOutput: camera.VideoOutput): void {
1602  videoOutput.release((err: BusinessError) => {
1603    if (err) {
1604      console.error(`Failed to release the video output instance ${err.code}`);
1605      return;
1606    }
1607    console.info('Callback invoked to indicate that the video output instance is released successfully.');
1608  });
1609}
1610```
1611
1612### release
1613
1614release(): Promise\<void\>
1615
1616释放输出资源,通过Promise获取结果。
1617
1618**系统能力:** SystemCapability.Multimedia.Camera.Core
1619
1620**返回值:**
1621
1622| 类型            | 说明                     |
1623| -------------- | ----------------------- |
1624| Promise\<void\> | 无返回结果的Promise对象。 |
1625
1626**错误码:**
1627
1628以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
1629
1630| 错误码ID         | 错误信息        |
1631| --------------- | --------------- |
1632| 7400201                |  Camera service fatal error.                           |
1633
1634**示例:**
1635
1636```ts
1637import { BusinessError } from '@kit.BasicServicesKit';
1638
1639function releasePreviewOutput(previewOutput: camera.PreviewOutput): void {
1640  previewOutput.release().then(() => {
1641    console.info('Promise returned to indicate that the preview output instance is released successfully.');
1642  }).catch((error: BusinessError) => {
1643    console.error(`Failed to preview output release, error code: ${error.code}`);
1644  });
1645}
1646
1647function releaseVideoOutput(videoOutput: camera.VideoOutput): void {
1648  videoOutput.release().then(() => {
1649    console.info('Promise returned to indicate that the video output instance is released successfully.');
1650  }).catch((error: BusinessError) => {
1651    console.error(`Failed to video output release, error code: ${error.code}`);
1652  });
1653}
1654```
1655
1656## PreviewOutput
1657
1658预览输出类。继承[CameraOutput](#cameraoutput)。
1659
1660### start<sup>(deprecated)</sup>
1661
1662start(callback: AsyncCallback\<void\>): void
1663
1664开始输出预览流,通过注册回调函数获取结果。使用callback异步回调。
1665
1666> **说明:**
1667>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.start](#start11)替代。
1668
1669**系统能力:** SystemCapability.Multimedia.Camera.Core
1670
1671**参数:**
1672
1673| 参数名      | 类型                  | 必填 | 说明                 |
1674| -------- | -------------------- | ---- | -------------------- |
1675| callback | AsyncCallback\<void\> | 是   | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
1676
1677**错误码:**
1678
1679以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
1680
1681| 错误码ID         | 错误信息        |
1682| --------------- | --------------- |
1683| 7400103                |  Session not config.                                   |
1684
1685**示例:**
1686
1687```ts
1688import { BusinessError } from '@kit.BasicServicesKit';
1689
1690function startPreviewOutput(previewOutput: camera.PreviewOutput): void {
1691  previewOutput.start((err: BusinessError) => {
1692    if (err) {
1693      console.error(`Failed to start the preview output, error code: ${err.code}.`);
1694      return;
1695    }
1696    console.info('Callback returned with preview output started.');
1697  });
1698}
1699```
1700
1701### start<sup>(deprecated)</sup>
1702
1703start(): Promise\<void\>
1704
1705开始输出预览流,通过Promise获取结果。
1706
1707> **说明:**
1708>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.start](#start11-1)替代。
1709
1710**系统能力:** SystemCapability.Multimedia.Camera.Core
1711
1712**返回值:**
1713
1714| 类型            | 说明                |
1715| -------------- |-------------------|
1716| Promise\<void\> | 无返回结果的Promise对象。  |
1717
1718**错误码:**
1719
1720以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
1721
1722| 错误码ID         | 错误信息        |
1723| --------------- | --------------- |
1724| 7400103                |  Session not config.                                   |
1725
1726**示例:**
1727
1728```ts
1729import { BusinessError } from '@kit.BasicServicesKit';
1730
1731function startPreviewOutput(previewOutput: camera.PreviewOutput): void {
1732  previewOutput.start().then(() => {
1733    console.info('Promise returned with preview output started.');
1734  }).catch((error: BusinessError) => {
1735    console.error(`Failed to preview output start, error code: ${error.code}.`);
1736  });
1737}
1738```
1739
1740### stop<sup>(deprecated)</sup>
1741
1742stop(callback: AsyncCallback\<void\>): void
1743
1744停止输出预览流,通过注册回调函数获取结果。使用callback异步回调。
1745
1746> **说明:**
1747>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.stop](#stop11)替代。
1748
1749**系统能力:** SystemCapability.Multimedia.Camera.Core
1750
1751**参数:**
1752
1753| 参数名      | 类型                  | 必填 | 说明                 |
1754| -------- | -------------------- | ---- | -------------------- |
1755| callback | AsyncCallback\<void\> | 是   | 回调函数,用于获取结果。 |
1756
1757**示例:**
1758
1759```ts
1760import { BusinessError } from '@kit.BasicServicesKit';
1761
1762function stopPreviewOutput(previewOutput: camera.PreviewOutput): void {
1763  previewOutput.stop((err: BusinessError) => {
1764    if (err) {
1765      console.error(`Failed to stop the preview output, error code: ${err.code}.`);
1766      return;
1767    }
1768    console.info('Returned with preview output stopped.');
1769  })
1770}
1771```
1772
1773### stop<sup>(deprecated)</sup>
1774
1775stop(): Promise\<void\>
1776
1777停止输出预览流,通过Promise获取结果。
1778
1779> **说明:**
1780>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.stop](#stop11-1)替代。
1781
1782**系统能力:** SystemCapability.Multimedia.Camera.Core
1783
1784**返回值:**
1785
1786| 类型            | 说明                     |
1787| -------------- | ------------------------ |
1788| Promise\<void\> | 无返回结果的Promise对象。 |
1789
1790**示例:**
1791
1792```ts
1793import { BusinessError } from '@kit.BasicServicesKit';
1794
1795function stopPreviewOutput(previewOutput: camera.PreviewOutput): void {
1796  previewOutput.stop().then(() => {
1797    console.info('Callback returned with preview output stopped.');
1798  }).catch((error: BusinessError) => {
1799    console.error(`Failed to preview output stop, error code: ${error.code}.`);
1800  });
1801}
1802```
1803
1804### on('frameStart')
1805
1806on(type: 'frameStart', callback: AsyncCallback\<void\>): void
1807
1808监听预览帧启动,通过注册回调函数获取结果。使用callback异步回调。
1809
1810> **说明:**
1811>
1812> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
1813
1814**系统能力:** SystemCapability.Multimedia.Camera.Core
1815
1816**参数:**
1817
1818| 参数名      | 类型                  | 必填 | 说明                                     |
1819| -------- | -------------------- | ---- | --------------------------------------- |
1820| type     | string               | 是   | 监听事件,固定为'frameStart',previewOutput创建成功可监听。底层第一次开始曝光时触发该事件并返回。 |
1821| callback | AsyncCallback\<void\> | 是   | 回调函数,用于获取结果。只要有该事件返回就证明预览开始。                    |
1822
1823**示例:**
1824
1825```ts
1826import { BusinessError } from '@kit.BasicServicesKit';
1827
1828function callback(err: BusinessError): void {
1829  if (err !== undefined && err.code !== 0) {
1830    console.error(`Callback Error, errorCode: ${err.code}`);
1831    return;
1832  }
1833  console.info('Preview frame started');
1834}
1835
1836function registerPreviewOutputFrameStart(previewOutput: camera.PreviewOutput): void {
1837  previewOutput.on('frameStart', callback);
1838}
1839```
1840
1841### off('frameStart')
1842
1843off(type: 'frameStart', callback?: AsyncCallback\<void\>): void
1844
1845注销监听预览帧启动。
1846
1847**系统能力:** SystemCapability.Multimedia.Camera.Core
1848
1849**参数:**
1850
1851| 参数名      | 类型                  | 必填 | 说明                                     |
1852| -------- | -------------------- | ---- | --------------------------------------- |
1853| type     | string               | 是   | 监听事件,固定为'frameStart',previewOutput创建成功可监听。 |
1854| callback | AsyncCallback\<void\> | 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
1855
1856**示例:**
1857
1858```ts
1859function unregisterPreviewOutputFrameStart(previewOutput: camera.PreviewOutput): void {
1860  previewOutput.off('frameStart');
1861}
1862```
1863
1864### on('frameEnd')
1865
1866on(type: 'frameEnd', callback: AsyncCallback\<void\>): void
1867
1868监听预览帧结束,通过注册回调函数获取结果。使用callback异步回调。
1869
1870> **说明:**
1871>
1872> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
1873
1874**系统能力:** SystemCapability.Multimedia.Camera.Core
1875
1876**参数:**
1877
1878| 参数名      | 类型                  | 必填 | 说明                                  |
1879| -------- | -------------------- | ---- | ------------------------------------- |
1880| type     | string               | 是   | 监听事件,固定为'frameEnd',previewOutput创建成功可监听。预览完全结束最后一帧时触发该事件并返回。 |
1881| callback | AsyncCallback\<void\> | 是   | 回调函数,用于获取结果。只要有该事件返回就证明预览结束。                |
1882
1883**示例:**
1884
1885```ts
1886import { BusinessError } from '@kit.BasicServicesKit';
1887
1888function callback(err: BusinessError): void {
1889  if (err !== undefined && err.code !== 0) {
1890    console.error(`Callback Error, errorCode: ${err.code}`);
1891    return;
1892  }
1893  console.info('Preview frame ended');
1894}
1895
1896function registerPreviewOutputFrameEnd(previewOutput: camera.PreviewOutput): void {
1897  previewOutput.on('frameEnd', callback);
1898}
1899```
1900
1901### off('frameEnd')
1902
1903off(type: 'frameEnd', callback?: AsyncCallback\<void\>): void
1904
1905注销监听预览帧结束。
1906
1907**系统能力:** SystemCapability.Multimedia.Camera.Core
1908
1909**参数:**
1910
1911| 参数名      | 类型                  | 必填 | 说明                                  |
1912| -------- | -------------------- | ---- | ------------------------------------- |
1913| type     | string               | 是   | 监听事件,固定为'frameEnd',previewOutput创建成功可监听。 |
1914| callback | AsyncCallback\<void\> | 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
1915
1916**示例:**
1917
1918```ts
1919function unregisterPreviewOutputFrameEnd(previewOutput: camera.PreviewOutput): void {
1920  previewOutput.off('frameEnd');
1921}
1922```
1923
1924### on('error')
1925
1926on(type: 'error', callback: ErrorCallback): void
1927
1928监听预览输出的错误事件,通过注册回调函数获取结果。使用callback异步回调。
1929
1930> **说明:**
1931>
1932> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
1933
1934**系统能力:** SystemCapability.Multimedia.Camera.Core
1935
1936**参数:**
1937
1938| 参数名     | 类型         | 必填 | 说明                       |
1939| -------- | --------------| ---- | ------------------------ |
1940| type     | string        | 是   | 监听事件,固定为'error',previewOutput创建成功可监听。预览接口使用错误时触发该事件,比如调用[Session.start](#start11-1),[CameraOutput.release](#release-1)等接口发生错误时返回对应错误信息。 |
1941| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | 是   | 回调函数,用于获取错误信息。返回错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。  |
1942
1943**示例:**
1944
1945```ts
1946import { BusinessError } from '@kit.BasicServicesKit';
1947
1948function callback(previewOutputError: BusinessError): void {
1949  console.error(`Preview output error code: ${previewOutputError.code}`);
1950}
1951
1952function registerPreviewOutputError(previewOutput: camera.PreviewOutput): void {
1953  previewOutput.on('error', callback)
1954}
1955```
1956
1957### off('error')
1958
1959off(type: 'error', callback?: ErrorCallback): void
1960
1961注销监听预览输出的错误事件。
1962
1963**系统能力:** SystemCapability.Multimedia.Camera.Core
1964
1965**参数:**
1966
1967| 参数名     | 类型         | 必填 | 说明                       |
1968| -------- | --------------| ---- | ------------------------ |
1969| type     | string        | 是   | 监听事件,固定为'error',previewOutput创建成功可监听。 |
1970| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
1971
1972**示例:**
1973
1974```ts
1975function unregisterPreviewOutputError(previewOutput: camera.PreviewOutput): void {
1976  previewOutput.off('error');
1977}
1978```
1979
1980### getSupportedFrameRates<sup>12+</sup>
1981
1982 getSupportedFrameRates(): Array\<FrameRateRange\>
1983
1984查询支持的帧率范围。
1985
1986**系统能力:** SystemCapability.Multimedia.Camera.Core
1987
1988**返回值:**
1989|      类型      |     说明     |
1990| -------------  | ------------ |
1991| Array<[FrameRateRange](#frameraterange)> | 支持的帧率范围列表 |
1992
1993**示例:**
1994
1995```ts
1996function getSupportedFrameRates(previewOutput: camera.PreviewOutput): Array<camera.FrameRateRange> {
1997  let supportedFrameRatesArray: Array<camera.FrameRateRange> = previewOutput.getSupportedFrameRates();
1998  return supportedFrameRatesArray;
1999}
2000```
2001
2002### setFrameRate<sup>12+</sup>
2003
2004setFrameRate(minFps: number, maxFps: number): void
2005
2006设置预览流帧率范围,设置的范围必须在支持的帧率范围内。
2007进行设置前,可通过[getSupportedFrameRates](#getsupportedframerates12)查询支持的帧率范围。
2008
2009> **说明:**
2010> 仅在[PhotoSession](#photosession11)或[VideoSession](#videosession11)模式下支持。
2011
2012**系统能力:** SystemCapability.Multimedia.Camera.Core
2013
2014**参数:**
2015
2016| 参数名     | 类型         | 必填 | 说明                       |
2017| -------- | --------------| ---- | ------------------------ |
2018| minFps   | number        | 是   | 最小帧率。 |
2019| maxFps   | number        | 是   | 最大帧率,当传入的最小值大于最大值时,传参异常,接口不生效。|
2020
2021**错误码:**
2022
2023以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
2024
2025| 错误码ID        | 错误信息        |
2026| --------------- | --------------- |
2027| 7400101                |  Parameter missing or parameter type incorrect.        |
2028| 7400110                |  Unresolved conflicts with current configurations.     |
2029
2030**示例:**
2031
2032```ts
2033function setFrameRateRange(previewOutput: camera.PreviewOutput, frameRateRange: Array<number>): void {
2034  previewOutput.setFrameRate(frameRateRange[0], frameRateRange[1]);
2035}
2036```
2037
2038### getActiveFrameRate<sup>12+</sup>
2039
2040getActiveFrameRate(): FrameRateRange
2041
2042获取已设置的帧率范围。
2043
2044使用[setFrameRate](#setframerate12)对预览流设置过帧率后可查询。
2045
2046**系统能力:** SystemCapability.Multimedia.Camera.Core
2047
2048**返回值:**
2049
2050|      类型      |     说明     |
2051| -------------  | ------------ |
2052| [FrameRateRange](#frameraterange) | 帧率范围 |
2053
2054**示例:**
2055
2056```ts
2057function getActiveFrameRate(previewOutput: camera.PreviewOutput): camera.FrameRateRange {
2058  let activeFrameRate: camera.FrameRateRange = previewOutput.getActiveFrameRate();
2059  return activeFrameRate;
2060}
2061```
2062
2063### getActiveProfile<sup>12+</sup>
2064
2065getActiveProfile(): Profile
2066
2067获取当前生效的配置信息。
2068
2069**系统能力:** SystemCapability.Multimedia.Camera.Core
2070
2071**返回值:**
2072
2073|      类型      | 说明        |
2074| -------------  |-----------|
2075| [Profile](#profile) | 当前生效的配置信息 |
2076
2077**错误码:**
2078
2079以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
2080
2081| 错误码ID   | 错误信息                         |
2082|---------|------------------------------|
2083| 7400201 | Camera service fatal error.  |
2084
2085**示例:**
2086
2087```ts
2088function testGetActiveProfile(previewOutput: camera.PreviewOutput): camera.Profile | undefined {
2089  let activeProfile: camera.Profile | undefined = undefined;
2090  try {
2091    activeProfile = previewOutput.getActiveProfile();
2092  } catch (error) {
2093    // 失败返回错误码error.code并处理
2094    let err = error as BusinessError;
2095    console.error(`The previewOutput.getActiveProfile call failed. error code: ${err.code}`);
2096  }
2097  return activeProfile;
2098}
2099```
2100
2101### getPreviewRotation<sup>12+</sup>
2102
2103getPreviewRotation(displayRotation: number): ImageRotation
2104
2105获取预览旋转角度。
2106
2107- 设备自然方向:设备默认使用方向,手机为竖屏(充电口向下)。
2108- 相机镜头角度:值等于相机图像顺时针旋转到设备自然方向的角度,手机后置相机传感器是横屏安装的,所以需要顺时针旋转90度到设备自然方向。
2109- 屏幕显示方向:需要屏幕显示的图片左上角为第一个像素点为坐标原点。锁屏时与自然方向一致。
2110
2111**系统能力:** SystemCapability.Multimedia.Camera.Core
2112
2113**参数:**
2114
2115| 参数名     | 类型         | 必填 | 说明                       |
2116| -------- | --------------| ---- | ------------------------ |
2117| displayRotation | number  | 是   | 显示设备的屏幕旋转角度,通过[display.getDefaultDisplaySync](../apis-arkui/js-apis-display.md#displaygetdefaultdisplaysync9)获得。 |
2118
2119**返回值:**
2120
2121|      类型      | 说明        |
2122| -------------  |-----------|
2123| [ImageRotation](#imagerotation) | 获取预览旋转角度。 |
2124
2125**错误码:**
2126
2127以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
2128
2129| 错误码ID   | 错误信息                         |
2130|---------|------------------------------|
2131| 7400101 | Parameter missing or parameter type incorrect.  |
2132| 7400201 | Camera service fatal error.  |
2133
2134**示例:**
2135
2136```ts
2137function testGetPreviewRotation(previewOutput: camera.PreviewOutput, imageRotation : camera.ImageRotation): camera.ImageRotation {
2138  let previewRotation: camera.ImageRotation = camera.ImageRotation.ROTATION_0;
2139  try {
2140    previewRotation = previewOutput.getPreviewRotation(imageRotation);
2141    console.log(`Preview rotation is: ${previewRotation}`);
2142  } catch (error) {
2143    // 失败返回错误码error.code并处理
2144    let err = error as BusinessError;
2145    console.error(`The previewOutput.getPreviewRotation call failed. error code: ${err.code}`);
2146  }
2147  return previewRotation;
2148}
2149```
2150### setPreviewRotation<sup>12+</sup>
2151setPreviewRotation(previewRotation: ImageRotation, isDisplayLocked?: boolean): void
2152
2153设置预览旋转角度。
2154
2155**系统能力:** SystemCapability.Multimedia.Camera.Core
2156
2157**参数:**
2158
2159| 参数名     | 类型         | 必填 | 说明                       |
2160| -------- | --------------| ---- | ------------------------ |
2161| previewRotation | [ImageRotation](#imagerotation)  | 是   | 预览旋转角度 |
2162| isDisplayLocked | boolean  | 否   | 是否旋转锁定 |
2163
2164**错误码:**
2165
2166以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
2167
2168| 错误码ID   | 错误信息                         |
2169|---------|------------------------------|
2170| 7400101 | Parameter missing or parameter type incorrect.  |
2171| 7400201 | Camera service fatal error.  |
2172
2173**示例:**
2174
2175```ts
2176function testSetPreviewRotation(previewOutput: camera.PreviewOutput, previewRotation : camera.ImageRotation, isDisplayLocked: boolean): void {
2177  try {
2178    previewOutput.setPreviewRotation(previewRotation, isDisplayLocked);
2179  } catch (error) {
2180    // 失败返回错误码error.code并处理
2181    let err = error as BusinessError;
2182    console.error(`The previewOutput.setPreviewRotation call failed. error code: ${err.code}`);
2183  }
2184  return;
2185}
2186```
2187## ImageRotation
2188
2189枚举,图片旋转角度。
2190
2191**系统能力:** SystemCapability.Multimedia.Camera.Core
2192
2193| 名称          | 值   | 说明           |
2194| ------------ | ---- | ------------- |
2195| ROTATION_0   | 0    | 图片旋转0度。   |
2196| ROTATION_90  | 90   | 图片旋转90度。  |
2197| ROTATION_180 | 180  | 图片旋转180度。 |
2198| ROTATION_270 | 270  | 图片旋转270度。 |
2199
2200## Location
2201
2202图片地理位置信息。
2203
2204**系统能力:** SystemCapability.Multimedia.Camera.Core
2205
2206| 名称          | 类型   | 只读 | 可选  |说明         |
2207| ------------ | ------ | ---- |-----|------------ |
2208| latitude     | number |  否  | 否   |纬度(度)。    |
2209| longitude    | number |  否  | 否   |经度(度)。    |
2210| altitude     | number |  否  | 否   |海拔(米)。    |
2211
2212## QualityLevel
2213
2214枚举,图片质量。
2215
2216**系统能力:** SystemCapability.Multimedia.Camera.Core
2217
2218| 名称                  | 值   | 说明         |
2219| -------------------- | ---- | ------------ |
2220| QUALITY_LEVEL_HIGH   | 0    | 图片质量高。   |
2221| QUALITY_LEVEL_MEDIUM | 1    | 图片质量中等。 |
2222| QUALITY_LEVEL_LOW    | 2    | 图片质量差。   |
2223
2224
2225## PhotoCaptureSetting
2226
2227拍摄照片的设置。
2228
2229**系统能力:** SystemCapability.Multimedia.Camera.Core
2230
2231| 名称      | 类型                            | 只读 | 可选 | 说明                                                                   |
2232| -------- | ------------------------------- | ---- | ---- |----------------------------------------------------------------------|
2233| quality  | [QualityLevel](#qualitylevel)   | 否   | 是   | 图片质量(默认低)。                                                           |
2234| rotation | [ImageRotation](#imagerotation) | 否   | 是   | 图片旋转角度(默认0度,顺时针旋转)。                                                  |
2235| location | [Location](#location)           | 否   | 是   | 图片地理位置信息(默认以设备硬件信息为准)。                                               |
2236| mirror   | boolean                         | 否   | 是   | 镜像使能开关(默认关)。使用之前需要使用[isMirrorSupported](#ismirrorsupported)进行判断是否支持。 |
2237
2238## Photo<sup>11+</sup>
2239
2240全质量图对象。
2241
2242### 属性
2243
2244**系统能力:** SystemCapability.Multimedia.Camera.Core
2245
2246| 名称   | 类型                            |     必填     | 说明       |
2247| ------ | ----------------------------- | -------------- | ---------- |
2248| main<sup>11+</sup> | [image.Image](../apis-image-kit/js-apis-image.md#image9) |        是       | 全质量图Image。 |
2249
2250### release<sup>11+</sup>
2251
2252release(): Promise\<void\>
2253
2254释放输出资源,通过Promise获取结果。
2255
2256**系统能力:** SystemCapability.Multimedia.Camera.Core
2257
2258**返回值:**
2259
2260| 类型            | 说明                     |
2261| -------------- | ----------------------- |
2262| Promise\<void\> | 无返回结果的Promise对象。 |
2263
2264**示例:**
2265
2266```ts
2267async function releasePhoto(photo: camera.Photo): Promise<void> {
2268  await photo.release();
2269}
2270```
2271
2272## PhotoOutput
2273
2274拍照会话中使用的输出信息,继承[CameraOutput](#cameraoutput)。
2275
2276### capture
2277
2278capture(callback: AsyncCallback\<void\>): void
2279
2280以默认设置触发一次拍照,通过注册回调函数获取结果。使用callback异步回调。
2281
2282**系统能力:** SystemCapability.Multimedia.Camera.Core
2283
2284**参数:**
2285
2286| 参数名      | 类型                  | 必填 | 说明                 |
2287| -------- | -------------------- | ---- | ------------------- |
2288| callback | AsyncCallback\<void\> | 是   | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
2289
2290**错误码:**
2291
2292以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
2293
2294| 错误码ID         | 错误信息        |
2295| --------------- | --------------- |
2296| 7400104                |  Session not running.                                  |
2297| 7400201                |  Camera service fatal error.                           |
2298
2299**示例:**
2300
2301```ts
2302import { BusinessError } from '@kit.BasicServicesKit';
2303
2304function capture(photoOutput: camera.PhotoOutput): void {
2305  photoOutput.capture((err: BusinessError) => {
2306    if (err) {
2307      console.error(`Failed to capture the photo, error code: ${err.code}.`);
2308      return;
2309    }
2310    console.info('Callback invoked to indicate the photo capture request success.');
2311  });
2312}
2313```
2314
2315### capture
2316
2317capture(): Promise\<void\>
2318
2319以默认设置触发一次拍照,通过Promise获取结果。
2320
2321**系统能力:** SystemCapability.Multimedia.Camera.Core
2322
2323**返回值:**
2324
2325| 类型            | 说明                     |
2326| -------------- | ------------------------ |
2327| Promise\<void\> | 无返回结果的Promise对象。 |
2328
2329**错误码:**
2330
2331以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
2332
2333| 错误码ID         | 错误信息        |
2334| --------------- | --------------- |
2335| 7400104                |  Session not running.                                  |
2336| 7400201                |  Camera service fatal error.                           |
2337
2338**示例:**
2339
2340```ts
2341import { BusinessError } from '@kit.BasicServicesKit';
2342
2343function capture(photoOutput: camera.PhotoOutput): void {
2344  photoOutput.capture().then(() => {
2345    console.info('Promise returned to indicate that photo capture request success.');
2346  }).catch((error: BusinessError) => {
2347    console.error(`Failed to photo output capture, error code: ${error.code}.`);
2348  });
2349}
2350```
2351
2352### capture
2353
2354capture(setting: PhotoCaptureSetting, callback: AsyncCallback\<void\>): void
2355
2356以指定参数触发一次拍照,通过注册回调函数获取结果。使用callback异步回调。
2357
2358**系统能力:** SystemCapability.Multimedia.Camera.Core
2359
2360**参数:**
2361
2362| 参数名      | 类型                                         | 必填 | 说明                  |
2363| -------- | ------------------------------------------- | ---- | -------------------- |
2364| setting  | [PhotoCaptureSetting](#photocapturesetting) | 是   | 拍照设置。             |
2365| callback | AsyncCallback\<void\>                        | 是   | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。  |
2366
2367**错误码:**
2368
2369以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
2370
2371| 错误码ID         | 错误信息        |
2372| --------------- | --------------- |
2373| 7400101                |  Parameter missing or parameter type incorrect.        |
2374| 7400104                |  Session not running.                                  |
2375| 7400201                |  Camera service fatal error.                           |
2376
2377**示例:**
2378
2379```ts
2380import { BusinessError } from '@kit.BasicServicesKit';
2381
2382function capture(photoOutput: camera.PhotoOutput): void {
2383  let captureLocation: camera.Location = {
2384    latitude: 0,
2385    longitude: 0,
2386    altitude: 0
2387  }
2388  let settings: camera.PhotoCaptureSetting = {
2389    quality: camera.QualityLevel.QUALITY_LEVEL_LOW,
2390    rotation: camera.ImageRotation.ROTATION_0,
2391    location: captureLocation,
2392    mirror: false
2393  }
2394  photoOutput.capture(settings, (err: BusinessError) => {
2395    if (err) {
2396      console.error(`Failed to capture the photo, error code: ${err.code}.`);
2397      return;
2398    }
2399    console.info('Callback invoked to indicate the photo capture request success.');
2400  });
2401}
2402```
2403
2404### capture
2405
2406capture(setting: PhotoCaptureSetting): Promise\<void\>
2407
2408以指定参数触发一次拍照,通过Promise获取结果。
2409
2410**系统能力:** SystemCapability.Multimedia.Camera.Core
2411
2412**参数:**
2413
2414| 参数名     | 类型                                         | 必填 | 说明      |
2415| ------- | ------------------------------------------- | ---- | -------- |
2416| setting | [PhotoCaptureSetting](#photocapturesetting) | 是   | 拍照设置,传入undefined类型数据按默认无参处理。 |
2417
2418**返回值:**
2419
2420| 类型            | 说明                     |
2421| -------------- | ------------------------ |
2422| Promise\<void\> | 无返回结果的Promise对象。 |
2423
2424**错误码:**
2425
2426以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
2427
2428| 错误码ID         | 错误信息        |
2429| --------------- | --------------- |
2430| 7400101                |  Parameter missing or parameter type incorrect.        |
2431| 7400104                |  Session not running.                                  |
2432| 7400201                |  Camera service fatal error.                           |
2433
2434**示例:**
2435
2436```ts
2437import { BusinessError } from '@kit.BasicServicesKit';
2438
2439function capture(photoOutput: camera.PhotoOutput): void {
2440  let captureLocation: camera.Location = {
2441    latitude: 0,
2442    longitude: 0,
2443    altitude: 0
2444  }
2445  let settings: camera.PhotoCaptureSetting = {
2446    quality: camera.QualityLevel.QUALITY_LEVEL_LOW,
2447    rotation: camera.ImageRotation.ROTATION_0,
2448    location: captureLocation,
2449    mirror: false
2450  }
2451  photoOutput.capture(settings).then(() => {
2452    console.info('Promise returned to indicate that photo capture request success.');
2453  }).catch((error: BusinessError) => {
2454    console.error(`Failed to photo output capture, error code: ${error.code}.`);
2455  });
2456}
2457```
2458
2459### on('photoAvailable')<sup>11+</sup>
2460
2461on(type: 'photoAvailable', callback: AsyncCallback\<Photo\>): void
2462
2463注册监听全质量图上报。使用callback异步回调。
2464
2465> **说明:**
2466>
2467> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
2468
2469**系统能力:** SystemCapability.Multimedia.Camera.Core
2470
2471**参数:**
2472
2473| 参数名     | 类型      | 必填 | 说明                                  |
2474| -------- | ---------- | --- | ------------------------------------ |
2475| type     | string     | 是   | 监听事件,固定为'photoAvailable',photoOutput创建成功后可监听。 |
2476| callback | AsyncCallback\<[Photo](#photo11)\> | 是   | 回调函数,用于监听全质量图上报。 |
2477
2478**示例:**
2479
2480```ts
2481import { BusinessError } from '@kit.BasicServicesKit';
2482import { image } from '@kit.ImageKit';
2483
2484function callback(err: BusinessError, photo: camera.Photo): void {
2485  if (err !== undefined && err.code !== 0) {
2486    console.error(`Callback Error, errorCode: ${err.code}`);
2487    return;
2488  }
2489  let mainImage: image.Image = photo.main;
2490}
2491
2492function registerPhotoOutputPhotoAvailable(photoOutput: camera.PhotoOutput): void {
2493  photoOutput.on('photoAvailable', callback);
2494}
2495```
2496
2497### off('photoAvailable')<sup>11+</sup>
2498
2499off(type: 'photoAvailable', callback?: AsyncCallback\<Photo\>): void
2500
2501注销监听全质量图上报。
2502
2503**系统能力:** SystemCapability.Multimedia.Camera.Core
2504
2505**参数:**
2506
2507| 参数名      | 类型                    | 必填 | 说明                                       |
2508| -------- | ---------------------- | ---- | ------------------------------------------ |
2509| type     | string                 | 是   | 监听事件,固定为'photoAvailable',photoOutput创建成功后可监听。 |
2510| callback | AsyncCallback\<[Photo](#photo11)\> | 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
2511
2512**示例:**
2513
2514```ts
2515import { BusinessError } from '@kit.BasicServicesKit';
2516import { image } from '@kit.ImageKit';
2517
2518function callback(err: BusinessError, photo: camera.Photo): void {
2519  if (err !== undefined && err.code !== 0) {
2520    console.error(`Callback Error, errorCode: ${err.code}`);
2521    return;
2522  }
2523  let mainImage: image.Image = photo.main;
2524}
2525
2526function unRegisterPhotoOutputPhotoAvailable(photoOutput: camera.PhotoOutput): void {
2527  photoOutput.off('photoAvailable', callback);
2528}
2529```
2530
2531### on('captureStartWithInfo')<sup>11+</sup>
2532
2533on(type: 'captureStartWithInfo', callback: AsyncCallback\<CaptureStartInfo\>): void
2534
2535监听拍照开始,通过注册回调函数获取[CaptureStartInfo](#capturestartinfo11)。使用callback异步回调。
2536
2537> **说明:**
2538>
2539> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
2540
2541**系统能力:** SystemCapability.Multimedia.Camera.Core
2542
2543**参数:**
2544
2545| 参数名     | 类型      | 必填 | 说明                                  |
2546| -------- | ---------- | --- | ------------------------------------ |
2547| type     | string     | 是   | 监听事件,固定为'captureStartWithInfo',photoOutput创建成功后可监听。 |
2548| callback | AsyncCallback\<[CaptureStartInfo](#capturestartinfo11)\> | 是   | 使用callback的方式获取Capture ID。|
2549
2550**示例:**
2551
2552```ts
2553import { BusinessError } from '@kit.BasicServicesKit';
2554
2555function callback(err: BusinessError, captureStartInfo: camera.CaptureStartInfo): void {
2556  if (err !== undefined && err.code !== 0) {
2557    console.error(`Callback Error, errorCode: ${err.code}`);
2558    return;
2559  }
2560  console.info(`photo capture started, captureStartInfo : ${captureStartInfo}`);
2561}
2562
2563function registerCaptureStartWithInfo(photoOutput: camera.PhotoOutput): void {
2564  photoOutput.on('captureStartWithInfo', callback);
2565}
2566```
2567
2568### off('captureStartWithInfo')<sup>11+</sup>
2569
2570off(type: 'captureStartWithInfo', callback?: AsyncCallback\<CaptureStartInfo\>): void
2571
2572注销监听拍照。
2573
2574**系统能力:** SystemCapability.Multimedia.Camera.Core
2575
2576**参数:**
2577
2578| 参数名      | 类型                    | 必填 | 说明                                       |
2579| -------- | ---------------------- | ---- | ------------------------------------------ |
2580| type     | string                 | 是   | 监听事件,固定为'captureStartWithInfo',photoOutput创建成功后可监听。 |
2581| callback | AsyncCallback\<[CaptureStartInfo](#capturestartinfo11)\> | 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
2582
2583**示例:**
2584
2585```ts
2586import { BusinessError } from '@kit.BasicServicesKit';
2587
2588function unRegisterCaptureStartWithInfo(photoOutput: camera.PhotoOutput): void {
2589  photoOutput.off('captureStartWithInfo');
2590}
2591```
2592
2593### isMovingPhotoSupported<sup>12+</sup>
2594
2595isMovingPhotoSupported(): boolean
2596
2597查询是否支持动态照片拍摄。
2598
2599**系统能力:** SystemCapability.Multimedia.Camera.Core
2600
2601**返回值:**
2602
2603| 类型            | 说明                     |
2604| -------------- | ----------------------- |
2605| boolean | 返回是否支持动态照片拍照,true表示支持,false表示不支持。 |
2606
2607**错误码:**
2608
2609以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
2610
2611| 错误码ID       | 错误信息       |
2612| -------------- | --------------- |
2613| 7400201 |  Camera service fatal error. |
2614
2615**示例:**
2616
2617```ts
2618import { BusinessError } from '@kit.BasicServicesKit';
2619
2620function isMovingPhotoSupported(photoOutput: camera.PhotoOutput): boolean {
2621  let isSupported: boolean = false;
2622  try {
2623    isSupported = photoOutput.isMovingPhotoSupported();
2624  } catch (error) {
2625    // 失败返回错误码error.code并处理
2626    let err = error as BusinessError;
2627    console.error(`The isMovingPhotoSupported call failed. error code: ${err.code}`);
2628  }
2629  return isSupported;
2630}
2631```
2632
2633### enableMovingPhoto<sup>12+</sup>
2634
2635enableMovingPhoto(enabled: boolean): void
2636
2637使能动态照片拍照。
2638
2639**需要权限:** ohos.permission.MICROPHONE
2640
2641**系统能力:** SystemCapability.Multimedia.Camera.Core
2642
2643**参数:**
2644
2645| 参数名      | 类型                    | 必填 | 说明                                       |
2646| -------- | ---------------------- | ---- | ------------------------------------------ |
2647| enabled  | boolean                | 是   | true为开启动态照片,false为关闭动态照片。     |
2648
2649**错误码:**
2650
2651以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
2652
2653| 错误码ID    | 错误信息                                           |
2654| -------- |------------------------------------------------|
2655| 201      | permission denied.                             |
2656| 7400101  | Parameter missing or parameter type incorrect. |
2657| 7400201  | Camera service fatal error.                    |
2658
2659**示例:**
2660
2661```ts
2662import { BusinessError } from '@kit.BasicServicesKit';
2663
2664function enableMovingPhoto(photoOutput: camera.PhotoOutput): void {
2665  try {
2666    photoOutput.enableMovingPhoto(true);
2667  } catch (error) {
2668    // 失败返回错误码error.code并处理
2669    let err = error as BusinessError;
2670    console.error(`The enableMovingPhoto call failed. error code: ${err.code}`);
2671  }
2672}
2673```
2674
2675### on('photoAssetAvailable')<sup>12+</sup>
2676
2677on(type: 'photoAssetAvailable', callback: AsyncCallback\<photoAccessHelper.PhotoAsset\>): void
2678
2679注册监听photoAsset上报。使用callback异步回调。
2680
2681> **说明:**
2682>
2683> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
2684
2685**系统能力:** SystemCapability.Multimedia.Camera.Core
2686
2687**参数:**
2688
2689| 参数名     | 类型      | 必填 | 说明                                  |
2690| -------- | ---------- | --- | ------------------------------------ |
2691| type     | string     | 是   | 监听事件,固定为'photoAssetAvailable',photoOutput创建成功后可监听。 |
2692| callback | AsyncCallback\<[photoAccessHelper.PhotoAsset](../apis-media-library-kit/js-apis-photoAccessHelper.md#photoasset)\> | 是   | 回调函数,用于监听photoAsset上报。 |
2693
2694**示例:**
2695
2696```ts
2697import { BusinessError } from '@kit.BasicServicesKit';
2698import { photoAccessHelper } from '@kit.MediaLibraryKit';
2699
2700function photoAssetAvailableCallback(err: BusinessError, photoAsset: photoAccessHelper.PhotoAsset): void {
2701  if (err) {
2702    console.info(`photoAssetAvailable error: ${JSON.stringify(err)}.`);
2703    return;
2704  }
2705  console.info('photoOutPutCallBack photoAssetAvailable');
2706  // 开发者可通过photoAsset获取图片相关信息
2707}
2708
2709function onPhotoOutputPhotoAssetAvailable(photoOutput: camera.PhotoOutput): void {
2710  photoOutput.on('photoAssetAvailable', photoAssetAvailableCallback);
2711}
2712```
2713
2714### off('photoAssetAvailable')<sup>12+</sup>
2715
2716off(type: 'photoAssetAvailable', callback?: AsyncCallback\<photoAccessHelper.PhotoAsset\>): void
2717
2718解注册photoAsset上报。
2719
2720**系统能力:** SystemCapability.Multimedia.Camera.Core
2721
2722**参数:**
2723
2724| 参数名     | 类型      | 必填  | 说明                                                                         |
2725| -------- | ---------- |-----|----------------------------------------------------------------------------|
2726| type     | string     | 是   | 监听事件,固定为'photoAssetAvailable',photoOutput创建成功后可监听。                         |
2727| callback | AsyncCallback\<[photoAccessHelper.PhotoAsset](../apis-media-library-kit/js-apis-photoAccessHelper.md#photoasset)\> | 否   | 需要解监听的回调方法。如果callback不为空且与此对应的监听方法一致,不为匿名方法,则解注册该方法;如果callback为空,则解监听所有回调。 |
2728
2729**示例:**
2730
2731```ts
2732function offPhotoOutputPhotoAssetAvailable(photoOutput: camera.PhotoOutput): void {
2733  photoOutput.off('photoAssetAvailable');
2734}
2735```
2736
2737### isMirrorSupported
2738
2739isMirrorSupported(): boolean
2740
2741查询是否支持镜像拍照。
2742
2743**系统能力:** SystemCapability.Multimedia.Camera.Core
2744
2745**返回值:**
2746
2747| 类型            | 说明                     |
2748| -------------- | ----------------------- |
2749| boolean | 返回是否支持镜像拍照,true表示支持,false表示不支持。 |
2750
2751**示例:**
2752
2753```ts
2754function isMirrorSupported(photoOutput: camera.PhotoOutput): boolean {
2755  let isSupported: boolean = photoOutput.isMirrorSupported();
2756  return isSupported;
2757}
2758```
2759
2760### enableMirror<sup>13+</sup>
2761
2762enableMirror(enabled: boolean): void
2763
2764是否启用镜像拍照。
2765
2766**系统能力:** SystemCapability.Multimedia.Camera.Core
2767
2768**参数:**
2769
2770| 参数名      | 类型                    | 必填 | 说明                        |
2771|----------| ---------------------- | ---- |---------------------------|
2772| enabled | boolean                | 是   | true为开启镜像拍照,false为关闭镜像拍照。 |
2773
2774**错误码:**
2775
2776以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
2777
2778| 错误码ID    | 错误信息                                           |
2779| -------- |------------------------------------------------|
2780| 7400101  | Parameter missing or parameter type incorrect. |
2781| 7400103  | Session not config.                    |
2782| 7400201  | Camera service fatal error.            |
2783
2784
2785**示例:**
2786
2787```ts
2788import { BusinessError } from '@kit.BasicServicesKit';
2789
2790function enableMirror(photoOutput: camera.PhotoOutput): void {
2791  try {
2792    photoOutput.enableMirror(true);
2793  } catch (error) {
2794    // 失败返回错误码error.code并处理
2795    let err = error as BusinessError;
2796    console.error(`The enableMirror call failed. error code: ${err.code}`);
2797  }
2798}
2799```
2800
2801### getSupportedMovingPhotoVideoCodecTypes<sup>13+</sup>
2802
2803getSupportedMovingPhotoVideoCodecTypes(): Array\<VideoCodecType\>
2804
2805查询支持的动态照片短视频编码类型。
2806
2807**系统能力:** SystemCapability.Multimedia.Camera.Core
2808
2809**返回值:**
2810
2811| 类型            | 说明                |
2812| -------------- |-------------------|
2813| Array\<[VideoCodecType](#videocodectype13)\> | 支持的动态照片短视频编码类型列表。 |
2814
2815**错误码:**
2816
2817以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
2818
2819| 错误码ID        | 错误信息                      |
2820| --------------- | ---------------               |
2821| 7400201         |  Camera service fatal error.  |
2822
2823**示例:**
2824
2825```ts
2826function getSupportedMovingPhotoVideoCodecType(photoOutput: camera.PhotoOutput): Array<camera.VideoCodecType> {
2827  let supportedVideoCodecTypesArray: Array<camera.VideoCodecType> = photoOutput.getSupportedMovingPhotoVideoCodecTypes();
2828  return supportedVideoCodecTypesArray;
2829}
2830```
2831
2832### setMovingPhotoVideoCodecType<sup>13+</sup>
2833
2834setMovingPhotoVideoCodecType(codecType: VideoCodecType): void
2835
2836设置动态照片短视频编码类型。
2837
2838**系统能力:** SystemCapability.Multimedia.Camera.Core
2839
2840**参数:**
2841
2842| 参数名        | 类型                                  | 必填 |  说明                |
2843| ------------- |-------------------------------------|-------| ------------        |
2844| codecType     | [VideoCodecType](#videocodectype13) |  是    |获取动态照片短视频编码类型  |
2845
2846**错误码:**
2847
2848以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
2849
2850| 错误码ID        | 错误信息                      |
2851| --------------- | ---------------               |
2852| 7400201         |  Camera service fatal error.  |
2853
2854**示例:**
2855
2856```ts
2857function setMovingPhotoVideoCodecTypes(photoOutput: camera.PhotoOutput, videoCodecType: camera.VideoCodecType): void {
2858   photoOutput.setMovingPhotoVideoCodecType(videoCodecType);
2859}
2860```
2861
2862### on('captureStart')<sup>(deprecated)</sup>
2863
2864on(type: 'captureStart', callback: AsyncCallback\<number\>): void
2865
2866监听拍照开始,通过注册回调函数获取Capture ID。使用callback异步回调。
2867
2868> **说明:**
2869> 从 API version 10开始支持,从API version 11开始废弃。建议使用[on('captureStartWithInfo')](#oncapturestartwithinfo11)替代。
2870>
2871> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
2872
2873**系统能力:** SystemCapability.Multimedia.Camera.Core
2874
2875**参数:**
2876
2877| 参数名      | 类型                    | 必填 | 说明                                       |
2878| -------- | ---------------------- | ---- | ------------------------------------------ |
2879| type     | string                 | 是   | 监听事件,固定为'captureStart',photoOutput创建成功后可监听。每次拍照,底层开始曝光时触发该事件并返回。 |
2880| callback | AsyncCallback\<number\> | 是   | 使用callback的方式获取Capture ID。            |
2881
2882**示例:**
2883
2884```ts
2885import { BusinessError } from '@kit.BasicServicesKit';
2886
2887function callback(err: BusinessError, captureId: number): void {
2888  if (err !== undefined && err.code !== 0) {
2889    console.error(`Callback Error, errorCode: ${err.code}`);
2890    return;
2891  }
2892  console.info(`photo capture started, captureId : ${captureId}`);
2893}
2894
2895function registerPhotoOutputCaptureStart(photoOutput: camera.PhotoOutput): void {
2896  photoOutput.on('captureStart', callback);
2897}
2898```
2899
2900### off('captureStart')<sup>(deprecated)</sup>
2901
2902off(type: 'captureStart', callback?: AsyncCallback\<number\>): void
2903
2904注销监听拍照开始。
2905
2906> **说明:**
2907> 从 API version 10开始支持,从API version 11开始废弃。建议使用[off('captureStartWithInfo')](#offcapturestartwithinfo11)替代。
2908>
2909> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
2910
2911**系统能力:** SystemCapability.Multimedia.Camera.Core
2912
2913**参数:**
2914
2915| 参数名      | 类型                    | 必填 | 说明                                       |
2916| -------- | ---------------------- | ---- | ------------------------------------------ |
2917| type     | string                 | 是   | 监听事件,固定为'captureStart',photoOutput创建成功后可监听。 |
2918| callback | AsyncCallback\<number\> | 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
2919
2920**示例:**
2921
2922```ts
2923function unregisterPhotoOutputCaptureStart(photoOutput: camera.PhotoOutput): void {
2924  photoOutput.off('captureStart');
2925}
2926```
2927
2928### on('frameShutter')
2929
2930on(type: 'frameShutter', callback: AsyncCallback\<FrameShutterInfo\>): void
2931
2932监听拍照帧输出捕获,通过注册回调函数获取结果。使用callback异步回调。
2933
2934**系统能力:** SystemCapability.Multimedia.Camera.Core
2935
2936**参数:**
2937
2938| 参数名     | 类型      | 必填 | 说明                                  |
2939| -------- | ---------- | --- | ------------------------------------ |
2940| type     | string     | 是   | 监听事件,固定为'frameShutter',photoOutput创建成功后可监听。 |
2941| callback | AsyncCallback\<[FrameShutterInfo](#frameshutterinfo)\> | 是   | 回调函数,用于获取相关信息。该回调返回意味着可以再次下发拍照请求。             |
2942
2943**示例:**
2944
2945```ts
2946import { BusinessError } from '@kit.BasicServicesKit';
2947
2948function callback(err: BusinessError, frameShutterInfo: camera.FrameShutterInfo): void {
2949  if (err !== undefined && err.code !== 0) {
2950    console.error(`Callback Error, errorCode: ${err.code}`);
2951    return;
2952  }
2953  console.info(`CaptureId for frame : ${frameShutterInfo.captureId}`);
2954  console.info(`Timestamp for frame : ${frameShutterInfo.timestamp}`);
2955}
2956
2957function registerPhotoOutputFrameShutter(photoOutput: camera.PhotoOutput): void {
2958  photoOutput.on('frameShutter', callback);
2959}
2960```
2961
2962### off('frameShutter')
2963
2964off(type: 'frameShutter', callback?: AsyncCallback\<FrameShutterInfo\>): void
2965
2966注销监听拍照帧输出捕获。
2967
2968**系统能力:** SystemCapability.Multimedia.Camera.Core
2969
2970**参数:**
2971
2972| 参数名     | 类型      | 必填 | 说明                                  |
2973| -------- | ---------- | --- | ------------------------------------ |
2974| type     | string     | 是   | 监听事件,固定为'frameShutter',photoOutput创建成功后可监听。 |
2975| callback | AsyncCallback\<[FrameShutterInfo](#frameshutterinfo)\> | 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
2976
2977**示例:**
2978
2979```ts
2980function unregisterPhotoOutputFrameShutter(photoOutput: camera.PhotoOutput): void {
2981  photoOutput.off('frameShutter');
2982}
2983```
2984
2985### on('captureEnd')
2986
2987on(type: 'captureEnd', callback: AsyncCallback\<CaptureEndInfo\>): void
2988
2989监听拍照结束,通过注册回调函数获取结果。使用callback异步回调。
2990
2991> **说明:**
2992>
2993> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
2994
2995**系统能力:** SystemCapability.Multimedia.Camera.Core
2996
2997**参数:**
2998
2999| 参数名     | 类型           | 必填 | 说明                                       |
3000| -------- | --------------- | ---- | ---------------------------------------- |
3001| type     | string          | 是   | 监听事件,固定为'captureEnd',photoOutput创建成功后可监听。拍照完全结束可触发该事件发生并返回相应信息。 |
3002| callback | AsyncCallback\<[CaptureEndInfo](#captureendinfo)\> | 是   | 回调函数,用于获取相关信息。                  |
3003
3004**示例:**
3005
3006```ts
3007import { BusinessError } from '@kit.BasicServicesKit';
3008
3009function callback(err: BusinessError, captureEndInfo: camera.CaptureEndInfo): void {
3010  if (err !== undefined && err.code !== 0) {
3011    console.error(`Callback Error, errorCode: ${err.code}`);
3012    return;
3013  }
3014  console.info(`photo capture end, captureId : ${captureEndInfo.captureId}`);
3015  console.info(`frameCount : ${captureEndInfo.frameCount}`);
3016}
3017
3018function registerPhotoOutputCaptureEnd(photoOutput: camera.PhotoOutput): void {
3019  photoOutput.on('captureEnd', callback);
3020}
3021```
3022
3023### off('captureEnd')
3024
3025off(type: 'captureEnd', callback?: AsyncCallback\<CaptureEndInfo\>): void
3026
3027注销监听拍照结束。
3028
3029**系统能力:** SystemCapability.Multimedia.Camera.Core
3030
3031**参数:**
3032
3033| 参数名     | 类型           | 必填 | 说明                                       |
3034| -------- | --------------- | ---- | ---------------------------------------- |
3035| type     | string          | 是   | 监听事件,固定为'captureEnd',photoOutput创建成功后可监听。 |
3036| callback | AsyncCallback\<[CaptureEndInfo](#captureendinfo)\> | 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
3037
3038**示例:**
3039
3040```ts
3041function unregisterPhotoOutputCaptureEnd(photoOutput: camera.PhotoOutput): void {
3042  photoOutput.off('captureEnd');
3043}
3044```
3045
3046### on('frameShutterEnd')<sup>12+</sup>
3047
3048on(type: 'frameShutterEnd', callback: AsyncCallback\<FrameShutterEndInfo\>): void
3049
3050监听拍照曝光结束捕获,通过注册回调函数获取结果。使用callback异步回调。
3051
3052> **说明:**
3053>
3054> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
3055
3056**系统能力:** SystemCapability.Multimedia.Camera.Core
3057
3058**参数:**
3059
3060| 参数名   | 类型                                                         | 必填 | 说明                                                         |
3061| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
3062| type     | string                                                       | 是   | 监听事件,固定为'frameShutterEnd',photoOutput创建成功后可监听。 |
3063| callback | AsyncCallback\<[FrameShutterEndInfo](#frameshutterendinfo12)\> | 是   | 回调函数,用于获取相关信息。该回调返回表示拍照曝光结束。   |
3064
3065**示例:**
3066
3067```ts
3068import { BusinessError } from '@kit.BasicServicesKit';
3069
3070function callback(err: BusinessError, frameShutterEndInfo: camera.FrameShutterEndInfo): void {
3071  if (err !== undefined && err.code !== 0) {
3072    console.error(`Callback Error, errorCode: ${err.code}`);
3073    return;
3074  }
3075  console.info(`CaptureId for frame : ${frameShutterEndInfo.captureId}`);
3076}
3077
3078function registerPhotoOutputFrameShutterEnd(photoOutput: camera.PhotoOutput): void {
3079  photoOutput.on('frameShutterEnd', callback);
3080}
3081```
3082
3083### off('frameShutterEnd')<sup>12+</sup>
3084
3085off(type: 'frameShutterEnd', callback?: AsyncCallback\<FrameShutterEndInfo\>): void
3086
3087注销监听拍照帧输出捕获。
3088
3089**系统能力:** SystemCapability.Multimedia.Camera.Core
3090
3091**参数:**
3092
3093| 参数名   | 类型                                                         | 必填 | 说明                                                         |
3094| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
3095| type     | string                                                       | 是   | 监听事件,固定为'frameShutterEnd',photoOutput创建成功后可监听。 |
3096| callback | AsyncCallback\<[FrameShutterEndInfo](#frameshutterendinfo12)\> | 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
3097
3098**示例:**
3099
3100```ts
3101function unregisterPhotoOutputFrameShutterEnd(photoOutput: camera.PhotoOutput): void {
3102  photoOutput.off('frameShutterEnd');
3103}
3104```
3105
3106### on('captureReady')<sup>12+</sup>
3107
3108on(type: 'captureReady', callback: AsyncCallback\<void\>): void
3109
3110监听可拍下一张,通过注册回调函数获取结果。使用callback异步回调。
3111
3112> **说明:**
3113>
3114> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
3115
3116**系统能力:** SystemCapability.Multimedia.Camera.Core
3117
3118**参数:**
3119
3120| 参数名   | 类型                  | 必填 | 说明                                                         |
3121| -------- | --------------------- | ---- | ------------------------------------------------------------ |
3122| type     | string                | 是   | 监听事件,固定为'captureReady',photoOutput创建成功后可监听。当下一张可拍时可触发该事件发生并返回相应信息。 |
3123| callback | AsyncCallback\<void\> | 是   | 回调函数,用于获取相关信息。                                 |
3124
3125**示例:**
3126
3127```ts
3128import { BusinessError } from '@kit.BasicServicesKit';
3129
3130function callback(err: BusinessError): void {
3131  if (err !== undefined && err.code !== 0) {
3132    console.error(`Callback Error, errorCode: ${err.code}`);
3133    return;
3134  }
3135  console.info(`photo capture ready`);
3136}
3137
3138function registerPhotoOutputCaptureReady(photoOutput: camera.PhotoOutput): void {
3139  photoOutput.on('captureReady', callback);
3140}
3141```
3142
3143### off('captureReady')<sup>12+</sup>
3144
3145off(type: 'captureReady', callback?: AsyncCallback\<void\>): void
3146
3147注销监听可拍下一张。
3148
3149**系统能力:** SystemCapability.Multimedia.Camera.Core
3150
3151**参数:**
3152
3153| 参数名   | 类型                                                 | 必填 | 说明                                                         |
3154| -------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------ |
3155| type     | string                                               | 是   | 监听事件,固定为'captureReady',photoOutput创建成功后可监听。 |
3156| callback | AsyncCallback\<[CaptureReadyInfo](#captureendinfo)\> | 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
3157
3158**示例:**
3159
3160```ts
3161function unregisterPhotoOutputCaptureReady(photoOutput: camera.PhotoOutput): void {
3162  photoOutput.off('captureReady');
3163}
3164```
3165
3166### on('estimatedCaptureDuration')<sup>12+</sup>
3167
3168on(type: 'estimatedCaptureDuration', callback: AsyncCallback\<number\>): void
3169
3170监听预估的拍照时间,通过注册回调函数获取结果。使用callback异步回调。
3171
3172> **说明:**
3173>
3174> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
3175
3176**系统能力:** SystemCapability.Multimedia.Camera.Core
3177
3178**参数:**
3179
3180| 参数名   | 类型                   | 必填 | 说明                                                         |
3181| -------- | ---------------------- | ---- | ------------------------------------------------------------ |
3182| type     | string                 | 是   | 监听事件,固定为'estimatedCaptureDuration',photoOutput创建成功后可监听。拍照完全结束可触发该事件发生并返回相应信息。 |
3183| callback | AsyncCallback\<number> | 是   | 回调函数,用于获取预估的单次拍照底层出sensor采集帧时间,如果上报-1,代表没有预估时间。                                 |
3184
3185**示例:**
3186
3187```ts
3188import { BusinessError } from '@kit.BasicServicesKit';
3189
3190function callback(err: BusinessError, duration: number): void {
3191  if (err !== undefined && err.code !== 0) {
3192    console.error(`Callback Error, errorCode: ${err.code}`);
3193    return;
3194  }
3195  console.info(`photo estimated capture duration : ${duration}`);
3196}
3197
3198function registerPhotoOutputEstimatedCaptureDuration(photoOutput: camera.PhotoOutput): void {
3199  photoOutput.on('estimatedCaptureDuration', callback);
3200}
3201```
3202
3203### off('estimatedCaptureDuration')<sup>12+</sup>
3204
3205off(type: 'estimatedCaptureDuration', callback?: AsyncCallback\<number\>): void
3206
3207注销监听预估的拍照时间。
3208
3209**系统能力:** SystemCapability.Multimedia.Camera.Core
3210
3211**参数:**
3212
3213| 参数名   | 类型                    | 必填 | 说明                                                         |
3214| -------- | ----------------------- | ---- | ------------------------------------------------------------ |
3215| type     | string                  | 是   | 监听事件,固定为'estimatedCaptureDuration',photoOutput创建成功后可监听。 |
3216| callback | AsyncCallback\<number\> | 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
3217
3218**示例:**
3219
3220```ts
3221function unregisterPhotoOutputEstimatedCaptureDuration(photoOutput: camera.PhotoOutput): void {
3222  photoOutput.off('estimatedCaptureDuration');
3223}
3224```
3225
3226### on('error')
3227
3228on(type: 'error', callback: ErrorCallback): void
3229
3230监听拍照输出发生错误,通过注册回调函数获取结果。使用callback异步回调。
3231
3232> **说明:**
3233>
3234> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
3235
3236**系统能力:** SystemCapability.Multimedia.Camera.Core
3237
3238**参数:**
3239
3240| 参数名     | 类型         | 必填 | 说明                                 |
3241| -------- | ------------- | ---- | ----------------------------------- |
3242| type     | string       | 是   | 监听事件,固定为'error',photoOutput创建成功后可监听。拍照接口调用时出现错误触发该事件并返回错误信息。 |
3243| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | 是   | 回调函数,用于获取错误信息。返回错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。             |
3244
3245**示例:**
3246
3247```ts
3248import { BusinessError } from '@kit.BasicServicesKit';
3249
3250function callback(err: BusinessError): void {
3251  console.error(`Photo output error code: ${err.code}`);
3252}
3253
3254function registerPhotoOutputError(photoOutput: camera.PhotoOutput): void {
3255  photoOutput.on('error', callback);
3256}
3257```
3258
3259### off('error')
3260
3261off(type: 'error', callback?: ErrorCallback): void
3262
3263注销监听拍照输出发生错误。
3264
3265**系统能力:** SystemCapability.Multimedia.Camera.Core
3266
3267**参数:**
3268
3269| 参数名     | 类型         | 必填 | 说明                                 |
3270| -------- | ------------- | ---- | ----------------------------------- |
3271| type     | string       | 是   | 监听事件,固定为'error',photoOutput创建成功后可监听。 |
3272| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
3273
3274**示例:**
3275
3276```ts
3277function unregisterPhotoOutputError(photoOutput: camera.PhotoOutput): void {
3278  photoOutput.off('error');
3279}
3280```
3281
3282### getActiveProfile<sup>12+</sup>
3283
3284getActiveProfile(): Profile
3285
3286获取当前生效的配置信息。
3287
3288**系统能力:** SystemCapability.Multimedia.Camera.Core
3289
3290**返回值:**
3291
3292|      类型      | 说明        |
3293| -------------  |-----------|
3294| [Profile](#profile) | 当前生效的配置信息 |
3295
3296**错误码:**
3297
3298以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
3299
3300| 错误码ID   | 错误信息                         |
3301|---------|------------------------------|
3302| 7400201 | Camera service fatal error.  |
3303
3304**示例:**
3305
3306```ts
3307function testGetActiveProfile(photoOutput: camera.PhotoOutput): camera.Profile | undefined {
3308  let activeProfile: camera.Profile | undefined = undefined;
3309  try {
3310    activeProfile = photoOutput.getActiveProfile();
3311  } catch (error) {
3312    // 失败返回错误码error.code并处理
3313    let err = error as BusinessError;
3314    console.error(`The photoOutput.getActiveProfile call failed. error code: ${err.code}`);
3315  }
3316  return activeProfile;
3317}
3318```
3319### getPhotoRotation<sup>12+</sup>
3320
3321getPhotoRotation(deviceDegree: number): ImageRotation
3322
3323获取拍照旋转角度。
3324
3325- 设备自然方向:设备默认使用方向,手机为竖屏(充电口向下)。
3326- 相机镜头角度:值等于相机图像顺时针旋转到设备自然方向的角度,手机后置相机传感器是横屏安装的,所以需要顺时针旋转90度到设备自然方向。
3327- 屏幕显示方向:需要屏幕显示的图片左上角为第一个像素点为坐标原点。锁屏时与自然方向一致。
3328
3329**系统能力:** SystemCapability.Multimedia.Camera.Core
3330
3331**参数:**
3332
3333| 参数名     | 类型         | 必填 | 说明                       |
3334| -------- | --------------| ---- | ------------------------ |
3335| deviceDegree | number | 是   | 设备旋转角度 |
3336
3337**返回值:**
3338
3339|      类型      | 说明        |
3340| -------------  |-----------|
3341| [ImageRotation](#imagerotation) | 获取拍照旋转角度。 |
3342
3343**错误码:**
3344
3345以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
3346
3347| 错误码ID   | 错误信息                         |
3348|---------|------------------------------|
3349| 7400101 | Parameter missing or parameter type incorrect.  |
3350| 7400201 | Camera service fatal error.  |
3351
3352**示例:**
3353
3354```ts
3355function testGetPhotoRotation(photoOutput: camera.PhotoOutput, deviceDegree : number): camera.ImageRotation {
3356  let photoRotation: camera.ImageRotation = camera.ImageRotation.ROTATION_0;
3357  try {
3358    photoRotation = photoOutput.getPhotoRotation(deviceDegree);
3359    console.log(`Photo rotation is: ${photoRotation}`);
3360  } catch (error) {
3361    // 失败返回错误码error.code并处理
3362    let err = error as BusinessError;
3363    console.error(`The photoOutput.getPhotoRotation call failed. error code: ${err.code}`);
3364  }
3365  return photoRotation;
3366}
3367```
3368
3369## FrameShutterInfo
3370
3371拍照帧输出信息。
3372
3373**系统能力:** SystemCapability.Multimedia.Camera.Core
3374
3375| 名称       | 类型   | 只读 | 可选 | 说明        |
3376| --------- | ------ | ---- | ---- | ---------- |
3377| captureId | number | 否   | 否   | 拍照的ID。  |
3378| timestamp | number | 否   | 否   | 快门时间戳。 |
3379
3380## FrameShutterEndInfo<sup>12+</sup>
3381
3382拍照曝光结束信息。
3383
3384**系统能力:** SystemCapability.Multimedia.Camera.Core
3385
3386| 名称      | 类型   | 只读 | 可选 | 说明       |
3387| --------- | ------ | ---- | ---- | ---------- |
3388| captureId | number | 否   | 否   | 拍照的ID。 |
3389
3390## CaptureStartInfo<sup>11+</sup>
3391
3392拍照开始信息。
3393
3394**系统能力:** SystemCapability.Multimedia.Camera.Core
3395
3396| 名称       | 类型    | 只读 | 可选 | 说明       |
3397| ---------- | ------ | ---- | ---- | --------- |
3398| captureId  | number | 否   | 否   | 拍照的ID。 |
3399| time       | number | 否   | 否   | 预估的单次拍照底层出sensor采集帧时间,如果上报-1,代表没有预估时间。    |
3400
3401## CaptureEndInfo
3402
3403拍照停止信息。
3404
3405**系统能力:** SystemCapability.Multimedia.Camera.Core
3406
3407| 名称       | 类型    | 只读 | 可选 | 说明       |
3408| ---------- | ------ | ---- | ---- | ---------|
3409| captureId  | number | 否   | 否   | 拍照的ID。 |
3410| frameCount | number | 否   | 否   | 帧数。    |
3411
3412## AutoDeviceSwitchStatus<sup>13+</sup>
3413
3414自动切换镜头状态信息。
3415
3416**系统能力:** SystemCapability.Multimedia.Camera.Core
3417
3418| 名称       | 类型      | 只读 | 可选 | 说明                      |
3419| ---------- |---------| ---- | ---- |-------------------------|
3420| isDeviceSwitched  | boolean | 否   | 否   | 自动切换镜头是否成功。             |
3421| isDeviceCapabilityChanged | boolean  | 否   | 否   | 自动切换镜头成功后,其镜头能力值是否发生改变。 |
3422
3423## VideoOutput
3424
3425录像会话中使用的输出信息,继承[CameraOutput](#cameraoutput)。
3426
3427### start
3428
3429start(callback: AsyncCallback\<void\>): void
3430
3431启动录制,通过注册回调函数获取结果。使用callback异步回调。
3432
3433**系统能力:** SystemCapability.Multimedia.Camera.Core
3434
3435**参数:**
3436
3437| 参数名      | 类型                  | 必填 | 说明                 |
3438| -------- | -------------------- | ---- | -------------------- |
3439| callback | AsyncCallback\<void\> | 是   | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
3440
3441**错误码:**
3442
3443以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
3444
3445| 错误码ID         | 错误信息        |
3446| --------------- | --------------- |
3447| 7400103                |  Session not config.                                   |
3448| 7400201                |  Camera service fatal error.                           |
3449
3450**示例:**
3451
3452```ts
3453import { BusinessError } from '@kit.BasicServicesKit';
3454
3455function startVideoOutput(videoOutput: camera.VideoOutput): void {
3456  videoOutput.start((err: BusinessError) => {
3457    if (err) {
3458      console.error(`Failed to start the video output, error code: ${err.code}.`);
3459      return;
3460    }
3461    console.info('Callback invoked to indicate the video output start success.');
3462  });
3463}
3464```
3465
3466### start
3467
3468start(): Promise\<void\>
3469
3470启动录制,通过Promise获取结果。
3471
3472**系统能力:** SystemCapability.Multimedia.Camera.Core
3473
3474**返回值:**
3475
3476| 类型            | 说明                     |
3477| -------------- | ----------------------- |
3478| Promise\<void\> | 无返回结果的Promise对象。 |
3479
3480**错误码:**
3481
3482以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
3483
3484| 错误码ID         | 错误信息        |
3485| --------------- | --------------- |
3486| 7400103                |  Session not config.                                   |
3487| 7400201                |  Camera service fatal error.                           |
3488
3489**示例:**
3490
3491```ts
3492import { BusinessError } from '@kit.BasicServicesKit';
3493
3494function startVideoOutput(videoOutput: camera.VideoOutput): void {
3495  videoOutput.start().then(() => {
3496    console.info('Promise returned to indicate that start method execution success.');
3497  }).catch((error: BusinessError) => {
3498    console.error(`Failed to video output start, error code: ${error.code}.`);
3499  });
3500}
3501```
3502
3503### stop
3504
3505stop(callback: AsyncCallback\<void\>): void
3506
3507结束录制,通过注册回调函数获取结果。使用callback异步回调。
3508
3509**系统能力:** SystemCapability.Multimedia.Camera.Core
3510
3511**参数:**
3512
3513| 参数名     | 类型                 | 必填 | 说明                     |
3514| -------- | -------------------- | ---- | ------------------------ |
3515| callback | AsyncCallback\<void\> | 是   | 回调函数,用于获取结果。 |
3516
3517**示例:**
3518
3519```ts
3520import { BusinessError } from '@kit.BasicServicesKit';
3521
3522function stopVideoOutput(videoOutput: camera.VideoOutput): void {
3523  videoOutput.stop((err: BusinessError) => {
3524    if (err) {
3525      console.error(`Failed to stop the video output, error code: ${err.code}.`);
3526      return;
3527    }
3528    console.info('Callback invoked to indicate the video output stop success.');
3529  });
3530}
3531```
3532
3533### stop
3534
3535stop(): Promise\<void\>
3536
3537结束录制,通过Promise获取结果。
3538
3539**系统能力:** SystemCapability.Multimedia.Camera.Core
3540
3541**返回值:**
3542
3543| 类型            | 说明                     |
3544| -------------- | ----------------------- |
3545| Promise\<void\> | 无返回结果的Promise对象。 |
3546
3547**示例:**
3548
3549```ts
3550import { BusinessError } from '@kit.BasicServicesKit';
3551
3552function stopVideoOutput(videoOutput: camera.VideoOutput): void {
3553  videoOutput.stop().then(() => {
3554    console.info('Promise returned to indicate that stop method execution success.');
3555  }).catch((error: BusinessError) => {
3556    console.error(`Failed to video output stop, error code: ${error.code}.`);
3557  });
3558}
3559```
3560
3561### on('frameStart')
3562
3563on(type: 'frameStart', callback: AsyncCallback\<void\>): void
3564
3565监听录像开始,通过注册回调函数获取结果。使用callback异步回调。
3566
3567> **说明:**
3568>
3569> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
3570
3571**系统能力:** SystemCapability.Multimedia.Camera.Core
3572
3573**参数:**
3574
3575| 参数名      | 类型                  | 必填 | 说明                                       |
3576| -------- | -------------------- | ---- | ----------------------------------------- |
3577| type     | string               | 是   | 监听事件,固定为'frameStart',videoOutput创建成功后可监听。底层第一次曝光时触发该事件并返回。 |
3578| callback | AsyncCallback\<void\> | 是   | 回调函数,用于获取结果。  只要有该事件返回就证明录像开始。                     |
3579
3580**示例:**
3581
3582```ts
3583import { BusinessError } from '@kit.BasicServicesKit';
3584
3585function callback(err: BusinessError): void {
3586  if (err !== undefined && err.code !== 0) {
3587    console.error(`Callback Error, errorCode: ${err.code}`);
3588    return;
3589  }
3590  console.info('Video frame started');
3591}
3592
3593function registerVideoOutputFrameStart(videoOutput: camera.VideoOutput): void {
3594  videoOutput.on('frameStart', callback);
3595}
3596```
3597
3598### off('frameStart')
3599
3600off(type: 'frameStart', callback?: AsyncCallback\<void\>): void
3601
3602注销监听录像开始。
3603
3604> **说明:**
3605>
3606> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
3607
3608**系统能力:** SystemCapability.Multimedia.Camera.Core
3609
3610**参数:**
3611
3612| 参数名      | 类型                  | 必填 | 说明                                       |
3613| -------- | -------------------- | ---- | ----------------------------------------- |
3614| type     | string               | 是   | 监听事件,固定为'frameStart',videoOutput创建成功后可监听。 |
3615| callback | AsyncCallback\<void\> | 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
3616
3617**示例:**
3618
3619```ts
3620function unregisterVideoOutputFrameStart(videoOutput: camera.VideoOutput): void {
3621  videoOutput.off('frameStart');
3622}
3623
3624```
3625
3626### on('frameEnd')
3627
3628on(type: 'frameEnd', callback: AsyncCallback\<void\>): void
3629
3630监听录像结束,通过注册回调函数获取结果。使用callback异步回调。
3631
3632**系统能力:** SystemCapability.Multimedia.Camera.Core
3633
3634**参数:**
3635
3636| 参数名      | 类型                  | 必填 | 说明                                       |
3637| -------- | -------------------- | ---- | ------------------------------------------ |
3638| type     | string               | 是   | 监听事件,固定为'frameEnd',videoOutput创建成功后可监听。录像完全结束最后一帧时触发该事件并返回。 |
3639| callback | AsyncCallback\<void\> | 是   | 回调函数,用于获取结果。 只要有该事件返回就证明录像结束。                      |
3640
3641**示例:**
3642
3643```ts
3644import { BusinessError } from '@kit.BasicServicesKit';
3645
3646function callback(err: BusinessError): void {
3647  if (err !== undefined && err.code !== 0) {
3648    console.error(`Callback Error, errorCode: ${err.code}`);
3649    return;
3650  }
3651  console.info('Video frame ended');
3652}
3653
3654function registerVideoOutputFrameEnd(videoOutput: camera.VideoOutput): void {
3655  videoOutput.on('frameEnd', callback);
3656}
3657```
3658
3659### off('frameEnd')
3660
3661off(type: 'frameEnd', callback?: AsyncCallback\<void\>): void
3662
3663注销监听录像结束。
3664
3665**系统能力:** SystemCapability.Multimedia.Camera.Core
3666
3667**参数:**
3668
3669| 参数名      | 类型                  | 必填 | 说明                                       |
3670| -------- | -------------------- | ---- | ------------------------------------------ |
3671| type     | string               | 是   | 监听事件,固定为'frameEnd',videoOutput创建成功后可监听。 |
3672| callback | AsyncCallback\<void\> | 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
3673
3674**示例:**
3675
3676```ts
3677function unregisterVideoOutputFrameEnd(videoOutput: camera.VideoOutput): void {
3678  videoOutput.off('frameEnd');
3679}
3680```
3681
3682### on('error')
3683
3684on(type: 'error', callback: ErrorCallback): void
3685
3686监听录像输出发生错误,通过注册回调函数获取结果。使用callback异步回调。
3687
3688> **说明:**
3689>
3690> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
3691
3692**系统能力:** SystemCapability.Multimedia.Camera.Core
3693
3694**参数:**
3695
3696| 参数名     | 类型       | 必填 | 说明                                    |
3697| -------- | ----------- | ---- | -------------------------------------- |
3698| type     | string      | 是   | 监听事件,固定为'error',videoOutput创建成功后可监听。录像接口调用出现错误时触发该事件并返回对应错误码,比如调用[start](#start-1),[CameraOutput.release](#release-1)接口时出现错误返回对应错误信息。 |
3699| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | 是   | 回调函数,用于获取错误信息。返回错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。                 |
3700
3701**示例:**
3702
3703```ts
3704import { BusinessError } from '@kit.BasicServicesKit';
3705
3706function callback(err: BusinessError): void {
3707  console.error(`Video output error code: ${err.code}`);
3708}
3709
3710function registerVideoOutputError(videoOutput: camera.VideoOutput): void {
3711  videoOutput.on('error', callback);
3712}
3713```
3714
3715### off('error')
3716
3717off(type: 'error', callback?: ErrorCallback): void
3718
3719注销监听录像输出发生错误。
3720
3721**系统能力:** SystemCapability.Multimedia.Camera.Core
3722
3723**参数:**
3724
3725| 参数名     | 类型         | 必填 | 说明                                 |
3726| -------- | ------------- | ---- | ----------------------------------- |
3727| type     | string       | 是   | 监听事件,固定为'error',photoOutput创建成功后可监听。 |
3728| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
3729
3730**示例:**
3731
3732```ts
3733function unregisterVideoOutputError(videoOutput: camera.VideoOutput): void {
3734  videoOutput.off('error');
3735}
3736```
3737
3738### getSupportedFrameRates<sup>12+</sup>
3739
3740getSupportedFrameRates(): Array\<FrameRateRange\>
3741
3742查询支持的帧率范围。
3743
3744**系统能力:** SystemCapability.Multimedia.Camera.Core
3745
3746**返回值:**
3747
3748|      类型      |     说明     |
3749| -------------  | ------------ |
3750| Array<[FrameRateRange](#frameraterange)> | 支持的帧率范围列表 |
3751
3752**示例:**
3753
3754```ts
3755function getSupportedFrameRates(videoOutput: camera.VideoOutput): Array<camera.FrameRateRange> {
3756  let supportedFrameRatesArray: Array<camera.FrameRateRange> = videoOutput.getSupportedFrameRates();
3757  return supportedFrameRatesArray;
3758}
3759```
3760
3761### setFrameRate<sup>12+</sup>
3762
3763setFrameRate(minFps: number, maxFps: number): void
3764
3765设置录像流帧率范围,设置的范围必须在支持的帧率范围内。
3766
3767进行设置前,可通过[getSupportedFrameRates](#getsupportedframerates12-1)查询支持的帧率范围。
3768
3769> **说明:**
3770> 仅在[PhotoSession](#photosession11)或[VideoSession](#videosession11)模式下支持。
3771
3772**系统能力:** SystemCapability.Multimedia.Camera.Core
3773
3774**参数:**
3775
3776| 参数名     | 类型         | 必填 | 说明                       |
3777| -------- | --------------| ---- | ------------------------ |
3778| minFps   | number        | 是   | 最小帧率。 |
3779| maxFps   | number        | 是   | 最大帧率。当传入的最小值大于最大值时,传参异常,接口不生效。 |
3780
3781**错误码:**
3782
3783以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
3784
3785| 错误码ID        | 错误信息        |
3786| --------------- | --------------- |
3787| 7400101                |  Parameter missing or parameter type incorrect.        |
3788| 7400110                |  Unresolved conflicts with current configurations.     |
3789
3790**示例:**
3791
3792```ts
3793function setFrameRateRange(videoOutput: camera.VideoOutput, frameRateRange: Array<number>): void {
3794  videoOutput.setFrameRate(frameRateRange[0], frameRateRange[1]);
3795}
3796```
3797
3798### getActiveFrameRate<sup>12+</sup>
3799
3800getActiveFrameRate(): FrameRateRange
3801
3802获取已设置的帧率范围。
3803
3804使用[setFrameRate](#setframerate12-1)对录像流设置过帧率后可查询。
3805
3806**系统能力:** SystemCapability.Multimedia.Camera.Core
3807
3808**返回值:**
3809
3810|      类型      |     说明     |
3811| -------------  | ------------ |
3812| [FrameRateRange](#frameraterange) | 帧率范围 |
3813
3814**示例:**
3815
3816```ts
3817function getActiveFrameRate(videoOutput: camera.VideoOutput): camera.FrameRateRange {
3818  let activeFrameRate: camera.FrameRateRange = videoOutput.getActiveFrameRate();
3819  return activeFrameRate;
3820}
3821```
3822
3823### getActiveProfile<sup>12+</sup>
3824
3825getActiveProfile(): VideoProfile
3826
3827获取当前生效的配置信息。
3828
3829**系统能力:** SystemCapability.Multimedia.Camera.Core
3830
3831**返回值:**
3832
3833|      类型      | 说明        |
3834| -------------  |-----------|
3835| [VideoProfile](#videoprofile) | 当前生效的配置信息 |
3836
3837**错误码:**
3838
3839以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
3840
3841| 错误码ID   | 错误信息                         |
3842|---------|------------------------------|
3843| 7400201 | Camera service fatal error.  |
3844
3845**示例:**
3846
3847```ts
3848function testGetActiveProfile(videoOutput: camera.VideoOutput): camera.Profile | undefined {
3849  let activeProfile: camera.VideoProfile | undefined = undefined;
3850  try {
3851    activeProfile = videoOutput.getActiveProfile();
3852  } catch (error) {
3853    // 失败返回错误码error.code并处理
3854    let err = error as BusinessError;
3855    console.error(`The videoOutput.getActiveProfile call failed. error code: ${err.code}`);
3856  }
3857  return activeProfile;
3858}
3859```
3860
3861### getVideoRotation<sup>12+</sup>
3862
3863getVideoRotation(deviceDegree: number): ImageRotation
3864
3865获取录像旋转角度。
3866
3867- 设备自然方向:设备默认使用方向,手机为竖屏(充电口向下)。
3868- 相机镜头角度:值等于相机图像顺时针旋转到设备自然方向的角度,手机后置相机传感器是横屏安装的,所以需要顺时针旋转90度到设备自然方向。
3869- 屏幕显示方向:需要屏幕显示的图片左上角为第一个像素点为坐标原点。锁屏时与自然方向一致。
3870
3871**系统能力:** SystemCapability.Multimedia.Camera.Core
3872
3873**参数:**
3874
3875| 参数名     | 类型         | 必填 | 说明                       |
3876| -------- | --------------| ---- | ------------------------ |
3877| deviceDegree | number | 是   | 设备旋转角度 |
3878
3879**返回值:**
3880
3881|      类型      | 说明        |
3882| -------------  |-----------|
3883| [ImageRotation](#imagerotation) | 获取录像旋转角度。 |
3884
3885**错误码:**
3886
3887以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
3888
3889| 错误码ID   | 错误信息                         |
3890|---------|------------------------------|
3891| 7400101 | Parameter missing or parameter type incorrect.  |
3892| 7400201 | Camera service fatal error.  |
3893
3894**示例:**
3895
3896```ts
3897function testGetVideoRotation(videoOutput: camera.VideoOutput, deviceDegree : number): camera.ImageRotation {
3898  let videoRotation: camera.ImageRotation = camera.ImageRotation.ROTATION_0;
3899  try {
3900    videoRotation = videoOutput.getVideoRotation(deviceDegree);
3901    console.log(`Video rotation is: ${videoRotation}`);
3902  } catch (error) {
3903    // 失败返回错误码error.code并处理
3904    let err = error as BusinessError;
3905    console.error(`The videoOutput.getVideoRotation call failed. error code: ${err.code}`);
3906  }
3907  return videoRotation;
3908}
3909```
3910
3911## MetadataOutput
3912
3913metadata流。继承[CameraOutput](#cameraoutput)。
3914
3915### start
3916
3917start(callback: AsyncCallback\<void\>): void
3918
3919开始输出metadata,通过注册回调函数获取结果。使用callback异步回调。
3920
3921**系统能力:** SystemCapability.Multimedia.Camera.Core
3922
3923**参数:**
3924
3925| 参数名     | 类型                                                         | 必填 | 说明                 |
3926| -------- | -------------------------- | ---- | ------------------- |
3927| callback | AsyncCallback\<void\>       | 是   | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
3928
3929**错误码:**
3930
3931以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
3932
3933| 错误码ID         | 错误信息        |
3934| --------------- | --------------- |
3935| 7400103                |  Session not config.                                   |
3936| 7400201                |  Camera service fatal error.                           |
3937
3938**示例:**
3939
3940```ts
3941import { BusinessError } from '@kit.BasicServicesKit';
3942
3943function startMetadataOutput(metadataOutput: camera.MetadataOutput): void {
3944  metadataOutput.start((err: BusinessError) => {
3945    if (err) {
3946      console.error(`Failed to start metadata output, error code: ${err.code}.`);
3947      return;
3948    }
3949    console.info('Callback returned with metadata output started.');
3950  });
3951}
3952```
3953
3954### start
3955
3956start(): Promise\<void\>
3957
3958开始输出metadata,通过Promise获取结果。
3959
3960**系统能力:** SystemCapability.Multimedia.Camera.Core
3961
3962**返回值:**
3963
3964| 类型                     | 说明                     |
3965| ----------------------  | ------------------------ |
3966| Promise\<void\>          | 无返回结果的Promise对象。 |
3967
3968**错误码:**
3969
3970以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
3971
3972| 错误码ID         | 错误信息        |
3973| --------------- | --------------- |
3974| 7400103                |  Session not config.                                   |
3975| 7400201                |  Camera service fatal error.                           |
3976
3977**示例:**
3978
3979```ts
3980import { BusinessError } from '@kit.BasicServicesKit';
3981
3982function startMetadataOutput(metadataOutput: camera.MetadataOutput): void {
3983  metadataOutput.start().then(() => {
3984    console.info('Callback returned with metadata output started.');
3985  }).catch((error: BusinessError) => {
3986    console.error(`Failed to metadata output stop, error code: ${error.code}`);
3987  });
3988}
3989```
3990
3991### stop
3992
3993stop(callback: AsyncCallback\<void\>): void
3994
3995停止输出metadata,通过注册回调函数获取结果。使用callback异步回调。
3996
3997**系统能力:** SystemCapability.Multimedia.Camera.Core
3998
3999**参数:**
4000
4001| 参数名     | 类型                         | 必填 | 说明                  |
4002| -------- | -------------------------- | ---- | ------------------- |
4003| callback | AsyncCallback\<void\>       | 是   | 回调函数,用于获取结果。 |
4004
4005**示例:**
4006
4007```ts
4008import { BusinessError } from '@kit.BasicServicesKit';
4009
4010function stopMetadataOutput(metadataOutput: camera.MetadataOutput): void {
4011  metadataOutput.stop((err: BusinessError) => {
4012    if (err) {
4013      console.error(`Failed to stop the metadata output, error code: ${err.code}.`);
4014      return;
4015    }
4016    console.info('Callback returned with metadata output stopped.');
4017  })
4018}
4019```
4020
4021### stop
4022
4023stop(): Promise\<void\>
4024
4025停止输出metadata,通过Promise获取结果。
4026
4027**系统能力:** SystemCapability.Multimedia.Camera.Core
4028
4029**返回值:**
4030
4031| 类型                    | 说明                        |
4032| ----------------------  | --------------------------- |
4033| Promise\<void\>         | 无返回结果的Promise对象。 |
4034
4035**示例:**
4036
4037```ts
4038import { BusinessError } from '@kit.BasicServicesKit';
4039
4040function stopMetadataOutput(metadataOutput: camera.MetadataOutput): void {
4041  metadataOutput.stop().then(() => {
4042    console.info('Callback returned with metadata output stopped.');
4043  }).catch((error: BusinessError) => {
4044    console.error(`Failed to metadata output stop, error code: ${error.code}`);
4045  });
4046}
4047```
4048
4049### on('metadataObjectsAvailable')
4050
4051on(type: 'metadataObjectsAvailable', callback: AsyncCallback\<Array\<MetadataObject\>\>): void
4052
4053监听检测到的metadata对象,通过注册回调函数获取结果。使用callback异步回调。
4054
4055> **说明:**
4056>
4057> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
4058
4059**系统能力:** SystemCapability.Multimedia.Camera.Core
4060
4061**参数:**
4062
4063| 参数名      | 类型         | 必填 | 说明                                  |
4064| -------- | -------------- | ---- | ------------------------------------ |
4065| type     | string         | 是   | 监听事件,固定为'metadataObjectsAvailable',metadataOutput创建成功后可监听。检测到有效的metadata数据时触发该事件发生并返回相应的metadata数据。 |
4066| callback | AsyncCallback\<Array\<[MetadataObject](#metadataobject)\>\> | 是   | 回调函数,用于获取metadata数据。 |
4067
4068**示例:**
4069
4070```ts
4071import { BusinessError } from '@kit.BasicServicesKit';
4072
4073function callback(err: BusinessError, metadataObjectArr: Array<camera.MetadataObject>): void {
4074  if (err !== undefined && err.code !== 0) {
4075    console.error(`Callback Error, errorCode: ${err.code}`);
4076    return;
4077  }
4078  console.info('metadata output metadataObjectsAvailable');
4079}
4080
4081function registerMetadataObjectsAvailable(metadataOutput: camera.MetadataOutput): void {
4082  metadataOutput.on('metadataObjectsAvailable', callback);
4083}
4084```
4085
4086### off('metadataObjectsAvailable')
4087
4088off(type: 'metadataObjectsAvailable', callback?: AsyncCallback\<Array\<MetadataObject\>\>): void
4089
4090注销监听检测到的metadata对象。
4091
4092**系统能力:** SystemCapability.Multimedia.Camera.Core
4093
4094**参数:**
4095
4096| 参数名      | 类型         | 必填 | 说明                                  |
4097| -------- | -------------- | ---- | ------------------------------------ |
4098| type     | string         | 是   | 监听事件,固定为'metadataObjectsAvailable',metadataOutput创建成功后可监听。 |
4099| callback | AsyncCallback\<Array\<[MetadataObject](#metadataobject)\>\> | 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
4100
4101**示例:**
4102
4103```ts
4104function unregisterMetadataObjectsAvailable(metadataOutput: camera.MetadataOutput): void {
4105  metadataOutput.off('metadataObjectsAvailable');
4106}
4107```
4108
4109### on('error')
4110
4111on(type: 'error', callback: ErrorCallback): void
4112
4113监听metadata流的错误,通过注册回调函数获取结果。使用callback异步回调。
4114
4115> **说明:**
4116>
4117> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
4118
4119**系统能力:** SystemCapability.Multimedia.Camera.Core
4120
4121**参数:**
4122
4123| 参数名     | 类型         | 必填 | 说明                                     |
4124| -------- | ------------- | ---- | --------------------------------------- |
4125| type     | string        | 是   | 监听事件,固定为'error',metadataOutput创建成功后可监听。metadata接口使用错误时触发该事件并返回对应错误码,比如调用[start](#start-3),[CameraOutput.release](#release-1)接口时发生错误返回对应错误信息。 |
4126| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | 是   | 回调函数,用于获取错误信息。返回错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。            |
4127
4128**示例:**
4129
4130```ts
4131import { BusinessError } from '@kit.BasicServicesKit';
4132
4133function callback(metadataOutputError: BusinessError): void {
4134  console.error(`Metadata output error code: ${metadataOutputError.code}`);
4135}
4136
4137function registerMetadataOutputError(metadataOutput: camera.MetadataOutput): void {
4138  metadataOutput.on('error', callback);
4139}
4140```
4141
4142### off('error')
4143
4144off(type: 'error', callback?: ErrorCallback): void
4145
4146注销监听metadata流的错误。
4147
4148**系统能力:** SystemCapability.Multimedia.Camera.Core
4149
4150**参数:**
4151
4152| 参数名     | 类型         | 必填 | 说明                                     |
4153| -------- | ------------- | ---- | --------------------------------------- |
4154| type     | string        | 是   | 监听事件,固定为'error',metadataOutput创建成功后可监听。 |
4155| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
4156
4157**示例:**
4158
4159```ts
4160function unregisterMetadataOutputError(metadataOutput: camera.MetadataOutput): void {
4161  metadataOutput.off('error');
4162}
4163```
4164
4165## MetadataObjectType
4166
4167枚举,metadata流。
4168
4169**系统能力:** SystemCapability.Multimedia.Camera.Core
4170
4171| 名称                       | 值   | 说明              |
4172| ------------------------- | ---- | ----------------- |
4173| FACE_DETECTION            | 0    | metadata对象类型,用于人脸检测。<br> 检测点应在0-1坐标系内,该坐标系左上角为(0,0),右下角为(1,1)。<br> 此坐标系以设备充电口在右侧时的横向设备方向为基准。<br>例如应用的预览界面布局以设备充电口在下侧时的竖向方向为基准,<br>布局宽高为(w,h), 返回点为(x,y),则转换后的坐标点为(1-y,x)。 |
4174
4175## Rect
4176
4177矩形定义。
4178
4179**系统能力:** SystemCapability.Multimedia.Camera.Core
4180
4181| 名称      | 类型   |  只读  | 可选  |           说明         |
4182| -------- | ------ | ------ |-----| --------------------- |
4183| topLeftX | number |   否   | 否   | 矩形区域左上角x坐标。   |
4184| topLeftY | number |   否   | 否   | 矩形区域左上角y坐标。   |
4185| width    | number |   否   | 否   | 矩形宽,相对值,范围[0, 1]。  |
4186| height   | number |   否   | 否   | 矩形高,相对值,范围[0, 1]。  |
4187
4188## MetadataObject
4189
4190相机元能力信息,[CameraInput](#camerainput)相机信息中的数据来源,通过metadataOutput.on('metadataObjectsAvailable')接口获取。
4191
4192**系统能力:** SystemCapability.Multimedia.Camera.Core
4193
4194| 名称         | 类型                                        | 只读 | 可选 |说明                |
4195| ----------- | ------------------------------------------- | ---- | ---- | ----------------- |
4196| type        | [MetadataObjectType](#metadataobjecttype)   |  是  |  否  | metadata 类型。    |
4197| timestamp   | number                                      |  是  |  否  | 当前时间戳(毫秒)。|
4198| boundingBox | [Rect](#rect)                               |  是  |  否  | metadata 区域框。  |
4199
4200## FlashMode
4201
4202枚举,闪光灯模式。
4203
4204**系统能力:** SystemCapability.Multimedia.Camera.Core
4205
4206| 名称                    | 值   | 说明        |
4207| ---------------------- | ---- | ---------- |
4208| FLASH_MODE_CLOSE       | 0    | 闪光灯关闭。 |
4209| FLASH_MODE_OPEN        | 1    | 闪光灯打开。 |
4210| FLASH_MODE_AUTO        | 2    | 自动闪光灯。 |
4211| FLASH_MODE_ALWAYS_OPEN | 3    | 闪光灯常亮。 |
4212
4213## ExposureMode
4214
4215枚举,曝光模式。
4216
4217**系统能力:** SystemCapability.Multimedia.Camera.Core
4218
4219| 名称                           | 值   | 说明         |
4220| ----------------------------- | ---- | ----------- |
4221| EXPOSURE_MODE_LOCKED          | 0    | 锁定曝光模式。不支持曝光区域中心点设置。 |
4222| EXPOSURE_MODE_AUTO            | 1    | 自动曝光模式。支持曝光区域中心点设置,可以使用[AutoExposure.setMeteringPoint](#setmeteringpoint11)设置曝光区域中心点。 |
4223| EXPOSURE_MODE_CONTINUOUS_AUTO | 2    | 连续自动曝光。不支持曝光区域中心点设置。 |
4224
4225## FocusMode
4226
4227枚举,焦距模式。
4228
4229**系统能力:** SystemCapability.Multimedia.Camera.Core
4230
4231| 名称                        | 值   | 说明          |
4232| -------------------------- | ---- | ------------ |
4233| FOCUS_MODE_MANUAL          | 0    | 手动对焦。通过手动修改相机焦距来改变对焦位置,不支持对焦点设置。     |
4234| FOCUS_MODE_CONTINUOUS_AUTO | 1    | 连续自动对焦。不支持对焦点设置。 |
4235| FOCUS_MODE_AUTO            | 2    | 自动对焦。支持对焦点设置,可以使用[Focus.setFocusPoint](#setfocuspoint11)设置对焦点,根据对焦点执行一次自动对焦。    |
4236| FOCUS_MODE_LOCKED          | 3    | 对焦锁定。不支持对焦点设置。     |
4237
4238## FocusState
4239
4240枚举,焦距状态。
4241
4242**系统能力:** SystemCapability.Multimedia.Camera.Core
4243
4244| 名称                   | 值   | 说明       |
4245| --------------------- | ---- | --------- |
4246| FOCUS_STATE_SCAN      | 0    | 触发对焦。  |
4247| FOCUS_STATE_FOCUSED   | 1    | 对焦成功。  |
4248| FOCUS_STATE_UNFOCUSED | 2    | 未完成对焦。 |
4249
4250## VideoStabilizationMode
4251
4252枚举,视频防抖模式。
4253
4254**系统能力:** SystemCapability.Multimedia.Camera.Core
4255
4256| 名称       | 值   | 说明         |
4257| --------- | ---- | ------------ |
4258| OFF       | 0    | 关闭视频防抖功能。   |
4259| LOW       | 1    | 使用基础防抖算法。   |
4260| MIDDLE    | 2    | 使用防抖效果一般的防抖算法,防抖效果优于LOW类型。   |
4261| HIGH      | 3    | 使用防抖效果最好的防抖算法,防抖效果优于MIDDLE类型。   |
4262| AUTO      | 4    | 自动进行选择。   |
4263
4264## Session<sup>11+</sup>
4265
4266会话类,保存一次相机运行所需要的所有资源[CameraInput](#camerainput)、[CameraOutput](#cameraoutput),并向相机设备申请完成相机功能(录像,拍照)。
4267
4268### beginConfig<sup>11+</sup>
4269
4270beginConfig(): void
4271
4272开始配置会话。
4273
4274**系统能力:** SystemCapability.Multimedia.Camera.Core
4275
4276**错误码:**
4277
4278以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
4279
4280| 错误码ID         | 错误信息        |
4281| --------------- | --------------- |
4282| 7400105                |  Session config locked.               |
4283| 7400201                |  Camera service fatal error.               |
4284
4285**示例:**
4286
4287```ts
4288import { BusinessError } from '@kit.BasicServicesKit';
4289
4290function beginConfig(session: camera.Session): void {
4291  try {
4292    session.beginConfig();
4293  } catch (error) {
4294    // 失败返回错误码error.code并处理
4295    let err = error as BusinessError;
4296    console.error(`The beginConfig call failed. error code: ${err.code}`);
4297  }
4298}
4299```
4300
4301### commitConfig<sup>11+</sup>
4302
4303commitConfig(callback: AsyncCallback\<void\>): void
4304
4305提交配置信息,通过注册回调函数获取结果。使用callback异步回调。
4306
4307**系统能力:** SystemCapability.Multimedia.Camera.Core
4308
4309**参数:**
4310
4311| 参数名     | 类型                   | 必填 | 说明                  |
4312| -------- | -------------------- | ---- | -------------------- |
4313| callback | AsyncCallback\<void\> | 是   | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
4314
4315**错误码:**
4316
4317以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
4318
4319| 错误码ID         | 错误信息        |
4320| --------------- | --------------- |
4321| 7400102                |  Operation not allowed.                                  |
4322| 7400201                |  Camera service fatal error.                           |
4323
4324**示例:**
4325
4326```ts
4327import { BusinessError } from '@kit.BasicServicesKit';
4328
4329function commitConfig(session: camera.Session): void {
4330  session.commitConfig((err: BusinessError) => {
4331    if (err) {
4332      console.error(`The commitConfig call failed. error code: ${err.code}`);
4333      return;
4334    }
4335    console.info('Callback invoked to indicate the commit config success.');
4336  });
4337}
4338```
4339
4340### commitConfig<sup>11+</sup>
4341
4342commitConfig(): Promise\<void\>
4343
4344提交配置信息,通过Promise获取结果。
4345
4346**系统能力:** SystemCapability.Multimedia.Camera.Core
4347
4348**返回值:**
4349
4350| 类型            | 说明                     |
4351| -------------- | ------------------------ |
4352| Promise\<void\> | 无返回结果的Promise对象。 |
4353
4354**错误码:**
4355
4356以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
4357
4358| 错误码ID         | 错误信息        |
4359| --------------- | --------------- |
4360| 7400102                |  Operation not allowed.                                  |
4361| 7400201                |  Camera service fatal error.                           |
4362
4363**示例:**
4364
4365```ts
4366import { BusinessError } from '@kit.BasicServicesKit';
4367
4368function commitConfig(session: camera.Session): void {
4369  session.commitConfig().then(() => {
4370    console.info('Promise returned to indicate the commit config success.');
4371  }).catch((error: BusinessError) => {
4372    // 失败返回错误码error.code并处理
4373    console.error(`The commitConfig call failed. error code: ${error.code}`);
4374  });
4375}
4376```
4377
4378### canAddInput<sup>11+</sup>
4379
4380canAddInput(cameraInput: CameraInput): boolean
4381
4382判断当前cameraInput是否可以添加到session中。当前函数需要在[beginConfig](#beginconfig11)和[commitConfig](#commitconfig11-1)之间生效。
4383
4384**系统能力:** SystemCapability.Multimedia.Camera.Core
4385
4386**参数:**
4387
4388| 参数名        | 类型                          | 必填 | 说明                     |
4389| ----------- | --------------------------- | ---- | ------------------------ |
4390| cameraInput | [CameraInput](#camerainput) | 是   | 需要添加的CameraInput实例。传参异常(如超出范围、传入null、未定义等),实际接口不会生效。 |
4391
4392**返回值:**
4393
4394| 类型            | 说明                     |
4395| -------------- | ------------------------ |
4396| boolean | 返回true表示支持添加当前cameraInput,返回false表示不支持添加。 |
4397
4398**示例:**
4399
4400```ts
4401import { BusinessError } from '@kit.BasicServicesKit';
4402
4403function canAddInput(session: camera.Session, cameraInput: camera.CameraInput): void {
4404  let canAdd: boolean = session.canAddInput(cameraInput);
4405  console.info(`The input canAddInput: ${canAdd}`);
4406}
4407```
4408
4409### addInput<sup>11+</sup>
4410
4411addInput(cameraInput: CameraInput): void
4412
4413把[CameraInput](#camerainput)加入到会话。
4414
4415**系统能力:** SystemCapability.Multimedia.Camera.Core
4416
4417**参数:**
4418
4419| 参数名        | 类型                          | 必填 | 说明                     |
4420| ----------- | --------------------------- | ---- | ------------------------ |
4421| cameraInput | [CameraInput](#camerainput) | 是   | 需要添加的CameraInput实例。 |
4422
4423**错误码:**
4424
4425以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
4426
4427| 错误码ID         | 错误信息        |
4428| --------------- | --------------- |
4429| 7400101                |  Parameter missing or parameter type incorrect.        |
4430| 7400102                |  Operation not allowed.                                  |
4431| 7400103                |  Session not config.                                   |
4432| 7400201                |  Camera service fatal error.                                   |
4433
4434**示例:**
4435
4436```ts
4437import { BusinessError } from '@kit.BasicServicesKit';
4438
4439function addInput(session: camera.Session, cameraInput: camera.CameraInput): void {
4440  try {
4441    session.addInput(cameraInput);
4442  } catch (error) {
4443    // 失败返回错误码error.code并处理
4444    let err = error as BusinessError;
4445    console.error(`The addInput call failed. error code: ${err.code}`);
4446  }
4447}
4448```
4449
4450### removeInput<sup>11+</sup>
4451
4452removeInput(cameraInput: CameraInput): void
4453
4454移除[CameraInput](#camerainput)。当前函数需要在[beginConfig](#beginconfig11)和[commitConfig](#commitconfig11-1)之间生效。
4455
4456**系统能力:** SystemCapability.Multimedia.Camera.Core
4457
4458**参数:**
4459
4460| 参数名        | 类型                          | 必填 | 说明                      |
4461| ----------- | --------------------------- | ---- | ------------------------ |
4462| cameraInput | [CameraInput](#camerainput) | 是   | 需要移除的CameraInput实例。 |
4463
4464**错误码:**
4465
4466以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
4467
4468| 错误码ID         | 错误信息        |
4469| --------------- | --------------- |
4470| 7400101                |  Parameter missing or parameter type incorrect.        |
4471| 7400102                |  Operation not allowed.                                  |
4472| 7400103                |  Session not config.                                   |
4473| 7400201                |  Camera service fatal error.                                   |
4474
4475**示例:**
4476
4477```ts
4478import { BusinessError } from '@kit.BasicServicesKit';
4479
4480function removeInput(session: camera.Session, cameraInput: camera.CameraInput): void {
4481  try {
4482    session.removeInput(cameraInput);
4483  } catch (error) {
4484    // 失败返回错误码error.code并处理
4485    let err = error as BusinessError;
4486    console.error(`The removeInput call failed. error code: ${err.code}`);
4487  }
4488}
4489```
4490
4491### canAddOutput<sup>11+</sup>
4492
4493canAddOutput(cameraOutput: CameraOutput): boolean
4494
4495判断当前cameraOutput是否可以添加到session中。当前函数需要在[addInput](#addinput11)和[commitConfig](#commitconfig11-1)之间生效。
4496
4497**系统能力:** SystemCapability.Multimedia.Camera.Core
4498
4499**参数:**
4500
4501| 参数名        | 类型                          | 必填 | 说明                     |
4502| ----------- | --------------------------- | ---- | ------------------------ |
4503| cameraOutput | [CameraOutput](#cameraoutput) | 是   | 需要添加的CameraOutput实例。传参异常(如超出范围、传入null、未定义等),实际接口不会生效。 |
4504
4505**返回值:**
4506
4507| 类型            | 说明                     |
4508| -------------- | ------------------------ |
4509| boolean | 是否可以添加当前cameraOutput到session中。 |
4510
4511**示例:**
4512
4513```ts
4514import { BusinessError } from '@kit.BasicServicesKit';
4515
4516function canAddOutput(session: camera.Session, cameraOutput: camera.CameraOutput): void {
4517  let canAdd: boolean = session.canAddOutput(cameraOutput);
4518  console.info(`This addOutput can add: ${canAdd}`);
4519}
4520```
4521
4522### addOutput<sup>11+</sup>
4523
4524addOutput(cameraOutput: CameraOutput): void
4525
4526把[CameraOutput](#cameraoutput)加入到会话。
4527
4528**系统能力:** SystemCapability.Multimedia.Camera.Core
4529
4530**参数:**
4531
4532| 参数名           | 类型                             | 必填 | 说明                      |
4533| ------------- | ------------------------------- | ---- | ------------------------ |
4534| cameraOutput  | [CameraOutput](#cameraoutput)   | 是   | 需要添加的CameraOutput实例。 |
4535
4536**错误码:**
4537
4538以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
4539
4540| 错误码ID         | 错误信息        |
4541| --------------- | --------------- |
4542| 7400101                |  Parameter missing or parameter type incorrect.        |
4543| 7400102                |  Operation not allowed.                                  |
4544| 7400103                |  Session not config.                                   |
4545| 7400201                |  Camera service fatal error.                                   |
4546
4547**示例:**
4548
4549```ts
4550import { BusinessError } from '@kit.BasicServicesKit';
4551
4552function addOutput(session: camera.Session, cameraOutput: camera.CameraOutput): void {
4553  try {
4554    session.addOutput(cameraOutput);
4555  } catch (error) {
4556    // 失败返回错误码error.code并处理
4557    let err = error as BusinessError;
4558    console.error(`The addOutput call failed. error code: ${err.code}`);
4559  }
4560}
4561```
4562
4563### removeOutput<sup>11+</sup>
4564
4565removeOutput(cameraOutput: CameraOutput): void
4566
4567从会话中移除[CameraOutput](#cameraoutput)。
4568
4569**系统能力:** SystemCapability.Multimedia.Camera.Core
4570
4571**参数:**
4572
4573| 参数名           | 类型                             | 必填 | 说明                      |
4574| ------------- | ------------------------------- | ---- | ------------------------ |
4575| cameraOutput  | [CameraOutput](#cameraoutput)   | 是   | 需要移除的CameraOutput实例。 |
4576
4577**错误码:**
4578
4579以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
4580
4581| 错误码ID         | 错误信息        |
4582| --------------- | --------------- |
4583| 7400101                |  Parameter missing or parameter type incorrect.        |
4584| 7400102                |  Operation not allowed.                                  |
4585| 7400103                |  Session not config.                                   |
4586| 7400201                |  Camera service fatal error.                                   |
4587
4588**示例:**
4589
4590```ts
4591import { BusinessError } from '@kit.BasicServicesKit';
4592
4593function removeOutput(session: camera.Session, previewOutput: camera.PreviewOutput): void {
4594  try {
4595    session.removeOutput(previewOutput);
4596  } catch (error) {
4597    // 失败返回错误码error.code并处理
4598    let err = error as BusinessError;
4599    console.error(`The removeOutput call failed. error code: ${err.code}`);
4600  }
4601}
4602```
4603
4604### start<sup>11+</sup>
4605
4606start(callback: AsyncCallback\<void\>): void
4607
4608开始会话工作,通过注册回调函数获取结果。使用callback异步回调。
4609
4610**系统能力:** SystemCapability.Multimedia.Camera.Core
4611
4612**参数:**
4613
4614| 参数名      | 类型                  | 必填 | 说明                 |
4615| -------- | -------------------- | ---- | -------------------- |
4616| callback | AsyncCallback\<void\> | 是   | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
4617
4618**错误码:**
4619
4620以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
4621
4622| 错误码ID         | 错误信息        |
4623| --------------- | --------------- |
4624| 7400102                |  Operation not allowed.                                |
4625| 7400103                |  Session not config.                                   |
4626| 7400201                |  Camera service fatal error.                           |
4627
4628**示例:**
4629
4630```ts
4631import { BusinessError } from '@kit.BasicServicesKit';
4632
4633function startCaptureSession(session: camera.Session): void {
4634  session.start((err: BusinessError) => {
4635    if (err) {
4636      console.error(`Failed to start the session, error code: ${err.code}.`);
4637      return;
4638    }
4639    console.info('Callback invoked to indicate the session start success.');
4640  });
4641}
4642```
4643
4644### start<sup>11+</sup>
4645
4646start(): Promise\<void\>
4647
4648开始会话工作,通过Promise获取结果。
4649
4650**系统能力:** SystemCapability.Multimedia.Camera.Core
4651
4652**返回值:**
4653
4654| 类型            | 说明                     |
4655| -------------- | ------------------------ |
4656| Promise\<void\> | 无返回结果的Promise对象。 |
4657
4658**错误码:**
4659
4660以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
4661
4662| 错误码ID         | 错误信息        |
4663| --------------- | --------------- |
4664| 7400102                |  Operation not allowed.                                |
4665| 7400103                |  Session not config.                                   |
4666| 7400201                |  Camera service fatal error.                           |
4667
4668**示例:**
4669
4670```ts
4671import { BusinessError } from '@kit.BasicServicesKit';
4672
4673function startCaptureSession(session: camera.Session): void {
4674  session.start().then(() => {
4675    console.info('Promise returned to indicate the session start success.');
4676  }).catch((error: BusinessError) => {
4677    console.error(`Failed to start the session, error code: ${error.code}.`);
4678  });
4679}
4680```
4681
4682### stop<sup>11+</sup>
4683
4684stop(callback: AsyncCallback\<void\>): void
4685
4686停止会话工作,通过注册回调函数获取结果。使用callback异步回调。
4687
4688**系统能力:** SystemCapability.Multimedia.Camera.Core
4689
4690**参数:**
4691
4692| 参数名      | 类型                  | 必填 | 说明                 |
4693| -------- | -------------------- | ---- | ------------------- |
4694| callback | AsyncCallback\<void\> | 是   | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
4695
4696**错误码:**
4697
4698以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
4699
4700| 错误码ID         | 错误信息        |
4701| --------------- | --------------- |
4702| 7400201                |  Camera service fatal error.                           |
4703
4704**示例:**
4705
4706```ts
4707import { BusinessError } from '@kit.BasicServicesKit';
4708
4709function stopCaptureSession(session: camera.Session): void {
4710  session.stop((err: BusinessError) => {
4711    if (err) {
4712      console.error(`Failed to stop the session, error code: ${err.code}.`);
4713      return;
4714    }
4715    console.info('Callback invoked to indicate the session stop success.');
4716  });
4717}
4718```
4719
4720### stop<sup>11+</sup>
4721
4722stop(): Promise\<void\>
4723
4724停止会话工作,通过Promise获取结果。
4725
4726**系统能力:** SystemCapability.Multimedia.Camera.Core
4727
4728**返回值:**
4729
4730| 类型            | 说明                |
4731| -------------- |-------------------|
4732| Promise\<void\> | 无返回结果的Promise对象。  |
4733
4734**错误码:**
4735
4736以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
4737
4738| 错误码ID         | 错误信息        |
4739| --------------- | --------------- |
4740| 7400201                |  Camera service fatal error.                           |
4741
4742**示例:**
4743
4744```ts
4745import { BusinessError } from '@kit.BasicServicesKit';
4746
4747function stopCaptureSession(session: camera.Session): void {
4748  session.stop().then(() => {
4749    console.info('Promise returned to indicate the session stop success.');
4750  }).catch((error: BusinessError) => {
4751    console.error(`Failed to stop the session, error code: ${error.code}.`);
4752  });
4753}
4754```
4755
4756### release<sup>11+</sup>
4757
4758release(callback: AsyncCallback\<void\>): void
4759
4760释放会话资源,通过注册回调函数获取结果。使用callback异步回调。
4761
4762**系统能力:** SystemCapability.Multimedia.Camera.Core
4763
4764**参数:**
4765
4766| 参数名      | 类型                  | 必填 | 说明                 |
4767| -------- | -------------------- | ---- | -------------------- |
4768| callback | AsyncCallback\<void\> | 是   | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
4769
4770**错误码:**
4771
4772以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
4773
4774| 错误码ID         | 错误信息        |
4775| --------------- | --------------- |
4776| 7400201                |  Camera service fatal error.                           |
4777
4778**示例:**
4779
4780```ts
4781import { BusinessError } from '@kit.BasicServicesKit';
4782
4783function releaseCaptureSession(session: camera.Session): void {
4784  session.release((err: BusinessError) => {
4785    if (err) {
4786      console.error(`Failed to release the session instance, error code: ${err.code}.`);
4787      return;
4788    }
4789    console.info('Callback invoked to indicate that the session instance is released successfully.');
4790  });
4791}
4792```
4793
4794### release<sup>11+</sup>
4795
4796release(): Promise\<void\>
4797
4798释放会话资源,通过Promise获取结果。
4799
4800**系统能力:** SystemCapability.Multimedia.Camera.Core
4801
4802**返回值:**
4803
4804| 类型            | 说明                     |
4805| -------------- | ------------------------ |
4806| Promise\<void\> | 无返回结果的Promise对象。 |
4807
4808**错误码:**
4809
4810以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
4811
4812| 错误码ID         | 错误信息        |
4813| --------------- | --------------- |
4814| 7400201                |  Camera service fatal error.                           |
4815
4816**示例:**
4817
4818```ts
4819import { BusinessError } from '@kit.BasicServicesKit';
4820
4821function releaseCaptureSession(session: camera.Session): void {
4822  session.release().then(() => {
4823    console.info('Promise returned to indicate that the session instance is released successfully.');
4824  }).catch((error: BusinessError) => {
4825    console.error(`Failed to release the session instance, error code: ${error.code}.`);
4826  });
4827}
4828```
4829
4830## Flash<sup>11+</sup>
4831
4832Flash extends [FlashQuery](#flashquery12)
4833
4834闪光灯类,对设备闪光灯操作。
4835
4836### setFlashMode<sup>11+</sup>
4837
4838setFlashMode(flashMode: FlashMode): void
4839
4840设置闪光灯模式。
4841
4842进行设置之前,需要先检查:
4843
48441. 设备是否支持闪光灯,可使用方法[hasFlash](#hasflash11)。
48452. 设备是否支持指定的闪光灯模式,可使用方法[isFlashModeSupported](#isflashmodesupported11)。
4846
4847**系统能力:** SystemCapability.Multimedia.Camera.Core
4848
4849**参数:**
4850
4851| 参数名       | 类型                     | 必填 | 说明                  |
4852| --------- | ----------------------- | ---- | --------------------- |
4853| flashMode | [FlashMode](#flashmode) | 是   | 指定闪光灯模式。传参为null或者undefined,作为0处理,闪光灯关闭。       |
4854
4855**错误码:**
4856
4857以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
4858
4859| 错误码ID         | 错误信息        |
4860| --------------- | --------------- |
4861| 7400103                |  Session not config.                                   |
4862
4863**示例:**
4864
4865```ts
4866import { BusinessError } from '@kit.BasicServicesKit';
4867
4868function setFlashMode(photoSession: camera.PhotoSession): void {
4869  try {
4870    photoSession.setFlashMode(camera.FlashMode.FLASH_MODE_AUTO);
4871  } catch (error) {
4872    // 失败返回错误码error.code并处理
4873    let err = error as BusinessError;
4874    console.error(`The setFlashMode call failed. error code: ${err.code}`);
4875  }
4876}
4877```
4878
4879### getFlashMode<sup>11+</sup>
4880
4881getFlashMode(): FlashMode
4882
4883获取当前设备的闪光灯模式。
4884
4885**系统能力:** SystemCapability.Multimedia.Camera.Core
4886
4887**返回值:**
4888
4889| 类型        | 说明                          |
4890| ---------- | ----------------------------- |
4891| [FlashMode](#flashmode)    | 获取当前设备的闪光灯模式。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
4892
4893**错误码:**
4894
4895以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
4896
4897| 错误码ID         | 错误信息        |
4898| --------------- | --------------- |
4899| 7400103                |  Session not config.                                   |
4900
4901**示例:**
4902
4903```ts
4904import { BusinessError } from '@kit.BasicServicesKit';
4905
4906function getFlashMode(photoSession: camera.PhotoSession): camera.FlashMode | undefined {
4907  let flashMode: camera.FlashMode | undefined = undefined;
4908  try {
4909    flashMode = photoSession.getFlashMode();
4910  } catch (error) {
4911    // 失败返回错误码error.code并处理
4912    let err = error as BusinessError;
4913    console.error(`The getFlashMode call failed.error code: ${err.code}`);
4914  }
4915  return flashMode;
4916}
4917```
4918
4919## FlashQuery<sup>12+</sup>
4920
4921提供了查询设备的闪光灯状态和模式的能力。
4922
4923### hasFlash<sup>11+</sup>
4924
4925hasFlash(): boolean
4926
4927检测是否有闪光灯,通过注册回调函数获取结果。
4928
4929**系统能力:** SystemCapability.Multimedia.Camera.Core
4930
4931**返回值:**
4932
4933| 类型        | 说明                          |
4934| ---------- | ----------------------------- |
4935| boolean    | 返回true表示设备支持闪光灯,false表示不支持。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
4936
4937**错误码:**
4938
4939以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
4940
4941| 错误码ID         | 错误信息        |
4942| --------------- | --------------- |
4943| 7400103                |  Session not config, only throw in session usage.       |
4944
4945**示例:**
4946
4947```ts
4948import { BusinessError } from '@kit.BasicServicesKit';
4949
4950function hasFlash(photoSession: camera.PhotoSession): boolean {
4951  let status: boolean = false;
4952  try {
4953    status = photoSession.hasFlash();
4954  } catch (error) {
4955    // 失败返回错误码error.code并处理
4956    let err = error as BusinessError;
4957    console.error(`The hasFlash call failed. error code: ${err.code}`);
4958  }
4959  return status;
4960}
4961```
4962
4963### isFlashModeSupported<sup>11+</sup>
4964
4965isFlashModeSupported(flashMode: FlashMode): boolean
4966
4967检测闪光灯模式是否支持。
4968
4969**系统能力:** SystemCapability.Multimedia.Camera.Core
4970
4971**参数:**
4972
4973| 参数名       | 类型                     | 必填 | 说明                               |
4974| --------- | ----------------------- | ---- | --------------------------------- |
4975| flashMode | [FlashMode](#flashmode) | 是   | 指定闪光灯模式。传参为null或者undefined,作为0处理,闪光灯关闭。             |
4976
4977**返回值:**
4978
4979| 类型        | 说明                          |
4980| ---------- | ----------------------------- |
4981| boolean    | 返回true表示支持该闪光灯模式,false表示不支持。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
4982
4983**错误码:**
4984
4985以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
4986
4987| 错误码ID         | 错误信息        |
4988| --------------- | --------------- |
4989| 7400103                |  Session not config, only throw in session usage.             |
4990
4991**示例:**
4992
4993```ts
4994import { BusinessError } from '@kit.BasicServicesKit';
4995
4996function isFlashModeSupported(photoSession: camera.PhotoSession): boolean {
4997  let status: boolean = false;
4998  try {
4999    status = photoSession.isFlashModeSupported(camera.FlashMode.FLASH_MODE_AUTO);
5000  } catch (error) {
5001    // 失败返回错误码error.code并处理
5002    let err = error as BusinessError;
5003    console.error(`The isFlashModeSupported call failed. error code: ${err.code}`);
5004  }
5005  return status;
5006}
5007```
5008
5009## AutoExposure<sup>11+</sup>
5010
5011AutoExposure extends [AutoExposureQuery](#autoexposurequery12)
5012
5013自动曝光类,对设备自动曝光(AE)操作。
5014
5015### getExposureMode<sup>11+</sup>
5016
5017getExposureMode(): ExposureMode
5018
5019获取当前曝光模式。
5020
5021**系统能力:** SystemCapability.Multimedia.Camera.Core
5022
5023**返回值:**
5024
5025| 类型        | 说明                          |
5026| ---------- | ----------------------------- |
5027| [ExposureMode](#exposuremode)    | 获取当前曝光模式。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
5028
5029**错误码:**
5030
5031以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
5032
5033| 错误码ID         | 错误信息        |
5034| --------------- | --------------- |
5035| 7400103                |  Session not config.                                   |
5036
5037**示例:**
5038
5039```ts
5040import { BusinessError } from '@kit.BasicServicesKit';
5041
5042function getExposureMode(photoSession: camera.PhotoSession): camera.ExposureMode | undefined {
5043  let exposureMode: camera.ExposureMode | undefined = undefined;
5044  try {
5045    exposureMode = photoSession.getExposureMode();
5046  } catch (error) {
5047    // 失败返回错误码error.code并处理
5048    let err = error as BusinessError;
5049    console.error(`The getExposureMode call failed. error code: ${err.code}`);
5050  }
5051  return exposureMode;
5052}
5053```
5054
5055### setExposureMode<sup>11+</sup>
5056
5057setExposureMode(aeMode: ExposureMode): void
5058
5059设置曝光模式。进行设置之前,需要先检查设备是否支持指定的曝光模式,可使用方法[isExposureModeSupported](#isexposuremodesupported11)。
5060
5061**系统能力:** SystemCapability.Multimedia.Camera.Core
5062
5063**参数:**
5064
5065| 参数名      | 类型                            | 必填 | 说明                    |
5066| -------- | -------------------------------| ---- | ----------------------- |
5067| aeMode   | [ExposureMode](#exposuremode)  | 是   | 曝光模式。传参为null或者undefined,作为0处理,曝光锁定。                |
5068
5069**错误码:**
5070
5071以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
5072
5073| 错误码ID         | 错误信息        |
5074| --------------- | --------------- |
5075| 7400103                |  Session not config.                                   |
5076
5077**示例:**
5078
5079```ts
5080import { BusinessError } from '@kit.BasicServicesKit';
5081
5082function setExposureMode(photoSession: camera.PhotoSession): void {
5083  try {
5084    photoSession.setExposureMode(camera.ExposureMode.EXPOSURE_MODE_LOCKED);
5085  } catch (error) {
5086    // 失败返回错误码error.code并处理
5087    let err = error as BusinessError;
5088    console.error(`The setExposureMode call failed. error code: ${err.code}`);
5089  }
5090}
5091```
5092
5093### getMeteringPoint<sup>11+</sup>
5094
5095getMeteringPoint(): Point
5096
5097查询曝光区域中心点。
5098
5099**系统能力:** SystemCapability.Multimedia.Camera.Core
5100
5101**返回值:**
5102
5103| 类型        | 说明                          |
5104| ---------- | ----------------------------- |
5105| [Point](#point)    | 获取当前曝光点。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
5106
5107**错误码:**
5108
5109以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
5110
5111| 错误码ID         | 错误信息        |
5112| --------------- | --------------- |
5113| 7400103                |  Session not config.                                   |
5114
5115**示例:**
5116
5117```ts
5118import { BusinessError } from '@kit.BasicServicesKit';
5119
5120function getMeteringPoint(photoSession: camera.PhotoSession): camera.Point | undefined {
5121  let exposurePoint: camera.Point | undefined = undefined;
5122  try {
5123    exposurePoint = photoSession.getMeteringPoint();
5124  } catch (error) {
5125    // 失败返回错误码error.code并处理
5126    let err = error as BusinessError;
5127    console.error(`The getMeteringPoint call failed. error code: ${err.code}`);
5128  }
5129  return exposurePoint;
5130}
5131```
5132
5133### setMeteringPoint<sup>11+</sup>
5134
5135setMeteringPoint(point: Point): void
5136
5137设置曝光区域中心点,曝光点应在0-1坐标系内,该坐标系左上角为{0,0},右下角为{1,1}。<br>此坐标系是以设备充电口在右侧时的横向设备方向为基准的,例如应用的预览界面布局以<br>设备充电口在下侧时的竖向方向为基准,布局宽高为{w,h},且触碰点为{x,y},<br>则转换后的坐标点为{y/h,1-x/w}。
5138
5139**系统能力:** SystemCapability.Multimedia.Camera.Core
5140
5141**参数:**
5142
5143| 参数名           | 类型                            | 必填 | 说明                 |
5144| ------------- | -------------------------------| ---- | ------------------- |
5145| point | [Point](#point)                | 是   | 曝光点,x、y设置范围应在[0,1]之内,超过范围,如果小于0设置0,大于1设置1。             |
5146
5147**错误码:**
5148
5149以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
5150
5151| 错误码ID         | 错误信息        |
5152| --------------- | --------------- |
5153| 7400103                |  Session not config.                                   |
5154
5155**示例:**
5156
5157```ts
5158import { BusinessError } from '@kit.BasicServicesKit';
5159
5160function setMeteringPoint(photoSession: camera.PhotoSession): void {
5161  const point: camera.Point = {x: 1, y: 1};
5162  try {
5163    photoSession.setMeteringPoint(point);
5164  } catch (error) {
5165    // 失败返回错误码error.code并处理
5166    let err = error as BusinessError;
5167    console.error(`The setMeteringPoint call failed. error code: ${err.code}`);
5168  }
5169}
5170```
5171
5172### setExposureBias<sup>11+</sup>
5173
5174setExposureBias(exposureBias: number): void
5175
5176设置曝光补偿,曝光补偿值(EV)。
5177
5178进行设置之前,建议先通过方法[getExposureBiasRange](#getexposurebiasrange11)查询支持的范围。
5179
5180**系统能力:** SystemCapability.Multimedia.Camera.Core
5181
5182**参数:**
5183
5184| 参数名     | 类型                            | 必填 | 说明                                                                                                                                                                                            |
5185| -------- | -------------------------------| ---- |-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
5186| exposureBias   | number                   | 是   | 曝光补偿,[getExposureBiasRange](#getexposurebiasrange11)查询支持的范围,如果设置超过支持范围的值,自动匹配到就近临界点。<br>曝光补偿存在步长,如步长为0.5。则设置1.2时,获取到实际生效曝光补偿为1.0。<br>接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
5187
5188**错误码:**
5189
5190以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
5191
5192| 错误码ID         | 错误信息        |
5193| --------------- | --------------- |
5194| 7400102                |  Operation not allowed.                                |
5195| 7400103                |  Session not config.                                   |
5196
5197**示例:**
5198
5199```ts
5200import { BusinessError } from '@kit.BasicServicesKit';
5201
5202function setExposureBias(photoSession: camera.PhotoSession, biasRangeArray: Array<number>): void {
5203  if (biasRangeArray && biasRangeArray.length > 0) {
5204    let exposureBias = biasRangeArray[0];
5205    try {
5206      photoSession.setExposureBias(exposureBias);
5207    } catch (error) {
5208      // 失败返回错误码error.code并处理
5209      let err = error as BusinessError;
5210      console.error(`The setExposureBias call failed. error code: ${err.code}`);
5211    }
5212  }
5213}
5214```
5215
5216### getExposureValue<sup>11+</sup>
5217
5218getExposureValue(): number
5219
5220查询当前曝光值。
5221
5222**系统能力:** SystemCapability.Multimedia.Camera.Core
5223
5224**返回值:**
5225
5226| 类型        | 说明                          |
5227| ---------- | ----------------------------- |
5228| number    | 获取曝光值。曝光补偿存在步长,如步长为0.5。则设置1.2时,获取到实际生效曝光补偿为1.0。<br>接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
5229
5230**错误码:**
5231
5232以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
5233
5234| 错误码ID         | 错误信息        |
5235| --------------- | --------------- |
5236| 7400103                |  Session not config.                                   |
5237
5238**示例:**
5239
5240```ts
5241import { BusinessError } from '@kit.BasicServicesKit';
5242
5243function getExposureValue(photoSession: camera.PhotoSession): number {
5244  const invalidValue: number = -1;
5245  let exposureValue: number = invalidValue;
5246  try {
5247    exposureValue = photoSession.getExposureValue();
5248  } catch (error) {
5249    // 失败返回错误码error.code并处理
5250    let err = error as BusinessError;
5251    console.error(`The getExposureValue call failed. error code: ${err.code}`);
5252  }
5253  return exposureValue;
5254}
5255```
5256
5257## AutoExposureQuery<sup>12+</sup>
5258
5259提供了针对设备的自动曝光特性提供了一系列查询功能。
5260
5261### isExposureModeSupported<sup>11+</sup>
5262
5263isExposureModeSupported(aeMode: ExposureMode): boolean
5264
5265检测曝光模式是否支持。
5266
5267**系统能力:** SystemCapability.Multimedia.Camera.Core
5268
5269**参数:**
5270
5271| 参数名      | 类型                           | 必填  | 说明                           |
5272| -------- | -------------------------------| ---- | ----------------------------- |
5273| aeMode   | [ExposureMode](#exposuremode)  | 是   | 曝光模式。传参为null或者undefined,作为0处理,曝光锁定。                 |
5274
5275**返回值:**
5276
5277| 类型        | 说明                          |
5278| ---------- | ----------------------------- |
5279| boolean    | 获取是否支持曝光模式。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
5280
5281**错误码:**
5282
5283以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
5284
5285| 错误码ID         | 错误信息        |
5286| --------------- | --------------- |
5287| 7400103                |  Session not config, only throw in session usage.          |
5288
5289**示例:**
5290
5291```ts
5292import { BusinessError } from '@kit.BasicServicesKit';
5293
5294function isExposureModeSupported(photoSession: camera.PhotoSession): boolean {
5295  let isSupported: boolean = false;
5296  try {
5297    isSupported = photoSession.isExposureModeSupported(camera.ExposureMode.EXPOSURE_MODE_LOCKED);
5298  } catch (error) {
5299    // 失败返回错误码error.code并处理
5300    let err = error as BusinessError;
5301    console.error(`The isExposureModeSupported call failed. error code: ${err.code}`);
5302  }
5303  return isSupported;
5304}
5305```
5306
5307### getExposureBiasRange<sup>11+</sup>
5308
5309getExposureBiasRange(): Array\<number\>
5310
5311查询曝光补偿范围。
5312
5313**系统能力:** SystemCapability.Multimedia.Camera.Core
5314
5315**返回值:**
5316
5317| 类型        | 说明                          |
5318| ---------- | ----------------------------- |
5319| Array\<number\>   | 获取补偿范围的数组。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
5320
5321**错误码:**
5322
5323以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
5324
5325| 错误码ID         | 错误信息        |
5326| --------------- | --------------- |
5327| 7400103                |  Session not config, only throw in session usage.               |
5328
5329**示例:**
5330
5331```ts
5332import { BusinessError } from '@kit.BasicServicesKit';
5333
5334function getExposureBiasRange(photoSession: camera.PhotoSession): Array<number> {
5335  let biasRangeArray: Array<number> = [];
5336  try {
5337    biasRangeArray = photoSession.getExposureBiasRange();
5338  } catch (error) {
5339    // 失败返回错误码error.code并处理
5340    let err = error as BusinessError;
5341    console.error(`The getExposureBiasRange call failed. error code: ${err.code}`);
5342  }
5343  return biasRangeArray;
5344}
5345```
5346
5347## Focus<sup>11+</sup>
5348
5349Focus extends [FocusQuery](#focusquery12)
5350
5351对焦类,对设备对焦操作。
5352
5353### setFocusMode<sup>11+</sup>
5354
5355setFocusMode(afMode: FocusMode): void
5356
5357设置对焦模式。
5358
5359进行设置之前,需要先检查设备是否支持指定的焦距模式,可使用方法[isFocusModeSupported](#isfocusmodesupported11)。
5360
5361**系统能力:** SystemCapability.Multimedia.Camera.Core
5362
5363**参数:**
5364
5365| 参数名      | 类型                     | 必填 | 说明                 |
5366| -------- | ----------------------- | ---- | ------------------- |
5367| afMode   | [FocusMode](#focusmode) | 是   | 指定的焦距模式。传参为null或者undefined,作为0处理,手动对焦模式。       |
5368
5369**错误码:**
5370
5371以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
5372
5373| 错误码ID         | 错误信息        |
5374| --------------- | --------------- |
5375| 7400103                |  Session not config.                                   |
5376
5377**示例:**
5378
5379```ts
5380import { BusinessError } from '@kit.BasicServicesKit';
5381
5382function setFocusMode(photoSession: camera.PhotoSession): void {
5383  try {
5384    photoSession.setFocusMode(camera.FocusMode.FOCUS_MODE_AUTO);
5385  } catch (error) {
5386    // 失败返回错误码error.code并处理
5387    let err = error as BusinessError;
5388    console.error(`The setFocusMode call failed. error code: ${err.code}`);
5389  }
5390}
5391```
5392
5393### getFocusMode<sup>11+</sup>
5394
5395getFocusMode(): FocusMode
5396
5397获取当前的对焦模式。
5398
5399**系统能力:** SystemCapability.Multimedia.Camera.Core
5400
5401**返回值:**
5402
5403| 类型        | 说明                          |
5404| ---------- | ----------------------------- |
5405| [FocusMode](#focusmode)   | 获取当前设备的焦距模式。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
5406
5407**错误码:**
5408
5409以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
5410
5411| 错误码ID         | 错误信息        |
5412| --------------- | --------------- |
5413| 7400103                |  Session not config.                                   |
5414
5415**示例:**
5416
5417```ts
5418import { BusinessError } from '@kit.BasicServicesKit';
5419
5420function getFocusMode(photoSession: camera.PhotoSession): camera.FocusMode | undefined {
5421  let afMode: camera.FocusMode | undefined = undefined;
5422  try {
5423    afMode = photoSession.getFocusMode();
5424  } catch (error) {
5425    // 失败返回错误码error.code并处理
5426    let err = error as BusinessError;
5427    console.error(`The getFocusMode call failed. error code: ${err.code}`);
5428  }
5429  return afMode;
5430}
5431```
5432
5433### setFocusPoint<sup>11+</sup>
5434
5435setFocusPoint(point: Point): void
5436
5437设置焦点,焦点应在0-1坐标系内,该坐标系左上角为{0,0},右下角为{1,1}。<br>此坐标系是以设备充电口在右侧时的横向设备方向为基准的,例如应用的预览界面布局以<br>设备充电口在下侧时的竖向方向为基准,布局宽高为{w,h},且触碰点为{x,y},<br>则转换后的坐标点为{y/h,1-x/w}。
5438
5439**系统能力:** SystemCapability.Multimedia.Camera.Core
5440
5441**参数:**
5442
5443| 参数名      | 类型                     | 必填 | 说明                 |
5444| -------- | ----------------------- | ---- | ------------------- |
5445| point    | [Point](#point)         | 是   | 焦点。x、y设置范围应在[0,1]之内,超过范围,如果小于0设置0,大于1设置1。   |
5446
5447**错误码:**
5448
5449以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
5450
5451| 错误码ID         | 错误信息        |
5452| --------------- | --------------- |
5453| 7400103                |  Session not config.                                   |
5454
5455**示例:**
5456
5457```ts
5458import { BusinessError } from '@kit.BasicServicesKit';
5459
5460function setFocusPoint(photoSession: camera.PhotoSession): void {
5461  const focusPoint: camera.Point = {x: 1, y: 1};
5462  try {
5463    photoSession.setFocusPoint(focusPoint);
5464  } catch (error) {
5465    // 失败返回错误码error.code并处理
5466    let err = error as BusinessError;
5467    console.error(`The setFocusPoint call failed. error code: ${err.code}`);
5468  }
5469}
5470```
5471
5472### getFocusPoint<sup>11+</sup>
5473
5474getFocusPoint(): Point
5475
5476查询焦点。
5477
5478**系统能力:** SystemCapability.Multimedia.Camera.Core
5479
5480**返回值:**
5481
5482| 类型        | 说明                          |
5483| ---------- | ----------------------------- |
5484| [Point](#point)    | 用于获取当前焦点。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
5485
5486**错误码:**
5487
5488以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
5489
5490| 错误码ID         | 错误信息        |
5491| --------------- | --------------- |
5492| 7400103                |  Session not config.                                   |
5493
5494**示例:**
5495
5496```ts
5497import { BusinessError } from '@kit.BasicServicesKit';
5498
5499function getFocusPoint(photoSession: camera.PhotoSession): camera.Point | undefined {
5500  let point: camera.Point | undefined = undefined;
5501  try {
5502    point = photoSession.getFocusPoint();
5503  } catch (error) {
5504    // 失败返回错误码error.code并处理
5505    let err = error as BusinessError;
5506    console.error(`The getFocusPoint call failed. error code: ${err.code}`);
5507  }
5508  return point;
5509}
5510```
5511
5512### getFocalLength<sup>11+</sup>
5513
5514getFocalLength(): number
5515
5516查询焦距值。
5517
5518**系统能力:** SystemCapability.Multimedia.Camera.Core
5519
5520**返回值:**
5521
5522| 类型        | 说明                          |
5523| ---------- | ----------------------------- |
5524| number    | 用于获取当前焦距,单位mm。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
5525
5526**错误码:**
5527
5528以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
5529
5530| 错误码ID         | 错误信息        |
5531| --------------- | --------------- |
5532| 7400103                |  Session not config.                                   |
5533
5534**示例:**
5535
5536```ts
5537import { BusinessError } from '@kit.BasicServicesKit';
5538
5539function getFocalLength(photoSession: camera.PhotoSession): number {
5540  const invalidValue: number = -1;
5541  let focalLength: number = invalidValue;
5542  try {
5543    focalLength = photoSession.getFocalLength();
5544  } catch (error) {
5545    // 失败返回错误码error.code并处理
5546    let err = error as BusinessError;
5547    console.error(`The getFocalLength call failed. error code: ${err.code}`);
5548  }
5549  return focalLength;
5550}
5551```
5552
5553## FocusQuery<sup>12+</sup>
5554
5555提供了查询是否支持当前对焦模式的方法。
5556
5557### isFocusModeSupported<sup>11+</sup>
5558
5559isFocusModeSupported(afMode: FocusMode): boolean
5560
5561检测对焦模式是否支持。
5562
5563**系统能力:** SystemCapability.Multimedia.Camera.Core
5564
5565**参数:**
5566
5567| 参数名      | 类型                     | 必填 | 说明                              |
5568| -------- | ----------------------- | ---- | -------------------------------- |
5569| afMode   | [FocusMode](#focusmode) | 是   | 指定的焦距模式。传参为null或者undefined,作为0处理,手动对焦模式。                    |
5570
5571**返回值:**
5572
5573| 类型        | 说明                          |
5574| ---------- | ----------------------------- |
5575| boolean    | 返回true表示支持该焦距模式,false表示不支持。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
5576
5577**错误码:**
5578
5579以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
5580
5581| 错误码ID         | 错误信息        |
5582| --------------- | --------------- |
5583| 7400103                |  Session not config, only throw in session usage.          |
5584
5585**示例:**
5586
5587```ts
5588import { BusinessError } from '@kit.BasicServicesKit';
5589
5590function isFocusModeSupported(photoSession: camera.PhotoSession): boolean {
5591  let status: boolean = false;
5592  try {
5593    status = photoSession.isFocusModeSupported(camera.FocusMode.FOCUS_MODE_AUTO);
5594  } catch (error) {
5595    // 失败返回错误码error.code并处理
5596    let err = error as BusinessError;
5597    console.error(`The isFocusModeSupported call failed. error code: ${err.code}`);
5598  }
5599  return status;
5600}
5601```
5602
5603## SmoothZoomMode<sup>11+</sup>
5604
5605平滑变焦模式。
5606
5607**系统能力:** SystemCapability.Multimedia.Camera.Core
5608
5609| 名称         | 值   | 说明            |
5610| ------------ | ---- | -------------- |
5611| NORMAL       | 0    | 贝塞尔曲线模式。  |
5612
5613## SmoothZoomInfo<sup>11+</sup>
5614
5615平滑变焦参数信息。
5616
5617**系统能力:** SystemCapability.Multimedia.Camera.Core
5618
5619| 名称     | 类型        |   只读   |   可选   | 说明       |
5620| -------- | ---------- | -------- | -------- | ---------- |
5621| duration |   number   |   否     |    否    | 平滑变焦总时长,单位ms。 |
5622
5623## Zoom<sup>11+</sup>
5624
5625Zoom extends [ZoomQuery](#zoomquery12)
5626
5627变焦类,对设备变焦操作。
5628
5629### setZoomRatio<sup>11+</sup>
5630
5631setZoomRatio(zoomRatio: number): void
5632
5633设置变焦比,变焦精度最高为小数点后两位,如果设置超过支持的精度范围,则只保留精度范围内数值。
5634
5635**系统能力:** SystemCapability.Multimedia.Camera.Core
5636
5637**参数:**
5638
5639| 参数名       | 类型                  | 必填 | 说明                                                                                                                              |
5640| --------- | -------------------- | ---- |---------------------------------------------------------------------------------------------------------------------------------|
5641| zoomRatio | number               | 是   | 可变焦距比,通过[getZoomRatioRange](#getzoomratiorange11)获取支持的变焦范围,如果设置超过支持范围的值,则只保留精度范围内数值。<br>设置可变焦距比到底层生效需要一定时间,获取正确设置的可变焦距比需要等待1~2帧的时间。 |
5642
5643**错误码:**
5644
5645以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
5646
5647| 错误码ID         | 错误信息        |
5648| --------------- | --------------- |
5649| 7400103                |  Session not config.                                   |
5650
5651**示例:**
5652
5653```ts
5654import { BusinessError } from '@kit.BasicServicesKit';
5655
5656function setZoomRatio(photoSession: camera.PhotoSession, zoomRatioRange: Array<number>): void {
5657  if (zoomRatioRange === undefined || zoomRatioRange.length <= 0) {
5658    return;
5659  }
5660  let zoomRatio = zoomRatioRange[0];
5661  try {
5662    photoSession.setZoomRatio(zoomRatio);
5663  } catch (error) {
5664    // 失败返回错误码error.code并处理
5665    let err = error as BusinessError;
5666    console.error(`The setZoomRatio call failed. error code: ${err.code}`);
5667  }
5668}
5669```
5670
5671### getZoomRatio<sup>11+</sup>
5672
5673getZoomRatio(): number
5674
5675获取当前的变焦比。
5676
5677**系统能力:** SystemCapability.Multimedia.Camera.Core
5678
5679**返回值:**
5680
5681| 类型        | 说明                          |
5682| ---------- | ----------------------------- |
5683| number    | 获取当前的变焦比结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
5684
5685**错误码:**
5686
5687以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
5688
5689| 错误码ID         | 错误信息        |
5690| --------------- | --------------- |
5691| 7400103                |  Session not config.                                   |
5692| 7400201                |  Camera service fatal error.                           |
5693
5694**示例:**
5695
5696```ts
5697import { BusinessError } from '@kit.BasicServicesKit';
5698
5699function getZoomRatio(photoSession: camera.PhotoSession): number {
5700  const invalidValue: number = -1;
5701  let zoomRatio: number = invalidValue;
5702  try {
5703    zoomRatio = photoSession.getZoomRatio();
5704  } catch (error) {
5705    // 失败返回错误码error.code并处理
5706    let err = error as BusinessError;
5707    console.error(`The getZoomRatio call failed. error code: ${err.code}`);
5708  }
5709  return zoomRatio;
5710}
5711```
5712
5713### setSmoothZoom<sup>11+</sup>
5714
5715setSmoothZoom(targetRatio: number, mode?: SmoothZoomMode): void
5716
5717触发平滑变焦。
5718
5719**系统能力:** SystemCapability.Multimedia.Camera.Core
5720
5721**参数:**
5722
5723| 参数名       | 类型            | 必填 | 说明               |
5724| ------------ | -------------- | ---- | ----------------- |
5725| targetRatio  | number         | 是   | 目标值。      |
5726| mode         | [SmoothZoomMode](#smoothzoommode11) | 否   | 模式。      |
5727
5728**错误码:**
5729
5730以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
5731
5732| 错误码ID         | 错误信息        |
5733| --------------- | --------------- |
5734| 7400103                |  Session not config.                                   |
5735
5736**示例:**
5737
5738```ts
5739import { BusinessError } from '@kit.BasicServicesKit';
5740
5741function setSmoothZoom(sessionExtendsZoom: camera.Zoom, targetZoomRatio: number, mode: camera.SmoothZoomMode): void {
5742  try {
5743    sessionExtendsZoom.setSmoothZoom(targetZoomRatio, mode);
5744  } catch (error) {
5745    // 失败返回错误码error.code并处理
5746    let err = error as BusinessError;
5747    console.error(`The setSmoothZoom call failed. error code: ${err.code}`);
5748  }
5749}
5750```
5751
5752## ZoomQuery<sup>12+</sup>
5753
5754提供了与设备的缩放相关的查询功能,包括获取支持的缩放比例范围。
5755
5756### getZoomRatioRange<sup>11+</sup>
5757
5758getZoomRatioRange(): Array\<number\>
5759
5760获取支持的变焦范围。
5761
5762**系统能力:** SystemCapability.Multimedia.Camera.Core
5763
5764**返回值:**
5765
5766| 类型        | 说明                          |
5767| ---------- | ----------------------------- |
5768| Array\<number\>   | 用于获取可变焦距比范围,返回的数组包括其最小值和最大值。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
5769
5770**错误码:**
5771
5772以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
5773
5774| 错误码ID         | 错误信息        |
5775| --------------- | --------------- |
5776| 7400103                |  Session not config, only throw in session usage.            |
5777
5778**示例:**
5779
5780```ts
5781import { BusinessError } from '@kit.BasicServicesKit';
5782
5783function getZoomRatioRange(photoSession: camera.PhotoSession): Array<number> {
5784  let zoomRatioRange: Array<number> = [];
5785  try {
5786    zoomRatioRange = photoSession.getZoomRatioRange();
5787  } catch (error) {
5788    // 失败返回错误码error.code并处理
5789    let err = error as BusinessError;
5790    console.error(`The getZoomRatioRange call failed. error code: ${err.code}`);
5791  }
5792  return zoomRatioRange;
5793}
5794```
5795
5796## Stabilization<sup>11+</sup>
5797
5798Stabilization extends [StabilizationQuery](#stabilizationquery12)
5799
5800提供设备在录像模式下设置视频防抖的操作。
5801
5802 > **说明:**
5803 >
5804 > 需要会话中有录像流([VideoOutput](#videooutput))的前提下,才可以对视频进行防抖设置,
5805 > 其中[VideoStabilizationMode](#videostabilizationmode)中的枚举HIGH需要在[Profile](#profile)的分辨率为1920*1080的场景下生效。
5806
5807### getActiveVideoStabilizationMode<sup>11+</sup>
5808
5809getActiveVideoStabilizationMode(): VideoStabilizationMode
5810
5811查询当前正在使用的视频防抖模式。
5812
5813**系统能力:** SystemCapability.Multimedia.Camera.Core
5814
5815**返回值:**
5816
5817| 类型        | 说明          |
5818| ---------- |-------------|
5819| [VideoStabilizationMode](#videostabilizationmode)    | 视频防抖是否正在使用。 |
5820
5821**错误码:**
5822
5823以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
5824
5825| 错误码ID         | 错误信息        |
5826| --------------- | --------------- |
5827| 7400103                |  Session not config.                                   |
5828
5829**示例:**
5830
5831```ts
5832import { BusinessError } from '@kit.BasicServicesKit';
5833
5834function getActiveVideoStabilizationMode(videoSession: camera.VideoSession): camera.VideoStabilizationMode | undefined {
5835  let vsMode: camera.VideoStabilizationMode | undefined = undefined;
5836  try {
5837    vsMode = videoSession.getActiveVideoStabilizationMode();
5838  } catch (error) {
5839    // 失败返回错误码error.code并处理
5840    let err = error as BusinessError;
5841    console.error(`The getActiveVideoStabilizationMode call failed. error code: ${err.code}`);
5842  }
5843  return vsMode;
5844}
5845```
5846
5847### setVideoStabilizationMode<sup>11+</sup>
5848
5849setVideoStabilizationMode(mode: VideoStabilizationMode): void
5850
5851设置视频防抖模式。需要先检查设备是否支持对应的防抖模式,可以通过[isVideoStabilizationModeSupported](#isvideostabilizationmodesupported11)方法判断所设置的模式是否支持。
5852
5853**系统能力:** SystemCapability.Multimedia.Camera.Core
5854
5855**参数:**
5856
5857| 参数名      | 类型                                              | 必填 | 说明                    |
5858| -------- | ------------------------------------------------- | ---- | --------------------- |
5859| mode     | [VideoStabilizationMode](#videostabilizationmode) | 是   | 需要设置的视频防抖模式。   |
5860
5861**错误码:**
5862
5863以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
5864
5865| 错误码ID         | 错误信息        |
5866| --------------- | --------------- |
5867| 7400103                |  Session not config.                                   |
5868
5869**示例:**
5870
5871```ts
5872import { BusinessError } from '@kit.BasicServicesKit';
5873
5874function setVideoStabilizationMode(videoSession: camera.VideoSession): void {
5875  try {
5876    videoSession.setVideoStabilizationMode(camera.VideoStabilizationMode.OFF);
5877  } catch (error) {
5878    // 失败返回错误码error.code并处理
5879    let err = error as BusinessError;
5880    console.error(`The setVideoStabilizationMode call failed. error code: ${err.code}`);
5881  }
5882}
5883```
5884
5885## StabilizationQuery<sup>12+</sup>
5886
5887提供了查询设备在录像模式下是否支持对应的视频防抖模式的能力。
5888
5889### isVideoStabilizationModeSupported<sup>11+</sup>
5890
5891isVideoStabilizationModeSupported(vsMode: VideoStabilizationMode): boolean
5892
5893查询是否支持指定的视频防抖模式。
5894
5895**系统能力:** SystemCapability.Multimedia.Camera.Core
5896
5897**参数:**
5898
5899| 参数名      | 类型                                              | 必填 | 说明                             |
5900| -------- | ------------------------------------------------- | ---- | ------------------------------ |
5901| vsMode   | [VideoStabilizationMode](#videostabilizationmode) | 是   | 视频防抖模式。                    |
5902
5903**返回值:**
5904
5905| 类型        | 说明                          |
5906| ---------- | ----------------------------- |
5907| boolean    | 返回视频防抖模式是否支持,true表示支持,false表示不支持。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
5908
5909**错误码:**
5910
5911以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
5912
5913| 错误码ID         | 错误信息        |
5914| --------------- | --------------- |
5915| 7400103                |  Session not config, only throw in session usage.             |
5916
5917**示例:**
5918
5919```ts
5920import { BusinessError } from '@kit.BasicServicesKit';
5921
5922function isVideoStabilizationModeSupported(videoSession: camera.VideoSession): boolean {
5923  let isSupported: boolean = false;
5924  try {
5925    isSupported = videoSession.isVideoStabilizationModeSupported(camera.VideoStabilizationMode.OFF);
5926  } catch (error) {
5927    // 失败返回错误码error.code并处理
5928    let err = error as BusinessError;
5929    console.error(`The isVideoStabilizationModeSupported call failed. error code: ${err.code}`);
5930  }
5931  return isSupported;
5932}
5933```
5934
5935## CaptureSession<sup>(deprecated)</sup>
5936
5937拍照会话类,保存一次相机运行所需要的所有资源[CameraInput](#camerainput)、[CameraOutput](#cameraoutput),并向相机设备申请完成相机功能(录像,拍照)。
5938
5939> **说明:**
5940>从 API version 10开始支持,从API version 11开始废弃。建议使用[PhotoSession](#photosession11)、[VideoSession](#videosession11)替代。
5941
5942### beginConfig<sup>(deprecated)</sup>
5943
5944beginConfig(): void
5945
5946开始配置会话。
5947
5948> **说明:**
5949>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.beginConfig](#beginconfig11)替代。
5950
5951**系统能力:** SystemCapability.Multimedia.Camera.Core
5952
5953**错误码:**
5954
5955以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
5956
5957| 错误码ID         | 错误信息        |
5958| --------------- | --------------- |
5959| 7400105         |  Session config locked.               |
5960
5961**示例:**
5962
5963```ts
5964import { BusinessError } from '@kit.BasicServicesKit';
5965
5966function beginConfig(captureSession: camera.CaptureSession): void {
5967  try {
5968    captureSession.beginConfig();
5969  } catch (error) {
5970    // 失败返回错误码error.code并处理
5971    let err = error as BusinessError;
5972    console.error(`The beginConfig call failed. error code: ${err.code}`);
5973  }
5974}
5975```
5976
5977### commitConfig<sup>(deprecated)</sup>
5978
5979commitConfig(callback: AsyncCallback\<void\>): void
5980
5981提交配置信息,通过注册回调函数获取结果。使用callback异步回调。
5982
5983> **说明:**
5984>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.commitConfig](#commitconfig11)替代。
5985
5986**系统能力:** SystemCapability.Multimedia.Camera.Core
5987
5988**参数:**
5989
5990| 参数名     | 类型                   | 必填 | 说明                  |
5991| -------- | -------------------- | ---- | -------------------- |
5992| callback | AsyncCallback\<void\> | 是   | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) |
5993
5994**错误码:**
5995
5996以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
5997
5998| 错误码ID         | 错误信息        |
5999| --------------- | --------------- |
6000| 7400102                |  Operation not allowed.                                  |
6001| 7400201                |  Camera service fatal error.                           |
6002
6003**示例:**
6004
6005```ts
6006import { BusinessError } from '@kit.BasicServicesKit';
6007
6008function commitConfig(captureSession: camera.CaptureSession): void {
6009  captureSession.commitConfig((err: BusinessError) => {
6010    if (err) {
6011      console.error(`The commitConfig call failed. error code: ${err.code}`);
6012      return;
6013    }
6014    console.info('Callback invoked to indicate the commit config success.');
6015  });
6016}
6017```
6018
6019### commitConfig<sup>(deprecated)</sup>
6020
6021commitConfig(): Promise\<void\>
6022
6023提交配置信息,通过Promise获取结果。
6024
6025> **说明:**
6026>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.commitConfig](#commitconfig11-1)替代。
6027
6028**系统能力:** SystemCapability.Multimedia.Camera.Core
6029
6030**返回值:**
6031
6032| 类型            | 说明                |
6033| -------------- |-------------------|
6034| Promise\<void\> | 无返回结果的Promise对象。 |
6035
6036**错误码:**
6037
6038以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
6039
6040| 错误码ID         | 错误信息        |
6041| --------------- | --------------- |
6042| 7400102                |  Operation not allowed.                                  |
6043| 7400201                |  Camera service fatal error.                           |
6044
6045**示例:**
6046
6047```ts
6048import { BusinessError } from '@kit.BasicServicesKit';
6049
6050function commitConfig(captureSession: camera.CaptureSession): void {
6051  captureSession.commitConfig().then(() => {
6052    console.info('Promise returned to indicate the commit config success.');
6053  }).catch((error: BusinessError) => {
6054    // 失败返回错误码error.code并处理
6055    console.error(`The commitConfig call failed. error code: ${error.code}`);
6056  });
6057}
6058```
6059
6060### addInput<sup>(deprecated)</sup>
6061
6062addInput(cameraInput: CameraInput): void
6063
6064把[CameraInput](#camerainput)加入到会话。
6065
6066> **说明:**
6067>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.addInput](#addinput11)替代。
6068
6069**系统能力:** SystemCapability.Multimedia.Camera.Core
6070
6071**参数:**
6072
6073| 参数名        | 类型                          | 必填 | 说明                     |
6074| ----------- | --------------------------- | ---- | ------------------------ |
6075| cameraInput | [CameraInput](#camerainput) | 是   | 需要添加的CameraInput实例。 |
6076
6077**错误码:**
6078
6079以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
6080
6081| 错误码ID   | 错误信息                                          |
6082|---------|-----------------------------------------------|
6083| 7400101 | Parameter missing or parameter type incorrect. |
6084| 7400102 | Operation not allowed.                           |
6085
6086**示例:**
6087
6088```ts
6089import { BusinessError } from '@kit.BasicServicesKit';
6090
6091function addInput(captureSession: camera.CaptureSession, cameraInput: camera.CameraInput): void {
6092  try {
6093    captureSession.addInput(cameraInput);
6094  } catch (error) {
6095    // 失败返回错误码error.code并处理
6096    let err = error as BusinessError;
6097    console.error(`The addInput call failed. error code: ${err.code}`);
6098  }
6099}
6100```
6101
6102### removeInput<sup>(deprecated)</sup>
6103
6104removeInput(cameraInput: CameraInput): void
6105
6106移除[CameraInput](#camerainput)。
6107
6108> **说明:**
6109>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.removeInput](#removeinput11)替代。
6110
6111**系统能力:** SystemCapability.Multimedia.Camera.Core
6112
6113**参数:**
6114
6115| 参数名        | 类型                          | 必填 | 说明                      |
6116| ----------- | --------------------------- | ---- | ------------------------ |
6117| cameraInput | [CameraInput](#camerainput) | 是   | 需要移除的CameraInput实例。 |
6118
6119**错误码:**
6120
6121以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
6122
6123| 错误码ID         | 错误信息        |
6124| --------------- | --------------- |
6125| 7400101                |  Parameter missing or parameter type incorrect.        |
6126| 7400102                |  Operation not allowed.                                  |
6127
6128**示例:**
6129
6130```ts
6131import { BusinessError } from '@kit.BasicServicesKit';
6132
6133function removeInput(captureSession: camera.CaptureSession, cameraInput: camera.CameraInput): void {
6134  try {
6135    captureSession.removeInput(cameraInput);
6136  } catch (error) {
6137    // 失败返回错误码error.code并处理
6138    let err = error as BusinessError;
6139    console.error(`The removeInput call failed. error code: ${err.code}`);
6140  }
6141}
6142```
6143
6144### addOutput<sup>(deprecated)</sup>
6145
6146addOutput(cameraOutput: CameraOutput): void
6147
6148把[CameraOutput](#cameraoutput)加入到会话。
6149
6150> **说明:**
6151>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.addOutput](#addoutput11)替代。
6152
6153**系统能力:** SystemCapability.Multimedia.Camera.Core
6154
6155**参数:**
6156
6157| 参数名           | 类型                             | 必填 | 说明                      |
6158| ------------- | ------------------------------- | ---- | ------------------------ |
6159| cameraOutput  | [CameraOutput](#cameraoutput)   | 是   | 需要添加的CameraOutput实例。 |
6160
6161**错误码:**
6162
6163以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
6164
6165| 错误码ID         | 错误信息        |
6166| --------------- | --------------- |
6167| 7400101                |  Parameter missing or parameter type incorrect.        |
6168| 7400102                |  Operation not allowed.                                  |
6169
6170**示例:**
6171
6172```ts
6173import { BusinessError } from '@kit.BasicServicesKit';
6174
6175function addOutput(captureSession: camera.CaptureSession, cameraOutput: camera.CameraOutput): void {
6176  try {
6177    captureSession.addOutput(cameraOutput);
6178  } catch (error) {
6179    // 失败返回错误码error.code并处理
6180    let err = error as BusinessError;
6181    console.error(`The addOutput call failed. error code: ${err.code}`);
6182  }
6183}
6184```
6185
6186### removeOutput<sup>(deprecated)</sup>
6187
6188removeOutput(cameraOutput: CameraOutput): void
6189
6190从会话中移除[CameraOutput](#cameraoutput)。
6191
6192> **说明:**
6193>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.removeOutput](#removeoutput11)替代。
6194
6195**系统能力:** SystemCapability.Multimedia.Camera.Core
6196
6197**参数:**
6198
6199| 参数名           | 类型                             | 必填 | 说明                      |
6200| ------------- | ------------------------------- | ---- | ------------------------ |
6201| cameraOutput  | [CameraOutput](#cameraoutput)   | 是   | 需要移除的CameraOutput实例。 |
6202
6203**错误码:**
6204
6205以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
6206
6207| 错误码ID         | 错误信息        |
6208| --------------- | --------------- |
6209| 7400101                |  Parameter missing or parameter type incorrect.        |
6210| 7400102                |  Operation not allowed.                                  |
6211
6212**示例:**
6213
6214```ts
6215import { BusinessError } from '@kit.BasicServicesKit';
6216
6217function removeOutput(captureSession: camera.CaptureSession, previewOutput: camera.PreviewOutput): void {
6218  try {
6219    captureSession.removeOutput(previewOutput);
6220  } catch (error) {
6221    // 失败返回错误码error.code并处理
6222    let err = error as BusinessError;
6223    console.error(`The removeOutput call failed. error code: ${err.code}`);
6224  }
6225}
6226```
6227
6228### start<sup>(deprecated)</sup>
6229
6230start(callback: AsyncCallback\<void\>): void
6231
6232开始会话工作,通过注册回调函数获取结果。使用callback异步回调。
6233
6234> **说明:**
6235>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.start](#start11)替代。
6236
6237**系统能力:** SystemCapability.Multimedia.Camera.Core
6238
6239**参数:**
6240
6241| 参数名      | 类型                  | 必填 | 说明                 |
6242| -------- | -------------------- | ---- | -------------------- |
6243| callback | AsyncCallback\<void\> | 是   | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
6244
6245**错误码:**
6246
6247以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
6248
6249| 错误码ID         | 错误信息        |
6250| --------------- | --------------- |
6251| 7400103                |  Session not config.                                   |
6252| 7400201                |  Camera service fatal error.                           |
6253
6254**示例:**
6255
6256```ts
6257import { BusinessError } from '@kit.BasicServicesKit';
6258
6259function startCaptureSession(captureSession: camera.CaptureSession): void {
6260  captureSession.start((err: BusinessError) => {
6261    if (err) {
6262      console.error(`Failed to start the session, error code: ${err.code}.`);
6263      return;
6264    }
6265    console.info('Callback invoked to indicate the session start success.');
6266  });
6267}
6268```
6269
6270### start<sup>(deprecated)</sup>
6271
6272start(): Promise\<void\>
6273
6274开始会话工作,通过Promise获取结果。
6275
6276> **说明:**
6277>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.start](#start11-1)替代。
6278
6279**系统能力:** SystemCapability.Multimedia.Camera.Core
6280
6281**返回值:**
6282
6283| 类型            | 说明                     |
6284| -------------- | ------------------------ |
6285| Promise\<void\> | 无返回结果的Promise对象。 |
6286
6287**错误码:**
6288
6289以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
6290
6291| 错误码ID         | 错误信息        |
6292| --------------- | --------------- |
6293| 7400103                |  Session not config.                                   |
6294| 7400201                |  Camera service fatal error.                           |
6295
6296**示例:**
6297
6298```ts
6299import { BusinessError } from '@kit.BasicServicesKit';
6300
6301function startCaptureSession(captureSession: camera.CaptureSession): void {
6302  captureSession.start().then(() => {
6303    console.info('Promise returned to indicate the session start success.');
6304  }).catch((err: BusinessError) => {
6305    console.error(`Failed to start the session, error code: ${err.code}.`);
6306  });
6307}
6308```
6309
6310### stop<sup>(deprecated)</sup>
6311
6312stop(callback: AsyncCallback\<void\>): void
6313
6314停止会话工作,通过注册回调函数获取结果。使用callback异步回调。
6315
6316> **说明:**
6317>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.stop](#stop11)替代。
6318
6319**系统能力:** SystemCapability.Multimedia.Camera.Core
6320
6321**参数:**
6322
6323| 参数名      | 类型                  | 必填 | 说明                 |
6324| -------- | -------------------- | ---- | ------------------- |
6325| callback | AsyncCallback\<void\> | 是   | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
6326
6327**错误码:**
6328
6329以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
6330
6331| 错误码ID         | 错误信息        |
6332| --------------- | --------------- |
6333| 7400201                |  Camera service fatal error.                           |
6334
6335**示例:**
6336
6337```ts
6338import { BusinessError } from '@kit.BasicServicesKit';
6339
6340function stopCaptureSession(captureSession: camera.CaptureSession): void {
6341  captureSession.stop((err: BusinessError) => {
6342    if (err) {
6343      console.error(`Failed to stop the session, error code: ${err.code}.`);
6344      return;
6345    }
6346    console.info('Callback invoked to indicate the session stop success.');
6347  });
6348}
6349```
6350
6351### stop<sup>(deprecated)</sup>
6352
6353stop(): Promise\<void\>
6354
6355停止会话工作,通过Promise获取结果。
6356
6357> **说明:**
6358>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.stop](#stop11-1)替代。
6359
6360**系统能力:** SystemCapability.Multimedia.Camera.Core
6361
6362**返回值:**
6363
6364| 类型            | 说明                     |
6365| -------------- | ----------------------- |
6366| Promise\<void\> | 无返回结果的Promise对象。。 |
6367
6368**错误码:**
6369
6370以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
6371
6372| 错误码ID         | 错误信息        |
6373| --------------- | --------------- |
6374| 7400201                |  Camera service fatal error.                           |
6375
6376**示例:**
6377
6378```ts
6379import { BusinessError } from '@kit.BasicServicesKit';
6380
6381function stopCaptureSession(captureSession: camera.CaptureSession): void {
6382  captureSession.stop().then(() => {
6383    console.info('Promise returned to indicate the session stop success.');
6384  }).catch((err: BusinessError) => {
6385    console.error(`Failed to stop the session, error code: ${err.code}.`);
6386  });
6387}
6388```
6389
6390### release<sup>(deprecated)</sup>
6391
6392release(callback: AsyncCallback\<void\>): void
6393
6394释放会话资源,通过注册回调函数获取结果。使用callback异步回调。
6395
6396> **说明:**
6397>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.release](#release11-1)替代。
6398
6399**系统能力:** SystemCapability.Multimedia.Camera.Core
6400
6401**参数:**
6402
6403| 参数名      | 类型                  | 必填 | 说明                 |
6404| -------- | -------------------- | ---- | -------------------- |
6405| callback | AsyncCallback\<void\> | 是   | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
6406
6407**错误码:**
6408
6409以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
6410
6411| 错误码ID         | 错误信息        |
6412| --------------- | --------------- |
6413| 7400201                |  Camera service fatal error.                           |
6414
6415**示例:**
6416
6417```ts
6418import { BusinessError } from '@kit.BasicServicesKit';
6419
6420function releaseCaptureSession(captureSession: camera.CaptureSession): void {
6421  captureSession.release((err: BusinessError) => {
6422    if (err) {
6423      console.error(`Failed to release the CaptureSession instance, error code: ${err.code}.`);
6424      return;
6425    }
6426    console.info('Callback invoked to indicate that the CaptureSession instance is released successfully.');
6427  });
6428}
6429```
6430
6431### release<sup>(deprecated)</sup>
6432
6433release(): Promise\<void\>
6434
6435释放会话资源,通过Promise获取结果。
6436
6437> **说明:**
6438>从 API version 10开始支持,从API version 11开始废弃。建议使用[Session.release](#release11-2)替代。
6439
6440**系统能力:** SystemCapability.Multimedia.Camera.Core
6441
6442**返回值:**
6443
6444| 类型            | 说明                     |
6445| -------------- | ------------------------ |
6446| Promise\<void\> | 无返回结果的Promise对象。 |
6447
6448**错误码:**
6449
6450以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
6451
6452| 错误码ID         | 错误信息        |
6453| --------------- | --------------- |
6454| 7400201                |  Camera service fatal error.                           |
6455
6456**示例:**
6457
6458```ts
6459import { BusinessError } from '@kit.BasicServicesKit';
6460
6461function releaseCaptureSession(captureSession: camera.CaptureSession): void {
6462  captureSession.release().then(() => {
6463    console.info('Promise returned to indicate that the CaptureSession instance is released successfully.');
6464  }).catch((err: BusinessError) => {
6465    console.error(`Failed to release the CaptureSession instance, error code: ${err.code}.`);
6466  });
6467}
6468```
6469
6470### hasFlash<sup>(deprecated)</sup>
6471
6472hasFlash(): boolean
6473
6474检测是否有闪光灯。
6475
6476> **说明:**
6477>从 API version 10开始支持,从API version 11开始废弃。建议使用[Flash.hasFlash](#hasflash11)替代。
6478
6479**系统能力:** SystemCapability.Multimedia.Camera.Core
6480
6481**返回值:**
6482
6483| 类型        | 说明                          |
6484| ---------- | ----------------------------- |
6485| boolean    | 返回true表示设备支持闪光灯,false表示不支持。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
6486
6487**错误码:**
6488
6489以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
6490
6491| 错误码ID         | 错误信息        |
6492| --------------- | --------------- |
6493| 7400103                |  Session not config.                                   |
6494
6495**示例:**
6496
6497```ts
6498import { BusinessError } from '@kit.BasicServicesKit';
6499
6500function hasFlash(captureSession: camera.CaptureSession): boolean {
6501  let status: boolean = false;
6502  try {
6503    status = captureSession.hasFlash();
6504  } catch (error) {
6505    // 失败返回错误码error.code并处理
6506    let err = error as BusinessError;
6507    console.error(`The hasFlash call failed. error code: ${err.code}`);
6508  }
6509  return status;
6510}
6511```
6512
6513### isFlashModeSupported<sup>(deprecated)</sup>
6514
6515isFlashModeSupported(flashMode: FlashMode): boolean
6516
6517检测闪光灯模式是否支持。
6518
6519> **说明:**
6520>从 API version 10开始支持,从API version 11开始废弃。建议使用[Flash.isFlashModeSupported](#isflashmodesupported11)替代。
6521
6522**系统能力:** SystemCapability.Multimedia.Camera.Core
6523
6524**参数:**
6525
6526| 参数名       | 类型                     | 必填 | 说明                               |
6527| --------- | ----------------------- | ---- | --------------------------------- |
6528| flashMode | [FlashMode](#flashmode) | 是   | 指定闪光灯模式。                     |
6529
6530**返回值:**
6531
6532| 类型        | 说明                          |
6533| ---------- | ----------------------------- |
6534| boolean    | 返回true表示支持该闪光灯模式,false表示不支持。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
6535
6536**错误码:**
6537
6538以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
6539
6540| 错误码ID         | 错误信息        |
6541| --------------- | --------------- |
6542| 7400103                |  Session not config.                                   |
6543
6544**示例:**
6545
6546```ts
6547import { BusinessError } from '@kit.BasicServicesKit';
6548
6549function isFlashModeSupported(captureSession: camera.CaptureSession): boolean {
6550  let status: boolean = false;
6551  try {
6552    status = captureSession.isFlashModeSupported(camera.FlashMode.FLASH_MODE_AUTO);
6553  } catch (error) {
6554    // 失败返回错误码error.code并处理
6555    let err = error as BusinessError;
6556    console.error(`The isFlashModeSupported call failed. error code: ${err.code}`);
6557  }
6558  return status;
6559}
6560```
6561
6562### setFlashMode<sup>(deprecated)</sup>
6563
6564setFlashMode(flashMode: FlashMode): void
6565
6566设置闪光灯模式。
6567
6568进行设置之前,需要先检查:
6569
65701. 设备是否支持闪光灯,可使用方法[hasFlash](#hasflashdeprecated)。
65712. 设备是否支持指定的闪光灯模式,可使用方法[isFlashModeSupported](#isflashmodesupporteddeprecated)。
6572
6573> **说明:**
6574>从 API version 10开始支持,从API version 11开始废弃。建议使用[Flash.setFlashMode](#setflashmode11)替代。
6575
6576**系统能力:** SystemCapability.Multimedia.Camera.Core
6577
6578**参数:**
6579
6580| 参数名     | 类型                    | 必填 | 说明                 |
6581| --------- | ----------------------- | ---- | -------------------- |
6582| flashMode | [FlashMode](#flashmode) | 是   | 指定闪光灯模式。       |
6583
6584**错误码:**
6585
6586以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
6587
6588| 错误码ID         | 错误信息        |
6589| --------------- | --------------- |
6590| 7400103                |  Session not config.                                   |
6591
6592**示例:**
6593
6594```ts
6595import { BusinessError } from '@kit.BasicServicesKit';
6596
6597function setFlashMode(captureSession: camera.CaptureSession): void {
6598  try {
6599    captureSession.setFlashMode(camera.FlashMode.FLASH_MODE_AUTO);
6600  } catch (error) {
6601    // 失败返回错误码error.code并处理
6602    let err = error as BusinessError;
6603    console.error(`The setFlashMode call failed. error code: ${err.code}`);
6604  }
6605}
6606```
6607
6608### getFlashMode<sup>(deprecated)</sup>
6609
6610getFlashMode(): FlashMode
6611
6612获取当前设备的闪光灯模式。
6613
6614> **说明:**
6615>从 API version 10开始支持,从API version 11开始废弃。建议使用[Flash.getFlashMode](#getflashmode11)替代。
6616
6617**系统能力:** SystemCapability.Multimedia.Camera.Core
6618
6619**返回值:**
6620
6621| 类型        | 说明                          |
6622| ---------- | ----------------------------- |
6623| [FlashMode](#flashmode)    | 获取当前设备的闪光灯模式。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
6624
6625**错误码:**
6626
6627以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
6628
6629| 错误码ID         | 错误信息        |
6630| --------------- | --------------- |
6631| 7400103                |  Session not config.                                   |
6632
6633**示例:**
6634
6635```ts
6636import { BusinessError } from '@kit.BasicServicesKit';
6637
6638function getFlashMode(captureSession: camera.CaptureSession): camera.FlashMode | undefined {
6639  let flashMode: camera.FlashMode | undefined = undefined;
6640  try {
6641    flashMode = captureSession.getFlashMode();
6642  } catch (error) {
6643    // 失败返回错误码error.code并处理
6644    let err = error as BusinessError;
6645    console.error(`The getFlashMode call failed.error code: ${err.code}`);
6646  }
6647  return flashMode;
6648}
6649```
6650
6651### isExposureModeSupported<sup>(deprecated)</sup>
6652
6653isExposureModeSupported(aeMode: ExposureMode): boolean
6654
6655检测曝光模式是否支持。
6656
6657> **说明:**
6658>从 API version 10开始支持,从API version 11开始废弃。建议使用[AutoExposure.isExposureModeSupported](#isexposuremodesupported11)替代。
6659
6660**系统能力:** SystemCapability.Multimedia.Camera.Core
6661
6662**参数:**
6663
6664| 参数名      | 类型                           | 必填  | 说明                           |
6665| -------- | -------------------------------| ---- | ----------------------------- |
6666| aeMode   | [ExposureMode](#exposuremode)  | 是   | 曝光模式。                      |
6667
6668**返回值:**
6669
6670| 类型        | 说明                          |
6671| ---------- | ----------------------------- |
6672| boolean    | 获取是否支持曝光模式。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
6673
6674**错误码:**
6675
6676以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
6677
6678| 错误码ID         | 错误信息        |
6679| --------------- | --------------- |
6680| 7400103                |  Session not config.                                   |
6681
6682**示例:**
6683
6684```ts
6685import { BusinessError } from '@kit.BasicServicesKit';
6686
6687function isExposureModeSupported(captureSession: camera.CaptureSession): boolean {
6688  let isSupported: boolean = false;
6689  try {
6690    isSupported = captureSession.isExposureModeSupported(camera.ExposureMode.EXPOSURE_MODE_LOCKED);
6691  } catch (error) {
6692    // 失败返回错误码error.code并处理
6693    let err = error as BusinessError;
6694    console.error(`The isExposureModeSupported call failed. error code: ${err.code}`);
6695  }
6696  return isSupported;
6697}
6698```
6699
6700### getExposureMode<sup>(deprecated)</sup>
6701
6702getExposureMode(): ExposureMode
6703
6704获取当前曝光模式。
6705
6706> **说明:**
6707>从 API version 10开始支持,从API version 11开始废弃。建议使用[AutoExposure.getExposureMode](#getexposuremode11)替代。
6708
6709**系统能力:** SystemCapability.Multimedia.Camera.Core
6710
6711**返回值:**
6712
6713| 类型        | 说明                          |
6714| ---------- | ----------------------------- |
6715| [ExposureMode](#exposuremode)    | 获取当前曝光模式。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
6716
6717**错误码:**
6718
6719以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
6720
6721| 错误码ID         | 错误信息        |
6722| --------------- | --------------- |
6723| 7400103                |  Session not config.                                   |
6724
6725**示例:**
6726
6727```ts
6728import { BusinessError } from '@kit.BasicServicesKit';
6729
6730function getExposureMode(captureSession: camera.CaptureSession): camera.ExposureMode | undefined {
6731  let exposureMode: camera.ExposureMode | undefined = undefined;
6732  try {
6733    exposureMode = captureSession.getExposureMode();
6734  } catch (error) {
6735    // 失败返回错误码error.code并处理
6736    let err = error as BusinessError;
6737    console.error(`The getExposureMode call failed. error code: ${err.code}`);
6738  }
6739  return exposureMode;
6740}
6741```
6742
6743### setExposureMode<sup>(deprecated)</sup>
6744
6745setExposureMode(aeMode: ExposureMode): void
6746
6747设置曝光模式。进行设置之前,需要先检查设备是否支持指定的曝光模式,可使用方法[isExposureModeSupported](#isexposuremodesupporteddeprecated)。
6748
6749> **说明:**
6750>从 API version 10开始支持,从API version 11开始废弃。建议使用[AutoExposure.setExposureMode](#setexposuremode11)替代。
6751
6752**系统能力:** SystemCapability.Multimedia.Camera.Core
6753
6754**参数:**
6755
6756| 参数名      | 类型                            | 必填 | 说明                    |
6757| -------- | -------------------------------| ---- | ----------------------- |
6758| aeMode   | [ExposureMode](#exposuremode)  | 是   | 曝光模式。                |
6759
6760**错误码:**
6761
6762以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
6763
6764| 错误码ID         | 错误信息        |
6765| --------------- | --------------- |
6766| 7400103                |  Session not config.                                   |
6767
6768**示例:**
6769
6770```ts
6771import { BusinessError } from '@kit.BasicServicesKit';
6772
6773function setExposureMode(captureSession: camera.CaptureSession): void {
6774  try {
6775    captureSession.setExposureMode(camera.ExposureMode.EXPOSURE_MODE_LOCKED);
6776  } catch (error) {
6777    // 失败返回错误码error.code并处理
6778    let err = error as BusinessError;
6779    console.error(`The setExposureMode call failed. error code: ${err.code}`);
6780  }
6781}
6782```
6783
6784### getMeteringPoint<sup>(deprecated)</sup>
6785
6786getMeteringPoint(): Point
6787
6788查询曝光区域中心点。
6789
6790> **说明:**
6791>从 API version 10开始支持,从API version 11开始废弃。建议使用[AutoExposure.getMeteringPoint](#getmeteringpoint11)替代。
6792
6793**系统能力:** SystemCapability.Multimedia.Camera.Core
6794
6795**返回值:**
6796
6797| 类型        | 说明                          |
6798| ---------- | ----------------------------- |
6799| [Point](#point)    | 获取当前曝光点。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
6800
6801**错误码:**
6802
6803以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
6804
6805| 错误码ID         | 错误信息        |
6806| --------------- | --------------- |
6807| 7400103                |  Session not config.                                   |
6808
6809**示例:**
6810
6811```ts
6812import { BusinessError } from '@kit.BasicServicesKit';
6813
6814function getMeteringPoint(captureSession: camera.CaptureSession): camera.Point | undefined {
6815  let exposurePoint: camera.Point | undefined = undefined;
6816  try {
6817    exposurePoint = captureSession.getMeteringPoint();
6818  } catch (error) {
6819    // 失败返回错误码error.code并处理
6820    let err = error as BusinessError;
6821    console.error(`The getMeteringPoint call failed. error code: ${err.code}`);
6822  }
6823  return exposurePoint;
6824}
6825```
6826
6827### setMeteringPoint<sup>(deprecated)</sup>
6828
6829setMeteringPoint(point: Point): void
6830
6831设置曝光区域中心点,曝光点应在0-1坐标系内,该坐标系左上角为{0,0},右下角为{1,1}。
6832此坐标系是以设备充电口在右侧时的横向设备方向为基准的,例如应用的预览界面布局以
6833设备充电口在下侧时的竖向方向为基准,布局宽高为{w,h},且触碰点为{x,y},
6834则转换后的坐标点为{y/h,1-x/w}。
6835
6836> **说明:**
6837>从 API version 10开始支持,从API version 11开始废弃。建议使用[AutoExposure.setMeteringPoint](#setmeteringpoint11)替代。
6838
6839**系统能力:** SystemCapability.Multimedia.Camera.Core
6840
6841**参数:**
6842
6843| 参数名           | 类型                            | 必填 | 说明                 |
6844| ------------- | -------------------------------| ---- | ------------------- |
6845| point | [Point](#point)                | 是   | 曝光点,x,y设置范围应在[0,1]之内,超过范围,如果小于0设置0,大于1设置1。             |
6846
6847**错误码:**
6848
6849以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
6850
6851| 错误码ID         | 错误信息        |
6852| --------------- | --------------- |
6853| 7400103                |  Session not config.                                   |
6854
6855**示例:**
6856
6857```ts
6858import { BusinessError } from '@kit.BasicServicesKit';
6859
6860function setMeteringPoint(captureSession: camera.CaptureSession): void {
6861  const point: camera.Point = {x: 1, y: 1};
6862  try {
6863    captureSession.setMeteringPoint(point);
6864  } catch (error) {
6865    // 失败返回错误码error.code并处理
6866    let err = error as BusinessError;
6867    console.error(`The setMeteringPoint call failed. error code: ${err.code}`);
6868  }
6869}
6870```
6871
6872### getExposureBiasRange<sup>(deprecated)</sup>
6873
6874getExposureBiasRange(): Array\<number\>
6875
6876查询曝光补偿范围。
6877
6878> **说明:**
6879>从 API version 10开始支持,从API version 11开始废弃。建议使用[AutoExposure.getExposureBiasRange](#getexposurebiasrange11)替代。
6880
6881**系统能力:** SystemCapability.Multimedia.Camera.Core
6882
6883**返回值:**
6884
6885| 类型        | 说明                          |
6886| ---------- | ----------------------------- |
6887| Array\<number\>   | 获取补偿范围的数组。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
6888
6889**错误码:**
6890
6891以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
6892
6893| 错误码ID         | 错误信息        |
6894| --------------- | --------------- |
6895| 7400103                |  Session not config.                                   |
6896
6897**示例:**
6898
6899```ts
6900import { BusinessError } from '@kit.BasicServicesKit';
6901
6902function getExposureBiasRange(captureSession: camera.CaptureSession): Array<number> {
6903  let biasRangeArray: Array<number> = [];
6904  try {
6905    biasRangeArray = captureSession.getExposureBiasRange();
6906  } catch (error) {
6907    // 失败返回错误码error.code并处理
6908    let err = error as BusinessError;
6909    console.error(`The getExposureBiasRange call failed. error code: ${err.code}`);
6910  }
6911  return biasRangeArray;
6912}
6913```
6914
6915### setExposureBias<sup>(deprecated)</sup>
6916
6917setExposureBias(exposureBias: number): void
6918
6919设置曝光补偿,曝光补偿值(EV)。
6920
6921进行设置之前,建议先通过方法[getExposureBiasRange](#getexposurebiasrangedeprecated)查询支持的范围。
6922
6923> **说明:**
6924>从 API version 10开始支持,从API version 11开始废弃。建议使用[AutoExposure.setExposureBias](#setexposurebias11)替代。
6925
6926**系统能力:** SystemCapability.Multimedia.Camera.Core
6927
6928**参数:**
6929
6930| 参数名     | 类型                            | 必填  | 说明                                                                                                                                                                                    |
6931| -------- | -------------------------------|-----|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
6932| exposureBias   | number                   | 是  | 曝光补偿,[getExposureBiasRange](#getexposurebiasrange11)查询支持的范围,如果设置超过支持范围的值,自动匹配到就近临界点。曝光补偿存在步长,如步长为0.5。则设置1.2时,获取到实际生效曝光补偿为1.0。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。传参为null或者undefined,作为0处理,曝光补偿设置0。 |
6933
6934**错误码:**
6935
6936以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
6937
6938| 错误码ID         | 错误信息        |
6939| --------------- | --------------- |
6940| 7400103                |  Session not config.                                   |
6941
6942**示例:**
6943
6944```ts
6945import { BusinessError } from '@kit.BasicServicesKit';
6946
6947function setExposureBias(captureSession: camera.CaptureSession, biasRangeArray: Array<number>): void {
6948  if (biasRangeArray && biasRangeArray.length > 0) {
6949    let exposureBias = biasRangeArray[0];
6950    try {
6951      captureSession.setExposureBias(exposureBias);
6952    } catch (error) {
6953      // 失败返回错误码error.code并处理
6954      let err = error as BusinessError;
6955      console.error(`The setExposureBias call failed. error code: ${err.code}`);
6956    }
6957  }
6958}
6959```
6960
6961### getExposureValue<sup>(deprecated)</sup>
6962
6963getExposureValue(): number
6964
6965查询当前曝光值。
6966
6967> **说明:**
6968>从 API version 10开始支持,从API version 11开始废弃。建议使用[AutoExposure.getExposureValue](#getexposurevalue11)替代。
6969
6970**系统能力:** SystemCapability.Multimedia.Camera.Core
6971
6972**返回值:**
6973
6974| 类型        | 说明                          |
6975| ---------- | ----------------------------- |
6976| number    | 获取曝光值。曝光补偿存在步长,如步长为0.5。则设置1.2时,获取到实际生效曝光补偿为1.0。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
6977
6978**错误码:**
6979
6980以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
6981
6982| 错误码ID         | 错误信息        |
6983| --------------- | --------------- |
6984| 7400103                |  Session not config.                                   |
6985
6986**示例:**
6987
6988```ts
6989import { BusinessError } from '@kit.BasicServicesKit';
6990
6991function getExposureValue(captureSession: camera.CaptureSession): number {
6992  const invalidValue: number = -1;
6993  let exposureValue: number = invalidValue;
6994  try {
6995    exposureValue = captureSession.getExposureValue();
6996  } catch (error) {
6997    // 失败返回错误码error.code并处理
6998    let err = error as BusinessError;
6999    console.error(`The getExposureValue call failed. error code: ${err.code}`);
7000  }
7001  return exposureValue;
7002}
7003```
7004
7005### isFocusModeSupported<sup>(deprecated)</sup>
7006
7007isFocusModeSupported(afMode: FocusMode): boolean
7008
7009检测对焦模式是否支持。
7010
7011> **说明:**
7012>从 API version 10开始支持,从API version 11开始废弃。建议使用[Focus.isFocusModeSupported](#isfocusmodesupported11)替代。
7013
7014**系统能力:** SystemCapability.Multimedia.Camera.Core
7015
7016**参数:**
7017
7018| 参数名      | 类型                     | 必填 | 说明                              |
7019| -------- | ----------------------- | ---- | -------------------------------- |
7020| afMode   | [FocusMode](#focusmode) | 是   | 指定的焦距模式。                    |
7021
7022**返回值:**
7023
7024| 类型        | 说明                          |
7025| ---------- | ----------------------------- |
7026| boolean    | 返回true表示支持该焦距模式,false表示不支持。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
7027
7028**错误码:**
7029
7030以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
7031
7032| 错误码ID         | 错误信息        |
7033| --------------- | --------------- |
7034| 7400103                |  Session not config.                                   |
7035
7036**示例:**
7037
7038```ts
7039import { BusinessError } from '@kit.BasicServicesKit';
7040
7041function isFocusModeSupported(captureSession: camera.CaptureSession): boolean {
7042  let status: boolean = false;
7043  try {
7044    status = captureSession.isFocusModeSupported(camera.FocusMode.FOCUS_MODE_AUTO);
7045  } catch (error) {
7046    // 失败返回错误码error.code并处理
7047    let err = error as BusinessError;
7048    console.error(`The isFocusModeSupported call failed. error code: ${err.code}`);
7049  }
7050  return status;
7051}
7052```
7053
7054### setFocusMode<sup>(deprecated)</sup>
7055
7056setFocusMode(afMode: FocusMode): void
7057
7058设置对焦模式。
7059
7060进行设置之前,需要先检查设备是否支持指定的焦距模式,可使用方法[isFocusModeSupported](#isfocusmodesupporteddeprecated)。
7061
7062> **说明:**
7063>从 API version 10开始支持,从API version 11开始废弃。建议使用[Focus.setFocusMode](#setfocusmode11)替代。
7064
7065**系统能力:** SystemCapability.Multimedia.Camera.Core
7066
7067**参数:**
7068
7069| 参数名      | 类型                     | 必填 | 说明                 |
7070| -------- | ----------------------- | ---- | ------------------- |
7071| afMode   | [FocusMode](#focusmode) | 是   | 指定的焦距模式。       |
7072
7073**错误码:**
7074
7075以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
7076
7077| 错误码ID         | 错误信息        |
7078| --------------- | --------------- |
7079| 7400103                |  Session not config.                                   |
7080
7081**示例:**
7082
7083```ts
7084import { BusinessError } from '@kit.BasicServicesKit';
7085
7086function setFocusMode(captureSession: camera.CaptureSession): void {
7087  try {
7088    captureSession.setFocusMode(camera.FocusMode.FOCUS_MODE_AUTO);
7089  } catch (error) {
7090    // 失败返回错误码error.code并处理
7091    let err = error as BusinessError;
7092    console.error(`The setFocusMode call failed. error code: ${err.code}`);
7093  }
7094}
7095```
7096
7097### getFocusMode<sup>(deprecated)</sup>
7098
7099getFocusMode(): FocusMode
7100
7101获取当前的对焦模式。
7102
7103> **说明:**
7104>从 API version 10开始支持,从API version 11开始废弃。建议使用[Focus.getFocusMode](#getfocusmode11)替代。
7105
7106**系统能力:** SystemCapability.Multimedia.Camera.Core
7107
7108**返回值:**
7109
7110| 类型        | 说明                          |
7111| ---------- | ----------------------------- |
7112| [FocusMode](#focusmode)   | 获取当前设备的焦距模式。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
7113
7114**错误码:**
7115
7116以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
7117
7118| 错误码ID         | 错误信息        |
7119| --------------- | --------------- |
7120| 7400103                |  Session not config.                                   |
7121
7122**示例:**
7123
7124```ts
7125import { BusinessError } from '@kit.BasicServicesKit';
7126
7127function getFocusMode(captureSession: camera.CaptureSession): camera.FocusMode | undefined {
7128  let afMode: camera.FocusMode | undefined = undefined;
7129  try {
7130    afMode = captureSession.getFocusMode();
7131  } catch (error) {
7132    // 失败返回错误码error.code并处理
7133    let err = error as BusinessError;
7134    console.error(`The getFocusMode call failed. error code: ${err.code}`);
7135  }
7136  return afMode;
7137}
7138```
7139
7140### setFocusPoint<sup>(deprecated)</sup>
7141
7142setFocusPoint(point: Point): void
7143
7144设置焦点,焦点应在0-1坐标系内,该坐标系左上角为{0,0},右下角为{1,1}。
7145此坐标系是以设备充电口在右侧时的横向设备方向为基准的,例如应用的预览界面布局以
7146设备充电口在下侧时的竖向方向为基准,布局宽高为{w,h},且触碰点为{x,y},
7147则转换后的坐标点为{y/h,1-x/w}。
7148
7149> **说明:**
7150>从 API version 10开始支持,从API version 11开始废弃。建议使用[Focus.setFocusPoint](#setfocuspoint11)替代。
7151
7152**系统能力:** SystemCapability.Multimedia.Camera.Core
7153
7154**参数:**
7155
7156| 参数名   | 类型                     | 必填  | 说明                 |
7157|-------| ----------------------- |-----| ------------------- |
7158| point | [Point](#point)         | 是  | 焦点。x,y设置范围应在[0,1]之内,超过范围,如果小于0设置0,大于1设置1。   |
7159
7160**错误码:**
7161
7162以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
7163
7164| 错误码ID         | 错误信息        |
7165| --------------- | --------------- |
7166| 7400103                |  Session not config.                                   |
7167
7168**示例:**
7169
7170```ts
7171import { BusinessError } from '@kit.BasicServicesKit';
7172
7173function setFocusPoint(captureSession: camera.CaptureSession): void {
7174  const focusPoint: camera.Point = {x: 1, y: 1};
7175  try {
7176    captureSession.setFocusPoint(focusPoint);
7177  } catch (error) {
7178    // 失败返回错误码error.code并处理
7179    let err = error as BusinessError;
7180    console.error(`The setFocusPoint call failed. error code: ${err.code}`);
7181  }
7182}
7183```
7184
7185### getFocusPoint<sup>(deprecated)</sup>
7186
7187getFocusPoint(): Point
7188
7189查询焦点。
7190
7191> **说明:**
7192>从 API version 10开始支持,从API version 11开始废弃。建议使用[Focus.getFocusPoint](#getfocuspoint11)替代。
7193
7194**系统能力:** SystemCapability.Multimedia.Camera.Core
7195
7196**返回值:**
7197
7198| 类型        | 说明                          |
7199| ---------- | ----------------------------- |
7200| [Point](#point)    | 用于获取当前焦点。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
7201
7202**错误码:**
7203
7204以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
7205
7206| 错误码ID         | 错误信息        |
7207| --------------- | --------------- |
7208| 7400103                |  Session not config.                                   |
7209
7210**示例:**
7211
7212```ts
7213import { BusinessError } from '@kit.BasicServicesKit';
7214
7215function getFocusPoint(captureSession: camera.CaptureSession): camera.Point | undefined {
7216  let point: camera.Point | undefined = undefined;
7217  try {
7218    point = captureSession.getFocusPoint();
7219  } catch (error) {
7220    // 失败返回错误码error.code并处理
7221    let err = error as BusinessError;
7222    console.error(`The getFocusPoint call failed. error code: ${err.code}`);
7223  }
7224  return point;
7225}
7226```
7227
7228### getFocalLength<sup>(deprecated)</sup>
7229
7230getFocalLength(): number
7231
7232查询焦距值。
7233
7234> **说明:**
7235>从 API version 10开始支持,从API version 11开始废弃。建议使用[Focus.getFocalLength](#getfocallength11)替代。
7236
7237**系统能力:** SystemCapability.Multimedia.Camera.Core
7238
7239**返回值:**
7240
7241| 类型        | 说明                          |
7242| ---------- | ----------------------------- |
7243| number    | 用于获取当前焦距。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
7244
7245**错误码:**
7246
7247以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
7248
7249| 错误码ID         | 错误信息        |
7250| --------------- | --------------- |
7251| 7400103                |  Session not config.                                   |
7252
7253**示例:**
7254
7255```ts
7256import { BusinessError } from '@kit.BasicServicesKit';
7257
7258function getFocalLength(captureSession: camera.CaptureSession): number {
7259  const invalidValue: number = -1;
7260  let focalLength: number = invalidValue;
7261  try {
7262    focalLength = captureSession.getFocalLength();
7263  } catch (error) {
7264    // 失败返回错误码error.code并处理
7265    let err = error as BusinessError;
7266    console.error(`The getFocalLength call failed. error code: ${err.code}`);
7267  }
7268  return focalLength;
7269}
7270```
7271
7272### getZoomRatioRange<sup>(deprecated)</sup>
7273
7274getZoomRatioRange(): Array\<number\>
7275
7276获取支持的变焦范围。
7277
7278> **说明:**
7279>从 API version 10开始支持,从API version 11开始废弃。建议使用[Zoom.getZoomRatioRange](#getzoomratiorange11)替代。
7280
7281**系统能力:** SystemCapability.Multimedia.Camera.Core
7282
7283**返回值:**
7284
7285| 类型        | 说明                          |
7286| ---------- | ----------------------------- |
7287| Array\<number\>   | 用于获取可变焦距比范围,返回的数组包括其最小值和最大值。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
7288
7289**错误码:**
7290
7291以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
7292
7293| 错误码ID         | 错误信息        |
7294| --------------- | --------------- |
7295| 7400103                |  Session not config.                                   |
7296
7297**示例:**
7298
7299```ts
7300import { BusinessError } from '@kit.BasicServicesKit';
7301
7302function getZoomRatioRange(captureSession: camera.CaptureSession): Array<number> {
7303  let zoomRatioRange: Array<number> = [];
7304  try {
7305    zoomRatioRange = captureSession.getZoomRatioRange();
7306  } catch (error) {
7307    // 失败返回错误码error.code并处理
7308    let err = error as BusinessError;
7309    console.error(`The getZoomRatioRange call failed. error code: ${err.code}`);
7310  }
7311  return zoomRatioRange;
7312}
7313```
7314
7315### setZoomRatio<sup>(deprecated)</sup>
7316
7317setZoomRatio(zoomRatio: number): void
7318
7319设置变焦比,变焦精度最高为小数点后两位,如果设置超过支持的精度范围,则只保留精度范围内数值。
7320
7321> **说明:**
7322>从 API version 10开始支持,从API version 11开始废弃。建议使用[Zoom.setZoomRatio](#setzoomratio11)替代。
7323
7324**系统能力:** SystemCapability.Multimedia.Camera.Core
7325
7326**参数:**
7327
7328| 参数名       | 类型                  | 必填  | 说明                 |
7329| --------- | -------------------- |-----| ------------------- |
7330| zoomRatio | number               | 是  | 可变焦距比,通过[getZoomRatioRange](#getzoomratiorange11)获取支持的变焦范围,如果设置超过支持范围的值,则只保留精度范围内数值。传参为null或者undefined,作为0处理,变焦设置最小值。 |
7331
7332**错误码:**
7333
7334以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
7335
7336| 错误码ID         | 错误信息        |
7337| --------------- | --------------- |
7338| 7400103                |  Session not config.                                   |
7339
7340**示例:**
7341
7342```ts
7343import { BusinessError } from '@kit.BasicServicesKit';
7344
7345function setZoomRatio(captureSession: camera.CaptureSession, zoomRatioRange: Array<number>): void {
7346  if (zoomRatioRange === undefined || zoomRatioRange.length <= 0) {
7347    return;
7348  }
7349  let zoomRatio = zoomRatioRange[0];
7350  try {
7351    captureSession.setZoomRatio(zoomRatio);
7352  } catch (error) {
7353    // 失败返回错误码error.code并处理
7354    let err = error as BusinessError;
7355    console.error(`The setZoomRatio call failed. error code: ${err.code}`);
7356  }
7357}
7358```
7359
7360### getZoomRatio<sup>(deprecated)</sup>
7361
7362getZoomRatio(): number
7363
7364获取当前的变焦比。
7365
7366> **说明:**
7367>从 API version 10开始支持,从API version 11开始废弃。建议使用[Zoom.getZoomRatio](#getzoomratio11)替代。
7368
7369**系统能力:** SystemCapability.Multimedia.Camera.Core
7370
7371**返回值:**
7372
7373| 类型        | 说明                          |
7374| ---------- | ----------------------------- |
7375| number    | 获取当前的变焦比结果。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
7376
7377**错误码:**
7378
7379以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
7380
7381| 错误码ID         | 错误信息        |
7382| --------------- | --------------- |
7383| 7400103                |  Session not config.                                   |
7384
7385**示例:**
7386
7387```ts
7388import { BusinessError } from '@kit.BasicServicesKit';
7389
7390function getZoomRatio(captureSession: camera.CaptureSession): number {
7391  const invalidValue: number = -1;
7392  let zoomRatio: number = invalidValue;
7393  try {
7394    zoomRatio = captureSession.getZoomRatio();
7395  } catch (error) {
7396    // 失败返回错误码error.code并处理
7397    let err = error as BusinessError;
7398    console.error(`The getZoomRatio call failed. error code: ${err.code}`);
7399  }
7400  return zoomRatio;
7401}
7402```
7403
7404### isVideoStabilizationModeSupported<sup>(deprecated)</sup>
7405
7406isVideoStabilizationModeSupported(vsMode: VideoStabilizationMode): boolean
7407
7408查询是否支持指定的视频防抖模式。
7409
7410> **说明:**
7411>从 API version 10开始支持,从API version 11开始废弃。建议使用[Stabilization.isVideoStabilizationModeSupported](#isvideostabilizationmodesupported11)替代。
7412
7413**系统能力:** SystemCapability.Multimedia.Camera.Core
7414
7415**参数:**
7416
7417| 参数名      | 类型                                              | 必填 | 说明                             |
7418| -------- | ------------------------------------------------- | ---- | ------------------------------ |
7419| vsMode   | [VideoStabilizationMode](#videostabilizationmode) | 是   | 视频防抖模式。传参为null或者undefined,作为0处理,超级防抖模式关闭。              |
7420
7421**返回值:**
7422
7423| 类型        | 说明                          |
7424| ---------- | ----------------------------- |
7425| boolean    | 返回视频防抖模式是否支持,true表示支持,false表示不支持。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
7426
7427**错误码:**
7428
7429以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
7430
7431| 错误码ID         | 错误信息        |
7432| --------------- | --------------- |
7433| 7400103                |  Session not config.                                   |
7434
7435**示例:**
7436
7437```ts
7438import { BusinessError } from '@kit.BasicServicesKit';
7439
7440function isVideoStabilizationModeSupported(captureSession: camera.CaptureSession): boolean {
7441  let isSupported: boolean = false;
7442  try {
7443    isSupported = captureSession.isVideoStabilizationModeSupported(camera.VideoStabilizationMode.OFF);
7444  } catch (error) {
7445    // 失败返回错误码error.code并处理
7446    let err = error as BusinessError;
7447    console.error(`The isVideoStabilizationModeSupported call failed. error code: ${err.code}`);
7448  }
7449  return isSupported;
7450}
7451```
7452
7453### getActiveVideoStabilizationMode<sup>(deprecated)</sup>
7454
7455getActiveVideoStabilizationMode(): VideoStabilizationMode
7456
7457查询当前正在使用的视频防抖模式。
7458
7459> **说明:**
7460>从 API version 10开始支持,从API version 11开始废弃。建议使用[Stabilization.getActiveVideoStabilizationMode](#getactivevideostabilizationmode11)替代。
7461
7462**系统能力:** SystemCapability.Multimedia.Camera.Core
7463
7464**返回值:**
7465
7466| 类型        | 说明                          |
7467| ---------- | ----------------------------- |
7468| [VideoStabilizationMode](#videostabilizationmode)    | 视频防抖是否正在使用。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。 |
7469
7470**错误码:**
7471
7472以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
7473
7474| 错误码ID         | 错误信息        |
7475| --------------- | --------------- |
7476| 7400103                |  Session not config.                                   |
7477
7478**示例:**
7479
7480```ts
7481import { BusinessError } from '@kit.BasicServicesKit';
7482
7483function getActiveVideoStabilizationMode(captureSession: camera.CaptureSession): camera.VideoStabilizationMode | undefined {
7484  let vsMode: camera.VideoStabilizationMode | undefined = undefined;
7485  try {
7486    vsMode = captureSession.getActiveVideoStabilizationMode();
7487  } catch (error) {
7488    // 失败返回错误码error.code并处理
7489    let err = error as BusinessError;
7490    console.error(`The getActiveVideoStabilizationMode call failed. error code: ${err.code}`);
7491  }
7492  return vsMode;
7493}
7494```
7495
7496### setVideoStabilizationMode<sup>(deprecated)</sup>
7497
7498setVideoStabilizationMode(mode: VideoStabilizationMode): void
7499
7500设置视频防抖模式。需要先检查设备是否支持对应的防抖模式,可以通过[isVideoStabilizationModeSupported](#isvideostabilizationmodesupporteddeprecated)方法判断所设置的模式是否支持。
7501
7502> **说明:**
7503>从 API version 10开始支持,从API version 11开始废弃。建议使用[Stabilization.setVideoStabilizationMode](#setvideostabilizationmode11)替代。
7504
7505**系统能力:** SystemCapability.Multimedia.Camera.Core
7506
7507**参数:**
7508
7509| 参数名      | 类型                                              | 必填 | 说明                    |
7510| -------- | ------------------------------------------------- | ---- | --------------------- |
7511| mode     | [VideoStabilizationMode](#videostabilizationmode) | 是   | 需要设置的视频防抖模式。传参为null或者undefined,作为0处理,超级防抖模式关闭。   |
7512
7513**错误码:**
7514
7515以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
7516
7517| 错误码ID         | 错误信息        |
7518| --------------- | --------------- |
7519| 7400103                |  Session not config.                                   |
7520
7521**示例:**
7522
7523```ts
7524import { BusinessError } from '@kit.BasicServicesKit';
7525
7526function setVideoStabilizationMode(captureSession: camera.CaptureSession): void {
7527  try {
7528    captureSession.setVideoStabilizationMode(camera.VideoStabilizationMode.OFF);
7529  } catch (error) {
7530    // 失败返回错误码error.code并处理
7531    let err = error as BusinessError;
7532    console.error(`The setVideoStabilizationMode call failed. error code: ${err.code}`);
7533  }
7534}
7535```
7536
7537### on('focusStateChange')<sup>(deprecated)</sup>
7538
7539on(type: 'focusStateChange', callback: AsyncCallback\<FocusState\>): void
7540
7541监听相机聚焦的状态变化,通过注册回调函数获取结果。使用callback异步回调。
7542
7543> **说明:**
7544> 从 API version 10开始支持,从API version 11开始废弃。建议使用[VideoSession.on('focusStateChange')](#onfocusstatechange11-1)替代。
7545>
7546> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
7547
7548**系统能力:** SystemCapability.Multimedia.Camera.Core
7549
7550**参数:**
7551
7552| 参数名     | 类型                                      | 必填 | 说明                       |
7553| -------- | ----------------------------------------- | ---- | ------------------------ |
7554| type     | string                                    | 是   | 监听事件,固定为'focusStateChange',session 创建成功可监听。仅当自动对焦模式时,且相机对焦状态发生改变时可触发该事件。 |
7555| callback | AsyncCallback\<[FocusState](#focusstate)\> | 是   | 回调函数,用于获取当前对焦状态。  |
7556
7557**示例:**
7558
7559```ts
7560import { BusinessError } from '@kit.BasicServicesKit';
7561
7562function registerFocusStateChange(captureSession: camera.CaptureSession): void {
7563  captureSession.on('focusStateChange', (err: BusinessError, focusState: camera.FocusState) => {
7564    if (err !== undefined && err.code !== 0) {
7565      console.error(`Callback Error, errorCode: ${err.code}`);
7566      return;
7567    }
7568    console.info(`Focus state: ${focusState}`);
7569  });
7570}
7571```
7572
7573### off('focusStateChange')<sup>(deprecated)</sup>
7574
7575off(type: 'focusStateChange', callback?: AsyncCallback\<FocusState\>): void
7576
7577注销监听相机聚焦的状态变化。
7578
7579> **说明:**
7580>从 API version 10开始支持,从API version 11开始废弃。建议使用[VideoSession.off('focusStateChange')](#offfocusstatechange11-1)替代。
7581
7582**系统能力:** SystemCapability.Multimedia.Camera.Core
7583
7584**参数:**
7585
7586| 参数名     | 类型                                      | 必填 | 说明                       |
7587| -------- | ----------------------------------------- | ---- | ------------------------ |
7588| type     | string                                    | 是   | 监听事件,固定为'focusStateChange',session 创建成功可监听。|
7589| callback | AsyncCallback\<[FocusState](#focusstate)\> | 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
7590
7591**示例:**
7592
7593```ts
7594function unregisterFocusStateChange(captureSession: camera.CaptureSession): void {
7595  captureSession.off('focusStateChange');
7596}
7597```
7598
7599### on('error')<sup>(deprecated)</sup>
7600
7601on(type: 'error', callback: ErrorCallback): void
7602
7603监听拍照会话的错误事件,通过注册回调函数获取结果。使用callback异步回调。
7604
7605> **说明:**
7606>
7607> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
7608
7609> **说明:**
7610>从 API version 10开始支持,从API version 11开始废弃。建议使用[VideoSession.on('error')](#onerror11-1)替代。
7611
7612**系统能力:** SystemCapability.Multimedia.Camera.Core
7613
7614**参数:**
7615
7616| 参数名     | 类型                                                                       | 必填 | 说明                           |
7617| -------- |--------------------------------------------------------------------------| ---- | ------------------------------ |
7618| type     | string                                                                   | 是   | 监听事件,固定为'error',session创建成功之后可监听该接口。session调用相关接口出现错误时会触发该事件,比如调用[beginConfig](#beginconfigdeprecated),[commitConfig](#commitconfigdeprecated-1),[addInput](#addinputdeprecated)等接口发生错误时返回错误信息。 |
7619| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | 是   | 回调函数,用于获取错误信息。返回错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。        |
7620
7621**示例:**
7622
7623```ts
7624import { BusinessError } from '@kit.BasicServicesKit';
7625
7626function registerCaptureSessionError(captureSession: camera.CaptureSession): void {
7627  captureSession.on('error', (error: BusinessError) => {
7628    console.error(`Capture session error code: ${error.code}`);
7629  });
7630}
7631```
7632
7633### off('error')<sup>(deprecated)</sup>
7634
7635off(type: 'error', callback?: ErrorCallback): void
7636
7637注销监听拍照会话的错误事件,通过注册回调函数获取结果。
7638
7639> **说明:**
7640>从 API version 10开始支持,从API version 11开始废弃。建议使用[VideoSession.off('error')](#offerror11-1)替代。
7641
7642**系统能力:** SystemCapability.Multimedia.Camera.Core
7643
7644**参数:**
7645
7646| 参数名     | 类型                                                          | 必填 | 说明                           |
7647| -------- | ----------------------------------------------------------- | ---- | ------------------------------ |
7648| type     | string                                                      | 是   | 监听事件,固定为'error',session创建成功之后可监听该接口。 |
7649| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback)| 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
7650
7651**示例:**
7652
7653```ts
7654function unregisterCaptureSessionError(captureSession: camera.CaptureSession): void {
7655  captureSession.off('error');
7656}
7657```
7658## ColorManagementQuery<sup>12+</sup>
7659
7660色彩管理类,用于查询色彩空间参数。
7661
7662### getSupportedColorSpaces<sup>12+</sup>
7663
7664getSupportedColorSpaces(): Array\<colorSpaceManager.ColorSpace\>
7665
7666获取支持的色彩空间列表。
7667
7668**系统能力:** SystemCapability.Multimedia.Camera.Core
7669
7670**返回值:**
7671
7672| 类型                                             | 说明                           |
7673| ----------------------------------------------- | ---------------------------- |
7674| Array<[colorSpaceManager.ColorSpace](../apis-arkgraphics2d/js-apis-colorSpaceManager.md#colorspace)>| 支持的色彩空间列表。     |
7675
7676**错误码:**
7677
7678以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
7679
7680| 错误码ID         | 错误信息        |
7681| --------------- | --------------- |
7682| 7400103         |  Session not config, only throw in session usage.                       |
7683
7684**示例:**
7685
7686```ts
7687import { BusinessError } from '@kit.BasicServicesKit';
7688import { colorSpaceManager } from '@kit.ArkGraphics2D';
7689
7690function getSupportedColorSpaces(session: camera.PhotoSession): Array<colorSpaceManager.ColorSpace> {
7691  let colorSpaces: Array<colorSpaceManager.ColorSpace> = [];
7692  try {
7693    colorSpaces = session.getSupportedColorSpaces();
7694  } catch (error) {
7695    let err = error as BusinessError;
7696    console.error(`The getSupportedColorSpaces call failed. error code: ${err.code}`);
7697  }
7698  return colorSpaces;
7699}
7700```
7701## ColorManagement<sup>12+</sup>
7702
7703ColorManagement extends [ColorManagementQuery](#colormanagementquery12)
7704
7705色彩管理类,继承自[ColorManagementQuery](#colormanagementquery12),用于设置色彩空间参数。
7706
7707### setColorSpace<sup>12+</sup>
7708
7709setColorSpace(colorSpace: colorSpaceManager.ColorSpace): void
7710
7711设置色彩空间。可以先通过[getSupportedColorSpaces](#getsupportedcolorspaces12)获取当前设备所支持的ColorSpaces。
7712
7713**P3广色域与HDR高动态范围成像**
7714
7715应用可以下发不同的色彩空间(ColorSpace)参数来支持P3广色域以及HDR的功能。
7716当应用不主动设置色彩空间时,拍照以及录像模式默认为HDR拍摄效果。
7717在拍照模式下设置HDR高显效果可直接支持P3色域。
7718应用针对不同模式使能HDR效果以及设置的色彩空间可参考下表。
7719
7720**录像模式:**
7721
7722| SDR/HRD拍摄         | CameraFormat             | ColorSpace       |
7723|--------------------|--------------------------|------------------|
7724| SDR                | CAMERA_FORMAT_YUV_420_SP | BT709_LIMIT      |
7725| HDR_VIVID(Default) | CAMERA_FORMAT_YCRCB_P010 | BT2020_HLG_LIMIT |
7726
7727**拍照模式:**
7728
7729| SDR/HRD拍摄    | ColorSpace |
7730|--------------|------------|
7731| SDR          | SRGB       |
7732| HDR(Default) | DISPLAY_P3 |
7733
7734**系统能力:** SystemCapability.Multimedia.Camera.Core
7735
7736**参数:**
7737
7738| 参数名         | 类型                 | 必填 | 说明                      |
7739| ------------ |---------------------- | -- | -------------------------- |
7740| colorSpace | [colorSpaceManager.ColorSpace](../apis-arkgraphics2d/js-apis-colorSpaceManager.md#colorspace)  | 是 | 色彩空间,通过[getSupportedColorSpaces](#getsupportedcolorspaces12)接口获取。   |
7741
7742**错误码:**
7743
7744以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
7745
7746| 错误码ID         | 错误信息        |
7747| --------------- | --------------- |
7748| 7400101         |  Parameter missing or parameter type incorrect.     |
7749| 7400102         |  The colorSpace does not match the format.     |
7750| 7400103         |  Session not config.                           |
7751| 7400201         |  Camera service fatal error.                   |
7752
7753**示例:**
7754
7755```ts
7756import { BusinessError } from '@kit.BasicServicesKit';
7757import { colorSpaceManager } from '@kit.ArkGraphics2D';
7758
7759function setColorSpace(session: camera.PhotoSession, colorSpaces: Array<colorSpaceManager.ColorSpace>): void {
7760  if (colorSpaces === undefined || colorSpaces.length <= 0) {
7761    return;
7762  }
7763  try {
7764    session.setColorSpace(colorSpaces[0]);
7765  } catch (error) {
7766    let err = error as BusinessError;
7767    console.error(`The setColorSpace call failed, error code: ${err.code}`);
7768  }
7769}
7770```
7771
7772### getActiveColorSpace<sup>12+</sup>
7773
7774getActiveColorSpace(): colorSpaceManager.ColorSpace
7775
7776获取当前设置的色彩空间。
7777
7778**系统能力:** SystemCapability.Multimedia.Camera.Core
7779
7780**返回值:**
7781
7782| 类型                                             | 说明                           |
7783| ----------------------------------------------- | ---------------------------- |
7784| [colorSpaceManager.ColorSpace](../apis-arkgraphics2d/js-apis-colorSpaceManager.md#colorspace)               | 当前设置的色彩空间。                |
7785
7786**错误码:**
7787
7788以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
7789
7790| 错误码ID         | 错误信息        |
7791| --------------- | --------------- |
7792| 7400103                |  Session not config.                                   |
7793
7794**示例:**
7795
7796```ts
7797import { BusinessError } from '@kit.BasicServicesKit';
7798import { colorSpaceManager } from '@kit.ArkGraphics2D';
7799
7800function getActiveColorSpace(session: camera.PhotoSession): colorSpaceManager.ColorSpace | undefined {
7801  let colorSpace: colorSpaceManager.ColorSpace | undefined = undefined;
7802  try {
7803    colorSpace = session.getActiveColorSpace();
7804  } catch (error) {
7805    let err = error as BusinessError;
7806    console.error(`The getActiveColorSpace call failed. error code: ${err.code}`);
7807  }
7808  return colorSpace;
7809}
7810```
7811
7812## AutoDeviceSwitchQuery<sup>13+</sup>
7813
7814自动切换镜头查询类,用于查询设备是否支持自动切换镜头。
7815
7816### isAutoDeviceSwitchSupported<sup>13+</sup>
7817
7818isAutoDeviceSwitchSupported(): boolean
7819
7820查询设备是否支持自动切换镜头能力。
7821
7822**系统能力:** SystemCapability.Multimedia.Camera.Core
7823
7824**返回值:**
7825
7826| 类型                                             | 说明          |
7827| ----------------------------------------------- |-------------|
7828| boolean               | 是否支持自动切换镜头。 |
7829
7830**错误码:**
7831
7832以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
7833
7834| 错误码ID         | 错误信息                                              |
7835| --------------- |---------------------------------------------------|
7836| 7400103         | Session not config, only throw in session usage.  |
7837
7838**示例:**
7839
7840```ts
7841import { BusinessError } from '@kit.BasicServicesKit';
7842
7843function isAutoDeviceSwitchSupported(session: camera.PhotoSession): boolean {
7844  let isSupported = false;
7845  try {
7846    isSupported = session.isAutoDeviceSwitchSupported();
7847  } catch (error) {
7848    let err = error as BusinessError;
7849    console.error(`The isAutoDeviceSwitchSupported call failed, error code: ${err.code}`);
7850  }
7851  return isSupported;
7852}
7853```
7854
7855## AutoDeviceSwitch<sup>13+</sup>
7856
7857AutoDeviceSwitch extends [AutoDeviceSwitchQuery](#autodeviceswitchquery13)
7858
7859自动切换镜头类,继承自[AutoDeviceSwitchQuery](#autodeviceswitchquery13),用于使能或去使能自动切换镜头。
7860
7861使用建议:自动切换镜头功能由系统自动完成输入设备切换、会话配置和参数接续,
7862如系统发现镜头切换时,两颗镜头的变焦范围不一致,则会通过[AutoDeviceSwitchStatus](#autodeviceswitchstatus13)中的isDeviceCapabilityChanged字段告知应用,
7863但仍需要应用自己处理UX的变更(如变焦范围的调整,需要重新通过[getZoomRatioRange](#getzoomratiorange11)接口获取数据并更新UX),
7864因此更适用于极简UX交换的场景。
7865
7866### enableAutoDeviceSwitch<sup>13+</sup>
7867
7868enableAutoDeviceSwitch(enabled: boolean): void
7869
7870使能或去使能自动切换镜头。可以先通过[isAutoDeviceSwitchSupported](#isautodeviceswitchsupported13)获取当前设备是否支持自动切换镜头。
7871
7872> **说明:**
7873> 该接口仅用于有多个前置镜头的折叠设备,在不同的折叠状态下可自动切换到当前可使用的前置镜头。无法实现前后置镜头的切换。
7874
7875**系统能力:** SystemCapability.Multimedia.Camera.Core
7876
7877**参数:**
7878
7879| 参数名         | 类型  | 必填 | 说明  |
7880| ----------- |---------------------- |---| -------------------------- |
7881| enabled | boolean  | 是 | 使能或去使能自动切换镜头。   |
7882
7883**错误码:**
7884
7885以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
7886
7887| 错误码ID   | 错误信息                                                                                                                                       |
7888|----------|------------------------------------------------------------------------------------------------------------------------------------------------|
7889| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameters verification failed. |
7890| 7400102  | Operation not allowed.                                                                                                                         |
7891| 7400103  | Session not config.                                                                                                                            |
7892| 7400201  | Camera service fatal error.                                                                                                                    |
7893
7894**示例:**
7895
7896```ts
7897import { BusinessError } from '@kit.BasicServicesKit';
7898
7899function enableAutoDeviceSwitch(session: camera.PhotoSession, isEnable: boolean): void {
7900  try {
7901    session.enableAutoDeviceSwitch(isEnable);
7902  } catch (error) {
7903    let err = error as BusinessError;
7904    console.error(`The enableAutoDeviceSwitch call failed, error code: ${err.code}`);
7905  }
7906}
7907```
7908
7909## PreconfigType<sup>12+</sup>
7910
7911枚举,提供预配置的类型。
7912
7913**系统能力:** SystemCapability.Multimedia.Camera.Core
7914
7915| 名称                      | 值 | 说明         |
7916|-------------------------|---|------------|
7917| PRECONFIG_720P          | 0 | 720P预配置。   |
7918| PRECONFIG_1080P         | 1 | 1080P预配置。  |
7919| PRECONFIG_4K            | 2 | 4K预配置。     |
7920| PRECONFIG_HIGH_QUALITY  | 3 | 高质量预配置。    |
7921
7922## PreconfigRatio<sup>12+</sup>
7923
7924枚举,提供预配置的分辨率比例。
7925
7926**系统能力:** SystemCapability.Multimedia.Camera.Core
7927
7928| 名称                       | 值 | 说明      |
7929|--------------------------|---|---------|
7930| PRECONFIG_RATIO_1_1      | 0 | 1:1画幅。  |
7931| PRECONFIG_RATIO_4_3      | 1 | 4:3画幅。  |
7932| PRECONFIG_RATIO_16_9     | 2 | 16:9画幅。 |
7933
7934## PhotoSession<sup>11+</sup>
7935
7936PhotoSession extends [Session](#session11), [Flash](#flash11), [AutoExposure](#autoexposure11), [Focus](#focus11), [Zoom](#zoom11), [ColorManagement](#colormanagement12), [AutoDeviceSwitch](#autodeviceswitch13)
7937
7938普通拍照模式会话类,提供了对闪光灯、曝光、对焦、变焦、色彩空间的操作。
7939
7940> **说明:**
7941>
7942> 默认的拍照模式,用于拍摄标准照片。支持多种照片格式和分辨率,适合大多数日常拍摄场景。
7943
7944### canPreconfig<sup>12+</sup>
7945
7946canPreconfig(preconfigType: PreconfigType, preconfigRatio?: PreconfigRatio): boolean
7947
7948查询当前Session是否支持指定的预配置类型。
7949
7950**系统能力:** SystemCapability.Multimedia.Camera.Core
7951
7952**参数:**
7953
7954| 参数名            | 类型                                  | 必填  | 说明              |
7955|----------------|-------------------------------------|-----|-----------------|
7956| preconfigType  | [PreconfigType](#preconfigtype12)   | 是   | 指定配置预期分辨率。      |
7957| preconfigRatio | [PreconfigRatio](#preconfigratio12) | 否   | 可选画幅比例,默认为4:3。  |
7958
7959**返回值:**
7960
7961| 类型      | 说明                                      |
7962|---------|-----------------------------------------|
7963| boolean | true: 支持指定预配值类型。<br/>false: 不支持指定预配值类型。 |
7964
7965**错误码:**
7966
7967以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
7968
7969| 错误码ID   | 错误信息                        |
7970|---------|-----------------------------|
7971| 7400201 | Camera service fatal error. |
7972
7973**示例:**
7974
7975```ts
7976function testCanPreconfig(photoSession: camera.PhotoSession, preconfigType: camera.PreconfigType,
7977  preconfigRatio: camera.PreconfigRatio): void {
7978  try {
7979    let result = photoSession.canPreconfig(preconfigType, preconfigRatio);
7980    console.info(`canPreconfig ${preconfigType} ${preconfigRatio} result is : ${result}`);
7981  } catch (error) {
7982    let err = error as BusinessError;
7983    console.error(`The canPreconfig call failed. error code: ${err.code}`);
7984  }
7985}
7986```
7987
7988### preconfig<sup>12+</sup>
7989
7990preconfig(preconfigType: PreconfigType, preconfigRatio?: PreconfigRatio): void
7991
7992对当前Session进行预配置。
7993
7994**系统能力:** SystemCapability.Multimedia.Camera.Core
7995
7996**参数:**
7997
7998| 参数名            | 类型                                  | 必填  | 说明              |
7999|----------------|-------------------------------------|-----|-----------------|
8000| preconfigType  | [PreconfigType](#preconfigtype12)   | 是   | 指定配置预期分辨率。      |
8001| preconfigRatio | [PreconfigRatio](#preconfigratio12) | 否   | 可选画幅比例,默认为4:3。  |
8002
8003**错误码:**
8004
8005以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
8006
8007| 错误码ID   | 错误信息                        |
8008|---------|-----------------------------|
8009| 7400201 | Camera service fatal error. |
8010
8011**示例:**
8012
8013```ts
8014function testPreconfig(photoSession: camera.PhotoSession, preconfigType: camera.PreconfigType,
8015  preconfigRatio: camera.PreconfigRatio): void {
8016  try {
8017    photoSession.preconfig(preconfigType, preconfigRatio);
8018    console.info(`preconfig ${preconfigType} ${preconfigRatio} success`);
8019  } catch (error) {
8020    let err = error as BusinessError;
8021    console.error(`The preconfig call failed. error code: ${err.code}`);
8022  }
8023}
8024```
8025
8026### on('error')<sup>11+</sup>
8027
8028on(type: 'error', callback: ErrorCallback): void
8029
8030监听普通拍照会话的错误事件,通过注册回调函数获取结果。使用callback异步回调。
8031
8032> **说明:**
8033>
8034> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
8035
8036**系统能力:** SystemCapability.Multimedia.Camera.Core
8037
8038**参数:**
8039
8040| 参数名     | 类型                                                          | 必填 | 说明                           |
8041| -------- | ----------------------------------------------------------- | ---- | ------------------------------ |
8042| type     | string                                                      | 是   | 监听事件,固定为'error',session创建成功之后可监听该接口。session调用相关接口出现错误时会触发该事件,比如调用[beginConfig](#beginconfig11),[commitConfig](#commitconfig11-1),[addInput](#addinput11)等接口发生错误时返回错误信息。 |
8043| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback)| 是   | 回调函数,用于获取错误信息。返回错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。        |
8044
8045**示例:**
8046
8047```ts
8048import { BusinessError } from '@kit.BasicServicesKit';
8049
8050function callback(err: BusinessError): void {
8051  console.error(`Photo session error code: ${err.code}`);
8052}
8053
8054function registerSessionError(photoSession: camera.PhotoSession): void {
8055  photoSession.on('error', callback);
8056}
8057```
8058
8059### off('error')<sup>11+</sup>
8060
8061off(type: 'error', callback?: ErrorCallback): void
8062
8063注销监听普通拍照会话的错误事件,通过注册回调函数获取结果。
8064
8065**系统能力:** SystemCapability.Multimedia.Camera.Core
8066
8067**参数:**
8068
8069| 参数名     | 类型                            | 必填 | 说明                           |
8070| -------- | -------------------------------- | ---- | ------------------------------ |
8071| type     | string                           | 是   | 监听事件,固定为'error',session创建成功之后可监听该接口。 |
8072| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback)| 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
8073
8074**示例:**
8075
8076```ts
8077function unregisterSessionError(photoSession: camera.PhotoSession): void {
8078  photoSession.off('error');
8079}
8080```
8081
8082### on('focusStateChange')<sup>11+</sup>
8083
8084on(type: 'focusStateChange', callback: AsyncCallback\<FocusState\>): void
8085
8086监听相机聚焦的状态变化,通过注册回调函数获取结果。使用callback异步回调。
8087
8088> **说明:**
8089>
8090> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
8091
8092**系统能力:** SystemCapability.Multimedia.Camera.Core
8093
8094**参数:**
8095
8096| 参数名     | 类型                    | 必填 | 说明                       |
8097| -------- | ---------------- | ---- | ------------------------ |
8098| type     | string                                    | 是   | 监听事件,固定为'focusStateChange',session创建成功可监听。仅当自动对焦模式时,且相机对焦状态发生改变时可触发该事件。 |
8099| callback | AsyncCallback\<[FocusState](#focusstate)\> | 是   | 回调函数,用于获取当前对焦状态。  |
8100
8101**示例:**
8102
8103```ts
8104import { BusinessError } from '@kit.BasicServicesKit';
8105
8106function callback(err: BusinessError, focusState: camera.FocusState): void {
8107  if (err !== undefined && err.code !== 0) {
8108    console.error(`Callback Error, errorCode: ${err.code}`);
8109    return;
8110  }
8111  console.info(`Focus state: ${focusState}`);
8112}
8113
8114function registerFocusStateChange(photoSession: camera.PhotoSession): void {
8115  photoSession.on('focusStateChange', callback);
8116}
8117```
8118
8119### off('focusStateChange')<sup>11+</sup>
8120
8121off(type: 'focusStateChange', callback?: AsyncCallback\<FocusState\>): void
8122
8123注销监听相机聚焦的状态变化。
8124
8125**系统能力:** SystemCapability.Multimedia.Camera.Core
8126
8127**参数:**
8128
8129| 参数名     | 类型                                      | 必填 | 说明                       |
8130| -------- | ----------------------------------------- | ---- | ------------------------ |
8131| type     | string                                    | 是   | 监听事件,固定为'focusStateChange',session创建成功可监听。 |
8132| callback | AsyncCallback\<[FocusState](#focusstate)\> | 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
8133
8134**示例:**
8135
8136```ts
8137function unregisterFocusStateChange(photoSession: camera.PhotoSession): void {
8138  photoSession.off('focusStateChange');
8139}
8140```
8141
8142### on('smoothZoomInfoAvailable')<sup>11+</sup>
8143
8144on(type: 'smoothZoomInfoAvailable', callback: AsyncCallback\<SmoothZoomInfo\>): void
8145
8146监听相机平滑变焦的状态变化,通过注册回调函数获取结果。使用callback异步回调。
8147
8148> **说明:**
8149>
8150> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
8151
8152**系统能力:** SystemCapability.Multimedia.Camera.Core
8153
8154**参数:**
8155
8156| 参数名     | 类型                   | 必填 | 说明                       |
8157| -------- | ----------------------- | ---- | ------------------------ |
8158| type     | string                  | 是   | 监听事件,固定为'smoothZoomInfoAvailable',session创建成功可监听。|
8159| callback | AsyncCallback\<[SmoothZoomInfo](#smoothzoominfo11)\> | 是   | 回调函数,用于获取当前平滑变焦状态。  |
8160
8161**示例:**
8162
8163```ts
8164import { BusinessError } from '@kit.BasicServicesKit';
8165
8166function callback(err: BusinessError, smoothZoomInfo: camera.SmoothZoomInfo): void {
8167  if (err !== undefined && err.code !== 0) {
8168    console.error(`Callback Error, errorCode: ${err.code}`);
8169    return;
8170  }
8171  console.info(`The duration of smooth zoom: ${smoothZoomInfo.duration}`);
8172}
8173
8174function registerSmoothZoomInfo(photoSession: camera.PhotoSession): void {
8175  photoSession.on('smoothZoomInfoAvailable', callback);
8176}
8177```
8178
8179### off('smoothZoomInfoAvailable')<sup>11+</sup>
8180
8181off(type: 'smoothZoomInfoAvailable', callback?: AsyncCallback\<SmoothZoomInfo\>): void
8182
8183注销监听相机平滑变焦的状态变化。
8184
8185**系统能力:** SystemCapability.Multimedia.Camera.Core
8186
8187**参数:**
8188
8189| 参数名     | 类型                                      | 必填 | 说明                       |
8190| -------- | ----------------------------------------- | ---- | ------------------------ |
8191| type     | string              | 是   | 监听事件,固定为'smoothZoomInfoAvailable',session创建成功可监听。|
8192| callback | AsyncCallback\<[SmoothZoomInfo](#smoothzoominfo11)\> | 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
8193
8194**示例:**
8195
8196```ts
8197function unregisterSmoothZoomInfo(photoSession: camera.PhotoSession): void {
8198  photoSession.off('smoothZoomInfoAvailable');
8199}
8200```
8201
8202### on('autoDeviceSwitchStatusChange')<sup>13+</sup>
8203
8204on(type: 'autoDeviceSwitchStatusChange', callback: AsyncCallback\<AutoDeviceSwitchStatus\>): void
8205
8206监听相机自动切换镜头状态变化,通过注册回调函数获取结果。使用callback异步回调。
8207
8208> **说明:**
8209>
8210> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
8211
8212**系统能力:** SystemCapability.Multimedia.Camera.Core
8213
8214**参数:**
8215
8216| 参数名     | 类型                                                                   | 必填 | 说明                                                     |
8217| -------- |----------------------------------------------------------------------| ---- |--------------------------------------------------------|
8218| type     | string                                                               | 是   | 监听事件,固定为'autoDeviceSwitchStatusChange',session创建成功可监听。 |
8219| callback | AsyncCallback\<[AutoDeviceSwitchStatus](#autodeviceswitchstatus13)\> | 是   | 回调函数,用于获取当前自动切换镜头的状态。                                  |
8220
8221**示例:**
8222
8223```ts
8224import { BusinessError } from '@kit.BasicServicesKit';
8225
8226function callback(err: BusinessError, autoDeviceSwitchStatus: camera.AutoDeviceSwitchStatus): void {
8227  if (err !== undefined && err.code !== 0) {
8228    console.error(`Callback Error, errorCode: ${err.code}`);
8229    return;
8230  }
8231  console.info(`isDeviceSwitched: ${autoDeviceSwitchStatus.isDeviceSwitched}, isDeviceCapabilityChanged: ${autoDeviceSwitchStatus.isDeviceCapabilityChanged}`);
8232}
8233
8234function registerAutoDeviceSwitchStatus(photoSession: camera.PhotoSession): void {
8235  photoSession.on('autoDeviceSwitchStatusChange', callback);
8236}
8237```
8238
8239### off('autoDeviceSwitchStatusChange')<sup>13+</sup>
8240
8241off(type: 'autoDeviceSwitchStatusChange', callback?: AsyncCallback\<AutoDeviceSwitchStatus\>): void
8242
8243注销监听相机自动切换镜头状态变化。
8244
8245**系统能力:** SystemCapability.Multimedia.Camera.Core
8246
8247**参数:**
8248
8249| 参数名     | 类型                                           | 必填 | 说明                       |
8250| -------- |----------------------------------------------| ---- | ------------------------ |
8251| type     | string                                       | 是   | 监听事件,固定为'autoDeviceSwitchStatusChange',session创建成功可监听。|
8252| callback | AsyncCallback\<[AutoDeviceSwitchStatus](#autodeviceswitchstatus13)\> | 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
8253
8254**示例:**
8255
8256```ts
8257function unregisterSmoothZoomInfo(photoSession: camera.PhotoSession): void {
8258  photoSession.off('autoDeviceSwitchStatusChange');
8259}
8260```
8261
8262## QualityPrioritization<sup>14+</sup>
8263
8264枚举,录像质量优先级。
8265
8266**系统能力:** SystemCapability.Multimedia.Camera.Core
8267
8268| 名称          | 值  | 说明       |
8269| ------------- | --- | ---------- |
8270| HIGH_QUALITY  | 0   | 高录像质量。   |
8271| POWER_BALANCE | 1   | 功耗平衡的录像质量。 |
8272
8273## VideoSession<sup>11+</sup>
8274
8275VideoSession extends [Session](#session11), [Flash](#flash11), [AutoExposure](#autoexposure11), [Focus](#focus11), [Zoom](#zoom11), [Stabilization](#stabilization11), [ColorManagement](#colormanagement12), [AutoDeviceSwitch](#autodeviceswitch13)
8276
8277普通录像模式会话类,提供了对闪光灯、曝光、对焦、变焦、视频防抖、色彩空间的操作。
8278
8279> **说明:**
8280>
8281> 默认的视频录制模式,适用于一般场景。支持720P、1080p等多种分辨率的录制,可选择不同帧率(如30fps、60fps)。
8282
8283### canPreconfig<sup>12+</sup>
8284
8285canPreconfig(preconfigType: PreconfigType, preconfigRatio?: PreconfigRatio): boolean
8286
8287查询当前Session是否支持指定的与配置类型。
8288
8289**系统能力:** SystemCapability.Multimedia.Camera.Core
8290
8291**参数:**
8292
8293| 参数名            | 类型                                  | 必填  | 说明              |
8294|----------------|-------------------------------------|-----|-----------------|
8295| preconfigType  | [PreconfigType](#preconfigtype12)   | 是   | 指定配置预期分辨率。      |
8296| preconfigRatio | [PreconfigRatio](#preconfigratio12) | 否   | 可选画幅比例,默认为16:9。 |
8297
8298**返回值:**
8299
8300| 类型      | 说明                                      |
8301|---------|-----------------------------------------|
8302| boolean | true: 支持指定预配值类型。<br/>false: 不支持指定预配值类型。 |
8303
8304**错误码:**
8305
8306以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
8307
8308| 错误码ID   | 错误信息                        |
8309|---------|-----------------------------|
8310| 7400201 | Camera service fatal error. |
8311
8312**示例:**
8313
8314```ts
8315function testCanPreconfig(videoSession: camera.VideoSession, preconfigType: camera.PreconfigType,
8316  preconfigRatio: camera.PreconfigRatio): void {
8317  try {
8318    let result = videoSession.canPreconfig(preconfigType, preconfigRatio);
8319    console.info(`canPreconfig ${preconfigType} ${preconfigRatio} result is : ${result}`);
8320  } catch (error) {
8321    let err = error as BusinessError;
8322    console.error(`The canPreconfig call failed. error code: ${err.code}`);
8323  }
8324}
8325```
8326
8327### preconfig<sup>12+</sup>
8328
8329preconfig(preconfigType: PreconfigType, preconfigRatio?: PreconfigRatio): void
8330
8331对当前Session进行预配置。
8332
8333**系统能力:** SystemCapability.Multimedia.Camera.Core
8334
8335**参数:**
8336
8337| 参数名            | 类型                                  | 必填  | 说明              |
8338|----------------|-------------------------------------|-----|-----------------|
8339| preconfigType  | [PreconfigType](#preconfigtype12)   | 是   | 指定配置预期分辨率。      |
8340| preconfigRatio | [PreconfigRatio](#preconfigratio12) | 否   | 可选画幅比例,默认为16:9。 |
8341
8342**错误码:**
8343
8344以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
8345
8346| 错误码ID   | 错误信息                        |
8347|---------|-----------------------------|
8348| 7400201 | Camera service fatal error. |
8349
8350**示例:**
8351
8352```ts
8353function testPreconfig(videoSession: camera.VideoSession, preconfigType: camera.PreconfigType,
8354  preconfigRatio: camera.PreconfigRatio): void {
8355  try {
8356    videoSession.preconfig(preconfigType, preconfigRatio);
8357    console.info(`preconfig ${preconfigType} ${preconfigRatio} success`);
8358  } catch (error) {
8359    let err = error as BusinessError;
8360    console.error(`The preconfig call failed. error code: ${err.code}`);
8361  }
8362}
8363```
8364
8365### on('error')<sup>11+</sup>
8366
8367on(type: 'error', callback: ErrorCallback): void
8368
8369监听普通录像会话的错误事件,通过注册回调函数获取结果。使用callback异步回调。
8370
8371> **说明:**
8372>
8373> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
8374
8375**系统能力:** SystemCapability.Multimedia.Camera.Core
8376
8377**参数:**
8378
8379| 参数名     | 类型              | 必填 | 说明                           |
8380| -------- | ------------------ | ---- | ------------------------------ |
8381| type     | string             | 是   | 监听事件,固定为'error',session创建成功之后可监听该接口。session调用相关接口出现错误时会触发该事件,比如调用[beginConfig](#beginconfig11),[commitConfig](#commitconfig11-1),[addInput](#addinput11)等接口发生错误时返回错误信息。 |
8382| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback)      | 是   | 回调函数,用于获取错误信息。返回错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。   |
8383
8384**示例:**
8385
8386```ts
8387import { BusinessError } from '@kit.BasicServicesKit';
8388
8389function callback(err: BusinessError): void {
8390  console.error(`Video session error code: ${err.code}`);
8391}
8392
8393function registerSessionError(videoSession: camera.VideoSession): void {
8394  videoSession.on('error', callback);
8395}
8396```
8397
8398### off('error')<sup>11+</sup>
8399
8400off(type: 'error', callback?: ErrorCallback): void
8401
8402注销监听普通录像会话的错误事件,通过注册回调函数获取结果。
8403
8404**系统能力:** SystemCapability.Multimedia.Camera.Core
8405
8406**参数:**
8407
8408| 参数名     | 类型                          | 必填 | 说明                           |
8409| -------- | --------------------------- | ---- | ------------------------------ |
8410| type     | string                    | 是   | 监听事件,固定为'error',session创建成功之后可监听该接口。 |
8411| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback)| 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
8412
8413**示例:**
8414
8415```ts
8416function unregisterSessionError(videoSession: camera.VideoSession): void {
8417  videoSession.off('error');
8418}
8419```
8420
8421### on('focusStateChange')<sup>11+</sup>
8422
8423on(type: 'focusStateChange', callback: AsyncCallback\<FocusState\>): void
8424
8425监听相机聚焦的状态变化,通过注册回调函数获取结果。使用callback异步回调。
8426
8427> **说明:**
8428>
8429> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
8430
8431**系统能力:** SystemCapability.Multimedia.Camera.Core
8432
8433**参数:**
8434
8435| 参数名     | 类型                    | 必填 | 说明                       |
8436| -------- | ---------------- | ---- | ------------------------ |
8437| type     | string                                    | 是   | 监听事件,固定为'focusStateChange',session创建成功可监听。仅当自动对焦模式时,且相机对焦状态发生改变时可触发该事件。 |
8438| callback | AsyncCallback\<[FocusState](#focusstate)\> | 是   | 回调函数,用于获取当前对焦状态。  |
8439
8440**示例:**
8441
8442```ts
8443import { BusinessError } from '@kit.BasicServicesKit';
8444
8445function callback(err: BusinessError, focusState: camera.FocusState): void {
8446  if (err !== undefined && err.code !== 0) {
8447    console.error(`Callback Error, errorCode: ${err.code}`);
8448    return;
8449  }
8450  console.info(`Focus state: ${focusState}`);
8451}
8452
8453function registerFocusStateChange(videoSession: camera.VideoSession): void {
8454  videoSession.on('focusStateChange', callback);
8455}
8456```
8457
8458### off('focusStateChange')<sup>11+</sup>
8459
8460off(type: 'focusStateChange', callback?: AsyncCallback\<FocusState\>): void
8461
8462注销监听相机聚焦的状态变化。
8463
8464**系统能力:** SystemCapability.Multimedia.Camera.Core
8465
8466**参数:**
8467
8468| 参数名     | 类型                                      | 必填 | 说明                       |
8469| -------- | ----------------------------------------- | ---- | ------------------------ |
8470| type     | string                                    | 是   | 监听事件,固定为'focusStateChange',session创建成功可监听。 |
8471| callback | AsyncCallback\<[FocusState](#focusstate)\> | 否  | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
8472
8473**示例:**
8474
8475```ts
8476function unregisterFocusStateChange(videoSession: camera.VideoSession): void {
8477  videoSession.off('focusStateChange');
8478}
8479```
8480
8481### on('smoothZoomInfoAvailable')<sup>11+</sup>
8482
8483on(type: 'smoothZoomInfoAvailable', callback: AsyncCallback\<SmoothZoomInfo\>): void
8484
8485监听相机平滑变焦的状态变化,通过注册回调函数获取结果。使用callback异步回调。
8486
8487> **说明:**
8488>
8489> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
8490
8491**系统能力:** SystemCapability.Multimedia.Camera.Core
8492
8493**参数:**
8494
8495| 参数名     | 类型                   | 必填 | 说明                       |
8496| -------- | ----------------------- | ---- | ------------------------ |
8497| type     | string                  | 是   | 监听事件,固定为'smoothZoomInfoAvailable',session创建成功可监听。|
8498| callback | AsyncCallback\<[SmoothZoomInfo](#smoothzoominfo11)\> | 是   | 回调函数,用于获取当前平滑变焦状态。  |
8499
8500**示例:**
8501
8502```ts
8503import { BusinessError } from '@kit.BasicServicesKit';
8504
8505function callback(err: BusinessError, smoothZoomInfo: camera.SmoothZoomInfo): void {
8506  if (err !== undefined && err.code !== 0) {
8507    console.error(`Callback Error, errorCode: ${err.code}`);
8508    return;
8509  }
8510  console.info(`The duration of smooth zoom: ${smoothZoomInfo.duration}`);
8511}
8512
8513function registerSmoothZoomInfo(videoSession: camera.VideoSession): void {
8514  videoSession.on('smoothZoomInfoAvailable', callback);
8515}
8516```
8517
8518### off('smoothZoomInfoAvailable')<sup>11+</sup>
8519
8520off(type: 'smoothZoomInfoAvailable', callback?: AsyncCallback\<SmoothZoomInfo\>): void
8521
8522注销监听相机平滑变焦的状态变化。
8523
8524**系统能力:** SystemCapability.Multimedia.Camera.Core
8525
8526**参数:**
8527
8528| 参数名     | 类型                                      | 必填 | 说明                       |
8529| -------- | ----------------------------------------- | ---- | ------------------------ |
8530| type     | string              | 是   | 监听事件,固定为'smoothZoomInfoAvailable',session创建成功可监听。|
8531| callback | AsyncCallback\<[SmoothZoomInfo](#smoothzoominfo11)\> | 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
8532
8533**示例:**
8534
8535```ts
8536function unregisterSmoothZoomInfo(videoSession: camera.VideoSession): void {
8537  videoSession.off('smoothZoomInfoAvailable');
8538}
8539```
8540
8541### on('autoDeviceSwitchStatusChange')<sup>13+</sup>
8542
8543on(type: 'autoDeviceSwitchStatusChange', callback: AsyncCallback\<AutoDeviceSwitchStatus\>): void
8544
8545监听相机自动切换镜头状态变化,通过注册回调函数获取结果。使用callback异步回调。
8546
8547> **说明:**
8548>
8549> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
8550
8551**系统能力:** SystemCapability.Multimedia.Camera.Core
8552
8553**参数:**
8554
8555| 参数名     | 类型                                                                   | 必填 | 说明                       |
8556| -------- |----------------------------------------------------------------------| ---- | ------------------------ |
8557| type     | string                                                               | 是   | 监听事件,固定为'autoDeviceSwitchStatusChange',session创建成功可监听。|
8558| callback | AsyncCallback\<[AutoDeviceSwitchStatus](#autodeviceswitchstatus13)\> | 是   | 回调函数,用于获取当前自动切换镜头的状态。  |
8559
8560**示例:**
8561
8562```ts
8563import { BusinessError } from '@kit.BasicServicesKit';
8564
8565function callback(err: BusinessError, autoDeviceSwitchStatus: camera.AutoDeviceSwitchStatus): void {
8566  if (err !== undefined && err.code !== 0) {
8567    console.error(`Callback Error, errorCode: ${err.code}`);
8568    return;
8569  }
8570  console.info(`isDeviceSwitched: ${autoDeviceSwitchStatus.isDeviceSwitched}, isDeviceCapabilityChanged: ${autoDeviceSwitchStatus.isDeviceCapabilityChanged}`);
8571}
8572
8573function registerAutoDeviceSwitchStatus(videoSession: camera.VideoSession): void {
8574  videoSession.on('autoDeviceSwitchStatusChange', callback);
8575}
8576```
8577
8578### off('autoDeviceSwitchStatusChange')<sup>13+</sup>
8579
8580off(type: 'autoDeviceSwitchStatusChange', callback?: AsyncCallback\<AutoDeviceSwitchStatus\>): void
8581
8582注销监听相机自动切换镜头状态变化。
8583
8584**系统能力:** SystemCapability.Multimedia.Camera.Core
8585
8586**参数:**
8587
8588| 参数名     | 类型                                           | 必填 | 说明                       |
8589| -------- |----------------------------------------------| ---- | ------------------------ |
8590| type     | string                                       | 是   | 监听事件,固定为'autoDeviceSwitchStatusChange',session创建成功可监听。|
8591| callback | AsyncCallback\<[AutoDeviceSwitchStatus](#autodeviceswitchstatus13)\> | 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
8592
8593**示例:**
8594
8595```ts
8596function unregisterSmoothZoomInfo(videoSession: camera.VideoSession): void {
8597  videoSession.off('autoDeviceSwitchStatusChange');
8598}
8599```
8600
8601### setQualityPrioritization<sup>14+</sup>
8602
8603setQualityPrioritization(quality : QualityPrioritization) : void;
8604
8605设置录像质量优先级。
8606
8607> **说明:**
8608> 默认为高质量,设置为功耗平衡将降低录像质量以减少功耗。实际功耗收益因平台而异。
8609
8610**系统能力:** SystemCapability.Multimedia.Camera.Core
8611
8612**参数:**
8613
8614| 参数名  | 类型                                              | 必填 | 说明                                       |
8615| ------- | ------------------------------------------------- | ---- | ------------------------------------------ |
8616| quality | [QualityPrioritization](#qualityprioritization14) | 是   | 需要设置的视频质量优先级(默认为高质量)。 |
8617
8618**错误码:**
8619
8620以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
8621
8622| 错误码ID | 错误信息                                                                                                                                        |
8623| -------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
8624| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
8625| 7400103  | Session not config.                                                                                                                             |
8626
8627**示例:**
8628
8629```ts
8630import { BusinessError } from '@kit.BasicServicesKit';
8631
8632function setQualityPrioritization(videoSession: camera.VideoSession): void {
8633  try {
8634    videoSession.setQualityPrioritization(camera.QualityPrioritization.POWER_BALANCE);
8635  } catch (error) {
8636    // 失败返回错误码error.code并处理
8637    let err = error as BusinessError;
8638    console.error(`The setQualityPrioritization call failed. error code: ${err.code}`);
8639  }
8640}
8641```
8642
8643## SecureSession<sup>12+</sup>
8644
8645SecureSession extends [Session](#session11), [Flash](#flash11), [AutoExposure](#autoexposure11), [Focus](#focus11), [Zoom](#zoom11)
8646
8647安全模式会话类,提供了对闪光灯、曝光、对焦、变焦的操作。
8648
8649> **说明:**
8650>
8651> 通过[createSession](#createsession11)接口传入[SceneMode](#scenemode11)为SECURE_PHOTO模式创建一个安全模式的会话。该模式开放给人脸识别、银行等有安全诉求的应用,需要结合<!--RP1-->安全TA<!--RP1End-->使用,支持同时出普通预览流和安全流的业务场景。<!--RP2-->
8652> <br>安全TA:可用于图片处理,它具备验证服务器下发数据的验签能力、图片签名、解析及组装tlv逻辑的能力,还具备密钥读取、创建及操作能力。<!--RP2End-->
8653
8654### addSecureOutput<sup>12+</sup>
8655
8656addSecureOutput(previewOutput: PreviewOutput): void
8657
8658把其中一条[PreviewOutput](#previewoutput)标记成安全输出。
8659
8660**系统能力:** SystemCapability.Multimedia.Camera.Core
8661
8662**参数:**
8663
8664| 参数名           | 类型                             | 必填 | 说明            |
8665| ------------- | ------------------------------- | ---- |---------------|
8666| previewOutput  | [PreviewOutput](#previewoutput)   | 是   | 需要标记成安全输出的预览流,传参异常时,会返回错误码。 |
8667
8668**错误码:**
8669
8670以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。
8671
8672| 错误码ID         | 错误信息        |
8673| --------------- | --------------- |
8674| 7400101                |  Parameter missing or parameter type incorrect.        |
8675| 7400102                |  Operation not allowed.                                  |
8676| 7400103                |  Session not config.                                   |
8677
8678**示例:**
8679
8680```ts
8681import { BusinessError } from '@kit.BasicServicesKit';
8682
8683function addSecureOutput(session: camera.SecureSession, previewOutput: camera.PreviewOutput): void {
8684  try {
8685    session.addSecureOutput(previewOutput);
8686  } catch (error) {
8687    // 失败返回错误码error.code并处理
8688    let err = error as BusinessError;
8689    console.error(`The addOutput call failed. error code: ${err.code}`);
8690  }
8691}
8692```
8693### on('error')<sup>12+</sup>
8694
8695on(type: 'error', callback: ErrorCallback): void
8696
8697监听安全相机会话的错误事件,通过注册回调函数获取结果。使用callback异步回调。
8698
8699> **说明:**
8700>
8701> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
8702
8703**系统能力:** SystemCapability.Multimedia.Camera.Core
8704
8705**参数:**
8706
8707| 参数名     | 类型              | 必填 | 说明                           |
8708| -------- | ------------------ | ---- | ------------------------------ |
8709| type     | string             | 是   | 监听事件,固定为'error',session创建成功之后可监听该接口。session调用相关接口出现错误时会触发该事件,比如调用[beginConfig](#beginconfig11),[commitConfig](#commitconfig11-1),[addInput](#addinput11)等接口发生错误时返回错误信息。 |
8710| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback)      | 是   | 回调函数,用于获取错误信息。返回错误码,错误码类型[CameraErrorCode](#cameraerrorcode)。   |
8711
8712**示例:**
8713
8714```ts
8715import { BusinessError } from '@kit.BasicServicesKit';
8716
8717function callback(err: BusinessError): void {
8718  console.error(`Video session error code: ${err.code}`);
8719}
8720
8721function registerSessionError(secureSession: camera.SecureSession): void {
8722  secureSession.on('error', callback);
8723}
8724```
8725
8726### off('error')<sup>12+</sup>
8727
8728off(type: 'error', callback?: ErrorCallback): void
8729
8730注销监听安全相机会话的错误事件,通过注册回调函数获取结果。
8731
8732**系统能力:** SystemCapability.Multimedia.Camera.Core
8733
8734**参数:**
8735
8736| 参数名     | 类型                          | 必填 | 说明                           |
8737| -------- | --------------------------- | ---- | ------------------------------ |
8738| type     | string                    | 是   | 监听事件,固定为'error',session创建成功之后可监听该接口。 |
8739| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback)| 否   | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
8740
8741**示例:**
8742
8743```ts
8744function unregisterSessionError(secureSession: camera.SecureSession): void {
8745  secureSession.off('error');
8746}
8747```
8748
8749### on('focusStateChange')<sup>12+</sup>
8750
8751on(type: 'focusStateChange', callback: AsyncCallback\<FocusState\>): void
8752
8753监听相机聚焦的状态变化,通过注册回调函数获取结果。使用callback异步回调。
8754
8755> **说明:**
8756>
8757> 当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。
8758
8759**系统能力:** SystemCapability.Multimedia.Camera.Core
8760
8761**参数:**
8762
8763| 参数名     | 类型                    | 必填 | 说明                       |
8764| -------- | ---------------- | ---- | ------------------------ |
8765| type     | string                                    | 是   | 监听事件,固定为'focusStateChange',session创建成功可监听。仅当自动对焦模式时,且相机对焦状态发生改变时可触发该事件。 |
8766| callback | AsyncCallback\<[FocusState](#focusstate)\> | 是   | 回调函数,用于获取当前对焦状态。  |
8767
8768**示例:**
8769
8770```ts
8771import { BusinessError } from '@kit.BasicServicesKit';
8772
8773function callback(err: BusinessError, focusState: camera.FocusState): void {
8774  if (err !== undefined && err.code !== 0) {
8775    console.error(`Callback Error, errorCode: ${err.code}`);
8776    return;
8777  }
8778  console.info(`Focus state: ${focusState}`);
8779}
8780
8781function registerFocusStateChange(secureSession: camera.SecureSession): void {
8782  secureSession.on('focusStateChange', callback);
8783}
8784```
8785
8786### off('focusStateChange')<sup>12+</sup>
8787
8788off(type: 'focusStateChange', callback?: AsyncCallback\<FocusState\>): void
8789
8790注销监听相机聚焦的状态变化。
8791
8792**系统能力:** SystemCapability.Multimedia.Camera.Core
8793
8794**参数:**
8795
8796| 参数名     | 类型                                      | 必填 | 说明                       |
8797| -------- | ----------------------------------------- | ---- | ------------------------ |
8798| type     | string                                    | 是   | 监听事件,固定为'focusStateChange',session创建成功可监听。 |
8799| callback | AsyncCallback\<[FocusState](#focusstate)\> | 否  | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
8800
8801**示例:**
8802
8803```ts
8804function unregisterFocusStateChange(secureSession: camera.SecureSession): void {
8805  secureSession.off('focusStateChange');
8806}
8807```