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