# Barcode

The Barcode extension component uses [ZXing.Net](https://github.com/micjahn/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.

![](/files/-MMNJWext98MQE8fRXEd)

{% embed url="<https://github.com/iceteagroup/wisej-extensions/tree/master/Wisej.Web.Ext.Barcode>" %}
Barcode Source Code
{% endembed %}

## 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.

{% embed url="<https://www.nuget.org/packages/Wisej-3-Barcode>" %}

### 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](/extensions/extensions/barcode/api/wisej.web.ext.barcode.barcode.md) extension also includes the ability to read and parse barcodes using a given [System.Drawing.Image](https://docs.microsoft.com/en-us/dotnet/api/system.drawing.image?view=dotnet-plat-ext-5.0) or by attaching to a [Wisej.Web.Ext.Camera](/extensions/extensions/camera.md) instance to detect barcodes in real-time on the client.

#### Using an Image

Using the [BarcodeReader ](/extensions/extensions/barcode/api/wisej.web.ext.barcode.barcodereader.md)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.

{% tabs %}
{% tab title="C#" %}

```csharp
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);
}
```

{% endtab %}

{% tab title="VB.NET" %}

```php
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
    Dim myBarcodeImage = Image.FromFile("path/to/image.png")
    Dim reader = New BarcodeReader()
    Dim resultString = reader.DecodeBarcode(myBarcodeImage)
    AlertBox.Show(resultString)
End Sub
```

{% endtab %}
{% endtabs %}

#### Using a Camera Instance

When attaching to a Camera instance, the processing of images takes place on the client using [zxing-js](https://github.com/zxing-js/library).

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 ](/extensions/extensions/barcode/api/wisej.web.ext.barcode.barcodereader.md#scanimage)method.

You must attach a handler for [ScanError ](/extensions/extensions/barcode/api/wisej.web.ext.barcode.barcodereader.md#scanerror)and [ScanSuccess ](/extensions/extensions/barcode/api/wisej.web.ext.barcode.barcodereader.md#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.

{% tabs %}
{% tab title="C#" %}

```csharp
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);
}
```

{% endtab %}

{% tab title="VB.NET" %}

```php
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)

        Dim reader = New BarcodeReader()
        // attach the reader to the camera.
        reader.Camera = Me.camera1

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

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

        // handle failed scans.
        reader.ScanError += AddressOf Reader_ScanError
End Sub

Private Sub Reader_ScanError(ByVal sender As Object, ByVal e As ScanEventArgs)
        AlertBox.Show(e.Data)
End Sub

Private Sub Reader_ScanSuccess(ByVal sender As Object, ByVal e As ScanEventArgs)
        AlertBox.Show(e.Data)
End Sub
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.wisej.com/extensions/extensions/barcode.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
