Skip to content

barcode-bakery/example-dotnet-qrcode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

This example repository will allow you to generate QRCode barcodes. You can find more information on our Barcode Bakery website.

This is based on the barcode QRCode library.

The library is not free, you must purchase a license in order to obtain it.

Installation

There are two ways to install our library:

  • With the command line, get the file from GitHub, run the following command.
PM> dotnet add PROJECT package BarcodeBakery.BarcodeQRCode --version 3.0.1

Requirements

  • .NET Standard 2.0
  • .NET Core 2.0+
  • .NET Framework 4.6.1+

Example usages

For a full example of how to use each symbology type, visit our API page.

Saving a QRCode to a MemoryStream

public static async Task CreateAsync(string filePath, string? text = null)
{
    // Loading Font
    var font = new BCGFont("Arial", 18);

    // Don't forget to sanitize user inputs
    text = text?.Length > 0 ? text : "QRCode";

    // Label, this part is optional
    var label = new BCGLabel();
    label.SetFont(font);
    label.SetPosition(BCGLabel.Position.Bottom);
    label.SetAlignment(BCGLabel.Alignment.Center);
    label.SetText(text);

    // The arguments are R, G, B for color.
    var colorBlack = new BCGColor(0, 0, 0);
    var colorWhite = new BCGColor(255, 255, 255);

    Exception? drawException = null;
    BCGBarcode? barcode = null;
    try
    {
        var code = new BCGqrcode();
        code.SetScale(3);
        code.SetSize(BCGqrcode.Size.Full);
        code.SetErrorLevel('M');
        code.SetMirror(false);
        code.SetQuietZone(true);
        code.SetForegroundColor(colorBlack); // Color of bars
        code.SetBackgroundColor(colorWhite); // Color of spaces

        code.AddLabel(label);

        code.Parse(text);
        barcode = code;
    }
    catch (Exception exception)
    {
        drawException = exception;
    }

    var drawing = new BCGDrawing(barcode, colorWhite);
    if (drawException != null)
    {
        drawing.DrawException(drawException);
    }

    // Saves the barcode into a MemoryStream
    var memoryStream = new System.IO.MemoryStream();
    await drawing.FinishAsync(BCGDrawing.ImageFormat.Png, memoryStream);
}

Saving the image to a file

Replace the last line of the previous code with the following:

// Saves the barcode into a file.
await drawing.FinishAsync(BCGDrawing.ImageFormat.Png, filePath);

This will generate the following:

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages