• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Interface (WhiteBalance)
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 20.
12
13WhiteBalance inherits from [WhiteBalanceQuery](arkts-apis-camera-WhiteBalanceQuery.md).
14
15It provides APIs to process white balance, including obtaining and setting the white balance mode and white balance value.
16
17## Modules to Import
18
19```ts
20import { camera } from '@kit.CameraKit';
21```
22
23## setWhiteBalanceMode<sup>20+</sup>
24
25setWhiteBalanceMode(mode: WhiteBalanceMode): void
26
27Sets a white balance mode.
28
29Before the setting, run [isWhiteBalanceModeSupported](arkts-apis-camera-WhiteBalanceQuery.md#iswhitebalancemodesupported20) to check whether the device supports the specified white balance mode.
30
31**Atomic service API**: This API can be used in atomic services since API version 20.
32
33**System capability**: SystemCapability.Multimedia.Camera.Core
34
35**Parameters**
36
37| Name     | Type                                     | Mandatory| Description                   |
38| -------- |-----------------------------------------| ---- | ----------------------- |
39| mode   | [WhiteBalanceMode](arkts-apis-camera-e.md#whitebalancemode20) | Yes  | White balance mode.               |
40
41**Error codes**
42
43For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
44
45| ID        | Error Message       |
46| --------------- | --------------- |
47| 7400101                |  Parameter missing or parameter type incorrect.        |
48| 7400103                |  Session not config.                                   |
49
50**Example**
51
52```ts
53import { BusinessError } from '@kit.BasicServicesKit';
54
55function setWhiteBalanceMode(session: camera.PhotoSession | camera.VideoSession): void {
56  try {
57    session.setWhiteBalanceMode(camera.WhiteBalanceMode.DAYLIGHT);
58  } catch (error) {
59    let err = error as BusinessError;
60    console.error(`The setWhiteBalanceMode call failed. error code: ${err.code}`);
61  }
62}
63```
64
65## getWhiteBalanceMode<sup>20+</sup>
66
67getWhiteBalanceMode(): WhiteBalanceMode
68
69Obtains the white balance mode in use.
70
71**Atomic service API**: This API can be used in atomic services since API version 20.
72
73**System capability**: SystemCapability.Multimedia.Camera.Core
74
75**Return value**
76
77| Type                                     | Description                         |
78|-----------------------------------------| ----------------------------- |
79| [WhiteBalanceMode](arkts-apis-camera-e.md#whitebalancemode20) | White balance mode in use.|
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| 7400103                |  Session not config.                                   |
88
89**Example**
90
91```ts
92import { BusinessError } from '@kit.BasicServicesKit';
93
94function getWhiteBalanceMode(session: camera.PhotoSession | camera.VideoSession): camera.WhiteBalanceMode | undefined {
95  let whiteBalanceMode: camera.WhiteBalanceMode | undefined = undefined;
96  try {
97    whiteBalanceMode = session.getWhiteBalanceMode();
98  } catch (error) {
99    let err = error as BusinessError;
100    console.error(`The getWhiteBalanceMode call failed. error code: ${err.code}`);
101  }
102  return whiteBalanceMode;
103}
104```
105
106## setWhiteBalance<sup>20+</sup>
107
108setWhiteBalance(whiteBalance: number): void
109
110Sets a white balance value.
111
112Before the setting, run [isWhiteBalanceModeSupported](arkts-apis-camera-WhiteBalanceQuery.md#iswhitebalancemodesupported20) to check the white balance value range supported by the device.
113
114**Atomic service API**: This API can be used in atomic services since API version 20.
115
116**System capability**: SystemCapability.Multimedia.Camera.Core
117
118**Parameters**
119
120| Name     | Type                    | Mandatory| Description                |
121| -------- | ----------------------- | ---- | ------------------- |
122| whiteBalance | number | Yes  | White balance value.|
123
124**Error codes**
125
126For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
127
128| ID        | Error Message       |
129| --------------- | --------------- |
130| 7400101                |  Parameter missing or parameter type incorrect.        |
131| 7400103                |  Session not config.                                   |
132
133**Example**
134
135```ts
136import { BusinessError } from '@kit.BasicServicesKit';
137
138function setWhiteBalance(session: camera.PhotoSession | camera.VideoSession): void {
139  try {
140    let whiteBalance: number = 1000;
141    session.setWhiteBalance(whiteBalance);
142  } catch (error) {
143    let err = error as BusinessError;
144    console.error(`The setWhiteBalance call failed. error code: ${err.code}`);
145  }
146}
147```
148
149## getWhiteBalance<sup>20+</sup>
150
151getWhiteBalance(): number
152
153Obtains the current white balance value.
154
155**Atomic service API**: This API can be used in atomic services since API version 20.
156
157**System capability**: SystemCapability.Multimedia.Camera.Core
158
159**Return value**
160
161| Type       | Description                         |
162| ---------- | ----------------------------- |
163| number    | White balance value.|
164
165**Error codes**
166
167For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
168
169| ID        | Error Message       |
170| --------------- | --------------- |
171| 7400103                |  Session not config.                                   |
172
173**Example**
174
175```ts
176import { BusinessError } from '@kit.BasicServicesKit';
177
178function getWhiteBalance(session: camera.PhotoSession | camera.VideoSession): number {
179  let whiteBalance: number = 0;
180  try {
181    whiteBalance = session.getWhiteBalance();
182  } catch (error) {
183    let err = error as BusinessError;
184    console.error(`The getWhiteBalance call failed. error code: ${err.code}`);
185  }
186  return whiteBalance;
187}
188```
189