• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.multimedia.camera (Camera Management)
2
3> **NOTE**
4>
5> The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.
6
7## Modules to Import
8
9```ts
10import camera from '@ohos.multimedia.camera';
11```
12
13## camera.getCameraManager
14
15getCameraManager(context: featureAbility.Context): CameraManager
16
17Obtains a **CameraManager** instance. This API returns the result synchronously.
18
19**System capability**: SystemCapability.Multimedia.Camera.Core
20
21**Parameters**
22
23| Name    | Type                                            | Mandatory| Description                          |
24| -------- | ----------------------------------------------- | ---- | ---------------------------- |
25| context  | [Context](js-apis-inner-app-context.md)      | Yes  | Application context.                  |
26
27**Return value**
28
29| Type                                            | Description                          |
30| ----------------------------------------------- | ---------------------------- |
31| [CameraManager](#cameramanager)           | **CameraManager** instance obtained.                  |
32
33**Error codes**
34
35For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
36
37| ID        | Error Message       |
38| --------------- | --------------- |
39| 7400101                |  Parameter missing or parameter type incorrect               |
40| 7400201                |  Camera service fatal error.                                  |
41
42**Example**
43
44```ts
45import featureAbility from '@ohos.ability.featureAbility';
46import { BusinessError } from '@ohos.base';
47
48function getCameraManager(context: featureAbility.Context): camera.CameraManager | undefined {
49  let cameraManager: camera.CameraManager | undefined = undefined;
50  try {
51    cameraManager = camera.getCameraManager(context);
52  } catch (error) {
53    let err = error as BusinessError;
54    console.error(`The getCameraManager call failed. error code: ${err.code}`);
55  }
56  return cameraManager;
57}
58```
59## camera.getModeManager
60
61getModeManager(context: featureAbility.Context): ModeManager
62
63Obtains a **ModeManager** instance. This API returns the result synchronously.
64
65Mode management, as an enhancement to **CameraManager**, is used to manage advanced camera features such as portrait mode.
66
67**System API**: This is a system API.
68
69**System capability**: SystemCapability.Multimedia.Camera.Core
70
71**Parameters**
72
73| Name    | Type                                            | Mandatory| Description                          |
74| -------- | ----------------------------------------------- | ---- | ---------------------------- |
75| context  | [Context](js-apis-inner-app-context.md)      | Yes  | Application context.                  |
76
77**Return value**
78
79| Type                                 | Description      |
80| --------------------------------------| -----------|
81| [ModeManager](#modemanager)           | Mode manager.|
82
83**Error codes**
84
85For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
86
87| ID        | Error Message       |
88| --------------- | --------------- |
89| 7400101                |  Parameter missing or parameter type incorrect               |
90| 7400201                |  Camera service fatal error.                                  |
91
92**Example**
93
94```ts
95import featureAbility from '@ohos.ability.featureAbility';
96import { BusinessError } from '@ohos.base';
97
98function getModeManager(context: featureAbility.Context): camera.ModeManager | undefined {
99  let modeManager: camera.ModeManager | undefined = undefined;
100  try {
101    modeManager = camera.getModeManager(context);
102  } catch (error) {
103    let err = error as BusinessError;
104    console.error(`The getModeManager call failed. error code: ${err.code}`);
105  }
106  return modeManager;
107}
108```
109
110## CameraStatus
111
112Enumerates the camera statuses.
113
114**System capability**: SystemCapability.Multimedia.Camera.Core
115
116| Name                      | Value  | Description           |
117| ------------------------- | ---- | ------------    |
118| CAMERA_STATUS_APPEAR      | 0    | A camera appears.  |
119| CAMERA_STATUS_DISAPPEAR   | 1    | The camera disappears.    |
120| CAMERA_STATUS_AVAILABLE   | 2    | The camera is available.      |
121| CAMERA_STATUS_UNAVAILABLE | 3    | The camera is unavailable.    |
122
123## Profile
124
125Defines the camera profile.
126
127**System capability**: SystemCapability.Multimedia.Camera.Core
128
129| Name     | Type                          | Mandatory| Description        |
130| -------- | ----------------------------- |---- | ------------- |
131| format   | [CameraFormat](#cameraformat) | Yes | Output format.     |
132| size     | [Size](#size)                 | Yes | Resolution.      |
133
134## FrameRateRange
135
136Defines the frame rate range.
137
138**System capability**: SystemCapability.Multimedia.Camera.Core
139
140| Name     | Type                          | Mandatory| Description        |
141| -------- | ----------------------------- |---- | ------------- |
142| min      | number                        | Yes | Minimum frame rate.     |
143| max      | number                        | Yes | Maximum frame rate.     |
144
145## VideoProfile
146
147Defines the video profile.
148
149**System capability**: SystemCapability.Multimedia.Camera.Core
150
151| Name                      | Type                                     | Mandatory| Description       |
152| ------------------------- | ----------------------------------------- | --- |----------- |
153| frameRateRange            | [FrameRateRange](#frameraterange)         | Yes | Frame rate range.  |
154
155## CameraOutputCapability
156
157Defines the camera output capability.
158
159**System capability**: SystemCapability.Multimedia.Camera.Core
160
161| Name                          | Type                                              | Mandatory| Description               |
162| ----------------------------- | -------------------------------------------------- | --- |------------------- |
163| previewProfiles               | Array\<[Profile](#profile)\>                        | Yes | Supported preview profiles.   |
164| photoProfiles                 | Array\<[Profile](#profile)\>                        | Yes | Supported shooting profiles.   |
165| videoProfiles                 | Array\<[VideoProfile](#videoprofile)\>              | Yes | Supported video recording profiles.   |
166| supportedMetadataObjectTypes  | Array\<[MetadataObjectType](#metadataobjecttype)\>  | Yes | Supported metadata object types.|
167
168## CameraErrorCode
169
170Enumerates the camera error codes, which are returned when an API call is incorrect or the **on()** API is used to listen for the error status.
171
172**System capability**: SystemCapability.Multimedia.Camera.Core
173
174| Name                      | Value         | Description           |
175| -------------------------  | ----       | ------------    |
176| INVALID_ARGUMENT           | 7400101    | A parameter is missing or the parameter type is incorrect.  |
177| OPERATION_NOT_ALLOWED      | 7400102    | The operation is not allowed.    |
178| SESSION_NOT_CONFIG         | 7400103    | The session is not configured.      |
179| SESSION_NOT_RUNNING        | 7400104    | The session is not running.   |
180| SESSION_CONFIG_LOCKED      | 7400105    | The session configuration is locked.    |
181| DEVICE_SETTING_LOCKED      | 7400106    | The device setting is locked.    |
182| CONFLICT_CAMERA            | 7400107    | The device is already started.    |
183| DEVICE_DISABLED            | 7400108    | The camera is disabled for security reasons.    |
184| DEVICE_PREEMPTED           | 7400109    | The camera is preempted.    |
185| SERVICE_FATAL_ERROR        | 7400201    | An error occurs in the camera service.    |
186
187## CameraMode
188
189Enumerates the camera modes.
190
191**System API**: This is a system API.
192
193**System capability**: SystemCapability.Multimedia.Camera.Core
194
195| Name            | Value   | Description    |
196| ----------------| ----  | ---------|
197| PORTRAIT         | 1    | Portrait mode. |
198
199## FilterType
200
201Enumerates the filter types.
202
203**System API**: This is a system API.
204
205**System capability**: SystemCapability.Multimedia.Camera.Core
206
207| Name            | Value   | Description    |
208| ----------------| ----  | ---------|
209| NONE           | 0      | No filter.    |
210| CLASSIC        | 1      | Classic.    |
211| DAWN           | 2      | Dawn.    |
212| PURE           | 3      | Pure.    |
213| GREY           | 4      | Gray.    |
214| NATURAL        | 5      | Natural.    |
215| MORI           | 6      | Mori.    |
216| FAIR           | 7      | Fair.    |
217| PINK           | 8      | Pink.    |
218
219
220## PortraitEffect
221
222Enumerates the portrait effects.
223
224**System API**: This is a system API.
225
226**System capability**: SystemCapability.Multimedia.Camera.Core
227
228| Name            | Value   | Description    |
229| ----------------| ----  | ---------|
230| OFF             | 0      | Disabled.   |
231| CIRCLES         | 1      | Circles.   |
232
233## BeautyType
234
235Enumerates the beauty types.
236
237**System API**: This is a system API.
238
239**System capability**: SystemCapability.Multimedia.Camera.Core
240
241| Name            | Value   | Description    |
242| ----------------| ----  | ---------|
243| AUTO           | 0      | Automatic.    |
244| SKIN_SMOOTH    | 1      | Skin smoothing.    |
245| FACE_SLENDER   | 2      | Face slimming.    |
246| SKIN_TONE      | 3      | Skin tone perfection.    |
247
248## CameraManager
249
250Implements camera management. Before calling any API in **CameraManager**, you must use **getCameraManager** to obtain a **CameraManager** instance.
251
252### getSupportedCameras
253
254getSupportedCameras(): Array\<CameraDevice\>
255
256Obtains supported cameras. This API returns the result synchronously.
257
258**System capability**: SystemCapability.Multimedia.Camera.Core
259
260**Return value**
261
262| Type                                            | Description                          |
263| ----------------------------------------------- | ---------------------------- |
264|  Array\<[CameraDevice](#cameradevice)>            | An array of supported cameras.                  |
265
266**Example**
267
268```ts
269import { BusinessError } from '@ohos.base';
270
271function getSupportedCameras(cameraManager: camera.CameraManager): Array<camera.CameraDevice> {
272  let cameras: Array<camera.CameraDevice> = [];
273  try {
274    cameras = cameraManager.getSupportedCameras();
275  } catch (error) {
276    let err = error as BusinessError;
277    console.error(`The getSupportedCameras call failed. error code: ${err.code}`);
278  }
279  return cameras;
280}
281```
282
283### getSupportedOutputCapability
284
285getSupportedOutputCapability(camera:CameraDevice): CameraOutputCapability
286
287Obtains the output capability supported by a camera. This API returns the result synchronously.
288
289**System capability**: SystemCapability.Multimedia.Camera.Core
290
291**Parameters**
292
293| Name        | Type                                                           | Mandatory| Description                     |
294| ------------ |--------------------------------------------------------------- | -- | -------------------------- |
295| cameraDevice | [CameraDevice](#cameradevice)                              | Yes| Target camera, which is obtained through **getSupportedCameras**.      |
296
297**Return value**
298
299| Type                                            | Description                          |
300| ----------------------------------------------- | ---------------------------- |
301| [CameraOutputCapability](#cameraoutputcapability)            | Camera output capability obtained.                  |
302
303**Example**
304
305```ts
306function getSupportedOutputCapability(cameraDevice: camera.CameraDevice, cameraManager: camera.CameraManager): camera.CameraOutputCapability {
307  let cameraOutputCapability: camera.CameraOutputCapability = cameraManager.getSupportedOutputCapability(cameraDevice);
308  return cameraOutputCapability;
309}
310```
311
312### isCameraMuted
313
314isCameraMuted(): boolean
315
316Checks whether the camera is muted.
317
318Before calling the API, ensure that the camera can be muted. You can use [isCameraMuteSupported](#iscameramutesupported) to check whether the camera can be muted.
319
320**System capability**: SystemCapability.Multimedia.Camera.Core
321
322**Return value**
323
324| Type       | Description                                        |
325| ---------- | -------------------------------------------- |
326| boolean    | Returns **true** if the camera is muted; returns **false** otherwise.|
327
328**Example**
329
330```ts
331function isCameraMuted(cameraManager: camera.CameraManager): boolean {
332  let isMuted: boolean = cameraManager.isCameraMuted();
333  return isMuted;
334}
335```
336
337### isCameraMuteSupported
338
339isCameraMuteSupported(): boolean
340
341Checks whether the camera can be muted.
342
343**System API**: This is a system API.
344
345**System capability**: SystemCapability.Multimedia.Camera.Core
346
347**Return value**
348
349| Type       | Description                         |
350| ---------- | ----------------------------- |
351| boolean    | Returns **true** if the camera can be muted; returns **false** otherwise.|
352
353**Example**
354
355```ts
356function isCameraMuteSupported(cameraManager: camera.CameraManager): boolean {
357  let isMuteSupported: boolean = cameraManager.isCameraMuteSupported();
358  return isMuteSupported;
359}
360```
361
362### muteCamera
363
364muteCamera(mute: boolean): void
365
366Mutes or unmutes the camera.
367
368**System API**: This is a system API.
369
370**System capability**: SystemCapability.Multimedia.Camera.Core
371
372**Parameters**
373
374| Name     | Type                             | Mandatory | Description       |
375| -------- | --------------------------------- | ---- | ---------- |
376| mute     | boolean                           |  Yes |  Whether to mute the camera. The value **true** means to mute the camera, and **false** means the opposite. |
377
378**Example**
379
380```ts
381function muteCamera(cameraManager: camera.CameraManager): void {
382  let mute: boolean = true;
383  cameraManager.muteCamera(mute);
384}
385```
386
387### createCameraInput
388
389createCameraInput(camera: CameraDevice): CameraInput
390
391Creates a **CameraInput** instance with the specified **CameraDevice** object. This API returns the result synchronously.
392
393**Required permissions**: ohos.permission.CAMERA
394
395**System capability**: SystemCapability.Multimedia.Camera.Core
396
397**Parameters**
398
399| Name    | Type                                        | Mandatory| Description                               |
400| -------- | ------------------------------------------- | ---- | --------------------------------- |
401| cameraDevice   | [CameraDevice](#cameradevice)         | Yes  | Target **CameraDevice** object, which is obtained through **getSupportedCameras**.  |
402
403**Return value**
404
405| Type       | Description                         |
406| ---------- | ----------------------------- |
407| [CameraInput](#camerainput)    | **CameraInput** instance created. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
408
409**Error codes**
410
411For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
412
413| ID        | Error Message       |
414| --------------- | --------------- |
415| 7400101                |  Parameter missing or parameter type incorrect               |
416
417**Example**
418
419```ts
420import { BusinessError } from '@ohos.base';
421
422function createCameraInput(cameraDevice: camera.CameraDevice, cameraManager: camera.CameraManager): camera.CameraInput {
423  let cameraInput: camera.CameraInput;
424  try {
425    cameraInput = cameraManager.createCameraInput(cameraDevice);
426  } catch (error) {
427    // If the operation fails, error.code is returned and processed.
428    let err = error as BusinessError;
429    console.error(`The createCameraInput call failed. error code: ${err.code}`);
430  }
431  return cameraInput;
432}
433```
434
435### createCameraInput
436
437createCameraInput(position: CameraPosition, type: CameraType): CameraInput
438
439Creates a **CameraInput** instance with the specified camera position and type. This API returns the result synchronously.
440
441**Required permissions**: ohos.permission.CAMERA
442
443**System capability**: SystemCapability.Multimedia.Camera.Core
444
445**Parameters**
446
447| Name    | Type                                       | Mandatory| Description                               |
448| -------- | ------------------------------------------- | ---- | --------------------------------- |
449| position | [CameraPosition](#cameraposition)           | Yes  | Camera position, which is obtained through **getSupportedCameras**. This API obtains a **CameraDevice** object, which contains the camera position information. |
450| type     | [CameraType](#cameratype)                   | Yes  | Camera type, which is obtained through **getSupportedCameras**. This API obtains a **CameraDevice** object, which contains the camera type information. |
451
452**Return value**
453
454| Type       | Description                         |
455| ---------- | ----------------------------- |
456| [CameraInput](#camerainput)    | **CameraInput** instance created. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
457
458**Error codes**
459
460For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
461
462| ID        | Error Message       |
463| --------------- | --------------- |
464| 7400101                |  Parameter missing or parameter type incorrect               |
465
466**Example**
467
468```ts
469import { BusinessError } from '@ohos.base';
470
471function createCameraInput(cameraDevice: camera.CameraDevice, cameraManager: camera.CameraManager): camera.CameraInput | undefined {
472  let position: camera.CameraPosition = cameraDevice.cameraPosition;
473  let type: camera.CameraType = cameraDevice.cameraType;
474  let cameraInput: camera.CameraInput | undefined = undefined;
475  try {
476    cameraInput = cameraManager.createCameraInput(position, type);
477  } catch (error) {
478    // If the operation fails, error.code is returned and processed.
479    let err = error as BusinessError;
480    console.log(`The createCameraInput call failed. error code: ${err.code}`);
481  }
482  return cameraInput;
483}
484```
485
486### createPreviewOutput
487
488createPreviewOutput(profile: Profile, surfaceId: string): PreviewOutput
489
490Creates a **PreviewOutput** instance. This API returns the result synchronously.
491
492**System capability**: SystemCapability.Multimedia.Camera.Core
493
494**Parameters**
495
496| Name    | Type                                            | Mandatory| Description                             |
497| -------- | ----------------------------------------------- | ---- | ------------------------------- |
498| profile  | [Profile](#profile)                             | Yes  | Supported preview profiles, which are obtained through **getSupportedOutputCapability**.|
499| surfaceId| string | Yes  | Surface ID, which is obtained from [XComponent](../arkui-ts/ts-basic-components-xcomponent.md) or [ImageReceiver](js-apis-image.md#imagereceiver9).|
500
501**Return value**
502
503| Type       | Description                         |
504| ---------- | ----------------------------- |
505| [PreviewOutput](#previewoutput)    | **PreviewOutput** instance created. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
506
507**Error codes**
508
509For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
510
511| ID        | Error Message       |
512| --------------- | --------------- |
513| 7400101                |  Parameter missing or parameter type incorrect               |
514
515**Example**
516
517```ts
518import { BusinessError } from '@ohos.base';
519
520function createPreviewOutput(cameraOutputCapability: camera.CameraOutputCapability, cameraManager: camera.CameraManager, surfaceId: string): camera.PreviewOutput | undefined {
521  let profile: camera.Profile = cameraOutputCapability.previewProfiles[0];
522  let previewOutput: camera.PreviewOutput | undefined = undefined;
523  try {
524    previewOutput = cameraManager.createPreviewOutput(profile, surfaceId);
525  } catch (error) {
526    // If the operation fails, error.code is returned and processed.
527    let err = error as BusinessError;
528    console.log(`The createPreviewOutput call failed. error code: ${err.code}`);
529  }
530  return previewOutput;
531}
532```
533
534### createPhotoOutput
535
536createPhotoOutput(profile: Profile, surfaceId: string): PhotoOutput
537
538Creates a **PhotoOutput** instance. This API returns the result synchronously.
539
540**System capability**: SystemCapability.Multimedia.Camera.Core
541
542**Parameters**
543
544| Name    | Type                                        | Mandatory| Description                                 |
545| -------- | ------------------------------------------- | ---- | ----------------------------------- |
546| profile  | [Profile](#profile)                         | Yes  | Supported shooting profiles, which are obtained through **getSupportedOutputCapability**.|
547| surfaceId| string            | Yes  | Surface ID, which is obtained from [ImageReceiver](js-apis-image.md#imagereceiver9).|
548
549**Return value**
550
551| Type       | Description                         |
552| ---------- | ----------------------------- |
553| [PhotoOutput](#photooutput)   | **PhotoOutput** instance created. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
554
555**Error codes**
556
557For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
558
559| ID        | Error Message       |
560| --------------- | --------------- |
561| 7400101                |  Parameter missing or parameter type incorrect               |
562
563**Example**
564
565```ts
566import { BusinessError } from '@ohos.base';
567
568function createPhotoOutput(cameraOutputCapability: camera.CameraOutputCapability, cameraManager: camera.CameraManager, surfaceId: string): camera.PhotoOutput | undefined {
569  let profile: camera.Profile = cameraOutputCapability.photoProfiles[0];
570  let photoOutput: camera.PhotoOutput | undefined = undefined;
571  try {
572    photoOutput = cameraManager.createPhotoOutput(profile, surfaceId);
573  } catch (error) {
574    // If the operation fails, error.code is returned and processed.
575    let err = error as BusinessError;
576    console.log(`The createPhotoOutput call failed. error code: ${err.code}`);
577  }
578  return photoOutput;
579}
580```
581
582### createVideoOutput
583
584createVideoOutput(profile: VideoProfile, surfaceId: string): VideoOutput
585
586Creates a **VideoOutput** instance. This API returns the result synchronously.
587
588**System capability**: SystemCapability.Multimedia.Camera.Core
589
590**Parameters**
591
592| Name    | Type                                       | Mandatory| Description                             |
593| -------- | ------------------------------------------- | ---- | ------------------------------ |
594| profile  | [VideoProfile](#videoprofile)               | Yes  | Supported video recording profiles, which are obtained through **getSupportedOutputCapability**.|
595| surfaceId| string          | Yes  | Surface ID, which is obtained from [VideoRecorder](js-apis-media.md#videorecorder9).|
596
597**Return value**
598
599| Type       | Description                         |
600| ---------- | ----------------------------- |
601| [VideoOutput](#videooutput)   | **VideoOutput** instance created. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
602
603**Error codes**
604
605For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
606
607| ID        | Error Message       |
608| --------------- | --------------- |
609| 7400101                |  Parameter missing or parameter type incorrect               |
610
611**Example**
612
613```ts
614import { BusinessError } from '@ohos.base';
615
616function createVideoOutput(cameraOutputCapability: camera.CameraOutputCapability, cameraManager: camera.CameraManager, surfaceId: string): camera.VideoOutput | undefined {
617  let profile: camera.VideoProfile = cameraOutputCapability.videoProfiles[0];
618  let videoOutput: camera.VideoOutput | undefined = undefined;
619  try {
620    videoOutput = cameraManager.createVideoOutput(profile, surfaceId);
621  } catch (error) {
622    // If the operation fails, error.code is returned and processed.
623    let err = error as BusinessError;
624    console.log(`The createPhotoOutput call failed. error code: ${err.code}`);
625  }
626  return videoOutput;
627}
628```
629
630### createMetadataOutput
631
632createMetadataOutput(metadataObjectTypes:Array\<MetadataObjectType\>): MetadataOutput
633
634Creates a **MetadataOutput** instance. This API returns the result synchronously.
635
636**System capability**: SystemCapability.Multimedia.Camera.Core
637
638**Parameters**
639
640| Name                 | Type                                              | Mandatory| Description                         |
641| -------------------- | -------------------------------------------------- | --- | ---------------------------- |
642| metadataObjectTypes  | Array\<[MetadataObjectType](#metadataobjecttype)\>  | Yes | Metadata object types, which are obtained through **getSupportedOutputCapability**.|
643
644**Return value**
645
646| Type       | Description                         |
647| ---------- | ----------------------------- |
648| [MetadataOutput](#metadataoutput)   | **MetadataOutput** instance created. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
649
650**Error codes**
651
652For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
653
654| ID        | Error Message       |
655| --------------- | --------------- |
656| 7400101                |  Parameter missing or parameter type incorrect               |
657
658**Example**
659
660```ts
661import { BusinessError } from '@ohos.base';
662
663function createMetadataOutput(cameraManager: camera.CameraManager, cameraOutputCapability: camera.CameraOutputCapability): void {
664  let metadataObjectTypes: Array<camera.MetadataObjectType> = cameraOutputCapability.supportedMetadataObjectTypes;
665  let metadataOutput: camera.MetadataOutput;
666  try {
667    metadataOutput = cameraManager.createMetadataOutput(metadataObjectTypes);
668  } catch (error) {
669    // If the operation fails, error.code is returned and processed.
670    let err = error as BusinessError;
671    console.log(`createMetadataOutput error. error code: ${err.code}`);
672  }
673}
674```
675
676### createCaptureSession
677
678createCaptureSession(): CaptureSession
679
680Creates a **CaptureSession** instance. This API returns the result synchronously.
681
682**System capability**: SystemCapability.Multimedia.Camera.Core
683
684**Return value**
685
686| Type       | Description                         |
687| ---------- | ----------------------------- |
688| [CaptureSession](#capturesession)   | **CaptureSession** instance created. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
689
690**Error codes**
691
692For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
693
694| ID        | Error Message       |
695| --------------- | --------------- |
696| 7400201                |  Camera service fatal error.               |
697
698**Example**
699
700```ts
701import { BusinessError } from '@ohos.base';
702
703function createCaptureSession(cameraManager: camera.CameraManager): camera.CaptureSession | undefined {
704  let captureSession: camera.CaptureSession | undefined = undefined;
705  try {
706    captureSession = cameraManager.createCaptureSession();
707  } catch (error) {
708    // If the operation fails, error.code is returned and processed.
709    let err = error as BusinessError;
710    console.log(`createCaptureSession error. error code: ${err.code}`);
711  }
712  return captureSession;
713}
714```
715
716### on('cameraStatus')
717
718on(type: 'cameraStatus', callback: AsyncCallback\<CameraStatusInfo\>): void
719
720Subscribes to camera status events. This API uses an asynchronous callback to return the result.
721
722**System capability**: SystemCapability.Multimedia.Camera.Core
723
724**Parameters**
725
726| Name    | Type           | Mandatory| Description      |
727| -------- | -----------------| ---- | --------- |
728| type     | string           | Yes  | Event type. The value is fixed at **'cameraStatus'**. The event can be listened for when a **CameraManager** instance is obtained. This event is triggered and the corresponding information is returned only when the device is enabled or disabled.|
729| callback | AsyncCallback\<[CameraStatusInfo](#camerastatusinfo)\> | Yes  | Callback used to return the camera status change.|                 |
730
731**Example**
732
733```ts
734import { BusinessError } from '@ohos.base';
735
736function registerCameraStatus(cameraManager: camera.CameraManager): void {
737  cameraManager.on('cameraStatus', (err: BusinessError, cameraStatusInfo: camera.CameraStatusInfo) => {
738    console.log(`camera : ${cameraStatusInfo.camera.cameraId}`);
739    console.log(`status: ${cameraStatusInfo.status}`);
740  });
741}
742```
743
744### off('cameraStatus')
745
746off(type: 'cameraStatus', callback?: AsyncCallback\<CameraStatusInfo\>): void
747
748Unsubscribes from camera status events. This API uses an asynchronous callback to return the result.
749
750**System capability**: SystemCapability.Multimedia.Camera.Core
751
752**Parameters**
753
754| Name    | Type           | Mandatory| Description      |
755| -------- | -----------------| ---- | --------- |
756| type     | string           | Yes  | Event type. The value is fixed at **'cameraStatus'**. The event can be listened for when a **CameraManager** instance is obtained.|
757| callback | AsyncCallback\<[CameraStatusInfo](#camerastatusinfo)\> | No  | Callback used for unsubscription. If a callback is passed in, only the subscription matching that callback is canceled.|                 |
758
759**Example**
760
761```ts
762function unregisterCameraStatus(cameraManager: camera.CameraManager): void {
763  cameraManager.off('cameraStatus');
764}
765```
766
767### on('cameraMute')
768
769on(type: 'cameraMute', callback: AsyncCallback\<boolean\>): void
770
771Subscribes to camera mute status events. This API uses an asynchronous callback to return the result.
772
773**System API**: This is a system API.
774
775**System capability**: SystemCapability.Multimedia.Camera.Core
776
777**Parameters**
778
779| Name    | Type            | Mandatory| Description      |
780| -------- | --------------- | ---- | --------- |
781| type     | string          | Yes  | Event type. The value is fixed at **'cameraMute'**, indicating the camera mute status. The event can be listened for when a **CameraManager** instance is obtained. This event is triggered and the status is returned when the camera is enabled or disabled.|
782| callback | AsyncCallback\<boolean> | Yes  | Callback used to return the mute status. The value **true** means that the camera is enabled, and **false** means that the camera is disabled.              |
783
784**Example**
785
786```ts
787import { BusinessError } from '@ohos.base';
788
789function registerCameraMute(cameraManager: camera.CameraManager): void {
790  cameraManager.on('cameraMute', (err: BusinessError, curMuted: boolean) => {
791    let isMuted: boolean = curMuted;
792    console.log(`cameraMute status: ${isMuted}`);
793  })
794}
795```
796
797### off('cameraMute')
798
799off(type: 'cameraMute', callback?: AsyncCallback\<boolean\>): void
800
801Unsubscribes from camera mute status events. This API uses an asynchronous callback to return the result.
802
803**System API**: This is a system API.
804
805**System capability**: SystemCapability.Multimedia.Camera.Core
806
807**Parameters**
808
809| Name    | Type            | Mandatory| Description      |
810| -------- | --------------- | ---- | --------- |
811| type     | string          | Yes  | Event type. The value is fixed at **'cameraMute'**, indicating the camera mute status. The event can be listened for when a **CameraManager** instance is obtained.|
812| callback | AsyncCallback\<boolean> | No  | Callback used for unsubscription. If a callback is passed in, only the subscription matching that callback is canceled.              |
813
814**Example**
815
816```ts
817import { BusinessError } from '@ohos.base';
818
819function callback(err: BusinessError, curMuetd: boolean): void {
820  let isMuted: boolean = curMuetd;
821}
822
823function unregisterCameraMute(cameraManager: camera.CameraManager): void {
824  cameraManager.on('cameraMute', callback);
825  cameraManager.off('cameraMute', callback);
826}
827```
828
829### isPrelaunchSupported
830
831isPrelaunchSupported(camera: CameraDevice): boolean
832
833Checks whether a camera supports prelaunch. This API is called in prior to **setPrelaunchConfig**.
834
835**System API**: This is a system API.
836
837**System capability**: SystemCapability.Multimedia.Camera.Core
838
839**Parameters**
840
841| Name    | Type            | Mandatory| Description      |
842| -------- | --------------- | ---- | --------- |
843| camera | [CameraDevice](#cameradevice) | Yes| Camera object.|
844
845**Return value**
846
847| Type| Description|
848| -------- | --------------- |
849| boolean | Returns whether the camera supports prelaunch. The value **true** means that the camera supports prelaunch, and **false** means the opposite.|
850
851**Error codes**
852
853For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
854
855| ID        | Error Message       |
856| --------------- | --------------- |
857| 7400101 | Parameter missing or parameter type incorrect. |
858
859**Example**
860
861```ts
862import featureAbility from '@ohos.ability.featureAbility';
863
864function isPreLaunchSupported(context: featureAbility.Context): boolean {
865  let cameraManager: camera.CameraManager = camera.getCameraManager(context);
866  let cameras: Array<camera.CameraDevice> = cameraManager.getSupportedCameras();
867  let isSupported: boolean = false;
868  if (cameras && cameras.length >= 1) {
869    isSupported = cameraManager.isPrelaunchSupported(cameras[0]);
870    console.log(`PreLaunch supported states: ${isSupported}`);
871    return isSupported;
872  }
873  return isSupported;
874}
875```
876
877### setPrelaunchConfig
878
879setPrelaunchConfig(prelaunchConfig: PrelaunchConfig): void
880
881**System API**: This is a system API.
882
883**Required permissions**: ohos.permission.CAMERA
884
885**System capability**: SystemCapability.Multimedia.Camera.Core
886
887**Parameters**
888
889| Name    | Type            | Mandatory| Description      |
890| -------- | --------------- | ---- | --------- |
891| prelaunchConfig | [PrelaunchConfig](#prelaunchconfig) | Yes| Prelaunch configuration.|
892
893**Error codes**
894
895For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
896
897| ID        | Error Message       |
898| --------------- | --------------- |
899| 7400101 | Parameter missing or parameter type incorrect. |
900| 7400102 | Operation not allow. |
901
902**Example**
903
904```ts
905import featureAbility from '@ohos.ability.featureAbility';
906import { BusinessError } from '@ohos.base';
907
908function setPrelaunchConfig(context: featureAbility.Context): void {
909  let cameraManager: camera.CameraManager = camera.getCameraManager(context);
910  let cameras: Array<camera.CameraDevice> = cameraManager.getSupportedCameras();
911  if (cameras && cameras.length >= 1) {
912    let cameraDevice: camera.CameraDevice = cameras[0];
913    if(cameraManager.isPrelaunchSupported(cameraDevice)) {
914      try {
915        cameraManager.setPrelaunchConfig({cameraDevice: cameraDevice});
916      } catch (error) {
917        let err = error as BusinessError;
918        console.error(`setPrelaunchConfig error. Code: ${err.code}, message: ${err.message}`);
919      }
920    }
921  }
922}
923```
924
925### prelaunch
926
927prelaunch(): void
928
929Prelaunches the camera. This API is called when a user clicks the system camera icon to start the camera application.
930
931**System API**: This is a system API.
932
933**System capability**: SystemCapability.Multimedia.Camera.Core
934
935**Example**
936
937```ts
938import featureAbility from '@ohos.ability.featureAbility';
939import { BusinessError } from '@ohos.base';
940
941function preLaunch(context: featureAbility.Context): void {
942  let cameraManager: camera.CameraManager = camera.getCameraManager(context);
943  try {
944    cameraManager.prelaunch();
945  } catch (error) {
946    let err = error as BusinessError;
947    console.error(`prelaunch error. Code: ${err.code}, message: ${err.message}`);
948  }
949}
950```
951
952### createDeferredPreviewOutput
953
954createDeferredPreviewOutput(profile: Profile): PreviewOutput
955
956Creates a deferred **PreviewOutput** instance and adds it to the data stream instead of a common **PreviewOutput** instance during stream configuration.
957
958**System API**: This is a system API.
959
960**System capability**: SystemCapability.Multimedia.Camera.Core
961
962**Parameters**
963
964| Name    | Type            | Mandatory| Description      |
965| -------- | --------------- | ---- | --------- |
966| profile | [Profile](#profile) | Yes| Configuration file of the camera preview stream.|
967
968**Return value**
969
970| Type| Description|
971| -------- | --------------- |
972| [PreviewOutput](#previewoutput) | Returns a **PreviewOutput** instance.|
973
974**Error codes**
975
976For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
977
978| ID        | Error Message       |
979| --------------- | --------------- |
980| 7400101 | Parameter missing or parameter type incorrect. |
981
982**Example**
983
984```ts
985import featureAbility from '@ohos.ability.featureAbility';
986
987function getDeferredPreviewOutput(context: featureAbility.Context, previewProfile: camera.Profile): camera.PreviewOutput {
988  const cameraManager: camera.CameraManager = camera.getCameraManager(context);
989  const output: camera.PreviewOutput = cameraManager.createDeferredPreviewOutput(previewProfile);
990  return output;
991}
992```
993## ModeManager
994
995Implements camera mode management. Before calling any API in this class, you must use [getModeManager](#cameragetmodemanager) to obtain a **ModeManager** instance.
996
997### getSupportedModes
998
999getSupportedModes(device: CameraDevice): Array\<CameraMode\>
1000
1001Obtains the modes supported by a camera device. This API returns the result synchronously.
1002
1003**System API**: This is a system API.
1004
1005**System capability**: SystemCapability.Multimedia.Camera.Core
1006
1007**Parameters**
1008
1009| Name    | Type                                                        | Mandatory| Description                |
1010| -------- | -------------------------- | ---- | ------------------- |
1011| device | [CameraDevice](#cameradevice)      | Yes  |   **CameraDevice** instance, which is obtained through [getSupportedCameras](#getsupportedcameras). |
1012
1013**Return value**
1014
1015| Type                                            | Description                          |
1016| ----------------------------------------------- | ---------------------------- |
1017|  Array\<[CameraMode](#cameramode)>            | Array of the supported modes.                  |
1018
1019**Example**
1020
1021```ts
1022function getSupportedModes(modeManager: camera.ModeManager, cameraDevice: camera.CameraDevice): Array<camera.CameraMode> {
1023  let cameraModes: Array<camera.CameraMode> = modeManager.getSupportedModes(cameraDevice);
1024  return cameraModes;
1025}
1026```
1027
1028### getSupportedOutputCapability
1029
1030getSupportedOutputCapability(device:CameraDevice, mode: CameraMode): CameraOutputCapability
1031
1032Obtains the output capability supported by a camera device in the specified mode. This API returns the result synchronously.
1033
1034**System API**: This is a system API.
1035
1036**System capability**: SystemCapability.Multimedia.Camera.Core
1037
1038**Parameters**
1039
1040| Name        | Type                                                           | Mandatory| Description                     |
1041| ------------ |--------------------------------------------------------------- | -- | -------------------------- |
1042| device       | [CameraDevice](#cameradevice)                              | Yes| **CameraDevice** instance, which is obtained through [getSupportedCameras](#getsupportedcameras).  |
1043| mode         | [CameraMode](#cameramode)                                  | Yes| Mode, which is obtained by calling [getSupportedModes](#getsupportedmodes).      |
1044
1045**Return value**
1046
1047| Type                                            | Description                          |
1048| ----------------------------------------------- | ---------------------------- |
1049| [CameraOutputCapability](#cameraoutputcapability)            | Camera output capability obtained.                  |
1050
1051**Example**
1052
1053```ts
1054function getSupportedOutputCapability(cameraManager: camera.CameraManager, modeManager: camera.ModeManager): camera.CameraOutputCapability | undefined {
1055  let cameras: Array<camera.CameraDevice> = cameraManager.getSupportedCameras();
1056  if (cameras == undefined || cameras.length <= 0) {
1057    return undefined;
1058  }
1059  let cameraDevice: camera.CameraDevice = cameras[0];
1060  let cameraModes: Array<camera.CameraMode> = modeManager.getSupportedModes(cameraDevice);
1061  if (cameraModes === undefined || cameraModes.length <= 0) {
1062    return undefined;
1063  }
1064  let mode: camera.CameraMode = cameraModes[0];
1065  let cameraOutputCapability: camera.CameraOutputCapability = modeManager.getSupportedOutputCapability(cameraDevice, mode);
1066  return cameraOutputCapability;
1067}
1068```
1069### createCaptureSession
1070
1071createCaptureSession(mode: CameraMode): CaptureSession
1072
1073Creates a session for a mode.
1074
1075**System API**: This is a system API.
1076
1077**System capability**: SystemCapability.Multimedia.Camera.Core
1078
1079**Parameters**
1080
1081| Name        | Type                                                           | Mandatory| Description                     |
1082| ------------ |--------------------------------------------------------------- | -- | -------------------------- |
1083| mode | [CameraMode](#cameramode)                              | Yes| Mode, which is obtained by calling [getSupportedModes](#getsupportedmodes).      |
1084
1085**Return value**
1086
1087| Type                                            | Description                          |
1088| ----------------------------------------------- | ---------------------------- |
1089| [CaptureSession](#capturesession)            | **CaptureSession** instance created.                  |
1090
1091**Example**
1092
1093```ts
1094import { BusinessError } from '@ohos.base';
1095
1096function createCaptureSession(cameraManager: camera.CameraManager, modeManager: camera.ModeManager): camera.CaptureSession {
1097  let cameras: Array<camera.CameraDevice> = cameraManager.getSupportedCameras();
1098  if (cameras == undefined || cameras.length <= 0) {
1099    return;
1100  }
1101  let cameraDevice: camera.CameraDevice = cameras[0];
1102  let cameraModes: Array<camera.CameraMode> = modeManager.getSupportedModes(cameraDevice);
1103  if (cameraModes === undefined || cameraModes.length <= 0) {
1104    return;
1105  }
1106  let mode: camera.CameraMode = cameraModes[0];
1107  let captureSession: camera.CaptureSession
1108  try {
1109    captureSession = modeManager.createCaptureSession(mode);
1110  } catch (error) {
1111    let err = error as BusinessError;
1112    console.error(`The createCaptureSession call failed. error code: ${err.code}`);
1113  }
1114  return captureSession;
1115}
1116```
1117
1118## PrelaunchConfig
1119
1120Defines the camera prelaunch configuration.
1121
1122Currently, the configuration is used for sensor-level prelaunch. It will be used for stream-level prelaunch in a later version.
1123
1124**System API**: This is a system API.
1125
1126**System capability**: SystemCapability.Multimedia.Camera.Core
1127
1128| Name  | Type                           |     Mandatory    | Description      |
1129| ------ | ----------------------------- | -------------- | ---------- |
1130| cameraDevice | [CameraDevice](#cameradevice) |        Yes      | Camera object.|
1131
1132## CameraStatusInfo
1133
1134Describes the camera status information.
1135
1136**System capability**: SystemCapability.Multimedia.Camera.Core
1137
1138| Name  | Type                           |     Mandatory    | Description      |
1139| ------ | ----------------------------- | -------------- | ---------- |
1140| camera | [CameraDevice](#cameradevice) |        Yes      | Camera object.|
1141| status | [CameraStatus](#camerastatus) |        Yes       | Camera status.|
1142
1143## CameraPosition
1144
1145Enumerates the camera positions.
1146
1147**System capability**: SystemCapability.Multimedia.Camera.Core
1148
1149| Name                        | Value  | Description           |
1150| --------------------------- | ---- | -------------- |
1151| CAMERA_POSITION_UNSPECIFIED | 0    | Unspecified position. |
1152| CAMERA_POSITION_BACK        | 1    | Rear camera.      |
1153| CAMERA_POSITION_FRONT       | 2    | Front camera.      |
1154
1155## CameraType
1156
1157Enumerates the camera types.
1158
1159**System capability**: SystemCapability.Multimedia.Camera.Core
1160
1161| Name                    | Value  | Description           |
1162| ----------------------- | ---- | -------------- |
1163| CAMERA_TYPE_DEFAULT     | 0    | Unspecified camera type. |
1164| CAMERA_TYPE_WIDE_ANGLE  | 1    | Wide camera.      |
1165| CAMERA_TYPE_ULTRA_WIDE  | 2    | Ultra wide camera.    |
1166| CAMERA_TYPE_TELEPHOTO   | 3    | Telephoto camera.      |
1167| CAMERA_TYPE_TRUE_DEPTH  | 4    | Camera with depth of field information.|
1168
1169## ConnectionType
1170
1171Enumerates the camera connection types.
1172
1173**System capability**: SystemCapability.Multimedia.Camera.Core
1174
1175| Name                         | Value  | Description          |
1176| ---------------------------- | ---- | ------------- |
1177| CAMERA_CONNECTION_BUILT_IN   | 0    | Built-in camera.     |
1178| CAMERA_CONNECTION_USB_PLUGIN | 1    | Camera connected using USB.|
1179| CAMERA_CONNECTION_REMOTE     | 2    | Remote camera.|
1180
1181## HostDeviceType
1182
1183Enumerates the remote camera types.
1184
1185**System API**: This is a system API.
1186
1187**System capability**: SystemCapability.Multimedia.Camera.Core
1188
1189| Name                         | Value      | Description          |
1190| ---------------------------- | ----     | ------------- |
1191| UNKNOWN_TYPE                 | 0        | Unknown type.     |
1192| PHONE                        | 0x0E     | Camera of a smartphone.|
1193| TABLET                       | 0x11     | Camera of a tablet.|
1194
1195## CameraDevice
1196
1197Defines the camera device information.
1198
1199**System capability**: SystemCapability.Multimedia.Camera.Core
1200
1201| Name          | Type                               | Mandatory| Description       |
1202| -------------- | --------------------------------- | ---- | ---------- |
1203| cameraId       | string                            | Yes  | **CameraDevice** object.|
1204| cameraPosition | [CameraPosition](#cameraposition) | Yes  | Camera position.   |
1205| cameraType     | [CameraType](#cameratype)         | Yes  | Camera type.   |
1206| connectionType | [ConnectionType](#connectiontype) | Yes  | Camera connection type.|
1207| hostDeviceName | string                            | Yes  | Name of the remote device.<br>**System API**: This is a system API.|
1208| hostDeviceType | [hostDeviceType](#hostdevicetype) | Yes  | Type of the remote device.<br>**System API**: This is a system API.|
1209
1210## Size
1211
1212Enumerates the camera output capability.
1213
1214**System capability**: SystemCapability.Multimedia.Camera.Core
1215
1216| Name  | Type  | Readable| Writable| Description        |
1217| ------ | ------ | ---- | ---- | ------------ |
1218| height | number | Yes  | Yes  | Image height, in pixels.|
1219| width  | number | Yes  | Yes  | Image width, in pixels.|
1220
1221## Point
1222
1223Enumerates the point coordinates, which are used for focus and exposure configuration.
1224
1225**System capability**: SystemCapability.Multimedia.Camera.Core
1226
1227| Name  | Type  | Mandatory  | Description        |
1228| ------ | ------ | ---- | ------------ |
1229| x      | number | Yes   | X coordinate of a point.  |
1230| y      | number | Yes   | Y coordinate of a point.  |
1231
1232## CameraFormat
1233
1234Enumerates the camera output formats.
1235
1236**System capability**: SystemCapability.Multimedia.Camera.Core
1237
1238| Name                    | Value       | Description        |
1239| ----------------------- | --------- | ------------ |
1240| CAMERA_FORMAT_RGBA_8888 | 3         | RGB image.            |
1241| CAMERA_FORMAT_YUV_420_SP| 1003      | YUV 420 SP image.     |
1242| CAMERA_FORMAT_JPEG      | 2000      | JPEG image.           |
1243
1244## CameraInput
1245
1246Provides camera information used in **[CaptureSession](#capturesession)**.
1247
1248### open
1249
1250open\(callback: AsyncCallback\<void\>\): void
1251
1252Opens this camera. This API uses an asynchronous callback to return the result.
1253
1254**System capability**: SystemCapability.Multimedia.Camera.Core
1255
1256**Parameters**
1257
1258| Name    | Type                 | Mandatory| Description                 |
1259| -------- | -------------------- | ---- | ------------------- |
1260| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
1261
1262**Error codes**
1263
1264For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
1265
1266| ID        | Error Message       |
1267| --------------- | --------------- |
1268| 7400107                |  Can not use camera cause of conflict.               |
1269| 7400108                |  Camera disabled cause of security reason.                                  |
1270| 7400201                |  Camera service fatal error.                                  |
1271
1272**Example**
1273
1274```ts
1275import { BusinessError } from '@ohos.base';
1276
1277function openCameraInput(cameraInput: camera.CameraInput): void {
1278  cameraInput.open((err: BusinessError) => {
1279    if (err) {
1280      console.error(`Failed to open the camera. ${err.code}`);
1281      return;
1282    }
1283    console.log('Callback returned with camera opened.');
1284  });
1285}
1286```
1287
1288### open
1289
1290open(): Promise\<void\>
1291
1292Opens this camera. This API uses a promise to return the result.
1293
1294**System capability**: SystemCapability.Multimedia.Camera.Core
1295
1296**Return value**
1297
1298| Type          | Description                     |
1299| -------------- | ----------------------- |
1300| Promise\<void\> | Promise used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
1301
1302**Error codes**
1303
1304For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
1305
1306| ID        | Error Message       |
1307| --------------- | --------------- |
1308| 7400107                |  Can not use camera cause of conflict.               |
1309| 7400108                |  Camera disabled cause of security reason.                                  |
1310| 7400201                |  Camera service fatal error.                                  |
1311
1312**Example**
1313
1314```ts
1315import { BusinessError } from '@ohos.base';
1316
1317function openCameraInput(cameraInput: camera.CameraInput): void {
1318  cameraInput.open().then(() => {
1319    console.log('Promise returned with camera opened.');
1320  }).catch((err: BusinessError) => {
1321    console.error(`Failed to open the camera. ${err.code}`);
1322  });
1323}
1324```
1325
1326### close
1327
1328close\(callback: AsyncCallback\<void\>\): void
1329
1330Closes this camera. This API uses an asynchronous callback to return the result.
1331
1332**System capability**: SystemCapability.Multimedia.Camera.Core
1333
1334**Parameters**
1335
1336| Name    | Type                  | Mandatory| Description                 |
1337| -------- | -------------------- | ---- | -------------------- |
1338| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
1339
1340**Error codes**
1341
1342For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
1343
1344| ID        | Error Message       |
1345| --------------- | --------------- |
1346| 7400201                |  Camera service fatal error.                                  |
1347
1348**Example**
1349
1350```ts
1351import { BusinessError } from '@ohos.base';
1352
1353function closeCameraInput(cameraInput: camera.CameraInput): void {
1354  cameraInput.close((err: BusinessError) => {
1355    if (err) {
1356      console.error(`Failed to close the cameras. ${err.code}`);
1357      return;
1358    }
1359    console.log('Callback returned with camera closed.');
1360  });
1361}
1362```
1363
1364### close
1365
1366close(): Promise\<void\>
1367
1368Closes this camera. This API uses a promise to return the result.
1369
1370**System capability**: SystemCapability.Multimedia.Camera.Core
1371
1372**Return value**
1373
1374| Type          | Description                     |
1375| -------------- | ----------------------- |
1376| Promise\<void\> | Promise used to return the result.|
1377
1378**Error codes**
1379
1380For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
1381
1382| ID        | Error Message       |
1383| --------------- | --------------- |
1384| 7400201                |  Camera service fatal error.                                  |
1385
1386**Example**
1387
1388```ts
1389import { BusinessError } from '@ohos.base';
1390
1391function closeCameraInput(cameraInput: camera.CameraInput): void {
1392  cameraInput.close().then(() => {
1393    console.log('Promise returned with camera closed.');
1394  }).catch((err: BusinessError) => {
1395    console.error(`Failed to close the cameras. ${err.code}`);
1396  });
1397}
1398```
1399
1400### on('error')
1401
1402on(type: 'error', camera:CameraDevice, callback: ErrorCallback): void
1403
1404Subscribes to **CameraInput** error events. This API uses a callback to return the result.
1405
1406**System capability**: SystemCapability.Multimedia.Camera.Core
1407
1408**Parameters**
1409
1410| Name    | Type                             | Mandatory| Description                                         |
1411| -------- | -------------------------------- | --- | ------------------------------------------- |
1412| type     | string                           | Yes  | Event type. The value is fixed at **'error'**. The event can be listened for when a **CameraInput** instance is created. This event is triggered and the result is returned when an error occurs on the camera. For example, if the device is unavailable or a conflict occurs, the error information is returned.|
1413| cameraDevice   | [CameraDevice](#cameradevice)    | Yes  | **CameraDevice** object.|
1414| callback | ErrorCallback | Yes  | Callback used to return an error code defined in [CameraErrorCode](#cameraerrorcode).  |
1415
1416**Example**
1417
1418```ts
1419import { BusinessError } from '@ohos.base';
1420
1421function registerCameraInputError(cameraInput: camera.CameraInput, cameraDevice: camera.CameraDevice): void {
1422  cameraInput.on('error', cameraDevice, (error: BusinessError) => {
1423    console.log(`Camera input error code: ${error.code}`);
1424  });
1425}
1426```
1427
1428### off('error')
1429
1430off(type: 'error', camera:CameraDevice, callback?: ErrorCallback): void
1431
1432Unsubscribes from **CameraInput** error events.
1433
1434**System capability**: SystemCapability.Multimedia.Camera.Core
1435
1436**Parameters**
1437
1438| Name    | Type                             | Mandatory| Description                                         |
1439| -------- | -------------------------------- | --- | ------------------------------------------- |
1440| type     | string                           | Yes  | Event type. The value is fixed at **'error'**. The event can be listened for when a **CameraInput** instance is created. This event is triggered and the result is returned when an error occurs on the camera. For example, if the device is unavailable or a conflict occurs, the error information is returned.|
1441| cameraDevice   | [CameraDevice](#cameradevice)    | Yes  | **CameraDevice** object.|
1442| callback | ErrorCallback | No  | Callback used for unsubscription. If a callback is passed in, only the subscription matching that callback is canceled.  |
1443
1444**Example**
1445
1446```ts
1447
1448function unregisterCameraInputError(cameraInput: camera.CameraInput, cameraDevice: camera.CameraDevice): void {
1449  cameraInput.off('error', cameraDevice);
1450}
1451```
1452
1453## FlashMode
1454
1455Enumerates the flash modes.
1456
1457**System capability**: SystemCapability.Multimedia.Camera.Core
1458
1459| Name                   | Value  | Description       |
1460| ---------------------- | ---- | ---------- |
1461| FLASH_MODE_CLOSE       | 0    | The flash is off.|
1462| FLASH_MODE_OPEN        | 1    | The flash is on.|
1463| FLASH_MODE_AUTO        | 2    | The flash mode is auto, indicating that the flash fires automatically depending on the shooting conditions.|
1464| FLASH_MODE_ALWAYS_OPEN | 3    | The flash is steady on.|
1465
1466## ExposureMode
1467
1468Enumerates the exposure modes.
1469
1470**System capability**: SystemCapability.Multimedia.Camera.Core
1471
1472| Name                          | Value  | Description        |
1473| ----------------------------- | ---- | ----------- |
1474| EXPOSURE_MODE_LOCKED          | 0    | Exposure locked. The metering point cannot be set.|
1475| EXPOSURE_MODE_AUTO            | 1    | Auto exposure. The metering point can be set by calling [setMeteringPoint](#setmeteringpoint).|
1476| EXPOSURE_MODE_CONTINUOUS_AUTO | 2    | Continuous auto exposure. The metering point cannot be set.|
1477
1478## FocusMode
1479
1480Enumerates the focus modes.
1481
1482**System capability**: SystemCapability.Multimedia.Camera.Core
1483
1484| Name                       | Value  | Description         |
1485| -------------------------- | ---- | ------------ |
1486| FOCUS_MODE_MANUAL          | 0    | Manual focus. The focal length of the camera can be manually set to change the focus position. However, the focal point cannot be set.    |
1487| FOCUS_MODE_CONTINUOUS_AUTO | 1    | Continuous auto focus. The focal point cannot be set.|
1488| FOCUS_MODE_AUTO            | 2    | Auto focus. The focal point can be set by calling [setFocusPoint](#setfocuspoint), and auto focus is performed once based on the focal point. After the auto focus operation is complete (regardless of whether the focus is successful or fails), the focus mode is locked. To enable the camera to initiate another auto focus, the application must call **CONTINUOUS_AUTO** again.   |
1489| FOCUS_MODE_LOCKED          | 3    | Focus locked. The focal point cannot be set.    |
1490
1491## FocusState
1492
1493Enumerates the focus states.
1494
1495**System capability**: SystemCapability.Multimedia.Camera.Core
1496
1497| Name                  | Value  | Description      |
1498| --------------------- | ---- | --------- |
1499| FOCUS_STATE_SCAN      | 0    | Focusing. |
1500| FOCUS_STATE_FOCUSED   | 1    | Focused. |
1501| FOCUS_STATE_UNFOCUSED | 2    | Unfocused.|
1502
1503## VideoStabilizationMode
1504
1505Enumerates the video stabilization modes.
1506
1507**System capability**: SystemCapability.Multimedia.Camera.Core
1508
1509| Name      | Value  | Description        |
1510| --------- | ---- | ------------ |
1511| OFF       | 0    | Video stabilization is disabled.  |
1512| LOW       | 1    | The basic video stabilization algorithm is used.  |
1513| MIDDLE    | 2    | A video stabilization algorithm with a stabilization effect better than that of the **LOW** type is used.  |
1514| HIGH      | 3    | A video stabilization algorithm with a stabilization effect better than that of the **MIDDLE** type is used.  |
1515| AUTO      | 4    | Automatic video stabilization is used.  |
1516
1517## CaptureSession
1518
1519Implements a shooting session, which saves all **[CameraInput](#camerainput)** and **[CameraOutput](#cameraoutput)** instances required to run the camera and requests the camera to complete shooting or video recording.
1520
1521### beginConfig
1522
1523beginConfig(): void
1524
1525Starts configuration for the session.
1526
1527**System capability**: SystemCapability.Multimedia.Camera.Core
1528
1529**Return value**
1530
1531| Type       | Description                         |
1532| ---------- | ----------------------------- |
1533| [CameraErrorCode](#cameraerrorcode)    | If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
1534
1535**Error codes**
1536
1537For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
1538
1539| ID        | Error Message       |
1540| --------------- | --------------- |
1541| 7400105                |  Session config locked.               |
1542
1543**Example**
1544
1545```ts
1546import { BusinessError } from '@ohos.base';
1547
1548function beginConfig(captureSession: camera.CaptureSession): void {
1549  try {
1550    captureSession.beginConfig();
1551  } catch (error) {
1552    // If the operation fails, error.code is returned and processed.
1553    let err = error as BusinessError;
1554    console.error(`The beginConfig call failed. error code: ${err.code}`);
1555  }
1556}
1557```
1558
1559### commitConfig
1560
1561commitConfig(callback: AsyncCallback\<void\>): void
1562
1563Commits the configuration for this **CaptureSession** instance. This API uses an asynchronous callback to return the result.
1564
1565**System capability**: SystemCapability.Multimedia.Camera.Core
1566
1567**Parameters**
1568
1569| Name    | Type                  | Mandatory| Description                 |
1570| -------- | -------------------- | ---- | -------------------- |
1571| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
1572
1573**Error codes**
1574
1575For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
1576
1577| ID        | Error Message       |
1578| --------------- | --------------- |
1579| 7400102                |  Operation not allow.                                  |
1580| 7400201                |  Camera service fatal error.                           |
1581
1582**Example**
1583
1584```ts
1585import { BusinessError } from '@ohos.base';
1586
1587function commitConfig(captureSession: camera.CaptureSession): void {
1588  captureSession.commitConfig((err: BusinessError) => {
1589    if (err) {
1590      console.error(`The commitConfig call failed. error code: ${err.code}`);
1591      return;
1592    }
1593    console.log('Callback invoked to indicate the commit config success.');
1594  });
1595}
1596```
1597
1598### commitConfig
1599
1600commitConfig(): Promise\<void\>
1601
1602Commits the configuration for this **CaptureSession** instance. This API uses a promise to return the result.
1603
1604**System capability**: SystemCapability.Multimedia.Camera.Core
1605
1606**Return value**
1607
1608| Type           | Description                     |
1609| -------------- | ------------------------ |
1610| Promise\<void\> | Promise used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
1611
1612**Error codes**
1613
1614For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
1615
1616| ID        | Error Message       |
1617| --------------- | --------------- |
1618| 7400102                |  Operation not allow.                                  |
1619| 7400201                |  Camera service fatal error.                           |
1620
1621**Example**
1622
1623```ts
1624import { BusinessError } from '@ohos.base';
1625
1626function commitConfig(captureSession: camera.CaptureSession): void {
1627  captureSession.commitConfig().then(() => {
1628    console.log('Promise returned to indicate the commit config success.');
1629  }).catch((err: BusinessError) => {
1630    // If the operation fails, error.code is returned and processed.
1631    console.error(`The commitConfig call failed. error code: ${err.code}`);
1632  });
1633}
1634```
1635
1636### addInput
1637
1638addInput(cameraInput: CameraInput): void
1639
1640Adds a [CameraInput](#camerainput) instance to the session.
1641
1642**System capability**: SystemCapability.Multimedia.Camera.Core
1643
1644**Parameters**
1645
1646| Name       | Type                         | Mandatory| Description                    |
1647| ----------- | --------------------------- | ---- | ------------------------ |
1648| cameraInput | [CameraInput](#camerainput) | Yes  | **CameraInput** instance to add.|
1649
1650**Return value**
1651
1652| Type       | Description                         |
1653| ---------- | ----------------------------- |
1654| [CameraErrorCode](#cameraerrorcode)    | If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
1655
1656**Error codes**
1657
1658For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
1659
1660| ID        | Error Message       |
1661| --------------- | --------------- |
1662| 7400101                |  Parameter missing or parameter type incorrect        |
1663| 7400102                |  Operation not allow.                                  |
1664
1665**Example**
1666
1667```ts
1668import { BusinessError } from '@ohos.base';
1669
1670function addInput(captureSession: camera.CaptureSession, cameraInput: camera.CameraInput): void {
1671  try {
1672    captureSession.addInput(cameraInput);
1673  } catch (error) {
1674    // If the operation fails, error.code is returned and processed.
1675    let err = error as BusinessError;
1676    console.log(`The addInput call failed. error code: ${err.code}`);
1677  }
1678}
1679```
1680
1681### removeInput
1682
1683removeInput(cameraInput: CameraInput): void
1684
1685Removes a [CameraInput](#camerainput) instance from the session.
1686
1687**System capability**: SystemCapability.Multimedia.Camera.Core
1688
1689**Parameters**
1690
1691| Name       | Type                         | Mandatory| Description                     |
1692| ----------- | --------------------------- | ---- | ------------------------ |
1693| cameraInput | [CameraInput](#camerainput) | Yes  | **CameraInput** instance to remove.|
1694
1695**Return value**
1696
1697| Type       | Description                         |
1698| ---------- | ----------------------------- |
1699| [CameraErrorCode](#cameraerrorcode)    | If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
1700
1701**Error codes**
1702
1703For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
1704
1705| ID        | Error Message       |
1706| --------------- | --------------- |
1707| 7400101                |  Parameter missing or parameter type incorrect        |
1708| 7400102                |  Operation not allow.                                  |
1709
1710**Example**
1711
1712```ts
1713import { BusinessError } from '@ohos.base';
1714
1715function removeInput(captureSession: camera.CaptureSession, cameraInput: camera.CameraInput): void {
1716  try {
1717    captureSession.removeInput(cameraInput);
1718  } catch (error) {
1719    // If the operation fails, error.code is returned and processed.
1720    let err = error as BusinessError;
1721    console.log(`The removeInput call failed. error code: ${err.code}`);
1722  }
1723}
1724```
1725
1726### addOutput
1727
1728addOutput(cameraOutput: CameraOutput): void
1729
1730Adds a [CameraOutput](#cameraoutput) instance to the session.
1731
1732**System capability**: SystemCapability.Multimedia.Camera.Core
1733
1734**Parameters**
1735
1736| Name          | Type                            | Mandatory| Description                     |
1737| ------------- | ------------------------------- | ---- | ------------------------ |
1738| cameraOutput  | [CameraOutput](#cameraoutput)   | Yes  | **CameraOutput** instance to add.|
1739
1740**Return value**
1741
1742| Type       | Description                         |
1743| ---------- | ----------------------------- |
1744| [CameraErrorCode](#cameraerrorcode)    | If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
1745
1746**Error codes**
1747
1748For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
1749
1750| ID        | Error Message       |
1751| --------------- | --------------- |
1752| 7400101                |  Parameter missing or parameter type incorrect        |
1753| 7400102                |  Operation not allow.                                  |
1754
1755**Example**
1756
1757```ts
1758import { BusinessError } from '@ohos.base';
1759
1760function addOutput(captureSession: camera.CaptureSession, cameraOutput: camera.CameraOutput): void {
1761  try {
1762    captureSession.addOutput(cameraOutput);
1763  } catch (error) {
1764    // If the operation fails, error.code is returned and processed.
1765    let err = error as BusinessError;
1766    console.log(`The addOutput call failed. error code: ${err.code}`);
1767  }
1768}
1769```
1770
1771### removeOutput
1772
1773removeOutput(cameraOutput: CameraOutput): void
1774
1775Removes a [CameraOutput](#cameraoutput) instance from the session.
1776
1777**System capability**: SystemCapability.Multimedia.Camera.Core
1778
1779**Parameters**
1780
1781| Name          | Type                            | Mandatory| Description                     |
1782| ------------- | ------------------------------- | ---- | ------------------------ |
1783| cameraOutput  | [CameraOutput](#cameraoutput)   | Yes  | **CameraOutput** instance to remove.|
1784
1785**Return value**
1786
1787| Type       | Description                         |
1788| ---------- | ----------------------------- |
1789| [CameraErrorCode](#cameraerrorcode)    | If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
1790
1791**Error codes**
1792
1793For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
1794
1795| ID        | Error Message       |
1796| --------------- | --------------- |
1797| 7400101                |  Parameter missing or parameter type incorrect        |
1798| 7400102                |  Operation not allow.                                  |
1799
1800**Example**
1801
1802```ts
1803import { BusinessError } from '@ohos.base';
1804
1805function removeOutput(captureSession: camera.CaptureSession, previewOutput: camera.PreviewOutput): void {
1806  try {
1807    captureSession.removeOutput(previewOutput);
1808  } catch (error) {
1809    // If the operation fails, error.code is returned and processed.
1810    let err = error as BusinessError;
1811    console.log(`The removeOutput call failed. error code: ${err.code}`);
1812  }
1813}
1814```
1815
1816### start
1817
1818start\(callback: AsyncCallback\<void\>\): void
1819
1820Starts this **CaptureSession**. This API uses an asynchronous callback to return the result.
1821
1822**System capability**: SystemCapability.Multimedia.Camera.Core
1823
1824**Parameters**
1825
1826| Name     | Type                 | Mandatory| Description                |
1827| -------- | -------------------- | ---- | -------------------- |
1828| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
1829
1830**Error codes**
1831
1832For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
1833
1834| ID        | Error Message       |
1835| --------------- | --------------- |
1836| 7400103                |  Session not config.                                   |
1837| 7400201                |  Camera service fatal error.                           |
1838
1839**Example**
1840
1841```ts
1842import { BusinessError } from '@ohos.base';
1843
1844function startCaptureSession(captureSession: camera.CaptureSession): void {
1845  captureSession.start((err: BusinessError) => {
1846    if (err) {
1847      console.error(`Failed to start the session ${err.code}`);
1848      return;
1849    }
1850    console.log('Callback invoked to indicate the session start success.');
1851  });
1852}
1853```
1854
1855### start
1856
1857start\(\): Promise\<void\>
1858
1859Starts this **CaptureSession**. This API uses a promise to return the result.
1860
1861**System capability**: SystemCapability.Multimedia.Camera.Core
1862
1863**Return value**
1864
1865| Type           | Description                    |
1866| -------------- | ------------------------ |
1867| Promise\<void\> | Promise used to return the result.|
1868
1869**Error codes**
1870
1871For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
1872
1873| ID        | Error Message       |
1874| --------------- | --------------- |
1875| 7400103                |  Session not config.                                   |
1876| 7400201                |  Camera service fatal error.                           |
1877
1878**Example**
1879
1880```ts
1881import { BusinessError } from '@ohos.base';
1882
1883function startCaptureSession(captureSession: camera.CaptureSession): void {
1884  captureSession.start().then(() => {
1885    console.log('Promise returned to indicate the session start success.');
1886  }).catch((err: BusinessError) => {
1887    console.error(`Failed to start the session ${err.code}`);
1888  });
1889}
1890```
1891
1892### stop
1893
1894stop\(callback: AsyncCallback\<void\>\): void
1895
1896Stops this **CaptureSession**. This API uses an asynchronous callback to return the result.
1897
1898**System capability**: SystemCapability.Multimedia.Camera.Core
1899
1900**Parameters**
1901
1902| Name     | Type                 | Mandatory| Description                |
1903| -------- | -------------------- | ---- | ------------------- |
1904| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
1905
1906**Error codes**
1907
1908For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
1909
1910| ID        | Error Message       |
1911| --------------- | --------------- |
1912| 7400201                |  Camera service fatal error.                           |
1913
1914**Example**
1915
1916```ts
1917import { BusinessError } from '@ohos.base';
1918
1919function stopCaptureSession(captureSession: camera.CaptureSession): void {
1920  captureSession.stop((err: BusinessError) => {
1921    if (err) {
1922      console.error(`Failed to stop the session ${err.code}`);
1923      return;
1924    }
1925    console.log('Callback invoked to indicate the session stop success.');
1926  });
1927}
1928```
1929
1930### stop
1931
1932stop(): Promise\<void\>
1933
1934Stops this **CaptureSession**. This API uses a promise to return the result.
1935
1936**System capability**: SystemCapability.Multimedia.Camera.Core
1937
1938**Return value**
1939
1940| Type           | Description                    |
1941| -------------- | ----------------------- |
1942| Promise\<void\> | Promise used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
1943
1944**Error codes**
1945
1946For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
1947
1948| ID        | Error Message       |
1949| --------------- | --------------- |
1950| 7400201                |  Camera service fatal error.                           |
1951
1952**Example**
1953
1954```ts
1955import { BusinessError } from '@ohos.base';
1956
1957function stopCaptureSession(captureSession: camera.CaptureSession): void {
1958  captureSession.stop().then(() => {
1959    console.log('Promise returned to indicate the session stop success.');
1960  }).catch((err: BusinessError) => {
1961    console.error(`Failed to stop the session ${err.code}`);
1962  });
1963}
1964```
1965
1966### release
1967
1968release\(callback: AsyncCallback\<void\>\): void
1969
1970Releases this **CaptureSession**. This API uses an asynchronous callback to return the result.
1971
1972**System capability**: SystemCapability.Multimedia.Camera.Core
1973
1974**Parameters**
1975
1976| Name     | Type                 | Mandatory| Description                |
1977| -------- | -------------------- | ---- | -------------------- |
1978| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
1979
1980**Error codes**
1981
1982For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
1983
1984| ID        | Error Message       |
1985| --------------- | --------------- |
1986| 7400201                |  Camera service fatal error.                           |
1987
1988**Example**
1989
1990```ts
1991import { BusinessError } from '@ohos.base';
1992
1993function releaseCaptureSession(captureSession: camera.CaptureSession): void {
1994  captureSession.release((err: BusinessError) => {
1995    if (err) {
1996      console.error(`Failed to release the CaptureSession instance ${err.code}`);
1997      return;
1998    }
1999    console.log('Callback invoked to indicate that the CaptureSession instance is released successfully.');
2000  });
2001}
2002```
2003
2004### release
2005
2006release(): Promise\<void\>
2007
2008Releases this **CaptureSession**. This API uses a promise to return the result.
2009
2010**System capability**: SystemCapability.Multimedia.Camera.Core
2011
2012**Return value**
2013
2014| Type           | Description                    |
2015| -------------- | ------------------------ |
2016| Promise\<void\> | Promise used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
2017
2018**Error codes**
2019
2020For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
2021
2022| ID        | Error Message       |
2023| --------------- | --------------- |
2024| 7400201                |  Camera service fatal error.                           |
2025
2026**Example**
2027
2028```ts
2029import { BusinessError } from '@ohos.base';
2030
2031function releaseCaptureSession(captureSession: camera.CaptureSession): void {
2032  captureSession.release().then(() => {
2033    console.log('Promise returned to indicate that the CaptureSession instance is released successfully.');
2034  }).catch((err: BusinessError) => {
2035    console.error(`Failed to release the CaptureSession instance ${err.code}`);
2036  });
2037}
2038```
2039
2040### hasFlash
2041
2042hasFlash(): boolean
2043
2044Checks whether the device has flash. This API uses an asynchronous callback to return the result.
2045
2046**System capability**: SystemCapability.Multimedia.Camera.Core
2047
2048**Return value**
2049
2050| Type       | Description                         |
2051| ---------- | ----------------------------- |
2052| boolean    | Returns **true** if the device has flash; returns **false** otherwise. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
2053
2054**Error codes**
2055
2056For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
2057
2058| ID        | Error Message       |
2059| --------------- | --------------- |
2060| 7400103                |  Session not config.                                   |
2061
2062**Example**
2063
2064```ts
2065import { BusinessError } from '@ohos.base';
2066
2067function hasFlash(captureSession: camera.CaptureSession): boolean {
2068  let status: boolean = false;
2069  try {
2070    status = captureSession.hasFlash();
2071  } catch (error) {
2072    // If the operation fails, error.code is returned and processed.
2073    let err = error as BusinessError;
2074    console.error(`The hasFlash call failed. error code: ${err.code}`);
2075  }
2076  return status;
2077}
2078```
2079
2080### isFlashModeSupported
2081
2082isFlashModeSupported(flashMode: FlashMode): boolean
2083
2084Checks whether a flash mode is supported.
2085
2086**System capability**: SystemCapability.Multimedia.Camera.Core
2087
2088**Parameters**
2089
2090| Name      | Type                    | Mandatory| Description                              |
2091| --------- | ----------------------- | ---- | --------------------------------- |
2092| flashMode | [FlashMode](#flashmode) | Yes  | Flash mode.                    |
2093
2094**Return value**
2095
2096| Type       | Description                         |
2097| ---------- | ----------------------------- |
2098| boolean    | Returns **true** if the flash mode is supported; returns **false** otherwise. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
2099
2100**Error codes**
2101
2102For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
2103
2104| ID        | Error Message       |
2105| --------------- | --------------- |
2106| 7400103                |  Session not config.                                   |
2107
2108**Example**
2109
2110```ts
2111import { BusinessError } from '@ohos.base';
2112
2113function isFlashModeSupported(captureSession: camera.CaptureSession): boolean {
2114  let status: boolean = false;
2115  try {
2116    status = captureSession.isFlashModeSupported(camera.FlashMode.FLASH_MODE_AUTO);
2117  } catch (error) {
2118    // If the operation fails, error.code is returned and processed.
2119    let err = error as BusinessError;
2120    console.error(`The isFlashModeSupported call failed. error code: ${err.code}`);
2121  }
2122  return status;
2123}
2124```
2125
2126### setFlashMode
2127
2128setFlashMode(flashMode: FlashMode): void
2129
2130Sets a flash mode for the device.
2131
2132Before the setting, do the following checks:
2133
21341. Use **[hasFlash](#hasflash)** to check whether the device has flash.
21352. Use **[isFlashModeSupported](#isflashmodesupported)** to check whether the device supports the flash mode.
2136
2137**System capability**: SystemCapability.Multimedia.Camera.Core
2138
2139**Parameters**
2140
2141| Name      | Type                    | Mandatory| Description                 |
2142| --------- | ----------------------- | ---- | --------------------- |
2143| flashMode | [FlashMode](#flashmode) | Yes  | Flash mode.      |
2144
2145**Return value**
2146
2147| Type       | Description                         |
2148| ---------- | ----------------------------- |
2149| [CameraErrorCode](#cameraerrorcode)    | If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
2150
2151**Error codes**
2152
2153For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
2154
2155| ID        | Error Message       |
2156| --------------- | --------------- |
2157| 7400103                |  Session not config.                                   |
2158
2159**Example**
2160
2161```ts
2162import { BusinessError } from '@ohos.base';
2163
2164function setFlashMode(captureSession: camera.CaptureSession): void {
2165  try {
2166    captureSession.setFlashMode(camera.FlashMode.FLASH_MODE_AUTO);
2167  } catch (error) {
2168    // If the operation fails, error.code is returned and processed.
2169    let err = error as BusinessError;
2170    console.error(`The setFlashMode call failed. error code: ${err.code}`);
2171  }
2172}
2173```
2174
2175### getFlashMode
2176
2177getFlashMode(): FlashMode
2178
2179Obtains the flash mode in use.
2180
2181**System capability**: SystemCapability.Multimedia.Camera.Core
2182
2183**Return value**
2184
2185| Type       | Description                         |
2186| ---------- | ----------------------------- |
2187| [FlashMode](#flashmode)    | Flash mode obtained. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
2188
2189**Error codes**
2190
2191For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
2192
2193| ID        | Error Message       |
2194| --------------- | --------------- |
2195| 7400103                |  Session not config.                                   |
2196
2197**Example**
2198
2199```ts
2200import { BusinessError } from '@ohos.base';
2201
2202function getFlashMode(captureSession: camera.CaptureSession): camera.FlashMode {
2203  let flashMode: camera.FlashMode;
2204  try {
2205    flashMode = captureSession.getFlashMode();
2206  } catch (error) {
2207    // If the operation fails, error.code is returned and processed.
2208    let err = error as BusinessError;
2209    console.error(`The getFlashMode call failed.error code: ${err.code}`);
2210  }
2211  return flashMode;
2212}
2213```
2214
2215### isExposureModeSupported
2216
2217isExposureModeSupported(aeMode: ExposureMode): boolean;
2218
2219Checks whether an exposure mode is supported.
2220
2221**System capability**: SystemCapability.Multimedia.Camera.Core
2222
2223**Parameters**
2224
2225| Name     | Type                          | Mandatory | Description                          |
2226| -------- | -------------------------------| ---- | ----------------------------- |
2227| aeMode   | [ExposureMode](#exposuremode)  | Yes  | Exposure mode.                     |
2228
2229**Return value**
2230
2231| Type       | Description                         |
2232| ---------- | ----------------------------- |
2233| boolean    | Returns **true** if the exposure mode is supported; returns **false** otherwise. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
2234
2235**Error codes**
2236
2237For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
2238
2239| ID        | Error Message       |
2240| --------------- | --------------- |
2241| 7400103                |  Session not config.                                   |
2242
2243**Example**
2244
2245```ts
2246import { BusinessError } from '@ohos.base';
2247
2248function isExposureModeSupported(captureSession: camera.CaptureSession): boolean {
2249  let isSupported: boolean = false;
2250  try {
2251    isSupported = captureSession.isExposureModeSupported(camera.ExposureMode.EXPOSURE_MODE_LOCKED);
2252  } catch (error) {
2253    // If the operation fails, error.code is returned and processed.
2254    let err = error as BusinessError;
2255    console.error(`The isExposureModeSupported call failed. error code: ${err.code}`);
2256  }
2257  return isSupported;
2258}
2259```
2260
2261### getExposureMode
2262
2263getExposureMode(): ExposureMode
2264
2265Obtains the exposure mode in use.
2266
2267**System capability**: SystemCapability.Multimedia.Camera.Core
2268
2269**Return value**
2270
2271| Type       | Description                         |
2272| ---------- | ----------------------------- |
2273| [ExposureMode](#exposuremode)    | Exposure mode obtained. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
2274
2275**Error codes**
2276
2277For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
2278
2279| ID        | Error Message       |
2280| --------------- | --------------- |
2281| 7400103                |  Session not config.                                   |
2282
2283**Example**
2284
2285```ts
2286import { BusinessError } from '@ohos.base';
2287
2288function getExposureMode(captureSession: camera.CaptureSession): camera.ExposureMode {
2289  let exposureMode: camera.ExposureMode;
2290  try {
2291    exposureMode = captureSession.getExposureMode();
2292  } catch (error) {
2293    // If the operation fails, error.code is returned and processed.
2294    let err = error as BusinessError;
2295    console.error(`The getExposureMode call failed. error code: ${err.code}`);
2296  }
2297  return exposureMode;
2298}
2299```
2300
2301### setExposureMode
2302
2303setExposureMode(aeMode: ExposureMode): void
2304
2305Sets an exposure mode for the device.
2306
2307**System capability**: SystemCapability.Multimedia.Camera.Core
2308
2309**Parameters**
2310
2311| Name     | Type                           | Mandatory| Description                   |
2312| -------- | -------------------------------| ---- | ----------------------- |
2313| aeMode   | [ExposureMode](#exposuremode)  | Yes  | Exposure mode.               |
2314
2315**Return value**
2316
2317| Type       | Description                         |
2318| ---------- | ----------------------------- |
2319| [CameraErrorCode](#cameraerrorcode)    | If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
2320
2321**Error codes**
2322
2323For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
2324
2325| ID        | Error Message       |
2326| --------------- | --------------- |
2327| 7400103                |  Session not config.                                   |
2328
2329**Example**
2330
2331```ts
2332import { BusinessError } from '@ohos.base';
2333
2334function setExposureMode(captureSession: camera.CaptureSession): void {
2335  try {
2336    captureSession.setExposureMode(camera.ExposureMode.EXPOSURE_MODE_LOCKED);
2337  } catch (error) {
2338    // If the operation fails, error.code is returned and processed.
2339    let err = error as BusinessError;
2340    console.error(`The setExposureMode call failed. error code: ${err.code}`);
2341  }
2342}
2343```
2344
2345### getMeteringPoint
2346
2347getMeteringPoint(): Point
2348
2349Obtains the metering point of the device.
2350
2351**System capability**: SystemCapability.Multimedia.Camera.Core
2352
2353**Return value**
2354
2355| Type       | Description                         |
2356| ---------- | ----------------------------- |
2357| [Point](#point)    | Metering point obtained. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
2358
2359**Error codes**
2360
2361For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
2362
2363| ID        | Error Message       |
2364| --------------- | --------------- |
2365| 7400103                |  Session not config.                                   |
2366
2367**Example**
2368
2369```ts
2370import { BusinessError } from '@ohos.base';
2371
2372function getMeteringPoint(captureSession: camera.CaptureSession): camera.Point {
2373  let exposurePoint: camera.Point;
2374  try {
2375    exposurePoint = captureSession.getMeteringPoint();
2376  } catch (error) {
2377    // If the operation fails, error.code is returned and processed.
2378    let err = error as BusinessError;
2379    console.error(`The getMeteringPoint call failed. error code: ${err.code}`);
2380  }
2381  return exposurePoint;
2382}
2383```
2384
2385### setMeteringPoint
2386
2387setMeteringPoint(point: Point): void
2388
2389Sets the metering point, which is the center point of the metering rectangle. The metering point must be in the coordinate system (0-1), where the upper left corner is {0, 0} and the lower right corner is {1, 1}.
2390
2391The coordinate system is based on the horizontal device direction with the device's charging port on the right. If the layout of the preview screen of an application is based on the vertical direction with the charging port on the lower side, the layout width and height are {w, h}, and the touch point is {x, y}, then the coordinate point after conversion is {y/h, 1-x/w}.
2392
2393**System capability**: SystemCapability.Multimedia.Camera.Core
2394
2395**Parameters**
2396
2397| Name          | Type                           | Mandatory| Description                |
2398| ------------- | -------------------------------| ---- | ------------------- |
2399| exposurePoint | [Point](#point)                | Yes  | Metering point. The value range of x and y must be within [0,1]. If a value less than 0 is passed, the value **0** is used. If a value greater than **1** is passed, the value **1** is used.            |
2400
2401**Return value**
2402
2403| Type       | Description                         |
2404| ---------- | ----------------------------- |
2405| [CameraErrorCode](#cameraerrorcode)    | If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
2406
2407**Error codes**
2408
2409For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
2410
2411| ID        | Error Message       |
2412| --------------- | --------------- |
2413| 7400103                |  Session not config.                                   |
2414
2415**Example**
2416
2417```ts
2418import { BusinessError } from '@ohos.base';
2419
2420function setMeteringPoint(captureSession: camera.CaptureSession): void {
2421  const exposurePoint: camera.Point = {x: 1, y: 1};
2422  try {
2423    captureSession.setMeteringPoint(exposurePoint);
2424  } catch (error) {
2425    // If the operation fails, error.code is returned and processed.
2426    let err = error as BusinessError;
2427    console.error(`The setMeteringPoint call failed. error code: ${err.code}`);
2428  }
2429}
2430```
2431
2432### getExposureBiasRange
2433
2434getExposureBiasRange(): Array\<number\>
2435
2436Obtains the exposure compensation values of the device.
2437
2438**System capability**: SystemCapability.Multimedia.Camera.Core
2439
2440**Return value**
2441
2442| Type       | Description                         |
2443| ---------- | ----------------------------- |
2444| Array\<number\>   | An array of compensation values. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
2445
2446**Error codes**
2447
2448For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
2449
2450| ID        | Error Message       |
2451| --------------- | --------------- |
2452| 7400103                |  Session not config.                                   |
2453
2454**Example**
2455
2456```ts
2457import { BusinessError } from '@ohos.base';
2458
2459function getExposureBiasRange(captureSession: camera.CaptureSession): Array<number> {
2460  let biasRangeArray: Array<number> = [];
2461  try {
2462    biasRangeArray = captureSession.getExposureBiasRange();
2463  } catch (error) {
2464    // If the operation fails, error.code is returned and processed.
2465    let err = error as BusinessError;
2466    console.error(`The getExposureBiasRange call failed. error code: ${err.code}`);
2467  }
2468  return biasRangeArray;
2469}
2470```
2471
2472### setExposureBias
2473
2474setExposureBias(exposureBias: number): void
2475
2476Sets an exposure compensation value (EV).
2477
2478Before the setting, you are advised to use **[getExposureBiasRange](#getexposurebiasrange)** to obtain the supported values.
2479
2480**System capability**: SystemCapability.Multimedia.Camera.Core
2481
2482**Parameters**
2483
2484| Name    | Type                           | Mandatory| Description                |
2485| -------- | -------------------------------| ---- | ------------------- |
2486| exposureBias   | number                   | Yes  | EV. The supported EV range can be obtained by calling **getExposureBiasRange**. If the value passed is not within the supported range, the nearest critical point is used. There is a step for EV. For example, if the step is 0.5 and this parameter is set to 1.2, the EV that takes effect is 1.0. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
2487
2488**Error codes**
2489
2490For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
2491
2492| ID        | Error Message       |
2493| --------------- | --------------- |
2494| 7400103                |  Session not config.                                   |
2495
2496**Example**
2497
2498```ts
2499import { BusinessError } from '@ohos.base';
2500
2501function setExposureBias(captureSession: camera.CaptureSession, biasRangeArray: Array<number>): void {
2502  let exposureBias = biasRangeArray[0];
2503  try {
2504    captureSession.setExposureBias(exposureBias);
2505  } catch (error) {
2506    // If the operation fails, error.code is returned and processed.
2507    let err = error as BusinessError;
2508    console.error(`The setExposureBias call failed. error code: ${err.code}`);
2509  }
2510}
2511```
2512
2513### getExposureValue
2514
2515getExposureValue(): number
2516
2517Obtains the exposure value in use.
2518
2519**System capability**: SystemCapability.Multimedia.Camera.Core
2520
2521**Return value**
2522
2523| Type       | Description                         |
2524| ---------- | ----------------------------- |
2525| number    | Exposure value obtained. There is a step for EV. For example, if the step is 0.5 and this parameter is set to 1.2, the EV that takes effect is 1.0. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
2526
2527**Error codes**
2528
2529For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
2530
2531| ID        | Error Message       |
2532| --------------- | --------------- |
2533| 7400103                |  Session not config.                                   |
2534
2535**Example**
2536
2537```ts
2538import { BusinessError } from '@ohos.base';
2539
2540function getExposureValue(captureSession: camera.CaptureSession): number {
2541  const invalid_value: number = -1;
2542  let exposureValue: number = invalid_value;
2543  try {
2544    exposureValue = captureSession.getExposureValue();
2545  } catch (error) {
2546    // If the operation fails, error.code is returned and processed.
2547    let err = error as BusinessError;
2548    console.error(`The getExposureValue call failed. error code: ${err.code}`);
2549  }
2550  return exposureValue;
2551}
2552```
2553
2554### isFocusModeSupported
2555
2556isFocusModeSupported(afMode: FocusMode): boolean
2557
2558Checks whether a focus mode is supported.
2559
2560**System capability**: SystemCapability.Multimedia.Camera.Core
2561
2562**Parameters**
2563
2564| Name     | Type                    | Mandatory| Description                             |
2565| -------- | ----------------------- | ---- | -------------------------------- |
2566| afMode   | [FocusMode](#focusmode) | Yes  | Focus mode.                   |
2567
2568**Return value**
2569
2570| Type       | Description                         |
2571| ---------- | ----------------------------- |
2572| boolean    | Returns **true** if the focus mode is supported; returns **false** otherwise. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
2573
2574**Error codes**
2575
2576For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
2577
2578| ID        | Error Message       |
2579| --------------- | --------------- |
2580| 7400103                |  Session not config.                                   |
2581
2582**Example**
2583
2584```ts
2585import { BusinessError } from '@ohos.base';
2586
2587function isFocusModeSupported(captureSession: camera.CaptureSession): boolean {
2588  let status: boolean = false;
2589  try {
2590    status = captureSession.isFocusModeSupported(camera.FocusMode.FOCUS_MODE_AUTO);
2591  } catch (error) {
2592    // If the operation fails, error.code is returned and processed.
2593    let err = error as BusinessError;
2594    console.error(`The isFocusModeSupported call failed. error code: ${err.code}`);
2595  }
2596  return status;
2597}
2598```
2599
2600### setFocusMode
2601
2602setFocusMode(afMode: FocusMode): void
2603
2604Sets a focus mode for the device.
2605
2606Before the setting, use **[isFocusModeSupported](#isfocusmodesupported)** to check whether the focus mode is supported.
2607
2608**System capability**: SystemCapability.Multimedia.Camera.Core
2609
2610**Parameters**
2611
2612| Name     | Type                    | Mandatory| Description                |
2613| -------- | ----------------------- | ---- | ------------------- |
2614| afMode   | [FocusMode](#focusmode) | Yes  | Focus mode.      |
2615
2616**Return value**
2617
2618| Type       | Description                         |
2619| ---------- | ----------------------------- |
2620| [CameraErrorCode](#cameraerrorcode)    | If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
2621
2622**Error codes**
2623
2624For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
2625
2626| ID        | Error Message       |
2627| --------------- | --------------- |
2628| 7400103                |  Session not config.                                   |
2629
2630**Example**
2631
2632```ts
2633import { BusinessError } from '@ohos.base';
2634
2635function setFocusMode(captureSession: camera.CaptureSession): void {
2636  try {
2637    captureSession.setFocusMode(camera.FocusMode.FOCUS_MODE_AUTO);
2638  } catch (error) {
2639    // If the operation fails, error.code is returned and processed.
2640    let err = error as BusinessError;
2641    console.error(`The setFocusMode call failed. error code: ${err.code}`);
2642  }
2643}
2644```
2645
2646### getFocusMode
2647
2648getFocusMode(): FocusMode
2649
2650Obtains the focus mode in use.
2651
2652**System capability**: SystemCapability.Multimedia.Camera.Core
2653
2654**Return value**
2655
2656| Type       | Description                         |
2657| ---------- | ----------------------------- |
2658| [FocusMode](#focusmode)   | Focus mode obtained. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
2659
2660**Error codes**
2661
2662For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
2663
2664| ID        | Error Message       |
2665| --------------- | --------------- |
2666| 7400103                |  Session not config.                                   |
2667
2668**Example**
2669
2670```ts
2671import { BusinessError } from '@ohos.base';
2672
2673function getFocusMode(captureSession: camera.CaptureSession): camera.FocusMode {
2674  let afMode: camera.FocusMode;
2675  try {
2676    afMode = captureSession.getFocusMode();
2677  } catch (error) {
2678    // If the operation fails, error.code is returned and processed.
2679    let err = error as BusinessError;
2680    console.error(`The getFocusMode call failed. error code: ${err.code}`);
2681  }
2682  return afMode;
2683}
2684```
2685
2686### setFocusPoint
2687
2688setFocusPoint(point: Point): void
2689
2690Sets the focal point. The focal point must be in the coordinate system (0-1), where the upper left corner is {0, 0} and the lower right corner is {1, 1}.
2691
2692The coordinate system is based on the horizontal device direction with the device's charging port on the right. If the layout of the preview screen of an application is based on the vertical direction with the charging port on the lower side, the layout width and height are {w, h}, and the touch point is {x, y}, then the coordinate point after conversion is {y/h, 1-x/w}.
2693
2694**System capability**: SystemCapability.Multimedia.Camera.Core
2695
2696**Parameters**
2697
2698| Name     | Type                    | Mandatory| Description                |
2699| -------- | ----------------------- | ---- | ------------------- |
2700| Point1    | [Point](#point)         | Yes  | Focal point. The value range of x and y must be within [0,1]. If a value less than 0 is passed, the value **0** is used. If a value greater than **1** is passed, the value **1** is used.  |
2701
2702**Return value**
2703
2704| Type       | Description                         |
2705| ---------- | ----------------------------- |
2706| [CameraErrorCode](#cameraerrorcode)    | If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
2707
2708**Error codes**
2709
2710For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
2711
2712| ID        | Error Message       |
2713| --------------- | --------------- |
2714| 7400103                |  Session not config.                                   |
2715
2716**Example**
2717
2718```ts
2719import { BusinessError } from '@ohos.base';
2720
2721function setFocusPoint(captureSession: camera.CaptureSession): void {
2722  const Point1: camera.Point = {x: 1, y: 1};
2723  try {
2724    captureSession.setFocusPoint(Point1);
2725  } catch (error) {
2726    // If the operation fails, error.code is returned and processed.
2727    let err = error as BusinessError;
2728    console.error(`The setFocusPoint call failed. error code: ${err.code}`);
2729  }
2730}
2731```
2732
2733### getFocusPoint
2734
2735getFocusPoint(): Point
2736
2737Obtains the focal point of the device.
2738
2739**System capability**: SystemCapability.Multimedia.Camera.Core
2740
2741**Return value**
2742
2743| Type       | Description                         |
2744| ---------- | ----------------------------- |
2745| [Point](#point)    | Focal point obtained. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
2746
2747**Error codes**
2748
2749For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
2750
2751| ID        | Error Message       |
2752| --------------- | --------------- |
2753| 7400103                |  Session not config.                                   |
2754
2755**Example**
2756
2757```ts
2758import { BusinessError } from '@ohos.base';
2759
2760function getFocusPoint(captureSession: camera.CaptureSession): camera.Point {
2761  let point: camera.Point;
2762  try {
2763    point = captureSession.getFocusPoint();
2764  } catch (error) {
2765    // If the operation fails, error.code is returned and processed.
2766    let err = error as BusinessError;
2767    console.error(`The getFocusPoint call failed. error code: ${err.code}`);
2768  }
2769  return point;
2770}
2771```
2772
2773### getFocalLength
2774
2775getFocalLength(): number
2776
2777Obtains the focal length of the device.
2778
2779**System capability**: SystemCapability.Multimedia.Camera.Core
2780
2781**Return value**
2782
2783| Type       | Description                         |
2784| ---------- | ----------------------------- |
2785| number    | Focal length obtained. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
2786
2787**Error codes**
2788
2789For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
2790
2791| ID        | Error Message       |
2792| --------------- | --------------- |
2793| 7400103                |  Session not config.                                   |
2794
2795**Example**
2796
2797```ts
2798import { BusinessError } from '@ohos.base';
2799
2800function getFocalLength(captureSession: camera.CaptureSession): number {
2801  const invalid_value: number = -1;
2802  let focalLength: number = invalid_value;
2803  try {
2804    focalLength = captureSession.getFocalLength();
2805  } catch (error) {
2806    // If the operation fails, error.code is returned and processed.
2807    let err = error as BusinessError;
2808    console.error(`The getFocalLength call failed. error code: ${err.code}`);
2809  }
2810  return focalLength;
2811}
2812```
2813
2814### getZoomRatioRange
2815
2816getZoomRatioRange(): Array\<number\>
2817
2818Obtains the supported zoom ratio range.
2819
2820**System capability**: SystemCapability.Multimedia.Camera.Core
2821
2822**Return value**
2823
2824| Type       | Description                         |
2825| ---------- | ----------------------------- |
2826| Array\<number\>   | Callback used to return an array containing the minimum and maximum zoom ratios. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
2827
2828**Error codes**
2829
2830For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
2831
2832| ID        | Error Message       |
2833| --------------- | --------------- |
2834| 7400103                |  Session not config.                                   |
2835
2836**Example**
2837
2838```ts
2839import { BusinessError } from '@ohos.base';
2840
2841function getZoomRatioRange(captureSession: camera.CaptureSession): Array<number> {
2842  let zoomRatioRange: Array<number> = [];
2843  try {
2844    zoomRatioRange = captureSession.getZoomRatioRange();
2845  } catch (error) {
2846    // If the operation fails, error.code is returned and processed.
2847    let err = error as BusinessError;
2848    console.error(`The getZoomRatioRange call failed. error code: ${err.code}`);
2849  }
2850  return zoomRatioRange;
2851}
2852```
2853
2854### setZoomRatio
2855
2856setZoomRatio(zoomRatio: number): void
2857
2858Sets a zoom ratio, with a maximum precision of two decimal places.
2859
2860**System capability**: SystemCapability.Multimedia.Camera.Core
2861
2862**Parameters**
2863
2864| Name      | Type                 | Mandatory| Description                |
2865| --------- | -------------------- | ---- | ------------------- |
2866| zoomRatio | number               | Yes  | Zoom ratio. The supported zoom ratio range can be obtained by calling **getZoomRatioRange**. If the value passed is not within the supported range, the nearest critical point is used.|
2867
2868**Return value**
2869
2870| Type       | Description                         |
2871| ---------- | ----------------------------- |
2872| [CameraErrorCode](#cameraerrorcode)    | If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
2873
2874**Error codes**
2875
2876For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
2877
2878| ID        | Error Message       |
2879| --------------- | --------------- |
2880| 7400103                |  Session not config.                                   |
2881
2882**Example**
2883
2884```ts
2885import { BusinessError } from '@ohos.base';
2886
2887function setZoomRatio(captureSession: camera.CaptureSession, zoomRatioRange: Array<number>): void {
2888  if (zoomRatioRange === undefined || zoomRatioRange.length <= 0) {
2889    return;
2890  }
2891  let zoomRatio = zoomRatioRange[0];
2892  try {
2893    captureSession.setZoomRatio(zoomRatio);
2894  } catch (error) {
2895    // If the operation fails, error.code is returned and processed.
2896    let err = error as BusinessError;
2897    console.error(`The setZoomRatio call failed. error code: ${err.code}`);
2898  }
2899}
2900```
2901
2902### getZoomRatio
2903
2904getZoomRatio(): number
2905
2906Obtains the zoom ratio in use.
2907
2908**System capability**: SystemCapability.Multimedia.Camera.Core
2909
2910**Return value**
2911
2912| Type       | Description                         |
2913| ---------- | ----------------------------- |
2914| number    | Zoom ratio obtained. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
2915
2916**Error codes**
2917
2918For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
2919
2920| ID        | Error Message       |
2921| --------------- | --------------- |
2922| 7400103                |  Session not config.                                   |
2923
2924**Example**
2925
2926```ts
2927import { BusinessError } from '@ohos.base';
2928
2929function getZoomRatio(captureSession: camera.CaptureSession): number {
2930  const invalid_value: number = -1;
2931  let zoomRatio: number = invalid_value;
2932  try {
2933    zoomRatio = captureSession.getZoomRatio();
2934  } catch (error) {
2935    // If the operation fails, error.code is returned and processed.
2936    let err = error as BusinessError;
2937    console.error(`The getZoomRatio call failed. error code: ${err.code}`);
2938  }
2939  return zoomRatio;
2940}
2941```
2942
2943### isVideoStabilizationModeSupported
2944
2945isVideoStabilizationModeSupported(vsMode: VideoStabilizationMode): boolean
2946
2947Checks whether the specified video stabilization mode is supported.
2948
2949**System capability**: SystemCapability.Multimedia.Camera.Core
2950
2951**Parameters**
2952
2953| Name     | Type                                             | Mandatory| Description                            |
2954| -------- | ------------------------------------------------- | ---- | ------------------------------ |
2955| vsMode   | [VideoStabilizationMode](#videostabilizationmode) | Yes  | Video stabilization mode.                   |
2956
2957**Return value**
2958
2959| Type       | Description                         |
2960| ---------- | ----------------------------- |
2961| boolean    | Returns **true** if the video stabilization mode is supported; returns **false** otherwise. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
2962
2963**Error codes**
2964
2965For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
2966
2967| ID        | Error Message       |
2968| --------------- | --------------- |
2969| 7400103                |  Session not config.                                   |
2970
2971**Example**
2972
2973```ts
2974import { BusinessError } from '@ohos.base';
2975
2976function isVideoStabilizationModeSupported(captureSession: camera.CaptureSession): boolean {
2977  let isSupported: boolean = false;
2978  try {
2979    isSupported = captureSession.isVideoStabilizationModeSupported(camera.VideoStabilizationMode.OFF);
2980  } catch (error) {
2981    // If the operation fails, error.code is returned and processed.
2982    let err = error as BusinessError;
2983    console.error(`The isVideoStabilizationModeSupported call failed. error code: ${err.code}`);
2984  }
2985  return isSupported;
2986}
2987```
2988
2989### getActiveVideoStabilizationMode
2990
2991getActiveVideoStabilizationMode(): VideoStabilizationMode
2992
2993Obtains the video stabilization mode in use.
2994
2995**System capability**: SystemCapability.Multimedia.Camera.Core
2996
2997**Return value**
2998
2999| Type       | Description                         |
3000| ---------- | ----------------------------- |
3001| VideoStabilizationMode    | Video stabilization mode obtained. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
3002
3003**Error codes**
3004
3005For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
3006
3007| ID        | Error Message       |
3008| --------------- | --------------- |
3009| 7400103                |  Session not config.                                   |
3010
3011**Example**
3012
3013```ts
3014import { BusinessError } from '@ohos.base';
3015
3016function getActiveVideoStabilizationMode(captureSession: camera.CaptureSession): camera.VideoStabilizationMode {
3017  let vsMode: camera.VideoStabilizationMode;
3018  try {
3019    vsMode = captureSession.getActiveVideoStabilizationMode();
3020  } catch (error) {
3021    // If the operation fails, error.code is returned and processed.
3022    let err = error as BusinessError;
3023    console.error(`The getActiveVideoStabilizationMode call failed. error code: ${err.code}`);
3024  }
3025  return vsMode;
3026}
3027```
3028
3029### setVideoStabilizationMode
3030
3031setVideoStabilizationMode(mode: VideoStabilizationMode): void
3032
3033Sets a video stabilization mode for the device.
3034
3035**System capability**: SystemCapability.Multimedia.Camera.Core
3036
3037**Parameters**
3038
3039| Name     | Type                                             | Mandatory| Description                   |
3040| -------- | ------------------------------------------------- | ---- | --------------------- |
3041| mode     | [VideoStabilizationMode](#videostabilizationmode) | Yes  | Video stabilization mode.  |
3042
3043**Return value**
3044
3045| Type       | Description                         |
3046| ---------- | ----------------------------- |
3047| [CameraErrorCode](#cameraerrorcode)    | If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
3048
3049**Error codes**
3050
3051For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
3052
3053| ID        | Error Message       |
3054| --------------- | --------------- |
3055| 7400103                |  Session not config.                                   |
3056
3057**Example**
3058
3059```ts
3060import { BusinessError } from '@ohos.base';
3061
3062function setVideoStabilizationMode(captureSession: camera.CaptureSession): void {
3063  try {
3064    captureSession.setVideoStabilizationMode(camera.VideoStabilizationMode.OFF);
3065  } catch (error) {
3066    // If the operation fails, error.code is returned and processed.
3067    let err = error as BusinessError;
3068    console.error(`The setVideoStabilizationMode call failed. error code: ${err.code}`);
3069  }
3070}
3071```
3072### getSupportedFilters
3073
3074getSupportedFilters(): Array\<number>
3075
3076Obtains the supported filter types.
3077
3078**System API**: This is a system API.
3079
3080**System capability**: SystemCapability.Multimedia.Camera.Core
3081
3082**Return value**
3083
3084| Type       | Description                         |
3085| ---------- | ----------------------------- |
3086|  Array\<FilterType\>     | Array of the supported filter types.|
3087
3088**Error codes**
3089
3090For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
3091
3092| ID        | Error Message       |
3093| --------------- | --------------- |
3094| 7400103                |  Session not config.                                   |
3095
3096**Example**
3097
3098```ts
3099function getSupportedFilters(portraitSession: camera.PortraitSession): Array<camera.FilterType> {
3100  let filterTypes: Array<camera.FilterType> = portraitSession.getSupportedFilters();
3101  return filterTypes;
3102}
3103```
3104### setFilter
3105
3106setFilter(filter: number): void
3107
3108Sets a filter type.
3109
3110**System API**: This is a system API.
3111
3112**System capability**: SystemCapability.Multimedia.Camera.Core
3113
3114**Parameters**
3115
3116| Name   | Type                       | Mandatory| Description                 |
3117| -------- | ----------------------------| ---- | ---------------------|
3118| filter     | [number](#filtertype) | Yes  | Filter type to set. |
3119
3120**Error codes**
3121
3122For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
3123
3124| ID        | Error Message       |
3125| --------------- | --------------- |
3126| 7400101                |  Parameter missing or parameter type incorrect.        |
3127| 7400103                |  Session not config.                                   |
3128
3129**Example**
3130
3131```ts
3132function setFilter(portraitSession: camera.PortraitSession, filterTypes: Array<camera.FilterType>): void {
3133  if (filterTypes === undefined || filterTypes.length <= 0) {
3134    return;
3135  }
3136  portraitSession.setFilter(filterTypes[0]);
3137}
3138```
3139
3140### getFilter
3141
3142 getFilter(): number
3143
3144Obtains the filter type in use.
3145
3146**System API**: This is a system API.
3147
3148**System capability**: SystemCapability.Multimedia.Camera.Core
3149
3150**Return value**
3151
3152| Type                    | Description                        |
3153| ----------               | ----------------------------|
3154| [number](#filtertype)| Filter type in use. For details, see [FilterType](#filtertype).|
3155
3156**Error codes**
3157
3158For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
3159
3160| ID        | Error Message       |
3161| --------------- | --------------- |
3162| 7400103                |  Session not config.                                   |
3163
3164**Example**
3165
3166```ts
3167function getFilter(portraitSession: camera.PortraitSession): number {
3168  let filterType: number = portraitSession.getFilter();
3169  return filterType;
3170}
3171```
3172### getSupportedBeautyTypes
3173
3174getSupportedBeautyTypes(): Array<[BeautyType](#beautytype)>
3175
3176Obtains the supported beauty types.
3177
3178**System API**: This is a system API.
3179
3180**System capability**: SystemCapability.Multimedia.Camera.Core
3181
3182**Return value**
3183
3184| Type               | Description                                                 |
3185| ----------          | -----------------------------                         |
3186|  Array\<[BeautyType](#beautytype)\>| Array of the supported beauty types.                            |
3187
3188**Error codes**
3189
3190For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
3191
3192| ID        | Error Message       |
3193| --------------- | --------------- |
3194| 7400103                |  Session not config.                                   |
3195
3196**Example**
3197
3198```ts
3199function getSupportedBeautyTypes(portraitSession: camera.PortraitSession): Array<camera.BeautyType> {
3200  let beautyTypes: Array<camera.BeautyType> = portraitSession.getSupportedBeautyTypes();
3201  return beautyTypes;
3202}
3203```
3204### getSupportedBeautyRange
3205
3206getSupportedBeautyRange(type: BeautyType): Array\<number\>
3207
3208Obtains the levels that can be set a beauty type. The beauty levels vary according to the device type. The following table is only an example.
3209
3210| Input Parameter          | Example Return Value   | Return Value Description    |
3211| ----------------| ----  | ---------|
3212| AUTO           | [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]     |Beauty levels supported when **type** is set to **AUTO**. The value **0** means that beauty mode is disabled, and other positive values mean the corresponding automatic beauty levels.   |
3213| SKIN_SMOOTH    | [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]     | Beauty levels supported when **type** is set to **SKIN_SMOOTH**. The value **0** means that the skin smoothing feature is disabled, and other positive values mean the corresponding skin smoothing levels.   |
3214| FACE_SLENDER   | [0, 1, 2, 3, 4, 5]      | Beauty levels supported when **type** is set to **FACE_SLENDER**. The value **0** means that the face slimming feature is disabled, and other positive values mean the corresponding face slimming levels.  |
3215| SKIN_TONE      | [-1, 16242611]      | Beauty levels supported when **type** is set to **SKIN_TONE**. The value **-1** means that the skin tone perfection feature is disabled. Other non-negative values mean the skin tone perfection levels represented by RGB,<br> for example, 16242611, which is 0xF7D7B3 in hexadecimal format, where F7, D7, and B3 represent the values of the R channel, G channel, and B channel, respectively.   |
3216
3217**System API**: This is a system API.
3218
3219**System capability**: SystemCapability.Multimedia.Camera.Core
3220
3221**Parameters**
3222
3223| Name     | Type                   | Mandatory| Description      |
3224| -------- | --------------------------| ---- | ----------|
3225| type     | [BeautyType](#beautytype) | Yes  | Beauty type.  |
3226
3227**Return value**
3228
3229| Type       | Description                         |
3230| ---------- | ----------------------------- |
3231|  Array\<number\>     | Array of levels supported.|
3232
3233**Error codes**
3234
3235For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
3236
3237| ID        | Error Message       |
3238| --------------- | --------------- |
3239| 7400103                |  Session not config.                                   |
3240
3241**Example**
3242
3243```ts
3244function getSupportedBeautyRange(portraitSession: camera.PortraitSession): Array<number> {
3245  let beautyTypes: Array<camera.BeautyType> = portraitSession.getSupportedBeautyTypes();
3246  if (beautyTypes === undefined || beautyTypes.length <= 0) {
3247    return [];
3248  }
3249  let beautyLevels: Array<number> = portraitSession.getSupportedBeautyRange(beautyTypes[0]);
3250  return beautyLevels;
3251}
3252```
3253
3254### setBeauty
3255
3256setBeauty(type: BeautyType, value: number): void
3257
3258Sets a beauty type and its level. Beauty mode is turned off only when all the [beauty types](#beautytype) obtained through [getSupportedBeautyTypes](#getsupportedbeautytypes) are disabled.
3259
3260**System API**: This is a system API.
3261
3262**System capability**: SystemCapability.Multimedia.Camera.Core
3263
3264**Parameters**
3265
3266| Name     | Type                   | Mandatory| Description                  |
3267| -------- | --------------------------| ---- | --------------------- |
3268| type     | [BeautyType](#beautytype) | Yes  | Beauty type.              |
3269| value    | number                    | Yes  | Beauty level, which can be obtained through [getSupportedBeautyRange](#getsupportedbeautyrange).|
3270
3271**Error codes**
3272
3273For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
3274
3275| ID        | Error Message       |
3276| --------------- | --------------- |
3277| 7400103                |  Session not config.                                   |
3278
3279**Example**
3280
3281```ts
3282function setBeauty(portraitSession: camera.PortraitSession): void {
3283  let beautyTypes: Array<camera.BeautyType> = portraitSession.getSupportedBeautyTypes();
3284  if (beautyTypes === undefined || beautyTypes.length <= 0) {
3285    return;
3286  }
3287  let beautyLevels: Array<number> = portraitSession.getSupportedBeautyRange(beautyTypes[0]);
3288  if (beautyLevels === undefined || beautyLevels.length <= 0) {
3289    return;
3290  }
3291  portraitSession.setBeauty(beautyTypes[0], beautyLevels[0]);
3292}
3293```
3294
3295### getBeauty
3296
3297getBeauty(type: BeautyType): number
3298
3299Obtains the level of the beauty type in use.
3300
3301**System API**: This is a system API.
3302
3303**System capability**: SystemCapability.Multimedia.Camera.Core
3304
3305**Parameters**
3306
3307| Name     | Type                                             | Mandatory| Description                   |
3308| -------- | ------------------------------------------------- | ---- | --------------------- |
3309| type     | [BeautyType](#beautytype) | Yes  | Beauty type.  |
3310
3311**Return value**
3312| Name     | Type                                             | Mandatory| Description                   |
3313| -------- | ------------------------------------------------- | ---- | --------------------- |
3314| value     | number | Yes  | Beauty level. |
3315
3316**Error codes**
3317
3318For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
3319
3320| ID        | Error Message       |
3321| --------------- | --------------- |
3322| 7400103                |  Session not config.                                   |
3323
3324**Example**
3325
3326```ts
3327function getBeauty(portraitSession: camera.PortraitSession): number {
3328  const invalid_value: number = -1;
3329  let beautyTypes = portraitSession.getSupportedBeautyTypes();
3330  if (beautyTypes === undefined || beautyTypes.length <= 0) {
3331    return invalid_value;
3332  }
3333  let beautyLevels: Array<number> = portraitSession.getSupportedBeautyRange(beautyTypes[0]);
3334  if (beautyLevels === undefined || beautyLevels.length <= 0) {
3335    return invalid_value;
3336  }
3337  portraitSession.setBeauty(beautyTypes[0], beautyLevels[0]);
3338  let beautyLevel: number = portraitSession.getBeauty(beautyTypes[0]);
3339  return beautyLevel;
3340}
3341```
3342
3343### on('focusStateChange')
3344
3345on(type: 'focusStateChange', callback: AsyncCallback\<FocusState\>): void
3346
3347Subscribes to focus state events. This API uses an asynchronous callback to return the result.
3348
3349**System capability**: SystemCapability.Multimedia.Camera.Core
3350
3351**Parameters**
3352
3353| Name    | Type                                     | Mandatory| Description                      |
3354| -------- | ----------------------------------------- | ---- | ------------------------ |
3355| type     | string                                    | Yes  | Event type. The value is fixed at **'focusStateChange'**. The event can be listened for when a session is created. This event is triggered only when the camera focus state changes in auto focus mode.|
3356| callback | AsyncCallback\<[FocusState](#focusstate)\> | Yes  | Callback used to return the focus state change. |
3357
3358**Example**
3359
3360```ts
3361import { BusinessError } from '@ohos.base';
3362
3363function registerFocusStateChange(captureSession: camera.CaptureSession): void {
3364  captureSession.on('focusStateChange', (err: BusinessError, focusState: camera.FocusState) => {
3365    console.log(`Focus state: ${focusState}`);
3366  });
3367}
3368```
3369
3370### off('focusStateChange')
3371
3372off(type: 'focusStateChange', callback?: AsyncCallback\<FocusState\>): void
3373
3374Unsubscribes from focus state events.
3375
3376**System capability**: SystemCapability.Multimedia.Camera.Core
3377
3378**Parameters**
3379
3380| Name    | Type                                     | Mandatory| Description                      |
3381| -------- | ----------------------------------------- | ---- | ------------------------ |
3382| type     | string                                    | Yes  | Event type. The value is fixed at **'focusStateChange'**. The event can be listened for when a session is created.|
3383| callback | AsyncCallback\<[FocusState](#focusstate)\> | No  | Callback used for unsubscription. |
3384
3385**Example**
3386
3387```ts
3388function unregisterFocusStateChange(captureSession: camera.CaptureSession): void {
3389  captureSession.off('focusStateChange');
3390}
3391```
3392
3393### on('error')
3394
3395on(type: 'error', callback: ErrorCallback): void
3396
3397Subscribes to **CaptureSession** error events. This API uses a callback to return the result.
3398
3399**System capability**: SystemCapability.Multimedia.Camera.Core
3400
3401**Parameters**
3402
3403| Name    | Type                                                         | Mandatory| Description                          |
3404| -------- | ----------------------------------------------------------- | ---- | ------------------------------ |
3405| type     | string                                                      | Yes  | Event type. The value is fixed at **'error'**. The event can be listened for when a session is created. This event is triggered and the error message is returned when an error occurs during the calling of a session-related API such as **beginConfig()**, **commitConfig()**, and **addInput**.|
3406| callback | ErrorCallback| Yes  | Callback used to return an error code defined in [CameraErrorCode](#cameraerrorcode).       |
3407
3408**Example**
3409
3410```ts
3411import { BusinessError } from '@ohos.base';
3412
3413function registerCaptureSessionError(captureSession: camera.CaptureSession): void {
3414  captureSession.on('error', (error: BusinessError) => {
3415    console.log(`Capture session error code: ${error.code}`);
3416  });
3417}
3418```
3419
3420### off('error')
3421
3422off(type: 'error', callback?: ErrorCallback): void
3423
3424Unsubscribes from **CaptureSession** error events. This API uses a callback to return the result.
3425
3426**System capability**: SystemCapability.Multimedia.Camera.Core
3427
3428**Parameters**
3429
3430| Name    | Type                                                         | Mandatory| Description                          |
3431| -------- | ----------------------------------------------------------- | ---- | ------------------------------ |
3432| type     | string                                                      | Yes  | Event type. The value is fixed at **'error'**. The event can be listened for when a session is created.|
3433| callback | ErrorCallback| No  | Callback used for unsubscription.      |
3434
3435**Example**
3436
3437```ts
3438function unregisterCaptureSessionError(captureSession: camera.CaptureSession): void {
3439  captureSession.off('error');
3440}
3441```
3442## PortraitSession
3443
3444This class inherits from [CaptureSession](#capturesession). It is used to set parameters of portrait mode.
3445
3446### getSupportedPortraitEffects
3447
3448getSupportedPortraitEffects(): Array<[PortraitEffect](#portraiteffect)>
3449
3450Obtains the supported portrait effects.
3451
3452**System API**: This is a system API.
3453
3454**System capability**: SystemCapability.Multimedia.Camera.Core
3455
3456**Return value**
3457
3458| Type                                            | Description                          |
3459| ----------------------------------------------- | ---------------------------- |
3460| Array<[PortraitEffect](#portraiteffect) > | Array of the supported portrait effects.              |
3461
3462**Error codes**
3463
3464For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
3465
3466| ID        | Error Message       |
3467| --------------- | --------------- |
3468| 7400103                |  Session not config.                                   |
3469
3470**Example**
3471
3472```ts
3473function getSupportedPortraitEffects(portraitSession: camera.PortraitSession): Array<camera.PortraitEffect> {
3474  let portraitEffects: Array<camera.PortraitEffect> = portraitSession.getSupportedPortraitEffects();
3475  return portraitEffects;
3476}
3477```
3478### setPortraitEffect
3479
3480setPortraitEffect(effect: PortraitEffect): void
3481
3482Sets a portrait effect.
3483
3484**System API**: This is a system API.
3485
3486**System capability**: SystemCapability.Multimedia.Camera.Core
3487
3488**Parameters**
3489
3490| Name        | Type                                                           | Mandatory| Description                     |
3491| ------------ |--------------------------------------------------------------- | -- | -------------------------- |
3492| effect | [PortraitEffect](#portraiteffect)                              | Yes| Portrait effect, which can be obtained through [getSupportedPortraitEffects](#getsupportedportraiteffects).  |
3493
3494**Error codes**
3495
3496For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
3497
3498| ID        | Error Message       |
3499| --------------- | --------------- |
3500| 7400103                |  Session not config.                                   |
3501
3502**Example**
3503
3504```ts
3505import { BusinessError } from '@ohos.base';
3506
3507function setPortraitEffect(portraitSession: camera.PortraitSession, portraitEffects: Array<camera.PortraitEffect>): void {
3508  if (portraitEffects === undefined || portraitEffects.length <= 0) {
3509    return;
3510  }
3511  try {
3512    portraitSession.setPortraitEffect(portraitEffects[0]);
3513  } catch (error) {
3514    let err = error as BusinessError;
3515    console.error(`The setPortraitEffect call failed. error code: ${err.code}`);
3516  }
3517}
3518```
3519### getPortraitEffect
3520
3521getPortraitEffect(): PortraitEffect
3522
3523Obtains the portrait effect in use.
3524
3525**System API**: This is a system API.
3526
3527**System capability**: SystemCapability.Multimedia.Camera.Core
3528
3529**Return value**
3530
3531| Type                                            | Description                          |
3532| ----------------------------------------------- | ---------------------------- |
3533| [PortraitEffect](#portraiteffect)               | Portrait effect in use.               |
3534
3535**Error codes**
3536
3537For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
3538
3539| ID        | Error Message       |
3540| --------------- | --------------- |
3541| 7400103                |  Session not config.                                   |
3542
3543**Example**
3544
3545```ts
3546function getSupportedPortraitEffects(portraitSession: camera.PortraitSession): Array<camera.PortraitEffect> {
3547  let portraitEffects: Array<camera.PortraitEffect> = portraitSession.getSupportedPortraitEffects();
3548  return portraitEffects;
3549}
3550```
3551
3552## CameraOutput
3553
3554Implements output information used in a **[CaptureSession](#capturesession)**. It is the base class of **output**.
3555
3556## PreviewOutput
3557
3558Implements preview output. It inherits **[CameraOutput](#cameraoutput)**.
3559
3560### start
3561
3562start(callback: AsyncCallback\<void\>): void
3563
3564Starts to output preview streams. This API uses an asynchronous callback to return the result.
3565
3566**System capability**: SystemCapability.Multimedia.Camera.Core
3567
3568**Parameters**
3569
3570| Name     | Type                 | Mandatory| Description                |
3571| -------- | -------------------- | ---- | -------------------- |
3572| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
3573
3574**Error codes**
3575
3576For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
3577
3578| ID        | Error Message       |
3579| --------------- | --------------- |
3580| 7400103                |  Session not config.                                   |
3581
3582**Example**
3583
3584```ts
3585import { BusinessError } from '@ohos.base';
3586
3587function startPreviewOutput(previewOutput: camera.PreviewOutput): void {
3588  previewOutput.start((err: BusinessError) => {
3589    if (err) {
3590      console.error(`Failed to start the previewOutput. ${err.code}`);
3591      return;
3592    }
3593    console.log('Callback returned with previewOutput started.');
3594  });
3595}
3596```
3597
3598### start
3599
3600start(): Promise\<void\>
3601
3602Starts to output preview streams. This API uses a promise to return the result.
3603
3604**System capability**: SystemCapability.Multimedia.Camera.Core
3605
3606**Return value**
3607
3608| Type           | Description                    |
3609| -------------- | ----------------------- |
3610| Promise\<void\> | Promise used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
3611
3612**Error codes**
3613
3614For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
3615
3616| ID        | Error Message       |
3617| --------------- | --------------- |
3618| 7400103                |  Session not config.                                   |
3619
3620**Example**
3621
3622```ts
3623import { BusinessError } from '@ohos.base';
3624
3625function startPreviewOutput(previewOutput: camera.PreviewOutput): void {
3626  previewOutput.start().then(() => {
3627    console.log('Promise returned with previewOutput started.');
3628  }).catch((err: BusinessError) => {
3629    console.log('Failed to previewOutput start '+ err.code);
3630  });
3631}
3632```
3633
3634### stop
3635
3636stop(callback: AsyncCallback\<void\>): void
3637
3638Stops outputting preview streams. This API uses an asynchronous callback to return the result.
3639
3640**System capability**: SystemCapability.Multimedia.Camera.Core
3641
3642**Parameters**
3643
3644| Name     | Type                 | Mandatory| Description                |
3645| -------- | -------------------- | ---- | -------------------- |
3646| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result.|
3647
3648**Example**
3649
3650```ts
3651import { BusinessError } from '@ohos.base';
3652
3653function stopPreviewOutput(previewOutput: camera.PreviewOutput): void {
3654  previewOutput.stop((err: BusinessError) => {
3655    if (err) {
3656      console.error(`Failed to stop the previewOutput. ${err.code}`);
3657      return;
3658    }
3659    console.log('Callback returned with previewOutput stopped.');
3660  })
3661}
3662```
3663
3664### stop
3665
3666stop(): Promise\<void\>
3667
3668Stops outputting preview streams. This API uses a promise to return the result.
3669
3670**System capability**: SystemCapability.Multimedia.Camera.Core
3671
3672**Return value**
3673
3674| Type           | Description                    |
3675| -------------- | ------------------------ |
3676| Promise\<void\> | Promise used to return the result.|
3677
3678**Example**
3679
3680```ts
3681import { BusinessError } from '@ohos.base';
3682
3683function stopPreviewOutput(previewOutput: camera.PreviewOutput): void {
3684  previewOutput.stop().then(() => {
3685    console.log('Callback returned with previewOutput stopped.');
3686  }).catch((err: BusinessError) => {
3687    console.log('Failed to previewOutput stop '+ err.code);
3688  });
3689}
3690```
3691
3692### release
3693
3694release(callback: AsyncCallback\<void\>): void
3695
3696Releases output resources. This API uses an asynchronous callback to return the result.
3697
3698**System capability**: SystemCapability.Multimedia.Camera.Core
3699
3700**Parameters**
3701
3702| Name     | Type                 | Mandatory| Description                |
3703| -------- | -------------------- | ---- | ------------------- |
3704| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
3705
3706**Error codes**
3707
3708For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
3709
3710| ID        | Error Message       |
3711| --------------- | --------------- |
3712| 7400201                |  Camera service fatal error.                           |
3713
3714**Example**
3715
3716```ts
3717import { BusinessError } from '@ohos.base';
3718
3719function releasePreviewOutput(previewOutput: camera.PreviewOutput): void {
3720  previewOutput.release((err: BusinessError) => {
3721    if (err) {
3722      console.error(`Failed to release the PreviewOutput instance ${err.code}`);
3723      return;
3724    }
3725    console.log('Callback invoked to indicate that the PreviewOutput instance is released successfully.');
3726  });
3727}
3728```
3729
3730### release
3731
3732release(): Promise\<void\>
3733
3734Releases output resources. This API uses a promise to return the result.
3735
3736**System capability**: SystemCapability.Multimedia.Camera.Core
3737
3738**Return value**
3739
3740| Type           | Description                    |
3741| -------------- | ----------------------- |
3742| Promise\<void\> | Promise used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
3743
3744**Error codes**
3745
3746For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
3747
3748| ID        | Error Message       |
3749| --------------- | --------------- |
3750| 7400201                |  Camera service fatal error.                           |
3751
3752**Example**
3753
3754```ts
3755import { BusinessError } from '@ohos.base';
3756
3757function releasePreviewOutput(previewOutput: camera.PreviewOutput): void {
3758  previewOutput.release().then(() => {
3759    console.log('Promise returned to indicate that the PreviewOutput instance is released successfully.');
3760  }).catch((err: BusinessError) => {
3761    console.log('Failed to previewOutput release '+ err.code);
3762  });
3763}
3764```
3765
3766### on('frameStart')
3767
3768on(type: 'frameStart', callback: AsyncCallback\<void\>): void
3769
3770Subscribes to preview frame start events. This API uses an asynchronous callback to return the result.
3771
3772**System capability**: SystemCapability.Multimedia.Camera.Core
3773
3774**Parameters**
3775
3776| Name     | Type                 | Mandatory| Description                                    |
3777| -------- | -------------------- | ---- | --------------------------------------- |
3778| type     | string               | Yes  | Event type. The value is fixed at **'frameStart'**. The event can be listened for when a **previewOutput** instance is created. This event is triggered and returned when the bottom layer starts exposure for the first time.|
3779| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result. The preview starts as long as this event is returned.                    |
3780
3781**Example**
3782
3783```ts
3784function registerPreviewOutputFrameStart(previewOutput: camera.PreviewOutput): void {
3785  previewOutput.on('frameStart', () => {
3786    console.log('Preview frame started');
3787  });
3788}
3789```
3790
3791### off('frameStart')
3792
3793off(type: 'frameStart', callback?: AsyncCallback\<void\>): void
3794
3795Unsubscribes from preview frame start events.
3796
3797**System capability**: SystemCapability.Multimedia.Camera.Core
3798
3799**Parameters**
3800
3801| Name     | Type                 | Mandatory| Description                                    |
3802| -------- | -------------------- | ---- | --------------------------------------- |
3803| type     | string               | Yes  | Event type. The value is fixed at **'frameStart'**. The event can be listened for when a **previewOutput** instance is created.|
3804| callback | AsyncCallback\<void\> | No  | Callback used for unsubscription.                    |
3805
3806**Example**
3807
3808```ts
3809function unregisterPreviewOutputFrameStart(previewOutput: camera.PreviewOutput): void {
3810  previewOutput.off('frameStart');
3811}
3812```
3813
3814### on('frameEnd')
3815
3816on(type: 'frameEnd', callback: AsyncCallback\<void\>): void
3817
3818Subscribes to preview frame end events. This API uses an asynchronous callback to return the result.
3819
3820**System capability**: SystemCapability.Multimedia.Camera.Core
3821
3822**Parameters**
3823
3824| Name     | Type                 | Mandatory| Description                                 |
3825| -------- | -------------------- | ---- | ------------------------------------- |
3826| type     | string               | Yes  | Event type. The value is fixed at **'frameEnd'**. The event can be listened for when a **previewOutput** instance is created. This event is triggered and returned when the last frame of preview ends.|
3827| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result. The preview ends as long as this event is returned.                |
3828
3829**Example**
3830
3831```ts
3832function registerPreviewOutputFrameEnd(previewOutput: camera.PreviewOutput): void {
3833  previewOutput.on('frameEnd', () => {
3834    console.log('Preview frame ended');
3835  });
3836}
3837```
3838
3839### off('frameEnd')
3840
3841off(type: 'frameEnd', callback?: AsyncCallback\<void\>): void
3842
3843Unsubscribes from preview frame end events.
3844
3845**System capability**: SystemCapability.Multimedia.Camera.Core
3846
3847**Parameters**
3848
3849| Name     | Type                 | Mandatory| Description                                 |
3850| -------- | -------------------- | ---- | ------------------------------------- |
3851| type     | string               | Yes  | Event type. The value is fixed at **'frameEnd'**. The event can be listened for when a **previewOutput** instance is created.|
3852| callback | AsyncCallback\<void\> | No  | Callback used for unsubscription.               |
3853
3854**Example**
3855
3856```ts
3857function unregisterPreviewOutputFrameEnd(previewOutput: camera.PreviewOutput): void {
3858  previewOutput.off('frameEnd');
3859}
3860```
3861
3862### on('error')
3863
3864on(type: 'error', callback: ErrorCallback): void
3865
3866Subscribes to **PreviewOutput** error events. This API uses a callback to return the result.
3867
3868**System capability**: SystemCapability.Multimedia.Camera.Core
3869
3870**Parameters**
3871
3872| Name    | Type        | Mandatory| Description                      |
3873| -------- | --------------| ---- | ------------------------ |
3874| type     | string        | Yes  | Event type. The value is fixed at **'error'**. The event can be listened for when a **previewOutput** instance is created. This event is triggered and the corresponding error message is returned when an error occurs during the use of a preview-related API such as **start()** or **release()**.|
3875| callback | ErrorCallback | Yes  | Callback used to return an error code defined in [CameraErrorCode](#cameraerrorcode). |
3876
3877**Example**
3878
3879```ts
3880import { BusinessError } from '@ohos.base';
3881
3882function registerPreviewOutputError(previewOutput: camera.PreviewOutput): void {
3883  previewOutput.on('error', (previewOutputError: BusinessError) => {
3884    console.log(`Preview output error code: ${previewOutputError.code}`);
3885  })
3886}
3887```
3888
3889### off('error')
3890
3891off(type: 'error', callback?: ErrorCallback): void
3892
3893Unsubscribes from **PreviewOutput** error events.
3894
3895**System capability**: SystemCapability.Multimedia.Camera.Core
3896
3897**Parameters**
3898
3899| Name    | Type        | Mandatory| Description                      |
3900| -------- | --------------| ---- | ------------------------ |
3901| type     | string        | Yes  | Event type. The value is fixed at **'error'**. The event can be listened for when a **previewOutput** instance is created.|
3902| callback | ErrorCallback | No  | Callback used for unsubscription. |
3903
3904**Example**
3905
3906```ts
3907function unregisterPreviewOutputError(previewOutput: camera.PreviewOutput): void {
3908  previewOutput.off('error');
3909}
3910```
3911
3912### addDeferredSurface
3913
3914addDeferredSurface(surfaceId: string): void
3915
3916Adds a surface for delayed preview. This API can run after **session.commitConfig()** or **session.start()** is called.
3917
3918**System API**: This is a system API.
3919
3920**System capability**: SystemCapability.Multimedia.Camera.Core
3921
3922**Parameters**
3923
3924| Name    | Type        | Mandatory| Description                      |
3925| -------- | --------------| ---- | ------------------------ |
3926| surfaceId | string | Yes| Surface ID, which is obtained from **[XComponent](../arkui-ts/ts-basic-components-xcomponent.md)**.|
3927
3928**Error codes**
3929
3930For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
3931
3932| ID        | Error Message       |
3933| --------------- | --------------- |
3934| 7400101                |  Parameter missing or parameter type incorrect        |
3935
3936**Example**
3937
3938```ts
3939import featureAbility from '@ohos.ability.featureAbility';
3940
3941async function preview(context: featureAbility.Context, cameraInfo: camera.CameraDevice, previewProfile: camera.Profile, photoProfile: camera.Profile, photoSurfaceId: string, previewSurfaceId: string): Promise<void> {
3942  const cameraManager: camera.CameraManager = camera.getCameraManager(context);
3943  const cameraInput: camera.CameraInput = cameraManager.createCameraInput(cameraInfo)
3944  const previewOutput: camera.PreviewOutput = cameraManager.createDeferredPreviewOutput(previewProfile);
3945  const photoOutput: camera.PhotoOutput = cameraManager.createPhotoOutput(photoProfile, photoSurfaceId);
3946  const session: camera.CaptureSession  = cameraManager.createCaptureSession();
3947  session.beginConfig();
3948  session.addInput(cameraInput);
3949  session.addOutput(previewOutput);
3950  session.addOutput(photoOutput);
3951  await session.commitConfig();
3952  await session.start();
3953  previewOutput.addDeferredSurface(previewSurfaceId);
3954}
3955```
3956
3957## ImageRotation
3958
3959Enumerates the image rotation angles.
3960
3961**System capability**: SystemCapability.Multimedia.Camera.Core
3962
3963| Name         | Value  | Description          |
3964| ------------ | ---- | ------------- |
3965| ROTATION_0   | 0    | The image rotates 0 degrees.  |
3966| ROTATION_90  | 90   | The image rotates 90 degrees. |
3967| ROTATION_180 | 180  | The image rotates 180 degrees.|
3968| ROTATION_270 | 270  | The image rotates 270 degrees.|
3969
3970## Location
3971
3972Defines geolocation information.
3973
3974**System capability**: SystemCapability.Multimedia.Camera.Core
3975
3976| Name         | Type  | Mandatory|Description        |
3977| ------------ | ------ | --- |------------ |
3978| latitude     | number | Yes |Latitude, in degrees.   |
3979| longitude    | number | Yes |Longitude, in degrees.   |
3980| altitude     | number | Yes |Altitude, in meters.   |
3981
3982## QualityLevel
3983
3984Enumerates the image quality levels.
3985
3986**System capability**: SystemCapability.Multimedia.Camera.Core
3987
3988| Name                 | Value  | Description        |
3989| -------------------- | ---- | ------------ |
3990| QUALITY_LEVEL_HIGH   | 0    | High image quality.  |
3991| QUALITY_LEVEL_MEDIUM | 1    | Medium image quality.|
3992| QUALITY_LEVEL_LOW    | 2    | Low image quality.  |
3993
3994
3995## PhotoCaptureSetting
3996
3997Defines the settings for photo capture.
3998
3999**System capability**: SystemCapability.Multimedia.Camera.Core
4000
4001| Name     | Type                           | Mandatory | Description             |
4002| -------- | ------------------------------- | ---- | -----------------|
4003| quality  | [QualityLevel](#qualitylevel)   | No  | Photo quality.        |
4004| rotation | [ImageRotation](#imagerotation) | No  | Rotation angle of the photo.     |
4005| location | [Location](#location)           | No  | Geolocation information of the photo.  |
4006| mirror   | boolean                         | No  |Whether mirroring is enabled. By default, mirroring is disabled.|
4007
4008## PhotoOutput
4009
4010Implements output information used in a shooting session. This class inherits from [CameraOutput](#cameraoutput).
4011
4012### capture
4013
4014capture(callback: AsyncCallback\<void\>): void
4015
4016Captures a photo with the default shooting parameters. This API uses an asynchronous callback to return the result.
4017
4018**System capability**: SystemCapability.Multimedia.Camera.Core
4019
4020**Parameters**
4021
4022| Name     | Type                 | Mandatory| Description                |
4023| -------- | -------------------- | ---- | ------------------- |
4024| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
4025
4026**Error codes**
4027
4028For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
4029
4030| ID        | Error Message       |
4031| --------------- | --------------- |
4032| 7400104                |  Session not running.                                  |
4033| 7400201                |  Camera service fatal error.                           |
4034
4035**Example**
4036
4037```ts
4038import { BusinessError } from '@ohos.base';
4039
4040function capture(photoOutput: camera.PhotoOutput): void {
4041  photoOutput.capture((err: BusinessError) => {
4042    if (err) {
4043      console.error(`Failed to capture the photo ${err.code}`);
4044      return;
4045    }
4046    console.log('Callback invoked to indicate the photo capture request success.');
4047  });
4048}
4049```
4050
4051### capture
4052
4053capture(): Promise\<void\>
4054
4055Captures a photo with the default shooting parameters. This API uses a promise to return the result.
4056
4057**System capability**: SystemCapability.Multimedia.Camera.Core
4058
4059**Return value**
4060
4061| Type           | Description                    |
4062| -------------- | ------------------------ |
4063| Promise\<void\> | Promise used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
4064
4065**Error codes**
4066
4067For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
4068
4069| ID        | Error Message       |
4070| --------------- | --------------- |
4071| 7400104                |  Session not running.                                  |
4072| 7400201                |  Camera service fatal error.                           |
4073
4074**Example**
4075
4076```ts
4077import { BusinessError } from '@ohos.base';
4078
4079function capture(photoOutput: camera.PhotoOutput): void {
4080  photoOutput.capture().then(() => {
4081    console.log('Promise returned to indicate that photo capture request success.');
4082  }).catch((err: BusinessError) => {
4083    console.log('Failed to photoOutput capture '+ err.code);
4084  });
4085}
4086```
4087
4088### capture
4089
4090capture(setting: PhotoCaptureSetting, callback: AsyncCallback\<void\>): void
4091
4092Captures a photo with the specified shooting parameters. This API uses an asynchronous callback to return the result.
4093
4094**System capability**: SystemCapability.Multimedia.Camera.Core
4095
4096**Parameters**
4097
4098| Name     | Type                                        | Mandatory| Description                 |
4099| -------- | ------------------------------------------- | ---- | -------------------- |
4100| setting  | [PhotoCaptureSetting](#photocapturesetting) | Yes  | Shooting settings.            |
4101| callback | AsyncCallback\<void\>                        | Yes  | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned. |
4102
4103**Error codes**
4104
4105For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
4106
4107| ID        | Error Message       |
4108| --------------- | --------------- |
4109| 7400101                |  Parameter missing or parameter type incorrect        |
4110| 7400104                |  Session not running.                                  |
4111| 7400201                |  Camera service fatal error.                           |
4112
4113**Example**
4114
4115```ts
4116import { BusinessError } from '@ohos.base';
4117
4118function capture(photoOutput: camera.PhotoOutput): void {
4119  let captureLocation: camera.Location = {
4120    latitude: 0,
4121    longitude: 0,
4122    altitude: 0,
4123  }
4124  let settings: camera.PhotoCaptureSetting = {
4125    quality: camera.QualityLevel.QUALITY_LEVEL_LOW,
4126    rotation: camera.ImageRotation.ROTATION_0,
4127    location: captureLocation,
4128    mirror: false
4129  }
4130  photoOutput.capture(settings, (err: BusinessError) => {
4131    if (err) {
4132      console.error(`Failed to capture the photo ${err.code}`);
4133      return;
4134    }
4135    console.log('Callback invoked to indicate the photo capture request success.');
4136  });
4137}
4138```
4139
4140### capture
4141
4142capture(setting?: PhotoCaptureSetting): Promise\<void\>
4143
4144Captures a photo with the specified shooting parameters. This API uses a promise to return the result.
4145
4146**System capability**: SystemCapability.Multimedia.Camera.Core
4147
4148**Parameters**
4149
4150| Name    | Type                                        | Mandatory| Description     |
4151| ------- | ------------------------------------------- | ---- | -------- |
4152| setting | [PhotoCaptureSetting](#photocapturesetting) | No  | Shooting parameters. The input of **undefined** is processed as if no parameters were passed.|
4153
4154**Return value**
4155
4156| Type           | Description                    |
4157| -------------- | ------------------------ |
4158| Promise\<void\> | Promise used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
4159
4160**Error codes**
4161
4162For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
4163
4164| ID        | Error Message       |
4165| --------------- | --------------- |
4166| 7400101                |  Parameter missing or parameter type incorrect        |
4167| 7400104                |  Session not running.                                  |
4168| 7400201                |  Camera service fatal error.                           |
4169
4170**Example**
4171
4172```ts
4173import { BusinessError } from '@ohos.base';
4174
4175function capture(photoOutput: camera.PhotoOutput): void {
4176  let captureLocation: camera.Location = {
4177    latitude: 0,
4178    longitude: 0,
4179    altitude: 0,
4180  }
4181  let settings: camera.PhotoCaptureSetting = {
4182    quality: camera.QualityLevel.QUALITY_LEVEL_LOW,
4183    rotation: camera.ImageRotation.ROTATION_0,
4184    location: captureLocation,
4185    mirror: false
4186  }
4187  photoOutput.capture(settings).then(() => {
4188    console.log('Promise returned to indicate that photo capture request success.');
4189  }).catch((err: BusinessError) => {
4190    console.log('Failed to photoOutput capture '+ err.code);
4191  });
4192}
4193```
4194
4195### isMirrorSupported
4196
4197isMirrorSupported(): boolean
4198
4199Checks whether mirroring is supported.
4200
4201**System capability**: SystemCapability.Multimedia.Camera.Core
4202
4203**Return value**
4204
4205| Type           | Description                    |
4206| -------------- | ----------------------- |
4207| boolean | Returns **true** if mirroring is supported; returns **false** otherwise.|
4208
4209**Example**
4210
4211```ts
4212function isMirrorSupported(photoOutput: camera.PhotoOutput): boolean {
4213  let isSupported: boolean = photoOutput.isMirrorSupported();
4214  return isSupported;
4215}
4216```
4217
4218### release
4219
4220release(callback: AsyncCallback\<void\>): void
4221
4222Releases output resources. This API uses an asynchronous callback to return the result.
4223
4224**System capability**: SystemCapability.Multimedia.Camera.Core
4225
4226**Parameters**
4227
4228| Name     | Type                 | Mandatory| Description                |
4229| -------- | -------------------- | ---- | ------------------- |
4230| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
4231
4232**Error codes**
4233
4234For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
4235
4236| ID        | Error Message       |
4237| --------------- | --------------- |
4238| 7400201                |  Camera service fatal error.                           |
4239
4240**Example**
4241
4242```ts
4243import { BusinessError } from '@ohos.base';
4244
4245function releasePhotoOutput(photoOutput: camera.PhotoOutput): void {
4246  photoOutput.release((err: BusinessError) => {
4247    if (err) {
4248      console.error(`Failed to release the PreviewOutput instance ${err.code}`);
4249      return;
4250    }
4251    console.log('Callback invoked to indicate that the PreviewOutput instance is released successfully.');
4252  });
4253}
4254```
4255
4256### release
4257
4258release(): Promise\<void\>
4259
4260Releases output resources. This API uses a promise to return the result.
4261
4262**System capability**: SystemCapability.Multimedia.Camera.Core
4263
4264**Return value**
4265
4266| Type           | Description                    |
4267| -------------- | ----------------------- |
4268| Promise\<void\> | Promise used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
4269
4270**Error codes**
4271
4272For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
4273
4274| ID        | Error Message       |
4275| --------------- | --------------- |
4276| 7400201                |  Camera service fatal error.                           |
4277
4278**Example**
4279
4280```ts
4281import { BusinessError } from '@ohos.base';
4282
4283function releasePhotoOutput(photoOutput: camera.PhotoOutput): void {
4284  photoOutput.release().then(() => {
4285    console.log('Promise returned to indicate that the PreviewOutput instance is released successfully.');
4286  }).catch((err: BusinessError) => {
4287    console.log('Failed to photoOutput release '+ err.code);
4288  });
4289}
4290```
4291
4292### on('captureStart')
4293
4294on(type: 'captureStart', callback: AsyncCallback\<number\>): void
4295
4296Subscribes to shooting start events. This API uses an asynchronous callback to return the capture ID.
4297
4298**System capability**: SystemCapability.Multimedia.Camera.Core
4299
4300**Parameters**
4301
4302| Name     | Type                   | Mandatory| Description                                      |
4303| -------- | ---------------------- | ---- | ------------------------------------------ |
4304| type     | string                 | Yes  | Event type. The value is fixed at **'captureStart'**. The event can be listened for when a **photoOutput** instance is created. This event is triggered and returned when the bottom layer starts exposure each time a photo is taken.|
4305| callback | AsyncCallback\<number\> | Yes  | Callback used to return the capture ID.           |
4306
4307**Example**
4308
4309```ts
4310import { BusinessError } from '@ohos.base';
4311
4312function registerPhotoOutputCaptureStart(photoOutput: camera.PhotoOutput): void {
4313  photoOutput.on('captureStart', (err: BusinessError, captureId: number) => {
4314    console.log(`photo capture stated, captureId : ${captureId}`);
4315  });
4316}
4317```
4318
4319### off('captureStart')
4320
4321off(type: 'captureStart', callback?: AsyncCallback\<number\>): void
4322
4323Unsubscribes from shooting start events.
4324
4325**System capability**: SystemCapability.Multimedia.Camera.Core
4326
4327**Parameters**
4328
4329| Name     | Type                   | Mandatory| Description                                      |
4330| -------- | ---------------------- | ---- | ------------------------------------------ |
4331| type     | string                 | Yes  | Event type. The value is fixed at **'captureStart'**. The event can be listened for when a **photoOutput** instance is created.|
4332| callback | AsyncCallback\<number\> | No  | Callback used for unsubscription.           |
4333
4334**Example**
4335
4336```ts
4337function unregisterPhotoOutputCaptureStart(photoOutput: camera.PhotoOutput): void {
4338  photoOutput.off('captureStart');
4339}
4340```
4341
4342### on('frameShutter')
4343
4344on(type: 'frameShutter', callback: AsyncCallback\<FrameShutterInfo\>): void
4345
4346Subscribes to frame shutter events. This API uses an asynchronous callback to return the result.
4347
4348**System capability**: SystemCapability.Multimedia.Camera.Core
4349
4350**Parameters**
4351
4352| Name    | Type     | Mandatory| Description                                 |
4353| -------- | ---------- | --- | ------------------------------------ |
4354| type     | string     | Yes  | Event type. The value is fixed at **'frameShutter'**. The event can be listened for when a **photoOutput** instance is created.|
4355| callback | AsyncCallback\<[FrameShutterInfo](#frameshutterinfo)\> | Yes  | Callback used to return the result. A new photographing request can be delivered as long as this event is returned.            |
4356
4357**Example**
4358
4359```ts
4360import { BusinessError } from '@ohos.base';
4361
4362function registerPhotoOutputFrameShutter(photoOutput: camera.PhotoOutput): void {
4363  photoOutput.on('frameShutter', (err: BusinessError, frameShutterInfo: camera.FrameShutterInfo) => {
4364    console.log(`photo capture end, captureId : ${frameShutterInfo.captureId}`);
4365    console.log(`Timestamp for frame : ${frameShutterInfo.timestamp}`);
4366  });
4367}
4368```
4369
4370### off('frameShutter')
4371
4372off(type: 'frameShutter', callback?: AsyncCallback\<FrameShutterInfo\>): void
4373
4374Unsubscribes from frame shutter events.
4375
4376**System capability**: SystemCapability.Multimedia.Camera.Core
4377
4378**Parameters**
4379
4380| Name    | Type     | Mandatory| Description                                 |
4381| -------- | ---------- | --- | ------------------------------------ |
4382| type     | string     | Yes  | Event type. The value is fixed at **'frameShutter'**. The event can be listened for when a **photoOutput** instance is created.|
4383| callback | AsyncCallback\<[FrameShutterInfo](#frameshutterinfo)\> | No  | Callback used for unsubscription.            |
4384
4385**Example**
4386
4387```ts
4388function unregisterPhotoOutputFrameShutter(photoOutput: camera.PhotoOutput): void {
4389  photoOutput.off('frameShutter');
4390}
4391```
4392
4393### on('captureEnd')
4394
4395on(type: 'captureEnd', callback: AsyncCallback\<CaptureEndInfo\>): void
4396
4397Subscribes to shooting end events. This API uses an asynchronous callback to return the result.
4398
4399**System capability**: SystemCapability.Multimedia.Camera.Core
4400
4401**Parameters**
4402
4403| Name    | Type          | Mandatory| Description                                      |
4404| -------- | --------------- | ---- | ---------------------------------------- |
4405| type     | string          | Yes  | Event type. The value is fixed at **'captureEnd'**. The event can be listened for when a **photoOutput** instance is created. This event is triggered and the corresponding information is returned when the photographing is complete.|
4406| callback | AsyncCallback\<[CaptureEndInfo](#captureendinfo)\> | Yes  | Callback used to return the result.                 |
4407
4408**Example**
4409
4410```ts
4411import { BusinessError } from '@ohos.base';
4412
4413function registerPhotoOutputCaptureEnd(photoOutput: camera.PhotoOutput): void {
4414  photoOutput.on('captureEnd', (err: BusinessError, captureEndInfo: camera.CaptureEndInfo) => {
4415    console.log(`photo capture end, captureId : ${captureEndInfo.captureId}`);
4416    console.log(`frameCount : ${captureEndInfo.frameCount}`);
4417  });
4418}
4419```
4420
4421### off('captureEnd')
4422
4423off(type: 'captureEnd', callback?: AsyncCallback\<CaptureEndInfo\>): void
4424
4425Unsubscribes from shooting end events.
4426
4427**System capability**: SystemCapability.Multimedia.Camera.Core
4428
4429**Parameters**
4430
4431| Name    | Type          | Mandatory| Description                                      |
4432| -------- | --------------- | ---- | ---------------------------------------- |
4433| type     | string          | Yes  | Event type. The value is fixed at **'captureEnd'**. The event can be listened for when a **photoOutput** instance is created.|
4434| callback | AsyncCallback\<[CaptureEndInfo](#captureendinfo)\> | No  | Callback used for unsubscription.                 |
4435
4436**Example**
4437
4438```ts
4439function unregisterPhotoOutputCaptureEnd(photoOutput: camera.PhotoOutput): void {
4440  photoOutput.off('captureEnd');
4441}
4442```
4443
4444### on('error')
4445
4446on(type: 'error', callback: ErrorCallback): void
4447
4448Subscribes to **PhotoOutput** error events. This API uses a callback to return the result.
4449
4450**System capability**: SystemCapability.Multimedia.Camera.Core
4451
4452**Parameters**
4453
4454| Name    | Type        | Mandatory| Description                                |
4455| -------- | ------------- | ---- | ----------------------------------- |
4456| type     | string       | Yes  | Event type. The value is fixed at **'error'**. The event can be listened for when a **photoOutput** instance is created. This event is triggered and the corresponding error message is returned when an error occurs during the calling of a photographing-related API.|
4457| callback | ErrorCallback | Yes  | Callback used to return an error code defined in [CameraErrorCode](#cameraerrorcode).            |
4458
4459**Example**
4460
4461```ts
4462import { BusinessError } from '@ohos.base';
4463
4464function registerPhotoOutputError(photoOutput: camera.PhotoOutput): void {
4465  photoOutput.on('error', (error: BusinessError) => {
4466    console.log(`Photo output error code: ${error.code}`);
4467  });
4468}
4469```
4470
4471### off('error')
4472
4473off(type: 'error', callback?: ErrorCallback): void
4474
4475Unsubscribes from **PhotoOutput** error events.
4476
4477**System capability**: SystemCapability.Multimedia.Camera.Core
4478
4479**Parameters**
4480
4481| Name    | Type        | Mandatory| Description                                |
4482| -------- | ------------- | ---- | ----------------------------------- |
4483| type     | string       | Yes  | Event type. The value is fixed at **'error'**. The event can be listened for when a **photoOutput** instance is created.|
4484| callback | ErrorCallback | No  | Callback used for unsubscription.          |
4485
4486**Example**
4487
4488```ts
4489function unregisterPhotoOutputError(photoOutput: camera.PhotoOutput): void {
4490  photoOutput.off('error');
4491}
4492```
4493
4494### isQuickThumbnailSupported
4495
4496isQuickThumbnailSupported(): boolean
4497
4498Checks whether the quick thumbnail feature is supported.
4499
4500This API takes effect after **CaptureSession.addOutput** and **CaptureSession.addInput** and before **CaptureSession.commitConfig**.
4501
4502**System API**: This is a system API.
4503
4504**System capability**: SystemCapability.Multimedia.Camera.Core
4505
4506**Return value**
4507
4508| Type| Description|
4509| --------- | ------ |
4510| boolean | Returns whether the quick thumbnail feature is supported. The value **true** means that the quick thumbnail feature is supported, and **false** means the opposite.|
4511
4512**Error codes**
4513
4514For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
4515
4516| ID        | Error Message       |
4517| --------------- | --------------- |
4518| 7400104                |  session is not running        |
4519
4520**Example**
4521
4522```ts
4523import featureAbility from '@ohos.ability.featureAbility';
4524
4525async function isQuickThumbnailSupported(context: featureAbility.Context, photoProfile: camera.Profile, surfaceId: string): Promise<boolean> {
4526  let cameraManager: camera.CameraManager = camera.getCameraManager(context);
4527  let cameras: Array<camera.CameraDevice> = cameraManager.getSupportedCameras();
4528  // Create a CaptureSession instance.
4529  let captureSession: camera.CaptureSession = cameraManager.createCaptureSession();
4530  // Start configuration for the session.
4531  captureSession.beginConfig();
4532  // Add a CameraInput instance to the session.
4533  let cameraInput: camera.CameraInput = cameraManager.createCameraInput(cameras[0]);
4534  await cameraInput.open();
4535  captureSession.addInput(cameraInput);
4536  // Add the photoOutput object to the session.
4537  let photoOutput: camera.PhotoOutput = cameraManager.createPhotoOutput(photoProfile, surfaceId);
4538  captureSession.addOutput(photoOutput);
4539  let isSupported: boolean = photoOutput.isQuickThumbnailSupported();
4540  return isSupported;
4541}
4542```
4543
4544### enableQuickThumbnail
4545
4546enableQuickThumbnail(enabled: boolean): void
4547
4548Enables or disables the quick thumbnail feature.
4549
4550This API takes effect after **CaptureSession.addOutput** and **CaptureSession.addInput** and before **CaptureSession.commitConfig**.
4551
4552**System API**: This is a system API.
4553
4554**System capability**: SystemCapability.Multimedia.Camera.Core
4555
4556**Parameters**
4557
4558| Name    | Type        | Mandatory| Description                                |
4559| -------- | ------------- | ---- | ----------------------------------- |
4560| enabled    | boolean       | Yes  | Whether to enable the quick thumbnail feature. The value **true** means to enable the quick thumbnail feature, and **false** means the opposite.|
4561
4562**Error codes**
4563
4564For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
4565
4566| ID        | Error Message       |
4567| --------------- | --------------- |
4568| 7400104                |  session is not running        |
4569
4570**Example**
4571
4572```ts
4573import featureAbility from '@ohos.ability.featureAbility';
4574import { BusinessError } from '@ohos.base';
4575
4576async function enableQuickThumbnail(context: featureAbility.Context, photoProfile: camera.Profile, surfaceId: string): Promise<void> {
4577  let cameraManager: camera.CameraManager = camera.getCameraManager(context);
4578  let cameras: Array<camera.CameraDevice> = cameraManager.getSupportedCameras();
4579  // Create a CaptureSession instance.
4580  let captureSession: camera.CaptureSession = cameraManager.createCaptureSession();
4581  // Start configuration for the session.
4582  captureSession.beginConfig();
4583  // Add a CameraInput instance to the session.
4584  let cameraInput: camera.CameraInput = cameraManager.createCameraInput(cameras[0]);
4585  await cameraInput.open();
4586  captureSession.addInput(cameraInput);
4587  // Add a PhotoOutput instance to the session.
4588  let photoOutput: camera.PhotoOutput = cameraManager.createPhotoOutput(photoProfile, surfaceId);
4589  captureSession.addOutput(photoOutput);
4590  let isSupported: boolean = photoOutput.isQuickThumbnailSupported();
4591  if (!isSupported) {
4592    console.log('Quick Thumbnail is not supported to be turned on.');
4593    return;
4594  }
4595  try {
4596    photoOutput.enableQuickThumbnail(true);
4597  } catch (error) {
4598    let err = error as BusinessError;
4599    console.error(`The enableQuickThumbnail call failed. error code: ${err.code}`);
4600  }
4601}
4602```
4603
4604### on('quickThumbnail')
4605
4606on(type: 'quickThumbnail', callback: AsyncCallback\<image.PixelMap>): void
4607
4608Subscribes to quick thumbnail output events.
4609
4610The listening takes effect after **enableQuickThumbnail(true)** is called.
4611
4612**System API**: This is a system API.
4613
4614**System capability**: SystemCapability.Multimedia.Camera.Core
4615
4616**Parameters**
4617
4618| Name    | Type        | Mandatory| Description                                |
4619| -------- | ------------- | ---- | ----------------------------------- |
4620| type    | string     | Yes  | Event type. The value is fixed at **'quickThumbnail'**.|
4621| callback | AsyncCallback\<[image.PixelMap](js-apis-image.md#pixelmap7)> | Yes| Promise that returns a **PixelMap** instance.|
4622
4623**Example**
4624
4625```ts
4626import featureAbility from '@ohos.ability.featureAbility';
4627import { BusinessError } from '@ohos.base';
4628
4629async function registerQuickThumbnail(context: featureAbility.Context, photoProfile: camera.Profile, surfaceId: string): Promise<void> {
4630  let cameraManager: camera.CameraManager = camera.getCameraManager(context);
4631  let cameras: Array<camera.CameraDevice> = cameraManager.getSupportedCameras();
4632  // Create a CaptureSession instance.
4633  let captureSession: camera.CaptureSession = cameraManager.createCaptureSession();
4634  // Start configuration for the session.
4635  captureSession.beginConfig();
4636  // Add a CameraInput instance to the session.
4637  let cameraInput: camera.CameraInput = cameraManager.createCameraInput(cameras[0]);
4638  await cameraInput.open();
4639  captureSession.addInput(cameraInput);
4640  // Add a PhotoOutput instance to the session.
4641  let photoOutput: camera.PhotoOutput = cameraManager.createPhotoOutput(photoProfile, surfaceId);
4642  captureSession.addOutput(photoOutput);
4643  let isSupported: boolean = photoOutput.isQuickThumbnailSupported();
4644  if (!isSupported) {
4645    console.log('Quick Thumbnail is not supported to be turned on.');
4646    return;
4647  }
4648  try {
4649    photoOutput.enableQuickThumbnail(true);
4650  } catch (error) {
4651    let err = error as BusinessError;
4652    console.error(`The enableQuickThumbnail call failed. error code: ${err.code}`);
4653  }
4654
4655  photoOutput.on('quickThumbnail', (err: BusinessError, pixelMap: image.PixelMap) => {
4656    if (err || pixelMap === undefined) {
4657      console.error('photoOutput on thumbnail failed');
4658      return;
4659    }
4660    // Display or save the PixelMap instance.
4661    // do something
4662  })
4663}
4664```
4665
4666### off('quickThumbnail')
4667
4668off(type: 'quickThumbnail', callback?: AsyncCallback\<image.PixelMap>): void
4669
4670Unsubscribes from quick thumbnail output events.
4671
4672**System API**: This is a system API.
4673
4674**System capability**: SystemCapability.Multimedia.Camera.Core
4675
4676**Parameters**
4677
4678| Name    | Type        | Mandatory| Description                                |
4679| -------- | ------------- | ---- | ----------------------------------- |
4680| type    | string     | Yes  | Event type. The value is fixed at **'quickThumbnail'**.|
4681| callback | AsyncCallback\<[image.PixelMap](js-apis-image.md#pixelmap7)> | No| Callback used for unsubscription.|
4682
4683**Example**
4684
4685```ts
4686function unregisterQuickThumbnail(photoOutput: camera.PhotoOutput): void {
4687  photoOutput.off('quickThumbnail');
4688}
4689```
4690
4691## FrameShutterInfo
4692
4693Defines the frame shutter information.
4694
4695**System capability**: SystemCapability.Multimedia.Camera.Core
4696
4697| Name     | Type  | Mandatory| Description        |
4698| --------- | ------ | ---- | ---------- |
4699| captureId | number | Yes  | ID of this capture action. |
4700| timestamp | number | Yes  | Timestamp when the frame shutter event is triggered.|
4701
4702## CaptureEndInfo
4703
4704Defines the capture end information.
4705
4706**System capability**: SystemCapability.Multimedia.Camera.Core
4707
4708| Name      | Type  | Mandatory| Description      |
4709| ---------- | ------ | ---- | ---------|
4710| captureId  | number | Yes  | ID of this capture action.|
4711| frameCount | number | Yes  | Number of frames captured.   |
4712
4713## VideoOutput
4714
4715Implements output information used in a video recording session. This class inherits from [CameraOutput](#cameraoutput).
4716
4717### start
4718
4719start(callback: AsyncCallback\<void\>): void
4720
4721Starts video recording. This API uses an asynchronous callback to return the result.
4722
4723**System capability**: SystemCapability.Multimedia.Camera.Core
4724
4725**Parameters**
4726
4727| Name     | Type                 | Mandatory| Description                |
4728| -------- | -------------------- | ---- | -------------------- |
4729| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
4730
4731**Error codes**
4732
4733For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
4734
4735| ID        | Error Message       |
4736| --------------- | --------------- |
4737| 7400103                |  Session not config.                                   |
4738| 7400201                |  Camera service fatal error.                           |
4739
4740**Example**
4741
4742```ts
4743import { BusinessError } from '@ohos.base';
4744
4745function startVideoOutput(videoOutput: camera.VideoOutput): void {
4746  videoOutput.start((err: BusinessError) => {
4747    if (err) {
4748      console.error(`Failed to start the video output ${err.code}`);
4749      return;
4750    }
4751    console.log('Callback invoked to indicate the video output start success.');
4752  });
4753}
4754```
4755
4756### start
4757
4758start(): Promise\<void\>
4759
4760Starts video recording. This API uses a promise to return the result.
4761
4762**System capability**: SystemCapability.Multimedia.Camera.Core
4763
4764**Return value**
4765
4766| Type           | Description                    |
4767| -------------- | ----------------------- |
4768| Promise\<void\> | Promise used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
4769
4770**Error codes**
4771
4772For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
4773
4774| ID        | Error Message       |
4775| --------------- | --------------- |
4776| 7400103                |  Session not config.                                   |
4777| 7400201                |  Camera service fatal error.                           |
4778
4779**Example**
4780
4781```ts
4782import { BusinessError } from '@ohos.base';
4783
4784function startVideoOutput(videoOutput: camera.VideoOutput): void {
4785  videoOutput.start().then(() => {
4786    console.log('Promise returned to indicate that start method execution success.');
4787  }).catch((err: BusinessError) => {
4788    console.log('Failed to videoOutput start '+ err.code);
4789  });
4790}
4791```
4792
4793### stop
4794
4795stop(callback: AsyncCallback\<void\>): void
4796
4797Stops video recording. This API uses an asynchronous callback to return the result.
4798
4799**System capability**: SystemCapability.Multimedia.Camera.Core
4800
4801**Parameters**
4802
4803| Name    | Type                | Mandatory| Description                    |
4804| -------- | -------------------- | ---- | ------------------------ |
4805| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result.|
4806
4807**Example**
4808
4809```ts
4810import { BusinessError } from '@ohos.base';
4811
4812function stopVideoOutput(videoOutput: camera.VideoOutput): void {
4813  videoOutput.stop((err: BusinessError) => {
4814    if (err) {
4815      console.error(`Failed to stop the video output ${err.code}`);
4816      return;
4817    }
4818    console.log('Callback invoked to indicate the video output stop success.');
4819  });
4820}
4821```
4822
4823### stop
4824
4825stop(): Promise\<void\>
4826
4827Stops video recording. This API uses a promise to return the result.
4828
4829**System capability**: SystemCapability.Multimedia.Camera.Core
4830
4831**Return value**
4832
4833| Type           | Description                    |
4834| -------------- | ----------------------- |
4835| Promise\<void\> | Promise used to return the result.|
4836
4837**Example**
4838
4839```ts
4840import { BusinessError } from '@ohos.base';
4841
4842function stopVideoOutput(videoOutput: camera.VideoOutput): void {
4843  videoOutput.stop().then(() => {
4844    console.log('Promise returned to indicate that stop method execution success.');
4845  }).catch((err: BusinessError) => {
4846    console.log('Failed to videoOutput stop '+ err.code);
4847  });
4848}
4849```
4850
4851### release
4852
4853release(callback: AsyncCallback\<void\>): void
4854
4855Releases output resources. This API uses an asynchronous callback to return the result.
4856
4857**System capability**: SystemCapability.Multimedia.Camera.Core
4858
4859**Parameters**
4860
4861| Name     | Type                 | Mandatory| Description                |
4862| -------- | -------------------- | ---- | ------------------- |
4863| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
4864
4865**Error codes**
4866
4867For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
4868
4869| ID        | Error Message       |
4870| --------------- | --------------- |
4871| 7400201                |  Camera service fatal error.                           |
4872
4873**Example**
4874
4875```ts
4876import { BusinessError } from '@ohos.base';
4877
4878function releaseVideoOutput(videoOutput: camera.VideoOutput): void {
4879  videoOutput.release((err: BusinessError) => {
4880    if (err) {
4881      console.error(`Failed to release the PreviewOutput instance ${err.code}`);
4882      return;
4883    }
4884    console.log('Callback invoked to indicate that the videoOutput instance is released successfully.');
4885  });
4886}
4887```
4888
4889### release
4890
4891release(): Promise\<void\>
4892
4893Releases output resources. This API uses a promise to return the result.
4894
4895**System capability**: SystemCapability.Multimedia.Camera.Core
4896
4897**Return value**
4898
4899| Type           | Description                    |
4900| -------------- | ----------------------- |
4901| Promise\<void\> | Promise used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
4902
4903**Error codes**
4904
4905For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
4906
4907| ID        | Error Message       |
4908| --------------- | --------------- |
4909| 7400201                |  Camera service fatal error.                           |
4910
4911**Example**
4912
4913```ts
4914import { BusinessError } from '@ohos.base';
4915
4916function releaseVideoOutput(videoOutput: camera.VideoOutput): void {
4917  videoOutput.release().then(() => {
4918    console.log('Promise returned to indicate that the videoOutput instance is released successfully.');
4919  }).catch((err: BusinessError) => {
4920    console.log('Failed to videoOutput release '+ err.code);
4921  });
4922}
4923```
4924
4925### on('frameStart')
4926
4927on(type: 'frameStart', callback: AsyncCallback\<void\>): void
4928
4929Subscribes to video recording start events. This API uses an asynchronous callback to return the result.
4930
4931**System capability**: SystemCapability.Multimedia.Camera.Core
4932
4933**Parameters**
4934
4935| Name     | Type                 | Mandatory| Description                                      |
4936| -------- | -------------------- | ---- | ----------------------------------------- |
4937| type     | string               | Yes  | Event type. The value is fixed at **'frameStart'**. The event can be listened for when a **videoOutput** instance is created. The event is triggered and the corresponding information is returned when the bottom layer starts exposure for the first time.|
4938| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result.  The recording starts as long as this event is returned.                    |
4939
4940**Example**
4941
4942```ts
4943function registerVideoOutputFrameStart(videoOutput: camera.VideoOutput): void {
4944  videoOutput.on('frameStart', () => {
4945    console.log('Video frame started');
4946  });
4947}
4948```
4949
4950### off('frameStart')
4951
4952off(type: 'frameStart', callback?: AsyncCallback\<void\>): void
4953
4954Unsubscribes from video recording start events.
4955
4956**System capability**: SystemCapability.Multimedia.Camera.Core
4957
4958**Parameters**
4959
4960| Name     | Type                 | Mandatory| Description                                      |
4961| -------- | -------------------- | ---- | ----------------------------------------- |
4962| type     | string               | Yes  | Event type. The value is fixed at **'frameStart'**. The event can be listened for when a **videoOutput** instance is created.|
4963| callback | AsyncCallback\<void\> | No  | Callback used for unsubscription.                    |
4964
4965**Example**
4966
4967```ts
4968function unregisterVideoOutputFrameStart(videoOutput: camera.VideoOutput): void {
4969  videoOutput.off('frameStart');
4970}
4971
4972```
4973
4974### on('frameEnd')
4975
4976on(type: 'frameEnd', callback: AsyncCallback\<void\>): void
4977
4978Subscribes to video recording stop events. This API uses an asynchronous callback to return the result.
4979
4980**System capability**: SystemCapability.Multimedia.Camera.Core
4981
4982**Parameters**
4983
4984| Name     | Type                 | Mandatory| Description                                      |
4985| -------- | -------------------- | ---- | ------------------------------------------ |
4986| type     | string               | Yes  | Event type. The value is fixed at **'frameEnd'**. The event can be listened for when a **videoOutput** instance is created. This event is triggered and returned when the last frame of recording is complete.|
4987| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result. The recording ends as long as this event is returned.                     |
4988
4989**Example**
4990
4991```ts
4992function registerVideoOutputFrameEnd(videoOutput: camera.VideoOutput): void {
4993  videoOutput.on('frameEnd', () => {
4994    console.log('Video frame ended');
4995  });
4996}
4997```
4998
4999### off('frameEnd')
5000
5001off(type: 'frameEnd', callback?: AsyncCallback\<void\>): void
5002
5003Unsubscribes from video recording stop events.
5004
5005**System capability**: SystemCapability.Multimedia.Camera.Core
5006
5007**Parameters**
5008
5009| Name     | Type                 | Mandatory| Description                                      |
5010| -------- | -------------------- | ---- | ------------------------------------------ |
5011| type     | string               | Yes  | Event type. The value is fixed at **'frameEnd'**. The event can be listened for when a **videoOutput** instance is created.|
5012| callback | AsyncCallback\<void\> | No  | Callback used for unsubscription.                     |
5013
5014**Example**
5015
5016```ts
5017function unregisterVideoOutputFrameEnd(videoOutput: camera.VideoOutput): void {
5018  videoOutput.off('frameEnd');
5019}
5020```
5021
5022### on('error')
5023
5024on(type: 'error', callback: ErrorCallback): void
5025
5026Subscribes to **VideoOutput** error events. This API uses a callback to return the result.
5027
5028**System capability**: SystemCapability.Multimedia.Camera.Core
5029
5030**Parameters**
5031
5032| Name    | Type      | Mandatory| Description                                   |
5033| -------- | ----------- | ---- | -------------------------------------- |
5034| type     | string      | Yes  | Event type. The value is fixed at **'error'**. The event can be listened for when a **videoOutput** instance is created. This event is triggered and the corresponding error message is returned when an error occurs during the calling of a recording-related API such as **start()** and **release()**.|
5035| callback | ErrorCallback | Yes  | Callback used to return an error code defined in [CameraErrorCode](#cameraerrorcode).                |
5036
5037**Example**
5038
5039```ts
5040import { BusinessError } from '@ohos.base';
5041
5042function registerVideoOutputError(videoOutput: camera.VideoOutput): void {
5043  videoOutput.on('error', (error: BusinessError) => {
5044    console.log(`Video output error code: ${error.code}`);
5045  });
5046}
5047```
5048
5049### off('error')
5050
5051off(type: 'error', callback?: ErrorCallback): void
5052
5053Unsubscribes from **VideoOutput** error events.
5054
5055**System capability**: SystemCapability.Multimedia.Camera.Core
5056
5057**Parameters**
5058
5059| Name    | Type      | Mandatory| Description                                   |
5060| -------- | ----------- | ---- | -------------------------------------- |
5061| type     | string      | Yes  | Event type. The value is fixed at **'error'**. The event can be listened for when a **videoOutput** instance is created.|
5062| callback | ErrorCallback | No  | Callback used for unsubscription.              |
5063
5064**Example**
5065
5066```ts
5067function unregisterVideoOutputError(videoOutput: camera.VideoOutput): void {
5068  videoOutput.off('error');
5069}
5070```
5071
5072## MetadataOutput
5073
5074Implements metadata streams. It inherits **[CameraOutput](#cameraoutput)**.
5075
5076### start
5077
5078start(callback: AsyncCallback\<void\>): void
5079
5080Starts to output metadata. This API uses an asynchronous callback to return the result.
5081
5082**System capability**: SystemCapability.Multimedia.Camera.Core
5083
5084**Parameters**
5085
5086| Name    | Type                                                        | Mandatory| Description                |
5087| -------- | -------------------------- | ---- | ------------------- |
5088| callback | AsyncCallback\<void\>       | Yes  | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
5089
5090**Error codes**
5091
5092For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
5093
5094| ID        | Error Message       |
5095| --------------- | --------------- |
5096| 7400103                |  Session not config.                                   |
5097| 7400201                |  Camera service fatal error.                           |
5098
5099**Example**
5100
5101```ts
5102import { BusinessError } from '@ohos.base';
5103
5104function startMetadataOutput(metadataOutput: camera.MetadataOutput): void {
5105  metadataOutput.start((err: BusinessError) => {
5106    if (err) {
5107      console.error(`Failed to start metadataOutput. ${err.code}`);
5108      return;
5109    }
5110    console.log('Callback returned with metadataOutput started.');
5111  });
5112}
5113```
5114
5115### start
5116
5117start(): Promise\<void\>
5118
5119Starts to output metadata. This API uses a promise to return the result.
5120
5121**System capability**: SystemCapability.Multimedia.Camera.Core
5122
5123**Return value**
5124
5125| Type                    | Description                    |
5126| ----------------------  | ------------------------ |
5127| Promise\<void\>          | Promise used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
5128
5129**Error codes**
5130
5131For details about the error codes, see [Camera Error Codes](../errorcodes/errorcode-camera.md).
5132
5133| ID        | Error Message       |
5134| --------------- | --------------- |
5135| 7400103                |  Session not config.                                   |
5136| 7400201                |  Camera service fatal error.                           |
5137
5138**Example**
5139
5140```ts
5141import { BusinessError } from '@ohos.base';
5142
5143function startMetadataOutput(metadataOutput: camera.MetadataOutput): void {
5144  metadataOutput.start().then(() => {
5145    console.log('Callback returned with metadataOutput started.');
5146  }).catch((err: BusinessError) => {
5147    console.log('Failed to metadataOutput start '+ err.code);
5148  });
5149}
5150```
5151
5152### stop
5153
5154stop(callback: AsyncCallback\<void\>): void
5155
5156Stops outputting metadata. This API uses an asynchronous callback to return the result.
5157
5158**System capability**: SystemCapability.Multimedia.Camera.Core
5159
5160**Parameters**
5161
5162| Name    | Type                        | Mandatory| Description                 |
5163| -------- | -------------------------- | ---- | ------------------- |
5164| callback | AsyncCallback\<void\>       | Yes  | Callback used to return the result.|
5165
5166**Example**
5167
5168```ts
5169import { BusinessError } from '@ohos.base';
5170
5171function stopMetadataOutput(metadataOutput: camera.MetadataOutput): void {
5172  metadataOutput.stop((err: BusinessError) => {
5173    if (err) {
5174      console.error(`Failed to stop the metadataOutput. ${err.code}`);
5175      return;
5176    }
5177    console.log('Callback returned with metadataOutput stopped.');
5178  })
5179}
5180```
5181
5182### stop
5183
5184stop(): Promise\<void\>
5185
5186Stops outputting metadata. This API uses a promise to return the result.
5187
5188**System capability**: SystemCapability.Multimedia.Camera.Core
5189
5190**Return value**
5191
5192| Type                   | Description                       |
5193| ----------------------  | --------------------------- |
5194| Promise\<void\>         | Promise used to return the result.|
5195
5196**Example**
5197
5198```ts
5199import { BusinessError } from '@ohos.base';
5200
5201function stopMetadataOutput(metadataOutput: camera.MetadataOutput): void {
5202  metadataOutput.stop().then(() => {
5203    console.log('Callback returned with metadataOutput stopped.');
5204  }).catch((err: BusinessError) => {
5205    console.log('Failed to metadataOutput stop '+ err.code);
5206  });
5207}
5208```
5209
5210### on('metadataObjectsAvailable')
5211
5212on(type: 'metadataObjectsAvailable', callback: AsyncCallback\<Array\<MetadataObject\>\>): void
5213
5214Subscribes to events indicating available metadata objects. This API uses an asynchronous callback to return the result.
5215
5216**System capability**: SystemCapability.Multimedia.Camera.Core
5217
5218**Parameters**
5219
5220| Name     | Type        | Mandatory| Description                                 |
5221| -------- | -------------- | ---- | ------------------------------------ |
5222| type     | string         | Yes  | Event type. The value is fixed at **'metadataObjectsAvailable'**. The event can be listened for when a **metadataOutput** instance is created. This event is triggered and the corresponding metadata is returned when valid metadata is detected.|
5223| callback | Callback\<Array\<[MetadataObject](#metadataobject)\>\> | Yes  | Callback used to return the metadata.|
5224
5225**Example**
5226
5227```ts
5228import { BusinessError } from '@ohos.base';
5229
5230function registerMetadataObjectsAvailable(metadataOutput: camera.MetadataOutput): void {
5231  metadataOutput.on('metadataObjectsAvailable', (err: BusinessError, metadataObjectArr: Array<camera.MetadataObject>) => {
5232    console.log(`metadata output metadataObjectsAvailable`);
5233  });
5234}
5235```
5236
5237### off('metadataObjectsAvailable')
5238
5239off(type: 'metadataObjectsAvailable', callback?: AsyncCallback\<Array\<MetadataObject\>\>): void
5240
5241Unsubscribes from events indicating available metadata objects.
5242
5243**System capability**: SystemCapability.Multimedia.Camera.Core
5244
5245**Parameters**
5246
5247| Name     | Type        | Mandatory| Description                                 |
5248| -------- | -------------- | ---- | ------------------------------------ |
5249| type     | string         | Yes  | Event type. The value is fixed at **'metadataObjectsAvailable'**. The event can be listened for when a **metadataOutput** instance is created.|
5250| callback | Callback\<Array\<[MetadataObject](#metadataobject)\>\> | No  | Callback used for unsubscription.|
5251
5252**Example**
5253
5254```ts
5255function unregisterMetadataObjectsAvailable(metadataOutput: camera.MetadataOutput): void {
5256  metadataOutput.off('metadataObjectsAvailable');
5257}
5258```
5259
5260### on('error')
5261
5262on(type: 'error', callback: ErrorCallback): void
5263
5264Subscribes to metadata error events. This API uses an asynchronous callback to return the result.
5265
5266**System capability**: SystemCapability.Multimedia.Camera.Core
5267
5268**Parameters**
5269
5270| Name    | Type        | Mandatory| Description                                    |
5271| -------- | ------------- | ---- | --------------------------------------- |
5272| type     | string        | Yes  | Event type. The value is fixed at **'error'**. The event can be listened for when a **metadataOutput** instance is created. This event is triggered and the corresponding error message is returned when an error occurs during the calling of a metadata-related API such as **start()** and **release()**.|
5273| callback | ErrorCallback | Yes  | Callback used to return an error code defined in [CameraErrorCode](#cameraerrorcode).           |
5274
5275**Example**
5276
5277```ts
5278import { BusinessError } from '@ohos.base';
5279
5280function registerMetadataOutputError(metadataOutput: camera.MetadataOutput): void {
5281  metadataOutput.on('error', (metadataOutputError: BusinessError) => {
5282    console.log(`Metadata output error code: ${metadataOutputError.code}`);
5283  });
5284}
5285```
5286
5287### off('error')
5288
5289off(type: 'error', callback?: ErrorCallback): void
5290
5291Unsubscribes from metadata error events.
5292
5293**System capability**: SystemCapability.Multimedia.Camera.Core
5294
5295**Parameters**
5296
5297| Name    | Type        | Mandatory| Description                                    |
5298| -------- | ------------- | ---- | --------------------------------------- |
5299| type     | string        | Yes  | Event type. The value is fixed at **'error'**. The event can be listened for when a **metadataOutput** instance is created.|
5300| callback | ErrorCallback | No  | Callback used for unsubscription.          |
5301
5302**Example**
5303
5304```ts
5305function unregisterMetadataOutputError(metadataOutput: camera.MetadataOutput): void {
5306  metadataOutput.off('error');
5307}
5308```
5309
5310## MetadataObjectType
5311
5312Enumerates the metadata object types.
5313
5314**System capability**: SystemCapability.Multimedia.Camera.Core
5315
5316| Name                      | Value  | Description             |
5317| ------------------------- | ---- | ----------------- |
5318| FACE_DETECTION            | 0    | Face detection. The detection point must be in the coordinate system (0-1), where the upper left corner is {0, 0} and the lower right corner is {1, 1}.<br> The coordinate system is based on the horizontal device direction with the device's charging port on the right.<br> If the layout of a preview screen of an application is based on the vertical direction with the charging port on the lower side,<br> the layout width and height are {w, h} and the return point is {x, y}, then the coordinate point after conversion is {1-y, x}.|
5319
5320## Rect
5321
5322Defines a rectangle.
5323
5324**System capability**: SystemCapability.Multimedia.Camera.Core
5325
5326| Name     | Type  |      Mandatory    |           Description                |
5327| -------- | ------ | --------------- | -------------------- |
5328| topLeftX | number |        Yes         | X-axis coordinate of the upper left corner of the rectangle.  |
5329| topLeftY | number |         Yes         | Y-axis coordinate of the upper left corner of the rectangle.  |
5330| width    | number |         Yes        | Width of the rectangle.             |
5331| height   | number |         Yes          |Height of the rectangle.             |
5332
5333## MetadataObject
5334
5335Implements camera metadata, which is the data source of [CameraInput](#camerainput). The metadata is obtained through metadataOutput.on('metadataObjectsAvailable').
5336
5337**System capability**: SystemCapability.Multimedia.Camera.Core
5338
5339| Name     | Type                           | Mandatory | Description             |
5340| -------- | ------------------------------- | ---- | -----------------|
5341| type  | [MetadataObjectType](#metadataobjecttype)   | No  | Metadata data type. Only face recognition is supported.|
5342| timestamp | number | No  | Current timestamp, in milliseconds.|
5343| boundingBox | [Rect](#rect)           | No  | Metadata rectangle.|
5344