Genera e riconosci codici a barre DotCode in .NET

Categoria del blog: Barcode.NET

13.08.2020

DotCode è una simbologia di codice a punti bidimensionale progettata per essere letta in modo affidabile quando stampata con tecnologie a getto d'inchiostro ad alta velocità o laser.

Esempi di codici a barre DotCode:
Esempi di codici a barre DotCode

Un codice a punti, genericamente,è un tipo di codice a barre che codifica i dati in una matrice di punti nominalmente scollegati in punti scelti all'interno di una griglia regolare di possibili posizioni. DotCode è un codice a punti la cui matrice è di forma rettangolare, con altezza "H" (righe) e larghezza "W" (colonne). Esattamente la metà delle possibili posizioni dei punti è disponibile per la stampa, come i quadrati scuri su una scacchiera.
La matrice del codice a barre DotCode non ha schemi fissi o di ricerca. Zone libere alte almeno 3Y o larghe 3X circondano la matrice delle posizioni dei punti di dati (vedi immagine sotto).

Struttura del codice a barre DotCode:
Struttura del codice a barre DotCode


Caratteristiche generali di DotCode:



VintaSoft Barcode .NET SDK supporta la lettura e la scrittura di codici a barre DotCode.

Ecco il codice C# che mostra come generare un codice a barre DotCode come immagine raster:
/// <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");
    }
}


Ecco il codice C# che mostra come generare un codice a barre DotCode in formato vettoriale:
/// <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();
}


Ecco il codice C# che mostra come generare un codice a barre DotCode come immagine SVG:
/// <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();
}

Ecco il codice C# che mostra come riconoscere un codice a barre DotCode in un'immagine:
/// <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();
            }
        }
    }
}