Skip to main content

BarcodeReader

Namespace: Wisej.Web.Ext.Barcode

Assembly: Wisej.Web.Ext.Barcode (4.1.0.0)

A component for extending the functionality of the Wisej Camera to include barcode detection.

public class BarcodeReader : Component, IExtenderProvider

Set the Camera property to a Wisej.Web.Ext.Camera.Camera control and handle the ScanSuccess event. The barcodes are detected in the browser, so the video frames are not sent to the server. Use ScanMode to choose whether the reader scans continuously, stops after the first barcode, or scans only when ScanImage is called.

Example:

The following example scans barcodes continuously with a camera and adds them to a list:

private BarcodeReader barcodeReader;

private void Page1_Load(object sender, EventArgs e)
{
this.barcodeReader = new BarcodeReader(this.components)
{
Camera = this.camera1,
ScanMode = ScanMode.Automatic
};

this.barcodeReader.ScanSuccess += barcodeReader_ScanSuccess;
}

private void barcodeReader_ScanSuccess(object sender, ScanEventArgs e)
{
this.listBoxCodes.Items.Add(e.Data);
}

Constructors​

Instance member BarcodeReader()​

Initializes a new instance of the BarcodeReader without a specified container.

Example:

var reader = new BarcodeReader();
reader.Camera = this.camera1;
reader.ScanSuccess += (s, e) => AlertBox.Show(e.Data);

Instance member BarcodeReader(container)​

Initializes a new instance of the BarcodeReader class with a specified container.

NameTypeDescription
containerIContainerAn IContainercontainer.

Adding the component to a container ensures that it's disposed together with the container, for example when the owning page or form is disposed.

Throws:

Example:

// "components" is the container created by the designer for the page or form.
var reader = new BarcodeReader(this.components);
reader.Camera = this.camera1;
reader.ScanMode = ScanMode.AutomaticOnce;

Properties​

Instance member Camera​

Control: The Wisej Camera instance to attach to.

Instance member ScanMode​

ScanMode: Returns or sets the mode in which the scanner should detect barcodes. (Default: Automatic)

Methods​

Instance member CanExtend(extendee)​

Returns whether this component can provide its extender properties to the specified object.

ParameterTypeDescription
extendeeObjectThe object to check.

Returns: Boolean. true if extendee is a Control; otherwise false.

This method is part of the IExtenderProvider implementation and is used by the designer.

Example:

var reader = new BarcodeReader();

Console.WriteLine(reader.CanExtend(this.camera1)); // True
Console.WriteLine(reader.CanExtend("text")); // False

Instance member DecodeBarcode(image)​

Decodes a barcode from the given image.

ParameterTypeDescription
imageImageThe image of the barcode.

Returns: String. The data encoded in the barcode, or an empty string if no barcode is found in the image.

Uses the ZXing.NET library to parse the image. The image is decoded on the server, so this method doesn't need the Camera.

Example:

The following example decodes a barcode from an image uploaded by the user:

private void upload1_Uploaded(object sender, UploadedEventArgs e)
{
using (var image = Image.FromStream(e.Files[0].InputStream))
{
var data = this.barcodeReader1.DecodeBarcode(image);

if (data == "")
this.textBoxCode.Text = "";
AlertBox.Show("No barcode found.");
else
this.textBoxCode.Text = data;
}
}

Protected member OnAddReferences(list)​

Ensures the Camera widget exists in the ComponentManager.

ParameterTypeDescription
listIList

Protected member OnScanError(e)​

Fires the ScanError event.

ParameterTypeDescription
eScanEventArgs

Protected member OnScanSuccess(e)​

Fires the Scan event.

ParameterTypeDescription
eScanEventArgs

Protected member OnWebEvent(e)​

Fires events from the client.

ParameterTypeDescription
eWisejEventArgs

Protected member OnWebRender(config)​

Provides the client widget's configuration.

ParameterTypeDescription
configObjectThe configuration.

Instance member ResetScanner()​

Resets the scanner in AutomaticOnce mode.

In AutomaticOnce mode the reader stops after the first barcode is detected. Call this method to start scanning for the next barcode. It has no effect in the other modes.

Example:

The following example scans one barcode at a time and restarts the scanner after the user confirms it:

private async void barcodeReader1_ScanSuccess(object sender, ScanEventArgs e)
{
var result = await MessageBox.ShowAsync($"Add item {e.Data}?", buttons: MessageBoxButtons.YesNo);
if (result == DialogResult.Yes)
this.listBoxItems.Items.Add(e.Data);

this.barcodeReader1.ResetScanner();
}

Instance member ScanImage()​

Scans the last frame from the attached Camera for a barcode.

Fires the ScanSuccess event when a barcode is detected, or the ScanError event when no barcode is found or the camera image isn't available. Use this method when ScanMode is set to Manual. The events are sent to the server only when a handler is attached to ScanSuccess.

Example:

The following example scans the camera image when the user clicks a button:

private void Page1_Load(object sender, EventArgs e)
{
this.barcodeReader1.ScanMode = ScanMode.Manual;
this.barcodeReader1.ScanSuccess += (s, args) => this.textBoxCode.Text = args.Data;
this.barcodeReader1.ScanError += (s, args) => AlertBox.Show("No barcode found. Try again.");
}

private void buttonScan_Click(object sender, EventArgs e)
{
this.barcodeReader1.ScanImage();
}

Events​

Instance member ScanError​

ScanEventHandler Fired when no barcode is detected in Manual mode.

Instance member ScanSuccess​

ScanEventHandler Fired when the user scans a barcode.

Implements​