Skip to content

Latest commit

 

History

History
101 lines (81 loc) · 2.95 KB

README.md

File metadata and controls

101 lines (81 loc) · 2.95 KB

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

This is based on the barcode MaxiCode 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.BarcodeMaxiCode --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 MaxiCode 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 : "MaxiCode";

    // 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 BCGmaxicode();
        code.SetScale(3);
        code.SetMode(4);
        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: