IRONSOFTWAREHOME
Barcode Web Scanner
using IronBarCode;

public string ReadBarCode(CamImage imageData)
{
        // Decode the base64 image data
        var splitObject = imageData.imageDataBase64.Split(',');
        byte[] imagebyteData = Convert.FromBase64String((splitObject.Length > 1) ? splitObject[1] : splitObject[0]);

        using (var ms = new MemoryStream(imagebyteData))
        {
            // Convert byte array to Image
            Image barcodeImage = Image.FromStream(ms);

            // Read barcode from Image
            var results = BarcodeReader.Read(barcodeImage);

	        // Read first value from barcode
            return $"{DateTime.Now}: Barcode is ({results[0].Value})";
        }

}
Imports IronBarCode

Public Function ReadBarCode(imageData As CamImage) As String
    ' Decode the base64 image data
    Dim splitObject = imageData.imageDataBase64.Split(","c)
    Dim imagebyteData As Byte() = Convert.FromBase64String(If(splitObject.Length > 1, splitObject(1), splitObject(0)))

    Using ms As New MemoryStream(imagebyteData)
        ' Convert byte array to Image
        Dim barcodeImage As Image = Image.FromStream(ms)

        ' Read barcode from Image
        Dim results = BarcodeReader.Read(barcodeImage)

        ' Read first value from barcode
        Return $"{DateTime.Now}: Barcode is ({results(0).Value})"
    End Using

End Function
NuGet Download
PM > Install-Package BarCode
Barcode Web Scanner

Barcode Web Scanner

Scanning barcodes from web sources often requires handling image data as text strings rather than physical files. The main advantage of this approach is that it allows your application to process images directly from user uploads or webcam feeds without first saving them to disk.

In this code example, we will demonstrate the main code snippet that showcases how to convert a Base64 string back into an image and scan it for data using IronBarcode when integrated with a web platform such as Blazor.

5-Step Guide to Setting up IronBarcode Web Scanner

  • byte[] imagebyteData = Convert.FromBase64String((splitObject.Length > 1) ? splitObject[1] : splitObject[0]);
  • using (var ms = new MemoryStream(imagebyteData))
  • Image barcodeImage = Image.FromStream(ms);
  • var results = BarcodeReader.Read(barcodeImage);
  • return $"{DateTime.Now}: Barcode is ({results[0].Value})";

Code Explanation

First, the input string, typically a Base64 string, is converted into a byte[] using Convert.FromBase64String and additional splitting logic using MemoryStream. Additionally, a check is performed to see if the string needs to be split. This handles cases where the input might contain headers, such as data URIs, ensuring only the actual image data is processed.

Next, these bytes are loaded into a MemoryStream. This acts as a temporary holder, allowing an Image object to be created directly from the stream using Image.FromStream. Once the image is loaded, it is passed to BarcodeReader.Read for scanning.

Finally, the reading result is returned along with a timestamp. The results array, which contains a list of BarcodeResults, is accessed to return the value of the first barcode via the Value property.

Learn more about creating a Web Scanner with IronBarcode!

Ready to Get Started?

Nuget Downloads 2,422,100Version:2026.9just released

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required