@ohos.multimedia.camera (相机管理)(系统接口)

本模块为开发者提供一套简单且易于理解的相机服务接口,开发者通过调用接口可以开发相机应用。应用通过访问和操作相机硬件,实现基础操作,如预览、拍照和录像;还可以通过接口组合完成更多操作,如控制闪光灯和曝光时间、对焦或调焦等。

说明:

  • 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
  • 当前页面仅包含本模块的系统接口,其他公开接口参见@ohos.multimedia.camera (相机管理)

导入模块

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

SceneMode11+

枚举,相机支持模式。

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

名称 说明
PORTRAIT_PHOTO 3 人像拍照模式。系统接口: 此接口为系统接口。
NIGHT_PHOTO 4 夜景拍照模式。系统接口: 此接口为系统接口。
PROFESSIONAL_PHOTO12+ 5 专业拍照模式。系统接口: 此接口为系统接口。
PROFESSIONAL_VIDEO12+ 6 专业录像模式。系统接口: 此接口为系统接口。
SLOW_MOTION_VIDEO12+ 7 慢动作模式。系统接口: 此接口为系统接口。
MACRO_PHOTO12+ 8 微距拍照模式。系统接口: 此接口为系统接口。
MACRO_VIDEO12+ 9 微距录像模式。系统接口: 此接口为系统接口。
LIGHT_PAINTING_PHOTO12+ 10 光绘摄影模式。系统接口: 此接口为系统接口。
HIGH_RESOLUTION_PHOTO12+ 11 高像素拍照模式。 系统接口: 此接口为系统接口。
QUICK_SHOT_PHOTO12+ 13 闪拍模式。系统接口: 此接口为系统接口。
APERTURE_VIDEO12+ 14 大光圈录像模式。系统接口: 此接口为系统接口。
PANORAMA_PHOTO12+ 15 全景拍照模式。 系统接口: 此接口为系统接口。
TIME_LAPSE_PHOTO12+ 16 延时摄影模式。 系统接口: 此接口为系统接口。
FLUORESCENCE_PHOTO13+ 17 荧光图片模式。系统接口: 此接口为系统接口。

SlowMotionStatus12+

枚举,慢动作状态。

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

名称 说明
DISABLED 0 慢动作关闭状态。
READY 1 慢动作就绪状态。
VIDEO_START 2 慢动作视频开始状态。
VIDEO_DONE 3 慢动作视频完成状态。
FINISHED 4 慢动作结束状态。

LcdFlashStatus12+

lcd闪光灯信息项。

系统接口: 此接口为系统接口。

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

名称 类型 只读 可选 说明
isLcdFlashNeeded boolean 是否需要lcd闪光灯,true为需要,false为不需要。
lcdCompensation number lcd闪光灯补偿值。

Photo11+

全质量图对象。

系统接口: 此接口为系统接口。

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

名称 类型 只读 可选 说明
raw12+ image.Image raw图。

PolicyType12+

枚举,策略类型。

系统接口: 此接口为系统接口。

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

名称 说明
PRIVACY12+ 1 隐私类型。

LightPaintingType12+

枚举,流光快门模式类型。

系统接口: 此接口为系统接口。

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

名称 说明
TRAFFIC_TRAILS 0 车水马龙。
STAR_TRAILS 1 绚丽星轨。
SILKY_WATER 2 丝绢流水。
LIGHT_GRAFFITI 3 光绘涂鸦。

CameraManager

相机管理器类,使用前需要通过getCameraManager获取相机管理实例。

createDepthDataOutput13+

createDepthDataOutput(profile: DepthProfile): DepthDataOutput

创建深度输出对象,同步返回结果。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
profile DepthProfile 支持的预览配置信息,通过getSupportedOutputCapability接口获取。

返回值:

类型 说明
DepthDataOutput DepthDataOutput实例。接口调用失败会返回相应错误码,错误码类型CameraErrorCode

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
202 Not System Application.
7400101 Parameter missing or parameter type incorrect.

示例:

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

function createDepthDataOutput(cameraOutputCapability: camera.CameraOutputCapability, cameraManager: camera.CameraManager): camera.DepthDataOutput | undefined {
  let profile: camera.DepthProfile = cameraOutputCapability.depthProfiles[0];
  let depthDataOutput: camera.DepthDataOutput | undefined = undefined;
  try {
    depthDataOutput = cameraManager.createDepthDataOutput(profile);
  } catch (error) {
    // 失败返回错误码error.code并处理。
    let err = error as BusinessError;
    console.error(`The createDepthDataOutput call failed. error code: ${err.code}`);
  }
  return depthDataOutput;
}

isCameraMuteSupported

isCameraMuteSupported(): boolean

查询当前设备是否支持禁用相机。

系统接口: 此接口为系统接口。

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

返回值:

类型 说明
boolean 返回true表示相机可以被禁用,返回false表示相机不能被禁用。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Permission verification failed. A non-system application calls a system API.

示例:

function isCameraMuteSupported(cameraManager: camera.CameraManager): boolean {
  let isMuteSupported: boolean = cameraManager.isCameraMuteSupported();
  return isMuteSupported;
}

muteCamera(deprecated)

muteCamera(mute: boolean): void

禁用相机。

说明: 从 API version 10开始支持,从API version 12开始废弃。建议使用muteCameraPersistent替代。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
mute boolean 禁用相机。true为禁用;false为解除禁用。

示例:

function muteCamera(cameraManager: camera.CameraManager): void {
  let mute: boolean = true;
  cameraManager.muteCamera(mute);
}

muteCameraPersistent12+

muteCameraPersistent(mute: boolean, type: PolicyType): void

以持久化的方式禁用相机。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
mute boolean 禁用相机。true为禁用;false为解除禁用。
type PolicyType 策略类型。请使用PolicyType里面支持的类型

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
201 Permission denied.
202 Not System Application.
7400101 Parameter missing or parameter type incorrect.

示例:

function muteCameraPersistent(cameraManager: camera.CameraManager): void {
  let mute: boolean = true;
  cameraManager.muteCameraPersistent(mute, camera.PolicyType.PRIVACY);
}

on('cameraMute')

on(type: 'cameraMute', callback: AsyncCallback<boolean>): void

禁用回调,通过注册回调函数获取相机禁用状态变化。使用callback异步回调。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'cameraMute',系统相机开关,cameraManager对象获取成功后可监听。系统设置打开或禁用相机会触发该事件并返回状态。
callback AsyncCallback<boolean> 回调函数,用于获取禁用状态变化信息,返回true为开启状态,返回false为禁用状态。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Permission verification failed. A non-system application calls a system API.

示例:

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

function callback(err: BusinessError, curMuted: boolean): void {
  if (err !== undefined && err.code !== 0) {
    console.error(`Callback Error, errorCode: ${err.code}`);
    return;
  }
  let isMuted: boolean = curMuted;
  console.info(`cameraMute status: ${isMuted}`);
}

function registerCameraMute(cameraManager: camera.CameraManager): void {
  cameraManager.on('cameraMute', callback);
}

off('cameraMute')

off(type: 'cameraMute', callback?: AsyncCallback<boolean>): void

禁用回调,通过注销注册回调函数获取相机禁用状态变化。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'cameraMute',系统相机开关,cameraManager对象获取成功后可监听。
callback AsyncCallback<boolean> 回调函数,可选参数,返回true为开启状态,返回false为禁用状态,有就是匹配on('cameraMute') callback(callback对象不可是匿名函数)。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Permission verification failed. A non-system application calls a system API.

示例:

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

function callback(err: BusinessError, curMuted: boolean): void {
  let isMuted: boolean = curMuted;
}

function unregisterCameraMute(cameraManager: camera.CameraManager): void {
  cameraManager.off('cameraMute', callback);
}

isPrelaunchSupported

isPrelaunchSupported(camera: CameraDevice): boolean

检查指定cameraDevice是否支持预热启动。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
camera CameraDevice 相机信息。

返回值:

类型 说明
boolean 返回指定cameraDevice是否支持预热启动,返回true为支持,返回false为不支持。

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
202 Permission verification failed. A non-system application calls a system API.
7400101 Parameter missing or parameter type incorrect.

示例:

import { common } from '@kit.AbilityKit';

function isPreLaunchSupported(context: common.BaseContext): boolean {
  let cameraManager: camera.CameraManager = camera.getCameraManager(context);
  let cameras: Array<camera.CameraDevice> = cameraManager.getSupportedCameras();
  let isSupported: boolean = false;
  if (cameras && cameras.length >= 1) {
    isSupported = cameraManager.isPrelaunchSupported(cameras[0]);
    console.info(`PreLaunch supported states: ${isSupported}`);
    return isSupported;
  }
  return isSupported;
}

setPrelaunchConfig

setPrelaunchConfig(prelaunchConfig: PrelaunchConfig): void

设置预热启动的配置参数。

在调用setPrelaunchConfig接口前,需要先检查设备是否支持预热启动,使用isPrelaunchSupported判断指定cameraDevice是否支持预热启动。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.CAMERA

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

参数:

参数名 类型 必填 说明
prelaunchConfig PrelaunchConfig 预启动配置参数。

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
202 Not System Application.
7400101 Parameter missing or parameter type incorrect.
7400102 Operation not allowed.
7400201 Camera service fatal error.

示例:

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

function setPrelaunchConfig(context: common.BaseContext): void {
  let cameraManager: camera.CameraManager = camera.getCameraManager(context);
  let cameras: Array<camera.CameraDevice> = cameraManager.getSupportedCameras();
  if (cameras && cameras.length >= 1) {
    let cameraDevice: camera.CameraDevice = cameras[0];
    if(cameraManager.isPrelaunchSupported(cameraDevice)) {
      try {
        cameraManager.setPrelaunchConfig({cameraDevice: cameraDevice});
      } catch (error) {
        let err = error as BusinessError;
        console.error(`setPrelaunchConfig error. Code: ${err.code}, message: ${err.message}`);
      }
    }
  }
}

prelaunch

prelaunch(): void

用户点击系统相机图标,拉起相机应用同时调用,下发预热请求,使能相机预热启动。

系统接口: 此接口为系统接口。

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

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

import { common } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { camera } from '@kit.CameraKit';

function preLaunch(context: common.BaseContext): void {
  let cameraManager: camera.CameraManager = camera.getCameraManager(context);
  try {
    cameraManager.prelaunch();
  } catch (error) {
    let err = error as BusinessError;
    console.error(`prelaunch error. Code: ${err.code}, message: ${err.message}`);
  }
}

preSwitchCamera11+

preSwitchCamera(cameraId: string): void

预切换相机,提升相机启动速度。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
cameraId string 相机id。

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
202 Not System Application.
7400101 Parameter missing or parameter type incorrect.
7400201 Camera service fatal error.

示例:

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

function preSwitch(cameraDevice: camera.CameraDevice, context: common.BaseContext): void {
  let cameraManager: camera.CameraManager = camera.getCameraManager(context);
  try {
    cameraManager.preSwitchCamera(cameraDevice.cameraId);
  } catch (error) {
    let err = error as BusinessError;
    console.error(`prelaunch error. Code: ${err.code}, message: ${err.message}`);
  }
}

CameraOutputCapability

相机输出能力项。

系统接口: 此接口为系统接口。

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

名称 类型 只读 可选 说明
depthProfiles13+ Array<DepthProfile> 支持的深度流配置信息集合。

CameraFormat

枚举,输出格式。

系统接口: 此接口为系统接口。

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

名称 说明
CAMERA_FORMAT_DEPTH_1613+ 3000 DEPTH_16格式的深度图。
CAMERA_FORMAT_DEPTH_3213+ 3001 DEPTH_32格式的深度图。

CameraInput

相机设备输入对象。

会话中Session使用的相机信息。

DepthDataAccuracy13+

深度数据的精度。

系统接口: 此接口为系统接口。

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

名称 说明
DEPTH_DATA_ACCURACY_RELATIVE 0 相对精度,基于视差计算得到的深度图。
DEPTH_DATA_ACCURACY_ABSOLUTE 1 绝对精度,基于测距计算得到的深度图。

DepthProfile13+

深度数据配置信息项,继承Profile

系统接口: 此接口为系统接口。

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

名称 类型 只读 可选 说明
dataAccuracy DepthDataAccuracy 深度数据的精度,分为相对精度和绝对精度。

DepthDataQualityLevel13+

深度数据的质量。

系统接口: 此接口为系统接口。

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

名称 说明
DEPTH_DATA_QUALITY_BAD 0 深度图的质量很差,无法用于虚化等。
DEPTH_DATA_QUALITY_FAIR 1 深度图的质量一般,无法生成高质量的虚化等。
DEPTH_DATA_QUALITY_GOOD 2 深度图的质量较高,可以生成高质量的虚化等。

DepthData13+

深度数据对象。

属性

系统接口: 此接口为系统接口。

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

名称 类型 只读 可选 说明
format CameraFormat 深度图的格式。
depthMap image.PixelMap 深度图。
qualityLevel DepthDataQualityLevel 深度图的质量。
dataAccuracy DepthDataAccuracy 深度图的精度。

release13+

release(): Promise<void>

释放输出资源。使用Promise异步回调。

系统接口: 此接口为系统接口。

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

返回值:

类型 说明
Promise<void> Promise对象,无返回结果。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

async function releaseDepthData(depthData: camera.DepthData): Promise<void> {
  await depthData.release();
}

DepthDataOutput13+

深度信息输出类。继承CameraOutput

start13+

start(): Promise<void>

启动深度信息输出流。使用Promise异步回调。

系统接口: 此接口为系统接口。

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

返回值:

类型 说明
Promise<void> Promise对象,无返回结果。

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
202 Not System Application.
7400103 Session not config.
7400201 Camera service fatal error.

示例:

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

function startDepthDataOutput(depthDataOutput: camera.DepthDataOutput): void {
  depthDataOutput.start().then(() => {
    console.info('Promise returned to indicate that start method execution success.');
  }).catch((error: BusinessError) => {
    console.error(`Failed to depth data output start, error code: ${error.code}.`);
  });
}

stop13+

stop(): Promise<void>

结束深度信息输出。使用Promise异步回调。

系统接口: 此接口为系统接口。

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

返回值:

类型 说明
Promise<void> Promise对象,无返回结果。

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
202 Not System Application.
7400103 Session not config.
7400201 Camera service fatal error.

示例:

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

function stopDepthDataOutput(depthDataOutput: camera.DepthDataOutput): void {
  depthDataOutput.stop().then(() => {
    console.info('Promise returned to indicate that stop method execution success.');
  }).catch((error: BusinessError) => {
    console.error(`Failed to depth data output stop, error code: ${error.code}.`);
  });
}

on('depthDataAvailable')13+

on(type: 'depthDataAvailable', callback: AsyncCallback<DepthData>): void

注册监听深度数据上报。使用callback异步回调。

说明:

当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'depthDataAvailable',depthDataOutput创建成功后可监听。
callback AsyncCallback<DepthData> 回调函数,用于监听深度信息上报。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

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

function callback(err: BusinessError, depthData: camera.DepthData): void {
  if (err !== undefined && err.code !== 0) {
    console.error(`Callback Error, errorCode: ${err.code}`);
    return;
  }
}

function registerDepthDataAvailable(depthDataOutput: camera.DepthDataOutput): void {
  depthDataOutput.on('depthDataAvailable', callback);
}

off('depthDataAvailable')13+

off(type: 'depthDataAvailable', callback?: AsyncCallback<DepthData>): void

注销监听深度信息上报。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'depthDataAvailable',depthDataOutput创建成功后可监听。
callback AsyncCallback<DepthData> 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

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

function callback(err: BusinessError, depthData: camera.DepthData): void {
  if (err !== undefined && err.code !== 0) {
    console.error(`Callback Error, errorCode: ${err.code}`);
    return;
  }
}

function unRegisterDepthDataAvailable(depthDataOutput: camera.DepthDataOutput): void {
  depthDataOutput.off('depthDataAvailable', callback);
}

on('error')13+

on(type: 'error', callback: ErrorCallback): void

监听深度信息输出的错误事件,通过注册回调函数获取结果。使用callback异步回调。

说明:

当前注册监听接口,不支持在on监听的回调方法里,调用off注销回调。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'error',depthDataOutput创建成功可监听。
callback ErrorCallback 回调函数,用于获取错误信息。返回错误码,错误码类型CameraErrorCode

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

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

function callback(depthDataOutputError: BusinessError): void {
  console.error(`Depth data output error code: ${depthDataOutputError.code}`);
}

function registerDepthDataOutputError(depthDataOutput: camera.DepthDataOutput): void {
  depthDataOutput.on('error', callback);
}

off('error')13+

off(type: 'error', callback?: ErrorCallback): void

注销监听深度信息输出的错误事件。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'error',depthDataOutput创建成功可监听。
callback ErrorCallback 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

function unregisterDepthDataOutputError(depthDataOutput: camera.DepthDataOutput): void {
  depthDataOutput.off('error');
}

DepthFusionQuery14+

深度融合查询类。

isDepthFusionSupported14+

isDepthFusionSupported(): boolean

查询是否支持深度融合,通过返回值获取结果。

系统接口: 此接口为系统接口。

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

返回值:

类型 说明
boolean 表示是否支持深度融合。true表示支持深度融合,false表示不支持深度融合。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档Camera错误码

错误码ID 错误信息
202 Not System Application.
7400103 Session not config, only throw in session usage.

示例:

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

function isDepthFusionSupported(DepthFusionQuery: camera.DepthFusionQuery): void {
  try {
    let isSupported: boolean = DepthFusionQuery.isDepthFusionSupported();
    console.info('Indicate that isDepthFusionSupported method execution success.');
  } catch (error) {
    let err = error as BusinessError;
    console.error(`Failed to depth fusion query  isDepthFusionSupported, error code: ${err.code}.`);
  }
}

getDepthFusionThreshold14+

getDepthFusionThreshold(): Array<number>

获取深度融合阈值,通过返回值获取结果。

系统接口: 此接口为系统接口。

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

返回值:

类型 说明
Array<number> 深度融合的阈值范围。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档Camera错误码

错误码ID 错误信息
202 Not System Application.
7400103 Session not config, only throw in session usage.

示例:

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

function getDepthFusionThreshold(DepthFusionQuery: camera.DepthFusionQuery): void {
  try {
    let threshold: Array<number> = DepthFusionQuery.getDepthFusionThreshold();
    console.info('Promise returned to indicate that getDepthFusionThreshold method execution success.');
  } catch (error) {
    let err = error as BusinessError;
    console.error(`Failed to depth fusion query  getDepthFusionThreshold, error code: ${err.code}.`);
  }
}

DepthFusion14+

深度融合类。继承DepthFusionQuery

isDepthFusionEnabled14+

isDepthFusionEnabled(): boolean

检测深度融合功能是否已启用,通过返回值获取结果。

系统接口: 此接口为系统接口。

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

返回值:

类型 说明
boolean 表示是否开启深度融合。true表示开启深度融合,false表示未开启深度融合。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档Camera错误码

错误码ID 错误信息
202 Not System Application.
7400103 Session not config.

示例:

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

function isDepthFusionEnabled(DepthFusion: camera.DepthFusion): boolean {
  let isEnable: boolean = false;
  try {
    isEnable = DepthFusion.isDepthFusionEnabled();
    console.info('Promise returned to indicate that isDepthFusionEnabled method execution success.');
  } catch (error) {
    let err = error as BusinessError;
    console.error(`Failed to depth fusion isDepthFusionEnabled, error code: ${err.code}.`);
  };
  return isEnable;
}

enableDepthFusion14+

enableDepthFusion(enabled: boolean): void

启用深度融合功能。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
enabled boolean 使能深度融合。true表示使能,false表示不使能。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档Camera错误码

错误码ID 错误信息
202 Not System Application.
7400101 Parameter missing or parameter type incorrect.
7400103 Session not config.
7400201 Camera service fatal error.

示例:

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

function enableDepthFusion(DepthFusion: camera.DepthFusion): void {
  try {
    let enabled: boolean = true;
    DepthFusion.enableDepthFusion(enabled);
    console.info('Promise returned to indicate that enableDepthFusion method execution success.');
  } catch (error) {
    let err = error as BusinessError;
    console.error(`Failed to depth fusion enableDepthFusion, error code: ${err.code}.`);
  };
}

PrelaunchConfig

相机预启动配置参数。

当前sensor级别预热,待扩展流预热参数。

系统接口: 此接口为系统接口。

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

名称 类型 只读 可选 说明
cameraDevice CameraDevice 相机信息。
restoreParamType11+ RestoreParamType 预保存参数类型。
activeTime11+ number 激活时间,单位min。
settingParam11+ SettingParam 设置参数内容。

RestoreParamType11+

预保存参数类型。

系统接口: 此接口为系统接口。

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

名称 说明
NO_NEED_RESTORE_PARAM 0 不需要预保存参数类型。
PRESISTENT_DEFAULT_PARAM 1 持久化参数类型,指某一时间点后,使用该参数恢复流信息。
TRANSIENT_ACTIVE_PARAM 2 临时参数类型,只在关闭相机后一段时间内,使用该参数恢复流信息,优先级高于持久化参数。

SettingParam11+

用于预热出图的效果参数。

系统接口: 此接口为系统接口。

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

名称 类型 只读 可选 说明
skinSmoothLevel number 美颜类型光滑信息,从Beauty.getSupportedBeautyRange获取支持的光滑范围,例如1表示1级光滑。
faceSlender number 美颜类型瘦脸信息,从Beauty.getSupportedBeautyRange获取支持的瘦脸范围,例如1表示1级瘦脸。
skinTone number 美颜类型肤色信息,从Beauty.getSupportedBeautyRange获取支持的肤色范围,例如0xBF986C表示一个颜色。

PreviewOutput

预览输出类。继承CameraOutput

isSketchSupported11+

isSketchSupported(): boolean

查询是否支持画中画能力。

系统接口: 此接口为系统接口。

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

返回值:

类型 说明
boolean 返回是否支持画中画,返回true为支持,返回false为不支持。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

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

function isSketchSupported(previewOutput: camera.PreviewOutput): boolean {
  try {
    let isSupported: boolean = previewOutput.isSketchSupported();
    return isSupported;
  } catch (error) {
    // 失败返回错误码error.code并处理。
    let err = error as BusinessError;
    console.error(`The isSketchSupported call failed. error code: ${err.code}`);
  }
  return false;
}

getSketchRatio11+

getSketchRatio(): number

获取当前状态下启动画中画的Zoom倍率。

系统接口: 此接口为系统接口。

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

返回值:

类型 说明
number 当前状态下启动画中画的Zoom倍率。不支持画中画的情况下,该接口返回-1。

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
7400103 Session not config.
202 Not System Application.

示例:

function getSketchRatio(previewOutput: camera.PreviewOutput): number {
  let sketchRatio: number = previewOutput.getSketchRatio();
  return sketchRatio;
}

enableSketch11+

enableSketch(enabled: boolean): void

使能画中画。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
enabled boolean true表明开启画中画流进行预览,false表明不开启。

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
202 Not System Application.
7400102 Operation not allowed.
7400103 Session not config.
7400201 Camera service fatal error.

示例:

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

function enableSketch(previewOutput: camera.PreviewOutput, session: camera.Session, cameraInput: camera.CameraInput): void {
  try {
    session.beginConfig();
    session.addInput(cameraInput);
    session.addOutput(previewOutput);
    previewOutput.enableSketch(true);
    session.commitConfig();
  } catch (error) {
    // 失败返回错误码error.code并处理。
    let err = error as BusinessError;
    console.error(`The enableSketch call failed. error code: ${err.code}`);
  }
}

attachSketchSurface11+

attachSketchSurface(surfaceId: string): void

添加画中画预览的Surface。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
surfaceId string XComponent组件获取的surfaceId。

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
202 Not System Application.
7400101 Parameter missing or parameter type incorrect.
7400103 Session not config.
7400201 Camera service fatal error.

示例:

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

function attachSketchSurface(previewOutput: camera.PreviewOutput, session: camera.Session, cameraInput: camera.CameraInput, sketchSurfaceId: string): void {
  try {
    session.beginConfig();
    session.addInput(cameraInput);
    session.addOutput(previewOutput);
    previewOutput.enableSketch(true);
    session.commitConfig();
    previewOutput.attachSketchSurface(sketchSurfaceId);
  } catch (error) {
    // 失败返回错误码error.code并处理。
    let err = error as BusinessError;
    console.error(`The attachSketchSurface call failed. error code: ${err.code}`);
  }
}

on('sketchStatusChanged')11+

on(type: 'sketchStatusChanged', callback: AsyncCallback<SketchStatusData>): void

监听画中画状态信息改变,通过注册回调函数获取SketchStatusData。使用callback异步回调。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'sketchStatusChanged',画中画流创建成功后可监听。底层画中画的状态启停以及画中画Zoom值变更会回调该接口。
callback AsyncCallback<SketchStatusData> 使用callback的方式获取SketchStatusData。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

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

function callback(error: BusinessError, data: camera.SketchStatusData): void {
  if (error !== undefined && error.code !== 0) {
    console.error(`Callback Error, errorCode: ${error.code}`);
    return;
  }
  console.info(`sketch errorCode is ${error.code}, data is ${JSON.stringify(data)}`);
}

function registerSketchStatusChanged(previewOutput: camera.PreviewOutput): void {
  previewOutput.on('sketchStatusChanged', callback);
}

off('sketchStatusChanged')11+

off(type: 'sketchStatusChanged', callback?: AsyncCallback<SketchStatusData>): void

注销监听画中画状态信息改变。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'sketchStatusChanged',画中画流创建成功后可监听。
callback AsyncCallback<SketchStatusData> 回调函数,可选,有就是匹配on('sketchStatusChanged') callback(callback对象不可是匿名函数)。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

function unregisterSketchStatusChanged(previewOutput: camera.PreviewOutput): void {
  previewOutput.off('sketchStatusChanged');
}

DeferredDeliveryImageType11+

枚举,分段式能力类型。即将拍照/录像分为两个阶段,一阶段以较快速度输出图片/视频提供给用户,二阶段完成优化处理,重新输出高质量图片/视频。

系统接口: 此接口为系统接口。

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

名称 说明
NONE 0 无分段式能力。
PHOTO 1 分段式拍照。
VIDEO 2 分段式录像。

DeferredPhotoProxy11+

类对象,缩略图代理类。

getThumbnail11+

getThumbnail(): Promise<image.PixelMap>

通过缩略图代理类提供的方法,获取缩略图PixelMap。使用Promise异步回调。

系统接口: 此接口为系统接口。

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

返回值:

类型 说明
Promise<image.PixelMap> 缩略图 PixelMap。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

import { image } from '@kit.ImageKit';

function getThumbnail(proxyObj: camera.DeferredPhotoProxy): void {
  proxyObj.getThumbnail().then((thumbnail: image.PixelMap) => {
    AppStorage.setOrCreate('proxyThumbnail', thumbnail);
  });
}

release11+

release(): Promise<void>

释放输出资源。使用Promise异步回调。

系统接口: 此接口为系统接口。

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

返回值:

类型 说明
Promise<void> Promise对象,无返回结果。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

async function releaseDeferredPhotoProxy(proxyObj: camera.DeferredPhotoProxy): Promise<void> {
  await proxyObj.release();
}

PhotoOutput

拍照会话中使用的输出信息,继承CameraOutput

burstCapture12+

burstCapture(setting: PhotoCaptureSetting): Promise<void>

开始连续拍照,一般用于拍照模式下,开始后底层持续上图,可以通过confirmCapture取消连续拍照。使用Promise异步回调。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
setting PhotoCaptureSetting 拍照设置,传入undefined类型数据按默认无参处理。

返回值:

类型 说明
Promise<void> Promise对象,无返回结果。

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
202 Not System Application.
7400101 Parameter missing or parameter type incorrect.
7400104 Session not running.
7400201 Camera service fatal error.

示例:

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

function burstCapture(photoOutput: camera.PhotoOutput): void {
  let captureLocation: camera.Location = {
    latitude: 0,
    longitude: 0,
    altitude: 0
  }
  let settings: camera.PhotoCaptureSetting = {
    quality: camera.QualityLevel.QUALITY_LEVEL_LOW,
    rotation: camera.ImageRotation.ROTATION_0,
    location: captureLocation,
    mirror: false
  }
  photoOutput.burstCapture(settings).then(() => {
    console.info('Promise returned to indicate that photo burstCapture request success.');
  }).catch((error: BusinessError) => {
    console.error(`Failed to photo output burstCapture, error code: ${error.code}.`);
  });
}

confirmCapture11+

confirmCapture(): void

确认拍照,一般用于夜景模式下,在曝光倒计时过程中如需终止倒计时提前拍照的时候调用。

已经调用burstCapture开始连续拍照后,调用该接口用于结束连续拍照。

系统接口: 此接口为系统接口。

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

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
202 Not System Application.
7400104 Session not running.
7400201 Camera service fatal error.

示例:

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

function confirmCapture(photoOutput: camera.PhotoOutput): void {
  try {
    photoOutput.confirmCapture();
  } catch (error) {
    let err = error as BusinessError;
    console.error(`The confirmCapture call failed. error code: ${err.code}`);
  }
}

isDeferredImageDeliverySupported11+

isDeferredImageDeliverySupported(type: DeferredDeliveryImageType): boolean

查询当前模式是否支持相关分段式能力。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type DeferredDeliveryImageType 分段式能力类型。

返回值:

类型 说明
boolean true: 当前模式支持该类型分段式能力, false: 不支持。

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
7400101 Parameter missing or parameter type incorrect.
7400104 Session not running.
7400201 Camera service fatal error.
202 Not System Application.

示例:

function isDeferredImageDeliverySupported(photoOutput: camera.PhotoOutput, type: camera.DeferredDeliveryImageType): boolean {
  let res: boolean = false;
  res = photoOutput.isDeferredImageDeliverySupported(type);
  return res;
}

isDeferredImageDeliveryEnabled11+

isDeferredImageDeliveryEnabled(type: DeferredDeliveryImageType): boolean

查询当前模式是否已开启相关分段式能力。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type DeferredDeliveryImageType 分段式能力类型。

返回值:

类型 说明
boolean true: 当前模式已开启该类型分段式能力, false: 未开启。

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
7400101 Parameter missing or parameter type incorrect.
7400104 Session not running.
7400201 Camera service fatal error.
202 Not System Application.

示例:

function isDeferredImageDeliveryEnabled(photoOutput: camera.PhotoOutput, type: camera.DeferredDeliveryImageType): boolean {
  let res: boolean = false;
  res = photoOutput.isDeferredImageDeliveryEnabled(type);
  return res;
}

deferImageDelivery11+

deferImageDelivery(type: DeferredDeliveryImageType): void

开启相关类型分段式能力。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type DeferredDeliveryImageType 分段式能力类型。

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
7400101 Parameter missing or parameter type incorrect.
7400104 Session not running.
7400201 Camera service fatal error.
202 Not System Application.

示例:

function deferImageDelivery(photoOutput: camera.PhotoOutput, type: camera.DeferredDeliveryImageType): void {
  photoOutput.deferImageDelivery(type);
}

isAutoHighQualityPhotoSupported13+

isAutoHighQualityPhotoSupported(): boolean

判断当前是否支持自动高画质。

系统接口: 此接口为系统接口。

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

返回值:

类型 说明
boolean 是否支持自动高画质,返回true是支持,返回false是不支持。

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
202 Not System Application.
7400104 Session not running.
7400201 Camera service fatal error.

示例:

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

function isAutoHighQualityPhotoSupported(photoOutput: camera.PhotoOutput): boolean {
  return photoOutput.isAutoHighQualityPhotoSupported();
}

enableAutoHighQualityPhoto13+

enableAutoHighQualityPhoto(enabled: boolean): void

使能拍照自动高画质。设置拍照自动高画质之前,需要调用isAutoHighQualityPhotoSupported判断当前是否支持。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
enabled boolean 是否使能拍照自动高画质,true为使能,false为不使能。

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
202 Not System Application.
7400101 Parameter missing or parameter type incorrect.
7400104 Session not running.
7400201 Camera service fatal error.

示例:

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

function enableAutoHighQualityPhoto(photoOutput: camera.PhotoOutput): void {
  return photoOutput.enableAutoHighQualityPhoto(true);
}

on('deferredPhotoProxyAvailable')11+

on(type: 'deferredPhotoProxyAvailable', callback: AsyncCallback<DeferredPhotoProxy>): void

注册监听缩略图上报。使用callback异步回调。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'deferredPhotoProxyAvailable',photoOutput创建成功后可监听。
callback AsyncCallback<DeferredPhotoProxy> 回调函数,用于获取相关信息。用于监听缩略图上报。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

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

function callback(err: BusinessError, proxyObj: camera.DeferredPhotoProxy): void {
  if (err !== undefined && err.code !== 0) {
    console.error(`Callback Error, errorCode: ${err.code}`);
    return;
  }
  proxyObj.getThumbnail().then((thumbnail: image.PixelMap) => {
    AppStorage.setOrCreate('proxyThumbnail', thumbnail);
  });
}

function registerPhotoOutputDeferredPhotoProxyAvailable(photoOutput: camera.PhotoOutput): void {
  photoOutput.on('deferredPhotoProxyAvailable', callback);
}

off('deferredPhotoProxyAvailable')11+

off(type: 'deferredPhotoProxyAvailable', callback?: AsyncCallback<DeferredPhotoProxy>): void

注销监听缩略图上报。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'deferredPhotoProxyAvailable',photoOutput创建成功后可监听。
callback AsyncCallback<DeferredPhotoProxy> 回调函数,可选,有就是匹配on('deferredPhotoProxyAvailable') callback(callback对象不可是匿名函数)。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

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

function callback(err: BusinessError, proxyObj: camera.DeferredPhotoProxy): void {
  if (err !== undefined && err.code !== 0) {
    console.error(`Callback Error, errorCode: ${err.code}`);
    return;
  }
  proxyObj.getThumbnail().then((thumbnail: image.PixelMap) => {
    AppStorage.setOrCreate('proxyThumbnail', thumbnail);
  });
}

function unRegisterPhotoOutputDeferredPhotoProxyAvailable(photoOutput: camera.PhotoOutput): void {
  photoOutput.off('deferredPhotoProxyAvailable', callback);
}

isQuickThumbnailSupported

isQuickThumbnailSupported(): boolean

是否支持输出快速缩略图。

addOutputaddInput之后,commitConfig之前生效。

系统接口: 此接口为系统接口。

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

返回值:

类型 说明
boolean 返回支持情况,如果返回true表示支持,否则不支持。

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
202 Not System Application.
7400104 session is not running.

示例:

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

async function isQuickThumbnailSupported(context: common.BaseContext, mode: camera.SceneMode, photoProfile: camera.Profile): Promise<boolean> {
  let cameraManager: camera.CameraManager = camera.getCameraManager(context);
  let cameras: Array<camera.CameraDevice> = cameraManager.getSupportedCameras();
  // 创建CaptureSession实例。
  let session: camera.Session = cameraManager.createSession(mode);
  // 开始配置会话。
  session.beginConfig();
  // 把CameraInput加入到会话。
  if (cameras.length <= 0) {
    console.info('Get supported cameras is null or [].');
    return false;
  }
  let cameraInput: camera.CameraInput = cameraManager.createCameraInput(cameras[0]);
  await cameraInput.open();
  session.addInput(cameraInput);
  // 把photoOutput加入到会话。
  let photoOutput: camera.PhotoOutput = cameraManager.createPhotoOutput(photoProfile);
  try {
    session.addOutput(photoOutput);
  } catch (error) {
    let err = error as BusinessError;
    console.error(`AddOutput called failed. error code: ${err.code}`);
    return false;
  }
  let isSupported: boolean = photoOutput.isQuickThumbnailSupported();
  return isSupported;
}

enableQuickThumbnail

enableQuickThumbnail(enabled: boolean): void

启用/禁用快速缩略图。

addOutputaddInput之后,commitConfig之前生效。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
enabled boolean true:使能快速缩略图;false:去使能快速缩略图。

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
202 Not System Application.
7400101 Parameter missing or parameter type incorrect.
7400104 session is not running.
7400201 Camera service fatal error.

示例:

import { common } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { camera } from '@kit.CameraKit';

async function enableQuickThumbnail(context: common.BaseContext, mode: camera.SceneMode, photoProfile: camera.Profile): Promise<void> {
  let cameraManager: camera.CameraManager = camera.getCameraManager(context);
  let cameras: Array<camera.CameraDevice> = cameraManager.getSupportedCameras();
  // 创建CaptureSession实例。
  let session: camera.Session = cameraManager.createSession(mode);
  // 开始配置会话。
  session.beginConfig();
  // 把CameraInput加入到会话。
  let cameraInput: camera.CameraInput = cameraManager.createCameraInput(cameras[0]);
  await cameraInput.open();
  session.addInput(cameraInput);
  // 把PhotoOutPut加入到会话。
  let photoOutput: camera.PhotoOutput = cameraManager.createPhotoOutput(photoProfile);
  session.addOutput(photoOutput);
  let isSupported: boolean = photoOutput.isQuickThumbnailSupported();
  if (!isSupported) {
    console.info('Quick Thumbnail is not supported to be turned on.');
    return;
  }
  try {
    photoOutput.enableQuickThumbnail(true);
  } catch (error) {
    let err = error as BusinessError;
    console.error(`The enableQuickThumbnail call failed. error code: ${err.code}`);
  }
}

on('quickThumbnail')

on(type: 'quickThumbnail', callback: AsyncCallback<image.PixelMap>): void

监听快速缩略图输出事件。使用callback异步回调。

在enableQuickThumbnail(true)使能快速缩略图之后监听生效。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'quickThumbnail'。
callback AsyncCallback<image.PixelMap> 回调返回PixelMap。

示例:

import { common } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { image } from '@kit.ImageKit';
import { camera } from '@kit.CameraKit';

function callback(err: BusinessError, pixelMap: image.PixelMap): void {
  if (err || pixelMap === undefined) {
      console.error('photoOutput on thumbnail failed');
      return;
  }
  // 显示或保存pixelMap。
  // 执行操作。
}

async function registerQuickThumbnail(context: common.BaseContext, mode: camera.SceneMode, photoProfile: camera.Profile): Promise<void> {
  let cameraManager: camera.CameraManager = camera.getCameraManager(context);
  let cameras: Array<camera.CameraDevice> = cameraManager.getSupportedCameras();
  // 创建CaptureSession实例。
  let session: camera.Session = cameraManager.createSession(mode);
  // 开始配置会话。
  session.beginConfig();
  // 把CameraInput加入到会话。
  let cameraInput: camera.CameraInput = cameraManager.createCameraInput(cameras[0]);
  await cameraInput.open();
  session.addInput(cameraInput);
  // 把PhotoOutPut加入到会话。
  let photoOutput: camera.PhotoOutput = cameraManager.createPhotoOutput(photoProfile);
  session.addOutput(photoOutput);
  let isSupported: boolean = photoOutput.isQuickThumbnailSupported();
  if (!isSupported) {
    console.info('Quick Thumbnail is not supported to be turned on.');
    return;
  }
  try {
    photoOutput.enableQuickThumbnail(true);
  } catch (error) {
    let err = error as BusinessError;
    console.error(`The enableQuickThumbnail call failed. error code: ${err.code}`);
  }

  photoOutput.on('quickThumbnail', callback);
}

off('quickThumbnail')

off(type: 'quickThumbnail', callback?: AsyncCallback<image.PixelMap>): void

注销监听快速缩略图输出事件。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'quickThumbnail'。
callback AsyncCallback<image.PixelMap> 回调函数,可选,有就是匹配on('quickThumbnail') callback(callback对象不可是匿名函数)。

示例:

function unregisterQuickThumbnail(photoOutput: camera.PhotoOutput): void {
  photoOutput.off('quickThumbnail');
}

MetadataOutput

metadata流。继承CameraOutput

MetadataObject

相机检测元数据信息的基础类型,CameraInput相机信息中的数据来源,通过metadataOutput.on('metadataObjectsAvailable')接口获取。

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

名称 类型 只读 可选 说明
objectId13+ number metadataObject Id序号。
confidence13+ number 检测置信度,取值范围[0, 1]。

PortraitEffect

人像效果类型。

系统接口: 此接口为系统接口。

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

名称 说明
OFF 0 关闭。
CIRCLES 1 圆形。
HEART11+ 2 心形。
ROTATED11+ 3 旋焦。
STUDIO11+ 4 影棚光。
THEATER11+ 5 剧场光。

BeautyQuery12+

提供了获取和设置美颜效果的方法。

getSupportedBeautyTypes11+

getSupportedBeautyTypes(): Array<BeautyType>

获取当前支持的美颜效果列表。

系统接口: 此接口为系统接口。

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

返回值:

类型 说明
Array<BeautyType> 返回当前支持的美颜效果列表。

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
202 Not System Application.
7400103 Session not config, only throw in session usage.

示例:

function getSupportedBeautyTypes(portraitPhotoSession: camera.PortraitPhotoSession): Array<camera.BeautyType> {
  let beautyTypes: Array<camera.BeautyType> = portraitPhotoSession.getSupportedBeautyTypes();
  return beautyTypes;
}

getSupportedBeautyRange11+

getSupportedBeautyRange(type: BeautyType): Array<number>

获取指定美颜效果的范围值。在不同设备返回的美颜强度有所不同,下表仅做示例。

传入参数 示例返回值 返回值说明
AUTO [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] 美颜类型为自动时支持的美颜强度,0表明关闭美颜,其余正值表明自动的美颜强度。
SKIN_SMOOTH [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] 美颜类型为光滑时支持的美颜强度,0表明关闭光滑,其余正值表明光滑的美颜强度。
FACE_SLENDER [0, 1, 2, 3, 4, 5] 美颜类型为瘦脸时支持的美颜强度,0表明关闭瘦脸,其余正值表明瘦脸的美颜强度。
SKIN_TONE [-1, 16242611] 美颜类型为美肤时支持的美颜强度,-1表明关闭美肤,其余非负值为使用RGB表示的美肤美颜强度,
16242611转化为16进制为0xF7D7B3,F7为R通道值,D7为G通道值,B3位B通道值。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type BeautyType 美颜类型。

返回值:

类型 说明
Array<number> 当前美颜类型所支持的美颜强度。

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
202 Not System Application.
7400103 Session not config, only throw in session usage.

示例:

function getSupportedBeautyRange(portraitPhotoSession: camera.PortraitPhotoSession): Array<number> {
  let beautyTypes: Array<camera.BeautyType> = portraitPhotoSession.getSupportedBeautyTypes();
  if (beautyTypes === undefined || beautyTypes.length <= 0) {
    return [];
  }
  let beautyLevels: Array<number> = portraitPhotoSession.getSupportedBeautyRange(beautyTypes[0]);
  return beautyLevels;
}

BeautyType

美颜类型。

系统接口: 此接口为系统接口。

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

名称 说明
AUTO 0 自动。
SKIN_SMOOTH 1 光滑。
FACE_SLENDER 2 瘦脸。
SKIN_TONE 3 肤色。

ManualExposureQuery12+

此接口提供了查询设备对手动曝光范围支持的功能。

getSupportedExposureRange11+

getSupportedExposureRange(): Array<number>

获取当前支持的手动曝光时长,单位ms。

系统接口: 此接口为系统接口。

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

返回值:

类型 说明
Array<number> 返回当前支持的手动曝光时长,单位ms。

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
202 Not System Application.
7400101 Parameter missing or parameter type incorrect.
7400103 Session not config, only throw in session usage.

示例:

function getSupportedExposureRange(nightPhotoSession: camera.NightPhotoSession): Array<number> {
  let exposureRange: Array<number> = nightPhotoSession.getSupportedExposureRange();
  return exposureRange;
}

ManualExposure11+

ManualExposure extends ManualExposureQuery

提供了获取和设置曝光值的功能。

getExposure11+

getExposure(): number

查询当前已设置的手动曝光时长,单位为ms。

系统接口: 此接口为系统接口。

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

返回值:

参数名 类型 必填 说明
value number 手动曝光时长,单位为ms。

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
202 Not System Application.
7400101 Parameter missing or parameter type incorrect.
7400103 Session not config.

示例:

function getExposure(nightPhotoSession: camera.NightPhotoSession): number | undefined {
  let exposureRange: Array<number> = nightPhotoSession.getSupportedExposureRange();
  if (exposureRange === undefined || exposureRange.length <= 0) {
    return undefined;
  }
  let exposure: number = nightPhotoSession.getExposure();
  return exposure;
}

setExposure11+

setExposure(exposure: number): void

设置手动曝光时长。getSupportedExposureRange获取得到支持的手动曝光时长列表选取用户所需的时长下发,单位ms。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
exposure number 手动曝光时长,通过getSupportedExposureRange接口获取。

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
202 Not System Application.
7400102 Operation not allowed.
7400103 Session not config.
function setExposure(nightPhotoSession: camera.NightPhotoSession): void {
  let exposureRange: Array<number> = nightPhotoSession.getSupportedExposureRange();
  if (exposureRange === undefined || exposureRange.length <= 0) {
    return;
  }
  nightPhotoSession.setExposure(exposureRange[0]);
}

TripodStatus13+

枚举,脚架状态枚举。

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

名称 说明
INVALID 0 错误状态/默认未检测到脚架状态。系统接口: 此接口为系统接口。
ACTIVE 1 脚架活动状态。系统接口: 此接口为系统接口。
ENTERING 2 进入脚架稳定状态。系统接口: 此接口为系统接口。
EXITING 3 退出脚架稳定状态。系统接口: 此接口为系统接口。

SceneFeatureType12+

枚举,场景特性枚举。

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

名称 说明
MOON_CAPTURE_BOOST 0 月亮场景。系统接口: 此接口为系统接口。
TRIPOD_DETECTION13+ 1 使用脚架拍摄的场景。系统接口: 此接口为系统接口。
LOW_LIGHT_BOOST13+ 2 长曝光场景。系统接口: 此接口为系统接口。

SceneFeatureDetectionResult12+

场景检测结果信息。

系统接口: 此接口为系统接口。

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

名称 类型 只读 可选 说明
featureType SceneFeatureType 特性类型。
detected boolean 表示是否检测到指定特性场景。true为检测到指定特性场景,false为未检测到指定特性场景。

TripodDetectionResult13+

TripodDetectionResult extends SceneFeatureDetectionResult

脚架检测信息。

系统接口: 此接口为系统接口。

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

名称 类型 只读 可选 说明
tripodStatus TripodStatus 脚架状态信息。

SceneDetectionQuery12+

场景检测查询能力。

isSceneFeatureSupported12+

isSceneFeatureSupported(type: SceneFeatureType): boolean

查询是否支持指定特性。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type SceneFeatureType 指定对应的场景特性。

返回值:

类型 说明
boolean 返回是否支持指定特性,返回true为支持,返回false为不支持。

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
202 Not System Application, only throw in session usage.
7400101 Parameter missing or parameter type incorrect.

示例:

function isSceneFeatureSupported(photoSessionForSys: camera.PhotoSessionForSys, featureType: camera.SceneFeatureType): boolean {
  let isSupported: boolean = photoSessionForSys.isSceneFeatureSupported(featureType);
  return isSupported;
}

SceneDetection12+

场景检测能力。继承SceneDetectionQuery

enableSceneFeature12+

enableSceneFeature(type: SceneFeatureType, enabled: boolean): void

使能指定特性,该接口应当在收到对应场景检测回调结果SceneFeatureDetectionResult之后调用。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type SceneFeatureType 指定需要开启或关闭的特性。
enabled boolean true表明开启指定特性,false表明关闭指定特性。

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
202 Not System Application.
7400101 Parameter missing or parameter type incorrect.

示例:

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

function enableSceneFeature(photoSession: camera.PhotoSessionForSys, cameraInput: camera.CameraInput, previewOutput: camera.PreviewOutput): void {
  photoSession.beginConfig();
  photoSession.addInput(cameraInput);
  photoSession.addOutput(previewOutput);
  photoSession.commitConfig();

  photoSession.on('featureDetection', camera.SceneFeatureType.MOON_CAPTURE_BOOST,
    (err: BusinessError, statusObject: camera.SceneFeatureDetectionResult) => {
      if (err !== undefined && err.code !== 0) {
        console.error(`Callback Error, errorCode: ${err.code}`);
        return;
      }
      console.info(
        `on featureDetectionStatus featureType:${statusObject.featureType} detected:${statusObject.detected}`);
      if (statusObject.featureType === camera.SceneFeatureType.MOON_CAPTURE_BOOST) {
        try {
          photoSession.enableSceneFeature(statusObject.featureType, statusObject.detected);
        } catch (error) {
          let err = error as BusinessError;
          console.error(`The enableSceneFeature call failed. error code: ${err.code}`);
        }
      }
    });
}

ZoomQuery12+

提供获取当前模式的等效焦距信息列表的方法。

Zoom11+

Zoom extends ZoomQuery

提供了处理设备变焦效果的相关方法,包括获取当前的变焦比,设置变焦比率,以及通过平滑方法设置目标变焦比,以及一些开启和结束变焦的函数。

prepareZoom11+

prepareZoom(): void

通知底层准备变焦,如sensor上电。

系统接口: 此接口为系统接口。

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

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
202 Not System Application.
7400103 Session not config.

示例:

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

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

unprepareZoom11+

unprepareZoom(): void

通知底层离开变焦准备状态。

系统接口: 此接口为系统接口。

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

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
202 Not System Application.
7400103 Session not config.

示例:

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

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

Beauty11+

Beauty extends BeautyQuery

提供了获取和设置美颜效果的方法。

setBeauty11+

setBeauty(type: BeautyType, value: number): void

设置美颜类型以及对应的美颜强度。将通过getSupportedBeautyTypes获取得到的BeautyType都关闭,表明当前美颜关闭;若有一种美颜类型未关闭,表明当前美颜打开。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type BeautyType 美颜类型。
value number 美颜强度,通过getSupportedBeautyRange接口获取。

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
202 Not System Application.
7400103 Session not config.

示例:

function setBeauty(portraitPhotoSession: camera.PortraitPhotoSession): void {
  let beautyTypes: Array<camera.BeautyType> = portraitPhotoSession.getSupportedBeautyTypes();
  if (beautyTypes === undefined || beautyTypes.length <= 0) {
    return;
  }
  let beautyLevels: Array<number> = portraitPhotoSession.getSupportedBeautyRange(beautyTypes[0]);
  if (beautyLevels === undefined || beautyLevels.length <= 0) {
    return;
  }
  portraitPhotoSession.setBeauty(beautyTypes[0], beautyLevels[0]);
}

getBeauty11+

getBeauty(type: BeautyType): number

查询当前已设置的美颜效果对应的美颜强度。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type BeautyType 美颜类型。

返回值:

参数名 类型 必填 说明
value number 美颜强度。

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
202 Not System Application.
7400103 Session not config.

示例:

function getBeauty(portraitPhotoSession: camera.PortraitPhotoSession): number {
  const invalidValue: number = -1;
  let beautyTypes = portraitPhotoSession.getSupportedBeautyTypes();
  if (beautyTypes === undefined || beautyTypes.length <= 0) {
    return invalidValue;
  }
  let beautyLevels: Array<number> = portraitPhotoSession.getSupportedBeautyRange(beautyTypes[0]);
  if (beautyLevels === undefined || beautyLevels.length <= 0) {
    return invalidValue;
  }
  portraitPhotoSession.setBeauty(beautyTypes[0], beautyLevels[0]);
  let beautyLevel: number = portraitPhotoSession.getBeauty(beautyTypes[0]);
  return beautyLevel;
}

ColorEffectQuery12+

提供了一个查询设备支持的颜色效果类型的方法。

getSupportedColorEffects11+

getSupportedColorEffects(): Array<ColorEffectType>

获取支持的色彩效果类型列表。

系统接口: 此接口为系统接口。

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

返回值:

类型 说明
Array<ColorEffectType> 支持的色彩效果类型列表。

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
202 Not System Application.
7400103 Session not config, only throw in session usage.

示例:

function getSupportedColorEffects(session: camera.PhotoSessionForSys): Array<camera.ColorEffectType> {
  let colorEffects: Array<camera.ColorEffectType> = session.getSupportedColorEffects();
  return colorEffects;
}

ColorEffect11+

ColorEffect extends ColorEffectQuery

提供了获取和设置镜头色彩效果的相关功能。

setColorEffect11+

setColorEffect(type: ColorEffectType): void

设置色彩效果类型。可以先通过getSupportedColorEffects获取当前设备所支持的ColorEffects。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type ColorEffectType 色彩效果类型,通过getSupportedColorEffects接口获取。

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
7400103 Session not config.
202 Not System Application.

示例:

function setColorEffect(session: camera.PhotoSessionForSys, colorEffect: camera.ColorEffectType): void {
  session.setColorEffect(colorEffect);
}

getColorEffect11+

getColorEffect(): ColorEffectType

获取当前设置的色彩效果类型。

系统接口: 此接口为系统接口。

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

返回值:

类型 说明
ColorEffectType 当前设置的色彩效果类型。

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
7400103 Session not config.
202 Not System Application.

示例:

function getColorEffect(session: camera.PhotoSessionForSys): camera.ColorEffectType {
  let colorEffect: camera.ColorEffectType = session.getColorEffect();
  return colorEffect;
}

ColorEffectType11+

枚举,色彩效果类型。

系统接口: 此接口为系统接口。

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

名称 说明
NORMAL 0 常规的色彩效果。
BRIGHT 1 明艳的色彩效果。
SOFT 2 柔和的色彩效果。
BLACK_WHITE12+ 3 黑白色彩效果。

PortraitQuery12+

人像查询类,用于获取人像参数。

getSupportedPortraitEffects

getSupportedPortraitEffects(): Array<PortraitEffect>

获取支持的人像虚化效果列表。

系统接口: 此接口为系统接口。

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

返回值:

类型 说明
Array<PortraitEffect> 支持的人像虚化效果列表。

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
202 Not System Application.
7400103 Session not config, only throw in session usage.

示例:

function getSupportedPortraitEffects(portraitPhotoSession: camera.PortraitPhotoSession): Array<camera.PortraitEffect> {
  let portraitEffects: Array<camera.PortraitEffect> = portraitPhotoSession.getSupportedPortraitEffects();
  return portraitEffects;
}

Portrait11+

Portrait继承自PortraitQuery

人像类,用于设置人像参数。

setPortraitEffect

setPortraitEffect(effect: PortraitEffect): void

设置人像虚化效果。需要先检查设备是否支持人像虚化模式,可以通过getSupportedPortraitEffects获取当前设备所支持的PortraitEffects。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
effect PortraitEffect 人像虚化效果,通过getSupportedPortraitEffects接口获取。

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
7400103 Session not config.
202 Not System Application.

示例:

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

function setPortraitEffect(portraitPhotoSession: camera.PortraitPhotoSession, portraitEffects: Array<camera.PortraitEffect>): void {
  if (portraitEffects === undefined || portraitEffects.length <= 0) {
    return;
  }
  try {
    portraitPhotoSession.setPortraitEffect(portraitEffects[0]);
  } catch (error) {
    let err = error as BusinessError;
    console.error(`The setPortraitEffect call failed. error code: ${err.code}`);
  }
}

getPortraitEffect

getPortraitEffect(): PortraitEffect

获取当前设置的人像虚化效果。

系统接口: 此接口为系统接口。

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

返回值:

类型 说明
PortraitEffect 当前设置的人像虚化效果。

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
7400103 Session not config.
202 Not System Application.

示例:

function getPortraitEffect(portraitPhotoSession: camera.PortraitPhotoSession): camera.PortraitEffect {
  let portraitEffect: camera.PortraitEffect = portraitPhotoSession.getPortraitEffect();
  return portraitEffect;
}

ApertureQuery12+

光圈查询能力。

getSupportedVirtualApertures11+

getSupportedVirtualApertures(): Array<number>

获取支持的虚拟光圈列表。

系统接口: 此接口为系统接口。

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

返回值:

类型 说明
Array<number> 支持的虚拟光圈列表。

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
202 Not System Application.
7400103 Session not config, only throw in session usage.

示例:

function getSupportedVirtualApertures(session: camera.PortraitPhotoSession): Array<number> {
  let virtualApertures: Array<number> = session.getSupportedVirtualApertures();
  return virtualApertures;
}

Aperture11+

光圈类,用于设置光圈参数。继承ApertureQuery

getVirtualAperture11+

getVirtualAperture(): number

获取当前设置的虚拟光圈值。

系统接口: 此接口为系统接口。

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

返回值:

类型 说明
number 当前设置的虚拟光圈值。

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
7400103 Session not config.
202 Not System Application.

示例:

function getVirtualAperture(session: camera.PortraitPhotoSession): number {
  let virtualAperture: number = session.getVirtualAperture();
  return virtualAperture;
}

setVirtualAperture11+

setVirtualAperture(aperture: number): void

设置虚拟光圈。可以先通过getSupportedVirtualApertures获取当前设备所支持的虚拟光圈列表。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
aperture number 虚拟光圈值,通过getSupportedVirtualApertures接口获取。

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
7400103 Session not config.
202 Not System Application.

示例:

function setVirtualAperture(session: camera.PortraitPhotoSession, virtualAperture: number): void {
  session.setVirtualAperture(virtualAperture);
}

CaptureSession(deprecated)

拍照会话类,保存一次相机运行所需要的所有资源CameraInputCameraOutput,并向相机设备申请完成相机功能(录像,拍照)。

说明: 从 API version 10开始支持,从API version 11开始废弃。建议使用PhotoSessionVideoSession替代。

getSupportedBeautyTypes(deprecated)

getSupportedBeautyTypes(): Array<BeautyType>

获取当前支持的美颜效果列表。

说明: 从 API version 10开始支持,从API version 11开始废弃。建议使用Beauty.getSupportedBeautyTypes替代。

系统接口: 此接口为系统接口。

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

返回值:

类型 说明
Array<BeautyType> 返回当前支持的美颜效果列表。

错误码:

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

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

示例:

function getSupportedBeautyTypes(captureSession: camera.CaptureSession): Array<camera.BeautyType> {
  let beautyTypes: Array<camera.BeautyType> = captureSession.getSupportedBeautyTypes();
  return beautyTypes;
}

getSupportedBeautyRange(deprecated)

getSupportedBeautyRange(type: BeautyType): Array<number>

获取指定美颜效果的范围值。在不同设备返回的美颜强度有所不同,下表仅做示例。

传入参数 示例返回值 返回值说明
AUTO [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] 美颜类型为自动时支持的美颜强度,0表明关闭美颜,其余正值表明自动的美颜强度。
SKIN_SMOOTH [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] 美颜类型为光滑时支持的美颜强度,0表明关闭光滑,其余正值表明光滑的美颜强度。
FACE_SLENDER [0, 1, 2, 3, 4, 5] 美颜类型为瘦脸时支持的美颜强度,0表明关闭瘦脸,其余正值表明瘦脸的美颜强度。
SKIN_TONE [-1, 16242611] 美颜类型为美肤时支持的美颜强度,-1表明关闭美肤,其余非负值为使用RGB表示的美肤美颜强度,
16242611转化为16进制为0xF7D7B3,F7为R通道值,D7为G通道值,B3位B通道值。

说明: 从 API version 10开始支持,从API version 11开始废弃。建议使用Beauty.getSupportedBeautyRange替代。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type BeautyType 美颜类型。

返回值:

类型 说明
Array<number> 当前美颜类型所支持的美颜强度。

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
7400103 Session not config.
202 Not System Application.

示例:

function getSupportedBeautyRange(captureSession: camera.CaptureSession): Array<number> {
  let beautyTypes: Array<camera.BeautyType> = captureSession.getSupportedBeautyTypes();
  if (beautyTypes === undefined || beautyTypes.length <= 0) {
    return [];
  }
  let beautyLevels: Array<number> = captureSession.getSupportedBeautyRange(beautyTypes[0]);
  return beautyLevels;
}

setBeauty(deprecated)

setBeauty(type: BeautyType, value: number): void

设置美颜类型以及对应的美颜强度。将通过getSupportedBeautyTypes获取得到的BeautyType都关闭,表明当前美颜关闭;若有一种美颜类型未关闭,表明当前美颜打开。

说明: 从 API version 10开始支持,从API version 11开始废弃。建议使用Beauty.setBeauty替代。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type BeautyType 美颜类型 。
value number 美颜强度,通过getSupportedBeautyRange接口获取。

错误码:

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

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

示例:

function setBeauty(captureSession: camera.CaptureSession): void {
  let beautyTypes: Array<camera.BeautyType> = captureSession.getSupportedBeautyTypes();
  if (beautyTypes === undefined || beautyTypes.length <= 0) {
    return;
  }
  let beautyLevels: Array<number> = captureSession.getSupportedBeautyRange(beautyTypes[0]);
  if (beautyLevels === undefined || beautyLevels.length <= 0) {
    return;
  }
  captureSession.setBeauty(beautyTypes[0], beautyLevels[0]);
}

getBeauty(deprecated)

getBeauty(type: BeautyType): number

查询当前已设置的美颜效果对应的美颜强度。

说明: 从 API version 10开始支持,从API version 11开始废弃。建议使用Beauty.getBeauty替代。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type BeautyType 美颜类型。

返回值:

参数名 类型 必填 说明
value number 美颜强度。

错误码:

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

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

示例:

function getBeauty(captureSession: camera.CaptureSession): number {
  const invalidValue: number = -1;
  let beautyTypes: Array<camera.BeautyType> = captureSession.getSupportedBeautyTypes();
  if (beautyTypes === undefined || beautyTypes.length <= 0) {
    return invalidValue;
  }
  let beautyLevels: Array<number> = captureSession.getSupportedBeautyRange(beautyTypes[0]);
  if (beautyLevels === undefined || beautyLevels.length <= 0) {
    return invalidValue;
  }
  captureSession.setBeauty(beautyTypes[0], beautyLevels[0]);
  let beautyLevel: number = captureSession.getBeauty(beautyTypes[0]);
  return beautyLevel;
}

PhotoSessionForSys11+

PhotoSessionForSys extends PhotoSession, Beauty, ColorEffect, ColorManagement, Macro, SceneDetection, EffectSuggestion, DepthFusion

提供给系统应用的PhotoSession,普通拍照模式会话类,继承自Session,用于设置普通拍照模式的参数以及保存所需要的所有资源CameraInputCameraOutput

系统接口: 此接口为系统接口。

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

PhotoSession11+

PhotoSession extends Session, Flash, AutoExposure, Focus, Zoom, ColorManagement

普通拍照模式会话类,继承自Session,用于设置普通拍照模式的参数以及保存所需要的所有资源CameraInputCameraOutput

on('featureDetection')12+

on(type: 'featureDetection', featureType: SceneFeatureType, callback: AsyncCallback<SceneFeatureDetectionResult>): void

监听相机特性检测状态变化。使用callback异步回调。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'featureDetection',photoSession创建成功可监听。
featureType SceneFeatureType 监听指定特性。
callback AsyncCallback<SceneFeatureDetectionResult> 回调函数,用于获取当前监听的特性的状态。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

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

function callback(err: BusinessError, result: camera.SceneFeatureDetectionResult): void {
  if (err !== undefined && err.code !== 0) {
    console.error(`Callback Error, errorCode: ${err.code}`);
    return;
  }
  console.info(`feature type: ${result.featureType}`);
  console.info(`feature status: ${result.detected}`);
}

function registerFeatureDetectionStatus(photoSession: camera.PhotoSession, featureType: camera.SceneFeatureType): void {
  photoSession.on('featureDetection', featureType, callback);
}

off('featureDetection')12+

off(type: 'featureDetection', featureType: SceneFeatureType, callback?: AsyncCallback<SceneFeatureDetectionResult>): void

注销监听相机特性检测状态变化。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'featureDetection',session创建成功可取消监听。
featureType SceneFeatureType 指定特性。
callback AsyncCallback<SceneFeatureDetectionResult> 回调函数,可选,有就是匹配on('featureDetection') callback(callback对象不可是匿名函数)。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

function unregisterFeatureDetectionStatus(photoSession: camera.PhotoSession, featureType: camera.SceneFeatureType): void {
  photoSession.off('featureDetection', featureType);
}

on('lcdFlashStatus')13+

on(type: 'lcdFlashStatus', callback: AsyncCallback<LcdFlashStatus>): void

监听LCD闪光灯状态变化。使用callback异步回调。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'lcdFlashStatus',session创建成功可监听。
callback AsyncCallback<LcdFlashStatus> 回调函数,用于获取当前lcd flash状态。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

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

function callback(err: BusinessError, lcdFlashStatus: camera.LcdFlashStatus): void {
  if (err !== undefined && err.code !== 0) {
    console.error(`Callback Error, errorCode: ${err.code}`);
    return;
  }
  console.info(`isLcdFlashNeeded: ${lcdFlashStatus.isLcdFlashNeeded}`);
  console.info(`lcdCompensation: ${lcdFlashStatus.lcdCompensation}`);
}

function registerLcdFlashStatus(photoSession: camera.PhotoSession): void {
  photoSession.on('lcdFlashStatus', callback);
}

off('lcdFlashStatus')13+

off(type: 'lcdFlashStatus', callback?: AsyncCallback<LcdFlashStatus>): void

注销监听LCD闪光灯状态变化。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'lcdFlashStatus',session创建成功可取消监听。
callback AsyncCallback<LcdFlashStatus> 回调函数,可选,有就是匹配on('lcdFlashStatus') callback(callback对象不可是匿名函数)。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

function unregisterLcdFlashStatus(photoSession: camera.PhotoSession): void {
  photoSession.off('lcdFlashStatus');
}

FocusTrackingMode15+

枚举,对焦追踪模式。

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

名称 说明
AUTO 0 自动。

FocusTrackingInfo15+

相机对焦追踪信息,通过VideoSessionForSys.on('focusTrackingInfoAvailable')接口获取。

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

名称 类型 只读 可选 说明
trackingMode FocusTrackingMode 跟踪模式。
trackingRegion Rect 跟踪区域。

LightStatus18+

枚举,相机光线状态(通过VideoSessionForSys.on('lightStatusChange')接口获取)。

系统接口: 此接口为系统接口。

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

名称 说明
NORMAL 0 光线正常。
INSUFFICIENT 1 光线偏暗。

VideoSessionForSys11+

VideoSessionForSys extends VideoSession, Beauty, ColorEffect, ColorManagement, Aperture, ColorReservation

提供给系统应用的VideoSession,普通录像模式会话类,继承自Session,用于设置普通录像模式的参数以及保存所需要的所有资源CameraInputCameraOutput

系统接口: 此接口为系统接口。

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

VideoSession11+

VideoSession extends Session, Flash, AutoExposure, Focus, Zoom, Stabilization, ColorManagement

普通录像模式会话类,继承自Session,用于设置普通录像模式的参数以及保存所需要的所有资源CameraInputCameraOutput

on('lcdFlashStatus')13+

on(type: 'lcdFlashStatus', callback: AsyncCallback<LcdFlashStatus>): void

监听LCD闪光灯状态变化。使用callback异步回调。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'lcdFlashStatus',session创建成功可监听。
callback AsyncCallback<LcdFlashStatus> 回调函数,用于获取当前lcd flash状态。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

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

function callback(err: BusinessError, lcdFlashStatus: camera.LcdFlashStatus): void {
  if (err !== undefined && err.code !== 0) {
    console.error(`Callback Error, errorCode: ${err.code}`);
    return;
  }
  console.info(`isLcdFlashNeeded: ${lcdFlashStatus.isLcdFlashNeeded}`);
  console.info(`lcdCompensation: ${lcdFlashStatus.lcdCompensation}`);
}

function registerLcdFlashStatus(videoSession: camera.VideoSession): void {
  videoSession.on('lcdFlashStatus', callback);
}

off('lcdFlashStatus')13+

off(type: 'lcdFlashStatus', callback?: AsyncCallback<LcdFlashStatus>): void

注销监听LCD闪光灯状态变化。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'lcdFlashStatus',session创建成功可取消监听。
callback AsyncCallback<LcdFlashStatus> 回调函数,可选,有就是匹配on('lcdFlashStatus') callback(callback对象不可是匿名函数)。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

function unregisterLcdFlashStatus(videoSession: camera.VideoSession): void {
  videoSession.off('lcdFlashStatus');
}

on('focusTrackingInfoAvailable')15+

on(type: 'focusTrackingInfoAvailable', callback: Callback<FocusTrackingInfo>): void

监听相机对焦跟踪信息,通过注册回调函数获取结果。使用callback方式返回结果。

系统接口: 此接口为系统接口。

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

参数

参数名 类型 必填 说明
type string 监听事件,固定为'focusTrackingInfoAvailable',VideoSessionForSys创建成功可监听。
callback Callback<FocusTrackingInfo> 回调函数,用于获取当前对焦跟踪信息。

错误码

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例

function callback(focusTrackingInfo: camera.FocusTrackingInfo): void {
  console.info(`Focus tracking mode: ${focusTrackingInfo.trackingMode}`);
  console.info(`Focus tracking Region: topLeftX ${focusTrackingInfo.trackingRegion.topLeftX}
                                       topLeftY ${focusTrackingInfo.trackingRegion.topLeftY}
                                       width ${focusTrackingInfo.trackingRegion.width}
                                       height ${focusTrackingInfo.trackingRegion.height}`);
}

function registerFocusTrackingInfoChanged(session: camera.VideoSessionForSys): void {
  session.on('focusTrackingInfoAvailable', callback);
}

off('focusTrackingInfoAvailable')15+

off(type: 'focusTrackingInfoAvailable', callback?: Callback<FocusTrackingInfo>): void

注销监听相机对焦跟踪信息。

系统接口: 此接口为系统接口。

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

参数

参数名 类型 必填 说明
type string 监听事件,固定为'focusTrackingInfoAvailable',videoSessionForSys创建成功可监听。
callback Callback<FocusTrackingInfo> 回调函数,可选,有就是匹配on('focusTrackingInfoAvailable') callback(callback对象不可是匿名函数)。

错误码

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例

function unregisterFocusTrackingInfoChanged(session: camera.VideoSessionForSys): void {
  session.off('focusTrackingInfoAvailable');
}

on('lightStatusChange')18+

on(type: 'lightStatusChange', callback: AsyncCallback<LightStatus>): void

监听相机获取光线状态。使用Callback方式返回结果。

系统接口: 此接口为系统接口。

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

参数

参数名 类型 必填 说明
type string 监听事件,固定为'lightStatusChange'。
'lightStatusChange':VideoSessionForSys创建成功时可监听。
callback AsyncCallback<LightStatus> 回调函数,用于获取当前光线状态信息。

错误码

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例

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

function handleLightStatusCallback(err: BusinessError, lightStatus: camera.LightStatus) : void {
  if (err !== undefined && err.code !== 0) {
    console.error(`Callback Error, errorCode: ${err.code}`);
    return;
  }
  console.info(`lightStatus: ${lightStatus}`);
}

function handleLightStatusOn(mSession: camera.VideoSessionForSys): void {
  console.info('handleLightStatusOn');
  try {
    mSession.on('lightStatusChange', handleLightStatusCallback);
  } catch (error) {
    let err = error as BusinessError;
    console.error(`handleLightStatusOn err:${err}`);
  }
}

off('lightStatusChange')18+

off(type: 'lightStatusChange', callback?: AsyncCallback<LightStatus>): void

注销监听相机获取光线状态。

系统接口: 此接口为系统接口。

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

参数

参数名 类型 必填 说明
type string 监听事件,固定为'lightStatusChange'。
'lightStatusChange':当VideoSessionForSys创建成功时,可监听。
callback AsyncCallback<LightStatus> 回调函数,可选,有就是匹配on('lightStatusChange') callback(callback对象不可是匿名函数)。

错误码

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例

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

function LightStatusCallback(err: BusinessError, lightStatus: camera.LightStatus) : void {
  if (err !== undefined && err.code !== 0) {
    console.error(`Callback Error, errorCode: ${err.code}`);
    return;
  }
  console.info(`lightStatus: ${lightStatus}`);
}

function handleLightStatusOff(mSession: camera.VideoSessionForSys): void {
  console.info('handleLightStatusOff');
  try {
    mSession.on('lightStatusChange', LightStatusCallback);
  } catch (error) {
    let err = error as BusinessError;
    console.error(`handleLightStatusOff err:${err}`);
  }
}

PortraitPhotoSession11+

PortraitPhotoSession extends Session, Flash, AutoExposure, Focus, Zoom, Beauty, ColorEffect, ColorManagement, Portrait, Aperture

人像拍照模式会话类,继承自Session,用于设置人像拍照模式的参数以及保存所需要的所有资源CameraInputCameraOutput

on('error')11+

on(type: 'error', callback: ErrorCallback): void

监听人像拍照会话的错误事件,通过注册回调函数获取结果。使用callback异步回调。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'error',session创建成功之后可监听该接口。session调用相关接口出现错误时会触发该事件,比如调用beginConfigcommitConfigaddInput等接口发生错误时返回错误信息。
callback ErrorCallback 回调函数,用于获取错误信息。返回错误码,错误码类型CameraErrorCode

示例:

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

function callback(err: BusinessError): void {
  console.error(`Portrait photo session error code: ${err.code}`);
}

function registerSessionError(portraitPhotoSession: camera.PortraitPhotoSession): void {
  portraitPhotoSession.on('error', callback);
}

off('error')11+

off(type: 'error', callback?: ErrorCallback): void

注销监听人像拍照会话的错误事件,通过注册回调函数获取结果。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'error',session创建成功之后可监听该接口。
callback ErrorCallback 回调函数,可选,有就是匹配on('error') callback(callback对象不可是匿名函数)。

示例:

function unregisterSessionError(portraitPhotoSession: camera.PortraitPhotoSession): void {
  portraitPhotoSession.off('error');
}

on('focusStateChange')11+

on(type: 'focusStateChange', callback: AsyncCallback<FocusState>): void

监听相机对焦的状态变化,通过注册回调函数获取结果。使用callback异步回调。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'focusStateChange',session创建成功可监听。仅当自动对焦模式时,且相机对焦状态发生改变时可触发该事件。
callback AsyncCallback<FocusState> 回调函数,用于获取当前对焦状态。

示例:

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

function callback(err: BusinessError, focusState: camera.FocusState): void {
  if (err !== undefined && err.code !== 0) {
    console.error(`Callback Error, errorCode: ${err.code}`);
    return;
  }
  console.info(`Focus state: ${focusState}`);
}

function registerFocusStateChange(portraitPhotoSession: camera.PortraitPhotoSession): void {
  portraitPhotoSession.on('focusStateChange', callback);
}

off('focusStateChange')11+

off(type: 'focusStateChange', callback?: AsyncCallback<FocusState>): void

注销监听相机对焦的状态变化。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'focusStateChange',session创建成功可监听。
callback AsyncCallback<FocusState> 回调函数,可选,有就是匹配on('focusStateChange') callback(callback对象不可是匿名函数)。

示例:

function unregisterFocusStateChange(portraitPhotoSession: camera.PortraitPhotoSession): void {
  portraitPhotoSession.off('focusStateChange');
}

on('smoothZoomInfoAvailable')11+

on(type: 'smoothZoomInfoAvailable', callback: AsyncCallback<SmoothZoomInfo>): void

监听相机平滑变焦的状态变化,通过注册回调函数获取结果。使用callback异步回调。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'smoothZoomInfoAvailable',session创建成功可监听。
callback AsyncCallback<SmoothZoomInfo> 回调函数,用于获取当前平滑变焦状态。

示例:

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

function callback(err: BusinessError, smoothZoomInfo: camera.SmoothZoomInfo): void {
  if (err !== undefined && err.code !== 0) {
    console.error(`Callback Error, errorCode: ${err.code}`);
    return;
  }
  console.info(`The duration of smooth zoom: ${smoothZoomInfo.duration}`);
}

function registerSmoothZoomInfo(portraitPhotoSession: camera.PortraitPhotoSession): void {
  portraitPhotoSession.on('smoothZoomInfoAvailable', callback);
}

off('smoothZoomInfoAvailable')11+

off(type: 'smoothZoomInfoAvailable', callback?: AsyncCallback<SmoothZoomInfo>): void

注销监听相机平滑变焦的状态变化。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'smoothZoomInfoAvailable',session创建成功可监听。
callback AsyncCallback<SmoothZoomInfo> 回调函数,可选,有就是匹配on('smoothZoomInfoAvailable') callback(callback对象不可是匿名函数)。

示例:

function unregisterSmoothZoomInfo(portraitPhotoSession: camera.PortraitPhotoSession): void {
  portraitPhotoSession.off('smoothZoomInfoAvailable');
}

on('lcdFlashStatus')13+

on(type: 'lcdFlashStatus', callback: AsyncCallback<LcdFlashStatus>): void

监听LCD闪光灯状态变化。使用callback异步回调。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'lcdFlashStatus',session创建成功可监听。
callback AsyncCallback<LcdFlashStatus> 回调函数,用于获取当前lcd flash状态。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

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

function callback(err: BusinessError, lcdFlashStatus: camera.LcdFlashStatus): void {
  if (err !== undefined && err.code !== 0) {
    console.error(`Callback Error, errorCode: ${err.code}`);
    return;
  }
  console.info(`isLcdFlashNeeded: ${lcdFlashStatus.isLcdFlashNeeded}`);
  console.info(`lcdCompensation: ${lcdFlashStatus.lcdCompensation}`);
}

function registerLcdFlashStatus(portraitPhotoSession: camera.PortraitPhotoSession): void {
  portraitPhotoSession.on('lcdFlashStatus', callback);
}

off('lcdFlashStatus')13+

off(type: 'lcdFlashStatus', callback?: AsyncCallback<LcdFlashStatus>): void

注销监听LCD闪光灯状态变化。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'lcdFlashStatus',session创建成功可取消监听。
callback AsyncCallback<LcdFlashStatus> 回调函数,可选,有就是匹配on('lcdFlashStatus') callback(callback对象不可是匿名函数)。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

function unregisterLcdFlashStatus(portraitPhotoSession: camera.PortraitPhotoSession): void {
  portraitPhotoSession.off('lcdFlashStatus');
}

NightPhotoSession11+

NightPhotoSession extends Session, Flash, AutoExposure, Focus, Zoom, ColorEffect, ColorManagement, ManualExposure

夜景拍照模式会话类,继承自Session,用于设置夜景拍照模式的参数以及保存所需要的所有资源CameraInputCameraOutputPhotoOutput

夜景拍照需要监听拍照结束事件on('captureEnd')作为一次拍照的结束。

on('error')11+

on(type: 'error', callback: ErrorCallback): void

监听夜景拍照会话的错误事件,通过注册回调函数获取结果。使用callback异步回调。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'error',session创建成功之后可监听该接口。session调用相关接口出现错误时会触发该事件,比如调用beginConfigcommitConfigaddInput等接口发生错误时返回错误信息。
callback ErrorCallback 回调函数,用于获取错误信息。返回错误码,错误码类型CameraErrorCode

示例:

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

function callback(err: BusinessError): void {
  console.error(`Night photo session error code: ${err.code}`);
}

function registerSessionError(nightPhotoSession: camera.NightPhotoSession): void {
  nightPhotoSession.on('error', callback);
}

off('error')11+

off(type: 'error', callback?: ErrorCallback): void

注销监听夜景拍照会话的错误事件,通过注册回调函数获取结果。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'error',session创建成功之后可监听该接口。
callback ErrorCallback 回调函数,可选,有就是匹配on('error') callback(callback对象不可是匿名函数)。

示例:

function unregisterSessionError(nightPhotoSession: camera.NightPhotoSession): void {
  nightPhotoSession.off('error');
}

on('focusStateChange')11+

on(type: 'focusStateChange', callback: AsyncCallback<FocusState>): void

监听相机对焦的状态变化,通过注册回调函数获取结果。使用callback异步回调。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'focusStateChange',session创建成功可监听。仅当自动对焦模式时,且相机对焦状态发生改变时可触发该事件。
callback AsyncCallback<FocusState> 回调函数,用于获取当前对焦状态。

示例:

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

function callback(err: BusinessError, focusState: camera.FocusState): void {
  if (err !== undefined && err.code !== 0) {
    console.error(`Callback Error, errorCode: ${err.code}`);
    return;
  }
  console.info(`Focus state: ${focusState}`);
}

function registerFocusStateChange(nightPhotoSession: camera.NightPhotoSession): void {
  nightPhotoSession.on('focusStateChange', callback);
}

off('focusStateChange')11+

off(type: 'focusStateChange', callback?: AsyncCallback<FocusState>): void

注销监听相机对焦的状态变化。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'focusStateChange',session创建成功可监听。
callback AsyncCallback<FocusState> 回调函数,可选,有就是匹配on('focusStateChange') callback(callback对象不可是匿名函数)。

示例:

function unregisterFocusStateChange(nightPhotoSession: camera.NightPhotoSession): void {
  nightPhotoSession.off('focusStateChange');
}

on('smoothZoomInfoAvailable')11+

on(type: 'smoothZoomInfoAvailable', callback: AsyncCallback<SmoothZoomInfo>): void

监听相机平滑变焦的状态变化,通过注册回调函数获取结果。使用callback异步回调。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'smoothZoomInfoAvailable',session创建成功可监听。
callback AsyncCallback<SmoothZoomInfo> 回调函数,用于获取当前平滑变焦状态。

示例:

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

function callback(err: BusinessError, smoothZoomInfo: camera.SmoothZoomInfo): void {
  if (err !== undefined && err.code !== 0) {
    console.error(`Callback Error, errorCode: ${err.code}`);
    return;
  }
  console.info(`The duration of smooth zoom: ${smoothZoomInfo.duration}`);
}

function registerSmoothZoomInfo(nightPhotoSession: camera.NightPhotoSession): void {
  nightPhotoSession.on('smoothZoomInfoAvailable', callback);
}

off('smoothZoomInfoAvailable')11+

off(type: 'smoothZoomInfoAvailable', callback?: AsyncCallback<SmoothZoomInfo>): void

注销监听相机平滑变焦的状态变化。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'smoothZoomInfoAvailable',session创建成功可监听。
callback AsyncCallback<SmoothZoomInfo> 回调函数,可选,有就是匹配on('smoothZoomInfoAvailable') callback(callback对象不可是匿名函数)。

示例:

function unregisterSmoothZoomInfo(nightPhotoSession: camera.NightPhotoSession): void {
  nightPhotoSession.off('smoothZoomInfoAvailable');
}

on('lcdFlashStatus')12+

on(type: 'lcdFlashStatus', callback: AsyncCallback<LcdFlashStatus>): void

监听lcd flash状态,通过注册回调函数获取结果。使用callback异步回调。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'lcdFlashStatus',session创建成功可监听。
callback AsyncCallback<LcdFlashStatus> 回调函数,用于获取当前lcd flash状态。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

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

function callback(err: BusinessError, lcdFlashStatus: camera.LcdFlashStatus): void {
  if (err !== undefined && err.code !== 0) {
    console.error(`Callback Error, errorCode: ${err.code}`);
    return;
  }
  console.info(`lcdFlashStatus: ${lcdFlashStatus}`);
}

function registerLcdFlashStatus(nightPhotoSession: camera.NightPhotoSession): void {
  nightPhotoSession.on('lcdFlashStatus', callback);
}

off('lcdFlashStatus')12+

off(type: 'lcdFlashStatus', callback?: AsyncCallback<LcdFlashStatus>): void

注销lcd flash状态,通过注册回调函数获取结果。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'lcdFlashStatus',session创建成功可监听。
callback AsyncCallback<LcdFlashStatus> 回调函数,可选,有就是匹配on('lcdFlashStatus') callback(callback对象不可是匿名函数)。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

function unregisterLcdFlashStatus(nightPhotoSession: camera.NightPhotoSession): void {
  nightPhotoSession.off('lcdFlashStatus');
}

HighResolutionPhotoSession12+

HighResolutionPhotoSession extends Session, AutoExposure, Focus

高像素拍照模式会话类,继承自Session,用于设置高像素拍照模式的参数以及保存所需要的所有资源CameraInputCameraOutput

说明:

高像素拍照场景下,需要使用物理镜头,不可以使用逻辑镜头。

on('error')12+

on(type: 'error', callback: ErrorCallback): void

监听高像素拍照会话的错误事件,通过注册回调函数获取结果。使用callback异步回调。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'error',session创建成功之后可监听该接口。session调用相关接口出现错误时会触发该事件,比如调用beginConfigcommitConfigaddInput等接口发生错误时返回错误信息。
callback ErrorCallback 回调函数,用于获取错误信息。返回错误码,错误码类型CameraErrorCode

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

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

function callback(err: BusinessError): void {
  console.error(`High resolution photo session error code: ${err.code}`);
}

function registerSessionError(highResolutionPhotoSession: camera.HighResolutionPhotoSession): void {
  highResolutionPhotoSession.on('error', callback);
}

off('error')12+

off(type: 'error', callback?: ErrorCallback): void

注销监听高像素拍照会话的错误事件,通过注册回调函数获取结果。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'error',session创建成功之后可监听该接口。
callback ErrorCallback 回调函数,可选,有就是匹配on('error') callback(callback对象不可是匿名函数)。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

function unregisterSessionError(highResolutionPhotoSession: camera.HighResolutionPhotoSession): void {
  highResolutionPhotoSession.off('error');
}

on('focusStateChange')12+

on(type: 'focusStateChange', callback: AsyncCallback<FocusState>): void

监听相机对焦的状态变化,通过注册回调函数获取结果。使用callback异步回调。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'focusStateChange',session创建成功可监听。仅当自动对焦模式时,且相机对焦状态发生改变时可触发该事件。
callback AsyncCallback<FocusState> 回调函数,用于获取当前对焦状态。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

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

function callback(err: BusinessError, focusState: camera.FocusState): void {
  if (err !== undefined && err.code !== 0) {
    console.error(`Callback Error, errorCode: ${err.code}`);
    return;
  }
  console.info(`Focus state: ${focusState}`);
}

function registerFocusStateChange(highResolutionPhotoSession: camera.HighResolutionPhotoSession): void {
  highResolutionPhotoSession.on('focusStateChange', callback);
}

off('focusStateChange')12+

off(type: 'focusStateChange', callback?: AsyncCallback<FocusState>): void

注销监听相机对焦的状态变化。

系统接口: 此接口为系统接口。

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

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'focusStateChange',session创建成功可监听。
callback AsyncCallback<FocusState> 回调函数,可选,有就是匹配on('focusStateChange') callback(callback对象不可是匿名函数)。

示例:

function unregisterFocusStateChange(highResolutionPhotoSession: camera.HighResolutionPhotoSession): void {
  highResolutionPhotoSession.off('focusStateChange');
}

SketchStatusData11+

画中画状态返回数据。

系统接口: 此接口为系统接口。

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

名称 类型 只读 可选 说明
status number 画中画当前的状态。0:已停止,1:已启动,2:停止中,3:启动中。
sketchRatio number 画中画画面的Zoom倍率。
centerPointOffset20+ Point 画中画的偏移点。

SlowMotionVideoSession12+

SlowMotionVideoSession extends Session, Flash, AutoExposure, Focus, Zoom, ColorEffect

慢动作录像模式会话类,继承自Session,用于设置慢动作录像模式的参数以及保存所需要的所有资源CameraInputCameraOutput

说明: 慢动作模式下只能添加预览流和录像流。

on('error')12+

on(type: 'error', callback: ErrorCallback): void

监听慢动作录像模式会话的错误事件,通过注册回调函数获取结果。使用callback异步回调。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'error',session创建成功之后可监听该接口。session调用相关接口出现错误时会触发该事件,比如调用beginConfigcommitConfigaddInput等接口发生错误时返回错误信息。
callback ErrorCallback 回调函数,用于获取错误信息。返回错误码,错误码类型CameraErrorCode

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

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

function callback(err: BusinessError): void {
  console.error(`Portrait photo session error code: ${err.code}`);
}

function registerSessionError(slowMotionVideoSession: camera.SlowMotionVideoSession): void {
  slowMotionVideoSession.on('error', callback);
}

off('error')12+

off(type: 'error', callback?: ErrorCallback): void

注销慢动作录像模式会话的错误事件,通过注册回调函数获取结果。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'error',session创建成功之后可监听该接口。
callback ErrorCallback 回调函数,可选,有就是匹配on('error') callback(callback对象不可是匿名函数)。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

function unregisterSessionError(slowMotionVideoSession: camera.SlowMotionVideoSession): void {
  slowMotionVideoSession.off('error');
}

on('focusStateChange')12+

on(type: 'focusStateChange', callback: AsyncCallback<FocusState>): void

监听相机对焦的状态变化,通过注册回调函数获取结果。使用callback异步回调。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'focusStateChange',session创建成功可监听。仅当自动对焦模式时,且相机对焦状态发生改变时可触发该事件。
callback AsyncCallback<FocusState> 回调函数,用于获取当前对焦状态。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

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

function callback(err: BusinessError, focusState: camera.FocusState): void {
  if (err !== undefined && err.code !== 0) {
    console.error(`Callback Error, errorCode: ${err.code}`);
    return;
  }
  console.info(`Focus state: ${focusState}`);
}

function registerFocusStateChange(slowMotionVideoSession: camera.SlowMotionVideoSession): void {
  slowMotionVideoSession.on('focusStateChange', callback);
}

off('focusStateChange')12+

off(type: 'focusStateChange', callback?: AsyncCallback<FocusState>): void

注销监听相机对焦的状态变化。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'focusStateChange',session创建成功可监听。
callback AsyncCallback<FocusState> 回调函数,可选,有就是匹配on('focusStateChange') callback(callback对象不可是匿名函数)。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

function unregisterFocusStateChange(slowMotionVideoSession: camera.SlowMotionVideoSession): void {
  slowMotionVideoSession.off('focusStateChange');
}

on('smoothZoomInfoAvailable')12+

on(type: 'smoothZoomInfoAvailable', callback: AsyncCallback<SmoothZoomInfo>): void

监听相机平滑变焦的状态变化,通过注册回调函数获取结果。使用callback异步回调。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'smoothZoomInfoAvailable',session创建成功可监听。
callback AsyncCallback<SmoothZoomInfo> 回调函数,用于获取当前平滑变焦状态。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

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

function callback(err: BusinessError, smoothZoomInfo: camera.SmoothZoomInfo): void {
  if (err !== undefined && err.code !== 0) {
    console.error(`Callback Error, errorCode: ${err.code}`);
    return;
  }
  console.info(`The duration of smooth zoom: ${smoothZoomInfo.duration}`);
}

function registerSmoothZoomInfo(slowMotionVideoSession: camera.SlowMotionVideoSession): void {
  slowMotionVideoSession.on('smoothZoomInfoAvailable', callback);
}

off('smoothZoomInfoAvailable')12+

off(type: 'smoothZoomInfoAvailable', callback?: AsyncCallback<SmoothZoomInfo>): void

注销监听相机平滑变焦的状态变化。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'smoothZoomInfoAvailable',session创建成功可监听。
callback AsyncCallback<SmoothZoomInfo> 回调函数,可选,有就是匹配on('smoothZoomInfoAvailable') callback(callback对象不可是匿名函数)。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

function unregisterSmoothZoomInfo(slowMotionVideoSession: camera.SlowMotionVideoSession): void {
  slowMotionVideoSession.off('smoothZoomInfoAvailable');
}

on('slowMotionStatus')12+

on(type: 'slowMotionStatus', callback: AsyncCallback<SlowMotionStatus>): void

监听慢动作状态变化,通过注册回调函数获取结果。使用callback异步回调。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'slowMotionStatus',session创建成功可监听。
callback AsyncCallback<SlowMotionStatus> 回调函数,用于获取当前慢动作状态。当慢动作状态发生变动时,此回调函数也会被执行。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

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

function callback(err: BusinessError, slowMotionStatus: camera.SlowMotionStatus): void {
  if (err !== undefined && err.code !== 0) {
    console.error(`Callback Error, errorCode: ${err.code}`);
    return;
  }
  console.info(`The slow motion status: ${slowMotionStatus}`);
}

function registerSlowMotionStatus(slowMotionVideoSession: camera.SlowMotionVideoSession): void {
  slowMotionVideoSession.on('slowMotionStatus', callback);
}

off('slowMotionStatus')12+

off(type: 'slowMotionStatus', callback?: AsyncCallback<SlowMotionStatus>): void

注销慢动作状态变化。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'slowMotionStatus',session创建成功可监听。
callback AsyncCallback<SlowMotionStatus> 回调函数,可选,有就是匹配on('slowMotionStatus') callback(callback对象不可是匿名函数)。接口调用失败会返回相应错误码,错误码类型CameraErrorCode

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

function unregisterSlowMotionStatus(slowMotionVideoSession: camera.SlowMotionVideoSession): void {
  slowMotionVideoSession.off('slowMotionStatus');
}

isSlowMotionDetectionSupported12+

isSlowMotionDetectionSupported(): boolean

查询当前设备是否支持慢动作检测功能。

说明: 该接口需要在commitConfig之后调用。

系统接口: 此接口为系统接口。

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

返回值:

类型 说明
boolean 返回true表示支持慢动作检测功能,false表示不支持。接口调用失败会返回相应错误码,错误码类型CameraErrorCode

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

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

function isSlowMotionDetectionSupported(slowMotionVideoSession: camera.SlowMotionVideoSession): boolean {
  let isSupported: boolean = false;
  try {
    isSupported = slowMotionVideoSession.isSlowMotionDetectionSupported();
  } catch (error) {
    // 失败返回错误码error.code并处理。
    let err = error as BusinessError;
    console.error(`The isFocusModeSupported call failed. error code: ${err.code}`);
  }
  return isSupported;
}

setSlowMotionDetectionArea12+

setSlowMotionDetectionArea(area: Rect): void

设置一个进行慢动作检测的区域。

说明: 在调用该方法之前,先调用isSlowMotionDetectionSupported确认设备是否支持慢动作检测功能, 才能保证其他相关方法的正常运行。 该接口需要在commitConfig之后调用。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
area Rect 矩形定义。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

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

function setSlowMotionDetectionArea(slowMotionVideoSession: camera.SlowMotionVideoSession): void {
  try {
    slowMotionVideoSession.setSlowMotionDetectionArea({topLeftX: 0.1, topLeftY: 0.1, width: 0.8, height: 0.8});
  } catch (error) {
    // 失败返回错误码error.code并处理。
    let err = error as BusinessError;
    console.error(`The setSlowMotionDetectionArea call failed. error code: ${err.code}`);
  }
}

PanoramaPhotoSession12+

PanoramaPhotoSession extends Session, Focus, AutoExposure, WhiteBalance, ColorEffect

全景拍照模式会话类,继承自Session,用于设置全景拍照模式的参数以及保存所需要的所有资源CameraInputCameraOutput

on('error')12+

on(type: 'error', callback: ErrorCallback): void

监听全景拍照会话的错误事件,通过注册回调函数获取结果。使用callback异步回调。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'error',session创建成功之后可监听该接口。session调用相关接口出现错误时会触发该事件,比如调用beginConfigcommitConfigaddInput等接口发生错误时返回错误信息。
callback ErrorCallback 回调函数,用于获取错误信息。返回错误码,错误码类型CameraErrorCode

示例:

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

function callback(err: BusinessError): void {
  console.error(`Panorama photo session error code: ${err.code}`);
}

function registerSessionError(panoramaPhotoSession: camera.PanoramaPhotoSession): void {
  panoramaPhotoSession.on('error', callback);
}

off('error')12+

off(type: 'error', callback?: ErrorCallback): void

注销监听全景拍照会话的错误事件,通过注册回调函数获取结果。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'error',session创建成功之后可监听该接口。
callback ErrorCallback 回调函数,可选,有就是匹配on('error') callback(callback对象不可是匿名函数)。

示例:

function unregisterSessionError(panoramaPhotoSession: camera.PanoramaPhotoSession): void {
  panoramaPhotoSession.off('error');
}

on('focusStateChange')12+

on(type: 'focusStateChange', callback: AsyncCallback<FocusState>): void

监听相机对焦的状态变化,通过注册回调函数获取结果。使用callback异步回调。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'focusStateChange',session创建成功可监听。仅当自动对焦模式时,且相机对焦状态发生改变时可触发该事件。
callback AsyncCallback<FocusState> 回调函数,用于获取当前对焦状态。

示例:

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

function callback(err: BusinessError, focusState: camera.FocusState): void {
  if (err !== undefined && err.code !== 0) {
    console.error(`Callback Error, errorCode: ${err.code}`);
    return;
  }
  console.info(`Focus state: ${focusState}`);
}

function registerFocusStateChange(panoramaPhotoSession: camera.PanoramaPhotoSession): void {
  panoramaPhotoSession.on('focusStateChange', callback);
}

off('focusStateChange')12+

off(type: 'focusStateChange', callback?: AsyncCallback<FocusState>): void

注销监听相机对焦的状态变化。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'focusStateChange',session创建成功可监听。
callback AsyncCallback<FocusState> 回调函数,可选,有就是匹配on('focusStateChange') callback(callback对象不可是匿名函数)。

示例:

function unregisterFocusStateChange(panoramaPhotoSession: camera.PanoramaPhotoSession): void {
  panoramaPhotoSession.off('focusStateChange');
}

IsoInfo12+

ISO参数信息。

系统接口: 此接口为系统接口。

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

名称 类型 只读 可选 说明
iso number ISO值。

ApertureInfo12+

光圈参数信息。

系统接口: 此接口为系统接口。

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

名称 类型 只读 可选 说明
aperture number 光圈值。

LuminationInfo12+

光照参数信息。

系统接口: 此接口为系统接口。

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

名称 类型 只读 可选 说明
lumination number 范围[0, 1],光照值归一化数值。

ExposureMeteringMode12+

枚举,测光模式。

系统接口: 此接口为系统接口。

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

名称 说明
CENTER_HIGHLIGHT_WEIGHTED 3 中心高光加权测光模式。专注于屏幕中心附近的高光区域。

FocusRangeType15+

枚举,对焦范围类型。

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

名称 说明
AUTO 0 自动对焦。
NEAR 1 近物对焦。

FocusDrivenType15+

枚举,对焦驱动类型。

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

名称 说明
AUTO 0 自动。
FACE 1 人脸驱动。

FocusQuery12+

提供了查询是否支持对焦辅助的方法。

isFocusAssistSupported12+

isFocusAssistSupported(): boolean

检测是否支持对焦辅助灯。

系统接口: 此接口为系统接口。

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

返回值:

类型 说明
boolean 返回true表示支持对焦辅助灯,false表示不支持。接口调用失败会返回相应错误码,错误码类型CameraErrorCode

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
7400103 Session not config, only throw in session usage.
202 Not System Application.

示例:

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

function isFocusAssistSupported(professionalPhotoSession: camera.ProfessionalPhotoSession): boolean {
  let status: boolean = false;
  try {
    status = professionalPhotoSession.isFocusAssistSupported();
  } catch (error) {
    // 失败返回错误码error.code并处理。
    let err = error as BusinessError;
    console.error(`The isFocusAssistSupported call failed. error code: ${err.code}`);
  }
  return status;
}

isFocusRangeTypeSupported15+

isFocusRangeTypeSupported(type: FocusRangeType): boolean

查询是否支持指定的对焦范围类型。

系统接口: 此接口为系统接口。

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

参数

参数名 类型 必填 说明
type FocusRangeType 指定对应的对焦范围类型。

返回值

类型 说明
boolean 返回true表示支持指定的对焦范围类型,false表示不支持。接口调用失败会返回相应错误码,错误码类型CameraErrorCode

错误码

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
202 Not System Application.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.
7400103 Session not config, only throw in session usage.

示例

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

function isFocusRangeTypeSupported(session: camera.VideoSessionForSys, type: camera.FocusRangeType): boolean {
  let status: boolean = false;
  try {
    status = session.isFocusRangeTypeSupported(type);
  } catch (error) {
    // 失败返回错误码error.code并处理。
    let err = error as BusinessError;
    console.error(`The isFocusRangeTypeSupported call failed. error code: ${err.code}`);
  }
  return status;
}

isFocusDrivenTypeSupported15+

isFocusDrivenTypeSupported(type: FocusDrivenType): boolean

查询是否支持指定的对焦驱动类型。

系统接口: 此接口为系统接口。

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

参数

参数名 类型 必填 说明
type FocusDrivenType 指定对应的对焦驱动类型。

返回值

类型 说明
boolean 返回true表示支持指定的对焦驱动类型,false表示不支持。接口调用失败会返回相应错误码,错误码类型CameraErrorCode

错误码

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
202 Not System Application.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.
7400103 Session not config, only throw in session usage.

示例

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

function isFocusDrivenTypeSupported(session: camera.VideoSessionForSys, type: camera.FocusDrivenType): boolean {
  let status: boolean = false;
  try {
    status = session.isFocusDrivenTypeSupported(type);
  } catch (error) {
    // 失败返回错误码error.code并处理。
    let err = error as BusinessError;
    console.error(`The isFocusDrivenTypeSupported call failed. error code: ${err.code}`);
  }
  return status;
}

Focus

Focus extends FocusQuery

提供了获取和设置相机对焦模式和对焦点位置的方法。

setFocusAssist12+

setFocusAssist(enabled: boolean): void

设置对焦辅助灯。进行设置之前,需要先检查设备是否支持对焦辅助灯,可使用方法isFocusAssistSupported

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
enabled boolean true:开启对焦辅助灯,false:关闭对焦辅助灯。

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
202 Not System Application.
7400101 Parameter missing or parameter type incorrect.
7400103 Session not config.

示例:

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

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

getFocusAssist12+

getFocusAssist(): boolean

获取对焦辅助灯是否开启。

系统接口: 此接口为系统接口。

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

返回值:

类型 说明
boolean 返回true表示相机已打开对焦辅助灯,返回false表示相机已关闭对焦辅助灯。

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
7400103 Session not config.
202 Not System Application.

示例:

function getFocusAssist(professionalPhotoSession: camera.ProfessionalPhotoSession): boolean {
  let isFocusAssistOpened: boolean = false;
  try {
    isFocusAssistOpened = professionalPhotoSession.getFocusAssist();
  } catch (error) {
    // 失败返回错误码error.code并处理。
    let err = error as BusinessError;
    console.error(`The getFocusAssist call failed. error code: ${err.code}`);
  }
  return isFocusAssistOpened;
}

setFocusRange15+

setFocusRange(type: FocusRangeType): void

设置对焦范围类型。进行设置之前,需要先检查设备是否支持指定的对焦范围类型,可使用方法isFocusRangeTypeSupported

系统接口: 此接口为系统接口。

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

参数

参数名 类型 必填 说明
type FocusRangeType 对焦范围类型。

错误码

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
202 Not System Application.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3.Parameter verification failed.
7400102 Operation not allowed.
7400103 Session not config.
7400201 Camera service fatal error.

示例

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

function setFocusRange(session: camera.VideoSessionForSys, type: camera.FocusRangeType): void {
  try {
    session.setFocusRange(type);
  } catch (error) {
    // 失败返回错误码error.code并处理。
    let err = error as BusinessError;
    console.error(`The setFocusRange call failed. error code: ${err.code}`);
  }
}

getFocusRange15+

getFocusRange(): FocusRangeType

获取当前设置的对焦范围类型。

系统接口: 此接口为系统接口。

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

返回值

类型 说明
FocusRangeType 当前设置的对焦范围类型。

错误码

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
202 Not System Application.
7400103 Session not config.

示例

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

function getFocusRange(session: camera.VideoSessionForSys): camera.FocusRangeType | undefined {
  let focusRangeType: camera.FocusRangeType | undefined = undefined;
  try {
    focusRangeType = session.getFocusRange();
  } catch (error) {
    // 失败返回错误码error.code并处理。
    let err = error as BusinessError;
    console.error(`The getFocusRange call failed. error code: ${err.code}`);
  }
  return focusRangeType;
}

setFocusDriven15+

setFocusDriven(type: FocusDrivenType): void

设置对焦驱动类型。进行设置之前,需要先检查设备是否支持指定的对焦驱动类型,可使用方法isFocusDrivenTypeSupported

系统接口: 此接口为系统接口。

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

参数

参数名 类型 必填 说明
type FocusDrivenType 对焦驱动类型。

错误码

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
202 Not System Application.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3.Parameter verification failed.
7400102 Operation not allowed.
7400103 Session not config.
7400201 Camera service fatal error.

示例

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

function setFocusDriven(session: camera.VideoSessionForSys, type: camera.FocusDrivenType): void {
  try {
    session.setFocusDriven(type);
  } catch (error) {
    // 失败返回错误码error.code并处理。
    let err = error as BusinessError;
    console.error(`The setFocusDriven call failed. error code: ${err.code}`);
  }
}

getFocusDriven15+

getFocusDriven(): FocusDrivenType

获取当前设置的对焦驱动类型。

系统接口: 此接口为系统接口。

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

返回值

类型 说明
FocusDrivenType 当前设置的对焦驱动类型。

错误码

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
202 Not System Application.
7400103 Session not config.

示例

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

function getFocusDriven(session: camera.VideoSessionForSys): camera.FocusDrivenType | undefined {
  let focusDrivenType: camera.FocusDrivenType | undefined = undefined;
  try {
    focusDrivenType = session.getFocusDriven();
  } catch (error) {
    // 失败返回错误码error.code并处理。
    let err = error as BusinessError;
    console.error(`The getFocusDriven call failed. error code: ${err.code}`);
  }
  return focusDrivenType;
}

ManualIsoQuery12+

提供了查询设备是否支持手动设置ISO和获取设备支持的ISO范围的方法。

isManualIsoSupported12+

isManualIsoSupported(): boolean

检测是否支持手动ISO。

系统接口: 此接口为系统接口。

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

返回值:

类型 说明
boolean 返回true表示支持手动调节ISO,false表示不支持。接口调用失败会返回相应错误码,错误码类型CameraErrorCode

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
7400103 Session not config, only throw in session usage.
202 Not System Application.

示例:

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

function isManualIsoSupported(professionalPhotoSession: camera.ProfessionalPhotoSession): boolean {
  let status: boolean = false;
  try {
    status = professionalPhotoSession.isManualIsoSupported();
  } catch (error) {
    // 失败返回错误码error.code并处理。
    let err = error as BusinessError;
    console.error(`The isManualIsoSupported call failed. error code: ${err.code}`);
  }
  return status;
}

getIsoRange12+

getIsoRange(): Array<number>

获取支持的ISO范围。

系统接口: 此接口为系统接口。

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

返回值:

类型 说明
Array<number> 用于获取ISO范围,范围为[50, 100, ..., 6400],实际根据底层能力返回为准,接口调用失败会返回相应错误码,错误码类型CameraErrorCode

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
202 Not System Application.
7400103 Session not config, only throw in session usage.

示例:

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

function getIsoRange(professionalPhotoSession: camera.ProfessionalPhotoSession): Array<number> {
  let isoRange: Array<number> = [];
  try {
    isoRange = professionalPhotoSession.getIsoRange();
  } catch (error) {
    // 失败返回错误码error.code并处理。
    let err = error as BusinessError;
    console.error(`The getIsoRange call failed. error code: ${err.code}`);
  }
  return isoRange;
}

ProfessionalPhotoSession12+

ProfessionalPhotoSession extends Session, AutoExposure, ManualExposure, Focus, ManualFocus, WhiteBalance, ManualIso, Flash, Zoom, ColorEffect, Aperture

专业拍照会话类,继承自Session,用于设置专业拍照会话的参数以及保存所需要的所有资源CameraInputCameraOutput

on('error')12+

on(type: 'error', callback: ErrorCallback): void

监听专业拍照会话的错误事件,通过注册回调函数获取结果。使用callback异步回调。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'error',session创建成功之后可监听该接口。session调用相关接口出现错误时会触发该事件,比如调用beginConfigcommitConfigaddInput等接口发生错误时返回错误信息。
callback ErrorCallback 回调函数,用于获取错误信息。返回错误码,错误码类型CameraErrorCode

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

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

function callback(err: BusinessError): void {
  console.error(`Professional photo session error code: ${err.code}`);
}

function registerSessionError(professionalPhotoSession: camera.ProfessionalPhotoSession): void {
  professionalPhotoSession.on('error', callback);
}

off('error')12+

off(type: 'error', callback?: ErrorCallback): void

注销监听专业拍照会话的错误事件,通过注册回调函数获取结果。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'error',session创建成功之后可监听该接口。
callback ErrorCallback 回调函数,可选,有就是匿名函数。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

function unregisterSessionError(professionalPhotoSession: camera.ProfessionalPhotoSession): void {
  professionalPhotoSession.off('error');
}

on('focusStateChange')12+

on(type: 'focusStateChange', callback: AsyncCallback<FocusState>): void

监听相机对焦的状态变化,通过注册回调函数获取结果。使用callback异步回调。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'focusStateChange',session创建成功可监听。仅当自动对焦模式时,且相机对焦状态发生改变时可触发该事件。
callback AsyncCallback<FocusState> 回调函数,用于获取当前对焦状态。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

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

function callback(err: BusinessError, focusState: camera.FocusState): void {
  if (err !== undefined && err.code !== 0) {
    console.error(`Callback Error, errorCode: ${err.code}`);
    return;
  }
  console.info(`Focus state: ${focusState}`);
}

function registerFocusStateChange(professionalPhotoSession: camera.ProfessionalPhotoSession): void {
  professionalPhotoSession.on('focusStateChange', callback);
}

off('focusStateChange')12+

off(type: 'focusStateChange', callback?: AsyncCallback<FocusState>): void

注销监听相机对焦的状态变化。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'focusStateChange',session创建成功可监听。
callback AsyncCallback<FocusState> 回调函数,可选,有就是匹配on('focusStateChange') callback(callback对象不可是匿名函数)。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

function unregisterFocusStateChange(professionalPhotoSession: camera.ProfessionalPhotoSession): void {
  professionalPhotoSession.off('focusStateChange');
}

on('smoothZoomInfoAvailable')12+

on(type: 'smoothZoomInfoAvailable', callback: AsyncCallback<SmoothZoomInfo>): void

监听相机平滑变焦的状态变化,通过注册回调函数获取结果。使用callback异步回调。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'smoothZoomInfoAvailable',session创建成功可监听。
callback AsyncCallback<SmoothZoomInfo> 回调函数,用于获取当前平滑变焦状态。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

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

function callback(err: BusinessError, smoothZoomInfo: camera.SmoothZoomInfo): void {
  if (err !== undefined && err.code !== 0) {
    console.error(`Callback Error, errorCode: ${err.code}`);
    return;
  }
  console.info(`The duration of smooth zoom: ${smoothZoomInfo.duration}`);
}

function registerSmoothZoomInfo(professionalPhotoSession: camera.ProfessionalPhotoSession): void {
  professionalPhotoSession.on('smoothZoomInfoAvailable', callback);
}

off('smoothZoomInfoAvailable')12+

off(type: 'smoothZoomInfoAvailable', callback?: AsyncCallback<SmoothZoomInfo>): void

注销监听相机平滑变焦的状态变化。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'smoothZoomInfoAvailable',session创建成功可监听。
callback AsyncCallback<SmoothZoomInfo> 回调函数,可选,有就是匹配on('smoothZoomInfoAvailable') callback(callback对象不可是匿名函数)。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

function unregisterSmoothZoomInfo(professionalPhotoSession: camera.ProfessionalPhotoSession): void {
  professionalPhotoSession.off('smoothZoomInfoAvailable');
}

on('isoInfoChange')12+

on(type: 'isoInfoChange', callback: AsyncCallback<IsoInfo>): void

监听自动ISO变化事件,通过注册回调函数获取实时ISO信息。使用callback异步回调。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'isoInfoChange'。
callback AsyncCallback<IsoInfo> 回调函数,用于获取ISO信息。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

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

function isoInfoCallback(err: BusinessError, info: camera.IsoInfo): void {
  if (err !== undefined && err.code !== 0) {
    console.error(`Callback Error, errorCode: ${err.code}`);
    return;
  }
  console.info(`ISO value: ${info.iso}`);
}

function registerIsoInfoEvent(professionalPhotoSession: camera.ProfessionalPhotoSession): void {
  professionalPhotoSession.on('isoInfoChange', isoInfoCallback);
}

off('isoInfoChange')12+

off(type: 'isoInfoChange', callback?: AsyncCallback<IsoInfo>): void

注销监听ISO信息事件,通过注册回调函数来注销。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'isoInfoChange'。
callback AsyncCallback<IsoInfo> 回调函数,可选,用于匹配on('isoInfoChange')的callback。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

function unregisterIsoInfoEvent(professionalPhotoSession: camera.ProfessionalPhotoSession): void {
  professionalPhotoSession.off('isoInfoChange');
}

on('exposureInfoChange')12+

on(type: 'exposureInfoChange', callback: AsyncCallback<ExposureInfo>): void

监听曝光信息事件,通过注册回调函数获取曝光信息。使用callback异步回调。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'exposureInfoChange'。
callback AsyncCallback<ExposureInfo> 回调函数,用于获取曝光信息。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

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

function exposureInfoCallback(err: BusinessError, info: camera.ExposureInfo): void {
  if (err !== undefined && err.code !== 0) {
    console.error(`Callback Error, errorCode: ${err.code}`);
    return;
  }
  console.info(`exposureTimeValue: ${info.exposureTime}`);
}

function registerExposureInfoEvent(professionalPhotoSession: camera.ProfessionalPhotoSession): void {
  professionalPhotoSession.on('exposureInfoChange', exposureInfoCallback);
}

off('exposureInfoChange')12+

off(type: 'exposureInfoChange', callback?: AsyncCallback<ExposureInfo>): void

注销监听曝光信息事件,通过注册回调函数来注销。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'exposureInfoChange'。
callback AsyncCallback<ExposureInfo> 回调函数,可选,用于匹配on('exposureInfoChange')的callback。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

function unregisterExposureInfoEvent(professionalPhotoSession: camera.ProfessionalPhotoSession): void {
  professionalPhotoSession.off('exposureInfoChange');
}

on('apertureInfoChange')12+

on(type: 'apertureInfoChange', callback: AsyncCallback<ApertureInfo>): void

监听物理光圈变化事件,通过注册回调函数获取实时物理光圈信息。使用callback异步回调。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'apertureInfoChange'。
callback AsyncCallback<ApertureInfo> 回调函数,用于获取物理光圈信息。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

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

function apertureInfoCallback(err: BusinessError, info: camera.ApertureInfo): void {
  if (err !== undefined && err.code !== 0) {
    console.error(`Callback Error, errorCode: ${err.code}`);
    return;
  }
  console.info(`Aperture value: ${info.aperture}`);
}

function registerApertureInfoEvent(professionalPhotoSession: camera.ProfessionalPhotoSession): void {
  professionalPhotoSession.on('apertureInfoChange', apertureInfoCallback);
}

off('apertureInfoChange')12+

off(type: 'apertureInfoChange', callback?: AsyncCallback<ApertureInfo>): void

注销监听物理光圈变化事件,通过注册回调函数来注销。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'apertureInfoChange'。
callback AsyncCallback<ApertureInfo> 回调函数,可选,用于匹配on('apertureInfoChange')的callback。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

function unregisterApertureInfoEvent(professionalPhotoSession: camera.ProfessionalPhotoSession): void {
  professionalPhotoSession.off('apertureInfoChange');
}

on('luminationInfoChange')12+

on(type: 'luminationInfoChange', callback: AsyncCallback<LuminationInfo>): void

监听光照变化事件,通过注册回调函数获取实时光照参数。使用callback异步回调。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'luminationInfoChange'。
callback AsyncCallback<LuminationInfo> 回调函数,用于获取光照参数。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

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

function luminationInfoCallback(err: BusinessError, info: camera.LuminationInfo): void {
  if (err !== undefined && err.code !== 0) {
    console.error(`Callback Error, errorCode: ${err.code}`);
    return;
  }
  console.info(`Lumination: ${info.lumination}`);
}

function registerLuminationInfoEvent(professionalPhotoSession: camera.ProfessionalPhotoSession): void {
  professionalPhotoSession.on('luminationInfoChange', luminationInfoCallback);
}

off('luminationInfoChange')12+

off(type: 'luminationInfoChange', callback?: AsyncCallback<LuminationInfo>): void

注销监听光照变化事件,通过注册回调函数来注销。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'luminationInfoChange'。
callback AsyncCallback<LuminationInfo> 回调函数,可选,用于匹配on('luminationInfoChange')的callback。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

function unregisterLuminationInfoEvent(professionalPhotoSession: camera.ProfessionalPhotoSession): void {
  professionalPhotoSession.off('luminationInfoChange');
}

ProfessionalVideoSession12+

ProfessionalVideoSession extends Session, AutoExposure, ManualExposure, Focus, ManualFocus, WhiteBalance, ManualIso, Flash, Zoom, ColorEffect, Aperture

专业录像模式会话类,继承自Session,用于设置专业录像模式的参数以及保存所需要的所有资源CameraInputCameraOutput

on('error')12+

on(type: 'error', callback: ErrorCallback): void

监听专业录像会话的错误事件,通过注册回调函数获取结果。使用callback异步回调。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'error',session创建成功之后可监听该接口。session调用相关接口出现错误时会触发该事件,比如调用beginConfigcommitConfigaddInput等接口发生错误时返回错误信息。
callback ErrorCallback 回调函数,用于获取错误信息。返回错误码,错误码类型CameraErrorCode

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

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

function callback(err: BusinessError): void {
  console.error(`Professional video session error code: ${err.code}`);
}

function registerSessionError(professionalVideoSession: camera.ProfessionalVideoSession): void {
  professionalVideoSession.on('error', callback);
}

off('error')12+

off(type: 'error', callback?: ErrorCallback): void

注销监听专业录像会话的错误事件,通过注册回调函数获取结果。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'error',session创建成功之后可监听该接口。
callback ErrorCallback 回调函数,可选,有就是匿名函数。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

function unregisterSessionError(professionalVideoSession: camera.ProfessionalVideoSession): void {
  professionalVideoSession.off('error');
}

on('focusStateChange')12+

on(type: 'focusStateChange', callback: AsyncCallback<FocusState>): void

监听相机对焦的状态变化,通过注册回调函数获取结果。使用callback异步回调。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'focusStateChange',session创建成功可监听。仅当自动对焦模式时,且相机对焦状态发生改变时可触发该事件。
callback AsyncCallback<FocusState> 回调函数,用于获取当前对焦状态。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

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

function callback(err: BusinessError, focusState: camera.FocusState): void {
  if (err !== undefined && err.code !== 0) {
    console.error(`Callback Error, errorCode: ${err.code}`);
    return;
  }
  console.info(`Focus state: ${focusState}`);
}

function registerFocusStateChange(professionalVideoSession: camera.ProfessionalVideoSession): void {
  professionalVideoSession.on('focusStateChange', callback);
}

off('focusStateChange')12+

off(type: 'focusStateChange', callback?: AsyncCallback<FocusState>): void

注销监听相机对焦的状态变化。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'focusStateChange',session创建成功可监听。
callback AsyncCallback<FocusState> 回调函数,可选,有就是匹配on('focusStateChange') callback(callback对象不可是匿名函数)。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

function unregisterFocusStateChange(professionalVideoSession: camera.ProfessionalVideoSession): void {
  professionalVideoSession.off('focusStateChange');
}

on('smoothZoomInfoAvailable')12+

on(type: 'smoothZoomInfoAvailable', callback: AsyncCallback<SmoothZoomInfo>): void

监听相机平滑变焦的状态变化,通过注册回调函数获取结果。使用callback异步回调。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'smoothZoomInfoAvailable',session创建成功可监听。
callback AsyncCallback<SmoothZoomInfo> 回调函数,用于获取当前平滑变焦状态。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

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

function callback(err: BusinessError, smoothZoomInfo: camera.SmoothZoomInfo): void {
  if (err !== undefined && err.code !== 0) {
    console.error(`Callback Error, errorCode: ${err.code}`);
    return;
  }
  console.info(`The duration of smooth zoom: ${smoothZoomInfo.duration}`);
}

function registerSmoothZoomInfo(professionalVideoSession: camera.ProfessionalVideoSession): void {
  professionalVideoSession.on('smoothZoomInfoAvailable', callback);
}

off('smoothZoomInfoAvailable')12+

off(type: 'smoothZoomInfoAvailable', callback?: AsyncCallback<SmoothZoomInfo>): void

注销监听相机平滑变焦的状态变化。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'smoothZoomInfoAvailable',session创建成功可监听。
callback AsyncCallback<SmoothZoomInfo> 回调函数,可选,有就是匹配on('smoothZoomInfoAvailable') callback(callback对象不可是匿名函数)。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

function unregisterSmoothZoomInfo(professionalVideoSession: camera.ProfessionalVideoSession): void {
  professionalVideoSession.off('smoothZoomInfoAvailable');
}

on('isoInfoChange')12+

on(type: 'isoInfoChange', callback: AsyncCallback<IsoInfo>): void

监听自动ISO变化事件,通过注册回调函数获取实时ISO信息。使用callback异步回调。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'isoInfoChange'。
callback AsyncCallback<IsoInfo> 回调函数,用于获取ISO信息。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

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

function isoInfoCallback(err: BusinessError, info: camera.IsoInfo): void {
  if (err !== undefined && err.code !== 0) {
    console.error(`Callback Error, errorCode: ${err.code}`);
    return;
  }
  console.info(`ISO value: ${info.iso}`);
}

function registerIsoInfoEvent(professionalVideoSession: camera.ProfessionalVideoSession): void {
  professionalVideoSession.on('isoInfoChange', isoInfoCallback);
}

off('isoInfoChange')12+

off(type: 'isoInfoChange', callback?: AsyncCallback<IsoInfo>): void

注销监听ISO信息事件,通过注册回调函数来注销。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'isoInfoChange'。
callback AsyncCallback<IsoInfo> 回调函数,可选,用于匹配on('isoInfoChange')的callback。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

function unregisterIsoInfoEvent(professionalVideoSession: camera.ProfessionalVideoSession): void {
  professionalVideoSession.off('isoInfoChange');
}

on('exposureInfoChange')12+

on(type: 'exposureInfoChange', callback: AsyncCallback<ExposureInfo>): void

监听曝光信息事件,通过注册回调函数获取曝光信息。使用callback异步回调。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'exposureInfoChange'。
callback AsyncCallback<ExposureInfo> 回调函数,用于获取曝光信息。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

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

function exposureInfoCallback(err: BusinessError, info: camera.ExposureInfo): void {
  if (err !== undefined && err.code !== 0) {
    console.error(`Callback Error, errorCode: ${err.code}`);
    return;
  }
  console.info(`exposureTimeValue: ${info.exposureTime}`);
}

function registerExposureInfoEvent(professionalVideoSession: camera.ProfessionalVideoSession): void {
  professionalVideoSession.on('exposureInfoChange', exposureInfoCallback);
}

off('exposureInfoChange')12+

off(type: 'exposureInfoChange', callback?: AsyncCallback<ExposureInfo>): void

注销监听曝光信息事件,通过注册回调函数来注销。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'exposureInfoChange'。
callback AsyncCallback<ExposureInfo> 回调函数,可选,用于匹配on('exposureInfoChange')的callback。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

function unregisterExposureInfoEvent(professionalVideoSession: camera.ProfessionalVideoSession): void {
  professionalVideoSession.off('exposureInfoChange');
}

on('apertureInfoChange')12+

on(type: 'apertureInfoChange', callback: AsyncCallback<ApertureInfo>): void

监听物理光圈变化事件,通过注册回调函数获取物理光圈信息。使用callback异步回调。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'apertureInfoChange'。
callback AsyncCallback<ApertureInfo> 回调函数,用于获取物理光圈信息。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

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

function apertureInfoCallback(err: BusinessError, info: camera.ApertureInfo): void {
  if (err !== undefined && err.code !== 0) {
    console.error(`Callback Error, errorCode: ${err.code}`);
    return;
  }
  console.info(`Aperture value: ${info.aperture}`);
}

function registerApertureInfoEvent(professionalVideoSession: camera.ProfessionalVideoSession): void {
  professionalVideoSession.on('apertureInfoChange', apertureInfoCallback);
}

off('apertureInfoChange')12+

off(type: 'apertureInfoChange', callback?: AsyncCallback<ApertureInfo>): void

注销监听物理光圈变化事件,通过注册回调函数来注销。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'apertureInfoChange'。
callback AsyncCallback<ApertureInfo> 回调函数,可选,用于匹配on('apertureInfoChange')的callback。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

function unregisterApertureInfoEvent(professionalVideoSession: camera.ProfessionalVideoSession): void {
  professionalVideoSession.off('apertureInfoChange');
}

on('luminationInfoChange')12+

on(type: 'luminationInfoChange', callback: AsyncCallback<LuminationInfo>): void

监听光照变化事件,通过注册回调函数获取光照参数。使用callback异步回调。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'luminationInfoChange'。
callback AsyncCallback<LuminationInfo> 回调函数,用于获取光照参数。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

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

function luminationInfoCallback(err: BusinessError, info: camera.LuminationInfo): void {
  if (err !== undefined && err.code !== 0) {
    console.error(`Callback Error, errorCode: ${err.code}`);
    return;
  }
  console.info(`Lumination: ${info.lumination}`);
}

function registerLuminationInfoEvent(professionalVideoSession: camera.ProfessionalVideoSession): void {
  professionalVideoSession.on('luminationInfoChange', luminationInfoCallback);
}

off('luminationInfoChange')12+

off(type: 'luminationInfoChange', callback?: AsyncCallback<LuminationInfo>): void

注销监听光照变化事件,通过注册回调函数来注销。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'luminationInfoChange'。
callback AsyncCallback<LuminationInfo> 回调函数,可选,用于匹配on('luminationInfoChange')的callback。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

function unregisterLuminationInfoEvent(professionalVideoSession: camera.ProfessionalVideoSession): void {
  professionalVideoSession.off('luminationInfoChange');
}

MacroPhotoSession12+

MacroPhotoSession extends Session, Flash, AutoExposure, Focus, Zoom, ColorEffect, ManualFocus

微距拍照模式会话类,继承自Session,用于设置微距拍照模式的参数以及保存所需要的所有资源CameraInputCameraOutput

on('error')12+

on(type: 'error', callback: ErrorCallback): void

监听微距拍照会话的错误事件,通过注册回调函数获取结果。使用callback异步回调。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'error',session创建成功之后可监听该接口。session调用相关接口出现错误时会触发该事件,比如调用beginConfigcommitConfigaddInput等接口发生错误时返回错误信息。
callback ErrorCallback 回调函数,用于获取错误信息。返回错误码,错误码类型CameraErrorCode

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

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

function callback(err: BusinessError): void {
  console.error(`MacroPhotoSession error code: ${err.code}`);
}

function registerSessionError(macroPhotoSession: camera.MacroPhotoSession): void {
  macroPhotoSession.on('error', callback);
}

off('error')12+

off(type: 'error', callback?: ErrorCallback): void

注销监听微距拍照会话的错误事件,通过注册回调函数获取结果。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'error',session创建成功之后可监听该接口。
callback ErrorCallback 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

function unregisterSessionError(macroPhotoSession: camera.MacroPhotoSession): void {
  macroPhotoSession.off('error');
}

on('focusStateChange')12+

on(type: 'focusStateChange', callback: AsyncCallback<FocusState>): void

监听相机对焦的状态变化,通过注册回调函数获取结果。使用callback异步回调。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'focusStateChange',session创建成功可监听。仅当自动对焦模式时,且相机对焦状态发生改变时可触发该事件。
callback AsyncCallback<FocusState> 回调函数,用于获取当前对焦状态。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

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

function callback(err: BusinessError, focusState: camera.FocusState): void {
  if (err !== undefined && err.code !== 0) {
    console.error(`Callback Error, errorCode: ${err.code}`);
    return;
  }
  console.info(`Focus state: ${focusState}`);
}

function registerFocusStateChange(macroPhotoSession: camera.MacroPhotoSession): void {
  macroPhotoSession.on('focusStateChange', callback);
}

off('focusStateChange')12+

off(type: 'focusStateChange', callback?: AsyncCallback<FocusState>): void

注销监听相机对焦的状态变化。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'focusStateChange',session创建成功可监听。
callback AsyncCallback<FocusState> 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

function unregisterFocusStateChange(macroPhotoSession: camera.MacroPhotoSession): void {
  macroPhotoSession.off('focusStateChange');
}

on('smoothZoomInfoAvailable')12+

on(type: 'smoothZoomInfoAvailable', callback: AsyncCallback<SmoothZoomInfo>): void

监听相机平滑变焦的状态变化,通过注册回调函数获取结果。使用callback异步回调。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'smoothZoomInfoAvailable',session创建成功可监听。
callback AsyncCallback<SmoothZoomInfo> 回调函数,用于获取当前平滑变焦状态。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

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

function callback(err: BusinessError, smoothZoomInfo: camera.SmoothZoomInfo): void {
  if (err !== undefined && err.code !== 0) {
    console.error(`Callback Error, errorCode: ${err.code}`);
    return;
  }
  console.info(`The duration of smooth zoom: ${smoothZoomInfo.duration}`);
}

function registerSmoothZoomInfo(macroPhotoSession: camera.MacroPhotoSession): void {
  macroPhotoSession.on('smoothZoomInfoAvailable', callback);
}

off('smoothZoomInfoAvailable')12+

off(type: 'smoothZoomInfoAvailable', callback?: AsyncCallback<SmoothZoomInfo>): void

注销监听相机平滑变焦的状态变化。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'smoothZoomInfoAvailable',session创建成功可监听。
callback AsyncCallback<SmoothZoomInfo> 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

function unregisterSmoothZoomInfo(macroPhotoSession: camera.MacroPhotoSession): void {
  macroPhotoSession.off('smoothZoomInfoAvailable');
}

MacroVideoSession12+

MacroVideoSession extends Session, Flash, AutoExposure, Focus, Zoom, ColorEffect, ManualFocus

微距录像模式会话类,继承自Session,用于设置微距录像模式的参数以及保存所需要的所有资源CameraInputCameraOutput

on('error')12+

on(type: 'error', callback: ErrorCallback): void

监听微距录像会话的错误事件,通过注册回调函数获取结果。使用callback异步回调。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'error',session创建成功之后可监听该接口。session调用相关接口出现错误时会触发该事件,比如调用beginConfigcommitConfigaddInput等接口发生错误时返回错误信息。
callback ErrorCallback 回调函数,用于获取错误信息。返回错误码,错误码类型CameraErrorCode

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

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

function callback(err: BusinessError): void {
  console.error(`MacroPhotoSession error code: ${err.code}`);
}

function registerSessionError(macroVideoSession: camera.MacroVideoSession): void {
  macroVideoSession.on('error', callback);
}

off('error')12+

off(type: 'error', callback?: ErrorCallback): void

注销监听微距录像会话的错误事件,通过注册回调函数获取结果。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'error',session创建成功之后可监听该接口。
callback ErrorCallback 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

function unregisterSessionError(macroVideoSession: camera.MacroVideoSession): void {
  macroVideoSession.off('error');
}

on('focusStateChange')12+

on(type: 'focusStateChange', callback: AsyncCallback<FocusState>): void

监听相机对焦的状态变化,通过注册回调函数获取结果。使用callback异步回调。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'focusStateChange',session创建成功可监听。仅当自动对焦模式时,且相机对焦状态发生改变时可触发该事件。
callback AsyncCallback<FocusState> 回调函数,用于获取当前对焦状态。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

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

function callback(err: BusinessError, focusState: camera.FocusState): void {
  if (err !== undefined && err.code !== 0) {
    console.error(`Callback Error, errorCode: ${err.code}`);
    return;
  }
  console.info(`Focus state: ${focusState}`);
}

function registerFocusStateChange(macroVideoSession: camera.MacroVideoSession): void {
  macroVideoSession.on('focusStateChange', callback);
}

off('focusStateChange')12+

off(type: 'focusStateChange', callback?: AsyncCallback<FocusState>): void

注销监听相机对焦的状态变化。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'focusStateChange',session创建成功可监听。
callback AsyncCallback<FocusState> 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

function unregisterFocusStateChange(macroVideoSession: camera.MacroVideoSession): void {
  macroVideoSession.off('focusStateChange');
}

on('smoothZoomInfoAvailable')12+

on(type: 'smoothZoomInfoAvailable', callback: AsyncCallback<SmoothZoomInfo>): void

监听相机平滑变焦的状态变化,通过注册回调函数获取结果。使用callback异步回调。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'smoothZoomInfoAvailable',session创建成功可监听。
callback AsyncCallback<SmoothZoomInfo> 回调函数,用于获取当前平滑变焦状态。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

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

function callback(err: BusinessError, smoothZoomInfo: camera.SmoothZoomInfo): void {
  if (err !== undefined && err.code !== 0) {
    console.error(`Callback Error, errorCode: ${err.code}`);
    return;
  }
  console.info(`The duration of smooth zoom: ${smoothZoomInfo.duration}`);
}

function registerSmoothZoomInfo(macroVideoSession: camera.MacroVideoSession): void {
  macroVideoSession.on('smoothZoomInfoAvailable', callback);
}

off('smoothZoomInfoAvailable')12+

off(type: 'smoothZoomInfoAvailable', callback?: AsyncCallback<SmoothZoomInfo>): void

注销监听相机平滑变焦的状态变化。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'smoothZoomInfoAvailable',session创建成功可监听。
callback AsyncCallback<SmoothZoomInfo> 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

function unregisterSmoothZoomInfo(macroVideoSession: camera.MacroVideoSession): void {
  macroVideoSession.off('smoothZoomInfoAvailable');
}

FlashQuery12+

此接口提供了查阅设备闪光灯信息相应的方法,包括是否支持lcd闪光灯。

isLcdFlashSupported12+

isLcdFlashSupported(): boolean

查询是否支持lcd闪光灯。

系统接口: 此接口为系统接口。

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

返回值:

类型 说明
boolean 查询是否支持lcd闪光灯,返回true为支持,返回false为不支持。

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
202 Not System Application.
7400103 Session not config, only throw in session usage.

示例:

function isLcdFlashSupported(nightPhotoSession: camera.NightPhotoSession): boolean {
  return nightPhotoSession.isLcdFlashSupported();
}

Flash11+

Flash extends FlashQuery

闪光灯类,对设备闪光灯操作。

enableLcdFlash13+

enableLcdFlash(enabled: boolean): void

使能或去使能LCD闪光灯。

进行设置之前,需要先检查:设备是否支持LCD闪光灯,可使用方法isLcdFlashSupported

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

参数:

参数名 类型 必填 说明
enabled boolean 使能或去使能LCD闪光灯,true为使能,false为去使能。传参为null或者undefined,作为0处理,去使能LCD闪光灯。

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
202 Not System Application.
7400103 Session not config.

示例:

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

function enableLcdFlash(session: camera.PhotoSessionForSys | camera.VideoSessionForSys | camera.NightPhotoSession): void {
  try {
    session.enableLcdFlash(true);
  } catch (error) {
    // 失败返回错误码error.code并处理。
    let err = error as BusinessError;
    console.error(`The setFlashMode call failed. error code: ${err.code}`);
  }
}

TimeLapseRecordState12+

枚举,延时摄影录制状态。

系统接口: 此接口为系统接口。

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

名称 说明
IDLE 0 未录制
RECORDING 1 录制中

TimeLapsePreviewType12+

枚举,延时摄影预览类型,影响拍摄算法。

系统接口: 此接口为系统接口。

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

名称 说明
DARK 1 暗光环境,指光照较差的场景,比如夜晚或暗处。
LIGHT 2 亮光环境,指光照较好的场景,比如白天或灯光下。

TryAEInfo12+

TryAE参数信息,TryAE是指延时摄影时硬件会根据环境光照变化上报状态的操作。

系统接口: 此接口为系统接口。

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

名称 类型 只读 可选 说明
isTryAEDone boolean 表示TryAE是否完成。true表示已完成,false表示未完成。
isTryAEHintNeeded boolean 表示是否需要TryAE。true表示需要,false表示不需要。
previewType TimeLapsePreviewType 预览类型。
captureInterval number 拍摄间隔,单位毫秒(ms)。

TimeLapsePhotoSession12+

TimeLapsePhotoSession extends Session, Focus, ManualFocus, AutoExposure, ManualExposure, ManualIso, WhiteBalance, Zoom, ColorEffect

延时摄影会话类,继承自Session,用于设置延时摄影会话的参数以及保存所需要的所有资源CameraInputCameraOutput

on('error')12+

on(type: 'error', callback: ErrorCallback): void

监听延时摄影会话的错误事件,通过注册回调函数获取结果。使用callback异步回调。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'error',session创建成功之后可监听该接口。session调用相关接口出现错误时会触发该事件,比如调用beginConfigcommitConfigaddInput等接口发生错误时返回错误信息。
callback ErrorCallback 回调函数,用于获取错误信息。返回错误码,错误码类型CameraErrorCode

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

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

function callback(err: BusinessError): void {
  console.error(`Time lapse photo session error code: ${err.code}`);
}

function registerSessionError(timeLapsePhotoSession: camera.TimeLapsePhotoSession): void {
  timeLapsePhotoSession.on('error', callback);
}

off('error')12+

off(type: 'error', callback?: ErrorCallback): void

注销监听延时摄影会话的错误事件,通过注册回调函数获取结果。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'error',session创建成功之后可监听该接口。
callback ErrorCallback 回调函数,可选,有就是匿名函数。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

function unregisterSessionError(timeLapsePhotoSession: camera.TimeLapsePhotoSession): void {
  timeLapsePhotoSession.off('error');
}

on('focusStateChange')12+

on(type: 'focusStateChange', callback: AsyncCallback<FocusState>): void

监听相机对焦的状态变化,通过注册回调函数获取结果。使用callback异步回调。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'focusStateChange',session创建成功可监听。仅当自动对焦模式时,且相机对焦状态发生改变时可触发该事件。
callback AsyncCallback<FocusState> 回调函数,用于获取当前对焦状态。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

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

function callback(err: BusinessError, focusState: camera.FocusState): void {
  if (err !== undefined && err.code !== 0) {
    console.error(`Callback Error, errorCode: ${err.code}`);
    return;
  }
  console.info(`Focus state: ${focusState}`);
}

function registerFocusStateChange(timeLapsePhotoSession: camera.TimeLapsePhotoSession): void {
  timeLapsePhotoSession.on('focusStateChange', callback);
}

off('focusStateChange')12+

off(type: 'focusStateChange', callback?: AsyncCallback<FocusState>): void

注销监听相机对焦的状态变化。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'focusStateChange',session创建成功可监听。
callback AsyncCallback<FocusState> 回调函数,可选,有就是匹配on('focusStateChange') callback(callback对象不可是匿名函数)。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

function unregisterFocusStateChange(timeLapsePhotoSession: camera.TimeLapsePhotoSession): void {
  timeLapsePhotoSession.off('focusStateChange');
}

on('isoInfoChange')12+

on(type: 'isoInfoChange', callback: AsyncCallback<IsoInfo>): void

监听自动ISO变化事件,通过注册回调函数获取实时ISO信息。使用callback异步回调。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'isoInfoChange'。
callback AsyncCallback<IsoInfo> 回调函数,用于获取ISO信息。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

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

function isoInfoCallback(err: BusinessError, info: camera.IsoInfo): void {
  if (err !== undefined && err.code !== 0) {
    console.error(`Callback Error, errorCode: ${err.code}`);
    return;
  }
  console.info(`ISO value: ${info.iso}`);
}

function registerIsoInfoEvent(timeLapsePhotoSession: camera.TimeLapsePhotoSession): void {
  timeLapsePhotoSession.on('isoInfoChange', isoInfoCallback);
}

off('isoInfoChange')12+

off(type: 'isoInfoChange', callback?: AsyncCallback<IsoInfo>): void

注销监听ISO信息事件,通过注册回调函数来注销。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'isoInfoChange'。
callback AsyncCallback<IsoInfo> 回调函数,可选,用于匹配on('isoInfoChange')的callback。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

function unregisterIsoInfoEvent(timeLapsePhotoSession: camera.TimeLapsePhotoSession): void {
  timeLapsePhotoSession.off('isoInfoChange');
}

on('exposureInfoChange')12+

on(type: 'exposureInfoChange', callback: AsyncCallback<ExposureInfo>): void

监听曝光信息事件,通过注册回调函数获取曝光信息。使用callback异步回调。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'exposureInfoChange'。
callback AsyncCallback<ExposureInfo> 回调函数,用于获取曝光信息。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

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

function exposureInfoCallback(err: BusinessError, info: camera.ExposureInfo): void {
  if (err !== undefined && err.code !== 0) {
    console.error(`Callback Error, errorCode: ${err.code}`);
    return;
  }
  console.info(`exposureTimeValue: ${info.exposureTime}`);
}

function registerExposureInfoEvent(timeLapsePhotoSession: camera.TimeLapsePhotoSession): void {
  timeLapsePhotoSession.on('exposureInfoChange', exposureInfoCallback);
}

off('exposureInfoChange')12+

off(type: 'exposureInfoChange', callback?: AsyncCallback<ExposureInfo>): void

注销监听曝光信息事件,通过注册回调函数来注销。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'exposureInfoChange'。
callback AsyncCallback<ExposureInfo> 回调函数,可选,用于匹配on('exposureInfoChange')的callback。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

function unregisterExposureInfoEvent(timeLapsePhotoSession: camera.TimeLapsePhotoSession): void {
  timeLapsePhotoSession.off('exposureInfoChange');
}

on('luminationInfoChange')12+

on(type: 'luminationInfoChange', callback: AsyncCallback<LuminationInfo>): void

监听光照变化事件,通过注册回调函数获取实时光照参数。使用callback异步回调。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'luminationInfoChange'。
callback AsyncCallback<LuminationInfo> 回调函数,用于获取光照参数。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

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

function luminationInfoCallback(err: BusinessError, info: camera.LuminationInfo): void {
  if (err !== undefined && err.code !== 0) {
    console.error(`Callback Error, errorCode: ${err.code}`);
    return;
  }
  console.info(`Lumination: ${info.lumination}`);
}

function registerLuminationInfoEvent(timeLapsePhotoSession: camera.TimeLapsePhotoSession): void {
  timeLapsePhotoSession.on('luminationInfoChange', luminationInfoCallback);
}

off('luminationInfoChange')12+

off(type: 'luminationInfoChange', callback?: AsyncCallback<LuminationInfo>): void

注销监听光照变化事件,通过注册回调函数来注销。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'luminationInfoChange'。
callback AsyncCallback<LuminationInfo> 回调函数,可选,用于匹配on('luminationInfoChange')的callback。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

function unregisterLuminationInfoEvent(timeLapsePhotoSession: camera.TimeLapsePhotoSession): void {
  timeLapsePhotoSession.off('luminationInfoChange');
}

on('tryAEInfoChange')12+

on(type: 'tryAEInfoChange', callback: AsyncCallback<TryAEInfo>): void

监听TryAE变化事件,通过注册回调函数获取实时TryAE参数。使用callback异步回调。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'tryAEInfoChange'。
callback AsyncCallback<TryAEInfo> 回调函数,用于获取TryAE参数。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

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

function tryAEInfoCallback(err: BusinessError, info: camera.TryAEInfo): void {
  if (err !== undefined && err.code !== 0) {
    console.error(`Callback Error, errorCode: ${err.code}`);
    return;
  }
  console.info(`TryAEInfo: ${info.isTryAEDone}, ${info.isTryAEHintNeeded}, ${info.previewType}, ${info.captureInterval}`);
}

function registerTryAEInfoEvent(timeLapsePhotoSession: camera.TimeLapsePhotoSession): void {
  timeLapsePhotoSession.on('tryAEInfoChange', tryAEInfoCallback);
}

off('tryAEInfoChange')12+

off(type: 'tryAEInfoChange', callback?: AsyncCallback<TryAEInfo>): void

注销监听TryAE变化事件,通过注册回调函数来注销。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'tryAEInfoChange'。
callback AsyncCallback<TryAEInfo> 回调函数,可选,用于匹配on('tryAEInfoChange')的callback。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

function unregisterTryAEInfoEvent(timeLapsePhotoSession: camera.TimeLapsePhotoSession): void {
  timeLapsePhotoSession.off('tryAEInfoChange');
}

isTryAENeeded12+

isTryAENeeded(): boolean

判断是否需要执行TryAE。

系统接口: 此接口为系统接口。

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

返回值:

类型 说明
boolean 是否需要执行TryAE,返回true为是,返回false为否,错误码类型CameraErrorCode

错误码:

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

错误码ID 错误信息
202 Not System Application.
7400103 Session not config, only throw in session usage.

示例:

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

function isTryAENeeded(timeLapsePhotoSession: camera.TimeLapsePhotoSession): boolean {
  let needed = false;
  try {
    needed = timeLapsePhotoSession.isTryAENeeded();
  } catch (error) {
    // 失败返回错误码error.code并处理。
    let err = error as BusinessError;
    console.error(`The isTryAENeeded call failed. error code: ${err.code}`);
  }
  return needed;
}

startTryAE12+

startTryAE(): void

开始执行TryAE。

系统接口: 此接口为系统接口。

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

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
202 Not System Application.
7400103 Session not config.
7400201 Camera service fatal error.

示例:

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

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

stopTryAE12+

stopTryAE(): void

停止执行TryAE。

系统接口: 此接口为系统接口。

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

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
202 Not System Application.
7400103 Session not config.
7400201 Camera service fatal error.

示例:

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

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

getSupportedTimeLapseIntervalRange12+

getSupportedTimeLapseIntervalRange(): Array<number>

获取支持的拍摄间隔范围。

系统接口: 此接口为系统接口。

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

返回值:

类型 说明
Array<number> 用于获取拍摄间隔范围,单位毫秒(ms),根据底层能力返回为准,接口调用失败会返回相应错误码,错误码类型CameraErrorCode

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
202 Not System Application.
7400103 Session not config, only throw in session usage.

示例:

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

function getSupportedTimeLapseIntervalRange(timeLapsePhotoSession: camera.TimeLapsePhotoSession): Array<number> {
  let intervalRange: Array<number> = [];
  try {
    intervalRange = timeLapsePhotoSession.getSupportedTimeLapseIntervalRange();
  } catch (error) {
    // 失败返回错误码error.code并处理。
    let err = error as BusinessError;
    console.error(`The getSupportedTimeLapseIntervalRange call failed. error code: ${err.code}`);
  }
  return intervalRange;
}

getTimeLapseInterval12+

getTimeLapseInterval(): number

获取当前的拍摄间隔值。

系统接口: 此接口为系统接口。

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

返回值:

类型 说明
number 返回当前拍摄间隔值,单位毫秒(ms)。

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
202 Not System Application.
7400103 Session not config.

示例:

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

function getTimeLapseInterval(timeLapsePhotoSession: camera.TimeLapsePhotoSession): number {
  let interval: number = 0;
  try {
    interval = timeLapsePhotoSession.getTimeLapseInterval();
  } catch (error) {
    // 失败返回错误码error.code并处理。
    let err = error as BusinessError;
    console.error(`The getTimeLapseInterval call failed. error code: ${err.code}`);
  }
  return interval;
}

setTimeLapseInterval12+

setTimeLapseInterval(interval: number): void

设置拍摄间隔值。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
interval number 设置拍摄间隔值,单位毫秒(ms)。

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
202 Not System Application.
7400101 Parameter missing or parameter type incorrect.
7400103 Session not config.

示例:

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

function setTimeLapseInterval(timeLapsePhotoSession: camera.TimeLapsePhotoSession): void {
  try {
    let interval: number = 10000;
    timeLapsePhotoSession.setTimeLapseInterval(interval);
  } catch (error) {
    // 失败返回错误码error.code并处理。
    let err = error as BusinessError;
    console.error(`The setTimeLapseInterval call failed. error code: ${err.code}`);
  }
}

getTimeLapseRecordState12+

getTimeLapseRecordState(): TimeLapseRecordState

获取当前拍摄状态。

系统接口: 此接口为系统接口。

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

返回值:

类型 说明
TimeLapseRecordState 获取当前拍摄状态。接口调用失败会返回相应错误码,错误码类型CameraErrorCode

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
202 Not System Application.
7400103 Session not config.

示例:

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

function getTimeLapseRecordState(timeLapsePhotoSession: camera.TimeLapsePhotoSession): camera.TimeLapseRecordState {
  let state = camera.TimeLapseRecordState.IDLE;
  try {
    state = timeLapsePhotoSession.getTimeLapseRecordState();
  } catch (error) {
    // 失败返回错误码error.code并处理。
    let err = error as BusinessError;
    console.error(`The getTimeLapseRecordState call failed. error code: ${err.code}`);
  }
  return state;
}

setTimeLapseRecordState12+

setTimeLapseRecordState(state: TimeLapseRecordState): void

设置当前拍摄状态。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
state TimeLapseRecordState 拍摄状态。

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
202 Not System Application.
7400101 Parameter missing or parameter type incorrect.
7400103 Session not config.

示例:

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

function setTimeLapseRecordState(timeLapsePhotoSession: camera.TimeLapsePhotoSession): void {
  try {
    timeLapsePhotoSession.setTimeLapseRecordState(camera.TimeLapseRecordState.RECORDING);
  } catch (error) {
    // 失败返回错误码error.code并处理。
    let err = error as BusinessError;
    console.error(`The setTimeLapseRecordState call failed. error code: ${err.code}`);
  }
}

getTimeLapsePreviewType12+

getTimeLapsePreviewType(): TimeLapsePreviewType

获取当前预览类型。

系统接口: 此接口为系统接口。

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

返回值:

类型 说明
TimeLapsePreviewType 获取当前预览类型。接口调用失败会返回相应错误码,错误码类型CameraErrorCode

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
202 Not System Application.
7400103 Session not config.

示例:

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

function getTimeLapsePreviewType(timeLapsePhotoSession: camera.TimeLapsePhotoSession): camera.TimeLapsePreviewType {
  let type = camera.TimeLapsePreviewType.DARK;
  try {
    type = timeLapsePhotoSession.getTimeLapsePreviewType();
  } catch (error) {
    // 失败返回错误码error.code并处理。
    let err = error as BusinessError;
    console.error(`The getTimeLapsePreviewType call failed. error code: ${err.code}`);
  }
  return type;
}

setTimeLapsePreviewType12+

setTimeLapsePreviewType(type: TimeLapsePreviewType): void

设置当前预览类型。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
state TimeLapsePreviewType 预览类型。

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
202 Not System Application.
7400101 Parameter missing or parameter type incorrect.
7400103 Session not config.

示例:

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

function setTimeLapsePreviewType(timeLapsePhotoSession: camera.TimeLapsePhotoSession): void {
  try {
    timeLapsePhotoSession.setTimeLapsePreviewType(camera.TimeLapsePreviewType.LIGHT);
  } catch (error) {
    // 失败返回错误码error.code并处理。
    let err = error as BusinessError;
    console.error(`The setTimeLapsePreviewType call failed. error code: ${err.code}`);
  }
}

LightPaintingPhotoSession12+

LightPaintingPhotoSession extends Session, Flash, Focus, Zoom, ColorEffect

流光快门拍照模式会话类,继承自Session,用于设置流光快门拍照模式的参数以及保存所需要的所有资源CameraInputCameraOutput

on('error')12+

on(type: 'error', callback: ErrorCallback): void

监听流光快门拍照会话的错误事件,通过注册回调函数获取结果。使用callback异步回调。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'error',session创建成功之后可监听该接口。session调用相关接口出现错误时会触发该事件,比如调用beginConfigcommitConfigaddInput等接口发生错误时返回错误信息。
callback ErrorCallback 回调函数,用于获取错误信息。返回错误码,错误码类型CameraErrorCode

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

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

function callback(err: BusinessError): void {
  console.error(`LightPaintingPhotoSession error code: ${err.code}`);
}

function registerSessionError(lightPaintingPhotoSession: camera.LightPaintingPhotoSession): void {
  lightPaintingPhotoSession.on('error', callback);
}

off('error')12+

off(type: 'error', callback?: ErrorCallback): void

注销监听流光快门拍照会话的错误事件,通过注册回调函数获取结果。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'error',session创建成功之后可监听该接口。
callback ErrorCallback 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

function unregisterSessionError(lightPaintingPhotoSession: camera.LightPaintingPhotoSession): void {
  lightPaintingPhotoSession.off('error');
}

on('focusStateChange')12+

on(type: 'focusStateChange', callback: AsyncCallback<FocusState>): void

监听相机对焦的状态变化,通过注册回调函数获取结果。使用callback异步回调。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'focusStateChange',session创建成功可监听。仅当自动对焦模式时,且相机对焦状态发生改变时可触发该事件。
callback AsyncCallback<FocusState> 回调函数,用于获取当前对焦状态。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

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

function callback(err: BusinessError, focusState: camera.FocusState): void {
  if (err !== undefined && err.code !== 0) {
    console.error(`Callback Error, errorCode: ${err.code}`);
    return;
  }
  console.info(`Focus state: ${focusState}`);
}

function registerFocusStateChange(lightPaintingPhotoSession: camera.LightPaintingPhotoSession): void {
  lightPaintingPhotoSession.on('focusStateChange', callback);
}

off('focusStateChange')12+

off(type: 'focusStateChange', callback?: AsyncCallback<FocusState>): void

注销监听相机对焦的状态变化。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'focusStateChange',session创建成功可监听。
callback AsyncCallback<FocusState> 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

function unregisterFocusStateChange(lightPaintingPhotoSession: camera.LightPaintingPhotoSession): void {
  lightPaintingPhotoSession.off('focusStateChange');
}

on('smoothZoomInfoAvailable')12+

on(type: 'smoothZoomInfoAvailable', callback: AsyncCallback<SmoothZoomInfo>): void

监听相机平滑变焦的状态变化,通过注册回调函数获取结果。使用callback异步回调。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'smoothZoomInfoAvailable',session创建成功可监听。
callback AsyncCallback<SmoothZoomInfo> 回调函数,用于获取当前平滑变焦状态。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

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

function callback(err: BusinessError, smoothZoomInfo: camera.SmoothZoomInfo): void {
  if (err !== undefined && err.code !== 0) {
    console.error(`Callback Error, errorCode: ${err.code}`);
    return;
  }
  console.info(`The duration of smooth zoom: ${smoothZoomInfo.duration}`);
}

function registerSmoothZoomInfo(lightPaintingPhotoSession: camera.LightPaintingPhotoSession): void {
  lightPaintingPhotoSession.on('smoothZoomInfoAvailable', callback);
}

off('smoothZoomInfoAvailable')12+

off(type: 'smoothZoomInfoAvailable', callback?: AsyncCallback<SmoothZoomInfo>): void

注销监听相机平滑变焦的状态变化。

系统接口: 此接口为系统接口。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为'smoothZoomInfoAvailable',session创建成功可监听。
callback AsyncCallback<SmoothZoomInfo> 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档

错误码ID 错误信息
202 Not System Application.

示例:

function unregisterSmoothZoomInfo(lightPaintingPhotoSession: camera.LightPaintingPhotoSession): void {
  lightPaintingPhotoSession.off('smoothZoomInfoAvailable');
}

getLightPaintingType12+

getLightPaintingType(): LightPaintingType

获取当前生效的流光快门模式类型。

系统接口: 此接口为系统接口。

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

返回值:

类型 说明
LightPaintingType 流光快门模式类型。

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
202 Not System Application.
7400103 Session not config.

示例:

function getLightPaintingType(lightPaintingPhotoSession: camera.LightPaintingPhotoSession): camera.LightPaintingType {
  let type: camera.LightPaintingType = lightPaintingPhotoSession.getLightPaintingType();
  return type;
}

setLightPaintingType12+

setLightPaintingType(type: LightPaintingType): void

设置当前生效的流光快门模式类型。

系统接口: 此接口为系统接口。

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

返回值:

参数名 类型 必填 说明
type LightPaintingType 设置流光快门模式的类型。

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
202 Not System Application.
7400101 Parameter missing or parameter type incorrect.
7400103 Session not config.

示例:

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

function setLightPaintingType(lightPaintingPhotoSession: camera.LightPaintingPhotoSession): void {
  try {
    let type: camera.LightPaintingType = camera.LightPaintingType.TRAFFIC_TRAILS;
    lightPaintingPhotoSession.setLightPaintingType(type);
  } catch (error) {
    // 失败返回错误码error.code并处理。
    let err = error as BusinessError;
    console.error(`The setLightPaintingType call failed. error code: ${err.code}`);
  }
}

getSupportedLightPaintingTypes12+

getSupportedLightPaintingTypes(): Array<LightPaintingType>

获取当前支持的流光快门模式类型。

系统接口: 此接口为系统接口。

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

返回值:

类型 说明
Array<LightPaintingType> 支持的流光快门模式类型。

错误码:

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
202 Not System Application.
7400103 Session not config.

示例:

function getSupportedLightPaintingTypes(lightPaintingPhotoSession: camera.LightPaintingPhotoSession): Array<camera.LightPaintingType> {
  let types: Array<camera.LightPaintingType> = lightPaintingPhotoSession.getSupportedLightPaintingTypes();
  return types
}

ColorReservationType15+

枚举,色彩保留类型。

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

名称 说明
NONE 0 无色彩保留效果。
PORTRAIT 1 人像留色。

ColorReservationQuery15+

提供了查询设备支持的色彩保留类型的功能。

getSupportedColorReservationTypes15+

getSupportedColorReservationTypes(): Array<ColorReservationType>

获取支持的色彩保留类型列表。

系统接口: 此接口为系统接口。

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

返回值

类型 说明
Array<ColorReservationType> 支持的色彩保留类型列表。

错误码

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
202 Not System Application.
7400103 Session not config, only throw in session usage.

示例

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

function getSupportedColorReservationTypes(session: camera.VideoSessionForSys): Array<camera.ColorReservationType> {
  let colorReservationTypes: Array<camera.ColorReservationType> = [];
  try {
    colorReservationTypes = session.getSupportedColorReservationTypes();
  } catch (error) {
    // 失败返回错误码error.code并处理。
    let err = error as BusinessError;
    console.error(`The getSupportedColorReservationTypes call failed. error code: ${err.code}`);
  }
  return colorReservationTypes;
}

ColorReservation15+

ColorReservation extends ColorReservationQuery

提供了获取和设置相机色彩保留类型的方法。

setColorReservation15+

setColorReservation(type: ColorReservationType): void

设置色彩保留类型。可以先通过getSupportedColorReservationTypes获取当前设备所支持的ColorReservationType。

系统接口: 此接口为系统接口。

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

参数

参数名 类型 必填 说明
type ColorReservationType 色彩保留类型,通过getSupportedColorReservationTypes接口获取。

错误码

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
202 Not System Application.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3.Parameter verification failed.
7400102 Operation not allowed.
7400103 Session not config.
7400201 Camera service fatal error.

示例

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

function setColorReservation(session: camera.VideoSessionForSys, type: camera.ColorReservationType): void {
  try {
    session.setColorReservation(type);
  } catch (error) {
    // 失败返回错误码error.code并处理。
    let err = error as BusinessError;
    console.error(`The setColorReservation call failed. error code: ${err.code}`);
  }
}

getColorReservation15+

getColorReservation(): ColorReservationType

获取当前设置的色彩保留类型。

系统接口: 此接口为系统接口。

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

返回值

类型 说明
ColorReservationType 当前设置的色彩保留类型。

错误码

以下错误码的详细介绍请参见Camera错误码通用错误码说明文档

错误码ID 错误信息
202 Not System Application.
7400103 Session not config, only throw in session usage.

示例

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

function getColorReservation(session: camera.VideoSessionForSys): camera.ColorReservationType | undefined {
  let colorReservation: camera.ColorReservationType | undefined = undefined;
  try {
    colorReservation = session.getColorReservation();
  } catch (error) {
    // 失败返回错误码error.code并处理。
    let err = error as BusinessError;
    console.error(`The setColorReservation call failed. error code: ${err.code}`);
  }
  return colorReservation;
}