This is wrapper around Html5Qrcode js library for scanning barcodes using camera
License
—
Deps
1
Install Size
—
Vulns
✓ 0
Published
Apr 12, 2024
$ dotnet add package Html5QrcodeBlazor.WrapperThis is blazor wrapper over html5-qrcode JS libarary. I was trying using other libararies allready ported to Blazor, but html5-qrcode is reading barcodes way better.
You can find nuget package here
builder.Services.AddScoped<Html5QrcodeReader>();<script src="/_content/Html5QrcodeBlazor.Wrapper/html5-qrcode.min.js"></script>@inject Html5QrcodeReader cameraBarcodeReaderOnBarcodeScan event:protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
cameraBarcodeReader.OnBarcodeScan += HandleBarcodeScanDebounced;
}
}
public async Task HandleBarcodeScan(string barcode)
{
foundBarcode = barcode.Trim();
}
At this point you have 2 options:
For Pro Mode check Index.razor.
For Easy Mode check EasyMode.razor.
Remember to implement @implements IAsyncDisposable:
public async ValueTask DisposeAsync()
{
cameraBarcodeReader.OnBarcodeScan -= HandleBarcodeScanDebounced;
await cameraBarcodeReader.Stop();
}
Explore Html5QrcodeBlazor.DemoWasm project for more details.