@ohos.multimedia.camera (Camera Management)
The camera module provides a set of camera service APIs for you to easily develop a camera application. The application can access and operate the camera hardware to implement basic operations, such as preview, taking photos, and recording videos. It can also perform more operations, for example, controlling the flash and exposure time, and focusing or adjusting the focus.
NOTE
The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.
Modules to Import
import camera from '@ohos.multimedia.camera';
camera.getCameraManager
getCameraManager(context: Context): CameraManager
Obtains a CameraManager instance. This API returns the result synchronously.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
context | Context | Yes | Application context. |
Return value
Type | Description |
---|---|
CameraManager | CameraManager instance obtained. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400101 | Parameter missing or parameter type incorrect. |
7400201 | Camera service fatal error. |
Example
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;
}
CameraDevice
Defines the camera device information.
System capability: SystemCapability.Multimedia.Camera.Core
Name | Type | Read-only | Mandatory | Description |
---|---|---|---|---|
cameraId | string | Yes | Yes | Camera ID. |
cameraPosition | CameraPosition | Yes | Yes | Camera position. |
cameraType | CameraType | Yes | Yes | Camera type. |
connectionType | ConnectionType | Yes | Yes | Camera connection type. |
CameraPosition
Enumerates the camera positions.
System capability: SystemCapability.Multimedia.Camera.Core
Name | Value | Description |
---|---|---|
CAMERA_POSITION_UNSPECIFIED | 0 | Unspecified position. |
CAMERA_POSITION_BACK | 1 | Rear camera. |
CAMERA_POSITION_FRONT | 2 | Front camera. |
CAMERA_POSITION_FOLD_INNER11+ | 3 | Folded camera. |
CameraType
Enumerates the camera types.
System capability: SystemCapability.Multimedia.Camera.Core
Name | Value | Description |
---|---|---|
CAMERA_TYPE_DEFAULT | 0 | Unspecified camera type. |
CAMERA_TYPE_WIDE_ANGLE | 1 | Wide camera. |
CAMERA_TYPE_ULTRA_WIDE | 2 | Ultra wide camera. |
CAMERA_TYPE_TELEPHOTO | 3 | Telephoto camera. |
CAMERA_TYPE_TRUE_DEPTH | 4 | Camera with depth of field information. |
ConnectionType
Enumerates the camera connection types.
System capability: SystemCapability.Multimedia.Camera.Core
Name | Value | Description |
---|---|---|
CAMERA_CONNECTION_BUILT_IN | 0 | Built-in camera. |
CAMERA_CONNECTION_USB_PLUGIN | 1 | Camera connected using USB. |
CAMERA_CONNECTION_REMOTE | 2 | Remote camera. |
CameraStatus
Enumerates the camera statuses.
System capability: SystemCapability.Multimedia.Camera.Core
Name | Value | Description |
---|---|---|
CAMERA_STATUS_APPEAR | 0 | A camera appears. |
CAMERA_STATUS_DISAPPEAR | 1 | The camera disappears. |
CAMERA_STATUS_AVAILABLE | 2 | The camera is available. |
CAMERA_STATUS_UNAVAILABLE | 3 | The camera is unavailable. |
CameraStatusInfo
Defines the camera status information.
System capability: SystemCapability.Multimedia.Camera.Core
Name | Type | Read-only | Mandatory | Description |
---|---|---|---|---|
camera | CameraDevice | No | Yes | Camera device. |
status | CameraStatus | No | Yes | Camera status. |
Profile
Defines the camera profile.
System capability: SystemCapability.Multimedia.Camera.Core
Name | Type | Read-only | Mandatory | Description |
---|---|---|---|---|
format | CameraFormat | Yes | Yes | Output format. |
size | Size | Yes | Yes | Resolution. |
FrameRateRange
Defines the frame rate range.
System capability: SystemCapability.Multimedia.Camera.Core
Name | Type | Read-only | Mandatory | Description |
---|---|---|---|---|
min | number | Yes | N/A | Minimum frame rate. |
max | number | Yes | N/A | Maximum frame rate. |
VideoProfile
Defines the video configuration information. It inherits from Profile.
System capability: SystemCapability.Multimedia.Camera.Core
Name | Type | Read-only | Mandatory | Description |
---|---|---|---|---|
frameRateRange | FrameRateRange | Yes | Yes | Frame rate range, in units of frames per second (FPS). |
CameraOutputCapability
Defines the camera output capability.
System capability: SystemCapability.Multimedia.Camera.Core
Name | Type | Read-only | Mandatory | Description |
---|---|---|---|---|
previewProfiles | Array<Profile> | Yes | N/A | Supported preview profiles. |
photoProfiles | Array<Profile> | Yes | N/A | Supported photo profiles. |
videoProfiles | Array<VideoProfile> | Yes | N/A | Supported video profiles. |
supportedMetadataObjectTypes | Array<MetadataObjectType> | Yes | N/A | Supported metadata object types. |
SceneMode11+
Enumerates the camera scene modes.
System capability: SystemCapability.Multimedia.Camera.Core
Name | Value | Description |
---|---|---|
NORMAL_PHOTO | 1 | Normal photo mode. |
NORMAL_VIDEO | 2 | Normal record mode. |
CameraErrorCode
Enumerates the camera error codes,
which are returned when an API call is incorrect or the on() API is used to listen for the error status.
System capability: SystemCapability.Multimedia.Camera.Core
Name | Value | Description |
---|---|---|
INVALID_ARGUMENT | 7400101 | A parameter is missing or the parameter type is incorrect. |
OPERATION_NOT_ALLOWED | 7400102 | The operation is not allowed. |
SESSION_NOT_CONFIG | 7400103 | The session is not configured. |
SESSION_NOT_RUNNING | 7400104 | The session is not running. |
SESSION_CONFIG_LOCKED | 7400105 | The session configuration is locked. |
DEVICE_SETTING_LOCKED | 7400106 | The device setting is locked. |
CONFLICT_CAMERA | 7400107 | The device is already started. |
DEVICE_DISABLED | 7400108 | The camera is disabled for security reasons. |
DEVICE_PREEMPTED | 7400109 | The camera is preempted. |
SERVICE_FATAL_ERROR | 7400201 | An error occurs in the camera service. |
CameraManager
Implements camera management. Before calling any API in CameraManager, you must use getCameraManager to obtain a CameraManager instance.
getSupportedCameras
getSupportedCameras(): Array<CameraDevice>
Obtains the supported camera devices. This API returns the result synchronously.
System capability: SystemCapability.Multimedia.Camera.Core
Return value
Type | Description |
---|---|
Array<CameraDevice> | Array of camera devices supported. |
Example
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;
}
getSupportedSceneModes11+
getSupportedSceneModes(camera: CameraDevice): Array<SceneMode>
Obtains the scene modes supported by a camera device. This API returns the result synchronously.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
camera | CameraDevice | Yes | CameraDevice instance, which is obtained through getSupportedCameras. |
Return value
Type | Description |
---|---|
Array<SceneMode> | Array of scene modes supported. |
Example
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(deprecated)
getSupportedOutputCapability(camera: CameraDevice): CameraOutputCapability
Obtains the output capability supported by a camera device. This API returns the result synchronously.
NOTE
This API is supported since API version 10 and deprecated since API version 11. You are advised to use getSupportedOutputCapability instead.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
camera | CameraDevice | Yes | CameraDevice instance, which is obtained through getSupportedCameras. |
Return value
Type | Description |
---|---|
CameraOutputCapability | Camera output capability obtained. |
Example
function getSupportedOutputCapability(camera: camera.CameraDevice, cameraManager: camera.CameraManager): camera.CameraOutputCapability {
let cameraOutputCapability: camera.CameraOutputCapability = cameraManager.getSupportedOutputCapability(camera);
return cameraOutputCapability;
}
getSupportedOutputCapability11+
getSupportedOutputCapability(camera: CameraDevice, mode: SceneMode): CameraOutputCapability
Obtains the output capability supported by a camera device in a given scene mode. This API returns the result synchronously.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
camera | CameraDevice | Yes | CameraDevice instance, which is obtained through getSupportedCameras. |
mode | SceneMode | Yes | Scene mode, which is obtained through getSupportedSceneModes. |
Return value
Type | Description |
---|---|
CameraOutputCapability | Camera output capability obtained. |
Example
function getSupportedOutputCapability(camera: camera.CameraDevice, cameraManager: camera.CameraManager, sceneMode: camera.SceneMode): camera.CameraOutputCapability {
let cameraOutputCapability: camera.CameraOutputCapability = cameraManager.getSupportedOutputCapability(camera, sceneMode);
return cameraOutputCapability;
}
isCameraMuted
isCameraMuted(): boolean
Checks whether the camera device is muted.
System capability: SystemCapability.Multimedia.Camera.Core
Return value
Type | Description |
---|---|
boolean | true: The camera device is muted. false: The camera device is not muted. |
Example
function isCameraMuted(cameraManager: camera.CameraManager): boolean {
let isMuted: boolean = cameraManager.isCameraMuted();
return isMuted;
}
createCameraInput
createCameraInput(camera: CameraDevice): CameraInput
Creates a CameraInput instance with the specified CameraDevice instance. This API returns the result synchronously.
Required permissions: ohos.permission.CAMERA
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
camera | CameraDevice | Yes | CameraDevice instance, which is obtained through getSupportedCameras. |
Return value
Type | Description |
---|---|
CameraInput | CameraInput instance created. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400101 | Parameter missing or parameter type incorrect. |
Example
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) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The createCameraInput call failed. error code: ${err.code}`);
}
return cameraInput;
}
createCameraInput
createCameraInput(position: CameraPosition, type: CameraType): CameraInput
Creates a CameraInput instance with the specified camera position and type. This API returns the result synchronously.
Required permissions: ohos.permission.CAMERA
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
position | CameraPosition | Yes | Camera position. You can call getSupportedCameras to obtain a CameraDevice instance, which contains the camera position information. |
type | CameraType | Yes | Camera type. You can call getSupportedCameras to obtain a CameraDevice instance, which contains the camera type information. |
Return value
Type | Description |
---|---|
CameraInput | CameraInput instance created. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400101 | Parameter missing or parameter type incorrect. |
Example
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) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The createCameraInput call failed. error code: ${err.code}`);
}
return cameraInput;
}
createPreviewOutput
createPreviewOutput(profile: Profile, surfaceId: string): PreviewOutput
Creates a PreviewOutput instance. This API returns the result synchronously.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
profile | Profile | Yes | Supported preview profiles, which are obtained through getSupportedOutputCapability. |
surfaceId | string | Yes | Surface ID, which is obtained from XComponent or ImageReceiver. |
Return value
Type | Description |
---|---|
PreviewOutput | PreviewOutput instance created. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400101 | Parameter missing or parameter type incorrect. |
Example
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) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The createPreviewOutput call failed. error code: ${err.code}`);
}
return previewOutput;
}
createPhotoOutput(deprecated)
createPhotoOutput(profile: Profile, surfaceId: string): PhotoOutput
Creates a PhotoOutput instance. This API returns the result synchronously.
NOTE
This API is supported since API version 10 and deprecated since API version 11. You are advised to use createPhotoOutput instead.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
profile | Profile | Yes | Supported photo profiles, which are obtained through getSupportedOutputCapability. |
surfaceId | string | Yes | Surface ID, which is obtained from ImageReceiver. |
Return value
Type | Description |
---|---|
PhotoOutput | PhotoOutput instance created. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
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) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The createPhotoOutput call failed. error code: ${err.code}`);
}
return photoOutput;
}
createPhotoOutput11+
createPhotoOutput(profile: Profile): PhotoOutput
Creates a PhotoOutput instance. This API returns the result synchronously.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
profile | Profile | Yes | Supported photo profiles, which are obtained through getSupportedOutputCapability. |
Return value
Type | Description |
---|---|
PhotoOutput | PhotoOutput instance created. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400101 | Parameter missing or parameter type incorrect. |
Example
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) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The createPhotoOutput call failed. error code: ${err.code}`);
}
return photoOutput;
}
createVideoOutput
createVideoOutput(profile: VideoProfile, surfaceId: string): VideoOutput
Creates a VideoOutput instance. This API returns the result synchronously.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
profile | VideoProfile | Yes | Supported video profiles, which are obtained through getSupportedOutputCapability. |
surfaceId | string | Yes | Surface ID, which is obtained from AVRecorder. |
Return value
Type | Description |
---|---|
VideoOutput | VideoOutput instance created. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400101 | Parameter missing or parameter type incorrect. |
Example
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) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The createVideoOutput call failed. error code: ${err.code}`);
}
return videoOutput;
}
createMetadataOutput
createMetadataOutput(metadataObjectTypes: Array<MetadataObjectType>): MetadataOutput
Creates a MetadataOutput instance. This API returns the result synchronously.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
metadataObjectTypes | Array<MetadataObjectType> | Yes | Metadata object types, which are obtained through getSupportedOutputCapability. |
Return value
Type | Description |
---|---|
MetadataOutput | MetadataOutput instance created. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400101 | Parameter missing or parameter type incorrect. |
Example
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) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`createMetadataOutput error. error code: ${err.code}`);
}
}
createCaptureSession(deprecated)
createCaptureSession(): CaptureSession
Creates a CaptureSession instance. This API returns the result synchronously.
NOTE
This API is supported since API version 10 and deprecated since API version 11. You are advised to use createSession instead.
System capability: SystemCapability.Multimedia.Camera.Core
Return value
Type | Description |
---|---|
CaptureSession | CaptureSession instance created. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400201 | Camera service fatal error. |
Example
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) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`createCaptureSession error. error code: ${err.code}`);
}
return captureSession;
}
createSession11+
createSession<T extends Session>(mode: SceneMode): T
Creates a Session instance with a given scene mode. This API returns the result synchronously.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
mode | SceneMode | Yes | Scene mode. |
Return value
Type | Description |
---|---|
T extends Session | Session instance created. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400201 | Camera service fatal error. |
Example
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) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`createCaptureSession error. error code: ${err.code}`);
}
return photoSession;
}
on('cameraStatus')
on(type: 'cameraStatus', callback: AsyncCallback<CameraStatusInfo>): void
Subscribes to camera status events. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description | |
---|---|---|---|---|
type | string | Yes | Event type. The value is fixed at 'cameraStatus'. The event can be listened for when a CameraManager instance is obtained. This event is triggered and the corresponding information is returned only when the camera device is enabled or disabled. | |
callback | AsyncCallback<CameraStatusInfo> | Yes | Callback used to return the camera status change. |
Example
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('cameraStatus')
off(type: 'cameraStatus', callback?: AsyncCallback<CameraStatusInfo>): void
Unsubscribes from camera status events. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type. The value is fixed at 'cameraStatus'. The event can be listened for when a CameraManager instance is obtained. |
callback | AsyncCallback<CameraStatusInfo> | No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('cameraStatus') with the specified callback is canceled. (The callback object cannot be an anonymous function.) |
Example
function unregisterCameraStatus(cameraManager: camera.CameraManager): void {
cameraManager.off('cameraStatus');
}
isTorchSupported11+
isTorchSupported(): boolean
Checks whether the camera device supports the flashlight.
System capability: SystemCapability.Multimedia.Camera.Core
Return value
Type | Description |
---|---|
boolean | true: The camera device supports the flashlight. false: The camera device does not support the flashlight. |
Example
function isTorchSupported(cameraManager: camera.CameraManager): boolean {
let isSupported = cameraManager.isTorchSupported();
return isSupported;
}
isTorchModeSupported11+
isTorchModeSupported(mode: TorchMode): boolean
Checks whether a flashlight mode is supported.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
mode | TorchMode | Yes | Flashlight mode. |
Return value
Type | Description |
---|---|
boolean | true: The flashlight mode is supported. false: The flashlight mode is not supported. |
Example
function isTorchModeSupported(cameraManager: camera.CameraManager, torchMode: camera.TorchMode): boolean {
let isSupported = cameraManager.isTorchModeSupported(torchMode);
return isSupported;
}
getTorchMode11+
getTorchMode(): TorchMode
Obtains the flashlight mode of this camera device.
System capability: SystemCapability.Multimedia.Camera.Core
Return value
Type | Description |
---|---|
TorchMode | Flashlight mode. |
Example
function getTorchMode(cameraManager: camera.CameraManager): camera.TorchMode | undefined {
let torchMode: camera.TorchMode | undefined = undefined;
torchMode = cameraManager.getTorchMode();
return torchMode;
}
setTorchMode11+
setTorchMode(mode: TorchMode): void
Sets the flashlight mode.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
mode | TorchMode | Yes | Flashlight mode. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400101 | Parameter missing or parameter type incorrect. |
Example
import { BusinessError } from '@ohos.base';
function setTorchMode(cameraManager: camera.CameraManager, torchMode: camera.TorchMode): void {
try {
cameraManager.setTorchMode(torchMode);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The setTorchMode call failed. error code: ${err.code}`);
}
}
on('torchStatusChange')11+
on(type: 'torchStatusChange', callback: AsyncCallback<TorchStatusInfo>): void
Subscribes to flashlight status change events. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type. The value is fixed at 'torchStatusChange'. The event can be listened for when a CameraManager instance is obtained. Currently, this event is triggered only in the following scenarios: The flashlight is turned on or turned off, or becomes unavailable or available. |
callback | AsyncCallback<TorchStatusInfo> | Yes | Callback used to return the flashlight status. |
Example
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('torchStatusChange')11+
off(type: 'torchStatusChange', callback?: AsyncCallback<TorchStatusInfo>): void
Unsubscribes from flashlight status change events. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type. The value is fixed at 'torchStatusChange'. The event can be listened for when a CameraManager instance is obtained. |
callback | AsyncCallback<TorchStatusInfo> | No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('torchStatusChange') with the specified callback is canceled. (The callback object cannot be an anonymous function.) |
Example
function unregisterTorchStatusChange(cameraManager: camera.CameraManager): void {
cameraManager.off('torchStatusChange');
}
TorchMode11+
Enumerates the flashlight modes.
System capability: SystemCapability.Multimedia.Camera.Core
Name | Value | Description |
---|---|---|
OFF | 0 | The flashlight is off. |
ON | 1 | The flashlight is on. |
AUTO | 2 | The flashlight mode is auto. |
TorchStatusInfo11+
Defines the flashlight status information.
System capability: SystemCapability.Multimedia.Camera.Core
Name | Type | Read-only | Mandatory | Description |
---|---|---|---|---|
isTorchAvailable | boolean | Yes | Yes | Whether the flashlight is available. |
isTorchActive | boolean | Yes | Yes | Whether the flashlight is activated. |
torchLevel | number | Yes | Yes | Flashlight level. The value range is [0, 1]. A larger value indicates a greater luminance. |
Size
Defines the output capability.
System capability: SystemCapability.Multimedia.Camera.Core
Name | Type | Read-only | Mandatory | Description |
---|---|---|---|---|
height | number | No | N/A | Image height, in pixels. |
width | number | No | N/A | Image width, in pixels. |
Point
Defines the point coordinates, which are used for focus and exposure configuration.
System capability: SystemCapability.Multimedia.Camera.Core
Name | Type | Read-only | Mandatory | Description |
---|---|---|---|---|
x | number | No | Yes | X coordinate of a point. |
y | number | No | Yes | Y coordinate of a point. |
CameraFormat
Enumerates the camera output formats.
System capability: SystemCapability.Multimedia.Camera.Core
Name | Value | Description |
---|---|---|
CAMERA_FORMAT_RGBA_8888 | 3 | RGBA_888 image. |
CAMERA_FORMAT_YUV_420_SP | 1003 | YUV_420_SP image. |
CAMERA_FORMAT_JPEG | 2000 | JPEG image. |
CAMERA_FORMAT_YCBCR_P01011+ | 2001 | YCBCR_P010 image. |
CAMERA_FORMAT_YCRCB_P01011+ | 2002 | YCRCB_P010 image. |
CameraInput
Defines the camera input object.
Provides camera device information used in Session.
open
open(callback: AsyncCallback<void>): void
Opens this camera device. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400107 | Can not use camera cause of conflict. |
7400108 | Camera disabled cause of security reason. |
7400201 | Camera service fatal error. |
Example
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
open(): Promise<void>
Opens this camera device. This API uses a promise to return the result.
System capability: SystemCapability.Multimedia.Camera.Core
Return value
Type | Description |
---|---|
Promise<void> | Promise used to return the result. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400107 | Can not use camera cause of conflict. |
7400108 | Camera disabled cause of security reason. |
7400201 | Camera service fatal error. |
Example
import { BusinessError } from '@ohos.base';
function openCameraInput(cameraInput: camera.CameraInput): void {
cameraInput.open().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
close(callback: AsyncCallback<void>): void
Closes this camera device. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400201 | Camera service fatal error. |
Example
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
close(): Promise<void>
Closes this camera device. This API uses a promise to return the result.
System capability: SystemCapability.Multimedia.Camera.Core
Return value
Type | Description |
---|---|
Promise<void> | Promise used to return the result. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400201 | Camera service fatal error. |
Example
import { BusinessError } from '@ohos.base';
function closeCameraInput(cameraInput: camera.CameraInput): void {
cameraInput.close().then(() => {
console.info('Promise returned with camera closed.');
}).catch((error: BusinessError) => {
let err = error as BusinessError;
console.error(`Failed to close the cameras, error code: ${err.code}.`);
});
}
on('error')
on(type: 'error', camera: CameraDevice, callback: ErrorCallback): void
Subscribes to CameraInput error events. This API uses a callback to return the result.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type. The value is fixed at 'error'. The event can be listened for when a CameraInput instance is created. This event is triggered and the result is returned when an error occurs on the camera device. For example, if the camera device is unavailable or a conflict occurs, the error information is returned. |
camera | CameraDevice | Yes | Camera device. |
callback | ErrorCallback | Yes | Callback used to return an error code defined in CameraErrorCode. |
Example
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('error')
off(type: 'error', camera: CameraDevice, callback?: ErrorCallback): void
Unsubscribes from CameraInput error events.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type. The value is fixed at 'error'. The event can be listened for when a CameraInput instance is created. This event is triggered and the result is returned when an error occurs on the camera device. For example, if the camera device is unavailable or a conflict occurs, the error information is returned. |
camera | CameraDevice | Yes | Camera device. |
callback | ErrorCallback | No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('error') with the specified callback is canceled. (The callback object cannot be an anonymous function.) |
Example
function unregisterCameraInputError(cameraInput: camera.CameraInput, camera: camera.CameraDevice): void {
cameraInput.off('error', camera);
}
CameraOutput
Implements output information used in Session. It is the base class of output.
release
release(callback: AsyncCallback<void>): void
Releases output resources. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400201 | Camera service fatal error. |
Example
import { BusinessError } from '@ohos.base';
function releasePreviewOutput(previewOutput: camera.PreviewOutput): void {
previewOutput.release((err: BusinessError) => {
if (err) {
console.error(`Failed to release the PreviewOutput instance ${err.code}`);
return;
}
console.info('Callback invoked to indicate that the previewOutput instance is released successfully.');
});
}
function releaseVideoOutput(videoOutput: camera.VideoOutput): void {
videoOutput.release((err: BusinessError) => {
if (err) {
console.error(`Failed to release the VideoOutput instance ${err.code}`);
return;
}
console.info('Callback invoked to indicate that the videoOutput instance is released successfully.');
});
}
release
release(): Promise<void>
Releases output resources. This API uses a promise to return the result.
System capability: SystemCapability.Multimedia.Camera.Core
Return value
Type | Description |
---|---|
Promise<void> | Promise used to return the result. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400201 | Camera service fatal error. |
Example
import { BusinessError } from '@ohos.base';
function releasePreviewOutput(previewOutput: camera.PreviewOutput): void {
previewOutput.release().then(() => {
console.info('Promise returned to indicate that the PreviewOutput instance is released successfully.');
}).catch((error: BusinessError) => {
let err = error as BusinessError;
console.error(`Failed to previewOutput release, error code: ${err.code}`);
});
}
function releaseVideoOutput(videoOutput: camera.VideoOutput): void {
videoOutput.release().then(() => {
console.info('Promise returned to indicate that the VideoOutput instance is released successfully.');
}).catch((error: BusinessError) => {
let err = error as BusinessError;
console.error(`Failed to videoOutput release, error code: ${err.code}`);
});
}
PreviewOutput
Implements preview output. It inherits from CameraOutput.
start(deprecated)
start(callback: AsyncCallback<void>): void
Starts to output preview streams. This API uses an asynchronous callback to return the result.
NOTE
This API is supported since API version 10 and deprecated since API version 11. You are advised to use Session.start instead.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
Example
import { BusinessError } from '@ohos.base';
function startPreviewOutput(previewOutput: camera.PreviewOutput): void {
previewOutput.start((err: BusinessError) => {
if (err) {
console.error(`Failed to start the previewOutput, error code: ${err.code}.`);
return;
}
console.info('Callback returned with previewOutput started.');
});
}
start(deprecated)
start(): Promise<void>
Starts to output preview streams. This API uses a promise to return the result.
NOTE
This API is supported since API version 10 and deprecated since API version 11. You are advised to use Session.start instead.
System capability: SystemCapability.Multimedia.Camera.Core
Return value
Type | Description |
---|---|
Promise<void> | Promise used to return the result. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
Example
import { BusinessError } from '@ohos.base';
function startPreviewOutput(previewOutput: camera.PreviewOutput): void {
previewOutput.start().then(() => {
console.info('Promise returned with previewOutput started.');
}).catch((error: BusinessError) => {
let err = error as BusinessError;
console.error(`Failed to previewOutput start, error code: ${err.code}.`);
});
}
stop(deprecated)
stop(callback: AsyncCallback<void>): void
Stops outputting preview streams. This API uses an asynchronous callback to return the result.
NOTE
This API is supported since API version 10 and deprecated since API version 11. You are advised to use Session.stop instead.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
callback | AsyncCallback<void> | Yes | Callback used to return the result. |
Example
import { BusinessError } from '@ohos.base';
function stopPreviewOutput(previewOutput: camera.PreviewOutput): void {
previewOutput.stop((err: BusinessError) => {
if (err) {
console.error(`Failed to stop the previewOutput, error code: ${err.code}.`);
return;
}
console.info('Returned with previewOutput stopped.');
})
}
stop(deprecated)
stop(): Promise<void>
Stops outputting preview streams. This API uses a promise to return the result.
NOTE
This API is supported since API version 10 and deprecated since API version 11. You are advised to use Session.stop instead.
System capability: SystemCapability.Multimedia.Camera.Core
Return value
Type | Description |
---|---|
Promise<void> | Promise used to return the result. |
Example
import { BusinessError } from '@ohos.base';
function stopPreviewOutput(previewOutput: camera.PreviewOutput): void {
previewOutput.stop().then(() => {
console.info('Callback returned with previewOutput stopped.');
}).catch((error: BusinessError) => {
let err = error as BusinessError;
console.error(`Failed to previewOutput stop, error code: ${err.code}.`);
});
}
on('frameStart')
on(type: 'frameStart', callback: AsyncCallback<void>): void
Subscribes to preview frame start events. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type. The value is fixed at 'frameStart'. The event can be listened for when a previewOutput instance is created. This event is triggered and returned when the bottom layer starts exposure for the first time. |
callback | AsyncCallback<void> | Yes | Callback used to return the result. The preview starts as long as this event is returned. |
Example
function callback(): void {
console.info('Preview frame started');
}
function registerPreviewOutputFrameStart(previewOutput: camera.PreviewOutput): void {
previewOutput.on('frameStart', callback);
}
off('frameStart')
off(type: 'frameStart', callback?: AsyncCallback<void>): void
Unsubscribes from preview frame start events.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type. The value is fixed at 'frameStart'. The event can be listened for when a previewOutput instance is created. |
callback | AsyncCallback<void> | No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('frameStart') with the specified callback is canceled. (The callback object cannot be an anonymous function.) |
Example
function unregisterPreviewOutputFrameStart(previewOutput: camera.PreviewOutput): void {
previewOutput.off('frameStart');
}
on('frameEnd')
on(type: 'frameEnd', callback: AsyncCallback<void>): void
Subscribes to preview frame end events. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type. The value is fixed at 'frameEnd'. The event can be listened for when a previewOutput instance is created. This event is triggered and returned when the last frame of preview ends. |
callback | AsyncCallback<void> | Yes | Callback used to return the result. The preview ends as long as this event is returned. |
Example
function callback(): void {
console.info('Preview frame ended');
}
function registerPreviewOutputFrameEnd(previewOutput: camera.PreviewOutput): void {
previewOutput.on('frameEnd', callback);
}
off('frameEnd')
off(type: 'frameEnd', callback?: AsyncCallback<void>): void
Unsubscribes from preview frame end events.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type. The value is fixed at 'frameEnd'. The event can be listened for when a previewOutput instance is created. |
callback | AsyncCallback<void> | No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('frameEnd') with the specified callback is canceled. (The callback object cannot be an anonymous function.) |
Example
function unregisterPreviewOutputFrameEnd(previewOutput: camera.PreviewOutput): void {
previewOutput.off('frameEnd');
}
on('error')
on(type: 'error', callback: ErrorCallback): void
Subscribes to PreviewOutput error events. This API uses a callback to return the result.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type. The value is fixed at 'error'. The event can be listened for when a previewOutput instance is created. This event is triggered and the corresponding error message is returned when an error occurs during the use of a preview-related API such as Session.start or CameraOutput.release. |
callback | ErrorCallback | Yes | Callback used to return an error code defined in CameraErrorCode. |
Example
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('error')
off(type: 'error', callback?: ErrorCallback): void
Unsubscribes from PreviewOutput error events.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type. The value is fixed at 'error'. The event can be listened for when a previewOutput instance is created. |
callback | ErrorCallback | No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('error') with the specified callback is canceled. (The callback object cannot be an anonymous function.) |
Example
function unregisterPreviewOutputError(previewOutput: camera.PreviewOutput): void {
previewOutput.off('error');
}
ImageRotation
Enumerates the image rotation angles.
System capability: SystemCapability.Multimedia.Camera.Core
Name | Value | Description |
---|---|---|
ROTATION_0 | 0 | The image rotates 0 degrees. |
ROTATION_90 | 90 | The image rotates 90 degrees. |
ROTATION_180 | 180 | The image rotates 180 degrees. |
ROTATION_270 | 270 | The image rotates 270 degrees. |
Location
Defines the geolocation information.
System capability: SystemCapability.Multimedia.Camera.Core
Name | Type | Read-only | Mandatory | Description |
---|---|---|---|---|
latitude | number | No | N/A | Latitude, in degrees. |
longitude | number | No | N/A | Longitude, in degrees. |
altitude | number | No | N/A | Altitude, in meters. |
QualityLevel
Enumerates the image quality levels.
System capability: SystemCapability.Multimedia.Camera.Core
Name | Value | Description |
---|---|---|
QUALITY_LEVEL_HIGH | 0 | High image quality. |
QUALITY_LEVEL_MEDIUM | 1 | Medium image quality. |
QUALITY_LEVEL_LOW | 2 | Low image quality. |
PhotoCaptureSetting
Defines the settings for taking an image.
System capability: SystemCapability.Multimedia.Camera.Core
Name | Type | Read-only | Mandatory | Description |
---|---|---|---|---|
quality | QualityLevel | No | No | Image quality (low by default). |
rotation | ImageRotation | No | No | Rotation angle of the image. The default value is 0, indicating clockwise rotation. |
location | Location | No | No | Geolocation information of the image (depending on the device hardware information by default). |
mirror | boolean | No | No | Whether mirror photography is enabled (disabled by default). Before using this enumerated value, call isMirrorSupported to check whether mirror photography is supported. |
Photo11+
Defines a higher-resolution image object.
Attributes
System capability: SystemCapability.Multimedia.Camera.Core
Name | Type | Mandatory | Description |
---|---|---|---|
main11+ | image.Image | Yes | Higher-resolution image. |
release11+
release(): Promise<void>
Releases output resources. This API uses a promise to return the result.
System capability: SystemCapability.Multimedia.Camera.Core
Return value
Type | Description |
---|---|
Promise<void> | Promise used to return the result. If the operation fails, an error code defined in CameraErrorCode is returned. |
Example
async function releasePhoto(photo: camera.Photo): Promise<void> {
await photo.release();
}
PhotoOutput
Implements output information used in a photo session. It inherits from CameraOutput.
capture
capture(callback: AsyncCallback<void>): void
Captures a photo with the default photo capture parameters. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400104 | Session not running. |
7400201 | Camera service fatal error. |
Example
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
capture(): Promise<void>
Captures a photo with the default photo capture parameters. This API uses a promise to return the result.
System capability: SystemCapability.Multimedia.Camera.Core
Return value
Type | Description |
---|---|
Promise<void> | Promise used to return the result. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400104 | Session not running. |
7400201 | Camera service fatal error. |
Example
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) => {
let err = error as BusinessError;
console.error(`Failed to photoOutput capture, error code: ${err.code}.`);
});
}
capture
capture(setting: PhotoCaptureSetting, callback: AsyncCallback<void>): void
Captures a photo with the specified photo capture parameters. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
setting | PhotoCaptureSetting | Yes | Photo capture settings. |
callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400101 | Parameter missing or parameter type incorrect. |
7400104 | Session not running. |
7400201 | Camera service fatal error. |
Example
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
capture(setting: PhotoCaptureSetting): Promise<void>
Captures a photo with the specified photo capture parameters. This API uses a promise to return the result.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
setting | PhotoCaptureSetting | Yes | Photo capture parameters. The input of undefined is processed as if no parameters were passed. |
Return value
Type | Description |
---|---|
Promise<void> | Promise used to return the result. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400101 | Parameter missing or parameter type incorrect. |
7400104 | Session not running. |
7400201 | Camera service fatal error. |
Example
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) => {
let err = error as BusinessError;
console.error(`Failed to photoOutput capture, error code: ${err.code}.`);
});
}
on('photoAvailable')11+
on(type: 'photoAvailable', callback: AsyncCallback<Photo>): void
Subscribes to events indicating available high-resolution images.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type. The value is fixed at 'photoAvailable'. The event can be listened for when a photoOutput instance is created. |
callback | AsyncCallback<Photo> | Yes | Callback used to return the high-resolution image. |
Example
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('photoAvailable')11+
off(type: 'photoAvailable', callback?: AsyncCallback<Photo>): void
Unsubscribes from events indicating available high-resolution images.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type. The value is fixed at 'photoAvailable'. The event can be listened for when a photoOutput instance is created. |
callback | AsyncCallback<Photo> | No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('photoAvailable') with the specified callback is canceled. (The callback object cannot be an anonymous function.) |
Example
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('captureStartWithInfo')11+
on(type: 'captureStartWithInfo', callback: AsyncCallback<CaptureStartInfo>): void
Subscribes to capture start events. This API uses an asynchronous callback to return the capture start ID.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type. The value is fixed at 'captureStartWithInfo'. The event can be listened for when a photoOutput instance is created. |
callback | AsyncCallback<CaptureStartInfo> | Yes | Callback used to return the capture ID. |
Example
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('captureStartWithInfo')11+
off(type: 'captureStartWithInfo', callback?: AsyncCallback<CaptureStartInfo>): void
Unsubscribes from capture start events.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type. The value is fixed at 'captureStartWithInfo'. The event can be listened for when a photoOutput instance is created. |
callback | AsyncCallback<CaptureStartInfo> | No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('captureStartWithInfo') with the specified callback is canceled. (The callback object cannot be an anonymous function.) |
Example
import { BusinessError } from '@ohos.base';
function unRegisterCaptureStartWithInfo(photoOutput: camera.PhotoOutput): void {
photoOutput.off('captureStartWithInfo');
}
isMirrorSupported
isMirrorSupported(): boolean
Checks whether mirror photography is supported.
System capability: SystemCapability.Multimedia.Camera.Core
Return value
Type | Description |
---|---|
boolean | true: Mirror photography is supported. false: Mirror photography is not supported. |
Example
function isMirrorSupported(photoOutput: camera.PhotoOutput): boolean {
let isSupported: boolean = photoOutput.isMirrorSupported();
return isSupported;
}
on('captureStart')(deprecated)
on(type: 'captureStart', callback: AsyncCallback<number>): void
Subscribes to capture start events. This API uses an asynchronous callback to return the capture ID.
NOTE
This API is supported since API version 10 and deprecated since API version 11. You are advised to use on('captureStartWithInfo') instead.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type. The value is fixed at 'captureStart'. The event can be listened for when a photoOutput instance is created. This event is triggered and returned when the bottom layer starts exposure each time a photo is taken. |
callback | AsyncCallback<number> | Yes | Callback used to return the capture ID. |
Example
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('captureStart')(deprecated)
off(type: 'captureStart', callback?: AsyncCallback<number>): void
Unsubscribes from capture start events.
NOTE
This API is supported since API version 10 and deprecated since API version 11. You are advised to use off('captureStartWithInfo') instead.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type. The value is fixed at 'captureStart'. The event can be listened for when a photoOutput instance is created. |
callback | AsyncCallback<number> | No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('captureStart') with the specified callback is canceled. (The callback object cannot be an anonymous function.) |
Example
function unregisterPhotoOutputCaptureStart(photoOutput: camera.PhotoOutput): void {
photoOutput.off('captureStart');
}
on('frameShutter')
on(type: 'frameShutter', callback: AsyncCallback<FrameShutterInfo>): void
Subscribes to frame shutter events. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type. The value is fixed at 'frameShutter'. The event can be listened for when a photoOutput instance is created. |
callback | AsyncCallback<FrameShutterInfo> | Yes | Callback used to return the result. A new photographing request can be delivered as long as this event is returned. |
Example
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('frameShutter')
off(type: 'frameShutter', callback?: AsyncCallback<FrameShutterInfo>): void
Unsubscribes from frame shutter events.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type. The value is fixed at 'frameShutter'. The event can be listened for when a photoOutput instance is created. |
callback | AsyncCallback<FrameShutterInfo> | No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('frameShutter') with the specified callback is canceled. (The callback object cannot be an anonymous function.) |
Example
function unregisterPhotoOutputFrameShutter(photoOutput: camera.PhotoOutput): void {
photoOutput.off('frameShutter');
}
on('captureEnd')
on(type: 'captureEnd', callback: AsyncCallback<CaptureEndInfo>): void
Subscribes to capture end events. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type. The value is fixed at 'captureEnd'. The event can be listened for when a photoOutput instance is created. This event is triggered and the corresponding information is returned when the photographing is complete. |
callback | AsyncCallback<CaptureEndInfo> | Yes | Callback used to return the result. |
Example
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('captureEnd')
off(type: 'captureEnd', callback?: AsyncCallback<CaptureEndInfo>): void
Unsubscribes from capture end events.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type. The value is fixed at 'captureEnd'. The event can be listened for when a photoOutput instance is created. |
callback | AsyncCallback<CaptureEndInfo> | No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('captureEnd') with the specified callback is canceled. (The callback object cannot be an anonymous function.) |
Example
function unregisterPhotoOutputCaptureEnd(photoOutput: camera.PhotoOutput): void {
photoOutput.off('captureEnd');
}
on('error')
on(type: 'error', callback: ErrorCallback): void
Subscribes to PhotoOutput error events. This API uses a callback to return the result.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type. The value is fixed at 'error'. The event can be listened for when a photoOutput instance is created. This event is triggered and the corresponding error message is returned when an error occurs during the calling of a photo-related API. |
callback | ErrorCallback | Yes | Callback used to return an error code defined in CameraErrorCode. |
Example
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('error')
off(type: 'error', callback?: ErrorCallback): void
Unsubscribes from PhotoOutput error events.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type. The value is fixed at 'error'. The event can be listened for when a photoOutput instance is created. |
callback | ErrorCallback | No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('error') with the specified callback is canceled. (The callback object cannot be an anonymous function.) |
Example
function unregisterPhotoOutputError(photoOutput: camera.PhotoOutput): void {
photoOutput.off('error');
}
FrameShutterInfo
Defines the frame shutter information.
System capability: SystemCapability.Multimedia.Camera.Core
Name | Type | Read-only | Mandatory | Description |
---|---|---|---|---|
captureId | number | No | Yes | ID of this capture action. |
timestamp | number | No | Yes | Timestamp when the frame shutter event is triggered. |
CaptureStartInfo11+
Defines the capture start information.
System capability: SystemCapability.Multimedia.Camera.Core
Name | Type | Read-only | Mandatory | Description |
---|---|---|---|---|
captureId | number | No | Yes | ID of this capture action. |
time | number | No | Yes | Capture timestamp. |
CaptureEndInfo
Defines the capture end information.
System capability: SystemCapability.Multimedia.Camera.Core
Name | Type | Read-only | Mandatory | Description |
---|---|---|---|---|
captureId | number | No | Yes | ID of this capture action. |
frameCount | number | No | Yes | Number of frames captured. |
VideoOutput
Implements output information used in a video session. It inherits from CameraOutput.
start
start(callback: AsyncCallback<void>): void
Starts video recording. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
7400201 | Camera service fatal error. |
Example
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
start(): Promise<void>
Starts video recording. This API uses a promise to return the result.
System capability: SystemCapability.Multimedia.Camera.Core
Return value
Type | Description |
---|---|
Promise<void> | Promise used to return the result. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
7400201 | Camera service fatal error. |
Example
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) => {
let err = error as BusinessError;
console.error(`Failed to videoOutput start, error code: ${err.code}.`);
});
}
stop
stop(callback: AsyncCallback<void>): void
Stops video recording. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
callback | AsyncCallback<void> | Yes | Callback used to return the result. |
Example
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
stop(): Promise<void>
Stops video recording. This API uses a promise to return the result.
System capability: SystemCapability.Multimedia.Camera.Core
Return value
Type | Description |
---|---|
Promise<void> | Promise used to return the result. |
Example
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) => {
let err = error as BusinessError;
console.error(`Failed to videoOutput stop, error code: ${err.code}.`);
});
}
on('frameStart')
on(type: 'frameStart', callback: AsyncCallback<void>): void
Subscribes to video recording start events. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type. The value is fixed at 'frameStart'. The event can be listened for when a videoOutput instance is created. The event is triggered and the corresponding information is returned when the bottom layer starts exposure for the first time. |
callback | AsyncCallback<void> | Yes | Callback used to return the result. The recording starts as long as this event is returned. |
Example
function callback(): void {
console.info('Video frame started');
}
function registerVideoOutputFrameStart(videoOutput: camera.VideoOutput): void {
videoOutput.on('frameStart', callback);
}
off('frameStart')
off(type: 'frameStart', callback?: AsyncCallback<void>): void
Unsubscribes from video recording start events.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type. The value is fixed at 'frameStart'. The event can be listened for when a videoOutput instance is created. |
callback | AsyncCallback<void> | No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('frameStart') with the specified callback is canceled. (The callback object cannot be an anonymous function.) |
Example
function unregisterVideoOutputFrameStart(videoOutput: camera.VideoOutput): void {
videoOutput.off('frameStart');
}
on('frameEnd')
on(type: 'frameEnd', callback: AsyncCallback<void>): void
Subscribes to video recording stop events. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type. The value is fixed at 'frameEnd'. The event can be listened for when a videoOutput instance is created. This event is triggered and returned when the last frame of recording is complete. |
callback | AsyncCallback<void> | Yes | Callback used to return the result. The recording ends as long as this event is returned. |
Example
function callback(): void {
console.info('Video frame ended');
}
function registerVideoOutputFrameEnd(videoOutput: camera.VideoOutput): void {
videoOutput.on('frameEnd', callback);
}
off('frameEnd')
off(type: 'frameEnd', callback?: AsyncCallback<void>): void
Unsubscribes from video recording stop events.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type. The value is fixed at 'frameEnd'. The event can be listened for when a videoOutput instance is created. |
callback | AsyncCallback<void> | No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('frameEnd') with the specified callback is canceled. (The callback object cannot be an anonymous function.) |
Example
function unregisterVideoOutputFrameEnd(videoOutput: camera.VideoOutput): void {
videoOutput.off('frameEnd');
}
on('error')
on(type: 'error', callback: ErrorCallback): void
Subscribes to VideoOutput error events. This API uses a callback to return the result.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type. The value is fixed at 'error'. The event can be listened for when a videoOutput instance is created. This event is triggered and the corresponding error message is returned when an error occurs during the use of a recording-related API such as start or CameraOutput.release. |
callback | ErrorCallback | Yes | Callback used to return an error code defined in CameraErrorCode. |
Example
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('error')
off(type: 'error', callback?: ErrorCallback): void
Unsubscribes from VideoOutput error events.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type. The value is fixed at 'error'. The event can be listened for when a photoOutput instance is created. |
callback | ErrorCallback | No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('error') with the specified callback is canceled. (The callback object cannot be an anonymous function.) |
Example
function unregisterVideoOutputError(videoOutput: camera.VideoOutput): void {
videoOutput.off('error');
}
MetadataOutput
Implements metadata streams. It inherits from CameraOutput.
start
start(callback: AsyncCallback<void>): void
Starts to output metadata. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
7400201 | Camera service fatal error. |
Example
import { BusinessError } from '@ohos.base';
function startMetadataOutput(metadataOutput: camera.MetadataOutput): void {
metadataOutput.start((err: BusinessError) => {
if (err) {
console.error(`Failed to start metadataOutput, error code: ${err.code}.`);
return;
}
console.info('Callback returned with metadataOutput started.');
});
}
start
start(): Promise<void>
Starts to output metadata. This API uses a promise to return the result.
System capability: SystemCapability.Multimedia.Camera.Core
Return value
Type | Description |
---|---|
Promise<void> | Promise used to return the result. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
7400201 | Camera service fatal error. |
Example
import { BusinessError } from '@ohos.base';
function startMetadataOutput(metadataOutput: camera.MetadataOutput): void {
metadataOutput.start().then(() => {
console.info('Callback returned with metadataOutput started.');
}).catch((error: BusinessError) => {
let err = error as BusinessError;
console.error(`Failed to metadataOutput stop, error code: ${err.code}`);
});
}
stop
stop(callback: AsyncCallback<void>): void
Stops outputting metadata. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
callback | AsyncCallback<void> | Yes | Callback used to return the result. |
Example
import { BusinessError } from '@ohos.base';
function stopMetadataOutput(metadataOutput: camera.MetadataOutput): void {
metadataOutput.stop((err: BusinessError) => {
if (err) {
console.error(`Failed to stop the metadataOutput, error code: ${err.code}.`);
return;
}
console.info('Callback returned with metadataOutput stopped.');
})
}
stop
stop(): Promise<void>
Stops outputting metadata. This API uses a promise to return the result.
System capability: SystemCapability.Multimedia.Camera.Core
Return value
Type | Description |
---|---|
Promise<void> | Promise used to return the result. |
Example
import { BusinessError } from '@ohos.base';
function stopMetadataOutput(metadataOutput: camera.MetadataOutput): void {
metadataOutput.stop().then(() => {
console.info('Callback returned with metadataOutput stopped.');
}).catch((error: BusinessError) => {
let err = error as BusinessError;
console.error(`Failed to metadataOutput stop, error code: ${err.code}`);
});
}
on('metadataObjectsAvailable')
on(type: 'metadataObjectsAvailable', callback: AsyncCallback<Array<MetadataObject>>): void
Subscribes to events indicating available metadata objects. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type. The value is fixed at 'metadataObjectsAvailable'. The event can be listened for when a metadataOutput instance is created. This event is triggered and the corresponding metadata is returned when valid metadata is detected. |
callback | AsyncCallback<Array<MetadataObject>> | Yes | Callback used to return the metadata. |
Example
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('metadataObjectsAvailable')
off(type: 'metadataObjectsAvailable', callback?: AsyncCallback<Array<MetadataObject>>): void
Unsubscribes from events indicating available metadata objects.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type. The value is fixed at 'metadataObjectsAvailable'. The event can be listened for when a metadataOutput instance is created. |
callback | AsyncCallback<Array<MetadataObject>> | No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('metadataObjectsAvailable') with the specified callback is canceled. (The callback object cannot be an anonymous function.) |
Example
function unregisterMetadataObjectsAvailable(metadataOutput: camera.MetadataOutput): void {
metadataOutput.off('metadataObjectsAvailable');
}
on('error')
on(type: 'error', callback: ErrorCallback): void
Subscribes to metadata error events. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type. The value is fixed at 'error'. The event can be listened for when a metadataOutput instance is created. This event is triggered and the corresponding error message is returned when an error occurs during the use of a metadata-related API such as start or CameraOutput.release. |
callback | ErrorCallback | Yes | Callback used to return an error code defined in CameraErrorCode. |
Example
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('error')
off(type: 'error', callback?: ErrorCallback): void
Unsubscribes from metadata error events.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type. The value is fixed at 'error'. The event can be listened for when a metadataOutput instance is created. |
callback | ErrorCallback | No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('error') with the specified callback is canceled. (The callback object cannot be an anonymous function.) |
Example
function unregisterMetadataOutputError(metadataOutput: camera.MetadataOutput): void {
metadataOutput.off('error');
}
MetadataObjectType
Enumerates the metadata object types.
System capability: SystemCapability.Multimedia.Camera.Core
Name | Value | Description |
---|---|---|
FACE_DETECTION | 0 | Metadata object used for face detection. The detection point must be in the coordinate system (0-1), where the upper left corner is (0, 0) and the lower right corner is (1, 1). The coordinate system is based on the horizontal device direction with the device's charging port on the right. If the layout of a preview screen of an application is based on the vertical direction with the charging port on the lower side, the layout width and height are (w, h) and the return point is (x, y), then the coordinate point after conversion is (1-y, x). |
Rect
Defines a rectangle.
System capability: SystemCapability.Multimedia.Camera.Core
Name | Type | Read-only | Mandatory | Description |
---|---|---|---|---|
topLeftX | number | No | N/A | X-axis coordinate of the upper left corner of the rectangle. |
topLeftY | number | No | N/A | Y-axis coordinate of the upper left corner of the rectangle. |
width | number | No | N/A | Width of the rectangle, which is a relative value. The value range is [0, 1]. |
height | number | No | N/A | Height of the rectangle, which is a relative value. The value range is [0, 1]. |
MetadataObject
Implements camera metadata, which is the data source of CameraInput. The metadata is obtained through metadataOutput.on('metadataObjectsAvailable').
System capability: SystemCapability.Multimedia.Camera.Core
Name | Type | Read-only | Mandatory | Description |
---|---|---|---|---|
type | MetadataObjectType | Yes | Yes | Metadata object type. |
timestamp | number | Yes | Yes | Current timestamp, in milliseconds. |
boundingBox | Rect | Yes | Yes | Metadata rectangle. |
FlashMode
Enumerates the flash modes.
System capability: SystemCapability.Multimedia.Camera.Core
Name | Value | Description |
---|---|---|
FLASH_MODE_CLOSE | 0 | The flash is off. |
FLASH_MODE_OPEN | 1 | The flash is on. |
FLASH_MODE_AUTO | 2 | The flash mode is auto, indicating that the flash fires automatically depending on the photo capture conditions. |
FLASH_MODE_ALWAYS_OPEN | 3 | The flash is steady on. |
ExposureMode
Enumerates the exposure modes.
System capability: SystemCapability.Multimedia.Camera.Core
Name | Value | Description |
---|---|---|
EXPOSURE_MODE_LOCKED | 0 | Exposure locked. The metering point cannot be set. |
EXPOSURE_MODE_AUTO | 1 | Auto exposure. The metering point can be set by calling AutoExposure.setMeteringPoint. |
EXPOSURE_MODE_CONTINUOUS_AUTO | 2 | Continuous auto exposure. The metering point cannot be set. |
FocusMode
Enumerates the focus modes.
System capability: SystemCapability.Multimedia.Camera.Core
Name | Value | Description |
---|---|---|
FOCUS_MODE_MANUAL | 0 | Manual focus. The focal length of the camera can be manually set to change the focus position. However, the focal point cannot be set. |
FOCUS_MODE_CONTINUOUS_AUTO | 1 | Continuous auto focus. The focal point cannot be set. |
FOCUS_MODE_AUTO | 2 | Auto focus. The focal point can be set by calling Focus.setFocusPoint, and auto focus is performed once based on the focal point. |
FOCUS_MODE_LOCKED | 3 | Focus locked. The focal point cannot be set. |
FocusState
Enumerates the focus states.
System capability: SystemCapability.Multimedia.Camera.Core
Name | Value | Description |
---|---|---|
FOCUS_STATE_SCAN | 0 | Focusing. |
FOCUS_STATE_FOCUSED | 1 | Focused. |
FOCUS_STATE_UNFOCUSED | 2 | Unfocused. |
VideoStabilizationMode
Enumerates the video stabilization modes.
System capability: SystemCapability.Multimedia.Camera.Core
Name | Value | Description |
---|---|---|
OFF | 0 | Video stabilization is disabled. |
LOW | 1 | The basic video stabilization algorithm is used. |
MIDDLE | 2 | A video stabilization algorithm with a stabilization effect better than that of the LOW type is used. |
HIGH | 3 | A video stabilization algorithm with a stabilization effect better than that of the MIDDLE type is used. |
AUTO | 4 | Automatic video stabilization is used. |
Session11+
Implements a session, which saves all CameraInput and CameraOutput instances required to run the camera and requests the camera to take a photo or record a video.
beginConfig11+
beginConfig(): void
Starts configuration for the session.
System capability: SystemCapability.Multimedia.Camera.Core
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400105 | Session config locked. |
Example
import { BusinessError } from '@ohos.base';
function beginConfig(session: camera.Session): void {
try {
session.beginConfig();
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The beginConfig call failed. error code: ${err.code}`);
}
}
commitConfig11+
commitConfig(callback: AsyncCallback<void>): void
Commits the configuration for this session. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400102 | Operation not allowed. |
7400201 | Camera service fatal error. |
Example
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.');
});
}
commitConfig11+
commitConfig(): Promise<void>
Commits the configuration for this session. This API uses a promise to return the result.
System capability: SystemCapability.Multimedia.Camera.Core
Return value
Type | Description |
---|---|
Promise<void> | Promise used to return the result. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400102 | Operation not allowed. |
7400201 | Camera service fatal error. |
Example
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) => {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The commitConfig call failed. error code: ${err.code}`);
});
}
canAddInput11+
canAddInput(cameraInput: CameraInput): boolean
Determines whether a CameraInput instance can be added to this session. This API must be called after beginConfig and before commitConfig.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
cameraInput | CameraInput | Yes | CameraInput instance to add. |
Return value
Type | Description |
---|---|
boolean | true: The CameraInput instance can be added. false: The CameraInput instance cannot be added. |
Example
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}`);
}
addInput11+
addInput(cameraInput: CameraInput): void
Adds a CameraInput instance to this session.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
cameraInput | CameraInput | Yes | CameraInput instance to add. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400101 | Parameter missing or parameter type incorrect. |
7400102 | Operation not allowed. |
7400103 | Session not config. |
Example
import { BusinessError } from '@ohos.base';
function addInput(session: camera.Session, cameraInput: camera.CameraInput): void {
try {
session.addInput(cameraInput);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The addInput call failed. error code: ${err.code}`);
}
}
removeInput11+
removeInput(cameraInput: CameraInput): void
Removes a CameraInput instance from this session. This API must be called after beginConfig and before commitConfig.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
cameraInput | CameraInput | Yes | CameraInput instance to remove. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400101 | Parameter missing or parameter type incorrect. |
7400102 | Operation not allowed. |
7400103 | Session not config. |
Example
import { BusinessError } from '@ohos.base';
function removeInput(session: camera.Session, cameraInput: camera.CameraInput): void {
try {
session.removeInput(cameraInput);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The removeInput call failed. error code: ${err.code}`);
}
}
canAddOutput11+
canAddOutput(cameraOutput: CameraOutput): boolean
Determines whether a CameraOutput instance can be added to this session. This API must be called after addInput and before commitConfig.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
cameraOutput | CameraOutput | Yes | CameraOutput instance to add. |
Return value
Type | Description |
---|---|
boolean | true: The CameraOutput instance can be added. false: The CameraOutput instance cannot be added. |
Example
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}`);
}
addOutput11+
addOutput(cameraOutput: CameraOutput): void
Adds a CameraOutput instance to this session.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
cameraOutput | CameraOutput | Yes | CameraOutput instance to add. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400101 | Parameter missing or parameter type incorrect. |
7400102 | Operation not allowed. |
7400103 | Session not config. |
Example
import { BusinessError } from '@ohos.base';
function addOutput(session: camera.Session, cameraOutput: camera.CameraOutput): void {
try {
session.addOutput(cameraOutput);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The addOutput call failed. error code: ${err.code}`);
}
}
removeOutput11+
removeOutput(cameraOutput: CameraOutput): void
Removes a CameraOutput instance from this session.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
cameraOutput | CameraOutput | Yes | CameraOutput instance to remove. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400101 | Parameter missing or parameter type incorrect. |
7400102 | Operation not allowed. |
7400103 | Session not config. |
Example
import { BusinessError } from '@ohos.base';
function removeOutput(session: camera.Session, previewOutput: camera.PreviewOutput): void {
try {
session.removeOutput(previewOutput);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The removeOutput call failed. error code: ${err.code}`);
}
}
start11+
start(callback: AsyncCallback<void>): void
Starts this session. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
7400201 | Camera service fatal error. |
Example
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.');
});
}
start11+
start(): Promise<void>
Starts this session. This API uses a promise to return the result.
System capability: SystemCapability.Multimedia.Camera.Core
Return value
Type | Description |
---|---|
Promise<void> | Promise used to return the result. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
7400201 | Camera service fatal error. |
Example
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) => {
let err = error as BusinessError;
console.error(`Failed to start the session, error code: ${err.code}.`);
});
}
stop11+
stop(callback: AsyncCallback<void>): void
Stops this session. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400201 | Camera service fatal error. |
Example
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.');
});
}
stop11+
stop(): Promise<void>
Stops this session. This API uses a promise to return the result.
System capability: SystemCapability.Multimedia.Camera.Core
Return value
Type | Description |
---|---|
Promise<void> | Promise used to return the result. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400201 | Camera service fatal error. |
Example
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) => {
let err = error as BusinessError;
console.error(`Failed to stop the session, error code: ${err.code}.`);
});
}
release11+
release(callback: AsyncCallback<void>): void
Releases this session. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400201 | Camera service fatal error. |
Example
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.');
});
}
release11+
release(): Promise<void>
Releases this session. This API uses a promise to return the result.
System capability: SystemCapability.Multimedia.Camera.Core
Return value
Type | Description |
---|---|
Promise<void> | Promise used to return the result. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400201 | Camera service fatal error. |
Example
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) => {
let err = error as BusinessError;
console.error(`Failed to release the session instance, error code: ${err.code}.`);
});
}
Flash11+
Provides APIs related to the flash.
hasFlash11+
hasFlash(): boolean
Checks whether the camera device has flash. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Multimedia.Camera.Core
Return value
Type | Description |
---|---|
boolean | true: The camera device has flash. false: The camera device does not have flash. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
Example
import { BusinessError } from '@ohos.base';
function hasFlash(photoSession: camera.PhotoSession): boolean {
let status: boolean = false;
try {
status = photoSession.hasFlash();
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The hasFlash call failed. error code: ${err.code}`);
}
return status;
}
isFlashModeSupported11+
isFlashModeSupported(flashMode: FlashMode): boolean
Checks whether a flash mode is supported.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
flashMode | FlashMode | Yes | Flash mode. |
Return value
Type | Description |
---|---|
boolean | true: The flash mode is supported. false: The flash mode is not supported. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
Example
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) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The isFlashModeSupported call failed. error code: ${err.code}`);
}
return status;
}
setFlashMode11+
setFlashMode(flashMode: FlashMode): void
Sets a flash mode.
Before the setting, do the following checks:
- Use hasFlash to check whether the camera device has flash.
- Use isFlashModeSupported to check whether the camera device supports the flash mode.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
flashMode | FlashMode | Yes | Flash mode. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
Example
import { BusinessError } from '@ohos.base';
function setFlashMode(photoSession: camera.PhotoSession): void {
try {
photoSession.setFlashMode(camera.FlashMode.FLASH_MODE_AUTO);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The setFlashMode call failed. error code: ${err.code}`);
}
}
getFlashMode11+
getFlashMode(): FlashMode
Obtains the flash mode in use.
System capability: SystemCapability.Multimedia.Camera.Core
Return value
Type | Description |
---|---|
FlashMode | Flash mode obtained. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
Example
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) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The getFlashMode call failed.error code: ${err.code}`);
}
return flashMode;
}
AutoExposure11+
Provides APIs related to auto exposure.
isExposureModeSupported11+
isExposureModeSupported(aeMode: ExposureMode): boolean
Checks whether an exposure mode is supported.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
aeMode | ExposureMode | Yes | Exposure mode. |
Return value
Type | Description |
---|---|
boolean | true: The exposure mode is supported. false: The exposure mode is not supported. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
Example
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) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The isExposureModeSupported call failed. error code: ${err.code}`);
}
return isSupported;
}
getExposureMode11+
getExposureMode(): ExposureMode
Obtains the exposure mode in use.
System capability: SystemCapability.Multimedia.Camera.Core
Return value
Type | Description |
---|---|
ExposureMode | Exposure mode obtained. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
Example
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) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The getExposureMode call failed. error code: ${err.code}`);
}
return exposureMode;
}
setExposureMode11+
setExposureMode(aeMode: ExposureMode): void
Sets an exposure mode. Before the setting, use isExposureModeSupported to check whether the target exposure mode is supported.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
aeMode | ExposureMode | Yes | Exposure mode. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
Example
import { BusinessError } from '@ohos.base';
function setExposureMode(photoSession: camera.PhotoSession): void {
try {
photoSession.setExposureMode(camera.ExposureMode.EXPOSURE_MODE_LOCKED);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The setExposureMode call failed. error code: ${err.code}`);
}
}
getMeteringPoint11+
getMeteringPoint(): Point
Obtains the metering point of the camera device.
System capability: SystemCapability.Multimedia.Camera.Core
Return value
Type | Description |
---|---|
Point | Metering point obtained. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
Example
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) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The getMeteringPoint call failed. error code: ${err.code}`);
}
return exposurePoint;
}
setMeteringPoint11+
setMeteringPoint(point: Point): void
Sets the metering point, which is the center point of the metering rectangle.
The metering point must be in the coordinate system (0-1), where the upper left corner is {0, 0} and the lower right corner is {1, 1}.
The coordinate system is based on the horizontal device direction with the device's charging port on the right. If the layout of the preview screen of an application is based on the vertical direction with the charging port on the lower side, the layout width and height are {w, h}, and the touch point is {x, y}, then the coordinate point after conversion is {y/h, 1-x/w}.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
point | Point | Yes | Metering point. The value range of x and y must be within [0, 1]. If a value less than 0 is passed, the value 0 is used. If a value greater than 1 is passed, the value 1 is used. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
Example
import { BusinessError } from '@ohos.base';
function setMeteringPoint(photoSession: camera.PhotoSession): void {
const exposurePoint: camera.Point = {x: 1, y: 1};
try {
photoSession.setMeteringPoint(exposurePoint);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The setMeteringPoint call failed. error code: ${err.code}`);
}
}
getExposureBiasRange11+
getExposureBiasRange(): Array<number>
Obtains the exposure compensation values of the camera device.
System capability: SystemCapability.Multimedia.Camera.Core
Return value
Type | Description |
---|---|
Array<number> | Array of compensation values. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
Example
import { BusinessError } from '@ohos.base';
function getExposureBiasRange(photoSession: camera.PhotoSession): Array<number> {
let biasRangeArray: Array<number> = [];
try {
biasRangeArray = photoSession.getExposureBiasRange();
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The getExposureBiasRange call failed. error code: ${err.code}`);
}
return biasRangeArray;
}
setExposureBias11+
setExposureBias(exposureBias: number): void
Sets an exposure compensation value (EV).
Before the setting, you are advised to use getExposureBiasRange to obtain the supported values.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
exposureBias | number | Yes | EV. The supported EV range can be obtained by calling getExposureBiasRange. If the value passed is not within the supported range, the nearest critical point is used. There is a step for EV. For example, if the step is 0.5 and this parameter is set to 1.2, the EV that takes effect is 1.0. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
Example
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) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The setExposureBias call failed. error code: ${err.code}`);
}
}
}
getExposureValue11+
getExposureValue(): number
Obtains the exposure value in use.
System capability: SystemCapability.Multimedia.Camera.Core
Return value
Type | Description |
---|---|
number | Exposure value obtained. There is a step for EV. For example, if the step is 0.5 and this parameter is set to 1.2, the EV that takes effect is 1.0. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
Example
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) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The getExposureValue call failed. error code: ${err.code}`);
}
return exposureValue;
}
Focus11+
Provides APIs related to focus operations.
isFocusModeSupported11+
isFocusModeSupported(afMode: FocusMode): boolean
Checks whether a focus mode is supported.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
afMode | FocusMode | Yes | Focus mode. |
Return value
Type | Description |
---|---|
boolean | true: The focus mode is supported. false: The focus mode is not supported. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
Example
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) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The isFocusModeSupported call failed. error code: ${err.code}`);
}
return status;
}
setFocusMode11+
setFocusMode(afMode: FocusMode): void
Sets a focus mode.
Before the setting, use isFocusModeSupported to check whether the focus mode is supported.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
afMode | FocusMode | Yes | Focus mode. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
Example
import { BusinessError } from '@ohos.base';
function setFocusMode(photoSession: camera.PhotoSession): void {
try {
photoSession.setFocusMode(camera.FocusMode.FOCUS_MODE_AUTO);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The setFocusMode call failed. error code: ${err.code}`);
}
}
getFocusMode11+
getFocusMode(): FocusMode
Obtains the focus mode in use.
System capability: SystemCapability.Multimedia.Camera.Core
Return value
Type | Description |
---|---|
FocusMode | Focus mode obtained. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
Example
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) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The getFocusMode call failed. error code: ${err.code}`);
}
return afMode;
}
setFocusPoint11+
setFocusPoint(point: Point): void
Sets the focal point. The focal point must be in the coordinate system (0-1), where the upper left corner is {0, 0} and the lower right corner is {1, 1}.
The coordinate system is based on the horizontal device direction with the device's charging port on the right. If the layout of the preview screen of an application is based on the vertical direction with the charging port on the lower side, the layout width and height are {w, h}, and the touch point is {x, y}, then the coordinate point after conversion is {y/h, 1-x/w}.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
point | Point | Yes | Focal point. The value range of x and y must be within [0, 1]. If a value less than 0 is passed, the value 0 is used. If a value greater than 1 is passed, the value 1 is used. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
Example
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) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The setFocusPoint call failed. error code: ${err.code}`);
}
}
getFocusPoint11+
getFocusPoint(): Point
Obtains the focal point of the camera device.
System capability: SystemCapability.Multimedia.Camera.Core
Return value
Type | Description |
---|---|
Point | Focal point obtained. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
Example
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) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The getFocusPoint call failed. error code: ${err.code}`);
}
return point;
}
getFocalLength11+
getFocalLength(): number
Obtains the focal length of the camera device.
System capability: SystemCapability.Multimedia.Camera.Core
Return value
Type | Description |
---|---|
number | Focal length, in mm. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
Example
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) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The getFocalLength call failed. error code: ${err.code}`);
}
return focalLength;
}
SmoothZoomMode11+
Enumerates the smooth zoom modes.
System capability: SystemCapability.Multimedia.Camera.Core
Name | Value | Description |
---|---|---|
NORMAL | 0 | Bessel curve mode. |
SmoothZoomInfo11+
Defines the smooth zoom information.
System capability: SystemCapability.Multimedia.Camera.Core
Name | Type | Read-only | Mandatory | Description |
---|---|---|---|---|
duration | number | No | Yes | Total duration of smooth zoom, in ms. |
Zoom11+
Provides APIs related to zoom operations.
getZoomRatioRange11+
getZoomRatioRange(): Array<number>
Obtains the supported zoom ratio range.
System capability: SystemCapability.Multimedia.Camera.Core
Return value
Type | Description |
---|---|
Array<number> | Callback used to return an array containing the minimum and maximum zoom ratios. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
Example
import { BusinessError } from '@ohos.base';
function getZoomRatioRange(photoSession: camera.PhotoSession): Array<number> {
let zoomRatioRange: Array<number> = [];
try {
zoomRatioRange = photoSession.getZoomRatioRange();
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The getZoomRatioRange call failed. error code: ${err.code}`);
}
return zoomRatioRange;
}
setZoomRatio11+
setZoomRatio(zoomRatio: number): void
Sets a zoom ratio, with a maximum precision of two decimal places.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
zoomRatio | number | Yes | Zoom ratio. The supported zoom ratio range can be obtained by calling getZoomRatioRange. If the value passed in is not within the supported range, the value within the precision range is retained. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
Example
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) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The setZoomRatio call failed. error code: ${err.code}`);
}
}
getZoomRatio11+
getZoomRatio(): number
Obtains the zoom ratio in use.
System capability: SystemCapability.Multimedia.Camera.Core
Return value
Type | Description |
---|---|
number | Zoom ratio obtained. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
Example
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) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The getZoomRatio call failed. error code: ${err.code}`);
}
return zoomRatio;
}
setSmoothZoom11+
setSmoothZoom(targetRatio: number, mode?: SmoothZoomMode): void
Sets smooth zoom.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
targetRatio | number | Yes | Target zoom ratio. |
mode | SmoothZoomMode | No | Smooth zoom mode. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
Example
import { BusinessError } from '@ohos.base';
function setSmoothZoom(sessionExtendsZoom: camera.Zoom, targetZoomRatio: number, mode: camera.SmoothZoomMode): void {
try {
sessionExtendsZoom.setSmoothZoom(targetZoomRatio, mode);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The setSmoothZoom call failed. error code: ${err.code}`);
}
}
Stabilization11+
Provides APIs for stabilization-related operations.
isVideoStabilizationModeSupported11+
isVideoStabilizationModeSupported(vsMode: VideoStabilizationMode): boolean
Checks whether a video stabilization mode is supported.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
vsMode | VideoStabilizationMode | Yes | Video stabilization mode. |
Return value
Type | Description |
---|---|
boolean | true: The video stabilization mode is supported. false: The video stabilization mode is not supported. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
Example
import { BusinessError } from '@ohos.base';
function isVideoStabilizationModeSupported(videoSession: camera.VideoSession): boolean {
let isSupported: boolean = false;
try {
isSupported = videoSession.isVideoStabilizationModeSupported(camera.VideoStabilizationMode.OFF);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The isVideoStabilizationModeSupported call failed. error code: ${err.code}`);
}
return isSupported;
}
getActiveVideoStabilizationMode11+
getActiveVideoStabilizationMode(): VideoStabilizationMode
Obtains the video stabilization mode in use.
System capability: SystemCapability.Multimedia.Camera.Core
Return value
Type | Description |
---|---|
VideoStabilizationMode | Video stabilization mode obtained. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
Example
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) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The getActiveVideoStabilizationMode call failed. error code: ${err.code}`);
}
return vsMode;
}
setVideoStabilizationMode11+
setVideoStabilizationMode(mode: VideoStabilizationMode): void
Sets a video stabilization mode. Before the setting, use isVideoStabilizationModeSupported to check whether the target video stabilization mode is supported.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
mode | VideoStabilizationMode | Yes | Video stabilization mode. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
Example
import { BusinessError } from '@ohos.base';
function setVideoStabilizationMode(videoSession: camera.VideoSession): void {
try {
videoSession.setVideoStabilizationMode(camera.VideoStabilizationMode.OFF);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The setVideoStabilizationMode call failed. error code: ${err.code}`);
}
}
CaptureSession(deprecated)
Implements a capture session, which saves all CameraInput and CameraOutput instances required to run the camera and requests the camera to complete shooting or video recording.
NOTE
This API is supported since API version 10 and deprecated since API version 11. You are advised to use PhotoSession and VideoSession instead.
beginConfig(deprecated)
beginConfig(): void
Starts configuration for the session.
NOTE
This API is supported since API version 10 and deprecated since API version 11. You are advised to use Session.beginConfig instead.
System capability: SystemCapability.Multimedia.Camera.Core
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400105 | Session config locked. |
Example
import { BusinessError } from '@ohos.base';
function beginConfig(captureSession: camera.CaptureSession): void {
try {
captureSession.beginConfig();
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The beginConfig call failed. error code: ${err.code}`);
}
}
commitConfig(deprecated)
commitConfig(callback: AsyncCallback<void>): void
Commits the configuration for this session. This API uses an asynchronous callback to return the result.
NOTE
This API is supported since API version 10 and deprecated since API version 11. You are advised to use Session.commitConfig instead.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400102 | Operation not allowed. |
7400201 | Camera service fatal error. |
Example
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(deprecated)
commitConfig(): Promise<void>
Commits the configuration for this session. This API uses a promise to return the result.
NOTE
This API is supported since API version 10 and deprecated since API version 11. You are advised to use Session.commitConfig instead.
System capability: SystemCapability.Multimedia.Camera.Core
Return value
Type | Description |
---|---|
Promise<void> | Promise used to return the result. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400102 | Operation not allowed. |
7400201 | Camera service fatal error. |
Example
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) => {
// If the operation fails, error.code is returned and processed.
console.error(`The commitConfig call failed. error code: ${err.code}`);
});
}
addInput(deprecated)
addInput(cameraInput: CameraInput): void
Adds a CameraInput instance to this session.
NOTE
This API is supported since API version 10 and deprecated since API version 11. You are advised to use Session.addInput instead.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
cameraInput | CameraInput | Yes | CameraInput instance to add. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400101 | Parameter missing or parameter type incorrect. |
7400102 | Operation not allowed. |
Example
import { BusinessError } from '@ohos.base';
function addInput(captureSession: camera.CaptureSession, cameraInput: camera.CameraInput): void {
try {
captureSession.addInput(cameraInput);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The addInput call failed. error code: ${err.code}`);
}
}
removeInput(deprecated)
removeInput(cameraInput: CameraInput): void
Removes a CameraInput instance from this session.
NOTE
This API is supported since API version 10 and deprecated since API version 11. You are advised to use Session.removeInput instead.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
cameraInput | CameraInput | Yes | CameraInput instance to remove. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400101 | Parameter missing or parameter type incorrect. |
7400102 | Operation not allowed. |
Example
import { BusinessError } from '@ohos.base';
function removeInput(captureSession: camera.CaptureSession, cameraInput: camera.CameraInput): void {
try {
captureSession.removeInput(cameraInput);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The removeInput call failed. error code: ${err.code}`);
}
}
addOutput(deprecated)
addOutput(cameraOutput: CameraOutput): void
Adds a CameraOutput instance to this session.
NOTE
This API is supported since API version 10 and deprecated since API version 11. You are advised to use Session.addOutput instead.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
cameraOutput | CameraOutput | Yes | CameraOutput instance to add. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400101 | Parameter missing or parameter type incorrect. |
7400102 | Operation not allowed. |
Example
import { BusinessError } from '@ohos.base';
function addOutput(captureSession: camera.CaptureSession, cameraOutput: camera.CameraOutput): void {
try {
captureSession.addOutput(cameraOutput);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The addOutput call failed. error code: ${err.code}`);
}
}
removeOutput(deprecated)
removeOutput(cameraOutput: CameraOutput): void
Removes a CameraOutput instance from this session.
NOTE
This API is supported since API version 10 and deprecated since API version 11. You are advised to use Session.removeOutput instead.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
cameraOutput | CameraOutput | Yes | CameraOutput instance to remove. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400101 | Parameter missing or parameter type incorrect. |
7400102 | Operation not allowed. |
Example
import { BusinessError } from '@ohos.base';
function removeOutput(captureSession: camera.CaptureSession, previewOutput: camera.PreviewOutput): void {
try {
captureSession.removeOutput(previewOutput);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The removeOutput call failed. error code: ${err.code}`);
}
}
start(deprecated)
start(callback: AsyncCallback<void>): void
Starts this session. This API uses an asynchronous callback to return the result.
NOTE
This API is supported since API version 10 and deprecated since API version 11. You are advised to use Session.start instead.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
7400201 | Camera service fatal error. |
Example
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(deprecated)
start(): Promise<void>
Starts this session. This API uses a promise to return the result.
NOTE
This API is supported since API version 10 and deprecated since API version 11. You are advised to use Session.start instead.
System capability: SystemCapability.Multimedia.Camera.Core
Return value
Type | Description |
---|---|
Promise<void> | Promise used to return the result. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
7400201 | Camera service fatal error. |
Example
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(deprecated)
stop(callback: AsyncCallback<void>): void
Stops this session. This API uses an asynchronous callback to return the result.
NOTE
This API is supported since API version 10 and deprecated since API version 11. You are advised to use Session.stop instead.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400201 | Camera service fatal error. |
Example
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(deprecated)
stop(): Promise<void>
Stops this session. This API uses a promise to return the result.
NOTE
This API is supported since API version 10 and deprecated since API version 11. You are advised to use Session.stop instead.
System capability: SystemCapability.Multimedia.Camera.Core
Return value
Type | Description |
---|---|
Promise<void> | Promise used to return the result. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400201 | Camera service fatal error. |
Example
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(deprecated)
release(callback: AsyncCallback<void>): void
Releases this session. This API uses an asynchronous callback to return the result.
NOTE
This API is supported since API version 10 and deprecated since API version 11. You are advised to use Session.release instead.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400201 | Camera service fatal error. |
Example
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(deprecated)
release(): Promise<void>
Releases this session. This API uses a promise to return the result.
NOTE
This API is supported since API version 10 and deprecated since API version 11. You are advised to use Session.release instead.
System capability: SystemCapability.Multimedia.Camera.Core
Return value
Type | Description |
---|---|
Promise<void> | Promise used to return the result. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400201 | Camera service fatal error. |
Example
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(deprecated)
hasFlash(): boolean
Checks whether the camera device has flash.
NOTE
This API is supported since API version 10 and deprecated since API version 11. You are advised to use Flash.hasFlash instead.
System capability: SystemCapability.Multimedia.Camera.Core
Return value
Type | Description |
---|---|
boolean | true: The camera device has flash. false: The camera device does not have flash. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
Example
import { BusinessError } from '@ohos.base';
function hasFlash(captureSession: camera.CaptureSession): boolean {
let status: boolean = false;
try {
status = captureSession.hasFlash();
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The hasFlash call failed. error code: ${err.code}`);
}
return status;
}
isFlashModeSupported(deprecated)
isFlashModeSupported(flashMode: FlashMode): boolean
Checks whether a flash mode is supported.
NOTE
This API is supported since API version 10 and deprecated since API version 11. You are advised to use Flash.isFlashModeSupported instead.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
flashMode | FlashMode | Yes | Flash mode. |
Return value
Type | Description |
---|---|
boolean | true: The flash mode is supported. false: The flash mode is not supported. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
Example
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) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The isFlashModeSupported call failed. error code: ${err.code}`);
}
return status;
}
setFlashMode(deprecated)
setFlashMode(flashMode: FlashMode): void
Sets a flash mode.
Before the setting, do the following checks:
- Use hasFlash to check whether the camera device has flash.
- Use isFlashModeSupported to check whether the camera device supports the flash mode.
NOTE
This API is supported since API version 10 and deprecated since API version 11. You are advised to use Flash.setFlashMode instead.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
flashMode | FlashMode | Yes | Flash mode. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
Example
import { BusinessError } from '@ohos.base';
function setFlashMode(captureSession: camera.CaptureSession): void {
try {
captureSession.setFlashMode(camera.FlashMode.FLASH_MODE_AUTO);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The setFlashMode call failed. error code: ${err.code}`);
}
}
getFlashMode(deprecated)
getFlashMode(): FlashMode
Obtains the flash mode in use.
NOTE
This API is supported since API version 10 and deprecated since API version 11. You are advised to use Flash.getFlashMode instead.
System capability: SystemCapability.Multimedia.Camera.Core
Return value
Type | Description |
---|---|
FlashMode | Flash mode obtained. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
Example
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) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The getFlashMode call failed.error code: ${err.code}`);
}
return flashMode;
}
isExposureModeSupported(deprecated)
isExposureModeSupported(aeMode: ExposureMode): boolean;
Checks whether an exposure mode is supported.
NOTE
This API is supported since API version 10 and deprecated since API version 11. You are advised to use AutoExposure.isExposureModeSupported instead.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
aeMode | ExposureMode | Yes | Exposure mode. |
Return value
Type | Description |
---|---|
boolean | true: The exposure mode is supported. false: The exposure mode is not supported. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
Example
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) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The isExposureModeSupported call failed. error code: ${err.code}`);
}
return isSupported;
}
getExposureMode(deprecated)
getExposureMode(): ExposureMode
Obtains the exposure mode in use.
NOTE
This API is supported since API version 10 and deprecated since API version 11. You are advised to use AutoExposure.getExposureMode instead.
System capability: SystemCapability.Multimedia.Camera.Core
Return value
Type | Description |
---|---|
ExposureMode | Exposure mode obtained. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
Example
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) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The getExposureMode call failed. error code: ${err.code}`);
}
return exposureMode;
}
setExposureMode(deprecated)
setExposureMode(aeMode: ExposureMode): void
Sets an exposure mode. Before the setting, use isExposureModeSupported to check whether the target exposure mode is supported.
NOTE
This API is supported since API version 10 and deprecated since API version 11. You are advised to use AutoExposure.setExposureMode instead.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
aeMode | ExposureMode | Yes | Exposure mode. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
Example
import { BusinessError } from '@ohos.base';
function setExposureMode(captureSession: camera.CaptureSession): void {
try {
captureSession.setExposureMode(camera.ExposureMode.EXPOSURE_MODE_LOCKED);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The setExposureMode call failed. error code: ${err.code}`);
}
}
getMeteringPoint(deprecated)
getMeteringPoint(): Point
Obtains the metering point of the camera device.
NOTE
This API is supported since API version 10 and deprecated since API version 11. You are advised to use AutoExposure.getMeteringPoint instead.
System capability: SystemCapability.Multimedia.Camera.Core
Return value
Type | Description |
---|---|
Point | Metering point obtained. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
Example
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) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The getMeteringPoint call failed. error code: ${err.code}`);
}
return exposurePoint;
}
setMeteringPoint(deprecated)
setMeteringPoint(point: Point): void
Sets the metering point, which is the center point of the metering rectangle.
The metering point must be in the coordinate system (0-1), where the upper left corner is {0, 0} and the lower right corner is {1, 1}.
The coordinate system is based on the horizontal device direction with the device's charging port on the right. If the layout of the preview screen of an application is based on the vertical direction with the charging port on the lower side, the layout width and height are {w, h}, and the touch point is {x, y}, then the coordinate point after conversion is {y/h, 1-x/w}.
NOTE
This API is supported since API version 10 and deprecated since API version 11. You are advised to use AutoExposure.setMeteringPoint instead.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
exposurePoint | Point | Yes | Metering point. The value range of x and y must be within [0,1]. If a value less than 0 is passed, the value 0 is used. If a value greater than 1 is passed, the value 1 is used. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
Example
import { BusinessError } from '@ohos.base';
function setMeteringPoint(captureSession: camera.CaptureSession): void {
const exposurePoint: camera.Point = {x: 1, y: 1};
try {
captureSession.setMeteringPoint(exposurePoint);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The setMeteringPoint call failed. error code: ${err.code}`);
}
}
getExposureBiasRange(deprecated)
getExposureBiasRange(): Array<number>
Obtains the exposure compensation values of the camera device.
NOTE
This API is supported since API version 10 and deprecated since API version 11. You are advised to use AutoExposure.getExposureBiasRange instead.
System capability: SystemCapability.Multimedia.Camera.Core
Return value
Type | Description |
---|---|
Array<number> | Array of compensation values. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
Example
import { BusinessError } from '@ohos.base';
function getExposureBiasRange(captureSession: camera.CaptureSession): Array<number> {
let biasRangeArray: Array<number> = [];
try {
biasRangeArray = captureSession.getExposureBiasRange();
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The getExposureBiasRange call failed. error code: ${err.code}`);
}
return biasRangeArray;
}
setExposureBias(deprecated)
setExposureBias(exposureBias: number): void
Sets an exposure compensation value (EV).
Before the setting, you are advised to use getExposureBiasRange to obtain the supported values.
NOTE
This API is supported since API version 10 and deprecated since API version 11. You are advised to use AutoExposure.setExposureBias instead.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
exposureBias | number | Yes | EV. The supported EV range can be obtained by calling getExposureBiasRange. If the value passed is not within the supported range, the nearest critical point is used. There is a step for EV. For example, if the step is 0.5 and this parameter is set to 1.2, the EV that takes effect is 1.0. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
Example
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) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The setExposureBias call failed. error code: ${err.code}`);
}
}
}
getExposureValue(deprecated)
getExposureValue(): number
Obtains the exposure value in use.
NOTE
This API is supported since API version 10 and deprecated since API version 11. You are advised to use AutoExposure.getExposureValue instead.
System capability: SystemCapability.Multimedia.Camera.Core
Return value
Type | Description |
---|---|
number | Exposure value obtained. There is a step for EV. For example, if the step is 0.5 and this parameter is set to 1.2, the EV that takes effect is 1.0. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
Example
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) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The getExposureValue call failed. error code: ${err.code}`);
}
return exposureValue;
}
isFocusModeSupported(deprecated)
isFocusModeSupported(afMode: FocusMode): boolean
Checks whether a focus mode is supported.
NOTE
This API is supported since API version 10 and deprecated since API version 11. You are advised to use Focus.isFocusModeSupported instead.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
afMode | FocusMode | Yes | Focus mode. |
Return value
Type | Description |
---|---|
boolean | true: The focus mode is supported. false: The focus mode is not supported. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
Example
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) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The isFocusModeSupported call failed. error code: ${err.code}`);
}
return status;
}
setFocusMode(deprecated)
setFocusMode(afMode: FocusMode): void
Sets a focus mode.
Before the setting, use isFocusModeSupported to check whether the focus mode is supported.
NOTE
This API is supported since API version 10 and deprecated since API version 11. You are advised to use Focus.setFocusMode instead.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
afMode | FocusMode | Yes | Focus mode. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
Example
import { BusinessError } from '@ohos.base';
function setFocusMode(captureSession: camera.CaptureSession): void {
try {
captureSession.setFocusMode(camera.FocusMode.FOCUS_MODE_AUTO);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The setFocusMode call failed. error code: ${err.code}`);
}
}
getFocusMode(deprecated)
getFocusMode(): FocusMode
Obtains the focus mode in use.
NOTE
This API is supported since API version 10 and deprecated since API version 11. You are advised to use Focus.getFocusMode instead.
System capability: SystemCapability.Multimedia.Camera.Core
Return value
Type | Description |
---|---|
FocusMode | Focus mode obtained. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
Example
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) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The getFocusMode call failed. error code: ${err.code}`);
}
return afMode;
}
setFocusPoint(deprecated)
setFocusPoint(point: Point): void
Sets the focal point. The focal point must be in the coordinate system (0-1), where the upper left corner is {0, 0} and the lower right corner is {1, 1}.
The coordinate system is based on the horizontal device direction with the device's charging port on the right. If the layout of the preview screen of an application is based on the vertical direction with the charging port on the lower side, the layout width and height are {w, h}, and the touch point is {x, y}, then the coordinate point after conversion is {y/h, 1-x/w}.
NOTE
This API is supported since API version 10 and deprecated since API version 11. You are advised to use Focus.setFocusPoint instead.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
Point | Point | Yes | Focal point. The value range of x and y must be within [0,1]. If a value less than 0 is passed, the value 0 is used. If a value greater than 1 is passed, the value 1 is used. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
Example
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) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The setFocusPoint call failed. error code: ${err.code}`);
}
}
getFocusPoint(deprecated)
getFocusPoint(): Point
Obtains the focal point of the camera device.
NOTE
This API is supported since API version 10 and deprecated since API version 11. You are advised to use Focus.getFocusPoint instead.
System capability: SystemCapability.Multimedia.Camera.Core
Return value
Type | Description |
---|---|
Point | Focal point obtained. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
Example
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) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The getFocusPoint call failed. error code: ${err.code}`);
}
return point;
}
getFocalLength(deprecated)
getFocalLength(): number
Obtains the focal length of the camera device.
NOTE
This API is supported since API version 10 and deprecated since API version 11. You are advised to use Focus.getFocalLength instead.
System capability: SystemCapability.Multimedia.Camera.Core
Return value
Type | Description |
---|---|
number | Focal length obtained. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
Example
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) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The getFocalLength call failed. error code: ${err.code}`);
}
return focalLength;
}
getZoomRatioRange(deprecated)
getZoomRatioRange(): Array<number>
Obtains the supported zoom ratio range.
NOTE
This API is supported since API version 10 and deprecated since API version 11. You are advised to use Zoom.getZoomRatioRange instead.
System capability: SystemCapability.Multimedia.Camera.Core
Return value
Type | Description |
---|---|
Array<number> | Callback used to return an array containing the minimum and maximum zoom ratios. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
Example
import { BusinessError } from '@ohos.base';
function getZoomRatioRange(captureSession: camera.CaptureSession): Array<number> {
let zoomRatioRange: Array<number> = [];
try {
zoomRatioRange = captureSession.getZoomRatioRange();
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The getZoomRatioRange call failed. error code: ${err.code}`);
}
return zoomRatioRange;
}
setZoomRatio(deprecated)
setZoomRatio(zoomRatio: number): void
Sets a zoom ratio, with a maximum precision of two decimal places.
NOTE
This API is supported since API version 10 and deprecated since API version 11. You are advised to use Zoom.setZoomRatio instead.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
zoomRatio | number | Yes | Zoom ratio. The supported zoom ratio range can be obtained by calling getZoomRatioRange. If the value passed in is not within the supported range, the value within the precision range is retained. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
Example
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) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The setZoomRatio call failed. error code: ${err.code}`);
}
}
getZoomRatio(deprecated)
getZoomRatio(): number
Obtains the zoom ratio in use.
NOTE
This API is supported since API version 10 and deprecated since API version 11. You are advised to use Zoom.getZoomRatio instead.
System capability: SystemCapability.Multimedia.Camera.Core
Return value
Type | Description |
---|---|
number | Zoom ratio obtained. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
Example
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) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The getZoomRatio call failed. error code: ${err.code}`);
}
return zoomRatio;
}
isVideoStabilizationModeSupported(deprecated)
isVideoStabilizationModeSupported(vsMode: VideoStabilizationMode): boolean
Checks whether a video stabilization mode is supported.
NOTE
This API is supported since API version 10 and deprecated since API version 11. You are advised to use Stabilization.isVideoStabilizationModeSupported instead.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
vsMode | VideoStabilizationMode | Yes | Video stabilization mode. |
Return value
Type | Description |
---|---|
boolean | true: The video stabilization mode is supported. false: The video stabilization mode is not supported. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
Example
import { BusinessError } from '@ohos.base';
function isVideoStabilizationModeSupported(captureSession: camera.CaptureSession): boolean {
let isSupported: boolean = false;
try {
isSupported = captureSession.isVideoStabilizationModeSupported(camera.VideoStabilizationMode.OFF);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The isVideoStabilizationModeSupported call failed. error code: ${err.code}`);
}
return isSupported;
}
getActiveVideoStabilizationMode(deprecated)
getActiveVideoStabilizationMode(): VideoStabilizationMode
Obtains the video stabilization mode in use.
NOTE
This API is supported since API version 10 and deprecated since API version 11. You are advised to use Stabilization.getActiveVideoStabilizationMode instead.
System capability: SystemCapability.Multimedia.Camera.Core
Return value
Type | Description |
---|---|
VideoStabilizationMode | Video stabilization mode obtained. If the operation fails, an error code defined in CameraErrorCode is returned. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
Example
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) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The getActiveVideoStabilizationMode call failed. error code: ${err.code}`);
}
return vsMode;
}
setVideoStabilizationMode(deprecated)
setVideoStabilizationMode(mode: VideoStabilizationMode): void
Sets a video stabilization mode. Before the setting, use isVideoStabilizationModeSupported to check whether the target video stabilization mode is supported.
NOTE
This API is supported since API version 10 and deprecated since API version 11. You are advised to use Stabilization.setVideoStabilizationMode instead.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
mode | VideoStabilizationMode | Yes | Video stabilization mode. |
Error codes
For details about the error codes, see Camera Error Codes.
ID | Error Message |
---|---|
7400103 | Session not config. |
Example
import { BusinessError } from '@ohos.base';
function setVideoStabilizationMode(captureSession: camera.CaptureSession): void {
try {
captureSession.setVideoStabilizationMode(camera.VideoStabilizationMode.OFF);
} catch (error) {
// If the operation fails, error.code is returned and processed.
let err = error as BusinessError;
console.error(`The setVideoStabilizationMode call failed. error code: ${err.code}`);
}
}
on('focusStateChange')(deprecated)
on(type: 'focusStateChange', callback: AsyncCallback<FocusState>): void
Subscribes to focus state change events. This API uses an asynchronous callback to return the result.
NOTE
This API is supported since API version 10 and deprecated since API version 11. You are advised to use VideoSession.on('focusStateChange') instead.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type. The value is fixed at 'focusStateChange'. The event can be listened for when a session is created. This event is triggered only when the camera focus state changes in auto focus mode. |
callback | AsyncCallback<FocusState> | Yes | Callback used to return the focus state change. |
Example
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('focusStateChange')(deprecated)
off(type: 'focusStateChange', callback?: AsyncCallback<FocusState>): void
Unsubscribes from focus state change events.
NOTE
This API is supported since API version 10 and deprecated since API version 11. You are advised to use VideoSession.off('focusStateChange') instead.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type. The value is fixed at 'focusStateChange'. The event can be listened for when a session is created. |
callback | AsyncCallback<FocusState> | No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('focusStateChange') with the specified callback is canceled. (The callback object cannot be an anonymous function.) |
Example
function unregisterFocusStateChange(captureSession: camera.CaptureSession): void {
captureSession.off('focusStateChange');
}
on('error')(deprecated)
on(type: 'error', callback: ErrorCallback): void
Subscribes to CaptureSession error events. This API uses a callback to return the result.
NOTE
This API is supported since API version 10 and deprecated since API version 11. You are advised to use VideoSession.on('error') instead.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type. The value is fixed at 'error'. The event can be listened for when a session is created. This event is triggered and the error message is returned when an error occurs during the calling of a session-related API such as beginConfig, commitConfig, and addInput. |
callback | ErrorCallback | Yes | Callback used to return an error code defined in CameraErrorCode. |
Example
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('error')(deprecated)
off(type: 'error', callback?: ErrorCallback): void
Unsubscribes from CaptureSession error events. This API uses a callback to return the result.
NOTE
This API is supported since API version 10 and deprecated since API version 11. You are advised to use VideoSession.off('error') instead.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type. The value is fixed at 'error'. The event can be listened for when a session is created. |
callback | ErrorCallback | No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('error') with the specified callback is canceled. (The callback object cannot be an anonymous function.) |
Example
function unregisterCaptureSessionError(captureSession: camera.CaptureSession): void {
captureSession.off('error');
}
PhotoSession11+
PhotoSession extends Session, Flash, AutoExposure, Focus, Zoom
Implements a photo session, which sets the parameters of the normal photo mode and saves all CameraInput and CameraOutput instances required to run the camera. It inherits from Session.
on('error')11+
on(type: 'error', callback: ErrorCallback): void
Subscribes to PhotoSession error events. This API uses a callback to return the result.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type. The value is fixed at 'error'. The event can be listened for when a session is created. This event is triggered and the error message is returned when an error occurs during the calling of a session-related API such as beginConfig, commitConfig, and addInput. |
callback | ErrorCallback | Yes | Callback used to return an error code defined in CameraErrorCode. |
Example
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', (error: BusinessError) => {
console.error(`Photo session error code: ${error.code}`);
});
}
off('error')11+
off(type: 'error', callback?: ErrorCallback): void
Unsubscribes from PhotoSession error events. This API uses a callback to return the result.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type. The value is fixed at 'error'. The event can be listened for when a session is created. |
callback | ErrorCallback | No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('error') with the specified callback is canceled. (The callback object cannot be an anonymous function.) |
Example
function unregisterSessionError(photoSession: camera.PhotoSession): void {
photoSession.off('error');
}
on('focusStateChange')11+
on(type: 'focusStateChange', callback: AsyncCallback<FocusState>): void
Subscribes to focus state change events. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type. The value is fixed at 'focusStateChange'. The event can be listened for when a session is created. This event is triggered only when the camera focus state changes in auto focus mode. |
callback | AsyncCallback<FocusState> | Yes | Callback used to return the focus state change. |
Example
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('focusStateChange')11+
off(type: 'focusStateChange', callback?: AsyncCallback<FocusState>): void
Unsubscribes from focus state change events.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type. The value is fixed at 'focusStateChange'. The event can be listened for when a session is created. |
callback | AsyncCallback<FocusState> | No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('focusStateChange') with the specified callback is canceled. (The callback object cannot be an anonymous function.) |
Example
function unregisterFocusStateChange(photoSession: camera.PhotoSession): void {
photoSession.off('focusStateChange');
}
on('smoothZoomInfoAvailable')11+
on(type: 'smoothZoomInfoAvailable', callback: AsyncCallback<SmoothZoomInfo>): void
Subscribes to smooth zoom state change events. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type. The value is fixed at 'smoothZoomInfoAvailable'. The event can be listened for when a session is created. |
callback | AsyncCallback<SmoothZoomInfo> | Yes | Callback used to return the smooth zoom state change. |
Example
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('smoothZoomInfoAvailable')11+
off(type: 'smoothZoomInfoAvailable', callback?: AsyncCallback<SmoothZoomInfo>): void
Unsubscribes from smooth zoom state change events.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type. The value is fixed at 'smoothZoomInfoAvailable'. The event can be listened for when a session is created. |
callback | AsyncCallback<SmoothZoomInfo> | No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('smoothZoomInfoAvailable') with the specified callback is canceled. (The callback object cannot be an anonymous function.) |
Example
function unregisterSmoothZoomInfo(photoSession: camera.PhotoSession): void {
photoSession.off('smoothZoomInfoAvailable');
}
VideoSession11+
VideoSession extends Session, Flash, AutoExposure, Focus, Zoom, Stabilization
Implements a video session, which sets the parameters of the normal video mode and saves all CameraInput and CameraOutput instances required to run the camera. It inherits from Session.
on('error')11+
on(type: 'error', callback: ErrorCallback): void
Subscribes to VideoSession error events. This API uses a callback to return the result.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type. The value is fixed at 'error'. The event can be listened for when a session is created. This event is triggered and the error message is returned when an error occurs during the calling of a session-related API such as beginConfig, commitConfig, and addInput. |
callback | ErrorCallback | Yes | Callback used to return an error code defined in CameraErrorCode. |
Example
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('error')11+
off(type: 'error', callback?: ErrorCallback): void
Unsubscribes from VideoSession error events. This API uses a callback to return the result.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type. The value is fixed at 'error'. The event can be listened for when a session is created. |
callback | ErrorCallback | No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('error') with the specified callback is canceled. (The callback object cannot be an anonymous function.) |
Example
function unregisterSessionError(videoSession: camera.VideoSession): void {
videoSession.off('error');
}
on('focusStateChange')11+
on(type: 'focusStateChange', callback: AsyncCallback<FocusState>): void
Subscribes to focus state change events. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type. The value is fixed at 'focusStateChange'. The event can be listened for when a session is created. This event is triggered only when the camera focus state changes in auto focus mode. |
callback | AsyncCallback<FocusState> | Yes | Callback used to return the focus state change. |
Example
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('focusStateChange')11+
off(type: 'focusStateChange', callback?: AsyncCallback<FocusState>): void
Unsubscribes from focus state change events.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type. The value is fixed at 'focusStateChange'. The event can be listened for when a session is created. |
callback | AsyncCallback<FocusState> | No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('focusStateChange') with the specified callback is canceled. (The callback object cannot be an anonymous function.) |
Example
function unregisterFocusStateChange(videoSession: camera.VideoSession): void {
videoSession.off('focusStateChange');
}
on('smoothZoomInfoAvailable')11+
on(type: 'smoothZoomInfoAvailable', callback: AsyncCallback<SmoothZoomInfo>): void
Subscribes to smooth zoom state change events. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type. The value is fixed at 'smoothZoomInfoAvailable'. The event can be listened for when a session is created. |
callback | AsyncCallback<SmoothZoomInfo> | Yes | Callback used to return the smooth zoom state change. |
Example
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('smoothZoomInfoAvailable')11+
off(type: 'smoothZoomInfoAvailable', callback?: AsyncCallback<SmoothZoomInfo>): void
Unsubscribes from smooth zoom state change events.
System capability: SystemCapability.Multimedia.Camera.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type. The value is fixed at 'smoothZoomInfoAvailable'. The event can be listened for when a session is created. |
callback | AsyncCallback<SmoothZoomInfo> | No | Callback used to return the result. This parameter is optional. If this parameter is specified, the subscription to the specified event on('smoothZoomInfoAvailable') with the specified callback is canceled. (The callback object cannot be an anonymous function.) |
Example
function unregisterSmoothZoomInfo(videoSession: camera.VideoSession): void {
videoSession.off('smoothZoomInfoAvailable');
}