VintaSoft Barcode .NET SDK 15.0: Documentation for .NET developer
Vintasoft.Barcode.BarcodeStructure Namespace / MatrixBarcodeStructure Class
Members Object Syntax Remarks Example Hierarchy Requirements SeeAlso
In This Topic
    MatrixBarcodeStructure Class
    In This Topic
    A class that stores structure of two-dimentsional matrix barcode (Aztec, QR Code, Micro QR, Data Matrix, Han Xin Code).
    Object Model
    BarcodeElement BarcodeElement BarcodeElement MatrixBarcodeStructure
    Syntax
    'Declaration
    
    Public Class MatrixBarcodeStructure
       Inherits BarcodeStructureBase
    
    
    public class MatrixBarcodeStructure : BarcodeStructureBase
    
    
    public __gc class MatrixBarcodeStructure : public BarcodeStructureBase*
    
    
    public ref class MatrixBarcodeStructure : public BarcodeStructureBase^
    
    
    Remarks

    When generating the "design" barcodes it is necessary to take into account that you cannot change any barcode element if you want to recognize the barcode.
    This class contains information about barcode elements of matrix barcode and provides information about importance of barcode elements for recognition systems.
    Information about importance of barcode elements for recognition systems can be used for generating the "design" barcode, which can be recognized.

    Two-dimensional matrix barcode usually consists from the following layers:

    • Fixed structure - fixed cells (search patterns, orientation patterns, alignment patterns, timing patterns), which do not depend on the user data (FixedStructure)
    • Format information - cells (symbol version, error correction level, mask), which contain service information (FixedStructure)
    • Data layer - cells, which contain the user data and error correction data (DataLayer)

    While changing the barcode element, it is necessary to take into account the importance of barcode element and the ability to restore the barcode element during the barcode recognition:
    • Search patterns - critical barcode cells, which are used to search for barcode on image. The barcode won't be recognized if the form of its cells is significantly distorted or damaged (IsSearchPattern(Int32,Int32)).
    • Format information - critical barcode cells, which contain service information. The barcode won't be recognized if the form of its cells is significantly distorted or damaged (IsFormatInformation(Int32,Int32)).
    • Alignment patterns - non-critical barcode cells for QR Code, Micro QR, DataMatrix, Han Xin Code; critical barcode cells for Aztec barcodes. The barcode won't be recognized or the chance to recognize it will considerably decrease if the form of barcode cells is significantly distorted or damaged (IsAlignmentPattern(Int32,Int32)) or if the barcode image has spatial distortions (for example, the image was taken with low quality from camera of smartphone).
    • Timing patterns - non-critical barcode cells for Aztec, QR Code, Micro QR, Han Xin Code; critical barcode cells for DataMatrix barcodes. The barcode won't be recognized or the chance to recognize it will considerably decrease if the form of barcode cells is significantly distorted or damaged (IsTimingPattern(Int32,Int32)) or if the barcode image has spatial distortions (for example, the image was taken with low quality from camera of smartphone).
    • Data layer - barcode cells, which contain user data and error correction information (IsDataLayer(Int32,Int32)).
      Data in this layer can be restored using the error correction algorithm. The error correction level defines how many data can be restored.
      The required error correction level can be calculated using the ErrorCorrectionCodewordCount and CorrectedErrors properties. You should increase the error correction level for recognized barcode if the value of CorrectedErrors property multiplied by 4 is greater than the value of the ErrorCorrectionCodewordCount property. Also the required error correction level can be calculated using the ISO15415QualityTest class.

    Example

    This C#/VB.NET code shows how to generate QR barcode as a text file (ASCII graphics).

       
    ''' <summary>
    ''' Generates the QR barcode structure as text file.
    ''' </summary>
    ''' <param name="value">The barcode value.</param>
    ''' <param name="outputFilename">The output filename.</param>
    Public Shared Sub GenerateQRBarcodeStructureAsText(value As String, outputFilename As String)   
        Using writer As New Vintasoft.Barcode.BarcodeWriter()   
            writer.Settings.Barcode = Vintasoft.Barcode.BarcodeType.Aztec   
            writer.Settings.Value = value   
            Dim barcode As Vintasoft.Barcode.BarcodeStructure.MatrixBarcodeStructure = DirectCast(writer.GetBarcodeStructure(), Vintasoft.Barcode.BarcodeStructure.MatrixBarcodeStructure)   
            Dim barcodeBBox As Vintasoft.Primitives.VintasoftRectI = barcode.GetBoundingBox()   
            Dim x0 As Integer = barcodeBBox.X   
            Dim x1 As Integer = barcodeBBox.X + barcodeBBox.Width   
            Dim y0 As Integer = barcodeBBox.Y   
            Dim y1 As Integer = barcodeBBox.Y + barcodeBBox.Height   
            Dim result As New System.Text.StringBuilder((barcodeBBox.Width * 2 + 2) * barcodeBBox.Height)   
            For y As Integer = y0 To y1   
                For x As Integer = x0 To x1   
                    Dim symbol As Char = " "C   
                    If barcode.IsBlackCell(x, y) Then   
                        If barcode.IsDataLayer(x, y) Then   
                            symbol = "D"C   
                        ElseIf barcode.IsAlignmentPattern(x, y) Then   
                            symbol = "A"C   
                        ElseIf barcode.IsFormatInformation(x, y) Then   
                            symbol = "F"C   
                        ElseIf barcode.IsSearchPattern(x, y) Then   
                            symbol = "#"C   
                        ElseIf barcode.IsTimingPattern(x, y) Then   
                            symbol = "T"C   
                        End If   
                    End If   
                    result.Append(symbol)   
                Next   
                result.AppendLine()   
            Next   
            System.IO.File.WriteAllText(outputFilename, result.ToString())   
        End Using   
    End Sub
    
    
    
    /// <summary>
    /// Generates the QR barcode structure as text file.
    /// </summary>
    /// <param name="value">The barcode value.</param>
    /// <param name="outputFilename">The output filename.</param>
    public static void GenerateQRBarcodeStructureAsText(string value, string outputFilename)
    {
        using (Vintasoft.Barcode.BarcodeWriter writer = new Vintasoft.Barcode.BarcodeWriter())
        {
            writer.Settings.Barcode = Vintasoft.Barcode.BarcodeType.Aztec;
            writer.Settings.Value = value;
            Vintasoft.Barcode.BarcodeStructure.MatrixBarcodeStructure barcode = (Vintasoft.Barcode.BarcodeStructure.MatrixBarcodeStructure)writer.GetBarcodeStructure();
            Vintasoft.Primitives.VintasoftRectI barcodeBBox = barcode.GetBoundingBox();
            int x0 = barcodeBBox.X;
            int x1 = barcodeBBox.X + barcodeBBox.Width;
            int y0 = barcodeBBox.Y;
            int y1 = barcodeBBox.Y + barcodeBBox.Height;
            System.Text.StringBuilder result = new System.Text.StringBuilder((barcodeBBox.Width * 2 + 2) * barcodeBBox.Height);
            for (int y = y0; y <= y1; y++)
            {
                for (int x = x0; x <= x1; x++)
                {
                    char symbol = ' ';
                    if (barcode.IsBlackCell(x, y))
                    {
                        if (barcode.IsDataLayer(x, y))
                            symbol = 'D';
                        else if (barcode.IsAlignmentPattern(x, y))
                            symbol = 'A';
                        else if (barcode.IsFormatInformation(x, y))
                            symbol = 'F';
                        else if (barcode.IsSearchPattern(x, y))
                            symbol = '#';
                        else if (barcode.IsTimingPattern(x, y))
                            symbol = 'T';
                    }
                    result.Append(symbol);
                }
                result.AppendLine();
            }
            System.IO.File.WriteAllText(outputFilename, result.ToString());
        }
    }
    
    

    Inheritance Hierarchy
    Requirements

    Target Platforms: .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5

    See Also