AutoExposure继承自AutoExposureQuery。
自动曝光类,对设备自动曝光(AE)操作。
getExposureMode(): ExposureMode
获取当前曝光模式。
元服务API: 从API version 19开始,该接口支持在元服务中使用。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
| 类型 | 说明 |
|---|---|
| ExposureMode | 获取当前曝光模式。接口调用失败会抛出相应错误码并返回undefined,错误码类型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;
} setExposureMode(aeMode: ExposureMode): void
设置曝光模式。进行设置之前,需要先检查设备是否支持指定的曝光模式,可使用方法isExposureModeSupported。
元服务API: 从API version 19开始,该接口支持在元服务中使用。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| aeMode | ExposureMode | 是 | 曝光模式。传参为null或者undefined,作为0处理,曝光锁定。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
| 错误码ID | 错误信息 |
|---|---|
| 7400102 | Operation not allowed. 适用版本:19+ |
| 7400103 | Session not config. |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
function setExposureMode(photoSession: camera.PhotoSession, mode: camera.ExposureMode): void {
try {
if (photoSession.isExposureModeSupported(mode)) {
photoSession.setExposureMode(mode);
}
} catch (error) {
// 失败返回错误码error.code并处理。
let err = error as BusinessError;
console.error(`The setExposureMode call failed. error code: ${err.code}`);
}
} 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;
} 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}`);
}
} 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. 适用版本:12+ |
| 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}`);
}
}
} 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;
} getExposureMeteringMode(): ExposureMeteringMode
获取当前曝光测光模式。
元服务API: 从API version 24开始,该接口支持在元服务中使用。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
| 类型 | 说明 |
|---|---|
| ExposureMeteringMode | 当前曝光测光模式。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
| 错误码ID | 错误信息 |
|---|---|
| 7400102 | Operation not allowed, the inputDevice or the session is abnormal. |
| 7400103 | Session not config, only throw in session usage. |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
function getExposureMeteringMode(photoSession: camera.PhotoSession): camera.ExposureMeteringMode {
let meteringMode: camera.ExposureMeteringMode = camera.ExposureMeteringMode.MATRIX;
try {
meteringMode = photoSession.getExposureMeteringMode();
} catch (error) {
// 失败返回错误码error.code并处理。
let err = error as BusinessError;
console.error(`The getExposureMeteringMode call failed. error code: ${err.code}`);
}
return meteringMode;
} setExposureMeteringMode(aeMeteringMode: ExposureMeteringMode): void
设置曝光测光模式。
元服务API: 从API version 24开始,该接口支持在元服务中使用。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| aeMeteringMode | ExposureMeteringMode | 是 | 曝光测光模式。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
| 错误码ID | 错误信息 |
|---|---|
| 7400102 | Operation not allowed, the inputDevice or the session is abnormal. |
| 7400103 | Session not config, only throw in session usage. |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
function setExposureMeteringMode(photoSession: camera.PhotoSession, aeMeteringMode: camera.ExposureMeteringMode): void {
try {
photoSession.setExposureMeteringMode(aeMeteringMode);
} catch (error) {
// 失败返回错误码error.code并处理。
let err = error as BusinessError;
console.error(`The setExposureMeteringMode call failed. error code: ${err.code}`);
}
} onExposureStateChange(callback: Callback<ExposureState>): void
监听曝光状态事件变更。使用callback异步回调。
起始版本: 26.0.0
模型约束: 此接口仅可在Stage模型下使用。
元服务API: 从API版本26.0.0开始,该接口支持在元服务中使用。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| callback | Callback<ExposureState> | 是 | 回调函数,返回当前曝光状态。 |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
function callback(exposureState: camera.ExposureState): void {
console.info(`exposureState: ${exposureState}`);
}
function registerPhotoOutputCaptureStart(captureSession: camera.PhotoSession): void {
captureSession.onExposureStateChange(callback);
} offExposureStateChange(callback?: Callback<ExposureState>): void
注销监听曝光状态事件变更。使用callback异步回调。
起始版本: 26.0.0
系统能力: SystemCapability.Multimedia.Camera.Core
模型约束: 此接口仅可在Stage模型下使用。
元服务API: 从API版本26.0.0开始,该接口支持在元服务中使用。
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| callback | Callback<ExposureState> | 否 | 回调函数,如果指定参数则取消对应callback,callback对象如果为空或为匿名函数,则取消所有callback。 |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
function callback(exposureState: camera.ExposureState): void {
console.info(`exposureState: ${exposureState}`);
}
function unregisterPhotoOutputCaptureStart(captureSession: camera.PhotoSession): void {
captureSession.offExposureStateChange(callback);
}
function unregisterPhotoOutputCaptureStartWithoutParam(captureSession: camera.PhotoSession): void {
captureSession.offExposureStateChange();
}