使用 VintaSoft Barcode .NET SDK 识别和生成 DotCode 条形码

博客分类:条形码   .NET

2025/07/10

VintaSoft Barcode .NET SDK 是一款专业的跨平台 SDK,支持 Windows、Linux 和 macOS,可用于在 .NET、WPF、Web 和 MAUI 中识别和生成 DotCode 条形码。只需几行代码即可将识别和生成 DotCode 条形码的功能添加到您的 .NET 应用程序中。


什么是DotCode条形码?

DotCode是一种二维矩阵条形码,设计用于在使用高速喷墨或激光点阵技术打印时可靠读取。使用这种条形码,可以以生产线速度将动态数据(生产日期、有效期、序列号等)应用于产品。DotCode 条形码的一个显著特点是没有任何可见的固定图案,以及以"棋盘格"顺序排列的矩阵点:


DotCode 条形码的特点

DotCode 条形码由 2019 年的 AIM 标准定义,该标准描述了当前版本的 DotCode Rev 4。

DotCode 条形码可以存储无限量的混合数据,并支持三种编码模式:

支持 GS1 标准,允许您以 GS1 格式编码数据 (BarcodeSymbologySubsets.GS1DotCode)。

DotCode 条形码使用 Reed-Solomon 纠错算法,该算法可以识别损坏的条形码。

DotCode 条形码可以编码以下特殊字符:


矩阵结构

DotCode 矩阵可以是正方形或矩形,允许灵活调整长宽比以适应不同用途。最小符号尺寸可以非常小(最大 3x3 毫米),使其成为标记香烟盒或药品等小型物品的理想选择。



VintaSoft Barcode .NET SDK 可以生成 DotCode 条形码,格式为光栅或矢量图像,以及 MatrixBarcodeStructure,从而实现高速条形码打印。


VintaSoft Barcode .NET SDK 可以识别哪些 DotCode 条形码?

VintaSoft Barcode .NET SDK 在识别 DotCode 条形码时,也使用独特的算法,能够快速识别存在各种问题的条形码:



以下 C# 代码演示了如何识别相机拍摄图像中的 DotCode 条形码:
/// <summary>
/// Reads DotCode barcodes from a <see cref="System.Drawing.Bitmap"/>.
/// </summary>
/// <param name="bitmap">A bitmap with barcodes.</param>
public static void ReadDotCodeBarcodesFromBitmap(System.Drawing.Bitmap bitmap)
{
    // create barcode reader
    using (Vintasoft.Barcode.BarcodeReader reader = new Vintasoft.Barcode.BarcodeReader())
    {
        // specify that reader must search for DotCode barcodes
        reader.Settings.ScanBarcodeTypes = Vintasoft.Barcode.BarcodeType.DotCode;

        // read barcodes from image
        Vintasoft.Barcode.IBarcodeInfo[] infos = Vintasoft.Barcode.GdiExtensions.ReadBarcodes(reader, bitmap);

        // if barcodes are not detected
        if (infos.Length == 0)
        {
            System.Console.WriteLine("No barcodes found.");
        }
        // if barcodes are detected
        else
        {
            // get information about extracted barcodes

            System.Console.WriteLine(string.Format("{0} barcodes found:", infos.Length));
            System.Console.WriteLine();
            for (int i = 0; i < infos.Length; i++)
            {
                Vintasoft.Barcode.IBarcodeInfo info = infos[i];
                System.Console.WriteLine(string.Format("[{0}:{1}]", i + 1, info.BarcodeType));
                System.Console.WriteLine(string.Format("Value:      {0}", info.Value));
                System.Console.WriteLine(string.Format("Region:     {0}", info.Region));
                System.Console.WriteLine();
            }
        }
    }
}


VintaSoft Barcode .NET SDK 可以生成哪些 DotCode 条形码?

VintaSoft Barcode .NET SDK 生成所有类型的 DotCode 条形码。

以下是演示如何生成 DotCode 条形码位图的 C# 代码:
/// <summary>
/// Returns the DotCode barcode as <see cref="System.Drawing.Bitmap"/>.
/// </summary>
/// <param name="value">The barcode value.</param>
/// <returns>A <see cref="System.Drawing.Bitmap"/> object.</returns>
public static System.Drawing.Bitmap GetDotCodeBarcodeAsBitmap(string value)
{
    // create the barcode writer
    using (Vintasoft.Barcode.BarcodeWriter barcodeWriter = new Vintasoft.Barcode.BarcodeWriter())
    {
        // set barcode writer settings
        barcodeWriter.Settings.Barcode = Vintasoft.Barcode.BarcodeType.DotCode;
        barcodeWriter.Settings.Value = value;

        // get a barcode image as System.Drawing.Bitmap
        return Vintasoft.Barcode.GdiExtensions.GetBarcodeAsBitmap(barcodeWriter);
    }
}


以下是演示如何生成 DotCode 条形码矢量 (SVG) 图像的 C# 代码:
/// <summary>
/// Returns the DotCode barcode in vector form as a SVG string.
/// </summary>
/// <param name="barcodeValue">Barcode value.</param>
public static void GetDotCodeBarcodeAsSvgString(string barcodeValue)
{
    // create the barcode writer
    using (Vintasoft.Barcode.BarcodeWriter barcodeWriter = new Vintasoft.Barcode.BarcodeWriter())
    {
        // set barcode writer settings
        barcodeWriter.Settings.Barcode = Vintasoft.Barcode.BarcodeType.DotCode;
        barcodeWriter.Settings.Value = barcodeValue;

        // generate DotCode barcode as a SVG string
        return barcodeWriter.GetBarcodeAsSvgFile();
    }
}