openharmony 鸿蒙 arkts-apis-camera-WhiteBalance

2026-08-25 浏览 (1)

Interface (WhiteBalance)

WhiteBalance inherits from WhiteBalanceQuery.

It provides APIs to process white balance, including obtaining and setting the white balance mode and white balance value.

NOTE

  • 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.
  • The initial APIs of this interface are supported since API version 20.

Modules to Import

import { camera } from '@kit.CameraKit';

setWhiteBalanceMode20+

setWhiteBalanceMode(mode: WhiteBalanceMode): void

Sets a white balance mode. Before the setting, run isWhiteBalanceModeSupported to check whether the device supports the specified white balance mode.

Atomic service API: This API can be used in atomic services since API version 20.

System capability: SystemCapability.Multimedia.Camera.Core

Parameters

NameTypeMandatoryDescription
modeWhiteBalanceModeYesWhite balance mode.

Error codes

For details about the error codes, see Camera Error Codes.

IDError Message
7400101Parameter missing or parameter type incorrect.
7400103Session not config.

Example

import { BusinessError } from '@kit.BasicServicesKit';

function setWhiteBalanceMode(session: camera.PhotoSession|camera.VideoSession): void {
  try {
    session.setWhiteBalanceMode(camera.WhiteBalanceMode.DAYLIGHT);
  } catch (error) {
    let err = error as BusinessError;
    console.error(`The setWhiteBalanceMode call failed. error code: ${err.code}`);
  }
}

getWhiteBalanceMode20+

getWhiteBalanceMode(): WhiteBalanceMode

Obtains the white balance mode in use.

Atomic service API: This API can be used in atomic services since API version 20.

System capability: SystemCapability.Multimedia.Camera.Core

Return value

TypeDescription
WhiteBalanceModeWhite balance mode in use. If the API call fails, undefined is returned.

Error codes

For details about the error codes, see Camera Error Codes.

IDError Message
7400103Session not config.

Example

import { BusinessError } from '@kit.BasicServicesKit';

function getWhiteBalanceMode(session: camera.PhotoSession|camera.VideoSession): camera.WhiteBalanceMode|undefined {
  let whiteBalanceMode: camera.WhiteBalanceMode|undefined = undefined;
  try {
    whiteBalanceMode = session.getWhiteBalanceMode();
  } catch (error) {
    let err = error as BusinessError;
    console.error(`The getWhiteBalanceMode call failed. error code: ${err.code}`);
  }
  return whiteBalanceMode;
}

setWhiteBalance20+

setWhiteBalance(whiteBalance: number): void

Sets a white balance value.

Before the setting, run getWhiteBalanceRange to check the white balance value range supported by the device.

Atomic service API: This API can be used in atomic services since API version 20.

System capability: SystemCapability.Multimedia.Camera.Core

Parameters

NameTypeMandatoryDescription
whiteBalancenumberYesWhite balance value.

Error codes

For details about the error codes, see Camera Error Codes.

IDError Message
7400101Parameter missing or parameter type incorrect.
7400103Session not config.

Example

import { BusinessError } from '@kit.BasicServicesKit';

function setWhiteBalance(session: camera.PhotoSession|camera.VideoSession): void {
  try {
    let whiteBalance: number = 1000;
    session.setWhiteBalance(whiteBalance);
  } catch (error) {
    let err = error as BusinessError;
    console.error(`The setWhiteBalance call failed. error code: ${err.code}`);
  }
}

getWhiteBalance20+

getWhiteBalance(): number

Obtains the current white balance value.

Atomic service API: This API can be used in atomic services since API version 20.

System capability: SystemCapability.Multimedia.Camera.Core

Return value

TypeDescription
numberWhite balance value.

Error codes

For details about the error codes, see Camera Error Codes.

IDError Message
7400103Session not config.

Example

import { BusinessError } from '@kit.BasicServicesKit';

function getWhiteBalance(session: camera.PhotoSession|camera.VideoSession): number {
  let whiteBalance: number = 0;
  try {
    whiteBalance = session.getWhiteBalance();
  } catch (error) {
    let err = error as BusinessError;
    console.error(`The getWhiteBalance call failed. error code: ${err.code}`);
  }
  return whiteBalance;
}

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 capi-oh-camera-capturesession-callbacks

openharmony 鸿蒙 arkts-apis-camera-OIS

openharmony 鸿蒙 capi-oh-camera-camera-devicequeryinfo

openharmony 鸿蒙 capi-oh-camera-camera-frameraterange

openharmony 鸿蒙 capi-oh-camera-camera-outputcapability

openharmony 鸿蒙 arkts-apis-camera-Photo

openharmony 鸿蒙 capi-oh-camera-camera-profile

openharmony 鸿蒙 capi-oh-camera-camera-manager

openharmony 鸿蒙 capi-oh-camera-previewoutput-callbacks

openharmony 鸿蒙 arkts-apis-camera-ManualExposureQuery

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/OqJqiQmJ