Options
All
  • Public
  • Public/Protected
  • All
Menu

Class BarcodeScanner

A class dedicated to video decoding.

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

Hierarchy

Index

UI Properties

barcodeFillStyle

barcodeFillStyle: string = "rgba(254,180,32,0.3)"

barcodeLineWidth

barcodeLineWidth: number = 1

barcodeStrokeStyle

barcodeStrokeStyle: string = "rgba(254,180,32,0.9)"

regionMaskFillStyle

regionMaskFillStyle: string = "rgba(0,0,0,0.5)"

regionMaskLineWidth

regionMaskLineWidth: number = 2

regionMaskStrokeStyle

regionMaskStrokeStyle: string = "rgb(254,142,20)"

Other Properties

bDestroyed

bDestroyed: boolean = false

Indicates whether the instance has been destroyed.

bPlaySoundOnSuccessfulRead

bPlaySoundOnSuccessfulRead: string | false | true = false

Whether to play sound when the scanner reads a barcode successfully. Default value is false, which does not play sound. Use frame or true to play a sound when any barcode is found within a frame. Use unduplicated to play a sound only when any unique/unduplicated barcode is found within a frame.

scanner.bPlaySoundOnSuccessfulRead = false;
scanner.bPlaySoundOnSuccessfulRead = true;
scanner.bPlaySoundOnSuccessfulRead = "frame";
scanner.bPlaySoundOnSuccessfulRead = "unduplicated";
scanner.show();

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 onFrameRead

onFrameRead: (results: TextResult[]) => void

The event that is triggered once a single frame has been scanned. The results object contains all the barcode results that the reader was able to decode.

scanner.onFrameRead = results => {
    for(let result of results){
        console.log(result.barcodeText);
    }
};

Type declaration

Optional onPlayed

onPlayed: (info: ScannerPlayCallbackInfo) => void

scanner.onplayed = rsl=>{ console.log(rsl.width+'x'+rsl.height) };

Type declaration

Optional onUnduplicatedRead

onUnduplicatedRead: (txt: string, result: TextResult) => void

This event is triggered when a not duplicated new barcode is found. txt holds the barcode text result. result contains the actual barcode result, including the text result. Old barcode will remember for duplicateForgetTime.

scanner.onUnduplicatedRead = (txt, result) => {
    alert(txt);
    console.log(result);
};

Type declaration

Optional oriCanvas

oriCanvas: HTMLCanvasElement | OffscreenCanvas = null

The original canvas.

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

Accessors

singleFrameMode

  • get singleFrameMode(): boolean
  • set singleFrameMode(value: boolean): void
  • A mode not use video, get a frame from OS camera instead.

    let scanner = await Dynamsoft.BarcodeReader.createInstance();
    if(scanner.singleFrameMode){
        // the browser does not provide webrtc API, dbrjs automatically use singleFrameMode instead
        scanner.show();
    }

    Returns boolean

  • A mode not use video, get a frame from OS camera instead.

    let scanner = await Dynamsoft.BarcodeReader.createInstance();
    scanner.singleFrameMode = true; // use singleFrameMode anyway
    scanner.show();

    Parameters

    • value: boolean

    Returns void

soundOnSuccessfullRead

  • get soundOnSuccessfullRead(): HTMLAudioElement
  • set soundOnSuccessfullRead(value: HTMLAudioElement): void
  • The sound to play when the scanner get successfull read.

    Returns HTMLAudioElement

  • The sound to play when the scanner get successfull read.

    scanner.soundOnSuccessfullRead = new Audio("./pi.mp3");

    Parameters

    • value: HTMLAudioElement

    Returns void

Static _bUseFullFeature

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

Static defaultUIElementURL

  • get defaultUIElementURL(): string
  • set defaultUIElementURL(value: string): void
  • Returns string

  • Parameters

    • value: string

    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

Initialize and Destroy Methods

destroy

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

    Returns Promise<any>

Static createInstance

  • Create a BarcodeScanner object.

    let scanner = await Dynamsoft.BarcodeScanner.createInstance();

    Parameters

    • Optional config: any

    Returns Promise<BarcodeScanner>

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>

Open and Close Methods

close

  • close(): void
  • Stop decoding, release camera, unbind UI.

    Returns void

hide

  • hide(): void
  • Stop decoding, release camera, unbind UI, and set the Element as display:none;.

    Returns void

isOpen

  • isOpen(): boolean
  • Check if the scanner is open.

    Returns boolean

open

  • Bind UI, open the camera, start decoding.

    await scanner.open()

    Returns Promise<ScannerPlayCallbackInfo>

show

  • Bind UI, open the camera, start decoding, and remove the UIElement display style if the original style is display:none;.

    await scanner.show()

    Returns Promise<ScannerPlayCallbackInfo>

Play and Pause Methods

pause

  • pause(): void
  • Pause the video. Will not release the camera.

    Returns void

pauseScan

  • pauseScan(): void
  • Pause the decoding process.

    Returns void

play

  • Continue the video.

    scanner.pause();
    \\*** a lot of work ***
    await scanner.play();

    Parameters

    • Optional deviceId: string
    • Optional width: number
    • Optional height: number

    Returns Promise<ScannerPlayCallbackInfo>

resumeScan

  • resumeScan(): void
  • Resume the decoding process.

    Returns void

stop

  • stop(): void
  • Stop the video, and release the camera.

    Returns void

UI Methods

getUIElement

  • getUIElement(): HTMLElement
  • Get the HTML element that contains your scanner object.

    Returns HTMLElement

setUIElement

  • setUIElement(elementOrUrl: HTMLElement | string): Promise<void>
  • set the HTML element that contains your scanner object.

    <video class="dbrScanner-video" playsinline="true"></video>
    <script>
        let scanner = await Dynamsoft.BarcodeScanner.createInstance();
        scanner.setUIElement(document.getElementByClassName("dbrScanner-video")[0]);
        await scanner.open();
    </script>

    Parameters

    • elementOrUrl: HTMLElement | string

    Returns Promise<void>

Camera Settings Methods

getAllCameras

  • Get infomation of all available cameras on your device.

    let cameras = await scanner.getAllCameras();
    if(cameras.length){
        await scanner.setCurrentCamera(cameras[0]);
    }

    Returns Promise<VideoDeviceInfo[]>

getCapabilities

  • getCapabilities(): MediaTrackCapabilities
  • Get the camera capabilities. Chrome only. Only available when the scanner is open.

    > scanner.getCapabilities()
    < {
      "aspectRatio":{"max":3840,"min":0.000462962962962963},
      "colorTemperature": {max: 7000, min: 2850, step: 50},
      "deviceId":"1e...3af7",
      "exposureCompensation": {max: 2.0000040531158447, min: -2.0000040531158447, step: 0.16666699945926666},
      "exposureMode":["continuous","manual"],
      "facingMode":["environment"],
      "focusMode":["continuous","single-shot","manual"],
      "frameRate":{"max":30,"min":0},
      "groupId":"71...a935",
      "height":{"max":2160,"min":1},
      "resizeMode":["none","crop-and-scale"],
      "torch":true,
      "whiteBalanceMode":["continuous","manual"],
      "width":{"max":3840,"min":1},
      "zoom":{max: 606, min: 100, step: 2}
      }
    see

    turnOnTorchturnOffTorchsetExposureCompensationsetZoom

    Returns MediaTrackCapabilities

getCurrentCamera

  • Get infomation of the currently used camera.

    let camera = await scanner.getCurrentCamera();

    Returns Promise<VideoDeviceInfo | null>

getResolution

  • getResolution(): number[]
  • Get current video resolution.

    let rsl = await scanner.getResolution();
    console.log(rsl.width + " x " + rsl.height);

    Returns number[]

getVideoSettings

  • getVideoSettings(): MediaStreamConstraints
  • Get current video settings of the BarcodeScanner object and saves it into a struct.

    Returns MediaStreamConstraints

setColorTemperature

  • setColorTemperature(value: number): Promise<void>
  • Adjusts the color temperature. Chrome only. Only available when the scanner is open. Will reject if not support.

    await scanner.setColorTemperature(5000);
    see

    getCapabilities

    Parameters

    • value: number

    Returns Promise<void>

setCurrentCamera

  • Choose the camera and play it by its information or devide id.

    let cameras = await scanner.getAllCameras();
    if(cameras.length){
        await scanner.setCurrentCamera(cameras[0]);
    }

    Parameters

    • cameraInfoOrDeviceId: any

    Returns Promise<ScannerPlayCallbackInfo>

setExposureCompensation

  • setExposureCompensation(value: number): Promise<void>
  • Adjusts the exposure level. Chrome only. Only available when the scanner is open. Will reject if not support.

    await scanner.setExposureCompensation(-0.7);
    see

    getCapabilities

    Parameters

    • value: number

    Returns Promise<void>

setFrameRate

  • setFrameRate(value: number): Promise<void>
  • Adjusts the frame rate. Chrome only. Only available when the scanner is open. Will reject if not support.

    await scanner.setFrameRate(10);
    see

    getCapabilities

    Parameters

    • value: number

    Returns Promise<void>

setResolution

  • Set the camera resolution.

    await scanner.setResolution(width, height);

    Parameters

    • width: number | number[]
    • height: number

    Returns Promise<ScannerPlayCallbackInfo>

setZoom

  • setZoom(value: number): Promise<void>
  • Adjusts the zoom ratio. Chrome only. Only available when the scanner is open. Will reject if not support.

    await scanner.setZoom(400);
    see

    getCapabilities

    Parameters

    • value: number

    Returns Promise<void>

turnOffTorch

  • turnOffTorch(): Promise<void>
  • Turn off the torch. Chrome only. Only available when the scanner is open. Will reject if not support.

    await scanner.turnOffTorch();
    see

    turnOnTorchgetCapabilities

    Returns Promise<void>

turnOnTorch

  • turnOnTorch(): Promise<void>
  • Turn on the torch. Chrome only. Only available when the scanner is open. Will reject if not support.

    await scanner.turnOnTorch();
    see

    turnOffTorchgetCapabilities

    Returns Promise<void>

updateVideoSettings

  • Video play settings.

    await scanner.updateVideoSettings({ video: {width: {ideal: 1280}, height: {ideal: 720}, facingMode: {ideal: 'environment'}} });

    Parameters

    • MediaStreamConstraints: any

    Returns Promise<ScannerPlayCallbackInfo | void>

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, coverage and single(experimental) to use preset settings for BarcodeScanner. We recommend using the speed-optimized single(experimental) preset if scanning only one barcode at a time. The single(experimental) is only available in BarcodeScanner. The default settings for BarcodeScanner is speed.

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

    RuntimeSettings

    Parameters

    Returns Promise<void>

Other Methods

getScanSettings

  • Get current scan settings of the BarcodeScanner object and saves it into a struct.

    let scanSettings = await scanner.getScanSettings();
    scanSettings.intervalTime = 50;
    scanSettings.duplicateForgetTime = 1000;
    await scanner.updateScanSettings(scanSettings);

    Returns Promise<ScanSettings>

updateScanSettings

  • Update ScanSettings by specify parameter values.

    let scanSettings = await scanner.getScanSettings();
    scanSettings.intervalTime = 50;
    scanSettings.duplicateForgetTime = 1000;
    await scanner.updateScanSettings(scanSettings);

    Parameters

    Returns Promise<void>

Static detectEnvironment

  • detectEnvironment(): Promise<any>

Generated using TypeDoc