VintaSoft Barcode .NET SDK v10.0
Vintasoft.WpfBarcode.BarcodeInfo Namespace / ValueItemBase Class
Members Example




In This Topic
    ValueItemBase Class
    In This Topic
    Specification for a value item of barcode.
    Object Model
    ValueItemBase Class
    Syntax
    'Declaration
     
    Public Class ValueItemBase 
    'Usage
     
    Dim instance As ValueItemBase
    public class ValueItemBase 
    public __gc class ValueItemBase 
    public ref class ValueItemBase 
    Example
    Imports System.Windows.Media.Imaging   
    Imports System.Text   
       
    Imports Vintasoft.WpfBarcode   
    Imports Vintasoft.WpfBarcode.BarcodeInfo   
       
    ''' <summary>   
    ''' Test that shows how to create an image with 2D barcode, which contains text and binary data.   
    ''' </summary>   
    Class ValueItemsExample   
       
    	''' <summary>   
    	''' Runs the test.   
    	''' </summary>   
    	Public Shared Sub Test()   
    		' generate binary data   
    		Dim data As Byte() = New Byte(15) {}   
    		For i As Integer = 0 To data.Length - 1   
    			data(i) = CByte(i * 16)   
    		Next   
       
    		' create image with PDF417 barcode   
    		Dim barcodeImage As BitmapSource = CreateBarcodeWithTextAndBinaryData(BarcodeType.PDF417, data)   
    		' read barcode from image   
    		ReadBarcode(barcodeImage, BarcodeType.PDF417)   
       
    		' create image with Aztec barcode   
    		barcodeImage = CreateBarcodeWithTextAndBinaryData(BarcodeType.Aztec, data)   
    		' read barcode from image   
    		ReadBarcode(barcodeImage, BarcodeType.Aztec)   
       
    		' create image with DataMatrix barcode   
    		barcodeImage = CreateBarcodeWithTextAndBinaryData(BarcodeType.DataMatrix, data)   
    		' read barcode from image   
    		ReadBarcode(barcodeImage, BarcodeType.DataMatrix)   
       
    		' create image with QR barcode   
    		barcodeImage = CreateBarcodeWithTextAndBinaryData(BarcodeType.QR, data)   
    		' read barcode from image   
    		ReadBarcode(barcodeImage, BarcodeType.QR)   
    	End Sub   
       
    	''' <summary>   
    	''' Creates image with barcode wih text and binary data.   
    	''' </summary>   
    	Private Shared Function CreateBarcodeWithTextAndBinaryData(barcodeType As BarcodeType, data As Byte()) As BitmapSource   
    		' create text value item   
    		Dim textData As New TextValueItem("BINARY DATA: ")   
    		' create binary value item   
    		Dim binaryData As New BinaryValueItem(data)   
       
    		' create the barcode writer   
    		Dim writer As New BarcodeWriter()   
       
    		' specify that writer must generate barcode of spefied type   
    		writer.Settings.Barcode = barcodeType   
       
    		' set the barcode value items   
    		writer.Settings.ValueItems = New ValueItemBase() {textData, binaryData}   
       
    		' create image with barcode   
    		Return writer.GetBarcodeAsBitmapSource()   
    	End Function   
       
    	''' <summary>   
    	''' Reads barcode from image and shows the barcode value items.   
    	''' </summary>   
    	Private Shared Sub ReadBarcode(image As BitmapSource, barcode As BarcodeType)   
    		' create the barcode reader   
    		Using reader As New BarcodeReader()   
    			' specify that reader must search for barcodes of specified types   
    			reader.Settings.ScanBarcodeTypes = barcode   
       
    			' read barcode from image   
    			Dim barcodeInfo As IBarcodeInfo = reader.ReadBarcodes(image)(0)   
       
    			' for each found barcode   
    			For i As Integer = 0 To barcodeInfo.ValueItems.Length - 1   
    				' show the barcode value tems   
       
    				Dim itemValue As New StringBuilder()   
    				If TypeOf barcodeInfo.ValueItems(i) Is BinaryValueItem Then   
    					Dim data As Byte() = DirectCast(barcodeInfo.ValueItems(i), BinaryValueItem).Value   
    					For j As Integer = 0 To data.Length - 1   
    						itemValue.Append(String.Format("{0} ", data(j)))   
    					Next   
    				Else   
    					itemValue.Append(barcodeInfo.ValueItems(i).ToString())   
    				End If   
    				Console.WriteLine(String.Format("[{0}] {1}", barcodeInfo.ValueItems(i).[GetType]().Name, itemValue))   
    			Next   
    		End Using   
       
    		Console.WriteLine()   
    	End Sub   
       
    End Class
    using System;
    using System.Windows.Media.Imaging;
    using System.Text;
                
    using Vintasoft.WpfBarcode;
    using Vintasoft.WpfBarcode.BarcodeInfo;
                
    /// <summary>
    /// Test that shows how to create an image with 2D barcode, which contains text and binary data.
    /// </summary>
    class ValueItemsExample
    {
                
        /// <summary>
        /// Runs the test.
        /// </summary>
        public static void Test()
        {
            // generate binary data
            byte[] data = new byte[16];
            for (int i = 0; i < data.Length; i++)
                data[i] = (byte)(i * 16);
                
            // create image with PDF417 barcode
            BitmapSource barcodeImage = CreateBarcodeWithTextAndBinaryData(BarcodeType.PDF417, data);
            // read barcode from image
            ReadBarcode(barcodeImage, BarcodeType.PDF417);
                
            // create image with Aztec barcode
            barcodeImage = CreateBarcodeWithTextAndBinaryData(BarcodeType.Aztec, data);
            // read barcode from image
            ReadBarcode(barcodeImage, BarcodeType.Aztec);
                
            // create image with DataMatrix barcode
            barcodeImage = CreateBarcodeWithTextAndBinaryData(BarcodeType.DataMatrix, data);
            // read barcode from image
            ReadBarcode(barcodeImage, BarcodeType.DataMatrix);
                
            // create image with QR barcode
            barcodeImage = CreateBarcodeWithTextAndBinaryData(BarcodeType.QR, data);
            // read barcode from image
            ReadBarcode(barcodeImage, BarcodeType.QR);
        }
                
        /// <summary>
        /// Creates image with barcode wih text and binary data.
        /// </summary>
        static BitmapSource CreateBarcodeWithTextAndBinaryData(BarcodeType barcodeType, byte[] data)
        {
            // create text value item
            TextValueItem textData = new TextValueItem("BINARY DATA: ");
            // create binary value item
            BinaryValueItem binaryData = new BinaryValueItem(data);
                
            // create the barcode writer
            BarcodeWriter writer = new BarcodeWriter();
                
            // specify that writer must generate barcode of spefied type
            writer.Settings.Barcode = barcodeType;
                
            // set the barcode value items
            writer.Settings.ValueItems = new ValueItemBase[] { textData, binaryData };
                
            // create image with barcode
            return writer.GetBarcodeAsBitmapSource();
        }
                
        /// <summary>
        /// Reads barcode from image and shows the barcode value items.
        /// </summary>
        static void ReadBarcode(BitmapSource image, BarcodeType barcode)
        {
            // create the barcode reader
            using (BarcodeReader reader = new BarcodeReader())
            {
                // specify that reader must search for barcodes of specified types
                reader.Settings.ScanBarcodeTypes = barcode;
                
                // read barcode from image
                IBarcodeInfo barcodeInfo = reader.ReadBarcodes(image)[0];
                
                // for each found barcode
                for (int i = 0; i < barcodeInfo.ValueItems.Length; i++)
                {
                    // show the barcode value tems
                
                    StringBuilder itemValue = new StringBuilder();
                    if (barcodeInfo.ValueItems[i] is BinaryValueItem)
                    {
                        byte[] data = ((BinaryValueItem)barcodeInfo.ValueItems[i]).Value;
                        for (int j = 0; j < data.Length; j++)
                            itemValue.Append(string.Format("{0} ", data[j]));
                    }
                    else
                    {
                        itemValue.Append(barcodeInfo.ValueItems[i].ToString());
                    }
                    Console.WriteLine(
                        string.Format("[{0}] {1}", barcodeInfo.ValueItems[i].GetType().Name, itemValue));
                }
            }
                
            Console.WriteLine();
        }
                
    }
    Inheritance Hierarchy
    Requirements

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

    See Also