Skip to content

kattunga/BlazorZXingJs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

88 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

build Actions Status

Nuget

BlazorZXingJs

Barcode/QRCode Reader and QRCode writer components.

This is a Blazor wrapper arround zxing-js library.

Supported Formats

It supports variety of barcode and 2d code types. For more information: zxing-js supported types

Prerequisites

NET 5.0 or newer

Installation

1. NuGet packages

Install-Package BlazorZXingJs

or

dotnet add package BlazorZXingJs

2. Refence to ZXing-JS library

This component requires the umd version of zxing-js library.

For blazor wasm, in wwwroot\index.html

...
<body>
    ...
    <script src="_framework/blazor.webassembly.js"></script>

    <!-- if you need to scan as soon as the app start, add this before _framework/blazor.webassembly.js -->
    <script src="_content/BlazorZXingJs/zxingjs-0.18.2/umd/index.min.js"></script>
</body>

For blazor server (, in Pages/_Host.cshtml

...
<body>
    <!-- ServerPrerrendered mode is not supported, so change it to render-mode=Server-->
    <component type="typeof(App)" render-mode="Server" />
    ...
    <script src="_framework/blazor.server.js"></script>

    <!-- if you need to scan as soon as the app start, add this before _framework/blazor.server.js -->
    <script src="_content/BlazorZXingJs/zxingjs-0.18.2/umd/index.min.js"></script>
</body>

Examples

Basic Read code with autodetect

@page "/"

@using BlazorZXingJs

<MultiFormatReader
    VideoWidth="300"
    VideoHeight="200"
    OnBarcodeRead="BarcodeRead">

    <VideoForbidden>
        <h4>no permission for videodevice</h4>
    </VideoForbidden>

    <NoVideoDevices>
        <h4>no devices available</h4>
    </NoVideoDevices>
</MultiFormatReader>

<h4>@LocalBarcodeText</h4>

@code {
    private string LocalBarcodeText;

    private void BarcodeRead(string code)
    {
        LocalBarcodeText = code;
    }
}

Advanced Read code

@page "/"

@using BlazorZXingJs

<MultiFormatReader
    Format="@_formatList"
    VideoWidth="300"
    VideoHeigth="200"
    VideoProperties="@_videoProperties"
    OnStartVideo="StartVideo"
    OnBarcodeRead="BarcodeRead">
</MultiFormatReader>

<h4>@LocalBarcodeText</h4>

@code {
    private string LocalBarcodeText;

    private BarcodeFormat[] _formatList  = new BarcodeFormat[] { BarcodeFormat.EAN_8, BarcodeFormat.EAN_13 };

    private MediaTrackConstraints _videoProperties = new MediaTrackConstraints() { Torch = true} ;

    private string _domException;

    private List<MediaDeviceInfo> _devices;
        
    private string _inputDevice;

    private void StartVideo(MultiFormatReaderStartEventArgs args)
    {
        _domException = args.DOMExceptionName;
        _devices = args.DeviceList;

        if (args.DeviceId != null)
        {
            _inputDevice = args.DeviceId;
        }
    }

    private void BarcodeRead(string code)
    {
        LocalBarcodeText = code;
    } 
}

Write QRCode

@page "/"

@using BlazorZXingJs

<QRCodeWriter Text="@LocalBarcodeText" Width="200" Heigth="200"></QRCodeWriter>

@code {
    private string LocalBarcodeText = "this is a message";

}

### Credits

This project is based on the original work of [sabitertan](https://github.com/sabitertan/BlazorBarcodeScanner)

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published