VintaSoft Barcode .NET SDK 15.0: Руководство для .NET разработчика
Vintasoft.Barcode.BarcodeInfo Namespace / NonDataFlags Class
Члены типа Объект Синтаксис Example Иерархия Требования Смотрите также
В этом разделе
    Класс NonDataFlags
    В этом разделе
    Содержит доступные флаги, не относящиеся к данным.
    Объектная модель
    NonDataFlagValueItem NonDataFlagValueItem NonDataFlagValueItem NonDataFlagValueItem NonDataFlagValueItem NonDataFlagValueItem NonDataFlagValueItem NonDataFlagValueItem NonDataFlagValueItem MacroCharacter MacroCharacter NonDataFlags
    Синтаксис
    'Declaration
    
    Public NotInheritable Class NonDataFlags
    
    
    public sealed class NonDataFlags
    
    
    public __gc __sealed class NonDataFlags
    
    
    public ref class NonDataFlags sealed
    
    
    Пример

    Этот C#/VB.NET код показывает, как сгенерировать и распознать флаги, которые не относятся к данным, в штрих-коде.

       
    Imports System.Collections.Generic   
       
    Imports Vintasoft.Barcode   
    Imports Vintasoft.Barcode.BarcodeInfo   
    Imports Vintasoft.Imaging   
       
    ''' <summary>
    ''' Test that shows how to create barcodes with data flags.
    ''' </summary>
    Class NonDataFlagsExample   
       
        ''' <summary>
        ''' Runs the test.
        ''' </summary>
        Public Shared Sub Test()   
            ' create image with Code128 barcode with FNC1 flag
            Using image As VintasoftBitmap = WriteFlagUsingValueProperty(BarcodeType.Code128, "", NonDataFlags.Fnc1, "abc")   
                ' read barcode from image
                ReadBarcode(image, BarcodeType.Code128)   
            End Using   
            ' create image with Code128 barcode with FNC1 flag
            Using image As VintasoftBitmap = WriteFlagUsingValueItemsProperty(BarcodeType.Code128, "123", NonDataFlags.Fnc1, "456")   
                ' read barcode from image
                ReadBarcode(image, BarcodeType.Code128)   
            End Using   
       
       
            ' create the barcode value with multiple FNC1 flags
            Dim barcodeValue As String = NonDataFlags.Fnc1.Name   
            barcodeValue += "A" & NonDataFlags.Fnc1.Name   
            barcodeValue += "B" & NonDataFlags.Fnc1.Name   
            barcodeValue += "C" & NonDataFlags.Fnc1.Name   
       
            ' create the barcode writer
            Using writer As New BarcodeWriter()   
                ' specify that writer must generate Code128 barcode
                writer.Settings.Barcode = BarcodeType.Code128   
                writer.Settings.ProcessSpecialSymbols = True   
                ' set the barcode value
                writer.Settings.Value = barcodeValue   
                ' create image with Code128 barcode with  multiple FNC1 flags
                Using image As VintasoftBitmap = writer.GetBarcodeAsVintasoftBitmap()   
                    ' read barcode from image
                    ReadBarcode(image, BarcodeType.Code128)   
                End Using   
            End Using   
       
       
            ' create image with DataMatrix barcode with FNC1 flag
            Using image As VintasoftBitmap = WriteFlagUsingValueItemsProperty(BarcodeType.DataMatrix, "DataMatrix", NonDataFlags.Fnc1, "!")   
                ' read barcode from image
                ReadBarcode(image, BarcodeType.DataMatrix)   
            End Using   
       
            ' create image with QR barcode with ECI123456 flag
            Using image As VintasoftBitmap = WriteFlagUsingValueProperty(BarcodeType.QR, "", NonDataFlags.CreateECICharacter(123456), "QR Test ECI123456")   
                ' read barcode from image
                ReadBarcode(image, BarcodeType.QR)   
            End Using   
       
            ' create image with DataMatrix barcode with Macro05 flag
            Using image As VintasoftBitmap = WriteFlagUsingValueItemsProperty(BarcodeType.DataMatrix, "", NonDataFlags.Macro05, "BarcodeData")   
                ' read barcode from image
                ReadBarcode(image, BarcodeType.DataMatrix)   
            End Using   
        End Sub   
       
        ''' <summary>
        ''' Writes a data flag to barcode using WriterSettings.Value property.
        ''' </summary>
        Private Shared Function WriteFlagUsingValueProperty(barcodeType As BarcodeType, leftValuePart As String, flag As NonDataFlagValueItem, rightValuePart As String) As VintasoftBitmap   
            ' create the barcode writer
            Using writer As New BarcodeWriter()   
                ' specify that writer must generate barcode of specified type
                writer.Settings.Barcode = barcodeType   
       
                ' specify that writer must process special characters in the barcode value
                writer.Settings.ProcessSpecialSymbols = True   
       
                ' set the barcode value
                writer.Settings.Value = leftValuePart & flag.Name & rightValuePart   
       
                ' create image with barcode
                Return writer.GetBarcodeAsVintasoftBitmap()   
            End Using   
        End Function   
       
        ''' <summary>
        ''' Writes a data flag to barcode using WriterSettings.ValueItems property.
        ''' </summary>
        Private Shared Function WriteFlagUsingValueItemsProperty(barcodeType As BarcodeType, leftValuePart As String, flag As NonDataFlagValueItem, rightValuePart As String) As VintasoftBitmap   
            ' create the barcode writer
            Using writer As New BarcodeWriter()   
                ' specify that writer must generate barcode of specified type
                writer.Settings.Barcode = barcodeType   
       
                ' create the barcode value items
       
                Dim items As New List(Of ValueItemBase)()   
                If leftValuePart <> "" Then   
                    items.Add(New TextValueItem(leftValuePart))   
                End If   
                items.Add(flag)   
                If rightValuePart <> "" Then   
                    items.Add(New TextValueItem(rightValuePart))   
                End If   
       
                ' set the barcode value items
                writer.Settings.ValueItems = items.ToArray()   
       
                ' create image with barcode
                Return writer.GetBarcodeAsVintasoftBitmap()   
            End Using   
        End Function   
       
        ''' <summary>
        ''' Reads a barcode and shows the recognized barcode value.
        ''' </summary>
        Private Shared Sub ReadBarcode(image As VintasoftBitmap, barcodeType As BarcodeType)   
            ' create the barcode reader
            Using reader As New BarcodeReader()   
                ' specify that reader must search for barcodes of specified type
                reader.Settings.ScanBarcodeTypes = barcodeType   
       
                ' reader barcode from image
                Dim barcodeInfo As IBarcodeInfo = reader.ReadBarcodes(image)(0)   
       
                barcodeInfo.ShowNonDataFlagsInValue = False   
                Console.WriteLine("Barcode value without flags: {0}", barcodeInfo.Value)   
       
                barcodeInfo.ShowNonDataFlagsInValue = True   
                Console.WriteLine("Barcode value with flags:    {0}", barcodeInfo.Value)   
       
                Console.WriteLine("Barcode value items:")   
                For i As Integer = 0 To barcodeInfo.ValueItems.Length - 1   
                    Dim valueItem As ValueItemBase = barcodeInfo.ValueItems(i)   
                    Console.WriteLine("  [{0}]: {1}", valueItem.[GetType]().Name, valueItem)   
                Next   
            End Using   
       
            Console.WriteLine()   
        End Sub   
       
    End Class
    
    
    
    using System;
    using System.Collections.Generic;
    
    using Vintasoft.Barcode;
    using Vintasoft.Barcode.BarcodeInfo;
    using Vintasoft.Imaging;
    
    /// <summary>
    /// Test that shows how to create barcodes with data flags.
    /// </summary>
    class NonDataFlagsExample
    {
    
        /// <summary>
        /// Runs the test.
        /// </summary>
        public static void Test()
        {
            // create image with Code128 barcode with FNC1 flag
            using (VintasoftBitmap image = WriteFlagUsingValueProperty(BarcodeType.Code128, "", NonDataFlags.Fnc1, "abc"))
            {
                // read barcode from image
                ReadBarcode(image, BarcodeType.Code128);
            }
            // create image with Code128 barcode with FNC1 flag
            using (VintasoftBitmap image = WriteFlagUsingValueItemsProperty(BarcodeType.Code128, "123", NonDataFlags.Fnc1, "456"))
            {
                // read barcode from image
                ReadBarcode(image, BarcodeType.Code128);
            }
    
    
            // create the barcode value with multiple FNC1 flags
            string barcodeValue = NonDataFlags.Fnc1.Name;
            barcodeValue += "A" + NonDataFlags.Fnc1.Name;
            barcodeValue += "B" + NonDataFlags.Fnc1.Name;
            barcodeValue += "C" + NonDataFlags.Fnc1.Name;
    
            // create the barcode writer
            using (BarcodeWriter writer = new BarcodeWriter())
            {
                // specify that writer must generate Code128 barcode
                writer.Settings.Barcode = BarcodeType.Code128;
                writer.Settings.ProcessSpecialSymbols = true;
                // set the barcode value
                writer.Settings.Value = barcodeValue;
                // create image with Code128 barcode with  multiple FNC1 flags
                using (VintasoftBitmap image = writer.GetBarcodeAsVintasoftBitmap())
                {
                    // read barcode from image
                    ReadBarcode(image, BarcodeType.Code128);
                }
            }
    
    
            // create image with DataMatrix barcode with FNC1 flag
            using (VintasoftBitmap image = WriteFlagUsingValueItemsProperty(
                BarcodeType.DataMatrix, "DataMatrix", NonDataFlags.Fnc1, "!"))
            {
                // read barcode from image
                ReadBarcode(image, BarcodeType.DataMatrix);
            }
    
            // create image with QR barcode with ECI123456 flag
            using (VintasoftBitmap image = WriteFlagUsingValueProperty(
                BarcodeType.QR, "", NonDataFlags.CreateECICharacter(123456), "QR Test ECI123456"))
            {
                // read barcode from image
                ReadBarcode(image, BarcodeType.QR);
            }
    
            // create image with DataMatrix barcode with Macro05 flag
            using (VintasoftBitmap image = WriteFlagUsingValueItemsProperty(
                BarcodeType.DataMatrix, "", NonDataFlags.Macro05, "BarcodeData"))
            {
                // read barcode from image
                ReadBarcode(image, BarcodeType.DataMatrix);
            }
        }
    
        /// <summary>
        /// Writes a data flag to barcode using WriterSettings.Value property.
        /// </summary>
        static VintasoftBitmap WriteFlagUsingValueProperty(
            BarcodeType barcodeType,
            string leftValuePart,
            NonDataFlagValueItem flag,
            string rightValuePart)
        {
            // create the barcode writer
            using (BarcodeWriter writer = new BarcodeWriter())
            {
                // specify that writer must generate barcode of specified type
                writer.Settings.Barcode = barcodeType;
    
                // specify that writer must process special characters in the barcode value
                writer.Settings.ProcessSpecialSymbols = true;
    
                // set the barcode value
                writer.Settings.Value = leftValuePart + flag.Name + rightValuePart;
    
                // create image with barcode
                return writer.GetBarcodeAsVintasoftBitmap();
            }
        }
    
        /// <summary>
        /// Writes a data flag to barcode using WriterSettings.ValueItems property.
        /// </summary>
        static VintasoftBitmap WriteFlagUsingValueItemsProperty(
            BarcodeType barcodeType,
            string leftValuePart,
            NonDataFlagValueItem flag,
            string rightValuePart)
        {
            // create the barcode writer
            using (BarcodeWriter writer = new BarcodeWriter())
            {
                // specify that writer must generate barcode of specified type
                writer.Settings.Barcode = barcodeType;
    
                // create the barcode value items
    
                List<ValueItemBase> items = new List<ValueItemBase>();
                if (leftValuePart != "")
                    items.Add(new TextValueItem(leftValuePart));
                items.Add(flag);
                if (rightValuePart != "")
                    items.Add(new TextValueItem(rightValuePart));
    
                // set the barcode value items
                writer.Settings.ValueItems = items.ToArray();
    
                // create image with barcode
                return writer.GetBarcodeAsVintasoftBitmap();
            }
        }
    
            /// <summary>
            /// Reads a barcode and shows the recognized barcode value.
            /// </summary>
            static void ReadBarcode(VintasoftBitmap image, BarcodeType barcodeType)
        {
            // create the barcode reader
            using (BarcodeReader reader = new BarcodeReader())
            {
                // specify that reader must search for barcodes of specified type
                reader.Settings.ScanBarcodeTypes = barcodeType;
    
                // reader barcode from image
                IBarcodeInfo barcodeInfo = reader.ReadBarcodes(image)[0];
                
                barcodeInfo.ShowNonDataFlagsInValue = false;
                Console.WriteLine("Barcode value without flags: {0}", barcodeInfo.Value);
    
                barcodeInfo.ShowNonDataFlagsInValue = true;
                Console.WriteLine("Barcode value with flags:    {0}", barcodeInfo.Value);
    
                Console.WriteLine("Barcode value items:");
                for (int i = 0; i < barcodeInfo.ValueItems.Length; i++)
                {
                    ValueItemBase valueItem = barcodeInfo.ValueItems[i];
                    Console.WriteLine("  [{0}]: {1}", valueItem.GetType().Name, valueItem);
                }
            }
    
            Console.WriteLine();
        }
    
    }
    
    

    Иерархия наследования

    System.Object
       Vintasoft.Barcode.BarcodeInfo.NonDataFlags

    Требования

    Целевые платформы: .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5

    Смотрите также