本模块为开发者提供一套简单且易于理解的相机服务接口,开发者通过调用接口可以开发相机应用。应用通过访问和操作相机硬件,实现基础操作,如预览、拍照和录像;还可以通过接口组合完成更多操作,如控制闪光灯和曝光时间、对焦或调焦等。
说明:
本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
import camera from '@ohos.multimedia.camera';
getCameraManager(context: Context): CameraManager
获取相机管理器实例,同步返回结果。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
context | Context | 是 | 应用上下文。 |
返回值:
类型 | 说明 |
---|---|
CameraManager | 相机管理器。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400101 | Parameter missing or parameter type incorrect. |
7400201 | Camera service fatal error. |
示例:
import common from '@ohos.app.ability.common';
import { BusinessError } from '@ohos.base';
function getCameraManager(context: common.BaseContext): camera.CameraManager | undefined {
let cameraManager: camera.CameraManager | undefined = undefined;
try {
cameraManager = camera.getCameraManager(context);
} catch (error) {
let err = error as BusinessError;
console.error(`The getCameraManager call failed. error code: ${err.code}`);
}
return cameraManager;
}
相机设备信息。
系统能力: SystemCapability.Multimedia.Camera.Core
名称 | 类型 | 只读 | 必填 | 说明 |
---|---|---|---|---|
cameraId | string | 是 | 是 | 相机id。 |
cameraPosition | CameraPosition | 是 | 是 | 相机位置。 |
cameraType | CameraType | 是 | 是 | 相机类型。 |
connectionType | ConnectionType | 是 | 是 | 相机连接类型。 |
cameraOrientation12+ | number | 是 | 是 | 相机旋转角度。 |
枚举,相机位置。
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.Camera.Core
名称 | 值 | 说明 |
---|---|---|
CAMERA_POSITION_UNSPECIFIED | 0 | 相机位置未指定。 |
CAMERA_POSITION_BACK | 1 | 后置相机。 |
CAMERA_POSITION_FRONT | 2 | 前置相机。 |
CAMERA_POSITION_FOLD_INNER11+ | 3 | 折叠态相机。 |
枚举,相机类型。
系统能力: SystemCapability.Multimedia.Camera.Core
名称 | 值 | 说明 |
---|---|---|
CAMERA_TYPE_DEFAULT | 0 | 相机类型未指定。 |
CAMERA_TYPE_WIDE_ANGLE | 1 | 广角相机。 |
CAMERA_TYPE_ULTRA_WIDE | 2 | 超广角相机。 |
CAMERA_TYPE_TELEPHOTO | 3 | 长焦相机。 |
CAMERA_TYPE_TRUE_DEPTH | 4 | 带景深信息的相机。 |
枚举,相机连接类型。
系统能力: SystemCapability.Multimedia.Camera.Core
名称 | 值 | 说明 |
---|---|---|
CAMERA_CONNECTION_BUILT_IN | 0 | 内置相机。 |
CAMERA_CONNECTION_USB_PLUGIN | 1 | USB连接的相机。 |
CAMERA_CONNECTION_REMOTE | 2 | 远程连接的相机。 |
枚举,相机状态。
系统能力: SystemCapability.Multimedia.Camera.Core
名称 | 值 | 说明 |
---|---|---|
CAMERA_STATUS_APPEAR | 0 | 新的相机出现。 |
CAMERA_STATUS_DISAPPEAR | 1 | 相机被移除。 |
CAMERA_STATUS_AVAILABLE | 2 | 相机可用。 |
CAMERA_STATUS_UNAVAILABLE | 3 | 相机不可用。 |
相机管理器回调返回的接口实例,表示相机状态信息。
系统能力: SystemCapability.Multimedia.Camera.Core
名称 | 类型 | 只读 | 必填 | 说明 |
---|---|---|---|---|
camera | CameraDevice | 否 | 是 | 相机信息。 |
status | CameraStatus | 否 | 是 | 相机状态。 |
相机配置信息项。
系统能力: SystemCapability.Multimedia.Camera.Core
名称 | 类型 | 只读 | 必填 | 说明 |
---|---|---|---|---|
format | CameraFormat | 是 | 是 | 输出格式。 |
size | Size | 是 | 是 | 分辨率。 |
帧率范围。
系统能力: SystemCapability.Multimedia.Camera.Core
名称 | 类型 | 只读 | 必填 | 说明 |
---|---|---|---|---|
min | number | 是 | N/A | 最小帧率。 |
max | number | 是 | N/A | 最大帧率。 |
视频配置信息项,继承Profile。
系统能力: SystemCapability.Multimedia.Camera.Core
名称 | 类型 | 只读 | 必填 | 说明 |
---|---|---|---|---|
frameRateRange | FrameRateRange | 是 | 是 | 帧率范围,fps(frames per second)。 |
相机输出能力项。
系统能力: SystemCapability.Multimedia.Camera.Core
名称 | 类型 | 只读 | 必填 | 说明 |
---|---|---|---|---|
previewProfiles | Array<Profile> | 是 | N/A | 支持的预览配置信息。 |
photoProfiles | Array<Profile> | 是 | N/A | 支持的拍照配置信息。 |
videoProfiles | Array<VideoProfile> | 是 | N/A | 支持的录像配置信息。 |
supportedMetadataObjectTypes | Array<MetadataObjectType> | 是 | N/A | 支持的metadata流类型信息。 |
枚举,相机支持模式。
系统能力: SystemCapability.Multimedia.Camera.Core
名称 | 值 | 说明 |
---|---|---|
NORMAL_PHOTO | 1 | 普通拍照模式。 |
NORMAL_VIDEO | 2 | 普通录像模式。 |
SECURE_PHOTO12+ | 12 | 安全相机模式。 |
相机错误码。
接口使用不正确以及on接口监听error状态返回。
系统能力: SystemCapability.Multimedia.Camera.Core
名称 | 值 | 说明 |
---|---|---|
INVALID_ARGUMENT | 7400101 | 参数缺失或者参数类型不对。 |
OPERATION_NOT_ALLOWED | 7400102 | 操作流程不对,不允许。 |
SESSION_NOT_CONFIG | 7400103 | session 未配置返回。 |
SESSION_NOT_RUNNING | 7400104 | session 未运行返回。 |
SESSION_CONFIG_LOCKED | 7400105 | session 配置已锁定返回。 |
DEVICE_SETTING_LOCKED | 7400106 | 设备设置已锁定返回。 |
CONFLICT_CAMERA | 7400107 | 设备重复打开返回。 |
DEVICE_DISABLED | 7400108 | 安全原因摄像头被禁用。 |
DEVICE_PREEMPTED | 7400109 | 相机被抢占导致无法使用。 |
UNRESOLVED_CONFLICTS_WITH_CURRENT_CONFIGURATIONS12+ | 7400110 | 与当前配置存在冲突。 |
SERVICE_FATAL_ERROR | 7400201 | 相机服务错误返回。 |
相机管理器类,使用前需要通过getCameraManager获取相机管理实例。
getSupportedCameras(): Array<CameraDevice>
获取支持指定的相机设备对象,同步返回结果。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
类型 | 说明 |
---|---|
Array<CameraDevice> | 相机设备列表。 |
示例:
import { BusinessError } from '@ohos.base';
function getSupportedCameras(cameraManager: camera.CameraManager): Array<camera.CameraDevice> {
let cameras: Array<camera.CameraDevice> = [];
try {
cameras = cameraManager.getSupportedCameras();
} catch (error) {
let err = error as BusinessError;
console.error(`The getSupportedCameras call failed. error code: ${err.code}`);
}
return cameras;
}
getSupportedSceneModes(camera: CameraDevice): Array<SceneMode>
获取指定的相机设备对象支持的模式,同步返回结果。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
camera | CameraDevice | 是 | 相机设备,通过 getSupportedCameras 接口获取。 |
返回值:
类型 | 说明 |
---|---|
Array<SceneMode> | 相机支持的模式列表。 |
示例:
import { BusinessError } from '@ohos.base';
function getSupportedSceneModes(cameraManager: camera.CameraManager, camera: camera.CameraDevice): Array<camera.SceneMode> {
let modes: Array<camera.SceneMode> = [];
try {
modes = cameraManager.getSupportedSceneModes(camera);
} catch (error) {
let err = error as BusinessError;
console.error(`The getSupportedSceneModes call failed. error code: ${err.code}`);
}
return modes;
}
getSupportedOutputCapability(camera: CameraDevice): CameraOutputCapability
查询相机设备支持的输出能力,同步返回结果。
说明: 从 API version 10开始支持,从API version 11开始废弃。建议使用getSupportedOutputCapability替代。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
camera | CameraDevice | 是 | 相机设备,通过 getSupportedCameras 接口获取。 |
返回值:
类型 | 说明 |
---|---|
CameraOutputCapability | 相机输出能力。 |
示例:
function getSupportedOutputCapability(camera: camera.CameraDevice, cameraManager: camera.CameraManager): camera.CameraOutputCapability {
let cameraOutputCapability: camera.CameraOutputCapability = cameraManager.getSupportedOutputCapability(camera);
return cameraOutputCapability;
}
getSupportedOutputCapability(camera: CameraDevice, mode: SceneMode): CameraOutputCapability
查询相机设备在模式下支持的输出能力,同步返回结果。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
camera | CameraDevice | 是 | 相机设备,通过 getSupportedCameras 接口获取。 |
mode | SceneMode | 是 | 相机模式,通过 getSupportedSceneModes 接口获取。 |
返回值:
类型 | 说明 |
---|---|
CameraOutputCapability | 相机输出能力。 |
示例:
function getSupportedOutputCapability(camera: camera.CameraDevice, cameraManager: camera.CameraManager, sceneMode: camera.SceneMode): camera.CameraOutputCapability {
let cameraOutputCapability: camera.CameraOutputCapability = cameraManager.getSupportedOutputCapability(camera, sceneMode);
return cameraOutputCapability;
}
isCameraMuted(): boolean
查询相机当前的禁用状态(禁用/未禁用)。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
类型 | 说明 |
---|---|
boolean | 返回true表示相机被禁用,返回false表示相机未被禁用。 |
示例:
function isCameraMuted(cameraManager: camera.CameraManager): boolean {
let isMuted: boolean = cameraManager.isCameraMuted();
return isMuted;
}
createCameraInput(camera: CameraDevice): CameraInput
使用CameraDevice对象创建CameraInput实例,同步返回结果。
需要权限: ohos.permission.CAMERA
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
camera | CameraDevice | 是 | CameraDevice对象,通过 getSupportedCameras 接口获取。 |
返回值:
类型 | 说明 |
---|---|
CameraInput | CameraInput实例。接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400101 | Parameter missing or parameter type incorrect. |
7400102 | Operation not allowed. |
7400201 | Camera service fatal error. |
示例:
import { BusinessError } from '@ohos.base';
function createCameraInput(camera: camera.CameraDevice, cameraManager: camera.CameraManager): camera.CameraInput | undefined {
let cameraInput: camera.CameraInput | undefined = undefined;
try {
cameraInput = cameraManager.createCameraInput(camera);
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The createCameraInput call failed. error code: ${err.code}`);
}
return cameraInput;
}
createCameraInput(position: CameraPosition, type: CameraType): CameraInput
根据相机位置和类型创建CameraInput实例,同步返回结果。
需要权限: ohos.permission.CAMERA
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
position | CameraPosition | 是 | 相机位置,通过 getSupportedCameras 接口获取设备,然后获取设备位置信息。 |
type | CameraType | 是 | 相机类型,通过 getSupportedCameras 接口获取设备,然后获取设备类型信息。 |
返回值:
类型 | 说明 |
---|---|
CameraInput | CameraInput实例。接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400101 | Parameter missing or parameter type incorrect. |
7400102 | Operation not allowed. |
7400201 | Camera service fatal error. |
示例:
import { BusinessError } from '@ohos.base';
function createCameraInput(camera: camera.CameraDevice, cameraManager: camera.CameraManager): camera.CameraInput | undefined {
let position: camera.CameraPosition = camera.cameraPosition;
let type: camera.CameraType = camera.cameraType;
let cameraInput: camera.CameraInput | undefined = undefined;
try {
cameraInput = cameraManager.createCameraInput(position, type);
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The createCameraInput call failed. error code: ${err.code}`);
}
return cameraInput;
}
createPreviewOutput(profile: Profile, surfaceId: string): PreviewOutput
创建预览输出对象,同步返回结果。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
profile | Profile | 是 | 支持的预览配置信息,通过getSupportedOutputCapability接口获取。 |
surfaceId | string | 是 | 从XComponent或者ImageReceiver组件获取的surfaceId。 |
返回值:
类型 | 说明 |
---|---|
PreviewOutput | PreviewOutput实例。接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400101 | Parameter missing or parameter type incorrect. |
7400201 | Camera service fatal error. |
示例:
import { BusinessError } from '@ohos.base';
function createPreviewOutput(cameraOutputCapability: camera.CameraOutputCapability, cameraManager: camera.CameraManager, surfaceId: string): camera.PreviewOutput | undefined {
let profile: camera.Profile = cameraOutputCapability.previewProfiles[0];
let previewOutput: camera.PreviewOutput | undefined = undefined;
try {
previewOutput = cameraManager.createPreviewOutput(profile, surfaceId);
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The createPreviewOutput call failed. error code: ${err.code}`);
}
return previewOutput;
}
createPhotoOutput(profile: Profile, surfaceId: string): PhotoOutput
创建拍照输出对象,同步返回结果。
说明: 从 API version 10开始支持,从API version 11开始废弃。建议使用createPhotoOutput替代。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
profile | Profile | 是 | 支持的拍照配置信息,通过getSupportedOutputCapability接口获取。 |
surfaceId | string | 是 | 从ImageReceiver获取的surfaceId。 |
返回值:
类型 | 说明 |
---|---|
PhotoOutput | PhotoOutput实例。接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400101 | Parameter missing or parameter type incorrect. |
import { BusinessError } from '@ohos.base';
function createPhotoOutput(cameraOutputCapability: camera.CameraOutputCapability, cameraManager: camera.CameraManager, surfaceId: string): camera.PhotoOutput | undefined {
let profile: camera.Profile = cameraOutputCapability.photoProfiles[0];
let photoOutput: camera.PhotoOutput | undefined = undefined;
try {
photoOutput = cameraManager.createPhotoOutput(profile, surfaceId);
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The createPhotoOutput call failed. error code: ${err.code}`);
}
return photoOutput;
}
createPhotoOutput(profile: Profile): PhotoOutput
创建拍照输出对象,同步返回结果。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
profile | Profile | 是 | 支持的拍照配置信息,通过getSupportedOutputCapability接口获取。 |
返回值:
类型 | 说明 |
---|---|
PhotoOutput | PhotoOutput实例。接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400101 | Parameter missing or parameter type incorrect. |
7400201 | Camera service fatal error. |
示例:
import { BusinessError } from '@ohos.base';
function createPhotoOutput(cameraOutputCapability: camera.CameraOutputCapability, cameraManager: camera.CameraManager): camera.PhotoOutput | undefined {
let profile: camera.Profile = cameraOutputCapability.photoProfiles[0];
let photoOutput: camera.PhotoOutput | undefined = undefined;
try {
photoOutput = cameraManager.createPhotoOutput(profile);
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The createPhotoOutput call failed. error code: ${err.code}`);
}
return photoOutput;
}
createVideoOutput(profile: VideoProfile, surfaceId: string): VideoOutput
创建录像输出对象,同步返回结果。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
profile | VideoProfile | 是 | 支持的录像配置信息,通过getSupportedOutputCapability接口获取。 |
surfaceId | string | 是 | 从AVRecorder获取的surfaceId。 |
返回值:
类型 | 说明 |
---|---|
VideoOutput | VideoOutput实例。接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400101 | Parameter missing or parameter type incorrect. |
7400201 | Camera service fatal error. |
示例:
import { BusinessError } from '@ohos.base';
function createVideoOutput(cameraOutputCapability: camera.CameraOutputCapability, cameraManager: camera.CameraManager, surfaceId: string): camera.VideoOutput | undefined {
let profile: camera.VideoProfile = cameraOutputCapability.videoProfiles[0];
let videoOutput: camera.VideoOutput | undefined = undefined;
try {
videoOutput = cameraManager.createVideoOutput(profile, surfaceId);
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The createVideoOutput call failed. error code: ${err.code}`);
}
return videoOutput;
}
createMetadataOutput(metadataObjectTypes: Array<MetadataObjectType>): MetadataOutput
创建metadata流输出对象,同步返回结果。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
metadataObjectTypes | Array<MetadataObjectType> | 是 | metadata流类型信息,通过getSupportedOutputCapability接口获取。 |
返回值:
类型 | 说明 |
---|---|
MetadataOutput | MetadataOutput实例。接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400101 | Parameter missing or parameter type incorrect. |
7400201 | Camera service fatal error. |
示例:
import { BusinessError } from '@ohos.base';
function createMetadataOutput(cameraManager: camera.CameraManager, cameraOutputCapability: camera.CameraOutputCapability): void {
let metadataObjectTypes: Array<camera.MetadataObjectType> = cameraOutputCapability.supportedMetadataObjectTypes;
let metadataOutput: camera.MetadataOutput | undefined = undefined;
try {
metadataOutput = cameraManager.createMetadataOutput(metadataObjectTypes);
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`createMetadataOutput error. error code: ${err.code}`);
}
}
createCaptureSession(): CaptureSession
创建CaptureSession实例,同步返回结果。
说明: 从 API version 10开始支持,从API version 11开始废弃。建议使用createSession替代。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
类型 | 说明 |
---|---|
CaptureSession | CaptureSession实例。接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400201 | Camera service fatal error. |
示例:
import { BusinessError } from '@ohos.base';
function createCaptureSession(cameraManager: camera.CameraManager): camera.CaptureSession | undefined {
let captureSession: camera.CaptureSession | undefined = undefined;
try {
captureSession = cameraManager.createCaptureSession();
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`createCaptureSession error. error code: ${err.code}`);
}
return captureSession;
}
createSession<T extends Session>(mode: SceneMode): T
创建指定SceneMode的Session实例,同步返回结果。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
mode | SceneMode | 是 | 相机支持的模式。 |
返回值:
类型 | 说明 |
---|---|
T extends Session | Session实例。接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400201 | Camera service fatal error. |
示例:
import { BusinessError } from '@ohos.base';
function createSession(cameraManager: camera.CameraManager, mode: camera.SceneMode): camera.Session | undefined {
let photoSession: camera.PhotoSession | undefined = undefined;
try {
photoSession = cameraManager.createSession(mode) as camera.PhotoSession;
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`createCaptureSession error. error code: ${err.code}`);
}
return photoSession;
}
on(type: 'cameraStatus', callback: AsyncCallback<CameraStatusInfo>): void
相机设备状态回调,通过注册回调函数获取相机的状态变化。使用callback异步回调。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'cameraStatus'。cameraManager对象获取成功后可监听。目前只支持对设备打开或者关闭会触发该事件并返回对应信息。 |
callback | AsyncCallback<CameraStatusInfo> | 是 | 回调函数,用于获取镜头状态变化信息。 |
示例:
import { BusinessError } from '@ohos.base';
function callback(err: BusinessError, cameraStatusInfo: camera.CameraStatusInfo): void {
console.info(`camera : ${cameraStatusInfo.camera.cameraId}`);
console.info(`status: ${cameraStatusInfo.status}`);
}
function registerCameraStatus(cameraManager: camera.CameraManager): void {
cameraManager.on('cameraStatus', callback);
}
off(type: 'cameraStatus', callback?: AsyncCallback<CameraStatusInfo>): void
相机设备状态注销回调,通过注销回调函数取消获取相机的状态变化。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'cameraStatus'。cameraManager对象获取成功后可监听。 |
callback | AsyncCallback<CameraStatusInfo> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
示例:
function unregisterCameraStatus(cameraManager: camera.CameraManager): void {
cameraManager.off('cameraStatus');
}
isTorchSupported(): boolean
检测设备是否支持手电筒。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
类型 | 说明 |
---|---|
boolean | 返回true表示设备支持手电筒。 |
示例:
function isTorchSupported(cameraManager: camera.CameraManager): boolean {
let isSupported = cameraManager.isTorchSupported();
return isSupported;
}
isTorchModeSupported(mode: TorchMode): boolean
检测是否支持设置的手电筒模式。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
mode | TorchMode | 是 | 手电筒模式。 |
返回值:
类型 | 说明 |
---|---|
boolean | 返回true表示设备支持设置的手电筒模式。 |
示例:
function isTorchModeSupported(cameraManager: camera.CameraManager, torchMode: camera.TorchMode): boolean {
let isSupported = cameraManager.isTorchModeSupported(torchMode);
return isSupported;
}
getTorchMode(): TorchMode
获取当前设备手电筒模式。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
类型 | 说明 |
---|---|
TorchMode | 返回设备当前手电筒模式。 |
示例:
function getTorchMode(cameraManager: camera.CameraManager): camera.TorchMode | undefined {
let torchMode: camera.TorchMode | undefined = undefined;
torchMode = cameraManager.getTorchMode();
return torchMode;
}
setTorchMode(mode: TorchMode): void
设置设备手电筒模式。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
mode | TorchMode | 是 | 手电筒模式。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400101 | Parameter missing or parameter type incorrect. |
7400102 | Operation not allowed. |
7400201 | Camera service fatal error. |
示例:
import { BusinessError } from '@ohos.base';
function setTorchMode(cameraManager: camera.CameraManager, torchMode: camera.TorchMode): void {
try {
cameraManager.setTorchMode(torchMode);
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The setTorchMode call failed. error code: ${err.code}`);
}
}
on(type: 'torchStatusChange', callback: AsyncCallback<TorchStatusInfo>): void
手电筒状态变化回调,通过注册回调函数获取手电筒状态变化。使用callback异步回调。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'torchStatusChange'。cameraManager对象获取成功后可监听。目前只支持手电筒打开,手电筒关闭,手电筒不可用,手电筒恢复可用会触发该事件并返回对应信息。 |
callback | AsyncCallback<TorchStatusInfo> | 是 | 回调函数,用于获取手电筒状态变化信息。 |
示例:
import { BusinessError } from '@ohos.base';
function callback(err: BusinessError, torchStatusInfo: camera.TorchStatusInfo): void {
console.info(`onTorchStatusChange, isTorchAvailable: ${torchStatusInfo.isTorchAvailable}, isTorchActive: ${torchStatusInfo.isTorchActive}, level: ${torchStatusInfo.torchLevel}`);
}
function registerTorchStatusChange(cameraManager: camera.CameraManager): void {
cameraManager.on('torchStatusChange', callback);
}
off(type: 'torchStatusChange', callback?: AsyncCallback<TorchStatusInfo>): void
手电筒状态变化注销回调,通过注销回调函数取消获取手电筒状态变化。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'torchStatusChange'。cameraManager对象获取成功后可监听。 |
callback | AsyncCallback<TorchStatusInfo> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
示例:
function unregisterTorchStatusChange(cameraManager: camera.CameraManager): void {
cameraManager.off('torchStatusChange');
}
枚举,手电筒模式。
系统能力: SystemCapability.Multimedia.Camera.Core
名称 | 值 | 说明 |
---|---|---|
OFF | 0 | 常关模式。 |
ON | 1 | 常开模式。 |
AUTO | 2 | 自动模式。 |
手电筒回调返回的接口实例,表示手电筒状态信息。
系统能力: SystemCapability.Multimedia.Camera.Core
名称 | 类型 | 只读 | 必填 | 说明 |
---|---|---|---|---|
isTorchAvailable | boolean | 是 | 是 | 手电筒是否可用。 |
isTorchActive | boolean | 是 | 是 | 手电筒是否被激活。 |
torchLevel | number | 是 | 是 | 手电筒亮度等级。取值范围为[0,1],越靠近1,亮度越大。 |
输出能力查询。
系统能力: SystemCapability.Multimedia.Camera.Core
名称 | 类型 | 只读 | 可选 | 说明 |
---|---|---|---|---|
height | number | 否 | 否 | 图像尺寸高(像素)。 |
width | number | 否 | 否 | 图像尺寸宽(像素)。 |
点坐标用于对焦、曝光配置。
系统能力: SystemCapability.Multimedia.Camera.Core
名称 | 类型 | 只读 | 必填 | 说明 |
---|---|---|---|---|
x | number | 否 | 是 | 点的x坐标。 |
y | number | 否 | 是 | 点的y坐标。 |
枚举,输出格式。
系统能力: SystemCapability.Multimedia.Camera.Core
名称 | 值 | 说明 |
---|---|---|
CAMERA_FORMAT_RGBA_8888 | 3 | RGBA_888格式的图片。 |
CAMERA_FORMAT_YUV_420_SP | 1003 | YUV_420_SP格式的图片。 |
CAMERA_FORMAT_JPEG | 2000 | JPEG格式的图片。 |
CAMERA_FORMAT_YCBCR_P01011+ | 2001 | YCBCR_P010格式的图片。 |
CAMERA_FORMAT_YCRCB_P01011+ | 2002 | YCRCB_P010格式的图片。 |
相机设备输入对象。
会话中Session使用的相机信息。
open(callback: AsyncCallback<void>): void
打开相机,通过注册回调函数获取状态。使用callback异步回调。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
callback | AsyncCallback<void> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400107 | Can not use camera cause of conflict. |
7400108 | Camera disabled cause of security reason. |
7400201 | Camera service fatal error. |
示例:
import { BusinessError } from '@ohos.base';
function openCameraInput(cameraInput: camera.CameraInput): void {
cameraInput.open((err: BusinessError) => {
if (err) {
console.error(`Failed to open the camera, error code: ${err.code}.`);
return;
}
console.info('Callback returned with camera opened.');
});
}
open(): Promise<void>
打开相机,通过Promise获取相机的状态。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
类型 | 说明 |
---|---|
Promise<void> | 无返回结果的Promise对象。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400107 | Can not use camera cause of conflict. |
7400108 | Camera disabled cause of security reason. |
7400201 | Camera service fatal error. |
示例:
import { BusinessError } from '@ohos.base';
function openCameraInput(cameraInput: camera.CameraInput): void {
cameraInput.open().then(() => {
console.info('Promise returned with camera opened.');
}).catch((error: BusinessError) => {
console.error(`Failed to open the camera, error code: ${err.code}.`);
});
}
open(isSecureEnabled: boolean): Promise<bigint>
打开相机,获取安全相机的句柄。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
isSecureEnabled | boolean | 是 | 是否使能以安全的方式打开相机。接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
返回值:
类型 | 说明 |
---|---|
Promise<bigint> | 使用Promise的方式获取打开相机句柄。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400107 | Can not use camera cause of conflict. |
7400108 | Camera disabled cause of security reason. |
7400201 | Camera service fatal error. |
示例:
import { BusinessError } from '@ohos.base';
function openCameraInput(cameraInput: camera.CameraInput): void {
cameraInput.open(true).then(() => {
console.info('Promise returned with camera opened.');
}).catch((error: BusinessError) => {
let err = error as BusinessError;
console.error(`Failed to open the camera, error code: ${err.code}.`);
});
}
close(callback: AsyncCallback<void>): void
关闭相机,通过注册回调函数获取状态。使用callback异步回调。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
callback | AsyncCallback<void> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400201 | Camera service fatal error. |
示例:
import { BusinessError } from '@ohos.base';
function closeCameraInput(cameraInput: camera.CameraInput): void {
cameraInput.close((err: BusinessError) => {
if (err) {
console.error(`Failed to close the cameras, error code: ${err.code}.`);
return;
}
console.info('Callback returned with camera closed.');
});
}
close(): Promise<void>
关闭相机,通过Promise获取状态。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
类型 | 说明 |
---|---|
Promise<void> | 无返回结果的Promise对象。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400201 | Camera service fatal error. |
示例:
import { BusinessError } from '@ohos.base';
function closeCameraInput(cameraInput: camera.CameraInput): void {
cameraInput.close().then(() => {
console.info('Promise returned with camera closed.');
}).catch((error: BusinessError) => {
console.error(`Failed to close the cameras, error code: ${error.code}.`);
});
}
on(type: 'error', camera: CameraDevice, callback: ErrorCallback): void
监听CameraInput的错误事件,通过注册回调函数获取结果。使用callback异步回调。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'error',CameraInput对象创建成功可监听。相机设备出错情况下可触发该事件并返回结果,比如设备不可用或者冲突等返回对应错误信息。 |
camera | CameraDevice | 是 | CameraDevice对象。 |
callback | ErrorCallback | 是 | 回调函数,用于获取结果。返回错误码,错误码类型CameraErrorCode。 |
示例:
import { BusinessError } from '@ohos.base';
function callback(err: BusinessError): void {
console.error(`Camera input error code: ${err.code}`);
}
function registerCameraInputError(cameraInput: camera.CameraInput, camera: camera.CameraDevice): void {
cameraInput.on('error', camera, callback);
}
off(type: 'error', camera: CameraDevice, callback?: ErrorCallback): void
注销监听CameraInput的错误事件。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'error',CameraInput对象创建成功可监听。相机设备出错情况下可触发该事件并返回结果,比如设备不可用或者冲突等返回对应错误信息。 |
camera | CameraDevice | 是 | CameraDevice对象。 |
callback | ErrorCallback | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
示例:
function unregisterCameraInputError(cameraInput: camera.CameraInput, camera: camera.CameraDevice): void {
cameraInput.off('error', camera);
}
会话中Session使用的输出信息,output的基类。
release(callback: AsyncCallback<void>): void
释放输出资源,通过注册回调函数获取结果。使用callback异步回调。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
callback | AsyncCallback<void> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400201 | Camera service fatal error. |
示例:
import { BusinessError } from '@ohos.base';
function releasePreviewOutput(previewOutput: camera.PreviewOutput): void {
previewOutput.release((err: BusinessError) => {
if (err) {
console.error(`Failed to release the Preview output instance ${err.code}`);
return;
}
console.info('Callback invoked to indicate that the preview output instance is released successfully.');
});
}
function releaseVideoOutput(videoOutput: camera.VideoOutput): void {
videoOutput.release((err: BusinessError) => {
if (err) {
console.error(`Failed to release the video output instance ${err.code}`);
return;
}
console.info('Callback invoked to indicate that the video output instance is released successfully.');
});
}
release(): Promise<void>
释放输出资源,通过Promise获取结果。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
类型 | 说明 |
---|---|
Promise<void> | 无返回结果的Promise对象。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400201 | Camera service fatal error. |
示例:
import { BusinessError } from '@ohos.base';
function releasePreviewOutput(previewOutput: camera.PreviewOutput): void {
previewOutput.release().then(() => {
console.info('Promise returned to indicate that the preview output instance is released successfully.');
}).catch((error: BusinessError) => {
console.error(`Failed to preview output release, error code: ${error.code}`);
});
}
function releaseVideoOutput(videoOutput: camera.VideoOutput): void {
videoOutput.release().then(() => {
console.info('Promise returned to indicate that the video output instance is released successfully.');
}).catch((error: BusinessError) => {
console.error(`Failed to video output release, error code: ${error.code}`);
});
}
预览输出类。继承CameraOutput。
start(callback: AsyncCallback<void>): void
开始输出预览流,通过注册回调函数获取结果。使用callback异步回调。
说明: 从 API version 10开始支持,从API version 11开始废弃。建议使用Session.start替代。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
callback | AsyncCallback<void> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config. |
示例:
import { BusinessError } from '@ohos.base';
function startPreviewOutput(previewOutput: camera.PreviewOutput): void {
previewOutput.start((err: BusinessError) => {
if (err) {
console.error(`Failed to start the preview output, error code: ${err.code}.`);
return;
}
console.info('Callback returned with preview output started.');
});
}
start(): Promise<void>
开始输出预览流,通过Promise获取结果。
说明: 从 API version 10开始支持,从API version 11开始废弃。建议使用Session.start替代。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
类型 | 说明 |
---|---|
Promise<void> | 无返回结果的Promise对象。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config. |
示例:
import { BusinessError } from '@ohos.base';
function startPreviewOutput(previewOutput: camera.PreviewOutput): void {
previewOutput.start().then(() => {
console.info('Promise returned with preview output started.');
}).catch((error: BusinessError) => {
console.error(`Failed to preview output start, error code: ${error.code}.`);
});
}
stop(callback: AsyncCallback<void>): void
停止输出预览流,通过注册回调函数获取结果。使用callback异步回调。
说明: 从 API version 10开始支持,从API version 11开始废弃。建议使用Session.stop替代。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
callback | AsyncCallback<void> | 是 | 回调函数,用于获取结果。 |
示例:
import { BusinessError } from '@ohos.base';
function stopPreviewOutput(previewOutput: camera.PreviewOutput): void {
previewOutput.stop((err: BusinessError) => {
if (err) {
console.error(`Failed to stop the preview output, error code: ${err.code}.`);
return;
}
console.info('Returned with preview output stopped.');
})
}
stop(): Promise<void>
停止输出预览流,通过Promise获取结果。
说明: 从 API version 10开始支持,从API version 11开始废弃。建议使用Session.stop替代。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
类型 | 说明 |
---|---|
Promise<void> | 无返回结果的Promise对象。 |
示例:
import { BusinessError } from '@ohos.base';
function stopPreviewOutput(previewOutput: camera.PreviewOutput): void {
previewOutput.stop().then(() => {
console.info('Callback returned with preview output stopped.');
}).catch((error: BusinessError) => {
console.error(`Failed to preview output stop, error code: ${error.code}.`);
});
}
on(type: 'frameStart', callback: AsyncCallback<void>): void
监听预览帧启动,通过注册回调函数获取结果。使用callback异步回调。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'frameStart',previewOutput创建成功可监听。底层第一次开始曝光时触发该事件并返回。 |
callback | AsyncCallback<void> | 是 | 回调函数,用于获取结果。只要有该事件返回就证明预览开始。 |
示例:
function callback(): void {
console.info('Preview frame started');
}
function registerPreviewOutputFrameStart(previewOutput: camera.PreviewOutput): void {
previewOutput.on('frameStart', callback);
}
off(type: 'frameStart', callback?: AsyncCallback<void>): void
注销监听预览帧启动。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'frameStart',previewOutput创建成功可监听。 |
callback | AsyncCallback<void> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
示例:
function unregisterPreviewOutputFrameStart(previewOutput: camera.PreviewOutput): void {
previewOutput.off('frameStart');
}
on(type: 'frameEnd', callback: AsyncCallback<void>): void
监听预览帧结束,通过注册回调函数获取结果。使用callback异步回调。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'frameEnd',previewOutput创建成功可监听。预览完全结束最后一帧时触发该事件并返回。 |
callback | AsyncCallback<void> | 是 | 回调函数,用于获取结果。只要有该事件返回就证明预览结束。 |
示例:
function callback(): void {
console.info('Preview frame ended');
}
function registerPreviewOutputFrameEnd(previewOutput: camera.PreviewOutput): void {
previewOutput.on('frameEnd', callback);
}
off(type: 'frameEnd', callback?: AsyncCallback<void>): void
注销监听预览帧结束。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'frameEnd',previewOutput创建成功可监听。 |
callback | AsyncCallback<void> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
示例:
function unregisterPreviewOutputFrameEnd(previewOutput: camera.PreviewOutput): void {
previewOutput.off('frameEnd');
}
on(type: 'error', callback: ErrorCallback): void
监听预览输出的错误事件,通过注册回调函数获取结果。使用callback异步回调。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'error',previewOutput创建成功可监听。预览接口使用错误时触发该事件,比如调用Session.start,CameraOutput.release等接口发生错误时返回对应错误信息。 |
callback | ErrorCallback | 是 | 回调函数,用于获取错误信息。返回错误码,错误码类型CameraErrorCode。 |
示例:
import { BusinessError } from '@ohos.base';
function callback(previewOutputError: BusinessError): void {
console.error(`Preview output error code: ${previewOutputError.code}`);
}
function registerPreviewOutputError(previewOutput: camera.PreviewOutput): void {
previewOutput.on('error', callback)
}
off(type: 'error', callback?: ErrorCallback): void
注销监听预览输出的错误事件。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'error',previewOutput创建成功可监听。 |
callback | ErrorCallback | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
示例:
function unregisterPreviewOutputError(previewOutput: camera.PreviewOutput): void {
previewOutput.off('error');
}
getSupportedFrameRates(): Array<FrameRateRange>
查询支持的帧率范围。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
类型 | 说明 |
---|---|
Array<FrameRateRange> | 支持的帧率范围列表 |
示例:
function getSupportedFrameRates(previewOutput: camera.PreviewOutput): Array<FrameRateRange> {
let supportedFrameRatesArray: Array<camera.FrameRateRange> = previewOutput.getSupportedFrameRates();
return supportedFrameRatesArray;
}
setFrameRate(minFps: number, maxFps: number): void
设置预览流帧率范围,设置的范围必须在支持的帧率范围内。 进行设置前,可通过getSupportedFrameRates查询支持的帧率范围。
说明: 仅在VideoSession模式下支持。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
minFps | number | 是 | 最小帧率 |
maxFps | number | 是 | 最大帧率 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400101 | Parameter missing or parameter type incorrect. |
7400110 | Unresolved conflicts with current configurations. |
示例:
function setFrameRateRange(previewOutput: camera.PreviewOutput, frameRateRange: Array<number>): void {
previewOutput.setFrameRate(frameRateRange[0], frameRateRange[1]);
}
getActiveFrameRate(): FrameRateRange
获取已设置的帧率范围。
使用setFrameRate对预览流设置过帧率后可查询。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
类型 | 说明 |
---|---|
FrameRateRange | 帧率范围 |
示例:
function getActiveFrameRate(previewOutput: camera.PreviewOutput): FrameRateRange {
let activeFrameRate: camera.FrameRateRange = previewOutput.getActiveFrameRate();
return activeFrameRate;
}
枚举,图片旋转角度。
系统能力: SystemCapability.Multimedia.Camera.Core
名称 | 值 | 说明 |
---|---|---|
ROTATION_0 | 0 | 图片旋转0度。 |
ROTATION_90 | 90 | 图片旋转90度。 |
ROTATION_180 | 180 | 图片旋转180度。 |
ROTATION_270 | 270 | 图片旋转270度。 |
图片地理位置信息。
系统能力: SystemCapability.Multimedia.Camera.Core
名称 | 类型 | 只读 | 可选 | 说明 |
---|---|---|---|---|
latitude | number | 否 | 否 | 纬度(度)。 |
longitude | number | 否 | 否 | 经度(度)。 |
altitude | number | 否 | 否 | 海拔(米)。 |
枚举,图片质量。
系统能力: SystemCapability.Multimedia.Camera.Core
名称 | 值 | 说明 |
---|---|---|
QUALITY_LEVEL_HIGH | 0 | 图片质量高。 |
QUALITY_LEVEL_MEDIUM | 1 | 图片质量中等。 |
QUALITY_LEVEL_LOW | 2 | 图片质量差。 |
拍摄照片的设置。
系统能力: SystemCapability.Multimedia.Camera.Core
名称 | 类型 | 只读 | 必填 | 说明 |
---|---|---|---|---|
quality | QualityLevel | 否 | 否 | 图片质量(默认低)。 |
rotation | ImageRotation | 否 | 否 | 图片旋转角度(默认0度,顺时针旋转)。 |
location | Location | 否 | 否 | 图片地理位置信息(默认以设备硬件信息为准)。 |
mirror | boolean | 否 | 否 | 镜像使能开关(默认关)。使用之前需要使用isMirrorSupported进行判断是否支持。 |
全质量图对象。
系统能力: SystemCapability.Multimedia.Camera.Core
名称 | 类型 | 必填 | 说明 |
---|---|---|---|
main11+ | image.Image | 是 | 全质量图Image。 |
release(): Promise<void>
释放输出资源,通过Promise获取结果。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
类型 | 说明 |
---|---|
Promise<void> | 无返回结果的Promise对象。 |
示例:
async function releasePhoto(photo: camera.Photo): Promise<void> {
await photo.release();
}
拍照会话中使用的输出信息,继承CameraOutput。
capture(callback: AsyncCallback<void>): void
以默认设置触发一次拍照,通过注册回调函数获取结果。使用callback异步回调。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
callback | AsyncCallback<void> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400104 | Session not running. |
7400201 | Camera service fatal error. |
示例:
import { BusinessError } from '@ohos.base';
function capture(photoOutput: camera.PhotoOutput): void {
photoOutput.capture((err: BusinessError) => {
if (err) {
console.error(`Failed to capture the photo, error code: ${err.code}.`);
return;
}
console.info('Callback invoked to indicate the photo capture request success.');
});
}
capture(): Promise<void>
以默认设置触发一次拍照,通过Promise获取结果。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
类型 | 说明 |
---|---|
Promise<void> | 无返回结果的Promise对象。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400104 | Session not running. |
7400201 | Camera service fatal error. |
示例:
import { BusinessError } from '@ohos.base';
function capture(photoOutput: camera.PhotoOutput): void {
photoOutput.capture().then(() => {
console.info('Promise returned to indicate that photo capture request success.');
}).catch((error: BusinessError) => {
console.error(`Failed to photo output capture, error code: ${error.code}.`);
});
}
capture(setting: PhotoCaptureSetting, callback: AsyncCallback<void>): void
以指定参数触发一次拍照,通过注册回调函数获取结果。使用callback异步回调。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
setting | PhotoCaptureSetting | 是 | 拍照设置。 |
callback | AsyncCallback<void> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400101 | Parameter missing or parameter type incorrect. |
7400104 | Session not running. |
7400201 | Camera service fatal error. |
示例:
import { BusinessError } from '@ohos.base';
function capture(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.capture(settings, (err: BusinessError) => {
if (err) {
console.error(`Failed to capture the photo, error code: ${err.code}.`);
return;
}
console.info('Callback invoked to indicate the photo capture request success.');
});
}
capture(setting: PhotoCaptureSetting): Promise<void>
以指定参数触发一次拍照,通过Promise获取结果。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
setting | PhotoCaptureSetting | 是 | 拍照设置,传入undefined类型数据按默认无参处理。 |
返回值:
类型 | 说明 |
---|---|
Promise<void> | 无返回结果的Promise对象。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400101 | Parameter missing or parameter type incorrect. |
7400104 | Session not running. |
7400201 | Camera service fatal error. |
示例:
import { BusinessError } from '@ohos.base';
function capture(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.capture(settings).then(() => {
console.info('Promise returned to indicate that photo capture request success.');
}).catch((error: BusinessError) => {
console.error(`Failed to photo output capture, error code: ${error.code}.`);
});
}
on(type: 'photoAvailable', callback: AsyncCallback<Photo>): void
注册监听全质量图上报。使用callback异步回调。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'photoAvailable',photoOutput创建成功后可监听。 |
callback | AsyncCallback<Photo> | 是 | 回调函数,用于监听全质量图上报。 |
示例:
import { BusinessError } from '@ohos.base';
import image from '@ohos.multimedia.image';
function callback(err: BusinessError, photo: camera.Photo): void {
let mainImage: image.Image = photo.main;
}
function registerPhotoOutputPhotoAvailable(photoOutput: camera.PhotoOutput): void {
photoOutput.on('photoAvailable', callback);
}
off(type: 'photoAvailable', callback?: AsyncCallback<Photo>): void
注销监听全质量图上报。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'photoAvailable',photoOutput创建成功后可监听。 |
callback | AsyncCallback<Photo> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
示例:
import { BusinessError } from '@ohos.base';
import image from '@ohos.multimedia.image';
function callback(err: BusinessError, photo: camera.Photo): void {
let mainImage: image.Image = photo.main;
}
function unRegisterPhotoOutputPhotoAvailable(photoOutput: camera.PhotoOutput): void {
photoOutput.off('photoAvailable', callback);
}
on(type: 'captureStartWithInfo', callback: AsyncCallback<CaptureStartInfo>): void
监听拍照开始,通过注册回调函数获取CaptureStartInfo。使用callback异步回调。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'captureStartWithInfo',photoOutput创建成功后可监听。 |
callback | AsyncCallback<CaptureStartInfo> | 是 | 使用callback的方式获取Capture ID。 |
示例:
import { BusinessError } from '@ohos.base';
function callback(err: BusinessError, captureStartInfo: camera.CaptureStartInfo): void {
console.info(`photo capture started, captureStartInfo : ${captureStartInfo}`);
}
function registerCaptureStartWithInfo(photoOutput: camera.PhotoOutput): void {
photoOutput.on('captureStartWithInfo', callback);
}
off(type: 'captureStartWithInfo', callback?: AsyncCallback<CaptureStartInfo>): void
注销监听拍照。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'captureStartWithInfo',photoOutput创建成功后可监听。 |
callback | AsyncCallback<CaptureStartInfo> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
示例:
import { BusinessError } from '@ohos.base';
function unRegisterCaptureStartWithInfo(photoOutput: camera.PhotoOutput): void {
photoOutput.off('captureStartWithInfo');
}
isMovingPhotoSupported(): boolean
查询是否支持动态照片拍摄。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
类型 | 说明 |
---|---|
boolean | 返回是否支持动态照片拍照,true表示支持,false表示不支持。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400201 | Camera service fatal error. |
示例:
import { BusinessError } from '@ohos.base';
function isMovingPhotoSupported(photoOutput: camera.PhotoOutput): boolean {
let isSupported: boolean = false;
try {
isSupported = photoOutput.isMovingPhotoSupported();
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The isMovingPhotoSupported call failed. error code: ${err.code}`);
}
return isSupported;
}
enableMovingPhoto(enabled: boolean): void
使能动态照片拍照。
需要权限: ohos.permission.MICROPHONE
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
enabled | boolean | 是 | true为开启动态照片,false为关闭动态照片。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
201 | permission denied. |
7400101 | Parameter missing or parameter type incorrect. |
7400201 | Camera service fatal error. |
示例:
import { BusinessError } from '@ohos.base';
function enableMovingPhoto(photoOutput: camera.PhotoOutput): void {
try {
photoOutput.enableMovingPhoto(true);
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The enableMovingPhoto call failed. error code: ${err.code}`);
}
}
on(type: 'photoAssetAvailable', callback: AsyncCallback<PhotoAsset>): void
注册监听photoAsset上报。使用callback异步回调。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'photoAssetAvailable',photoOutput创建成功后可监听。 |
callback | AsyncCallback<PhotoAsset> | 是 | 回调函数,用于监听photoAsset上报。 |
示例:
import { BusinessError } from '@ohos.base';
import photoAccessHelper from '@ohos.file.photoAccessHelper';
function photoAssetAvailableCallback(err: BusinessError, photoAsset: photoAccessHelper.PhotoAsset): void {
if (err) {
console.info(`photoAssetAvailable error: ${JSON.stringify(err)}.`);
return;
}
console.info('photoOutPutCallBack photoAssetAvailable');
// 开发者可通过photoAsset获取图片相关信息
}
function onPhotoOutputPhotoAssetAvailable(photoOutput: camera.PhotoOutput): void {
photoOutput.on('photoAssetAvailable', photoAssetAvailableCallback);
}
off(type: 'photoAssetAvailable', callback?: AsyncCallback<PhotoAsset>): void
解注册photoAsset上报。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 可选 | 说明 |
---|---|---|---|
type | string | 否 | 监听事件,固定为'photoAssetAvailable',photoOutput创建成功后可监听。 |
callback | AsyncCallback<PhotoAsset> | 是 | 需要解监听的回调方法。如果callback不为空且与此对应的监听方法一致,不为匿名方法,则解注册该方法;如果callback为空,则解监听所有回调。 |
示例:
function offPhotoOutputPhotoAssetAvailable(photoOutput: camera.PhotoOutput): void {
photoOutput.off('photoAssetAvailable');
}
isMirrorSupported(): boolean
查询是否支持镜像拍照。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
类型 | 说明 |
---|---|
boolean | 返回是否支持镜像拍照,true表示支持,false表示不支持。 |
示例:
function isMirrorSupported(photoOutput: camera.PhotoOutput): boolean {
let isSupported: boolean = photoOutput.isMirrorSupported();
return isSupported;
}
on(type: 'captureStart', callback: AsyncCallback<number>): void
监听拍照开始,通过注册回调函数获取Capture ID。使用callback异步回调。
说明: 从 API version 10开始支持,从API version 11开始废弃。建议使用on('captureStartWithInfo')替代。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'captureStart',photoOutput创建成功后可监听。每次拍照,底层开始曝光时触发该事件并返回。 |
callback | AsyncCallback<number> | 是 | 使用callback的方式获取Capture ID。 |
示例:
import { BusinessError } from '@ohos.base';
function callback(err: BusinessError, captureId: number): void {
console.info(`photo capture started, captureId : ${captureId}`);
}
function registerPhotoOutputCaptureStart(photoOutput: camera.PhotoOutput): void {
photoOutput.on('captureStart', callback);
}
off(type: 'captureStart', callback?: AsyncCallback<number>): void
注销监听拍照开始。
说明: 从 API version 10开始支持,从API version 11开始废弃。建议使用off('captureStartWithInfo')替代。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'captureStart',photoOutput创建成功后可监听。 |
callback | AsyncCallback<number> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
示例:
function unregisterPhotoOutputCaptureStart(photoOutput: camera.PhotoOutput): void {
photoOutput.off('captureStart');
}
on(type: 'frameShutter', callback: AsyncCallback<FrameShutterInfo>): void
监听拍照帧输出捕获,通过注册回调函数获取结果。使用callback异步回调。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'frameShutter',photoOutput创建成功后可监听。 |
callback | AsyncCallback<FrameShutterInfo> | 是 | 回调函数,用于获取相关信息。该回调返回意味着可以再次下发拍照请求。 |
示例:
import { BusinessError } from '@ohos.base';
function callback(err: BusinessError, frameShutterInfo: camera.FrameShutterInfo): void {
console.info(`CaptureId for frame : ${frameShutterInfo.captureId}`);
console.info(`Timestamp for frame : ${frameShutterInfo.timestamp}`);
}
function registerPhotoOutputFrameShutter(photoOutput: camera.PhotoOutput): void {
photoOutput.on('frameShutter', callback);
}
off(type: 'frameShutter', callback?: AsyncCallback<FrameShutterInfo>): void
注销监听拍照帧输出捕获。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'frameShutter',photoOutput创建成功后可监听。 |
callback | AsyncCallback<FrameShutterInfo> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
示例:
function unregisterPhotoOutputFrameShutter(photoOutput: camera.PhotoOutput): void {
photoOutput.off('frameShutter');
}
on(type: 'captureEnd', callback: AsyncCallback<CaptureEndInfo>): void
监听拍照结束,通过注册回调函数获取结果。使用callback异步回调。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'captureEnd',photoOutput创建成功后可监听。拍照完全结束可触发该事件发生并返回相应信息。 |
callback | AsyncCallback<CaptureEndInfo> | 是 | 回调函数,用于获取相关信息。 |
示例:
import { BusinessError } from '@ohos.base';
function callback(err: BusinessError, captureEndInfo: camera.CaptureEndInfo): void {
console.info(`photo capture end, captureId : ${captureEndInfo.captureId}`);
console.info(`frameCount : ${captureEndInfo.frameCount}`);
}
function registerPhotoOutputCaptureEnd(photoOutput: camera.PhotoOutput): void {
photoOutput.on('captureEnd', callback);
}
off(type: 'captureEnd', callback?: AsyncCallback<CaptureEndInfo>): void
注销监听拍照结束。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'captureEnd',photoOutput创建成功后可监听。 |
callback | AsyncCallback<CaptureEndInfo> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
示例:
function unregisterPhotoOutputCaptureEnd(photoOutput: camera.PhotoOutput): void {
photoOutput.off('captureEnd');
}
on(type: 'frameShutterEnd', callback: AsyncCallback<FrameShutterEndInfo>): void
监听拍照曝光结束捕获,通过注册回调函数获取结果。使用callback异步回调。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'frameShutterEnd',photoOutput创建成功后可监听。 |
callback | AsyncCallback<FrameShutterEndInfo> | 是 | 回调函数,用于获取相关信息。该回调返回表示拍照曝光结束。 |
示例:
import { BusinessError } from '@ohos.base';
function callback(err: BusinessError, frameShutterEndInfo: camera.FrameShutterEndInfo): void {
console.info(`CaptureId for frame : ${frameShutterEndInfo.captureId}`);
}
function registerPhotoOutputFrameShutterEnd(photoOutput: camera.PhotoOutput): void {
photoOutput.on('frameShutterEnd', callback);
}
off(type: 'frameShutterEnd', callback?: AsyncCallback<FrameShutterEndInfo>): void
注销监听拍照帧输出捕获。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'frameShutterEnd',photoOutput创建成功后可监听。 |
callback | AsyncCallback<FrameShutterEndInfo> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
示例:
function unregisterPhotoOutputFrameShutterEnd(photoOutput: camera.PhotoOutput): void {
photoOutput.off('frameShutterEnd');
}
on(type: 'captureReady', callback: AsyncCallback<void>): void
监听可拍下一张,通过注册回调函数获取结果。使用callback异步回调。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'captureReady',photoOutput创建成功后可监听。当下一张可拍时可触发该事件发生并返回相应信息。 |
callback | AsyncCallback<void> | 是 | 回调函数,用于获取相关信息。 |
示例:
import { BusinessError } from '@ohos.base';
function callback(): void {
console.info(`photo capture ready`);
}
function registerPhotoOutputcaptureReady(photoOutput: camera.PhotoOutput): void {
photoOutput.on('captureReady', callback);
}
off(type: 'captureReady', callback?: AsyncCallback<void>): void
注销监听监听可拍下一张。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'captureReady',photoOutput创建成功后可监听。 |
callback | AsyncCallback<CaptureReadyInfo> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
示例:
function unregisterPhotoOutputcaptureReady(photoOutput: camera.PhotoOutput): void {
photoOutput.off('captureReady');
}
on(type: 'estimatedCaptureDuration', callback: AsyncCallback<number>): void
监听预估的拍照时间,通过注册回调函数获取结果。使用callback异步回调。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'estimatedCaptureDuration',photoOutput创建成功后可监听。拍照完全结束可触发该事件发生并返回相应信息。 |
callback | AsyncCallback<number> | 是 | 回调函数,用于获取相关信息。 |
示例:
import { BusinessError } from '@ohos.base';
function callback(err: BusinessError, duration: number): void {
console.info(`photo estimated capture duration : ${duration}`);
}
function registerPhotoOutputEstimatedCaptureDuration(photoOutput: camera.PhotoOutput): void {
photoOutput.on('estimatedCaptureDuration', callback);
}
off(type: 'estimatedCaptureDuration', callback?: AsyncCallback<number>): void
注销监听预估的拍照时间。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'estimatedCaptureDuration',photoOutput创建成功后可监听。 |
callback | AsyncCallback<number> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
示例:
function unregisterPhotoOutputEstimatedCaptureDuration(photoOutput: camera.PhotoOutput): void {
photoOutput.off('estimatedCaptureDuration');
}
on(type: 'error', callback: ErrorCallback): void
监听拍照输出发生错误,通过注册回调函数获取结果。使用callback异步回调。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'error',photoOutput创建成功后可监听。拍照接口调用时出现错误触发该事件并返回错误信息。 |
callback | ErrorCallback | 是 | 回调函数,用于获取错误信息。返回错误码,错误码类型CameraErrorCode。 |
示例:
import { BusinessError } from '@ohos.base';
function callback(err: BusinessError): void {
console.error(`Photo output error code: ${err.code}`);
}
function registerPhotoOutputError(photoOutput: camera.PhotoOutput): void {
photoOutput.on('error', callback);
}
off(type: 'error', callback?: ErrorCallback): void
注销监听拍照输出发生错误。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'error',photoOutput创建成功后可监听。 |
callback | ErrorCallback | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
示例:
function unregisterPhotoOutputError(photoOutput: camera.PhotoOutput): void {
photoOutput.off('error');
}
拍照帧输出信息。
系统能力: SystemCapability.Multimedia.Camera.Core
名称 | 类型 | 只读 | 必填 | 说明 |
---|---|---|---|---|
captureId | number | 否 | 是 | 拍照的ID。 |
timestamp | number | 否 | 是 | 快门时间戳。 |
拍照曝光结束信息。
系统能力: SystemCapability.Multimedia.Camera.Core
名称 | 类型 | 只读 | 必填 | 说明 |
---|---|---|---|---|
captureId | number | 否 | 是 | 拍照的ID。 |
拍照开始信息。
系统能力: SystemCapability.Multimedia.Camera.Core
名称 | 类型 | 只读 | 必填 | 说明 |
---|---|---|---|---|
captureId | number | 否 | 是 | 拍照的ID。 |
time | number | 否 | 是 | 拍照时间戳。 |
拍照停止信息。
系统能力: SystemCapability.Multimedia.Camera.Core
名称 | 类型 | 只读 | 必填 | 说明 |
---|---|---|---|---|
captureId | number | 否 | 是 | 拍照的ID。 |
frameCount | number | 否 | 是 | 帧数。 |
录像会话中使用的输出信息,继承CameraOutput。
start(callback: AsyncCallback<void>): void
启动录制,通过注册回调函数获取结果。使用callback异步回调。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
callback | AsyncCallback<void> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config. |
7400201 | Camera service fatal error. |
示例:
import { BusinessError } from '@ohos.base';
function startVideoOutput(videoOutput: camera.VideoOutput): void {
videoOutput.start((err: BusinessError) => {
if (err) {
console.error(`Failed to start the video output, error code: ${err.code}.`);
return;
}
console.info('Callback invoked to indicate the video output start success.');
});
}
start(): Promise<void>
启动录制,通过Promise获取结果。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
类型 | 说明 |
---|---|
Promise<void> | 无返回结果的Promise对象。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config. |
7400201 | Camera service fatal error. |
示例:
import { BusinessError } from '@ohos.base';
function startVideoOutput(videoOutput: camera.VideoOutput): void {
videoOutput.start().then(() => {
console.info('Promise returned to indicate that start method execution success.');
}).catch((error: BusinessError) => {
console.error(`Failed to video output start, error code: ${error.code}.`);
});
}
stop(callback: AsyncCallback<void>): void
结束录制,通过注册回调函数获取结果。使用callback异步回调。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
callback | AsyncCallback<void> | 是 | 回调函数,用于获取结果。 |
示例:
import { BusinessError } from '@ohos.base';
function stopVideoOutput(videoOutput: camera.VideoOutput): void {
videoOutput.stop((err: BusinessError) => {
if (err) {
console.error(`Failed to stop the video output, error code: ${err.code}.`);
return;
}
console.info('Callback invoked to indicate the video output stop success.');
});
}
stop(): Promise<void>
结束录制,通过Promise获取结果。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
类型 | 说明 |
---|---|
Promise<void> | 无返回结果的Promise对象。 |
示例:
import { BusinessError } from '@ohos.base';
function stopVideoOutput(videoOutput: camera.VideoOutput): void {
videoOutput.stop().then(() => {
console.info('Promise returned to indicate that stop method execution success.');
}).catch((error: BusinessError) => {
console.error(`Failed to video output stop, error code: ${error.code}.`);
});
}
on(type: 'frameStart', callback: AsyncCallback<void>): void
监听录像开始,通过注册回调函数获取结果。使用callback异步回调。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'frameStart',videoOutput创建成功后可监听。底层第一次曝光时触发该事件并返回。 |
callback | AsyncCallback<void> | 是 | 回调函数,用于获取结果。 只要有该事件返回就证明录像开始。 |
示例:
function callback(): void {
console.info('Video frame started');
}
function registerVideoOutputFrameStart(videoOutput: camera.VideoOutput): void {
videoOutput.on('frameStart', callback);
}
off(type: 'frameStart', callback?: AsyncCallback<void>): void
注销监听录像开始。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'frameStart',videoOutput创建成功后可监听。 |
callback | AsyncCallback<void> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
示例:
function unregisterVideoOutputFrameStart(videoOutput: camera.VideoOutput): void {
videoOutput.off('frameStart');
}
on(type: 'frameEnd', callback: AsyncCallback<void>): void
监听录像结束,通过注册回调函数获取结果。使用callback异步回调。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'frameEnd',videoOutput创建成功后可监听。录像完全结束最后一帧时触发该事件并返回。 |
callback | AsyncCallback<void> | 是 | 回调函数,用于获取结果。 只要有该事件返回就证明录像结束。 |
示例:
function callback(): void {
console.info('Video frame ended');
}
function registerVideoOutputFrameEnd(videoOutput: camera.VideoOutput): void {
videoOutput.on('frameEnd', callback);
}
off(type: 'frameEnd', callback?: AsyncCallback<void>): void
注销监听录像结束。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'frameEnd',videoOutput创建成功后可监听。 |
callback | AsyncCallback<void> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
示例:
function unregisterVideoOutputFrameEnd(videoOutput: camera.VideoOutput): void {
videoOutput.off('frameEnd');
}
on(type: 'error', callback: ErrorCallback): void
监听录像输出发生错误,通过注册回调函数获取结果。使用callback异步回调。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'error',videoOutput创建成功后可监听。录像接口调用出现错误时触发该事件并返回对应错误码,比如调用start,CameraOutput.release接口时出现错误返回对应错误信息。 |
callback | ErrorCallback | 是 | 回调函数,用于获取错误信息。返回错误码,错误码类型CameraErrorCode。 |
示例:
import { BusinessError } from '@ohos.base';
function callback(err: BusinessError): void {
console.error(`Video output error code: ${err.code}`);
}
function registerVideoOutputError(videoOutput: camera.VideoOutput): void {
videoOutput.on('error', callback);
}
off(type: 'error', callback?: ErrorCallback): void
注销监听录像输出发生错误。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'error',photoOutput创建成功后可监听。 |
callback | ErrorCallback | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
示例:
function unregisterVideoOutputError(videoOutput: camera.VideoOutput): void {
videoOutput.off('error');
}
getSupportedFrameRates(): Array<FrameRateRange>
查询支持的帧率范围。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
类型 | 说明 |
---|---|
Array<FrameRateRange> | 支持的帧率范围列表 |
示例:
function getSupportedFrameRates(videoOutput: camera.VideoOutput): Array<FrameRateRange> {
let supportedFrameRatesArray: Array<camera.FrameRateRange> = videoOutput.getSupportedFrameRates();
return supportedFrameRatesArray;
}
setFrameRate(minFps: number, maxFps: number): void
设置预览流帧率范围,设置的范围必须在支持的帧率范围内。
进行设置前,可通过getSupportedFrameRates查询支持的帧率范围。
说明: 仅在VideoSession模式下支持。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
minFps | number | 是 | 最小帧率 |
maxFps | number | 是 | 最大帧率 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400101 | Parameter missing or parameter type incorrect. |
7400110 | Unresolved conflicts with current configurations. |
示例:
function setFrameRateRange(videoOutput: camera.VideoOutput, frameRateRange: Array<number>): void {
videoOutput.setFrameRate(frameRateRange[0], frameRateRange[1]);
}
getActiveFrameRate(): FrameRateRange
获取已设置的帧率范围。
使用setFrameRate对预览流设置过帧率后可查询。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
类型 | 说明 |
---|---|
FrameRateRange | 帧率范围 |
示例:
function getActiveFrameRate(videoOutput: camera.VideoOutput): FrameRateRange {
let activeFrameRate: camera.FrameRateRange = videoOutput.getActiveFrameRate();
return activeFrameRate;
}
metadata流。继承CameraOutput。
start(callback: AsyncCallback<void>): void
开始输出metadata,通过注册回调函数获取结果。使用callback异步回调。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
callback | AsyncCallback<void> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config. |
7400201 | Camera service fatal error. |
示例:
import { BusinessError } from '@ohos.base';
function startMetadataOutput(metadataOutput: camera.MetadataOutput): void {
metadataOutput.start((err: BusinessError) => {
if (err) {
console.error(`Failed to start metadata output, error code: ${err.code}.`);
return;
}
console.info('Callback returned with metadata output started.');
});
}
start(): Promise<void>
开始输出metadata,通过Promise获取结果。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
类型 | 说明 |
---|---|
Promise<void> | 无返回结果的Promise对象。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config. |
7400201 | Camera service fatal error. |
示例:
import { BusinessError } from '@ohos.base';
function startMetadataOutput(metadataOutput: camera.MetadataOutput): void {
metadataOutput.start().then(() => {
console.info('Callback returned with metadata output started.');
}).catch((error: BusinessError) => {
console.error(`Failed to metadata output stop, error code: ${error.code}`);
});
}
stop(callback: AsyncCallback<void>): void
停止输出metadata,通过注册回调函数获取结果。使用callback异步回调。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
callback | AsyncCallback<void> | 是 | 回调函数,用于获取结果。 |
示例:
import { BusinessError } from '@ohos.base';
function stopMetadataOutput(metadataOutput: camera.MetadataOutput): void {
metadataOutput.stop((err: BusinessError) => {
if (err) {
console.error(`Failed to stop the metadata output, error code: ${err.code}.`);
return;
}
console.info('Callback returned with metadata output stopped.');
})
}
stop(): Promise<void>
停止输出metadata,通过Promise获取结果。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
类型 | 说明 |
---|---|
Promise<void> | 无返回结果的Promise对象。 |
示例:
import { BusinessError } from '@ohos.base';
function stopMetadataOutput(metadataOutput: camera.MetadataOutput): void {
metadataOutput.stop().then(() => {
console.info('Callback returned with metadata output stopped.');
}).catch((error: BusinessError) => {
console.error(`Failed to metadata output stop, error code: ${error.code}`);
});
}
on(type: 'metadataObjectsAvailable', callback: AsyncCallback<Array<MetadataObject>>): void
监听检测到的metadata对象,通过注册回调函数获取结果。使用callback异步回调。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'metadataObjectsAvailable',metadataOutput创建成功后可监听。检测到有效的metadata数据时触发该事件发生并返回相应的metadata数据。 |
callback | AsyncCallback<Array<MetadataObject>> | 是 | 回调函数,用于获取metadata数据。 |
示例:
import { BusinessError } from '@ohos.base';
function callback(err: BusinessError, metadataObjectArr: Array<camera.MetadataObject>): void {
console.info('metadata output metadataObjectsAvailable');
}
function registerMetadataObjectsAvailable(metadataOutput: camera.MetadataOutput): void {
metadataOutput.on('metadataObjectsAvailable', callback);
}
off(type: 'metadataObjectsAvailable', callback?: AsyncCallback<Array<MetadataObject>>): void
注销监听检测到的metadata对象。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'metadataObjectsAvailable',metadataOutput创建成功后可监听。 |
callback | AsyncCallback<Array<MetadataObject>> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
示例:
function unregisterMetadataObjectsAvailable(metadataOutput: camera.MetadataOutput): void {
metadataOutput.off('metadataObjectsAvailable');
}
on(type: 'error', callback: ErrorCallback): void
监听metadata流的错误,通过注册回调函数获取结果。使用callback异步回调。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'error',metadataOutput创建成功后可监听。metadata接口使用错误时触发该事件并返回对应错误码,比如调用start,CameraOutput.release接口时发生错误返回对应错误信息。 |
callback | ErrorCallback | 是 | 回调函数,用于获取错误信息。返回错误码,错误码类型CameraErrorCode。 |
示例:
import { BusinessError } from '@ohos.base';
function callback(metadataOutputError: BusinessError): void {
console.error(`Metadata output error code: ${metadataOutputError.code}`);
}
function registerMetadataOutputError(metadataOutput: camera.MetadataOutput): void {
metadataOutput.on('error', callback);
}
off(type: 'error', callback?: ErrorCallback): void
注销监听metadata流的错误。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'error',metadataOutput创建成功后可监听。 |
callback | ErrorCallback | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
示例:
function unregisterMetadataOutputError(metadataOutput: camera.MetadataOutput): void {
metadataOutput.off('error');
}
枚举,metadata流。
系统能力: SystemCapability.Multimedia.Camera.Core
名称 | 值 | 说明 |
---|---|---|
FACE_DETECTION | 0 | metadata对象类型,用于人脸检测。 检测点应在0-1坐标系内,该坐标系左上角为(0,0),右下角为(1,1)。 此坐标系以设备充电口在右侧时的横向设备方向为基准。 例如应用的预览界面布局以设备充电口在下侧时的竖向方向为基准, 布局宽高为(w,h), 返回点为(x,y),则转换后的坐标点为(1-y,x)。 |
矩形定义。
系统能力: SystemCapability.Multimedia.Camera.Core
名称 | 类型 | 只读 | 可选 | 说明 |
---|---|---|---|---|
topLeftX | number | 否 | 否 | 矩形区域左上角x坐标。 |
topLeftY | number | 否 | 否 | 矩形区域左上角y坐标。 |
width | number | 否 | 否 | 矩形宽,相对值,范围[0, 1]。 |
height | number | 否 | 否 | 矩形高,相对值,范围[0, 1]。 |
相机元能力信息,CameraInput相机信息中的数据来源,通过metadataOutput.on('metadataObjectsAvailable')接口获取。
系统能力: SystemCapability.Multimedia.Camera.Core
名称 | 类型 | 只读 | 必填 | 说明 |
---|---|---|---|---|
type | MetadataObjectType | 是 | 是 | metadata 类型。 |
timestamp | number | 是 | 是 | 当前时间戳(毫秒)。 |
boundingBox | Rect | 是 | 是 | metadata 区域框。 |
枚举,闪光灯模式。
系统能力: SystemCapability.Multimedia.Camera.Core
名称 | 值 | 说明 |
---|---|---|
FLASH_MODE_CLOSE | 0 | 闪光灯关闭。 |
FLASH_MODE_OPEN | 1 | 闪光灯打开。 |
FLASH_MODE_AUTO | 2 | 自动闪光灯。 |
FLASH_MODE_ALWAYS_OPEN | 3 | 闪光灯常亮。 |
枚举,曝光模式。
系统能力: SystemCapability.Multimedia.Camera.Core
名称 | 值 | 说明 |
---|---|---|
EXPOSURE_MODE_LOCKED | 0 | 锁定曝光模式。不支持曝光区域中心点设置。 |
EXPOSURE_MODE_AUTO | 1 | 自动曝光模式。支持曝光区域中心点设置,可以使用AutoExposure.setMeteringPoint设置曝光区域中心点。 |
EXPOSURE_MODE_CONTINUOUS_AUTO | 2 | 连续自动曝光。不支持曝光区域中心点设置。 |
枚举,焦距模式。
系统能力: SystemCapability.Multimedia.Camera.Core
名称 | 值 | 说明 |
---|---|---|
FOCUS_MODE_MANUAL | 0 | 手动对焦。通过手动修改相机焦距来改变对焦位置,不支持对焦点设置。 |
FOCUS_MODE_CONTINUOUS_AUTO | 1 | 连续自动对焦。不支持对焦点设置。 |
FOCUS_MODE_AUTO | 2 | 自动对焦。支持对焦点设置,可以使用Focus.setFocusPoint设置对焦点,根据对焦点执行一次自动对焦。 |
FOCUS_MODE_LOCKED | 3 | 对焦锁定。不支持对焦点设置。 |
枚举,焦距状态。
系统能力: SystemCapability.Multimedia.Camera.Core
名称 | 值 | 说明 |
---|---|---|
FOCUS_STATE_SCAN | 0 | 触发对焦。 |
FOCUS_STATE_FOCUSED | 1 | 对焦成功。 |
FOCUS_STATE_UNFOCUSED | 2 | 未完成对焦。 |
枚举,视频防抖模式。
系统能力: SystemCapability.Multimedia.Camera.Core
名称 | 值 | 说明 |
---|---|---|
OFF | 0 | 关闭视频防抖功能。 |
LOW | 1 | 使用基础防抖算法。 |
MIDDLE | 2 | 使用防抖效果一般的防抖算法,防抖效果优于LOW类型。 |
HIGH | 3 | 使用防抖效果最好的防抖算法,防抖效果优于MIDDLE类型。 |
AUTO | 4 | 自动进行选择。 |
会话类,保存一次相机运行所需要的所有资源CameraInput、CameraOutput,并向相机设备申请完成相机功能(录像,拍照)。
beginConfig(): void
开始配置会话。
系统能力: SystemCapability.Multimedia.Camera.Core
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400105 | Session config locked. |
7400201 | Camera service fatal error. |
示例:
import { BusinessError } from '@ohos.base';
function beginConfig(session: camera.Session): void {
try {
session.beginConfig();
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The beginConfig call failed. error code: ${err.code}`);
}
}
commitConfig(callback: AsyncCallback<void>): void
提交配置信息,通过注册回调函数获取结果。使用callback异步回调。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
callback | AsyncCallback<void> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400102 | Operation not allowed. |
7400201 | Camera service fatal error. |
示例:
import { BusinessError } from '@ohos.base';
function commitConfig(session: camera.Session): void {
session.commitConfig((err: BusinessError) => {
if (err) {
console.error(`The commitConfig call failed. error code: ${err.code}`);
return;
}
console.info('Callback invoked to indicate the commit config success.');
});
}
commitConfig(): Promise<void>
提交配置信息,通过Promise获取结果。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
类型 | 说明 |
---|---|
Promise<void> | 无返回结果的Promise对象。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400102 | Operation not allowed. |
7400201 | Camera service fatal error. |
示例:
import { BusinessError } from '@ohos.base';
function commitConfig(session: camera.Session): void {
session.commitConfig().then(() => {
console.info('Promise returned to indicate the commit config success.');
}).catch((error: BusinessError) => {
// 失败返回错误码error.code并处理
console.error(`The commitConfig call failed. error code: ${error.code}`);
});
}
canAddInput(cameraInput: CameraInput): boolean
判断当前cameraInput是否可以添加到session中。当前函数需要在beginConfig和commitConfig之间生效。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
cameraInput | CameraInput | 是 | 需要添加的CameraInput实例。 |
返回值:
类型 | 说明 |
---|---|
boolean | 返回true表示支持添加当前cameraInput,返回false表示不支持添加。 |
示例:
import { BusinessError } from '@ohos.base';
function canAddInput(session: camera.Session, cameraInput: camera.CameraInput): void {
let canAdd: boolean = session.canAddInput(cameraInput);
console.info(`The input canAddInput: ${canAdd}`);
}
addInput(cameraInput: CameraInput): void
把CameraInput加入到会话。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
cameraInput | CameraInput | 是 | 需要添加的CameraInput实例。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400101 | Parameter missing or parameter type incorrect. |
7400102 | Operation not allowed. |
7400103 | Session not config. |
7400201 | Camera service fatal error. |
示例:
import { BusinessError } from '@ohos.base';
function addInput(session: camera.Session, cameraInput: camera.CameraInput): void {
try {
session.addInput(cameraInput);
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The addInput call failed. error code: ${err.code}`);
}
}
removeInput(cameraInput: CameraInput): void
移除CameraInput。当前函数需要在beginConfig和commitConfig之间生效。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
cameraInput | CameraInput | 是 | 需要移除的CameraInput实例。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400101 | Parameter missing or parameter type incorrect. |
7400102 | Operation not allowed. |
7400103 | Session not config. |
7400201 | Camera service fatal error. |
示例:
import { BusinessError } from '@ohos.base';
function removeInput(session: camera.Session, cameraInput: camera.CameraInput): void {
try {
session.removeInput(cameraInput);
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The removeInput call failed. error code: ${err.code}`);
}
}
canAddOutput(cameraOutput: CameraOutput): boolean
判断当前cameraOutput是否可以添加到session中。当前函数需要在addInput和commitConfig之间生效。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
cameraOutput | CameraOutput | 是 | 需要添加的CameraOutput实例。 |
返回值:
类型 | 说明 |
---|---|
boolean | 是否可以添加当前cameraOutput到session中。 |
示例:
import { BusinessError } from '@ohos.base';
function canAddOutput(session: camera.Session, cameraOutput: camera.CameraOutput): void {
let canAdd: boolean = session.canAddOutput(cameraOutput);
console.info(`This addOutput can add: ${canAdd}`);
}
addOutput(cameraOutput: CameraOutput): void
把CameraOutput加入到会话。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
cameraOutput | CameraOutput | 是 | 需要添加的CameraOutput实例。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400101 | Parameter missing or parameter type incorrect. |
7400102 | Operation not allowed. |
7400103 | Session not config. |
7400201 | Camera service fatal error. |
示例:
import { BusinessError } from '@ohos.base';
function addOutput(session: camera.Session, cameraOutput: camera.CameraOutput): void {
try {
session.addOutput(cameraOutput);
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The addOutput call failed. error code: ${err.code}`);
}
}
removeOutput(cameraOutput: CameraOutput): void
从会话中移除CameraOutput。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
cameraOutput | CameraOutput | 是 | 需要移除的CameraOutput实例。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400101 | Parameter missing or parameter type incorrect. |
7400102 | Operation not allowed. |
7400103 | Session not config. |
7400201 | Camera service fatal error. |
示例:
import { BusinessError } from '@ohos.base';
function removeOutput(session: camera.Session, previewOutput: camera.PreviewOutput): void {
try {
session.removeOutput(previewOutput);
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The removeOutput call failed. error code: ${err.code}`);
}
}
start(callback: AsyncCallback<void>): void
开始会话工作,通过注册回调函数获取结果。使用callback异步回调。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
callback | AsyncCallback<void> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400102 | Operation not allowed. |
7400103 | Session not config. |
7400201 | Camera service fatal error. |
示例:
import { BusinessError } from '@ohos.base';
function startCaptureSession(session: camera.Session): void {
session.start((err: BusinessError) => {
if (err) {
console.error(`Failed to start the session, error code: ${err.code}.`);
return;
}
console.info('Callback invoked to indicate the session start success.');
});
}
start(): Promise<void>
开始会话工作,通过Promise获取结果。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
类型 | 说明 |
---|---|
Promise<void> | 无返回结果的Promise对象。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400102 | Operation not allowed. |
7400103 | Session not config. |
7400201 | Camera service fatal error. |
示例:
import { BusinessError } from '@ohos.base';
function startCaptureSession(session: camera.Session): void {
session.start().then(() => {
console.info('Promise returned to indicate the session start success.');
}).catch((error: BusinessError) => {
console.error(`Failed to start the session, error code: ${error.code}.`);
});
}
stop(callback: AsyncCallback<void>): void
停止会话工作,通过注册回调函数获取结果。使用callback异步回调。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
callback | AsyncCallback<void> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400201 | Camera service fatal error. |
示例:
import { BusinessError } from '@ohos.base';
function stopCaptureSession(session: camera.Session): void {
session.stop((err: BusinessError) => {
if (err) {
console.error(`Failed to stop the session, error code: ${err.code}.`);
return;
}
console.info('Callback invoked to indicate the session stop success.');
});
}
stop(): Promise<void>
停止会话工作,通过Promise获取结果。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
类型 | 说明 |
---|---|
Promise<void> | 无返回结果的Promise对象。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400201 | Camera service fatal error. |
示例:
import { BusinessError } from '@ohos.base';
function stopCaptureSession(session: camera.Session): void {
session.stop().then(() => {
console.info('Promise returned to indicate the session stop success.');
}).catch((error: BusinessError) => {
console.error(`Failed to stop the session, error code: ${error.code}.`);
});
}
release(callback: AsyncCallback<void>): void
释放会话资源,通过注册回调函数获取结果。使用callback异步回调。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
callback | AsyncCallback<void> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400201 | Camera service fatal error. |
示例:
import { BusinessError } from '@ohos.base';
function releaseCaptureSession(session: camera.Session): void {
session.release((err: BusinessError) => {
if (err) {
console.error(`Failed to release the session instance, error code: ${err.code}.`);
return;
}
console.info('Callback invoked to indicate that the session instance is released successfully.');
});
}
release(): Promise<void>
释放会话资源,通过Promise获取结果。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
类型 | 说明 |
---|---|
Promise<void> | 无返回结果的Promise对象。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400201 | Camera service fatal error. |
示例:
import { BusinessError } from '@ohos.base';
function releaseCaptureSession(session: camera.Session): void {
session.release().then(() => {
console.info('Promise returned to indicate that the session instance is released successfully.');
}).catch((error: BusinessError) => {
console.error(`Failed to release the session instance, error code: ${error.code}.`);
});
}
Flash extends FlashQuery
闪光灯类,对设备闪光灯操作。
setFlashMode(flashMode: FlashMode): void
设置闪光灯模式。
进行设置之前,需要先检查:
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
flashMode | FlashMode | 是 | 指定闪光灯模式。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config. |
示例:
import { BusinessError } from '@ohos.base';
function setFlashMode(photoSession: camera.PhotoSession): void {
try {
photoSession.setFlashMode(camera.FlashMode.FLASH_MODE_AUTO);
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The setFlashMode call failed. error code: ${err.code}`);
}
}
getFlashMode(): FlashMode
获取当前设备的闪光灯模式。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
类型 | 说明 |
---|---|
FlashMode | 获取当前设备的闪光灯模式。接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config. |
示例:
import { BusinessError } from '@ohos.base';
function getFlashMode(photoSession: camera.PhotoSession): camera.FlashMode | undefined {
let flashMode: camera.FlashMode | undefined = undefined;
try {
flashMode = photoSession.getFlashMode();
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The getFlashMode call failed.error code: ${err.code}`);
}
return flashMode;
}
提供了查询设备的闪光灯状态和模式的能力。
hasFlash(): boolean
检测是否有闪光灯,通过注册回调函数获取结果。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
类型 | 说明 |
---|---|
boolean | 返回true表示设备支持闪光灯,false表示不支持。接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config. |
示例:
import { BusinessError } from '@ohos.base';
function hasFlash(photoSession: camera.PhotoSession): boolean {
let status: boolean = false;
try {
status = photoSession.hasFlash();
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The hasFlash call failed. error code: ${err.code}`);
}
return status;
}
isFlashModeSupported(flashMode: FlashMode): boolean
检测闪光灯模式是否支持。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
flashMode | FlashMode | 是 | 指定闪光灯模式。 |
返回值:
类型 | 说明 |
---|---|
boolean | 返回true表示支持该闪光灯模式,false表示不支持。接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config. |
示例:
import { BusinessError } from '@ohos.base';
function isFlashModeSupported(photoSession: camera.PhotoSession): boolean {
let status: boolean = false;
try {
status = photoSession.isFlashModeSupported(camera.FlashMode.FLASH_MODE_AUTO);
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The isFlashModeSupported call failed. error code: ${err.code}`);
}
return status;
}
AutoExposure extends AutoExposureQuery
自动曝光类,对设备自动曝光(AE)操作。
getExposureMode(): ExposureMode
获取当前曝光模式。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
类型 | 说明 |
---|---|
ExposureMode | 获取当前曝光模式。接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config. |
示例:
import { BusinessError } from '@ohos.base';
function getExposureMode(photoSession: camera.PhotoSession): camera.ExposureMode | undefined {
let exposureMode: camera.ExposureMode | undefined = undefined;
try {
exposureMode = photoSession.getExposureMode();
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The getExposureMode call failed. error code: ${err.code}`);
}
return exposureMode;
}
setExposureMode(aeMode: ExposureMode): void
设置曝光模式。进行设置之前,需要先检查设备是否支持指定的曝光模式,可使用方法isExposureModeSupported。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
aeMode | ExposureMode | 是 | 曝光模式。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config. |
示例:
import { BusinessError } from '@ohos.base';
function setExposureMode(photoSession: camera.PhotoSession): void {
try {
photoSession.setExposureMode(camera.ExposureMode.EXPOSURE_MODE_LOCKED);
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The setExposureMode call failed. error code: ${err.code}`);
}
}
getMeteringPoint(): Point
查询曝光区域中心点。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
类型 | 说明 |
---|---|
Point | 获取当前曝光点。接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config. |
示例:
import { BusinessError } from '@ohos.base';
function getMeteringPoint(photoSession: camera.PhotoSession): camera.Point | undefined {
let exposurePoint: camera.Point | undefined = undefined;
try {
exposurePoint = photoSession.getMeteringPoint();
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The getMeteringPoint call failed. error code: ${err.code}`);
}
return exposurePoint;
}
setMeteringPoint(point: Point): void
设置曝光区域中心点,曝光点应在0-1坐标系内,该坐标系左上角为{0,0},右下角为{1,1}。
此坐标系是以设备充电口在右侧时的横向设备方向为基准的,例如应用的预览界面布局以
设备充电口在下侧时的竖向方向为基准,布局宽高为{w,h},且触碰点为{x,y},
则转换后的坐标点为{y/h,1-x/w}。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
point | Point | 是 | 曝光点,x、y设置范围应在[0,1]之内,超过范围,如果小于0设置0,大于1设置1。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config. |
示例:
import { BusinessError } from '@ohos.base';
function setMeteringPoint(photoSession: camera.PhotoSession): void {
const point: camera.Point = {x: 1, y: 1};
try {
photoSession.setMeteringPoint(point);
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The setMeteringPoint call failed. error code: ${err.code}`);
}
}
setExposureBias(exposureBias: number): void
设置曝光补偿,曝光补偿值(EV)。
进行设置之前,建议先通过方法getExposureBiasRange查询支持的范围。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
exposureBias | number | 是 | 曝光补偿,getExposureBiasRange查询支持的范围,如果设置超过支持范围的值,自动匹配到就近临界点。 曝光补偿存在步长,如步长为0.5。则设置1.2时,获取到实际生效曝光补偿为1.0。 接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400102 | Operation not allowed. |
7400103 | Session not config. |
示例:
import { BusinessError } from '@ohos.base';
function setExposureBias(photoSession: camera.PhotoSession, biasRangeArray: Array<number>): void {
if (biasRangeArray && biasRangeArray.length > 0) {
let exposureBias = biasRangeArray[0];
try {
photoSession.setExposureBias(exposureBias);
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The setExposureBias call failed. error code: ${err.code}`);
}
}
}
getExposureValue(): number
查询当前曝光值。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
类型 | 说明 |
---|---|
number | 获取曝光值。曝光补偿存在步长,如步长为0.5。则设置1.2时,获取到实际生效曝光补偿为1.0。 接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config. |
示例:
import { BusinessError } from '@ohos.base';
function getExposureValue(photoSession: camera.PhotoSession): number {
const invalidValue: number = -1;
let exposureValue: number = invalidValue;
try {
exposureValue = photoSession.getExposureValue();
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The getExposureValue call failed. error code: ${err.code}`);
}
return exposureValue;
}
提供了针对设备的自动曝光特性提供了一系列查询功能。
isExposureModeSupported(aeMode: ExposureMode): boolean
检测曝光模式是否支持。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
aeMode | ExposureMode | 是 | 曝光模式。 |
返回值:
类型 | 说明 |
---|---|
boolean | 获取是否支持曝光模式。接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config. |
示例:
import { BusinessError } from '@ohos.base';
function isExposureModeSupported(photoSession: camera.PhotoSession): boolean {
let isSupported: boolean = false;
try {
isSupported = photoSession.isExposureModeSupported(camera.ExposureMode.EXPOSURE_MODE_LOCKED);
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The isExposureModeSupported call failed. error code: ${err.code}`);
}
return isSupported;
}
getExposureBiasRange(): Array<number>
查询曝光补偿范围。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
类型 | 说明 |
---|---|
Array<number> | 获取补偿范围的数组。接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config. |
示例:
import { BusinessError } from '@ohos.base';
function getExposureBiasRange(photoSession: camera.PhotoSession): Array<number> {
let biasRangeArray: Array<number> = [];
try {
biasRangeArray = photoSession.getExposureBiasRange();
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The getExposureBiasRange call failed. error code: ${err.code}`);
}
return biasRangeArray;
}
Focus extends FocusQuery
对焦类,对设备对焦操作。
setFocusMode(afMode: FocusMode): void
设置对焦模式。
进行设置之前,需要先检查设备是否支持指定的焦距模式,可使用方法isFocusModeSupported。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
afMode | FocusMode | 是 | 指定的焦距模式。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config. |
示例:
import { BusinessError } from '@ohos.base';
function setFocusMode(photoSession: camera.PhotoSession): void {
try {
photoSession.setFocusMode(camera.FocusMode.FOCUS_MODE_AUTO);
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The setFocusMode call failed. error code: ${err.code}`);
}
}
getFocusMode(): FocusMode
获取当前的对焦模式。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
类型 | 说明 |
---|---|
FocusMode | 获取当前设备的焦距模式。接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config. |
示例:
import { BusinessError } from '@ohos.base';
function getFocusMode(photoSession: camera.PhotoSession): camera.FocusMode | undefined {
let afMode: camera.FocusMode | undefined = undefined;
try {
afMode = photoSession.getFocusMode();
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The getFocusMode call failed. error code: ${err.code}`);
}
return afMode;
}
setFocusPoint(point: Point): void
设置焦点,焦点应在0-1坐标系内,该坐标系左上角为{0,0},右下角为{1,1}。
此坐标系是以设备充电口在右侧时的横向设备方向为基准的,例如应用的预览界面布局以
设备充电口在下侧时的竖向方向为基准,布局宽高为{w,h},且触碰点为{x,y},
则转换后的坐标点为{y/h,1-x/w}。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
point | Point | 是 | 焦点。x、y设置范围应在[0,1]之内,超过范围,如果小于0设置0,大于1设置1。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config. |
示例:
import { BusinessError } from '@ohos.base';
function setFocusPoint(photoSession: camera.PhotoSession): void {
const focusPoint: camera.Point = {x: 1, y: 1};
try {
photoSession.setFocusPoint(focusPoint);
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The setFocusPoint call failed. error code: ${err.code}`);
}
}
getFocusPoint(): Point
查询焦点。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
类型 | 说明 |
---|---|
Point | 用于获取当前焦点。接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config. |
示例:
import { BusinessError } from '@ohos.base';
function getFocusPoint(photoSession: camera.PhotoSession): camera.Point | undefined {
let point: camera.Point | undefined = undefined;
try {
point = photoSession.getFocusPoint();
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The getFocusPoint call failed. error code: ${err.code}`);
}
return point;
}
getFocalLength(): number
查询焦距值。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
类型 | 说明 |
---|---|
number | 用于获取当前焦距,单位mm。接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config. |
示例:
import { BusinessError } from '@ohos.base';
function getFocalLength(photoSession: camera.PhotoSession): number {
const invalidValue: number = -1;
let focalLength: number = invalidValue;
try {
focalLength = photoSession.getFocalLength();
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The getFocalLength call failed. error code: ${err.code}`);
}
return focalLength;
}
提供了查询是否支持当前对焦模式的方法。
isFocusModeSupported(afMode: FocusMode): boolean
检测对焦模式是否支持。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
afMode | FocusMode | 是 | 指定的焦距模式。 |
返回值:
类型 | 说明 |
---|---|
boolean | 返回true表示支持该焦距模式,false表示不支持。接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config. |
示例:
import { BusinessError } from '@ohos.base';
function isFocusModeSupported(photoSession: camera.PhotoSession): boolean {
let status: boolean = false;
try {
status = photoSession.isFocusModeSupported(camera.FocusMode.FOCUS_MODE_AUTO);
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The isFocusModeSupported call failed. error code: ${err.code}`);
}
return status;
}
平滑变焦模式。
系统能力: SystemCapability.Multimedia.Camera.Core
名称 | 值 | 说明 |
---|---|---|
NORMAL | 0 | 贝塞尔曲线模式。 |
平滑变焦参数信息。
系统能力: SystemCapability.Multimedia.Camera.Core
名称 | 类型 | 只读 | 必填 | 说明 |
---|---|---|---|---|
duration | number | 否 | 是 | 平滑变焦总时长,单位ms。 |
Zoom extends ZoomQuery
变焦类,对设备变焦操作。
setZoomRatio(zoomRatio: number): void
设置变焦比,变焦精度最高为小数点后两位,如果设置超过支持的精度范围,则只保留精度范围内数值。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
zoomRatio | number | 是 | 可变焦距比,通过getZoomRatioRange获取支持的变焦范围,如果设置超过支持范围的值,则只保留精度范围内数值。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config. |
示例:
import { BusinessError } from '@ohos.base';
function setZoomRatio(photoSession: camera.PhotoSession, zoomRatioRange: Array<number>): void {
if (zoomRatioRange === undefined || zoomRatioRange.length <= 0) {
return;
}
let zoomRatio = zoomRatioRange[0];
try {
photoSession.setZoomRatio(zoomRatio);
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The setZoomRatio call failed. error code: ${err.code}`);
}
}
getZoomRatio(): number
获取当前的变焦比。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
类型 | 说明 |
---|---|
number | 获取当前的变焦比结果。接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config. |
7400201 | Camera service fatal error. |
示例:
import { BusinessError } from '@ohos.base';
function getZoomRatio(photoSession: camera.PhotoSession): number {
const invalidValue: number = -1;
let zoomRatio: number = invalidValue;
try {
zoomRatio = photoSession.getZoomRatio();
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The getZoomRatio call failed. error code: ${err.code}`);
}
return zoomRatio;
}
setSmoothZoom(targetRatio: number, mode?: SmoothZoomMode): void
触发平滑变焦。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
targetRatio | number | 是 | 目标值。 |
mode | SmoothZoomMode | 否 | 模式。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config. |
示例:
import { BusinessError } from '@ohos.base';
function setSmoothZoom(sessionExtendsZoom: camera.Zoom, targetZoomRatio: number, mode: camera.SmoothZoomMode): void {
try {
sessionExtendsZoom.setSmoothZoom(targetZoomRatio, mode);
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The setSmoothZoom call failed. error code: ${err.code}`);
}
}
提供了与设备的缩放相关的查询功能,包括获取支持的缩放比例范围。
getZoomRatioRange(): Array<number>
获取支持的变焦范围。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
类型 | 说明 |
---|---|
Array<number> | 用于获取可变焦距比范围,返回的数组包括其最小值和最大值。接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config. |
示例:
import { BusinessError } from '@ohos.base';
function getZoomRatioRange(photoSession: camera.PhotoSession): Array<number> {
let zoomRatioRange: Array<number> = [];
try {
zoomRatioRange = photoSession.getZoomRatioRange();
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The getZoomRatioRange call failed. error code: ${err.code}`);
}
return zoomRatioRange;
}
Stabilization extends StabilizationQuery
提供设备在录像模式下设置视频防抖的操作。
说明:
需要会话中有录像流(VideoOutput)的前提下,才可以对视频进行防抖设置, 其中VideoStabilizationMode中的枚举HIGH需要在Profile的分辨率为1920*1080的场景下生效。
getActiveVideoStabilizationMode(): VideoStabilizationMode
查询当前正在使用的视频防抖模式。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
类型 | 说明 |
---|---|
VideoStabilizationMode | 视频防抖是否正在使用。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config. |
示例:
import { BusinessError } from '@ohos.base';
function getActiveVideoStabilizationMode(videoSession: camera.VideoSession): camera.VideoStabilizationMode | undefined {
let vsMode: camera.VideoStabilizationMode | undefined = undefined;
try {
vsMode = videoSession.getActiveVideoStabilizationMode();
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The getActiveVideoStabilizationMode call failed. error code: ${err.code}`);
}
return vsMode;
}
setVideoStabilizationMode(mode: VideoStabilizationMode): void
设置视频防抖模式。需要先检查设备是否支持对应的防抖模式,可以通过isVideoStabilizationModeSupported方法判断所设置的模式是否支持。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
mode | VideoStabilizationMode | 是 | 需要设置的视频防抖模式。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config. |
示例:
import { BusinessError } from '@ohos.base';
function setVideoStabilizationMode(videoSession: camera.VideoSession): void {
try {
videoSession.setVideoStabilizationMode(camera.VideoStabilizationMode.OFF);
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The setVideoStabilizationMode call failed. error code: ${err.code}`);
}
}
提供了查询设备在录像模式下是否支持对应的视频防抖模式的能力。
isVideoStabilizationModeSupported(vsMode: VideoStabilizationMode): boolean
查询是否支持指定的视频防抖模式。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
vsMode | VideoStabilizationMode | 是 | 视频防抖模式。 |
返回值:
类型 | 说明 |
---|---|
boolean | 返回视频防抖模式是否支持,true表示支持,false表示不支持。接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config. |
示例:
import { BusinessError } from '@ohos.base';
function isVideoStabilizationModeSupported(videoSession: camera.VideoSession): boolean {
let isSupported: boolean = false;
try {
isSupported = videoSession.isVideoStabilizationModeSupported(camera.VideoStabilizationMode.OFF);
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The isVideoStabilizationModeSupported call failed. error code: ${err.code}`);
}
return isSupported;
}
拍照会话类,保存一次相机运行所需要的所有资源CameraInput、CameraOutput,并向相机设备申请完成相机功能(录像,拍照)。
说明: 从 API version 10开始支持,从API version 11开始废弃。建议使用PhotoSession、VideoSession替代。
beginConfig(): void
开始配置会话。
说明: 从 API version 10开始支持,从API version 11开始废弃。建议使用Session.beginConfig替代。
系统能力: SystemCapability.Multimedia.Camera.Core
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400105 | Session config locked. |
示例:
import { BusinessError } from '@ohos.base';
function beginConfig(captureSession: camera.CaptureSession): void {
try {
captureSession.beginConfig();
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The beginConfig call failed. error code: ${err.code}`);
}
}
commitConfig(callback: AsyncCallback<void>): void
提交配置信息,通过注册回调函数获取结果。使用callback异步回调。
说明: 从 API version 10开始支持,从API version 11开始废弃。建议使用Session.commitConfig替代。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
callback | AsyncCallback<void> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型CameraErrorCode |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400102 | Operation not allowed. |
7400201 | Camera service fatal error. |
示例:
import { BusinessError } from '@ohos.base';
function commitConfig(captureSession: camera.CaptureSession): void {
captureSession.commitConfig((err: BusinessError) => {
if (err) {
console.error(`The commitConfig call failed. error code: ${err.code}`);
return;
}
console.info('Callback invoked to indicate the commit config success.');
});
}
commitConfig(): Promise<void>
提交配置信息,通过Promise获取结果。
说明: 从 API version 10开始支持,从API version 11开始废弃。建议使用Session.commitConfig替代。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
类型 | 说明 |
---|---|
Promise<void> | 无返回结果的Promise对象。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400102 | Operation not allowed. |
7400201 | Camera service fatal error. |
示例:
import { BusinessError } from '@ohos.base';
function commitConfig(captureSession: camera.CaptureSession): void {
captureSession.commitConfig().then(() => {
console.info('Promise returned to indicate the commit config success.');
}).catch((error: BusinessError) => {
// 失败返回错误码error.code并处理
console.error(`The commitConfig call failed. error code: ${error.code}`);
});
}
addInput(cameraInput: CameraInput): void
把CameraInput加入到会话。
说明: 从 API version 10开始支持,从API version 11开始废弃。建议使用Session.addInput替代。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
cameraInput | CameraInput | 是 | 需要添加的CameraInput实例。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400101 | Parameter missing or parameter type incorrect. |
7400102 | Operation not allowed. |
示例:
import { BusinessError } from '@ohos.base';
function addInput(captureSession: camera.CaptureSession, cameraInput: camera.CameraInput): void {
try {
captureSession.addInput(cameraInput);
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The addInput call failed. error code: ${err.code}`);
}
}
removeInput(cameraInput: CameraInput): void
移除CameraInput。
说明: 从 API version 10开始支持,从API version 11开始废弃。建议使用Session.removeInput替代。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
cameraInput | CameraInput | 是 | 需要移除的CameraInput实例。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400101 | Parameter missing or parameter type incorrect. |
7400102 | Operation not allowed. |
示例:
import { BusinessError } from '@ohos.base';
function removeInput(captureSession: camera.CaptureSession, cameraInput: camera.CameraInput): void {
try {
captureSession.removeInput(cameraInput);
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The removeInput call failed. error code: ${err.code}`);
}
}
addOutput(cameraOutput: CameraOutput): void
把CameraOutput加入到会话。
说明: 从 API version 10开始支持,从API version 11开始废弃。建议使用Session.addOutput替代。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
cameraOutput | CameraOutput | 是 | 需要添加的CameraOutput实例。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400101 | Parameter missing or parameter type incorrect. |
7400102 | Operation not allowed. |
示例:
import { BusinessError } from '@ohos.base';
function addOutput(captureSession: camera.CaptureSession, cameraOutput: camera.CameraOutput): void {
try {
captureSession.addOutput(cameraOutput);
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The addOutput call failed. error code: ${err.code}`);
}
}
removeOutput(cameraOutput: CameraOutput): void
从会话中移除CameraOutput。
说明: 从 API version 10开始支持,从API version 11开始废弃。建议使用Session.removeOutput替代。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
cameraOutput | CameraOutput | 是 | 需要移除的CameraOutput实例。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400101 | Parameter missing or parameter type incorrect. |
7400102 | Operation not allowed. |
示例:
import { BusinessError } from '@ohos.base';
function removeOutput(captureSession: camera.CaptureSession, previewOutput: camera.PreviewOutput): void {
try {
captureSession.removeOutput(previewOutput);
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The removeOutput call failed. error code: ${err.code}`);
}
}
start(callback: AsyncCallback<void>): void
开始会话工作,通过注册回调函数获取结果。使用callback异步回调。
说明: 从 API version 10开始支持,从API version 11开始废弃。建议使用Session.start替代。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
callback | AsyncCallback<void> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config. |
7400201 | Camera service fatal error. |
示例:
import { BusinessError } from '@ohos.base';
function startCaptureSession(captureSession: camera.CaptureSession): void {
captureSession.start((err: BusinessError) => {
if (err) {
console.error(`Failed to start the session, error code: ${err.code}.`);
return;
}
console.info('Callback invoked to indicate the session start success.');
});
}
start(): Promise<void>
开始会话工作,通过Promise获取结果。
说明: 从 API version 10开始支持,从API version 11开始废弃。建议使用Session.start替代。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
类型 | 说明 |
---|---|
Promise<void> | 无返回结果的Promise对象。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config. |
7400201 | Camera service fatal error. |
示例:
import { BusinessError } from '@ohos.base';
function startCaptureSession(captureSession: camera.CaptureSession): void {
captureSession.start().then(() => {
console.info('Promise returned to indicate the session start success.');
}).catch((err: BusinessError) => {
console.error(`Failed to start the session, error code: ${err.code}.`);
});
}
stop(callback: AsyncCallback<void>): void
停止会话工作,通过注册回调函数获取结果。使用callback异步回调。
说明: 从 API version 10开始支持,从API version 11开始废弃。建议使用Session.stop替代。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
callback | AsyncCallback<void> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400201 | Camera service fatal error. |
示例:
import { BusinessError } from '@ohos.base';
function stopCaptureSession(captureSession: camera.CaptureSession): void {
captureSession.stop((err: BusinessError) => {
if (err) {
console.error(`Failed to stop the session, error code: ${err.code}.`);
return;
}
console.info('Callback invoked to indicate the session stop success.');
});
}
stop(): Promise<void>
停止会话工作,通过Promise获取结果。
说明: 从 API version 10开始支持,从API version 11开始废弃。建议使用Session.stop替代。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
类型 | 说明 |
---|---|
Promise<void> | 无返回结果的Promise对象。。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400201 | Camera service fatal error. |
示例:
import { BusinessError } from '@ohos.base';
function stopCaptureSession(captureSession: camera.CaptureSession): void {
captureSession.stop().then(() => {
console.info('Promise returned to indicate the session stop success.');
}).catch((err: BusinessError) => {
console.error(`Failed to stop the session, error code: ${err.code}.`);
});
}
release(callback: AsyncCallback<void>): void
释放会话资源,通过注册回调函数获取结果。使用callback异步回调。
说明: 从 API version 10开始支持,从API version 11开始废弃。建议使用Session.release替代。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
callback | AsyncCallback<void> | 是 | 回调函数,用于获取结果。接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400201 | Camera service fatal error. |
示例:
import { BusinessError } from '@ohos.base';
function releaseCaptureSession(captureSession: camera.CaptureSession): void {
captureSession.release((err: BusinessError) => {
if (err) {
console.error(`Failed to release the CaptureSession instance, error code: ${err.code}.`);
return;
}
console.info('Callback invoked to indicate that the CaptureSession instance is released successfully.');
});
}
release(): Promise<void>
释放会话资源,通过Promise获取结果。
说明: 从 API version 10开始支持,从API version 11开始废弃。建议使用Session.release替代。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
类型 | 说明 |
---|---|
Promise<void> | 无返回结果的Promise对象。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400201 | Camera service fatal error. |
示例:
import { BusinessError } from '@ohos.base';
function releaseCaptureSession(captureSession: camera.CaptureSession): void {
captureSession.release().then(() => {
console.info('Promise returned to indicate that the CaptureSession instance is released successfully.');
}).catch((err: BusinessError) => {
console.error(`Failed to release the CaptureSession instance, error code: ${err.code}.`);
});
}
hasFlash(): boolean
检测是否有闪光灯。
说明: 从 API version 10开始支持,从API version 11开始废弃。建议使用Flash.hasFlash替代。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
类型 | 说明 |
---|---|
boolean | 返回true表示设备支持闪光灯,false表示不支持。接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config. |
示例:
import { BusinessError } from '@ohos.base';
function hasFlash(captureSession: camera.CaptureSession): boolean {
let status: boolean = false;
try {
status = captureSession.hasFlash();
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The hasFlash call failed. error code: ${err.code}`);
}
return status;
}
isFlashModeSupported(flashMode: FlashMode): boolean
检测闪光灯模式是否支持。
说明: 从 API version 10开始支持,从API version 11开始废弃。建议使用Flash.isFlashModeSupported替代。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
flashMode | FlashMode | 是 | 指定闪光灯模式。 |
返回值:
类型 | 说明 |
---|---|
boolean | 返回true表示支持该闪光灯模式,false表示不支持。接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config. |
示例:
import { BusinessError } from '@ohos.base';
function isFlashModeSupported(captureSession: camera.CaptureSession): boolean {
let status: boolean = false;
try {
status = captureSession.isFlashModeSupported(camera.FlashMode.FLASH_MODE_AUTO);
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The isFlashModeSupported call failed. error code: ${err.code}`);
}
return status;
}
setFlashMode(flashMode: FlashMode): void
设置闪光灯模式。
进行设置之前,需要先检查:
说明: 从 API version 10开始支持,从API version 11开始废弃。建议使用Flash.setFlashMode替代。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
flashMode | FlashMode | 是 | 指定闪光灯模式。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config. |
示例:
import { BusinessError } from '@ohos.base';
function setFlashMode(captureSession: camera.CaptureSession): void {
try {
captureSession.setFlashMode(camera.FlashMode.FLASH_MODE_AUTO);
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The setFlashMode call failed. error code: ${err.code}`);
}
}
getFlashMode(): FlashMode
获取当前设备的闪光灯模式。
说明: 从 API version 10开始支持,从API version 11开始废弃。建议使用Flash.getFlashMode替代。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
类型 | 说明 |
---|---|
FlashMode | 获取当前设备的闪光灯模式。接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config. |
示例:
import { BusinessError } from '@ohos.base';
function getFlashMode(captureSession: camera.CaptureSession): camera.FlashMode | undefined {
let flashMode: camera.FlashMode | undefined = undefined;
try {
flashMode = captureSession.getFlashMode();
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The getFlashMode call failed.error code: ${err.code}`);
}
return flashMode;
}
isExposureModeSupported(aeMode: ExposureMode): boolean
检测曝光模式是否支持。
说明: 从 API version 10开始支持,从API version 11开始废弃。建议使用AutoExposure.isExposureModeSupported替代。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
aeMode | ExposureMode | 是 | 曝光模式。 |
返回值:
类型 | 说明 |
---|---|
boolean | 获取是否支持曝光模式。接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config. |
示例:
import { BusinessError } from '@ohos.base';
function isExposureModeSupported(captureSession: camera.CaptureSession): boolean {
let isSupported: boolean = false;
try {
isSupported = captureSession.isExposureModeSupported(camera.ExposureMode.EXPOSURE_MODE_LOCKED);
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The isExposureModeSupported call failed. error code: ${err.code}`);
}
return isSupported;
}
getExposureMode(): ExposureMode
获取当前曝光模式。
说明: 从 API version 10开始支持,从API version 11开始废弃。建议使用AutoExposure.getExposureMode替代。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
类型 | 说明 |
---|---|
ExposureMode | 获取当前曝光模式。接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config. |
示例:
import { BusinessError } from '@ohos.base';
function getExposureMode(captureSession: camera.CaptureSession): camera.ExposureMode | undefined {
let exposureMode: camera.ExposureMode | undefined = undefined;
try {
exposureMode = captureSession.getExposureMode();
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The getExposureMode call failed. error code: ${err.code}`);
}
return exposureMode;
}
setExposureMode(aeMode: ExposureMode): void
设置曝光模式。进行设置之前,需要先检查设备是否支持指定的曝光模式,可使用方法isExposureModeSupported。
说明: 从 API version 10开始支持,从API version 11开始废弃。建议使用AutoExposure.setExposureMode替代。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
aeMode | ExposureMode | 是 | 曝光模式。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config. |
示例:
import { BusinessError } from '@ohos.base';
function setExposureMode(captureSession: camera.CaptureSession): void {
try {
captureSession.setExposureMode(camera.ExposureMode.EXPOSURE_MODE_LOCKED);
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The setExposureMode call failed. error code: ${err.code}`);
}
}
getMeteringPoint(): Point
查询曝光区域中心点。
说明: 从 API version 10开始支持,从API version 11开始废弃。建议使用AutoExposure.getMeteringPoint替代。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
类型 | 说明 |
---|---|
Point | 获取当前曝光点。接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config. |
示例:
import { BusinessError } from '@ohos.base';
function getMeteringPoint(captureSession: camera.CaptureSession): camera.Point | undefined {
let exposurePoint: camera.Point | undefined = undefined;
try {
exposurePoint = captureSession.getMeteringPoint();
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The getMeteringPoint call failed. error code: ${err.code}`);
}
return exposurePoint;
}
setMeteringPoint(point: Point): void
设置曝光区域中心点,曝光点应在0-1坐标系内,该坐标系左上角为{0,0},右下角为{1,1}。 此坐标系是以设备充电口在右侧时的横向设备方向为基准的,例如应用的预览界面布局以 设备充电口在下侧时的竖向方向为基准,布局宽高为{w,h},且触碰点为{x,y}, 则转换后的坐标点为{y/h,1-x/w}。
说明: 从 API version 10开始支持,从API version 11开始废弃。建议使用AutoExposure.setMeteringPoint替代。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
point | Point | 是 | 曝光点,x,y设置范围应在[0,1]之内,超过范围,如果小于0设置0,大于1设置1。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config. |
示例:
import { BusinessError } from '@ohos.base';
function setMeteringPoint(captureSession: camera.CaptureSession): void {
const point: camera.Point = {x: 1, y: 1};
try {
captureSession.setMeteringPoint(point);
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The setMeteringPoint call failed. error code: ${err.code}`);
}
}
getExposureBiasRange(): Array<number>
查询曝光补偿范围。
说明: 从 API version 10开始支持,从API version 11开始废弃。建议使用AutoExposure.getExposureBiasRange替代。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
类型 | 说明 |
---|---|
Array<number> | 获取补偿范围的数组。接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config. |
示例:
import { BusinessError } from '@ohos.base';
function getExposureBiasRange(captureSession: camera.CaptureSession): Array<number> {
let biasRangeArray: Array<number> = [];
try {
biasRangeArray = captureSession.getExposureBiasRange();
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The getExposureBiasRange call failed. error code: ${err.code}`);
}
return biasRangeArray;
}
setExposureBias(exposureBias: number): void
设置曝光补偿,曝光补偿值(EV)。
进行设置之前,建议先通过方法getExposureBiasRange查询支持的范围。
说明: 从 API version 10开始支持,从API version 11开始废弃。建议使用AutoExposure.setExposureBias替代。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 可选 | 说明 |
---|---|---|---|
exposureBias | number | 否 | 曝光补偿,getExposureBiasRange查询支持的范围,如果设置超过支持范围的值,自动匹配到就近临界点。曝光补偿存在步长,如步长为0.5。则设置1.2时,获取到实际生效曝光补偿为1.0。接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config. |
示例:
import { BusinessError } from '@ohos.base';
function setExposureBias(captureSession: camera.CaptureSession, biasRangeArray: Array<number>): void {
if (biasRangeArray && biasRangeArray.length > 0) {
let exposureBias = biasRangeArray[0];
try {
captureSession.setExposureBias(exposureBias);
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The setExposureBias call failed. error code: ${err.code}`);
}
}
}
getExposureValue(): number
查询当前曝光值。
说明: 从 API version 10开始支持,从API version 11开始废弃。建议使用AutoExposure.getExposureValue替代。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
类型 | 说明 |
---|---|
number | 获取曝光值。曝光补偿存在步长,如步长为0.5。则设置1.2时,获取到实际生效曝光补偿为1.0。接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config. |
示例:
import { BusinessError } from '@ohos.base';
function getExposureValue(captureSession: camera.CaptureSession): number {
const invalidValue: number = -1;
let exposureValue: number = invalidValue;
try {
exposureValue = captureSession.getExposureValue();
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The getExposureValue call failed. error code: ${err.code}`);
}
return exposureValue;
}
isFocusModeSupported(afMode: FocusMode): boolean
检测对焦模式是否支持。
说明: 从 API version 10开始支持,从API version 11开始废弃。建议使用Focus.isFocusModeSupported替代。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
afMode | FocusMode | 是 | 指定的焦距模式。 |
返回值:
类型 | 说明 |
---|---|
boolean | 返回true表示支持该焦距模式,false表示不支持。接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config. |
示例:
import { BusinessError } from '@ohos.base';
function isFocusModeSupported(captureSession: camera.CaptureSession): boolean {
let status: boolean = false;
try {
status = captureSession.isFocusModeSupported(camera.FocusMode.FOCUS_MODE_AUTO);
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The isFocusModeSupported call failed. error code: ${err.code}`);
}
return status;
}
setFocusMode(afMode: FocusMode): void
设置对焦模式。
进行设置之前,需要先检查设备是否支持指定的焦距模式,可使用方法isFocusModeSupported。
说明: 从 API version 10开始支持,从API version 11开始废弃。建议使用Focus.setFocusMode替代。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
afMode | FocusMode | 是 | 指定的焦距模式。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config. |
示例:
import { BusinessError } from '@ohos.base';
function setFocusMode(captureSession: camera.CaptureSession): void {
try {
captureSession.setFocusMode(camera.FocusMode.FOCUS_MODE_AUTO);
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The setFocusMode call failed. error code: ${err.code}`);
}
}
getFocusMode(): FocusMode
获取当前的对焦模式。
说明: 从 API version 10开始支持,从API version 11开始废弃。建议使用Focus.getFocusMode替代。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
类型 | 说明 |
---|---|
FocusMode | 获取当前设备的焦距模式。接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config. |
示例:
import { BusinessError } from '@ohos.base';
function getFocusMode(captureSession: camera.CaptureSession): camera.FocusMode | undefined {
let afMode: camera.FocusMode | undefined = undefined;
try {
afMode = captureSession.getFocusMode();
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The getFocusMode call failed. error code: ${err.code}`);
}
return afMode;
}
setFocusPoint(point: Point): void
设置焦点,焦点应在0-1坐标系内,该坐标系左上角为{0,0},右下角为{1,1}。 此坐标系是以设备充电口在右侧时的横向设备方向为基准的,例如应用的预览界面布局以 设备充电口在下侧时的竖向方向为基准,布局宽高为{w,h},且触碰点为{x,y}, 则转换后的坐标点为{y/h,1-x/w}。
说明: 从 API version 10开始支持,从API version 11开始废弃。建议使用Focus.setFocusPoint替代。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
Point | Point | 是 | 焦点。x,y设置范围应在[0,1]之内,超过范围,如果小于0设置0,大于1设置1。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config. |
示例:
import { BusinessError } from '@ohos.base';
function setFocusPoint(captureSession: camera.CaptureSession): void {
const focusPoint: camera.Point = {x: 1, y: 1};
try {
captureSession.setFocusPoint(focusPoint);
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The setFocusPoint call failed. error code: ${err.code}`);
}
}
getFocusPoint(): Point
查询焦点。
说明: 从 API version 10开始支持,从API version 11开始废弃。建议使用Focus.getFocusPoint替代。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
类型 | 说明 |
---|---|
Point | 用于获取当前焦点。接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config. |
示例:
import { BusinessError } from '@ohos.base';
function getFocusPoint(captureSession: camera.CaptureSession): camera.Point | undefined {
let point: camera.Point | undefined = undefined;
try {
point = captureSession.getFocusPoint();
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The getFocusPoint call failed. error code: ${err.code}`);
}
return point;
}
getFocalLength(): number
查询焦距值。
说明: 从 API version 10开始支持,从API version 11开始废弃。建议使用Focus.getFocalLength替代。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
类型 | 说明 |
---|---|
number | 用于获取当前焦距。接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config. |
示例:
import { BusinessError } from '@ohos.base';
function getFocalLength(captureSession: camera.CaptureSession): number {
const invalidValue: number = -1;
let focalLength: number = invalidValue;
try {
focalLength = captureSession.getFocalLength();
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The getFocalLength call failed. error code: ${err.code}`);
}
return focalLength;
}
getZoomRatioRange(): Array<number>
获取支持的变焦范围。
说明: 从 API version 10开始支持,从API version 11开始废弃。建议使用Zoom.getZoomRatioRange替代。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
类型 | 说明 |
---|---|
Array<number> | 用于获取可变焦距比范围,返回的数组包括其最小值和最大值。接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config. |
示例:
import { BusinessError } from '@ohos.base';
function getZoomRatioRange(captureSession: camera.CaptureSession): Array<number> {
let zoomRatioRange: Array<number> = [];
try {
zoomRatioRange = captureSession.getZoomRatioRange();
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The getZoomRatioRange call failed. error code: ${err.code}`);
}
return zoomRatioRange;
}
setZoomRatio(zoomRatio: number): void
设置变焦比,变焦精度最高为小数点后两位,如果设置超过支持的精度范围,则只保留精度范围内数值。
说明: 从 API version 10开始支持,从API version 11开始废弃。建议使用Zoom.setZoomRatio替代。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 可选 | 说明 |
---|---|---|---|
zoomRatio | number | 否 | 可变焦距比,通过getZoomRatioRange获取支持的变焦范围,如果设置超过支持范围的值,则只保留精度范围内数值。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config. |
示例:
import { BusinessError } from '@ohos.base';
function setZoomRatio(captureSession: camera.CaptureSession, zoomRatioRange: Array<number>): void {
if (zoomRatioRange === undefined || zoomRatioRange.length <= 0) {
return;
}
let zoomRatio = zoomRatioRange[0];
try {
captureSession.setZoomRatio(zoomRatio);
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The setZoomRatio call failed. error code: ${err.code}`);
}
}
getZoomRatio(): number
获取当前的变焦比。
说明: 从 API version 10开始支持,从API version 11开始废弃。建议使用Zoom.getZoomRatio替代。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
类型 | 说明 |
---|---|
number | 获取当前的变焦比结果。接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config. |
示例:
import { BusinessError } from '@ohos.base';
function getZoomRatio(captureSession: camera.CaptureSession): number {
const invalidValue: number = -1;
let zoomRatio: number = invalidValue;
try {
zoomRatio = captureSession.getZoomRatio();
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The getZoomRatio call failed. error code: ${err.code}`);
}
return zoomRatio;
}
isVideoStabilizationModeSupported(vsMode: VideoStabilizationMode): boolean
查询是否支持指定的视频防抖模式。
说明: 从 API version 10开始支持,从API version 11开始废弃。建议使用Stabilization.isVideoStabilizationModeSupported替代。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
vsMode | VideoStabilizationMode | 是 | 视频防抖模式。 |
返回值:
类型 | 说明 |
---|---|
boolean | 返回视频防抖模式是否支持,true表示支持,false表示不支持。接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config. |
示例:
import { BusinessError } from '@ohos.base';
function isVideoStabilizationModeSupported(captureSession: camera.CaptureSession): boolean {
let isSupported: boolean = false;
try {
isSupported = captureSession.isVideoStabilizationModeSupported(camera.VideoStabilizationMode.OFF);
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The isVideoStabilizationModeSupported call failed. error code: ${err.code}`);
}
return isSupported;
}
getActiveVideoStabilizationMode(): VideoStabilizationMode
查询当前正在使用的视频防抖模式。
说明: 从 API version 10开始支持,从API version 11开始废弃。建议使用Stabilization.getActiveVideoStabilizationMode替代。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
类型 | 说明 |
---|---|
VideoStabilizationMode | 视频防抖是否正在使用。接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config. |
示例:
import { BusinessError } from '@ohos.base';
function getActiveVideoStabilizationMode(captureSession: camera.CaptureSession): camera.VideoStabilizationMode | undefined {
let vsMode: camera.VideoStabilizationMode | undefined = undefined;
try {
vsMode = captureSession.getActiveVideoStabilizationMode();
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The getActiveVideoStabilizationMode call failed. error code: ${err.code}`);
}
return vsMode;
}
setVideoStabilizationMode(mode: VideoStabilizationMode): void
设置视频防抖模式。需要先检查设备是否支持对应的防抖模式,可以通过isVideoStabilizationModeSupported方法判断所设置的模式是否支持。
说明: 从 API version 10开始支持,从API version 11开始废弃。建议使用Stabilization.setVideoStabilizationMode替代。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
mode | VideoStabilizationMode | 是 | 需要设置的视频防抖模式。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config. |
示例:
import { BusinessError } from '@ohos.base';
function setVideoStabilizationMode(captureSession: camera.CaptureSession): void {
try {
captureSession.setVideoStabilizationMode(camera.VideoStabilizationMode.OFF);
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The setVideoStabilizationMode call failed. error code: ${err.code}`);
}
}
on(type: 'focusStateChange', callback: AsyncCallback<FocusState>): void
监听相机聚焦的状态变化,通过注册回调函数获取结果。使用callback异步回调。
说明: 从 API version 10开始支持,从API version 11开始废弃。建议使用VideoSession.on('focusStateChange')替代。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'focusStateChange',session 创建成功可监听。仅当自动对焦模式时,且相机对焦状态发生改变时可触发该事件。 |
callback | AsyncCallback<FocusState> | 是 | 回调函数,用于获取当前对焦状态。 |
示例:
import { BusinessError } from '@ohos.base';
function registerFocusStateChange(captureSession: camera.CaptureSession): void {
captureSession.on('focusStateChange', (err: BusinessError, focusState: camera.FocusState) => {
console.info(`Focus state: ${focusState}`);
});
}
off(type: 'focusStateChange', callback?: AsyncCallback<FocusState>): void
注销监听相机聚焦的状态变化。
说明: 从 API version 10开始支持,从API version 11开始废弃。建议使用VideoSession.off('focusStateChange')替代。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'focusStateChange',session 创建成功可监听。 |
callback | AsyncCallback<FocusState> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
示例:
function unregisterFocusStateChange(captureSession: camera.CaptureSession): void {
captureSession.off('focusStateChange');
}
on(type: 'error', callback: ErrorCallback): void
监听拍照会话的错误事件,通过注册回调函数获取结果。使用callback异步回调。
说明: 从 API version 10开始支持,从API version 11开始废弃。建议使用VideoSession.on('error')替代。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'error',session创建成功之后可监听该接口。session调用相关接口出现错误时会触发该事件,比如调用beginConfig,commitConfig,addInput等接口发生错误时返回错误信息。 |
callback | ErrorCallback | 是 | 回调函数,用于获取错误信息。返回错误码,错误码类型CameraErrorCode。 |
示例:
import { BusinessError } from '@ohos.base';
function registerCaptureSessionError(captureSession: camera.CaptureSession): void {
captureSession.on('error', (error: BusinessError) => {
console.error(`Capture session error code: ${error.code}`);
});
}
off(type: 'error', callback?: ErrorCallback): void
注销监听拍照会话的错误事件,通过注册回调函数获取结果。
说明: 从 API version 10开始支持,从API version 11开始废弃。建议使用VideoSession.off('error')替代。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'error',session创建成功之后可监听该接口。 |
callback | ErrorCallback | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
示例:
function unregisterCaptureSessionError(captureSession: camera.CaptureSession): void {
captureSession.off('error');
}
色彩管理类,用于查询色彩空间参数。
getSupportedColorSpaces(): Array<colorSpaceManager.ColorSpace>
获取支持的色彩空间列表。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
类型 | 说明 |
---|---|
Array<colorSpaceManager.ColorSpace> | 支持的色彩空间列表。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config, only throw in session usage. |
示例:
import { BusinessError } from '@ohos.base';
import colorSpaceManager from '@ohos.graphics.colorSpaceManager';
function getSupportedColorSpaces(session: camera.PhotoSession): Array<colorSpaceManager.ColorSpace> {
let colorSpaces: Array<colorSpaceManager.ColorSpace> = [];
try {
colorSpaces = session.getSupportedColorSpaces();
} catch (error) {
let err = error as BusinessError;
console.error(`The getSupportedColorSpaces call failed. error code: ${err.code}`);
}
return colorSpaces;
}
ColorManagement extends ColorManagementQuery
色彩管理类,继承自ColorManagementQuery,用于设置色彩空间参数。
setColorSpace(colorSpace: colorSpaceManager.ColorSpace): void
设置色彩空间。可以先通过getSupportedColorSpaces获取当前设备所支持的ColorSpaces。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
colorSpace | colorSpaceManager.ColorSpace | 是 | 色彩空间,通过getSupportedColorSpaces接口获取。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400101 | Parameter missing or parameter type incorrect. |
7400102 | The colorSpace does not match the format. |
7400103 | Session not config. |
7400201 | Camera service fatal error. |
示例:
import { BusinessError } from '@ohos.base';
import colorSpaceManager from '@ohos.graphics.colorSpaceManager';
function setColorSpace(session: camera.PhotoSession, colorSpaces: Array<colorSpaceManager.ColorSpace>): void {
if (colorSpaces === undefined || colorSpaces.length <= 0) {
return;
}
try {
session.setColorSpace(colorSpaces[0]);
} catch (error) {
let err = error as BusinessError;
console.error(`The setColorSpace call failed, error code: ${err.code}`);
}
}
getActiveColorSpace(): colorSpaceManager.ColorSpace
获取当前设置的色彩空间。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
类型 | 说明 |
---|---|
colorSpaceManager.ColorSpace | 当前设置的色彩空间。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400103 | Session not config. |
示例:
import { BusinessError } from '@ohos.base';
import colorSpaceManager from '@ohos.graphics.colorSpaceManager';
function getActiveColorSpace(session: camera.PhotoSession): colorSpaceManager.ColorSpace | undefined {
let colorSpace: colorSpaceManager.ColorSpace | undefined = undefined;
try {
colorSpace = session.getActiveColorSpace();
} catch (error) {
let err = error as BusinessError;
console.error(`The getActiveColorSpace call failed. error code: ${err.code}`);
}
return colorSpace;
}
PhotoSession extends Session, Flash, AutoExposure, Focus, Zoom, ColorManagement
普通拍照模式会话类,提供了对闪光灯、曝光、对焦、变焦、色彩空间的操作。
on(type: 'error', callback: ErrorCallback): void
监听普通拍照会话的错误事件,通过注册回调函数获取结果。使用callback异步回调。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'error',session创建成功之后可监听该接口。session调用相关接口出现错误时会触发该事件,比如调用beginConfig,commitConfig,addInput等接口发生错误时返回错误信息。 |
callback | ErrorCallback | 是 | 回调函数,用于获取错误信息。返回错误码,错误码类型CameraErrorCode。 |
示例:
import { BusinessError } from '@ohos.base';
function callback(err: BusinessError): void {
console.error(`Photo session error code: ${err.code}`);
}
function registerSessionError(photoSession: camera.PhotoSession): void {
photoSession.on('error', callback);
}
off(type: 'error', callback?: ErrorCallback): void
注销监听普通拍照会话的错误事件,通过注册回调函数获取结果。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'error',session创建成功之后可监听该接口。 |
callback | ErrorCallback | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
示例:
function unregisterSessionError(photoSession: camera.PhotoSession): void {
photoSession.off('error');
}
on(type: 'focusStateChange', callback: AsyncCallback<FocusState>): void
监听相机聚焦的状态变化,通过注册回调函数获取结果。使用callback异步回调。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'focusStateChange',session创建成功可监听。仅当自动对焦模式时,且相机对焦状态发生改变时可触发该事件。 |
callback | AsyncCallback<FocusState> | 是 | 回调函数,用于获取当前对焦状态。 |
示例:
import { BusinessError } from '@ohos.base';
function callback(err: BusinessError, focusState: camera.FocusState): void {
console.info(`Focus state: ${focusState}`);
}
function registerFocusStateChange(photoSession: camera.PhotoSession): void {
photoSession.on('focusStateChange', callback);
}
off(type: 'focusStateChange', callback?: AsyncCallback<FocusState>): void
注销监听相机聚焦的状态变化。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'focusStateChange',session创建成功可监听。 |
callback | AsyncCallback<FocusState> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
示例:
function unregisterFocusStateChange(photoSession: camera.PhotoSession): void {
photoSession.off('focusStateChange');
}
on(type: 'smoothZoomInfoAvailable', callback: AsyncCallback<SmoothZoomInfo>): void
监听相机平滑变焦的状态变化,通过注册回调函数获取结果。使用callback异步回调。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'smoothZoomInfoAvailable',session创建成功可监听。 |
callback | AsyncCallback<SmoothZoomInfo> | 是 | 回调函数,用于获取当前平滑变焦状态。 |
示例:
import { BusinessError } from '@ohos.base';
function callback(err: BusinessError, smoothZoomInfo: camera.SmoothZoomInfo): void {
console.info(`The duration of smooth zoom: ${smoothZoomInfo.duration}`);
}
function registerSmoothZoomInfo(photoSession: camera.PhotoSession): void {
photoSession.on('smoothZoomInfoAvailable', callback);
}
off(type: 'smoothZoomInfoAvailable', callback?: AsyncCallback<SmoothZoomInfo>): void
注销监听相机平滑变焦的状态变化。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'smoothZoomInfoAvailable',session创建成功可监听。 |
callback | AsyncCallback<SmoothZoomInfo> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
示例:
function unregisterSmoothZoomInfo(photoSession: camera.PhotoSession): void {
photoSession.off('smoothZoomInfoAvailable');
}
VideoSession extends Session, Flash, AutoExposure, Focus, Zoom, Stabilization, ColorManagement
普通录像模式会话类,提供了对闪光灯、曝光、对焦、变焦、视频防抖、色彩空间的操作。
on(type: 'error', callback: ErrorCallback): void
监听普通录像会话的错误事件,通过注册回调函数获取结果。使用callback异步回调。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'error',session创建成功之后可监听该接口。session调用相关接口出现错误时会触发该事件,比如调用beginConfig,commitConfig,addInput等接口发生错误时返回错误信息。 |
callback | ErrorCallback | 是 | 回调函数,用于获取错误信息。返回错误码,错误码类型CameraErrorCode。 |
示例:
import { BusinessError } from '@ohos.base';
function callback(err: BusinessError): void {
console.error(`Video session error code: ${err.code}`);
}
function registerSessionError(videoSession: camera.VideoSession): void {
videoSession.on('error', callback);
}
off(type: 'error', callback?: ErrorCallback): void
注销监听普通录像会话的错误事件,通过注册回调函数获取结果。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'error',session创建成功之后可监听该接口。 |
callback | ErrorCallback | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
示例:
function unregisterSessionError(videoSession: camera.VideoSession): void {
videoSession.off('error');
}
on(type: 'focusStateChange', callback: AsyncCallback<FocusState>): void
监听相机聚焦的状态变化,通过注册回调函数获取结果。使用callback异步回调。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'focusStateChange',session创建成功可监听。仅当自动对焦模式时,且相机对焦状态发生改变时可触发该事件。 |
callback | AsyncCallback<FocusState> | 是 | 回调函数,用于获取当前对焦状态。 |
示例:
import { BusinessError } from '@ohos.base';
function callback(err: BusinessError, focusState: camera.FocusState): void {
console.info(`Focus state: ${focusState}`);
}
function registerFocusStateChange(videoSession: camera.VideoSession): void {
videoSession.on('focusStateChange', callback);
}
off(type: 'focusStateChange', callback?: AsyncCallback<FocusState>): void
注销监听相机聚焦的状态变化。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'focusStateChange',session创建成功可监听。 |
callback | AsyncCallback<FocusState> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
示例:
function unregisterFocusStateChange(videoSession: camera.VideoSession): void {
videoSession.off('focusStateChange');
}
on(type: 'smoothZoomInfoAvailable', callback: AsyncCallback<SmoothZoomInfo>): void
监听相机平滑变焦的状态变化,通过注册回调函数获取结果。使用callback异步回调。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'smoothZoomInfoAvailable',session创建成功可监听。 |
callback | AsyncCallback<SmoothZoomInfo> | 是 | 回调函数,用于获取当前平滑变焦状态。 |
示例:
import { BusinessError } from '@ohos.base';
function callback(err: BusinessError, smoothZoomInfo: camera.SmoothZoomInfo): void {
console.info(`The duration of smooth zoom: ${smoothZoomInfo.duration}`);
}
function registerSmoothZoomInfo(videoSession: camera.VideoSession): void {
videoSession.on('smoothZoomInfoAvailable', callback);
}
off(type: 'smoothZoomInfoAvailable', callback?: AsyncCallback<SmoothZoomInfo>): void
注销监听相机平滑变焦的状态变化。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'smoothZoomInfoAvailable',session创建成功可监听。 |
callback | AsyncCallback<SmoothZoomInfo> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
示例:
function unregisterSmoothZoomInfo(videoSession: camera.VideoSession): void {
videoSession.off('smoothZoomInfoAvailable');
}
SecureSession extends Session, Flash, AutoExposure, Focus, Zoom
安全模式会话类,提供了对闪光灯、曝光、对焦、变焦的操作。
addSecureOutput(previewOutput: PreviewOutput): void
把其中一条PreviewOutput标记成安全输出。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
previewOutput | PreviewOutput | 是 | 需要标记成安全输出的预览流 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
错误码ID | 错误信息 |
---|---|
7400101 | Parameter missing or parameter type incorrect. |
7400102 | Operation not allowed. |
7400103 | Session not config. |
示例:
import { BusinessError } from '@ohos.base';
function addSecureOutput(session: camera.SecureSession, previewOutput: camera.PreviewOutput): void {
try {
session.addSecureOutput(previewOutput);
} catch (error) {
// 失败返回错误码error.code并处理
let err = error as BusinessError;
console.error(`The addOutput call failed. error code: ${err.code}`);
}
}
on(type: 'error', callback: ErrorCallback): void
监听安全相机会话的错误事件,通过注册回调函数获取结果。使用callback异步回调。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'error',session创建成功之后可监听该接口。session调用相关接口出现错误时会触发该事件,比如调用beginConfig,commitConfig,addInput等接口发生错误时返回错误信息。 |
callback | ErrorCallback | 是 | 回调函数,用于获取错误信息。返回错误码,错误码类型CameraErrorCode。 |
示例:
import { BusinessError } from '@ohos.base';
function callback(err: BusinessError): void {
console.error(`Video session error code: ${err.code}`);
}
function registerSessionError(secureSession: camera.SecureSession): void {
secureSession.on('error', callback);
}
off(type: 'error', callback?: ErrorCallback): void
注销监听安全相机会话的错误事件,通过注册回调函数获取结果。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'error',session创建成功之后可监听该接口。 |
callback | ErrorCallback | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
示例:
function unregisterSessionError(secureSession: camera.SecureSession): void {
secureSession.off('error');
}
on(type: 'focusStateChange', callback: AsyncCallback<FocusState>): void
监听相机聚焦的状态变化,通过注册回调函数获取结果。使用callback异步回调。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'focusStateChange',session创建成功可监听。仅当自动对焦模式时,且相机对焦状态发生改变时可触发该事件。 |
callback | AsyncCallback<FocusState> | 是 | 回调函数,用于获取当前对焦状态。 |
示例:
import { BusinessError } from '@ohos.base';
function callback(err: BusinessError, focusState: camera.FocusState): void {
console.info(`Focus state: ${focusState}`);
}
function registerFocusStateChange(secureSession: camera.SecureSession): void {
secureSession.on('focusStateChange', callback);
}
off(type: 'focusStateChange', callback?: AsyncCallback<FocusState>): void
注销监听相机聚焦的状态变化。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'focusStateChange',session创建成功可监听。 |
callback | AsyncCallback<FocusState> | 否 | 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。 |
示例:
function unregisterFocusStateChange(secureSession: camera.SecureSession): void {
secureSession.off('focusStateChange');
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。