Click or drag to resize

Encode Barcode as Image

This sample encodes a text message as a two dimensional quick response barcode (QR-Code)) and saves it to an image file.

C#
using Opait.Barcoder.Api;

// Encodes the specified message as a QR-Code image.
static void EncodeBarcode(string message, string fileName)
{
    // Initialize the barcoder library with default options.
    var barcoder = new Barcoder();

    // Create a barcode encoder of the specified type and content.
    var encoder = barcoder.CreateEncoder(BarcodeType.QRCode, message);

    // Create a bitmap renderer for the generated barcode.
    var renderer = barcoder.CreateBitmapRenderer();

    // Render to a bitmap of 200x200 pixels.
    using (var bitmap = renderer.RenderBarcode(encoder, 200, 200))
    {
        // Save the rendered image.
        bitmap.Save(fileName);
    }
}