• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Interface (AutoExposure)
2<!--Kit: Camera Kit-->
3<!--Subsystem: Multimedia-->
4<!--Owner: @qano-->
5<!--SE: @leo_ysl-->
6<!--TSE: @xchaosioda-->
7
8> **NOTE**
9>
10> - 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.
11> - The initial APIs of this interface are supported since API version 11.
12
13AutoExposure inherits from [AutoExposureQuery](arkts-apis-camera-AutoExposureQuery.md).
14
15It provides APIs related to auto exposure.
16
17## Modules to Import
18
19```ts
20import { camera } from '@kit.CameraKit';
21```
22
23## getExposureMode<sup>11+</sup>
24
25getExposureMode(): ExposureMode
26
27Obtains the exposure mode in use.
28
29**Atomic service API**: This API can be used in atomic services since API version 19.
30
31**System capability**: SystemCapability.Multimedia.Camera.Core
32
33**Return value**
34
35| Type       | Description                         |
36| ---------- | ----------------------------- |
37| [ExposureMode](arkts-apis-camera-e.md#exposuremode)    | Exposure mode obtained. If the operation fails, an error code defined in [CameraErrorCode](arkts-apis-camera-e.md#cameraerrorcode) is returned.|
38
39**Error codes**
40
41For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
42
43| ID        | Error Message       |
44| --------------- | --------------- |
45| 7400103                |  Session not config.                                   |
46
47**Example**
48
49```ts
50import { BusinessError } from '@kit.BasicServicesKit';
51
52function getExposureMode(photoSession: camera.PhotoSession): camera.ExposureMode | undefined {
53  let exposureMode: camera.ExposureMode | undefined = undefined;
54  try {
55    exposureMode = photoSession.getExposureMode();
56  } catch (error) {
57    // If the operation fails, error.code is returned and processed.
58    let err = error as BusinessError;
59    console.error(`The getExposureMode call failed. error code: ${err.code}`);
60  }
61  return exposureMode;
62}
63```
64
65## setExposureMode<sup>11+</sup>
66
67setExposureMode(aeMode: ExposureMode): void
68
69Sets an exposure mode. Before the setting, call [isExposureModeSupported](arkts-apis-camera-AutoExposureQuery.md#isexposuremodesupported11) to check whether the exposure mode is supported.
70
71**Atomic service API**: This API can be used in atomic services since API version 19.
72
73**System capability**: SystemCapability.Multimedia.Camera.Core
74
75**Parameters**
76
77| Name     | Type                           | Mandatory| Description                   |
78| -------- | -------------------------------| ---- | ----------------------- |
79| aeMode   | [ExposureMode](arkts-apis-camera-e.md#exposuremode)  | Yes  | Exposure mode. If the input parameter is null or undefined, it is treated as 0 and exposure is locked.               |
80
81**Error codes**
82
83For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
84
85| ID        | Error Message       |
86| --------------- | --------------- |
87| 7400102                | Operation not allowed.                                 |
88| 7400103                |  Session not config.                                   |
89
90**Example**
91
92```ts
93import { BusinessError } from '@kit.BasicServicesKit';
94
95function setExposureMode(photoSession: camera.PhotoSession): void {
96  try {
97    photoSession.setExposureMode(camera.ExposureMode.EXPOSURE_MODE_LOCKED);
98  } catch (error) {
99    // If the operation fails, error.code is returned and processed.
100    let err = error as BusinessError;
101    console.error(`The setExposureMode call failed. error code: ${err.code}`);
102  }
103}
104```
105
106## getMeteringPoint<sup>11+</sup>
107
108getMeteringPoint(): Point
109
110Obtains the metering point of the camera device.
111
112**Atomic service API**: This API can be used in atomic services since API version 19.
113
114**System capability**: SystemCapability.Multimedia.Camera.Core
115
116**Return value**
117
118| Type       | Description                         |
119| ---------- | ----------------------------- |
120| [Point](arkts-apis-camera-i.md#point)    | Metering point obtained. If the operation fails, an error code defined in [CameraErrorCode](arkts-apis-camera-e.md#cameraerrorcode) is returned.|
121
122**Error codes**
123
124For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
125
126| ID  | Error Message       |
127|---------| --------------- |
128| 7400103 |  Session not config.                                   |
129
130**Example**
131
132```ts
133import { BusinessError } from '@kit.BasicServicesKit';
134
135function getMeteringPoint(photoSession: camera.PhotoSession): camera.Point | undefined {
136  let exposurePoint: camera.Point | undefined = undefined;
137  try {
138    exposurePoint = photoSession.getMeteringPoint();
139  } catch (error) {
140    // If the operation fails, error.code is returned and processed.
141    let err = error as BusinessError;
142    console.error(`The getMeteringPoint call failed. error code: ${err.code}`);
143  }
144  return exposurePoint;
145}
146```
147
148## setMeteringPoint<sup>11+</sup>
149
150setMeteringPoint(point: Point): void
151
152Sets the metering point, which is the center point of the metering rectangle.
153
154The 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}.
155
156The 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}.
157
158**Atomic service API**: This API can be used in atomic services since API version 19.
159
160**System capability**: SystemCapability.Multimedia.Camera.Core
161
162**Parameters**
163
164| Name          | Type                           | Mandatory| Description                |
165| ------------- | -------------------------------| ---- | ------------------- |
166| point | [Point](arkts-apis-camera-i.md#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.            |
167
168**Error codes**
169
170For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
171
172| ID        | Error Message       |
173| --------------- | --------------- |
174| 7400103                |  Session not config.                                   |
175
176**Example**
177
178```ts
179import { BusinessError } from '@kit.BasicServicesKit';
180
181function setMeteringPoint(photoSession: camera.PhotoSession): void {
182  const point: camera.Point = {x: 1, y: 1};
183  try {
184    photoSession.setMeteringPoint(point);
185  } catch (error) {
186    // If the operation fails, error.code is returned and processed.
187    let err = error as BusinessError;
188    console.error(`The setMeteringPoint call failed. error code: ${err.code}`);
189  }
190}
191```
192
193## setExposureBias<sup>11+</sup>
194
195setExposureBias(exposureBias: number): void
196
197Sets an exposure compensation value (EV).
198
199Before the setting, you are advised to use [getExposureBiasRange](arkts-apis-camera-AutoExposureQuery.md#getexposurebiasrange11) to obtain the supported values.
200
201**Atomic service API**: This API can be used in atomic services since API version 19.
202
203**System capability**: SystemCapability.Multimedia.Camera.Core
204
205**Parameters**
206
207| Name    | Type                           | Mandatory| Description                                                                                                                                                                                           |
208| -------- | -------------------------------| ---- |-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
209| exposureBias   | number                   | Yes  | EV. The supported EV range can be obtained by calling [getExposureBiasRange](arkts-apis-camera-AutoExposureQuery.md#getexposurebiasrange11). If the value passed is not within the supported range, the nearest critical point is used.<br>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.<br>If the operation fails, an error code defined in [CameraErrorCode](arkts-apis-camera-e.md#cameraerrorcode) is returned.|
210
211**Error codes**
212
213For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
214
215| ID        | Error Message       |
216| --------------- | --------------- |
217| 7400102                |  Operation not allowed.                                |
218| 7400103                |  Session not config.                                   |
219
220**Example**
221
222```ts
223import { BusinessError } from '@kit.BasicServicesKit';
224
225function setExposureBias(photoSession: camera.PhotoSession, biasRangeArray: Array<number>): void {
226  if (biasRangeArray && biasRangeArray.length > 0) {
227    let exposureBias = biasRangeArray[0];
228    try {
229      photoSession.setExposureBias(exposureBias);
230    } catch (error) {
231      // If the operation fails, error.code is returned and processed.
232      let err = error as BusinessError;
233      console.error(`The setExposureBias call failed. error code: ${err.code}`);
234    }
235  }
236}
237```
238
239## getExposureValue<sup>11+</sup>
240
241getExposureValue(): number
242
243Obtains the exposure value in use.
244
245**Atomic service API**: This API can be used in atomic services since API version 19.
246
247**System capability**: SystemCapability.Multimedia.Camera.Core
248
249**Return value**
250
251| Type       | Description                         |
252| ---------- | ----------------------------- |
253| 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.<br>If the operation fails, an error code defined in [CameraErrorCode](arkts-apis-camera-e.md#cameraerrorcode) is returned.|
254
255**Error codes**
256
257For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
258
259| ID        | Error Message       |
260| --------------- | --------------- |
261| 7400103                |  Session not config.                                   |
262
263**Example**
264
265```ts
266import { BusinessError } from '@kit.BasicServicesKit';
267
268function getExposureValue(photoSession: camera.PhotoSession): number {
269  const invalidValue: number = -1;
270  let exposureValue: number = invalidValue;
271  try {
272    exposureValue = photoSession.getExposureValue();
273  } catch (error) {
274    // If the operation fails, error.code is returned and processed.
275    let err = error as BusinessError;
276    console.error(`The getExposureValue call failed. error code: ${err.code}`);
277  }
278  return exposureValue;
279}
280```
281