Barcode

The Barcode extension component uses ZXing.Net to generate Barcodes on the server and render them on the client. Supports: UPC-A, EAN-8, EAN-13, Code 39, Code 128, ITF, Codabar, Plessey, MSI, QR Code, PDF-417, Aztec, Data Matrix.

Features

  • Generate Barcodes

  • Read Barcodes using the device's camera.

How to Use

The Barcode extension can be added to a Wisej.NET project using NuGet Package Manager.

Barcode

This class can be used to display values as Barcodes. Use the Text property to set the value and the BarcodeType property to select the type of Barcode. The BarcodeType determines the list of allowed values/formats. Use the ShowLabel property to optionally show the value as a label text (if supported by the BarcodeType).

BarcodeReader

The Wisej.Web.Ext.Barcode extension also includes the ability to read and parse barcodes using a given System.Drawing.Image or by attaching to a Wisej.Web.Ext.Camera instance to detect barcodes in real-time on the client.

Using an Image

Using the BarcodeReader to parse images on the server is easy. It utilizes ZXing.Net to parse the data from the image.

The following code snippet shows how to parse the barcode data and display it in an AlertBox.

private void button1_Click(object sender, EventArgs e)
{
    var myBarcodeImage = Image.FromFile("path/to/image.png");

    var reader = new BarcodeReader();
    var resultString = reader.DecodeBarcode(myBarcodeImage);

    AlertBox.Show(resultString);
}

Using a Camera Instance

When attaching to a Camera instance, the processing of images takes place on the client using zxing-js.

Three scan modes are available:

  • Automatic: Continuously scans the environment for barcodes.

  • AutomaticOnce: Stops scanning after one successful barcode detection.

  • Manual: Requires the user to call the ScanImage method.

You must attach a handler for ScanError and ScanSuccess to receive the scanning data from the client widget.

The following example shows how to attach and continuously scan images from the camera instance.

private void button1_Click(object sender, EventArgs e)
{
    var reader = new BarcodeReader();
    // attach the reader to the camera.
    reader.Camera = this.camera1;

    // continuously have the camera watching for barcodes.
    reader.ScanMode = ScanMode.Automatic;

    // handle successful scans.
    reader.ScanSuccess += Reader_ScanSuccess;

    // handle failed scans.
    reader.ScanError += Reader_ScanError;
}

private void Reader_ScanError(object sender, ScanEventArgs e)
{
    // handle failure.
    AlertBox.Show(e.Data);
}

private void Reader_ScanSuccess(object sender, ScanEventArgs e)
{
    // handle success.
    AlertBox.Show(e.Data);
}

Last updated