AztecQRGenerator.Core 1.3.0

dotnet add package AztecQRGenerator.Core --version 1.3.0
                    
NuGet\Install-Package AztecQRGenerator.Core -Version 1.3.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="AztecQRGenerator.Core" Version="1.3.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AztecQRGenerator.Core" Version="1.3.0" />
                    
Directory.Packages.props
<PackageReference Include="AztecQRGenerator.Core" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add AztecQRGenerator.Core --version 1.3.0
                    
#r "nuget: AztecQRGenerator.Core, 1.3.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.
#:package AztecQRGenerator.Core@1.3.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=AztecQRGenerator.Core&version=1.3.0
                    
Install as a Cake Addin
#tool nuget:?package=AztecQRGenerator.Core&version=1.3.0
                    
Install as a Cake Tool

AztecQRGenerator.Core

A powerful .NET Framework library for generating QR codes and Aztec codes from Base64-encoded data with support for multiple image formats.

Features

  • ? QR Code Generation - Standards-compliant QR codes
  • ? Aztec Code Generation - Compact 2D barcodes
  • ? Multiple Formats - PNG, JPEG, and BMP output
  • ? Flexible API - Return as Bitmap or save to file
  • ? Customizable - Configurable size and error correction
  • ? ISO-8859-1 Encoding - Latin-1 character support
  • ? Production Ready - Comprehensive error handling and logging

Installation

Install via NuGet Package Manager:

Install-Package AztecQRGenerator.Core

Or via .NET CLI:

dotnet add package AztecQRGenerator.Core

Quick Start

Generate QR Code as Bitmap

using AztecQR;
using System.Drawing;

var generator = new QRGenerator();

// Generate QR code in memory
Bitmap qrCode = generator.GenerateQRCodeAsBitmap(
    qrstring: "SGVsbG8gV29ybGQh",  // Base64 encoded data
    lCorrection: 2,                 // Error correction level (0-10)
    lPixelDensity: 300              // Size in pixels
);

// Use the bitmap (e.g., display in UI)
pictureBox.Image = qrCode;

// Remember to dispose when done
qrCode.Dispose();

Save QR Code to File

using AztecQR;
using System.Drawing.Imaging;

var generator = new QRGenerator();

// Save as PNG (recommended)
bool success = generator.GenerateQRCodeToFile(
    qrstring: "SGVsbG8gV29ybGQh",
    lCorrection: 2,
    lPixelDensity: 300,
    filePath: "qrcode.png",
    format: ImageFormat.Png
);

Generate Aztec Code

using AztecQR;
using System.Drawing;

var generator = new AztecGenerator();

// Generate Aztec code in memory
Bitmap aztecCode = generator.GenerateAztecCodeAsBitmap(
    aztecstring: "SGVsbG8gV29ybGQh",
    lCorrection: 2,
    lPixelDensity: 300
);

// Or save directly to file
generator.GenerateAztecCodeToFile(
    aztecstring: "SGVsbG8gV29ybGQh",
    lCorrection: 2,
    lPixelDensity: 300,
    filePath: "aztec.png",
    format: ImageFormat.Png
);

Supported Image Formats

Format Extension Quality File Size Recommended For
PNG .png Excellent (lossless) Moderate ? QR/Aztec codes (default)
JPEG .jpg, .jpeg Fair (lossy) Small ?? Not recommended for barcodes
BMP .bmp Excellent (lossless) Very Large ?? Legacy systems only

Recommendation: Use PNG format for barcodes. JPEG compression can cause artifacts that reduce scanability.

API Reference

QRGenerator Class

Methods

GenerateQRCodeAsBitmap(string qrstring, int lCorrection, int lPixelDensity)

  • Returns: Bitmap - QR code as a bitmap object
  • Use for: In-memory generation, UI display

GenerateQRCodeToFile(string qrstring, int lCorrection, int lPixelDensity, string filePath, ImageFormat format)

  • Returns: bool - True if successful
  • Use for: Saving directly to file with format selection

AztecGenerator Class

Methods

GenerateAztecCodeAsBitmap(string aztecstring, int lCorrection, int lPixelDensity)

  • Returns: Bitmap - Aztec code as a bitmap object
  • Use for: In-memory generation, UI display

GenerateAztecCodeToFile(string aztecstring, int lCorrection, int lPixelDensity, string filePath, ImageFormat format)

  • Returns: bool - True if successful
  • Use for: Saving directly to file with format selection

Parameters

  • qrstring / aztecstring: Base64 encoded string to encode in the barcode
  • lCorrection: Error correction level (0-10, default: 2) - Higher = more redundancy
  • lPixelDensity: Size in pixels (must be > 0, typical: 200-500)
  • filePath: Output file path (including extension)
  • format: ImageFormat.Png, ImageFormat.Jpeg, or ImageFormat.Bmp

Advanced Usage

Multiple Formats from One Generation

using (Bitmap qr = generator.GenerateQRCodeAsBitmap("SGVsbG8=", 2, 300))
{
    qr.Save("output.png", ImageFormat.Png);
    qr.Save("output.jpg", ImageFormat.Jpeg);
    qr.Save("output.bmp", ImageFormat.Bmp);
}

Error Handling

try
{
    var generator = new QRGenerator();
    bool success = generator.GenerateQRCodeToFile(
        "SGVsbG8gV29ybGQh", 2, 300, "output.png", ImageFormat.Png
    );
    
    if (success)
    {
        Console.WriteLine("QR code generated successfully!");
    }
}
catch (ArgumentException ex)
{
    Console.WriteLine($"Invalid input: {ex.Message}");
}
catch (InvalidOperationException ex)
{
    Console.WriteLine($"Generation failed: {ex.Message}");
}
catch (IOException ex)
{
    Console.WriteLine($"File error: {ex.Message}");
}

Logging

The library includes built-in logging to help with debugging:

// Set minimum log level (default: Info)
Logger.Instance.SetMinimumLogLevel(LogLevel.Debug);

// Logs are written to: {AppDirectory}/Logs/AztecQR_yyyyMMdd.log

Requirements

  • .NET Framework 4.7.2 or higher
  • System.Drawing (included)
  • ZXing.Net 0.16.9 (automatically installed)

Performance

  • Generation Speed: ~10-50ms per barcode (depends on size)
  • Memory Usage: ~1-5 MB per generation (proportional to pixel density)
  • Thread Safety: Logger is thread-safe, generators are not (create per thread)

Best Practices

  1. ? Use PNG format for all production barcodes
  2. ? Dispose bitmaps properly to prevent memory leaks
  3. ? Validate Base64 input before generation
  4. ? Test scanability with real barcode scanners
  5. ?? Avoid JPEG unless file size is absolutely critical
  6. ?? Use appropriate sizes (300-500px recommended for printing)

Examples

Windows Forms Application

private void GenerateQRCode()
{
    var generator = new QRGenerator();
    string base64Data = Convert.ToBase64String(
        Encoding.UTF8.GetBytes(textBox.Text)
    );
    
    Bitmap qrCode = generator.GenerateQRCodeAsBitmap(base64Data, 2, 300);
    pictureBox.Image = qrCode;
}

ASP.NET Web Application

public ActionResult GenerateQRCode(string data)
{
    var generator = new QRGenerator();
    using (Bitmap qrCode = generator.GenerateQRCodeAsBitmap(data, 2, 300))
    {
        using (MemoryStream ms = new MemoryStream())
        {
            qrCode.Save(ms, ImageFormat.Png);
            return File(ms.ToArray(), "image/png");
        }
    }
}

Batch Processing

var generator = new QRGenerator();
var dataList = new List<string> { "data1", "data2", "data3" };

foreach (var data in dataList)
{
    string fileName = $"qr_{DateTime.Now.Ticks}.png";
    generator.GenerateQRCodeToFile(data, 2, 300, fileName, ImageFormat.Png);
}

Troubleshooting

Common Issues

Invalid Base64 String

  • Ensure your input is properly Base64-encoded
  • Use Convert.ToBase64String() to encode data

File Access Denied

  • Check write permissions in the output directory
  • Ensure the path is valid

Low Scan Success Rate

  • Use PNG format instead of JPEG
  • Increase pixel density (try 400-500)
  • Increase error correction level
  • Test with multiple scanner apps

License

MIT License - See LICENSE for details

Author

Johan Henningsson


Version 1.2.0 - Multiple format support, in-memory generation, comprehensive logging

Product Compatible and additional computed target framework versions.
.NET Framework net472 is compatible.  net48 was computed.  net481 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.3.0 116 1/10/2026
1.2.3 128 1/1/2026
1.2.2 97 12/31/2025
1.2.1 96 12/31/2025

Version 1.3.0:
- Fixed: Removed duplicate file save operations in GenerateQRBitmap() and GenerateAztecBitmap()
- Now generates only one file instead of two identical files

Version 1.2.1:
- Removed unused lTaNmbrqr parameter from GenerateAztecBitmap() and GenerateQRBitmap() methods
- Code cleanup and consistency improvements

Version 1.2.0:
- Added support for multiple image formats (PNG, JPEG, BMP)
- Added GenerateQRCodeToFile() and GenerateAztecCodeToFile() with format selection
- Added GenerateQRCodeAsBitmap() and GenerateAztecCodeAsBitmap() for in-memory generation
- Comprehensive logging support
- Full backward compatibility maintained