Aztec codes are widely used in mobile ticketing, transport, secure payments, and smart cards due to their robustness and quick readability. This article explains how to generate Aztec codes using Aspose.BarCode for .NET.

Introduction

Aztec codes are a type of 2D barcode that offer high data density and strong error correction capabilities. They are ideal for mobile ticketing, transport, secure payments, and smart cards due to their robustness and quick readability. This article will guide you through generating Aztec codes in .NET applications using Aspose.BarCode.

Prerequisites

Before starting, ensure that you have the following:

  • Visual Studio 2019 or later
  • .NET 6.0 or later (or .NET Framework 4.6.2+)
  • Aspose.BarCode for .NET installed via NuGet
  • Basic knowledge of C#

To install Aspose.BarCode, run the following command in the Package Manager Console:

PM> Install-Package Aspose.BarCode

Step-by-Step Implementation

Step 1: Install and Import Aspose.BarCode

Install the NuGet package and import the required namespaces:

using Aspose.BarCode.Generation;

Step 2: Create the Aztec Code Generator

Instantiate the generator for Aztec codes:

BarcodeGenerator generator = new BarcodeGenerator(EncodeTypes.Aztec, "TICKET2025-BOARDING");

Step 3: Customize Aztec Code Settings

Configure layers, ECC, and other options:

// Set number of layers (Auto or specific 1-32)
generator.Parameters.Barcode.Aztec.AztecLayers = AztecSymbolMode.Auto;
// Set error correction percent (default: 23%)
generator.Parameters.Barcode.Aztec.AztecErrorLevel = 33;
// Set module (pixel) size
generator.Parameters.Barcode.XDimension.Pixels = 6;
// Optional: Set foreground and background color
generator.Parameters.Barcode.BarColor = Color.Black;
generator.Parameters.Barcode.BackColor = Color.White;

Step 4: Generate and Save the Aztec Code

Export the code to PNG, JPEG, or any supported format:

generator.Save("aztec-code.png", BarCodeImageFormat.Png);

Complete Example

Here is a complete example demonstrating how to generate an Aztec code in C# using Aspose.BarCode:

using Aspose.BarCode.Generation;
using System.Drawing; // Required for Color

class Program
{
    static void Main()
    {
        // Create Aztec generator for a ticket
        BarcodeGenerator generator = new BarcodeGenerator(EncodeTypes.Aztec, "TICKET2025-BOARDING");
        generator.Parameters.Barcode.Aztec.AztecLayers = AztecSymbolMode.Auto;
        generator.Parameters.Barcode.Aztec.AztecErrorLevel = 33; // 33% error correction
        generator.Parameters.Barcode.XDimension.Pixels = 6;
        generator.Parameters.Barcode.BarColor = Color.Black;
        generator.Parameters.Barcode.BackColor = Color.White;
        generator.Save("aztec-code.png", BarCodeImageFormat.Png);
    }
}

Use Cases and Applications

  • Mobile and transport tickets: Subway, airline, or event entry
  • Payment tokens: Secure payment/transaction codes
  • Identity/Smart cards: Secure personal information encoding

Common Challenges and Solutions

Challenge 1: Aztec code not scanning? Solution: Increase error correction, verify contrast and size, test on intended devices.

Challenge 2: Need higher security? Solution: Use maximum ECC (up to 95%), keep code text short, avoid data redundancy.

Challenge 3: Data too long for one code? Solution: Split across multiple codes, or switch to PDF417 for very large payloads.

Performance Considerations

  • Batch generate Aztec codes for ticketing or mobile apps
  • Use memory streams for high-volume in-memory export
  • Adjust layers and ECC for scan reliability

Best Practices

  1. Use Auto mode for layers unless specific print/size required
  2. Test output on mobile and handheld devices
  3. Export to PNG for best print/display quality
  4. Document all code text and ECC settings for traceability

Advanced Scenarios

1. Batch Generate Aztec Codes

foreach (var item in tickets)
{
    BarcodeGenerator g = new BarcodeGenerator(EncodeTypes.Aztec, item.CodeText);
    g.Save($"aztec_{item.Id}.png", BarCodeImageFormat.Png);
}

2. Set Specific Number of Layers

generator.Parameters.Barcode.Aztec.AztecLayers = AztecSymbolMode.Layers16;

Conclusion

With Aspose.BarCode for .NET, you can generate Aztec codes for transport, mobile, and secure workflows—customized for reliability and speed. See more options in the Aspose.BarCode API Reference.

More in this category