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.
- C#
- VB.NET
public class BarcodeReader : Component, IExtenderProvider
Public Class BarcodeReader
Inherits Component
Implements 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
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);
BarcodeReader(container)
Initializes a new instance of the BarcodeReader class with a specified container.
| Name | Type | Description |
|---|---|---|
| container | IContainer | An 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:
- ArgumentNullException container is null.
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
Camera
Control: The Wisej Camera instance to attach to.
ScanMode
ScanMode: Returns or sets the mode in which the scanner should detect barcodes. (Default: Automatic)
Methods
CanExtend(extendee)
Returns whether this component can provide its extender properties to the specified object.
| Parameter | Type | Description |
|---|---|---|
| extendee | Object | The 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
DecodeBarcode(image)
Decodes a barcode from the given image.
| Parameter | Type | Description |
|---|---|---|
| image | Image | The 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;
}
}
OnAddReferences(list)
Ensures the Camera widget exists in the ComponentManager.
| Parameter | Type | Description |
|---|---|---|
| list | IList |
OnScanError(e)
Fires the ScanError event.
| Parameter | Type | Description |
|---|---|---|
| e | ScanEventArgs |
OnScanSuccess(e)
Fires the Scan event.
| Parameter | Type | Description |
|---|---|---|
| e | ScanEventArgs |
OnWebEvent(e)
Fires events from the client.
| Parameter | Type | Description |
|---|---|---|
| e | WisejEventArgs |
OnWebRender(config)
Provides the client widget's configuration.
| Parameter | Type | Description |
|---|---|---|
| config | Object | The configuration. |
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();
}
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
ScanError
ScanEventHandler Fired when no barcode is detected in Manual mode.
ScanSuccess
ScanEventHandler Fired when the user scans a barcode.
Implements
| Name | Description |
|---|---|
| IUserData | |
| IWisejComponent | |
| IWisejSerializable |