Skip to content

API Reference

Chung-Sheng Wu edited this page Jun 6, 2020 · 7 revisions

Public functions

scanImageData

async (image: ImageData, scanner?: ImageScanner | undefined) => Array<Symbol>

Arguments
  • image: ImageData object to be scanned.
  • scanner: ImageScanner for scanning, the default scanner is used if omit.
Return

Array of Symbol

scanRGBABuffer

async (buffer: ArrayBuffer, width: number, height: number, scanner?: ImageScanner | undefined) => Array<Symbol>

Arguments
  • buffer: ArrayBuffer in RGBA format (32 bits for each pixel).
  • width: Image width.
  • height: Image height.
  • scanner: ImageScanner for scanning, the default scanner is used if omit.
Return

Array of Symbol

scanGrayBuffer

async (buffer: ArrayBuffer, width: number, height: number, scanner?: ImageScanner | undefined) => Array<Symbol>

Arguments
  • buffer: ArrayBuffer in Gray(Y800) format (8 bits bits for each pixel).
  • width: Image width.
  • height: Image height.
  • scanner: ImageScanner for scanning, the default scanner is used if omit.
Return

Array of Symbol

getDefaultScanner

async () => ImageScanner

Return

Return the default global ImageScanner used by public functions.

Example

const scanner = await getDefaultScanner();
scanner.setConfig(...);

const image = ...;
const res = scanImageData(image, scanner);

ImageScanner

Mapping to ZBar::ImageScanner, see here.

create

static async () => ImageScanner

Return

New ImageScanner object.

destroy

() => void

Destroy this ImageScanner and release memory.

setConfig

(sym: ZBarSymbolType, conf: ZBarConfigType, value: number) => number

Arguments
  • sym: Symbol type which configuration apply to. See here.
  • conf: Configuration type to update. See here.
  • value
Return

0 for success, non-0 for failure. See here

enableCache

(enable?: boolean) => void

See here.

recycleImage

(image: Image): void

See here

scan

(image: Image) => number

Arguments
Return

>0 if symbols were successfully decoded from the image, 0 if no symbols were found or -1 if an error occurs

getResults

() => Array<Symbol>

Return last scanned results of the ImageScanner. See Symbol.

Example

const scanner = await ImageScanner.create();
scanner.setConfig(...);

const image = ...;
scanner.scan(image);
const res = scanner.getResults();
scanner.destroy();

Image

createFromGrayBuffer

static async (width: number, height: number, dataBuf: ArrayBuffer, sequenceNum?: number) => Image

Arguments
  • width
  • height
  • dataBuf
  • sequenceNum: see here Image to scan.
Return

Image object.

createFromRGBABuffer

static async (width: number, height: number, dataBuf: ArrayBuffer, sequenceNum?: number) => Image

Arguments
  • width
  • height
  • dataBuf
  • sequenceNum: see here Image to scan.
Return

Image object.

destroy

() => void

Destroy this Image and release memory.

Arguments
  • width
  • height
  • dataBuf
  • sequenceNum: see here Image to scan.
Return

Image object.

getSymbols

() => Array<Symbol>

Return scanned results of the Image. See Symbol.

Example

const scanner = ...;
const data = ...;
const image = await Image.createFromRGBABuffer(width, height, data);
scanner.scan(image);
const res = image.getSymbols();
image.destroy();

Symbol

  • type: ZBarSymbolType, type of the symbol.
  • typeName: string, type of the symbol in string.
  • data: Int8Array, raw data of scanned symbol.
  • points: Array<{x: number, y: number} as Point>, points of the symbol.
  • time: number.
  • cacheCount: number, see here.
  • quality: number, see here.

decode

(encoding?: string) => string

Decode the data with encoding, see TextDecoder.

Example

const scanner = ...;
const res = scanner.getResults();
for (let sym of res) {
	console.log(sym.typeName);
	console.log(sym.decode());
}