JavaScript API Reference
The Dynamsoft Barcode Reader JavaScript library comes with two primary classes: BarcodeReader and BarcodeScanner.
BarcodeReader
A low-level barcode reader that processes still images and returns 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. |
destroyContext() | Destroys the BarcodeReader instance. |
isContextDestroyed() | Returns whether the instance has been destroyed. |
Decode Barcodes on a Single Image
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. |
Decode Barcodes on multiple images from an Image Source
API Name | Description |
---|---|
setImageSource | Sets an image source for continous scanning. |
onUniqueRead | This event is triggered when a new, unduplicated barcode is found. |
onImageRead | This event is triggered after the library finishes scanning an image. |
startScanning() | Starts continuous scanning of incoming images. |
stopScanning() | Stops continuous scanning. |
pauseScanning() | Pause continuous scanning but keep the video stream. |
resumeScanning() | Resumes continuous scanning. |
getScanSettings() | Returns the current scan settings. |
updateScanSettings() | Changes scan settings with the object passed in. |
Change Settings
API Name | Description |
---|---|
getRuntimeSettings() | Returns the current runtime settings. |
initRuntimeSettingsWithString | Initializes the Runtime Settings with the settings in the given JSON string. |
updateRuntimeSettings() | Updates runtime settings with a given struct or a preset template. |
resetRuntimeSettings() | Resets all parameters to default values. |
outputRuntimeSettingsToString() | Return the current RuntimeSettings in the form of a string. |
getModeArgument() | Returns the argument value for the specified mode parameter. |
setModeArgument() | Sets the argument value for the specified mode parameter. |
Auxiliary
API Name | Description |
---|---|
ifSaveOriginalImageInACanvas | Whether to save the original image into a <canvas> element. |
getOriginalImageInACanvas() | Returns 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 performs continuous barcode scanning on the incoming frames.
The default built-in UI of a barcode scanner object is defined in the file dbr.ui.html
. The UI fits the entire page and sits on top. 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 users to select a still image or take a shot with the camera for barcode scanning.
The following code snippet shows the basic usage of the BarcodeScanner
class.
let scanner = await Dynamsoft.DBR.BarcodeScanner.createInstance();
scanner.onUniqueRead = txt => console.log(txt);
await scanner.show();
The BarcodeScanner
class is based on BarcodeReader and inherits most of its methods and properties. The following APIs are different or unique:
Create and Destroy Instances
API Name | Description |
---|---|
createInstance() | Creates a BarcodeScanner instance. |
destroyContext() | Destroys the BarcodeScanner instance. |
isContextDestroyed() | Returns whether the instance has been destroyed. |
Decode Barcodes
API Name | Description |
---|---|
onUniqueRead | This event is triggered when a new, unduplicated barcode is found. |
onFrameRead | This event is triggered after the library finishes scanning a frame. |
Basic Interaction
API Name | Description |
---|---|
show() | Binds and shows UI, opens the camera and starts decoding. |
hide() | Stops decoding, releases camera, hides and unbinds UI. |
open() | Binds UI, opens the camera and starts decoding. |
close() | Stops decoding, releases camera and unbinds UI. |
isOpen() | Indicates whether the camera is turned on. |
Scan Settings
API Name | Description |
---|---|
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. |
barcodeFillStyleBeforeVerification | Specifies the color used inside the shape which highlights a found linear barcode which has not been verified. |
barcodeStrokeStyleBeforeVerification | Specifies the color used to paint the outline of the shape which highlights a found linear barcode which has not been verified. |
barcodeLineWidthBeforeVerification | Specifies the line width of the outline of the shape which highlights a found linear barcode which has not been verified. |
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. |
setVideoFit() | Sets the object-fit CSS property of the video element. |
ifShowScanRegionMask | Whether to show or hide the scan region mask. |
showTip() | Shows a Tip message. |
hideTip() | Hides the Tip message. |
updateTipMessage() | Changes the Tip message. |
onTipSuggested() | An event that gets triggered whenever a Tip is suggested. |
convertToPageCoordinates() | Converts coordinates of a barcode location to the coordinates relative to the top left point of the entire document. |
convertToClientCoordinates() | Converts coordinates of a barcode location to the coordinates within the application’s viewport at which the event occurred (as opposed to the coordinate within the page). |
Camera 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. |
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. |
onWarning | A callback which is triggered when the resolution is not ideal (<720P). |
testCameraAccess | Test whether there is an available camera. |
Video Decoding Process Control
API Name | Description |
---|---|
play() | Play the video if it is already open but paused or stopped. |
onPlayed | This event is triggered when the video stream starts playing. |
pauseScan() | Pauses the decoding process. |
resumeScan() | Resumes the decoding process. |
pause() | Pauses the video without releasing the camera. |
stop() | Stops the video and releases the camera. |
videoSrc | Sets or returns the source of the video. |
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. |
getFrameRate() | Returns the real-time frame rate. |
setFrameRate() | Adjusts the frame rate. |
turnOnTorch() | Turns on the torch/flashlight. |
turnOffTorch() | Turns off the torch/flashlight. |
getZoomSettings() | Returns the zoom settings. |
setZoom() | Zooms the video stream. |
resetZoom() | Resets the zoom level of the video. |
getFocusSettings() | Returns the focus settings. |
setFocus() | Sets how the camera focuses. |
enableTapToFocus() | Enables manual camera focus when clicking/tapping on the video. |
disableTapToFocus() | Disables manual camera focus when clicking/tapping on the video. |
isTapToFocusEnabled() | Returns whether clicking/tapping on the video invokes the camera to focus. |
getColorTemperature() | Returns the color temperature of the selected camera. |
setColorTemperature() | Adjusts the color temperature of the selected camera. |
getExposureCompensation() | Returns the exposure compensation index of the selected camera. |
setExposureCompensation() | Sets the exposure compensation index of the selected camera. |
License Control
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
- LocalizationResult
- Region
- RuntimeSettings
- FurtherModes
- ScannerPlayCallbackInfo
- ScanSettings
- TextResult
- VideoDeviceInfo
- imagesource
- dsimage
Enums
- EnumBarcodeColourMode
- EnumBarcodeComplementMode
- EnumBarcodeFormat
- EnumBarcodeFormat_2
- EnumBinarizationMode
- EnumClarityCalculationMethod
- EnumClarityFilterMode
- EnumColourClusteringMode
- EnumColourConversionMode
- EnumConflictMode
- EnumDeblurMode
- EnumDeformationResistingMode
- EnumDPMCodeReadingMode
- EnumErrorCode
- EnumGrayscaleTransformationMode
- EnumImagePixelFormat
- EnumImagePreprocessingMode
- EnumIMResultDataType
- EnumIntermediateResultSavingMode
- EnumIntermediateResultType
- EnumLocalizationMode
- EnumPDFReadingMode
- EnumQRCodeErrorCorrectionLevel
- EnumRegionPredetectionMode
- EnumResultCoordinateType
- EnumResultType
- EnumScaleUpMode
- EnumTerminatePhase
- EnumTextFilterMode
- EnumTextResultOrderMode
- EnumTextureDetectionMode