Camera

Defined under the namespace Scandit.Datacapture.Core

TorchState

Added in version 6.13.0

Possible values for the torch state.

On

Added in version 6.13.0

Value to indicate that the torch is turned on.

Off

Added in version 6.13.0

Value to indicate that the torch is turned off.

VideoFrameResolution
interface VideoFrameResolution

Added in version 6.13.0

Resolution of a video frame.

width
readonly width: number

Added in version 6.13.0

Width in pixels.

height
readonly height: number

Added in version 6.13.0

Height in pixels.

Camera
class Camera : FrameSource

Added in version 6.13.0

Gives access to the built-in camera on Web. It implements the FrameSource interface, and, as such can be set as the frame source for the DataCaptureContext.

Instances of this class are created through one of the factory methods default(), or atPosition().

The camera is started by changing the desired state to FrameSourceState.On.

By default, the resolution of captured frames as well as auto-focus and exposure settings are chosen such that they work best for a variety of use cases. To fine-tune recognition, the camera settings can be changed through applying new camera settings.

desiredState
get desiredState(): FrameSourceState

Added in version 6.13.0

Implemented from FrameSource. See FrameSource.desiredState.

getCurrentState()
getCurrentState(): FrameSourceState

Added in version 6.13.0

Implemented from FrameSource. See FrameSource.getCurrentState.

position
readonly position: CameraPosition

Added in version 6.13.0

The direction that the camera faces.

currentResolution
get currentResolution(): VideoFrameResolution | null

Added in version 6.13.0

The current video frame resolution of the camera.

addListener(listener)
addListener(listener: FrameSourceListener | null): void

Added in version 6.13.0

Implemented from FrameSource. See FrameSource.addListener().

removeListener(listener)
removeListener(listener: FrameSourceListener | null): void

Added in version 6.13.0

Implemented from FrameSource. See FrameSource.removeListener().

default()
static get default(): Camera

Added in version 6.13.0

Gets the default camera of the device. This method is identical to calling atPosition() with CameraPosition.WorldFacing.

See atPosition() for a more detailed description of the method behavior.

atPosition(cameraPosition)
static atPosition(cameraPosition: CameraPosition): Camera | null

Added in version 6.13.0

Retrieves the camera instance of the first camera at the provided position. In case the system does not have a camera at the provided position, null is returned.

When this method is called multiple times with the same argument, the same Camera instance is returned. The FrameSource.getCurrentState of the camera as well as the settings depend on previous invocations. For example, if the camera is currently in use and is active, the camera’s FrameSource.getCurrentState will be FrameSourceState.On. The only guarantee about the state and settings is that when instance is initially created, the FrameSource.getCurrentState is FrameSourceState.Off and has the default CameraSettings.

Important

In case parts of your app use custom camera settings and others use the default settings, make sure to reset the camera to use the default settings when you need them by passing the default camera settings to applySettings() to ensure that you don’t have any other settings when you’d expect the defaults to be active.

Important

There is no guarantee that the selected Camera will actually have the given position, depending on device, browser and camera it could not correspond to the camera’s real position.

The camera object is returned if present, regardless whether the application has permissions to use it or not.

fromDeviceCamera(deviceCamera)
static fromDeviceCamera(deviceCamera: DeviceCamera): Camera

Added in version 6.18.0

Constructs a new camera based on the passed DeviceCamera.

switchToDesiredState(state)
switchToDesiredState(state: FrameSourceState): Promise<void>

Added in version 6.13.0

Implemented from FrameSource. See FrameSource.switchToDesiredState().

applySettings(settings)
applySettings(settings: CameraSettings): Promise<void>

Added in version 6.13.0

Applies the camera settings to the camera. The task will complete when the settings have been applied and the camera has switched to use the new settings. If the camera is currently in FrameSourceState.Off state, the task will complete immediately. If, on the other hand, the camera is currently in FrameSourceState.On state, the settings will be modified on the fly.

settings
get settings(): CameraSettings

Added in version 6.20.0

Get the currently set CameraSettings on this camera. Use applySettings() to apply new settings.

isTorchAvailable()
isTorchAvailable(): Promise<boolean>

Added in version 6.13.0

Whether the torch is available for the given camera.

Available only on Chrome Android. When the camera is off, this method always returns false. When the camera is on, it returns true for cameras that support the torch, false otherwise.

getDesiredTorchState()
getDesiredTorchState(): TorchState

Added in version 6.13.0

Get the desired torch state for this camera. By default, the torch state is TorchState.Off. When setting the desired torch state to TorchState.On, the torch will be on as long as the camera is running (the camera’s state is FrameSourceState.On) and off otherwise.

setDesiredTorchState(desiredTorchState)
setDesiredTorchState(desiredTorchState: TorchState): Promise<void>

Added in version 6.13.0

Set the desired torch state for this camera. By default, the torch state is TorchState.Off. When setting the desired torch state to TorchState.On, the torch will be on as long as the camera is running (the camera’s state is FrameSourceState.On) and off otherwise. When setting the desired torch state for a camera that does not have a torch (see isTorchAvailable()), this call has no effect.

getMirrorImageEnabled()
getMirrorImageEnabled(): boolean

Added in version 6.13.0

Get whether the currently selected camera’s video is mirrored along the vertical axis. By default front cameras are automatically mirrored.

setMirrorImageEnabled(enabled)
setMirrorImageEnabled(enabled: boolean): Promise<void>

Added in version 6.13.0

Set whether the currently selected camera’s video is mirrored along the vertical axis. By default front cameras are automatically mirrored. This setting is applied per camera and the method has no effect if no camera is currently selected. In Single Image Mode this method has no effect.

label
readonly label: string

Added in version 6.13.0

The label describing the device, provided by the browser. Might be empty.

deviceId
deviceId: string

Added in version 6.13.0

The unique identifier for the device, can change between page loads. To force the usage of a given camera, set the deviceId on the default camera before starting it.