Dev Center
Table of contents

JavaScript API Reference

The library comes with two primary Classes: BarcodeReader and BarcodeScanner.

BarcodeReader

A low-level barcode reader that processes still images and return barcode results. The following code snippet shows its basic usage.

let reader = await Dynamsoft.DBR.BarcodeReader.createInstance();
let results = await reader.decode(imageSource);
for(let result of results){
  console.log(result.barcodeText);
}

The APIs for this class include

Create and Destroy Instances

API Name Description
createInstance Creates a BarcodeReader instance.
destroy Destroies the BarcodeReader instance.
bDestroyed Indicates whether the instance has been destroyed.

Decode Barcodes

API Name Description
decode Decodes barcodes from an image.
decodeBase64String Decodes barcodes from a base64-encoded image (with or without MIME).
decodeUrl Decodes barcodes from an image specified by its URL.
decodeBuffer Decodes barcodes from raw image data.

Change Settings

API Name Description
getRuntimeSettings Returns the current runtime settings.
updateRuntimeSettings Updates runtime settings with a given struct or a preset template.
resetRuntimeSettings Resets all parameters to default values.
getModeArgument Returns the argument value for the specified mode parameter.
setModeArgument Sets the argument value for the specified mode parameter.

Auxiliary

API Name Description
bSaveOriCanvas Whether to save the original image into a <canvas> element.
oriCanvas An HTMLCanvasElement that holds the original image.


BarcodeScanner

A barcode scanner object gets access to a camera via the MediaDevices interface, then uses its built-in UI to show the camera input and perform continuous barcode scanning on the incoming frames.

The default built-in UI of each barcode scanner is defined in the file “dbr.scanner.html”. If used directly, the UI will fit the entire page and sit on top. There are a few ways to customize it, read more on how to Customize the UI.

Although a barcode scanner is designed to scan barcodes from a video input, it also supports a special mode called singleFrameMode which allows the user to select a still image or take a shot with the mobile camera for barcode scanning.

The following code snippet shows the basic usage of the BarcodeScanner class.

let scanner = await Dynamsoft.DBR.BarcodeScanner.createInstance();
scanner.onUnduplicatedRead = txt => console.log(txt);
await scanner.show();

The BarcodeScanner is a child class of BarcodeReader and inherits all its methods and properties. APIs not directly inherited include

Create and Destroy Instances

API Name Description
createInstance Creates a BarcodeScanner instance.
destroy Destroys the BarcodeScanner instance.
bDestroyed Indicates whether the instance has been destroyed.

Decode Barcodes

API Name Description
onUnduplicatedRead This event is triggered when a new, unduplicated barcode is found.
onFrameRead This event is triggered after the library finishes scanning a frame.
decodeCurrentFrame Scans the current frame of the video for barcodes.

Basic Interaction

API Name Description
show Binds and shows UI, opens the camera and starts decoding.
hide Stops decoding, releases camera and unbinds UI.
pauseScan Pauses the decoding process.
resumeScan Resumes the decoding process.

Scan Settings

API Name Description  
bPlaySoundOnSuccessfulRead Whether and when to play sound on barcode recognition.  
soundOnSuccessfullRead Specifies the sound to play on barcode recognition.  
bVibrateOnSuccessfulRead Whether and when to vibrate on barcode recognition.  
vibrateDuration Returns or sets how long the vibration lastsin milliseconds.  
singleFrameMode Returns or sets whether to enable the singe-frame mode.  
getScanSettings Returns the current scan settings.  
updateScanSettings Changes scan settings with the object passed in.  

UI Control

API Name Description
getUIElement Returns the HTML element that is used by the BarcodeScanner instance.
setUIElement Specifies an HTML element for the BarcodeScanner instance to use as its UI.
defaultUIElementURL Returns or sets the URL of the .html file that defines the default UI Element.
barcodeFillStyle Specifies the color used inside the shape which highlights a found barcode.
barcodeStrokeStyle Specifies the color used to paint the outline of the shape which highlights a found barcode.
barcodeLineWidth Specifies the line width of the outline of the shape which highlights a found barcode.
regionMaskFillStyle Specifies the color used in the square-loop shape between the actual scanning area and the boundary of the video input.
regionMaskStrokeStyle Specifies the color used to paint the outline of the scanning region.
regionMaskLineWidth Specifies the width of the outline of the scanning region.

Camera Control

API Name Description
getAllCameras Returns infomation of all available cameras on the device.
getCurrentCamera Returns information about the current camera.
setCurrentCamera Chooses a camera as the video source.
getResolution Returns the resolution of the current video input.
setResolution Sets the resolution of the current video input.
getVideoSettings Returns the current video settings.
updateVideoSettings Changes the video input.
openVideo Binds UI and opens the camera to show the video stream.
showVideo Similar to openVideo but will also show the UI Element if it is hidden.
play Play the video if it is already open but paused or stopped.
onPlayed This event is triggered when the video stream starts playing.
pause Pauses the video without releasing the camera.
stop Stops the video and releases the camera.

Advanced Camera Control

API Name Description
getCapabilities Inspects and returns the capabilities of the current camera.
getCameraSettings Returns the current values for each constrainable property of the current camera.
setFrameRate Adjusts the frame rate.
setColorTemperature Adjusts the color temperature.
setExposureCompensation Sets the exposure compensation index.
setZoom Sets the exposure compensation index.
turnOnTorch Turns on the torch/flashlight.
turnOffTorch Turns off the torch/flashlight.

License Control

The library provides flexible licensing options with the support of the following APIs

Initialization Control

The following static methods and properties help to set up the runtime environment for the library.

Interfaces and Enums

In order to make the code more predictable and readable, the library defines a series of supporting interfaces and enumerations.

Interfaces

Enums

This page is compatible for:

Version 7.5.0

Is this page helpful?

YesYes NoNo

In this article:

version 8.4.0

  • Latest version(10.2.10)
  • Version 10.x
    • Version 10.0.21
    • Version 10.0.20
  • Version 9.x
    • Version 9.6.40
    • Version 9.6.33
    • Version 9.6.32
    • Version 9.6.31
    • Version 9.6.30
    • Version 9.6.21
    • Version 9.6.20
    • Version 9.6.11
    • Version 9.6.10
    • Version 9.6.2
    • Version 9.6.1
    • Version 9.6.0
    • Version 9.3.1
    • Version 9.3.0
    • Version 9.2.13
    • Version 9.2.12
    • Version 9.2.11
    • Version 9.0.2
    • Version 9.0.1
    • Version 9.0.0
  • Version 8.x
    • Version 8.8.7
    • Version 8.8.5
    • Version 8.8.3
    • Version 8.8.0
    • Version 8.6.3
    • Version 8.6.0
    • Version 8.4.0
    • Version 8.2.5
    • Version 8.2.3
    • Version 8.2.1
    • Version 8.2.0
    • Version 8.1.3
    • Version 8.1.2
    • Version 8.1.0
    • Version 8.0.0
  • Version 7.x
    • Version 7.6.0
    • Version 7.5.0
Change +