harmony 鸿蒙Interface (AutoExposure)

  • 2025-06-12
  • 浏览 (6)

Interface (AutoExposure)

说明:

本模块首批接口从API version 11开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。

AutoExposure extends AutoExposureQuery

自动曝光类,对设备自动曝光(AE)操作。

getExposureMode11+

getExposureMode(): ExposureMode

获取当前曝光模式。

原子化服务API: 从API version 19开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.Camera.Core

返回值:

类型 说明
ExposureMode 获取当前曝光模式。接口调用失败会返回相应错误码,错误码类型CameraErrorCode

错误码:

以下错误码的详细介绍请参见Camera错误码

错误码ID 错误信息
7400103 Session not config.

示例:

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

function getExposureMode(photoSession: camera.PhotoSession): camera.ExposureMode|undefined {
  let exposureMode: camera.ExposureMode|undefined = undefined;
  try {
    exposureMode = photoSession.getExposureMode();
  } catch (error) {
    // 失败返回错误码error.code并处理。
    let err = error as BusinessError;
    console.error(`The getExposureMode call failed. error code: ${err.code}`);
  }
  return exposureMode;
}

setExposureMode11+

setExposureMode(aeMode: ExposureMode): void

设置曝光模式。进行设置之前,需要先检查设备是否支持指定的曝光模式,可使用方法isExposureModeSupported

原子化服务API: 从API version 19开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.Camera.Core

参数:

参数名 类型 必填 说明
aeMode ExposureMode 曝光模式。传参为null或者undefined,作为0处理,曝光锁定。

错误码:

以下错误码的详细介绍请参见Camera错误码

错误码ID 错误信息
7400102 Operation not allowed.
7400103 Session not config.

示例:

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

function setExposureMode(photoSession: camera.PhotoSession): void {
  try {
    photoSession.setExposureMode(camera.ExposureMode.EXPOSURE_MODE_LOCKED);
  } catch (error) {
    // 失败返回错误码error.code并处理。
    let err = error as BusinessError;
    console.error(`The setExposureMode call failed. error code: ${err.code}`);
  }
}

getMeteringPoint11+

getMeteringPoint(): Point

查询曝光区域中心点。

原子化服务API: 从API version 19开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.Camera.Core

返回值:

类型 说明
Point 获取当前曝光点。接口调用失败会返回相应错误码,错误码类型CameraErrorCode

错误码:

以下错误码的详细介绍请参见Camera错误码

错误码ID 错误信息
7400103 Session not config.

示例:

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

function getMeteringPoint(photoSession: camera.PhotoSession): camera.Point|undefined {
  let exposurePoint: camera.Point|undefined = undefined;
  try {
    exposurePoint = photoSession.getMeteringPoint();
  } catch (error) {
    // 失败返回错误码error.code并处理。
    let err = error as BusinessError;
    console.error(`The getMeteringPoint call failed. error code: ${err.code}`);
  }
  return exposurePoint;
}

setMeteringPoint11+

setMeteringPoint(point: Point): void

设置曝光区域中心点,曝光点应在0-1坐标系内,该坐标系左上角为{0,0},右下角为{1,1}。

此坐标系是以设备充电口在右侧时的横向设备方向为基准的,例如应用的预览界面布局以设备充电口在下侧时的竖向方向为基准,布局宽高为{w,h},且触碰点为{x,y},则转换后的坐标点为{y/h,1-x/w}。

原子化服务API: 从API version 19开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.Camera.Core

参数:

参数名 类型 必填 说明
point Point 曝光点,x、y设置范围应在[0,1]之内,超过范围,如果小于0设置0,大于1设置1。

错误码:

以下错误码的详细介绍请参见Camera错误码

错误码ID 错误信息
7400103 Session not config.

示例:

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

function setMeteringPoint(photoSession: camera.PhotoSession): void {
  const point: camera.Point = {x: 1, y: 1};
  try {
    photoSession.setMeteringPoint(point);
  } catch (error) {
    // 失败返回错误码error.code并处理。
    let err = error as BusinessError;
    console.error(`The setMeteringPoint call failed. error code: ${err.code}`);
  }
}

setExposureBias11+

setExposureBias(exposureBias: number): void

设置曝光补偿,曝光补偿值(EV)。

进行设置之前,建议先通过方法getExposureBiasRange查询支持的范围。

原子化服务API: 从API version 19开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.Camera.Core

参数:

参数名 类型 必填 说明
exposureBias number 曝光补偿,getExposureBiasRange查询支持的范围,如果设置超过支持范围的值,自动匹配到就近临界点。
曝光补偿存在步长,如步长为0.5。则设置1.2时,获取到实际生效曝光补偿为1.0。
接口调用失败会返回相应错误码,错误码类型CameraErrorCode

错误码:

以下错误码的详细介绍请参见Camera错误码

错误码ID 错误信息
7400102 Operation not allowed.
7400103 Session not config.

示例:

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

function setExposureBias(photoSession: camera.PhotoSession, biasRangeArray: Array<number>): void {
  if (biasRangeArray && biasRangeArray.length > 0) {
    let exposureBias = biasRangeArray[0];
    try {
      photoSession.setExposureBias(exposureBias);
    } catch (error) {
      // 失败返回错误码error.code并处理。
      let err = error as BusinessError;
      console.error(`The setExposureBias call failed. error code: ${err.code}`);
    }
  }
}

getExposureValue11+

getExposureValue(): number

查询当前曝光值。

原子化服务API: 从API version 19开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.Camera.Core

返回值:

类型 说明
number 获取曝光值。曝光补偿存在步长,如步长为0.5。则设置1.2时,获取到实际生效曝光补偿为1.0。
接口调用失败会返回相应错误码,错误码类型CameraErrorCode

错误码:

以下错误码的详细介绍请参见Camera错误码

错误码ID 错误信息
7400103 Session not config.

示例:

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

function getExposureValue(photoSession: camera.PhotoSession): number {
  const invalidValue: number = -1;
  let exposureValue: number = invalidValue;
  try {
    exposureValue = photoSession.getExposureValue();
  } catch (error) {
    // 失败返回错误码error.code并处理。
    let err = error as BusinessError;
    console.error(`The getExposureValue call failed. error code: ${err.code}`);
  }
  return exposureValue;
}

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Camera Kit(相机服务)

harmony 鸿蒙Interface (AutoDeviceSwitch)

harmony 鸿蒙Interface (AutoDeviceSwitchQuery)

harmony 鸿蒙Interface (AutoExposureQuery)

harmony 鸿蒙Interface (CameraInput)

harmony 鸿蒙Interface (CameraManager)

harmony 鸿蒙Interface (CameraOutput)

harmony 鸿蒙废弃的Interface (CaptureSession, deprecated)

harmony 鸿蒙Interface (ColorManagement)

harmony 鸿蒙Interface (ColorManagementQuery)

0  赞