Get Barcode Type and Encoded Data

Decode Barcode Type and Data

To retrieve the data encoded in a barcode and determine its type, the class BarCodeResult provides the key fields:

  • CodeText – the decoded data from the barcode.
  • CodeType – the type of barcode.

The following code sample shows how to extract the data and barcode type from a sample barcode image (in this case, a QR Code).

How to get BarCodeInstance

// Create a QR barcode
var gen = new BarCodeInstance.BarcodeGenerator("QR", "Åspóse.Barcóde©");
gen.Parameters.Barcode.XDimension = "4px";
document.getElementById("img").src = gen.GenerateBarCodeImage(); // Display QR code image

// Recognize the QR barcode from the image
var reader = new BarCodeInstance.BarCodeReader(gen.GenerateBarCodeImage(), "QR");
reader.ReadBarCodes();
for (var i = 0; i < reader.FoundCount; i++) {
    const result = reader.FoundBarCodes(i);
    console.log(`CodeText: ${result.CodeText}`);
    console.log(`CodeType: ${result.CodeType}`);
}

gen.delete();
reader.delete();