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

bDestroyed

bDestroyed: boolean = false

Indicates whether the instance has been destroyed.

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 | OffscreenCanvas = null

The original canvas.

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

Accessors

Static _bUseFullFeature

  • get _bUseFullFeature(): boolean
  • set _bUseFullFeature(value: boolean): void
  • Returns boolean

  • Parameters

    • value: boolean

    Returns void

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
  • Get or set the Dynamsoft Barcode Reader SDK product keys.

    Returns string

  • Get or set the Dynamsoft Barcode Reader SDK product keys.

    Parameters

    • keys: string

    Returns void

Static version

  • get version(): string
  • Returns string

Initialize and Destroy Methods

destroy

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

    Returns Promise<any>

Static createInstance

  • Create a BarcodeReader object.

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

    Returns Promise<BarcodeReader>

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>

Decode 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>
  • Decode barcodes from raw buffer.

    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[]>

Runtime Settings Methods

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 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>

Other Methods

Static detectEnvironment

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

    Returns Promise<any>

Generated using TypeDoc