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 array using Convert.FromBase64String. 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 using creating a Web Scanner with IronBarcode!

Ready to Get Started?
Nuget Downloads 2,094,439 | Version: 2026.3 just released
Still Scrolling Icon

Still Scrolling?

Want proof fast? PM > Install-Package BarCode
run a sample watch your string become a barcode.