Options
All
  • Public
  • Public/Protected
  • All
Menu

Class BarcodeReader

A class dedicated to image decoding.

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

Hierarchy

Index

Properties

bSaveOriCanvas

bSaveOriCanvas: boolean = false

Whether to save the original image into canvas.

reader.bSaveOriCanvas = true;
let results = await reader.decode(source);
document.body.append(reader.oriCanvas);

Optional oriCanvas

oriCanvas: HTMLCanvasElement = null

The original canvas.

reader.bSaveOriCanvas = true;
let results = await reader.decode(source);
document.body.append(reader.oriCanvas);

Static _bUseFullFeature

_bUseFullFeature: boolean = bNode

Whether to use full feature wasm. The api may change in later version.

Min wasm:
oned + qr + pdf417 + datamatrix.
===
Full wasm:
all supported barcode format +
high level deblur available (lv8, 9) +
DPM +
template API +
intermediate results API
===
e.g.:
Use min in video deocode (small, download and initialization fast).
Use full in file decode (need high level deblur).

Need to be set before loadWasm.

Dynamsoft.BarcodeReader._bUseFullFeature = true;
await Dynamsoft.BarcodeReader.loadWasm();

For web, _bUseFullFeature is false as default. For Node.js, _bUseFullFeature will not work, and BarcodeReader will always work on full feature.

Accessors

Static engineResourcePath

  • get engineResourcePath(): string
  • set engineResourcePath(value: string): void
  • The SDK will try to automatically explore the engine location. If the auto-explored engine location is not accurate, manually specify the engine location.

    Dynamsoft.BarcodeReader.engineResourcePath = "https://cdn.jsdelivr.net/npm/dynamsoft-javascript-barcode@7.2.2/dist/";
    await Dynamsoft.BarcodeReader.loadWasm();

    Returns string

  • The SDK will try to automatically explore the engine location. If the auto-explored engine location is not accurate, manually specify the engine location.

    Dynamsoft.BarcodeReader.engineResourcePath = "https://cdn.jsdelivr.net/npm/dynamsoft-javascript-barcode@7.2.2/dist/";
    await Dynamsoft.BarcodeReader.loadWasm();

    Parameters

    • value: string

    Returns void

Static productKeys

  • get productKeys(): string
  • set productKeys(keys: string): void
  • Returns string

  • Parameters

    • keys: string

    Returns void

Static version

  • get version(): string
  • Returns string

Methods

decode

  • decode(source: Blob | Buffer | ArrayBuffer | Uint8Array | Uint8ClampedArray | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | string): Promise<TextResult[]>
  • The main decoding method can accept a variety of data types, including binary data, images, base64(with mime), urls, etc.

    let results = await reader.decode(blob);
    for(let result of results){
        console.log(result.barcodeText);
    }

    Parameters

    • source: Blob | Buffer | ArrayBuffer | Uint8Array | Uint8ClampedArray | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | string

    Returns Promise<TextResult[]>

decodeBase64String

  • decodeBase64String(base64: string): Promise<TextResult[]>
  • The decoding method can accept base64 with or without mime. e.g. data:image/jpg;base64,Xfjshekk.... or Xfjshekk....

    let results = await reader.decodeBase64String(strBase64);
    for(let result of results){
        console.log(result.barcodeText);
    }

    Parameters

    • base64: string

    Returns Promise<TextResult[]>

decodeBuffer

  • decodeBuffer(buffer: Uint8Array | Uint8ClampedArray | ArrayBuffer | Blob | Buffer, width: number, height: number, stride: number, format: EnumImagePixelFormat, config?: any): Promise<any>
  • Parameters

    • buffer: Uint8Array | Uint8ClampedArray | ArrayBuffer | Blob | Buffer
    • width: number
    • height: number
    • stride: number
    • format: EnumImagePixelFormat
    • Optional config: any

    Returns Promise<any>

decodeUrl

  • The decoding method can accept url. The url source need to be in the same domain or allowed cors.

    let results = await reader.decodeUrl("./1.png");
    for(let result of results){
        console.log(result.barcodeText);
    }

    Parameters

    • url: string

    Returns Promise<TextResult[]>

destroy

  • destroy(): Promise<any>
  • Destructor the BarcodeReader object. Equivalent to the previous method deleteInstance().

    Returns Promise<any>

getModeArgument

  • getModeArgument(modeName: string, index: number, argumentName: string): Promise<string>
  • Gets the optional argument for a specified mode in Modes parameters.

    let argumentValue = await reader.getModeArgument("BinarizationModes", 0, "EnableFillBinaryVacancy");

    Parameters

    • modeName: string
    • index: number
    • argumentName: string

    Returns Promise<string>

getRuntimeSettings

  • Gets current settings and save it into a struct.

    let settings = await reader.getRuntimeSettings();
    settings.deblurLevel = 5;
    await reader.updateRuntimeSettings(settings);
    see

    RuntimeSettings

    Returns Promise<RuntimeSettings>

resetRuntimeSettings

  • resetRuntimeSettings(): Promise<void>
  • Resets all parameters to default values.

    await reader.resetRuntimeSettings();

    Returns Promise<void>

setModeArgument

  • setModeArgument(modeName: string, index: number, argumentName: string, argumentValue: string): Promise<void>
  • Sets the optional argument for a specified mode in Modes parameters.

    await reader.setModeArgument("BinarizationModes", 0, "EnableFillBinaryVacancy", "1");

    Parameters

    • modeName: string
    • index: number
    • argumentName: string
    • argumentValue: string

    Returns Promise<void>

updateRuntimeSettings

  • Update runtime settings with a given struct or a string of speed, balance or coverage. Use speed, balance and coverage to use preset settings for BarcodeReader. The default settings for BarcodeReader is coverage.

    await reader.updateRuntimeSettings('balance');
    let settings = await reader.getRuntimeSettings();
    settings.barcodeFormatIds = Dynamsoft.EnumBarcodeFormat.BF_ONED;
    await reader.updateRuntimeSettings(settings);
    see

    RuntimeSettings

    Parameters

    Returns Promise<void>

Static createInstance

  • Create a BarcodeReader object.

    let reader = await Dynamsoft.BarcodeReader.createInstance();

    Returns Promise<BarcodeReader>

Static detectEnvironment

  • detectEnvironment(): Promise<any>
  • Detect environment and get a report.

    Returns Promise<any>

Static isLoaded

  • isLoaded(): boolean
  • Determine if the decoding module has been loaded successfully.

    Returns boolean

Static loadWasm

  • loadWasm(): Promise<void>
  • Manually load and compile the decoding module. Used for preloading to avoid taking too long for lazy loading.

    Returns Promise<void>

Generated using TypeDoc