Generate and recognize DotCode barcodes in .NET

Blog category: Barcode.NET

August 13, 2020

DotCode is a two-dimensional dot code symbology designed to be reliably read when printed by high-speed inkjet or laser dot technologies.

Samples of DotCode barcodes:
Samples of DotCode barcodes

A dot code, generically, is a type of bar code that encodes data in an array of nominally disconnected dots at chosen sites within a regular grid of possible locations. DotCode is a dot code whose array is rectangular in shape, of height "H" (rows) and width "W" (columns). Exactly half of the possible dot locations made available for printing, like the dark squares on a checker-board.
DotCode barcode matrix does not have fixed or search patterns. Quiet zones that are at least 3Y tall or 3X wide surround the array of data dot locations (see image below).

DotCode barcode structure:
Structure of DotCode barcode


General features of DotCode:



VintaSoft Barcode .NET SDK supports reading and writing of DotCode barcodes.

Here is C# code that shows how to generate DotCode barcode as raster image:
/// <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");
    }
}


Here is C# code that shows how to generate DotCode barcode in vector form:
/// <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();
}


Here is C# code that shows how to generate DotCode barcode as SVG image:
/// <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();
}

Here is C# code that shows how to recognize DotCode barcode in image:
/// <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();
            }
        }
    }
}