Imports Vintasoft.Barcode
Imports Vintasoft.Barcode.BarcodeInfo
Imports Vintasoft.Barcode.SymbologySubsets
Imports Vintasoft.Imaging
Class AAMVAExample
''' <summary>
''' Generates and recognizes AAMVA barcode.
''' </summary>
Public Shared Sub Test()
' create DL data elements
Dim dlElements As AamvaDataElement() = New AamvaDataElement() {New AamvaDataElement(AamvaDataElementIdentifiers.DAQ, "C12345678"), New AamvaDataElement(AamvaDataElementIdentifiers.DCS, "CARPENTER"), New AamvaDataElement(AamvaDataElementIdentifiers.DDE, "N"), New AamvaDataElement(AamvaDataElementIdentifiers.DAC, "JON"), New AamvaDataElement(AamvaDataElementIdentifiers.DDF, "N"), New AamvaDataElement(AamvaDataElementIdentifiers.DAD, "T"), _
New AamvaDataElement(AamvaDataElementIdentifiers.DDG, "N"), New AamvaDataElement(AamvaDataElementIdentifiers.DCA, "D"), New AamvaDataElement(AamvaDataElementIdentifiers.DCB, "1"), New AamvaDataElement(AamvaDataElementIdentifiers.DCD, "NONE"), New AamvaDataElement(AamvaDataElementIdentifiers.DBD, "10052015"), New AamvaDataElement(AamvaDataElementIdentifiers.DBB, "07241984"), _
New AamvaDataElement(AamvaDataElementIdentifiers.DBA, "01092022"), New AamvaDataElement(AamvaDataElementIdentifiers.DBC, "1"), New AamvaDataElement(AamvaDataElementIdentifiers.DAU, "067 in"), New AamvaDataElement(AamvaDataElementIdentifiers.DAY, "BLK"), New AamvaDataElement(AamvaDataElementIdentifiers.DAG, "3211 SANCTUARY LANE"), New AamvaDataElement(AamvaDataElementIdentifiers.DAI, "LOUISVILLE"), _
New AamvaDataElement(AamvaDataElementIdentifiers.DAJ, "KY"), New AamvaDataElement(AamvaDataElementIdentifiers.DAK, "123454321"), New AamvaDataElement(AamvaDataElementIdentifiers.DCF, "9876543210123456"), New AamvaDataElement(AamvaDataElementIdentifiers.DCG, "USA"), New AamvaDataElement(AamvaDataElementIdentifiers.DCK, "1234567890123456"), New AamvaDataElement(AamvaDataElementIdentifiers.DDB, "01062016")}
' create ZK data elements
Dim zkElements As AamvaDataElement() = New AamvaDataElement() {New AamvaDataElement("ZKA", "Y"), New AamvaDataElement("ZKB", "TEST"), New AamvaDataElement("ZKC", "9876"), New AamvaDataElement("ZKD", "DUP")}
' create subfiles
Dim subfiles As AamvaSubfile() = New AamvaSubfile() {New AamvaSubfile("DL", dlElements), New AamvaSubfile("ZK", zkElements)}
' create AAMVA barcode value
Dim barcodeValue As New AamvaBarcodeValue(AamvaVersionLevel.AAMVA2016, 636046, 0, subfiles)
' generate barcode image
Using barcodeImage As VintasoftBitmap = Generate(barcodeValue)
' recognize barcode value
Dim recognizedBarcode As AamvaBarcodeInfo = Recognize(barcodeImage)
' check value
If barcodeValue.ToString() <> recognizedBarcode.AamvaValue.ToString() Then
Throw New ApplicationException()
End If
' print value
Console.WriteLine("Version: {0}", recognizedBarcode.VersionLevel)
Console.WriteLine("Country: {0}", recognizedBarcode.CountryId)
Console.WriteLine("IIN: {0}", recognizedBarcode.IssuerIdentificationNumber)
Console.WriteLine("License number: {0}", recognizedBarcode.LicenseNumber)
Console.WriteLine("First name: {0}", recognizedBarcode.FirstName)
Console.WriteLine("Family name: {0}", recognizedBarcode.FamilyName)
Console.WriteLine("Middle name: {0}", recognizedBarcode.MiddleName)
Console.WriteLine("Sex (1=M;2=F): {0}", recognizedBarcode.Sex)
Console.WriteLine("Eye color: {0}", recognizedBarcode.EyeColor)
Console.WriteLine("Date of birth: {0}", recognizedBarcode.DateOfBirth.ToShortDateString())
Console.WriteLine("Issue date: {0}", recognizedBarcode.IssueDate.ToShortDateString())
Console.WriteLine("Expiration date: {0}", recognizedBarcode.ExpirationDate.ToShortDateString())
Console.WriteLine("State code: {0}", recognizedBarcode.AddressStateCode)
Console.WriteLine("City: {0}", recognizedBarcode.AddressCity)
Console.WriteLine("Postal code: {0}", recognizedBarcode.AddressPostalCode)
Console.WriteLine("Street: {0}", recognizedBarcode.AddressStreet1)
Console.WriteLine()
Console.WriteLine("Data elements:")
For Each subfile As AamvaSubfile In recognizedBarcode.Subfiles
Console.WriteLine("[{0}] subfile:", subfile.SubfileType)
For Each dataElement As AamvaDataElement In subfile.DataElements
If dataElement.Identifier.VersionLevel <> AamvaVersionLevel.Undefined Then
Console.Write(" [{0}] {1}:", dataElement.Identifier.ID, dataElement.Identifier.Description)
Else
Console.Write(" [{0}]:", dataElement.Identifier.ID)
End If
Console.WriteLine(" {0}", dataElement.Value)
Next
Next
End Using
End Sub
''' <summary>
''' Generates the AAMVA barcode image.
''' </summary>
''' <param name="barcodeValue">The barcode value.</param>
Private Shared Function Generate(barcodeValue As AamvaBarcodeValue) As VintasoftBitmap
' create barcode writer
Using writer As New BarcodeWriter()
' encode AAMVA barcode to writer settings
BarcodeSymbologySubsets.AAMVA.Encode(barcodeValue, writer.Settings)
' generate barcode image
Return writer.GetBarcodeAsVintasoftBitmap()
End Using
End Function
''' <summary>
''' Recognizes the AAMVA barcode from image.
''' </summary>
''' <param name="barcodeImage">The barcode image.</param>
Private Shared Function Recognize(barcodeImage As VintasoftBitmap) As AamvaBarcodeInfo
' create barcode reader
Using reader As New BarcodeReader()
' specify that AAMVA barcode must be recognized
reader.Settings.ScanBarcodeSubsets.Add(BarcodeSymbologySubsets.AAMVA)
' recognize barcodes
Dim info As IBarcodeInfo = reader.ReadBarcodes(barcodeImage)(0)
' return information about recognized AAMVA barcode
Return DirectCast(info, AamvaBarcodeInfo)
End Using
End Function
End Class