.NET で DotCode バーコードを生成および認識します

ブログ カテゴリ: バーコード.NET

2020/08/13

DotCodeは、高速インクジェットまたはレーザードット技術で印刷された際に確実に読み取れるよう設​​計された2次元ドットコードです。

DotCodeバーコードのサンプル:
Samples of DotCode barcodes

一般的にドットコードは、規則的なグリッド内の指定された位置に、名目上は不連続なドットの配列でデータをエンコードするバーコードの一種です。DotCodeは、高さ「H」(行)と幅「W」(列)の長方形の配列を持つドットコードです。チェッカーボード上の暗い四角形のように、印刷可能なドット位置のちょうど半分が利用可能です。
DotCodeバーコードマトリックスには、固定パターンや検索パターンはありません。データ ドットの位置の配列の周囲には、少なくとも 3Y の高さまたは 3X の幅の静かなゾーンが設けられています (下の画像を参照)。

DotCode バーコード構造:
Structure of DotCode barcode


DotCode の一般的な機能:



VintaSoft Barcode .NET SDK はDotCode バーコードの読み取りと書き込み。

DotCode バーコードをラスター イメージとして生成する方法を示す C# コードは次のとおりです。
/// <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");
    }
}


DotCode バーコードをベクター形式で生成する方法を示す C# コードは次のとおりです。
/// <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();
}


DotCode バーコードを SVG イメージとして生成する方法を示す C# コードは次のとおりです。
/// <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();
}

画像内の DotCode バーコードを認識する方法を示す C# コードは次のとおりです。
/// <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();
            }
        }
    }
}