VintaSoft Barcode .NET SDK v10.0
Vintasoft.WpfBarcode.BarcodeStructure Namespace / MatrixBarcodeStructure Class
Members Example




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
    MatrixBarcodeStructure Class
    Syntax
    'Declaration
     
    Public Class MatrixBarcodeStructure 
       Inherits BarcodeStructureBase
    'Usage
     
    Dim instance As MatrixBarcodeStructure
    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).
    • 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).
    • 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) 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) 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).
      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 BarcodeInfo2D.ErrorCorrectionCodewordCount and BarcodeInfo2D.CorrectedErrors properties. You should increase the error correction level for recognized barcode if the value of BarcodeInfo2D.CorrectedErrors property multiplied by 4 is greater than the value of the BarcodeInfo2D.ErrorCorrectionCodewordCount property. Also the required error correction level can be calculated using the ISO15415QualityTest class.
    Example
    This example 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(ByVal value As String, ByVal outputFilename As String)   
        Dim writer As New BarcodeWriter()   
        writer.Settings.Barcode = BarcodeType.Aztec   
        writer.Settings.Value = value   
        Dim barcode As MatrixBarcodeStructure = DirectCast(writer.GetBarcodeStructure(), MatrixBarcodeStructure)   
        Dim barcodeBBox As Int32Rect = 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 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   
        File.WriteAllText(outputFilename, result.ToString())   
    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)
    {
        BarcodeWriter writer = new BarcodeWriter();
        writer.Settings.Barcode = BarcodeType.Aztec;
        writer.Settings.Value = value;
        MatrixBarcodeStructure barcode = (MatrixBarcodeStructure)writer.GetBarcodeStructure();
        Int32Rect barcodeBBox = barcode.GetBoundingBox();
        int x0 = barcodeBBox.X;
        int x1 = barcodeBBox.X + barcodeBBox.Width;
        int y0 = barcodeBBox.Y;
        int y1 = barcodeBBox.Y + barcodeBBox.Height;
        StringBuilder result = new 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();
        }
        File.WriteAllText(outputFilename, result.ToString());            
    }
    Inheritance Hierarchy
    Requirements

    Target Platforms: Windows 8, Windows 7, Windows Vista, Windows XP, Windows Server 2012, Windows Server 2008, Windows Server 2003

    See Also