openharmony 鸿蒙 camera-whitebalance

2026-08-25 浏览 (1)

White Balance Settings (ArkTS)

Starting from API version 20, you can configure white balance effects. White balance is a color correction technique used by cameras to produce different visual effects in photos. Currently, white balance effects are supported in the following sessions: photo session (for taking photos), video session (for recording videos), and secure session (for secure camera operations).

How to Develop

Read Camera for the API reference.

  1. Import the camera module, which provides camera-related properties and methods.

    import { camera } from '@kit.CameraKit';
    import { BusinessError } from '@kit.BasicServicesKit';
    
  2. Set white balance. Two methods are provided for setting white balance.

    • Method 1: Use isWhiteBalanceModeSupported to check whether a specific white balance mode is supported. Then, call setWhiteBalanceMode and getWhiteBalanceMode to set and obtain the white balance mode. Note that you can only view the currently set white balance mode. The available white balance modes include automatic, manual, cloudy, incandescent, fluorescent, and daylight. If both a white balance mode and a white balance value are set, only one takes effect, with the white balance mode taking precedence by default.

      function isWhiteBalanceModeSupported(session: camera.PhotoSession|camera.VideoSession): boolean {
         let status: boolean = false;
         let whiteBalanceMode: camera.WhiteBalanceMode|undefined = undefined;
         try {
            let mode: camera.WhiteBalanceMode = camera.WhiteBalanceMode.DAYLIGHT;
            status = session.isWhiteBalanceModeSupported(mode);
            if(status){
            session.setWhiteBalanceMode(mode);
            }
            whiteBalanceMode = session.getWhiteBalanceMode();
         } catch (error) {
         let err = error as BusinessError;
         console.error(`The isWhiteBalanceModeSupported call failed. error code: ${err.code}`);
         }
         return status;
      }
      
    • Method 2: Call getWhiteBalanceRange to obtain the range of white balance values supported by the device. Then, call setWhiteBalance and getWhiteBalance to set and obtain the white balance value. Note that you can only view the currently set white balance value.

      function getWhiteBalanceRange(session: camera.PhotoSession|camera.VideoSession): Array<number> {
         let range: Array<number> = [];
         try {
            range = session.getWhiteBalanceRange();
            let whiteBalance: number = 3000;
            if(whiteBalance > range[0] && whiteBalance < range[1]){
            session.setWhiteBalance(whiteBalance);
            }
            whiteBalance = session.getWhiteBalance();
         } catch (error) {
           let err = error as BusinessError;
           console.error(`The getWhiteBalanceRange call failed. error code: ${err.code}`);
         }
         return range;
      }
      

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 native-camera-preview

openharmony 鸿蒙 camera-worker

openharmony 鸿蒙 camera-background-recovery

openharmony 鸿蒙 camera-preparation

openharmony 鸿蒙 camera-shooting

openharmony 鸿蒙 camera-moving-photo

openharmony 鸿蒙 camera-system-pressure

openharmony 鸿蒙 native-camera-preview-imageReceiver

openharmony 鸿蒙 native-camera-shooting

openharmony 鸿蒙 camera-recording-case

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