Web Demos

BARCODE READER SDK DEMO

Explore the flexibe barcode reading settings to optimize for your specific usage scenario.

WEB TWAIN SDK DEMO

Try the most popular web scanner features: scan images, import local images and PDF files, edit, save to local, upload to database, and etc.

BARCODE READER JAVASCRIPT DEMO

Transform any camera-equipped devices into real-time, browser-based barcode and QR code scanners.

MRZ SCANNER WEB DEMO

Detects the machine-readable zone of a passport, scans the text, and parses into human-readable data.

APP STORE DEMOS

BARCODE READER SDK FOR IOS

BARCODE READER SDK FOR ANDROID

VIEW MORE DEMOS >
Resource Base
Table of contents

Camera Control

Basic Control

API Name Description
ifSkipCameraInspection Returns or sets whether to skip camera inspection at initialization to save time.
ifSaveLastUsedCamera Returns or sets whether to save the last used camera and resolution.
getAllCameras() Returns infomation of all available cameras on the device.
selectCamera() Chooses a camera as the video source.
getSelectedCamera() Returns information about the selected / current camera.
open() Turns on the camera to start streaming live video.
close() Stops video streaming and releases the camera.
isOpen() Returns whether the selected camera is turned on / occupied.
pause() Pauses video streaming without releasing the camera.
resume() Resumes video streaming.
setResolution() Sets the resolution of the current video input.
getResolution() Returns the resolution of the current video input.
getResolutions() Returns the resolutions supported by the current video input.
videoSrc Sets or returns the source of the video.

Advanced Control

API Name Description
setFrameRate() Adjusts the frame rate.
getFrameRate() Returns the real-time frame rate.
turnOnTorch() Turns on the torch/flashlight if the current camera supports it.
turnOffTorch() Turns off the torch/flashlight.
setZoom() Sets the zoom level of the video.
setFocus() Sets the focus mode and focus distance of the camera.
getFocus() Gets the focus mode and focus distance of the camera.
getCapabilities() Inspects and returns the capabilities of the selected camera.
getCameraSettings() Returns the current values for each constrainable property of the selected camera.
setColorTemperature() Adjusts the color temperature of the selected camera.
setExposureCompensation() Sets the exposure compensation index of the selected camera.

ifSkipCameraInspection

Returns or sets whether to skip camera inspection at initialization to save time. Note that if a previously used camera is already available in the localStorage, the inspection is skipped automatically. Read more on ifSaveLastUsedCamera.

ifSkipCameraInspection: boolean;

ifSaveLastUsedCamera

Returns or sets whether to save the last used camera and resolution. This feature makes use of the localStorage of the browser.

NOTE

This feature only works on mainstream browsers like Chrome, Firefox and Safari. Other browsers may change the device IDs dynamically thus making it impossible to track the camera.

ifSaveLastUsedCamera: boolean;

getAllCameras

Returns infomation of all available cameras on the device.

getAllCameras(): Promise<VideoDeviceInfo[]>;

Parameters

None.

Return value

A promise resolving to an array of VideoDeviceInfo objects.

Code Snippet

let cameras = await enhancer.getAllCameras();
if (cameras.length) {
    await enhancer.selectCamera(cameras[0]);
}

See also

selectCamera

Chooses a camera as the video source.

If called before open() or show(), the selected camera will be used. Otherwise, the system will decide which one to use.

selectCamera(cameraObjectOrDeviceID: videodeviceinfo | string): Promise<PlayCallbackInfo>;

Parameters

cameraObjectOrDeviceID : specifies the camera.

Return value

A promise resolving to a PlayCallbackInfo object.

Code Snippet

let cameras = await enhancer.getAllCameras();
if (cameras.length) {
    await enhancer.selectCamera(cameras[0]);
}

See also

getSelectedCamera

Returns information about the selected / current camera.

getSelectedCamera(): VideoDeviceInfo;

Parameters

None.

Return value

A VideoDeviceInfo object with details about the selected camera.

Code Snippet

let camera = enhancer.getSelectedCamera();
console.log(camera.label);

See also

open

Turns on the camera to start streaming live video.

open(appendOrShowUI?: boolean): Promise<PlayCallbackInfo>;

Parameters

appendOrShowUI : this parameter specifies how to handle the UI. When set to true, if the UI doesn’t exist in the DOM tree, the CameraEnhancer instance will append it in the DOM and show it; if the UI already exists in the DOM tree but is hidden, it’ll be displayed. When not set or set to false, it means not to change the original state of that UI: if it doesn’t exist in the DOM tree, nothing shows up on the page; if it exists in the DOM tree, it may or may not show up depending on its original state.

NOTE: if setUIElement() is not called before open(), the default UI Element will be used, which is equivalent to the following code:

await cameraEnhancer.setUIElement(Dynamsoft.DCE.CameraEnhancer.defaultUIElementURL);
await cameraEnhancer.open(appendOrShowUI);

If you want to use a different UI element, call API setUIElement() beforehand.

Return value

A promise resolving to a PlayCallbackInfo object.

See also

close

Stops video streaming and releases the camera.

close(hideUI?: boolean): void;

Parameters

hideUI : this parameter specifies how to handle the UI. When set to true, if the UI doesn’t exist in the DOM tree or it exists but is hidden, nothing is done; if the UI already exists in the DOM tree and is shown, it’ll be hidden. When not set or set to false, it means not to change the original state of that UI: if it doesn’t exist in the DOM tree, nothing happens; if it exists in the DOM tree, it may or may not be hidden depending on its original state.

Return value

None.

isOpen

Returns whether the selected camera is turned on / occupied.

isOpen(): boolean;

Parameters

None.

Return value

true means the camera is turned on and false the opposite.

pause

Pauses video streaming without releasing the camera.

pause(): void;

Parameters

None.

Return value

None.

resume

Resumes video streaming.

resume(): void;

Parameters

None.

Return value

None.

setResolution

Sets the resolution of the current video input. If the specified resolution is not exactly supported, the closest resolution will be applied.

If called before open() or show(), the camera will use the set resolution when it opens. Otherwise, the default resolution is used, which is 1280 x 720.

setResolution(widthOrResolution: number | number[], height: number): Promise<PlayCallbackInfo>;

Parameters

width : specifies the horizontal resolution.

height : specifies the vertical resolution.

Return value

A promise resolving to a PlayCallbackInfo object.

Code Snippet

await enhancer.setResolution(width, height);

See also

getResolution

Returns the resolution of the current video input.

getResolution(): number[];

Parameters

None.

Return value

An array of two numbers representing the resolution in the sequence of [width, height].

Code Snippet

let resolution = await enhancer.getResolution();
console.log(resolution.width + " x " + resolution.height);

getResolutions

Returns the resolutions supported by the current video input.

The returned resolutions are limited to these values “160 by 120”, “320 by 240”, “480 by 360”, “640 by 480”, “800 by 600”, “960 by 720”, “1280 by 720”, “1920 by 1080”, “2560 by 1440”, “3840 by 2160”.

getResolutions(): Promise<Array<Array<number>>>;

Parameters

None.

Return value

A promise that resolves when the operation succeeds.

Code Snippet

const resolutions = await enhancer.getResolutions();
console.log(resolutions);

setFrameRate

Adjusts the frame rate.

At present, this method only works in Edge, Safari, Chrome and other Chromium-based browsers (Firefox is not supported). Also, it should be called when a camera is open.

setFrameRate(rate: number): Promise<void>;

Parameters

rate : specifies the new frame rate.

Return value

A promise that resolves when the operation succeeds.

Code Snippet

await enhancer.setFrameRate(10);

See also

getFrameRate

Returns the real-time frame rate.

getFrameRate(): number;

Parameters

None.

Return value

The calculated real-time frame rate.

Code Snippet

await enhancer.getFrameRate();

turnOnTorch

Turns on the torch/flashlight if the current camera supports it.

At present, this method only works in Edge, Chrome and other Chromium-based browsers (Firefox is not supported). Also, it should be called when a camera is open.

turnOnTorch(): Promise<void>;

Parameters

None.

Return value

A promise that resolves when the operation succeeds.

Code Snippet

await enhancer.turnOnTorch();

See also

turnOffTorch

Turns off the torch/flashlight.

At present, this method only works in Edge, Chrome and other Chromium-based browsers (Firefox is not supported). Also, it should be called when a camera is open.

turnOffTorch(): Promise<void>;

Parameters

None.

Return value

A promise that resolves when the operation succeeds.

Code Snippet

await enhancer.turnOffTorch();

See also

setZoom

Sets the focus mode and focus distance of the camera.

At present, this method only works in Edge, Chrome and other Chromium-based browsers (Firefox is not supported). Also, it should be called when a camera is open.

setZoom(zoomValue: number): Promise<void>;

Parameters

zoomValue : specifies the zoom level.

Return value

A promise that resolves when the operation succeeds.

Code Snippet

await enhancer.setZoom(400);

See also

setFocus

Sets the focus mode and focus distance of the camera.

At present, this method only works in Edge, Chrome and other Chromium-based browsers (Firefox is not supported). Also, it should be called when a camera is open.

setFocus(mode: string, distance?: number): Promise<void>;

Parameters

mode : specifies the focus mode, the available values include continuous and manual .

distance : specifies the focus distance, only required when the mode is set to manual . Use getCapabilities to get the allowed value range.

Return value

A promise that resolves when the operation succeeds.

Code Snippet

await enhancer.setFocus("manual", 400);

See also

getFocus

Gets the focus mode and the focus distance.

getFocus(): {mode: string, distance?: number};

Parameters

None.

Return value

A promise that resolves when the operation succeeds.

Code Snippet

await enhancer.getFocus();

See also

getCapabilities

Inspects and returns the capabilities of the selected camera.

At present, this method only works in Edge, Safari, Chrome and other Chromium-based browsers (Firefox is not supported). Also, it should be called when a camera is open.

getCapabilities(): MediaTrackCapabilities;

Parameters

None.

Return value

A MediaTrackCapabilities object which specifies the values or range of values for each constrainable property of the current camera.

Code Snippet

enhancer.getCapabilities();
/* Result sample
{
  aspectRatio: {max: 1280, min: 0.001388888888888889},
  brightness: {max: 64, min: -64, step: 1},
  colorTemperature: {max: 6500, min: 2800, step: 10},
  contrast: {max: 95, min: 0, step: 1},
  deviceId: "3a505c29a3312600ea0afd79f8e2b4ba4fba3e539257801ff1de8718c27f2bed",
  exposureMode: ["continuous", "manual"],
  exposureTime: {max: 10000, min: 39.0625, step: 39.0625},
  facingMode: [],
  focusDistance: {max: 1024, min: 0, step: 10},
  focusMode: ["continuous", "manual"],
  frameRate: {max: 30, min: 0},
  groupId: "35a82dcb7d5b0ef5bda550718d194f04a812c976175e926ccb81fb9d235d010f",
  height: {max: 720, min: 1},
  resizeMode: ["none", "crop-and-scale"],
  saturation: {max: 100, min: 0, step: 1},
  sharpness: {max: 7, min: 1, step: 1},
  whiteBalanceMode: ["continuous", "manual"],
  width: {max: 1280, min: 1}
}
*/

See also

getCameraSettings

Returns the current values for each constrainable property of the selected camera.

getCameraSettings(): MediaTrackSettings;

Parameters

None.

Return value

The current values for each constrainable property of the current camera in the form of a MediaTrackSettings object.

Code Snippet

enhancer.getCameraSettings();
/* Result sample
{
  aspectRatio: 1.3333333333333333,
  brightness: 0,
  colorTemperature: 4600,
  contrast: 0,
  deviceId: "3a505c29a3312600ea0afd79f8e2b4ba4fba3e539257801ff1de8718c27f2bed",
  exposureMode: "continuous",
  exposureTime: 156.25,
  focusDistance: 120,
  focusMode: "continuous",
  frameRate: 30,
  groupId: "35a82dcb7d5b0ef5bda550718d194f04a812c976175e926ccb81fb9d235d010f",
  height: 480,
  resizeMode: "none",
  saturation: 73,
  sharpness: 2,
  whiteBalanceMode: "continuous",
  width: 640
}
*/

See also

setColorTemperature

Adjusts the color temperature of the selected camera.

At present, this method only works in Edge, Chrome and other Chromium-based browsers (Firefox is not supported). Also, it should be called when a camera is open.

setColorTemperature(colorTemperatur: number): Promise<void>;

Parameters

colorTemperatur : specifies the new color temperature.

Return value

A promise that resolves when the operation succeeds.

Code Snippet

await enhancer.setColorTemperature(5000);

See also

setExposureCompensation

Sets the exposure compensation index of the selected camera.

At present, this method only works in Edge, Chrome and other Chromium-based browsers (Firefox is not supported). Also, it should be called when a camera is open.

setExposureCompensation(exposureCompensation: number): Promise<void>;

Parameters

exposureCompensation : specifies the new exposure compensation index.

Return value

A promise that resolves when the operation succeeds.

Code Snippet

await enhancer.setExposureCompensation(-0.7);

See also

videoSrc

Sets or returns the source of the video.

You can use this property to specify an existing video as the source to play which will be processed the same way as the video feed from a live camera.

videoSrc: string | MediaStream | MediaSource | Blob;

This page is compatible for:

Version 1.0

Is this page helpful?

YesYes NoNo

In this article:

latest version

  • Latest version
  • Version 2.3.2
  • Version 2.3.1
  • Version 2.1.0
  • Version 2.0.0
  • Version 1.0.3
  • Version 1.0.1
  • Version 1.0.0
Change +
© 2003–2022 Dynamsoft. All rights reserved.
Privacy Statement / Site Map / Home / Purchase / Support