Giter Site home page Giter Site logo

baltermia / barcodereader-imagesharp Goto Github PK

View Code? Open in Web Editor NEW
8.0 2.0 4.0 87 KB

A barcode reader compatible with SixLabors.ImageSharp using ZXing. Trying to remove System.Drawing.Common dependencies.

License: MIT License

C# 100.00%
dotnet imagesharp zxing barcode

barcodereader-imagesharp's Introduction

BarcodeReader.ImageSharp

Nuget Downloads Build Status

A barcode reader compatible with SixLabors.ImageSharp using ZXing. Trying to remove System.Drawing.Common dependencies.

I created this library specifically to use with blazor but you can totally use this for other use cases!

Features

This is a basic facade-library for the ZXing.Bindings.ImageSharp.V2 library which uses SixLabors.ImageSharp.

Included Features are:

  • Barcode reading functionality that supports all ImageSharp image formats
  • Decode Barcodes synchronously and asynchronously
  • Get rich results from the decoding
  • Fired events for better support in decoding loops

.NET Support

The library supports a vast majority of up-to-date .NET versions:

  • .NET Standard 2.0+
  • .NET Framework 4.7.2+
  • .NET Core 3.1+
  • .NET 5+

Installation

There are two ways to add the BarcodeReader.ImageSharp library to your projects:

  1. Open the command line and go into the directoy where your .csproj file is located, then execute this command:
dotnet add package BarcodeReader.ImageSharp
  1. Or add it in the GUI of Visual Studio 20XX:
    Tools -> Nuget Package Manager -> Manage Nuget Packages for Solution...

Then add the following using to your C# files:

using BarcodeReader.ImageSharp;

And depending on your code, you probably need one or more of the following usings:

using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Formats.Png;

How to Use

In the following code we use one of ImageSharps pixelformats IPixel<Rgba32> which we will use to load PNG images from files.

string path = @"C:\images\qrcode.png";

// first we need to Load a image
Image<Rgba32> image = Image.Load<Rgba32>(path);

// then we create a new BarcodeReader object
BarcodeReader<Rgba32> reader = new BarcodeReader<Rgba32>(types: ZXing.BarcodeFormat.QR_CODE);

// then we can get a result by decoding
BarcodeResult<Rgba32> result = await reader.DecodeAsync(image);

// then we can print out the result
if (result.Status == Status.Found)
{
    Console.WriteLine(result.Value);
}
else if (result.Status == Status.NotFound)
{
    Console.WriteLine(result.Message);
}
else if (result.Status == Status.Error)
{
    Console.WriteLine("An error occured while decoding barcode");
}

If you're using the reader in a while loop, you can use the DetectedBarcode event to only recieve BarcodeResults with a Status.Found:

// add handler to event
reader.DetectedBarcode += Recieved_Handler;

// infite loop for demonstration purposes
while (true)
{
    // recieve image from any method (not defined here)
    Image<Rgba32> img = GetNewImage();
    
    // decode the image. DetectedBarcode events are fired when a barcode could be found
    await reader.DecodeAsync(img);
}

// handler which is called when a barcode could be detected by any Decode call
void Recieved_Handler(object sender, BarcodeEventArgs<Rgba32> e) { /* Do something with the result */ }

barcodereader-imagesharp's People

Contributors

baltermia avatar przemyslawklys avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

barcodereader-imagesharp's Issues

Having trouble reading Image<Rgba32>

This is not a bug, I might not use the library properly.

Like a lot of people, I had the bad surprise to see that System.drawing is not supported by .net6 (except if you are running on Windows server).
To keep the QrCode feature, I decided to go for ZXing and ImageSharp libraries and I tried to add barcodereader-imagesharp library.
I figure out how to create a QrCode but I have been struggling for a long time on the reading of the QrCode.

Starting from formFile which is a IFormFile

var image = Image.Load(formFile.OpenReadStream());
var barcodeReader = new BarcodeReader.ImageSharp.BarcodeReader(true, BarcodeFormat.QR_CODE);
var result = await barcodeReader.DecodeAsync(image);
var str = result.ToString();

Can you please highlight what is wrong in my code?
Would it be better to work byte array of the image?

Any help would be appreciated.
Thanks.
Sebastien

License MIT?

What's the license for this project? Can you clarify?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.