Skip to content
Open source · MIT · net10.0 / net11.0

Barcode scanning for Blazor,
decoded in C#.

QR Code, Micro QR, Data Matrix, PDF417, Aztec, MaxiCode, Code 128, Code 39, Code 93, Codabar, EAN-13, EAN-8, UPC-A, UPC-E, ITF and the GS1 DataBar family - from the camera or from still images. No barcode SDK and no JavaScript scanner library: the browser opens the camera and copies pixels, and everything after that is managed code you can step into.

dotnet add package Bit.BbScanner
Checkout.razor
<BbScanner Formats="BbBarcodeFormat.QrCode | BbBarcodeFormat.Ean13"
           Region="BbScanRegion.CenteredSquare(0.7)"
           OnScan="HandleScan" />

private void HandleScan(BbBarcodeResult result)
    => Console.WriteLine($"{result.Format}: {result.Text}");

Live · in this tab

The same decoder a camera frame goes through, on the symbol beside this text.

Decoding in C#no barcode SDK, no JavaScript scanner library
One copy per framea [JSImport] memory view, no JSON or base64
Nineteen symbologiesread to specification, check digits verified
Runs anywhere .NET runsBbBarcodeDecoder needs no browser

Capabilities

A scanner component, and the decoder behind it

<BbScanner> owns the camera, the frame loop, the overlays and the controls; BbBarcodeDecoder turns pixels into a strongly typed BbBarcodeResult - with the corner points, the raw bytes and the symbol's metadata - wherever .NET runs.

Every parameter, live

Formats, frame rate, processing size, region, duplicate suppression and the advanced BbScannerOptions - all applied to the running camera without dropping it.

Live playground →

Camera, torch and zoom

Device selection, front and rear cameras, torch and zoom where the hardware offers them - and never a control the hardware will refuse.

Camera control →

Aim with a region

A normalized BbScanRegion crops the frame before any pixel is touched, so every later stage gets cheaper in proportion to the area removed.

Scan region →

Photos and buffers

A built-in file picker and drop target for still images, ScanImageAsync for an upload the application already holds, and DecodeImage for raw pixels - tuned for one exhaustive attempt rather than fifteen a second, and never asking for the camera.

Image scanning →

Built for real workflows

Read one code and stop, pause for "scan another", count each value once for a stocktake, ignore every code but the one you expect, read a whole sheet of labels at once, and beep or vibrate on a scan.

Lifecycle & duplicates →

Measured, not guessed

Per-stage timings for every frame, and a decoder benchmark that runs in your browser on your device - with no garbage allocated per frame.

Performance →

Yours to restyle and translate

Every colour, radius and dimension is a CSS custom property, the reticle and the messages are render fragments, and every text it shows or announces can be translated - with right-to-left, screen readers, reduced motion and forced colours built in.

Customisation →

Failures you can act on

Permission refused, no camera, camera in use, no HTTPS, an image that is not one: every failure arrives as a classified BbScannerException, and the permission can be checked before the browser ever asks.

Errors & permissions →

In practice

See it in code

01

One package, one namespace

No services to register, no script tag and no stylesheet link: the package's initializer adds the stylesheet and the component imports its own module. Put it on any interactive page - WebAssembly, Server, Auto or Hybrid.

Getting started →
dotnet add package Bit.BbScanner

@* _Imports.razor *@
@using Bit.BbScanner

@* Scan.razor *@
<BbScanner OnScan="r => _last = r" />
02

Ask for less, get it faster

Narrow Formats to the symbologies you need - an unused one costs nothing because its decoder is never created - and aim the decoder at the part of the frame that matters.

Live playground →
<BbScanner Formats="BbBarcodeFormat.Ean13"
           Region="BbScanRegion.CenteredSquare(0.6)"
           OnScan="AddToBasket" />
03

Decode without a camera

The pipeline has no dependency on Blazor, JavaScript or a camera: a server decoding uploads, a worker reading a folder of images, or a unit test uses the same decoder.

API reference →
using var decoder = new BbBarcodeDecoder(BbScannerOptions.ForStillImages());

var result = decoder.Decode(rgbaPixels, width, height, BbPixelFormat.Rgba32);
if (result is not null)
    Console.WriteLine($"{result.Format}: {result.Text}");

// result.Corners, result.RawBytes, result.Metadata …

Comparison

Why not wrap a JavaScript scanner?

Wrapping a JavaScript barcode library puts the part that matters - the decoding - on the far side of interop, in code your .NET tests, debugger and server cannot reach. BbScanner keeps only the camera in the browser.

ConcernJavaScript scanner behind interopBbScanner
Where the decoding runsJavaScript, outside the .NET debuggerC#, in managed code you can step into
What crosses interopResults marshalled back as JSONOne memory-view copy of each frame into a reused buffer on WebAssembly; the scan region's luminance, in 30 KB slices, under Server and Hybrid
DependenciesA script library to ship and keep up to dateNone beyond Microsoft.AspNetCore.Components.Web
The resultWhatever shape the library returnsBbBarcodeResult: text, raw bytes, corners, metadata
Without a browserA second decoder for the serverThe same BbBarcodeDecoder, anywhere .NET runs

Where to start

Choose your path

New to BbScanner?

Install, add the namespace, drop the component on a page - scanning in five minutes.

Getting started →

No barcode to hand?

Every symbology is drawn on the samples page: open it on a second screen and scan it with the playground.

Sample barcodes →

Building with an AI agent?

This site is an MCP server: point your agent at /mcp and it reads the shipped library instead of guessing.

Try the MCP server →

Questions

Frequently asked

Which render modes can open the camera?

All the interactive ones, on .NET 10 and 11: a standalone Blazor WebAssembly app, Blazor Server, the InteractiveServer, InteractiveWebAssembly and InteractiveAuto pages of a Blazor Web App, and a Blazor Hybrid app's BlazorWebView in MAUI, WPF or Windows Forms. On WebAssembly the frames are decoded in the browser; under Server the page sends the scan region's luminance to the server; in a MAUI app Bit.BbScanner.Maui opens the device's own camera and its frames go straight to the decoder in the app.

Why does the camera not start on my test server?

Browsers only expose the camera in a secure context - a page served over HTTPS, or from localhost. Anywhere else the component reports NotSupported straight away, with a message that says so, rather than waiting on a prompt that will never appear. The render mode makes no difference here; in a Blazor Hybrid app the platform has to allow the camera as well, and asks the user itself.

How does it avoid misreads?

Misreading is treated as worse than missing: check digits and guard patterns are verified, a Reed-Solomon correction is only accepted when the corrected block re-verifies, and ITF, Codabar, UPC-E, the GS1 DataBar family and unchecked Code 39 results must repeat on a second scan line before they are reported. Narrowing Formats to what you expect, and ItfLengths to the lengths you use, closes the rest of the gap.

Does it read PDF417?

Yes - the kind on driving licences, boarding passes and shipping labels. The library ships the specification's symbol character table, finds a symbol at any rotation before reading it row by row, and repairs damaged rows with the symbol's own error correction. Compact (truncated) PDF417, with its right row indicator dropped, reads too; MicroPDF417, a different symbology, is not read.

Does it read Aztec?

Yes - the code on boarding passes and rail and transit tickets, compact and full range, at any rotation and seen at an angle. Its bullseye is found wherever it is in the frame, and a large symbol is fitted through its own reference grid. Mirrored symbols read too, and an Aztec Rune reads as its number.

Does it read MaxiCode and Micro QR?

Yes. MaxiCode, the hexagonal code with a bullseye on parcels, is found by its rings at any angle and seen at a slant, and a carrier's structured message - postal code, country and class of service - comes back as the carrier writes it. Micro QR, the one-finder QR for small parts, reads in all four sizes and is only looked for when no QR code was, so it costs QR scanning nothing.

Does it read GS1 DataBar?

Yes, the whole family. Omnidirectional, Truncated and their two-row Stacked forms - the small barcode on loose produce - and DataBar Limited, on packs too small for anything else, come back as the GS1 element string, 01 and fourteen digits. DataBar Expanded and Expanded Stacked, on weighed fresh food and coupons, come back as whatever element string they carry - a GTIN with its weight, price, batch or best-before date - with a group separator after each variable length element. A symbol too short, or turned too far, for one scan line to cross whole is pieced together from several. The linear part of a GS1 Composite symbol is not read, because the two-dimensional part that holds the rest of its data is not.

Point it at a barcode

One package, one namespace, one component - and the camera hands its pixels to C#.

dotnet add package Bit.BbScanner
An unhandled error has occurred. Reload 🗙