Thanks for downloading Dynamsoft Barcode Reader Package!
Your download will start shortly. If your download does not begin, click here to retry.
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);
}
API Name | Description |
---|---|
createInstance | Creates a BarcodeReader instance. |
destroyContext | Destroies the BarcodeReader instance. |
isContextDestroyed | Indicates whether the instance has been destroyed. |
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. |
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. |
API Name | Description |
---|---|
ifSaveOriginalImageInACanvas | Whether to save the original image into a <canvas> element. |
getOriginalImageInACanvas | Returns an HTMLCanvasElement that holds the original image. |
Creates a BarcodeReader
instance.
static createInstance(): Promise<BarcodeReader>
Parameters
None.
Return value
A promise resolving to the created BarcodeReader
object.
Code snippet
let reader = await Dynamsoft.DBR.BarcodeReader.createInstance();
Destroies the BarcodeReader
instance. If your page needs to create new instances from time to time, don’t forget to destroy unused old instances.
destroyContext(): Promise<void>
Parameters
None.
Return value
A promise that resolves when the operation succeeds.
Code snippet
let reader = await Dynamsoft.DBR.BarcodeReader.createInstance();
// ... decode ...
reader.destroyContext();
Returns whether the instance has been destroyed.
isContextDestroyed(): boolean
Decodes barcodes from an image.
decode(source: Blob | Buffer | ArrayBuffer | Uint8Array | Uint8ClampedArray | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | string): Promise<TextResult[]>
Parameters
source
: specifies the image to decode. The supported image formats include png
, jpeg
, bmp
, gif
and a few others (some browsers support webp
, tif
). Also note that the image can be specified in a lot of ways including binary data, base64 string (with MIME), URL, etc.
Return value
A promise resolving to a TextResult
object that contains all the barcode results found in this image.
Code snippet
let results1 = await reader.decode(blob);
let results2 = await reader.decode(htmlImageElement);
let results3 = await reader.decode(url);
let results4 = await reader.decode(strBase64WithMime); // like `data:image/png;base64,iV************`
You can even use an HTMLVideoElement
as the source. If the video is playing, the current frame will be decoded.
let results;
try{
// The current frame will be decoded.
results = await reader.decode(htmlVideoElement);
}catch(ex){
// If no frame in the video, throws an exception.
}
See also
Decodes barcodes from a base64-encoded image (with or without MIME).
decodeBase64String(base64Str: string): Promise<TextResult[]>
Parameters
base64Str
: specifies the image represented by a string.
Return value
A promise resolving to a TextResult
object that contains all the barcode results found in this image.
Code snippet
let results = await reader.decodeBase64String(strBase64); //e.g. `data:image/jpg;base64,Xfjshekk....` or `Xfjshekk...`.
for(let result of results){
console.log(result.barcodeText);
}
See also
Decodes barcodes from an image specified by its URL. Note that the image should either be from the same domain or has the ‘Access-Control-Allow-Origin’ header set to allow access from your current domain.
decodeUrl(url: string): Promise<TextResult[]>
Parameters
url
: specifies the image with its URL.
Return value
A promise resolving to a TextResult
object that contains all the barcode results found in this image.
Code snippet
let results = await reader.decodeUrl("https://www.yourdomain.com/imageWithBarcodes.png");
for(let result of results){
console.log(result.barcodeText);
}
See also
Decodes barcodes from raw image data.
decodeBuffer(buffer: Blob | Buffer | ArrayBuffer | Uint8Array | Uint8ClampedArray, width: number, height: number, stride: number, format: EnumImagePixelFormat): Promise<TextResult[]>
Parameters
buffer
: specifies the image represented by a Uint8Array
, Uint8ClampedArray
, ArrayBuffer
, Blob
or Buffer
object.
Return value
A promise resolving to a TextResult
object that contains all the barcode results found in this image.
See also
Returns the current runtime settings.
getRuntimeSettings(): Promise<RuntimeSettings>
Parameters
None.
Return value
A promise resolving to a RuntimeSettings
object that contains the settings for barcode reading.
Code snippet
let settings = await reader.getRuntimeSettings();
settings.barcodeFormatIds = Dynamsoft.DBR.EnumBarcodeFormat.BF_QR_CODE; // Decodes only QR code.
await reader.updateRuntimeSettings(settings);
See also
Updates runtime settings with a given struct or a preset template represented by one of the following strings
speed
: fast but may miss a few codes;coverage
: slow but try to find all codes, this is the default setting for a BarcodeReader
instance;balance
: between speed
and coverage
;single
: optimized for scanning one single barcode from a video input, this is supported only by the sub-class BarcodeScanner
and is also the default setting for a BarcodeScanner
instance.updateRuntimeSettings(settings: RuntimeSettings | string): Promise<void>
Parameters
settings
: a RuntimeSettings
object that contains the new settings for barcode reading.
Return value
A promise that resolves when the operation succeeds.
Code snippet
await reader.updateRuntimeSettings('balance');
let settings = await reader.getRuntimeSettings();
settings.barcodeFormatIds = Dynamsoft.DBR.EnumBarcodeFormat.BF_ONED;
await reader.updateRuntimeSettings(settings);
See also
Resets all parameters to default values.
For a BarcodeReader
instance, it is equivalent to setting the coverage
template.
For a BarcodeScanner
instance, it is equivalent to setting the single
template.
resetRuntimeSettings(): Promise<void>
Parameters
None.
Return value
A promise that resolves when the operation succeeds.
Code snippet
await reader.resetRuntimeSettings();
Returns the argument value for the specified mode parameter.
getModeArgument(modeName: string, index: number, argumentName: string): Promise<string>
Parameters
modeName
: specifies the mode which contains one or multiple elements.
index
: specifies an element of the mode by its index.
argumentName
: specifies the argument.
Return value
A promise resolving to a string which represents the value of the argument.
Code snippet
let argumentValue = await reader.getModeArgument("BinarizationModes", 0, "EnableFillBinaryVacancy");
See also
Sets the argument value for the specified mode parameter.
setModeArgument(modeName: string, index: number, argumentName: string, argumentValue: string): Promise<void>
Parameters
modeName
: specifies the mode which contains one or multiple elements.
index
: specifies an element of the mode by its index.
argumentName
: specifies the argument.
argumentValue
: specifies the value.
Return value
A promise that resolves when the operation succeeds.
Code snippet
await reader.setModeArgument("BinarizationModes", 0, "EnableFillBinaryVacancy", "1");
See also
Whether to save the original image into a <canvas> element. The original image refers to the actual image the library tried to read barcodes from.
Note that the result is an HTMLCanvasElement
element and you can insert it into the DOM to show the image.
ifSaveOriginalImageInACanvas: boolean;
Default value
false
Code snippet
reader.ifSaveOriginalImageInACanvas = true;
let results = await reader.decode(source);
document.body.append(reader.getOriginalImageInACanvas());
An HTMLCanvasElement that holds the original image. The original image refers to the actual image the library tried to read barcodes from.
getOriginalImageInACanvas(): HTMLCanvasElement | OffscreenCanvas
Code snippet
reader.ifSaveOriginalImageInACanvas = true;
let results = await reader.decode(source);
document.body.append(reader.getOriginalImageInACanvas());
See also
latest version