在 .NET 中生成和识别 DotCode 条形码

博客分类:条形码   .NET

2020/08/13

DotCode 是一种二维点码符号系统专为高速喷墨或激光点阵打印技术而设计,确保可靠读取。

DotCode 条形码示例:
Samples of DotCode barcodes

一般来说,点阵码是一种条形码,它将数据编码在一系列名义上不连续的点上,这些点位于规则网格内的特定位置。DotCode 是一种点阵码,其阵列呈矩形,高度为"H"(行),宽度为"W"(列)。打印时,仅使用一半的可能点位,就像棋盘上的深色方格一样。
DotCode 条形码矩阵没有固定或搜索模式。数据点阵列周围环绕着至少 3Y 高或 3X 宽的静默区(见下图)。

DotCode 条形码结构:
Structure of DotCode barcode


DotCode 的一般特性:



VintaSoft Barcode .NET SDK 支持 DotCode 条码的读写。

以下是 C# 代码,展示了如何生成 DotCode 条形码栅格图像:
/// <summary>
/// Generates DotCode barcode as raster image.
/// </summary>
public void GenerateDotCodeBarcodeAsRasterImage()
{
    // create the barcode writer
    Vintasoft.Barcode.BarcodeWriter barcodeWriter = new Vintasoft.Barcode.BarcodeWriter();

    // set barcode writer settings
    barcodeWriter.Settings.Barcode = Vintasoft.Barcode.BarcodeType.DotCode;
    barcodeWriter.Settings.Value = "abc012345def";

    // get a barcode image
    using (System.Drawing.Image image = barcodeWriter.GetBarcodeAsBitmap())
    {
        // save the barcode image to a file
        image.Save("DotCodeBarcode.png");
    }
}


以下是 C# 代码,展示了如何生成矢量形式的 DotCode 条形码:
/// <summary>
/// Generates DotCode barcode as graphics path.
/// </summary>
public System.Drawing.Drawing2D.GraphicsPath GenerateDotCodeBarcodeAsGraphicsPath()
{
    // create the barcode writer
    Vintasoft.Barcode.BarcodeWriter barcodeWriter = new Vintasoft.Barcode.BarcodeWriter();

    // set barcode writer settings
    barcodeWriter.Settings.Barcode = Vintasoft.Barcode.BarcodeType.DotCode;
    barcodeWriter.Settings.Value = "012345abcde";

    // return barcode as graphics path
    return barcodeWriter.GetBarcodeAsGraphicsPath();
}


以下是 C# 代码,展示了如何生成 SVG 图像格式的 DotCode 条形码:
/// <summary>
/// Generates DotCode barcode as SVG image.
/// </summary>
public string GenerateDotCodeBarcodeAsSvgImage()
{
    // create the barcode writer
    Vintasoft.Barcode.BarcodeWriter barcodeWriter = new Vintasoft.Barcode.BarcodeWriter();

    // set barcode writer settings
    barcodeWriter.Settings.Barcode = Vintasoft.Barcode.BarcodeType.DotCode;
    barcodeWriter.Settings.Value = "012345abcde";

    // return barcode as SVG image
    return barcodeWriter.GetBarcodeAsSvgFile();
}

以下是 C# 代码,展示了如何识别图像中的 DotCode 条形码:
/// <summary>
/// Recognizes DotCode barcode in image.
/// </summary>
public void RecognizeDotCodeBarcode()
{
    // 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;

        // ScanInterval must be lower than dot size of DotCode barcode, in pixels
        reader.Settings.ScanInterval = 3;

        // read barcodes from image file
        Vintasoft.Barcode.IBarcodeInfo[] barcodeInfos = reader.ReadBarcodes("DotCodeCodeBarcode.png");

        // if barcodes are not detected
        if (barcodeInfos.Length == 0)
        {
            Console.WriteLine("Barcodes are not found.");
        }
        // if barcodes are detected
        else
        {
            // get information about recognized barcodes

            Console.WriteLine(string.Format("{0} barcode(s) found:", barcodeInfos.Length));
            Console.WriteLine();
            for (int i = 0; i &lt; barcodeInfos.Length; i++)
            {
                Vintasoft.Barcode.IBarcodeInfo barcodeInfo = barcodeInfos[i];
                Console.WriteLine(string.Format("[{0}:{1}]", i + 1, barcodeInfo.BarcodeType));
                Console.WriteLine(string.Format("Value:      {0}", barcodeInfo.Value));
                Console.WriteLine(string.Format("Region:     {0}", barcodeInfo.Region));
                Console.WriteLine();
            }
        }
    }
}