Image and file scanning
The same decoder reads a still image. Nothing about the pipeline changes; only the tuning
does, because a one-shot decode can afford to be exhaustive. None of it opens the camera, so
a page that only scans images (AutoStart="false", as here) never asks for camera
permission.
Pick or drop an image
The component ships a hidden file input and the plumbing to read it: the
Scan image button in its control bar, or Choose an image here, which
calls OpenFilePickerAsync. Dragging an image file onto the scanner does the
same. Results arrive through OnScan; "No barcode found" or a refused file is
shown as a notice on the scanner rather than raised as an error.
Blazor's InputFile
An image the application already holds - from InputFile, an upload, a
download - goes to ScanImageAsync, which decodes it in the browser like a
picked file, under the same size limit, and returns every symbol in it (up to
maxSymbols, 16 by default) instead of raising OnScan. A refused or
unreadable image throws an InvalidImage error, shown under the scanner. Under
Blazor Server the bytes travel to the browser to be decoded and come back as luminance, so an
upload crosses the network twice; with the built-in picker the browser decodes the file and
sends only the prepared luminance to the server.
Pixels the application has
These skip image files entirely: each renders symbols into a pixel buffer, as a canvas
or a generated image would give them, and hands it to the scanner with the scanner's
symbologies and options. DecodeImage returns the first symbol it finds;
DecodeAllInImage returns every one, here a QR Code and a Data Matrix side by
side.
Four ways in
| The image comes from | Call | Results | A refused image |
|---|---|---|---|
| The user, through the scanner | The Scan image button, dropping a file on the scanner, or OpenFilePickerAsync from your own button | Raised through OnScan, outlined and announced | Shown as a notice for a few seconds |
| An encoded file you hold | ScanImageAsync(stream) or ScanImageAsync(bytes, contentType) - PNG, JPEG, WebP, anything the browser decodes | Returned, no events | Throws BbScannerException, kind InvalidImage |
| Pixels you hold | DecodeImage for the first symbol, DecodeAllInImage for all of them, from RGBA, BGRA, RGB or gray pixels | Returned, no events | - |
| The running camera | ScanCurrentFrameAsync, the current frame at full resolution - see camera | Returned, no events | - |
Why still images differ
A camera gets another chance in fifty milliseconds, so a live frame should give up
early. A file gets one chance, so every still image - picked, dropped, scanned or captured - is
decoded with the trade-offs of BbScannerOptions.ForStillImages(): at least 60 scan
lines instead of 15, TryHarder for the exhaustive detector path and a sweep of linear
symbols round every ten degrees, AllowInverted for light-on-dark symbols, the whole
image rather than the Region, and no duplicate suppression. The scanner's
Formats and its other options still apply. The same preset serves the headless decoder:
var options = BbScannerOptions.ForStillImages(); options.Formats = BbBarcodeFormat.QrCode; using var decoder = new BbBarcodeDecoder(options); var result = decoder.Decode(pixels, width, height, BbPixelFormat.Rgba32);
Large photographs
A twelve megapixel photo carries no more barcode detail than a two megapixel one, so the component asks the browser to scale anything larger than 1600 pixels on its longest edge before it crosses into managed code. That alone is the difference between a snappy decode and a visible pause on a phone. A photo is turned upright by its EXIF orientation first, and a transparent image is read as if printed on white, which is what a code generator's PNG means.