RazorBarcodeLibrary 1.0.0

dotnet add package RazorBarcodeLibrary --version 1.0.0
NuGet\Install-Package RazorBarcodeLibrary -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="RazorBarcodeLibrary" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add RazorBarcodeLibrary --version 1.0.0
#r "nuget: RazorBarcodeLibrary, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install RazorBarcodeLibrary as a Cake Addin
#addin nuget:?package=RazorBarcodeLibrary&version=1.0.0

// Install RazorBarcodeLibrary as a Cake Tool
#tool nuget:?package=RazorBarcodeLibrary&version=1.0.0

Razor Barcode Library

A Razor Class Library, equipped with the Dynamsoft JavaScript Barcode SDK, enables the creation of web-based barcode reader and scanner applications entirely in C#.

Online Demo

https://yushulx.me/Razor-Barcode-Library/

Demo Video

https://github.com/yushulx/Razor-Barcode-Library/assets/2202306/ac3c333f-7895-420a-94ee-6debe805a8b7

Prerequisites

Quick Usage

  • Import and initialize the Razor Barcode Library.

    @using RazorBarcodeLibrary
    
    protected override async Task OnInitializedAsync()
    {
        barcodeJsInterop = new BarcodeJsInterop(JSRuntime);
        await barcodeJsInterop.LoadJS();
    }
    
  • Set the license key and load the wasm module.

    await barcodeJsInterop.SetLicense('LICENSE-KEY');
    await barcodeJsInterop.LoadWasm();
    
  • Create a barcode reader instance.

    BarcodeReader reader = await barcodeJsInterop.CreateBarcodeReader();
    
  • Read barcodes from a base64 image source.

    List<BarcodeResult> results = await reader.DecodeBase64(imageSrc);
    string text = "";
    foreach (BarcodeResult result in results)
    {
        text += "format: " + result.Format + ", ";
        text += "text: " + result.Text + "<br>";
    }
    
  • Create a barcode scanner instance and set the callback function.

    @implements BarcodeScanner.ICallback
    
    BarcodeReader reader = await barcodeJsInterop.CreateBarcodeScanner();
    await scanner.RegisterCallback(this);
    
    public async Task OnCallback(List<BarcodeResult> results) {}
    
  • Open the camera and start scanning.

    <div id="videoContainer"></div>
    
    await scanner.SetVideoElement("videoContainer");
    List<Camera> cameras = await scanner.GetCameras();
    await scanner.OpenCamera(cameras[0]);
    

API

Camera Class

Represents a camera device with its device ID and label.

BarcodeResult Class

Represents the result of a barcode scan, including the decoded text, format, and positional details.

BarcodeJsInterop Class

Provides JavaScript interop functionalities for barcode operations.

  • Task LoadJS(): Loads and initializes the JavaScript module.
  • Task SetLicense(string license): Sets the license key for the barcode functionality.
  • Task LoadWasm(): Loads the WebAssembly for barcode processing.
  • Task<BarcodeReader> CreateBarcodeReader(): Creates a new BarcodeReader instance.
  • Task<BarcodeScanner> CreateBarcodeScanner(): Creates a new BarcodeScanner instance.
  • Task DrawCanvas(string id, int sourceWidth, int sourceHeight, List<BarcodeResult> results): Draws the barcode results on a specified canvas.
  • Task ClearCanvas(string id): Clears the specified canvas element.

BarcodeReader Class

Provides functionalities to decode barcodes from various sources such as Base64 strings and canvas objects.

  • Task<List<BarcodeResult>> DecodeBase64(string base64): Asynchronously decodes a barcode from a Base64 encoded string.
  • Task<List<BarcodeResult>> DecodeCanvas(IJSObjectReference canvas): Asynchronously decodes a barcode from a canvas object.
  • Task<string> GetParameters(): Asynchronously retrieves the current parameters of the barcode reader.
  • Task<int> SetParameters(string parameters): Asynchronously sets the parameters for the barcode reader.

BarcodeScanner Class

Provides functionalities for barcode scanning using a camera.

  • Task SetVideoElement(string videoId): Sets a div element as the video container.
  • Task OpenCamera(Camera camera): Opens the camera for barcode scanning.
  • Task CloseCamera(): Closes the current camera.
  • Task<List<Camera>> GetCameras(): Gets a list of available cameras.
  • Task RegisterCallback(ICallback callback): Registers a callback for handling barcode scan results.

Example

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 597 11/17/2023
0.1.1 446 11/14/2023

- Added barcode scanner API.