在今天的数字景观中,有效和可靠的数据存储解决方案至关重要. Aztec 代码提供高容量的条码格式,可以使用强大的错误纠正能力存放大量 alphanumeric 数据.

创建 Aztec 代码

在 C# 中创建一个 Aztec 代码是简单的,由于 Aspose.BarCode 为 .NET 提供的强大的功能:

步骤指南

首先,请确保您从 NuGet 或您最喜欢的来源安装了所需的包.

using Aspose.BarCode;

public void GenerateAztecCode()
{
    // Create an instance of BarCodeGenerator for Aztec symbology
    BarCodeGenerator generator = new BarCodeGenerator(EncodeTypes.Aztec);
    
    // Set the data to encode in the barcode
    generator.CodeText = "SampleData1234567890";
    
    // Save the generated Aztec code as an image file
    generator.Save("aztec_code.png", BarCodeImageFormat.Png);
}

定制代码

您可以自定义条形码的各个方面,如尺寸、颜色和错误纠正级别:

// Set the width and height of the barcode image
int width = 200;
int height = 200;
generator.GraphicsUnit = System.Drawing.GraphicsUnit.Pixel;
generator.SymbologySettings.Aztec.CodeSize = new Size(width, height);

generator.Save("custom_aztec_code.png", BarCodeImageFormat.Png);

阅读 Aztec 代码

阅读 Aztec 代码返回数据与 Aspose.BarCode for .NET 同样简单,下面的示例表明如何阅读创建的 Aztec 条形码图像并提取编码文本.

步骤指南

要阅读一个 Aztec 代码,启动一个 BarCodeReader 对象并指定您要解码的条码图像的文件路径.

using Aspose.BarCode.BarCodeRecognition;

public void ReadAztecCode()
{
    // Initialize a BarCodeReader instance for reading Aztec codes
    BarCodeReader reader = new BarCodeReader("aztec_code.png", DecodeType.Aztec);
    
    // Iterate through all detected barcodes in the image
    foreach (BarCodeResult result in reader.ReadBarCodes())
    {
        Console.WriteLine($"Decoded text: {result.CodeText}");
        Console.WriteLine($"Barcode type: {result.CodeType}");
        Console.WriteLine($"Confidence: {result.ReadingQuality}%");
    }
}

提高阅读能力

为了更好地阅读,您可以设置 BarCodeReader 适用质量设置,在困难的条件下提高检测准确性.

reader.QualitySettings.AllowMedianSmoothing = true;
reader.QualitySettings.MedianSmoothingWindowSize = 5;

结论

通过使用 Aspose.BarCode for .NET,开发人员可以轻松地将 Aztec 代码生成和阅读功能集成到他们的应用程序中,确保高容量数据存储和获取.

More in this category