'Declaration Public Class AamvaBarcodeSymbology Inherits BarcodeSymbologySubset
public class AamvaBarcodeSymbology : BarcodeSymbologySubset
public __gc class AamvaBarcodeSymbology : public BarcodeSymbologySubset*
public ref class AamvaBarcodeSymbology : public BarcodeSymbologySubset^
Этот C#/VB.NET код показывает, как сгенерировать и распознать штрих-код AAMVA.
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
using System; using Vintasoft.Barcode; using Vintasoft.Barcode.BarcodeInfo; using Vintasoft.Barcode.SymbologySubsets; using Vintasoft.Imaging; class AAMVAExample { /// <summary> /// Generates and recognizes AAMVA barcode. /// </summary> public static void Test() { // create DL data elements AamvaDataElement[] dlElements = 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 AamvaDataElement[] zkElements = new AamvaDataElement[] { new AamvaDataElement("ZKA", "Y"), new AamvaDataElement("ZKB", "TEST"), new AamvaDataElement("ZKC", "9876"), new AamvaDataElement("ZKD", "DUP"), }; // create subfiles AamvaSubfile[] subfiles = new AamvaSubfile[]{ new AamvaSubfile("DL", dlElements), new AamvaSubfile("ZK", zkElements) }; // create AAMVA barcode value AamvaBarcodeValue barcodeValue = new AamvaBarcodeValue(AamvaVersionLevel.AAMVA2016, 636046, 0, subfiles); // generate barcode image using (VintasoftBitmap barcodeImage = Generate(barcodeValue)) { // recognize barcode value AamvaBarcodeInfo recognizedBarcode = Recognize(barcodeImage); // check value if (barcodeValue.ToString() != recognizedBarcode.AamvaValue.ToString()) throw new ApplicationException(); // 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:"); foreach (AamvaSubfile subfile in recognizedBarcode.Subfiles) { Console.WriteLine("[{0}] subfile:", subfile.SubfileType); foreach (AamvaDataElement dataElement in subfile.DataElements) { if (dataElement.Identifier.VersionLevel != AamvaVersionLevel.Undefined) Console.Write(" [{0}] {1}:", dataElement.Identifier.ID, dataElement.Identifier.Description); else Console.Write(" [{0}]:", dataElement.Identifier.ID); Console.WriteLine(" {0}", dataElement.Value); } } } } /// <summary> /// Generates the AAMVA barcode image. /// </summary> /// <param name="barcodeValue">The barcode value.</param> private static VintasoftBitmap Generate(AamvaBarcodeValue barcodeValue) { // create barcode writer using (BarcodeWriter writer = new BarcodeWriter()) { // encode AAMVA barcode to writer settings BarcodeSymbologySubsets.AAMVA.Encode(barcodeValue, writer.Settings); // generate barcode image return writer.GetBarcodeAsVintasoftBitmap(); } } /// <summary> /// Recognizes the AAMVA barcode from image. /// </summary> /// <param name="barcodeImage">The barcode image.</param> private static AamvaBarcodeInfo Recognize(VintasoftBitmap barcodeImage) { // create barcode reader using (BarcodeReader reader = new BarcodeReader()) { // specify that AAMVA barcode must be recognized reader.Settings.ScanBarcodeSubsets.Add(BarcodeSymbologySubsets.AAMVA); // recognize barcodes IBarcodeInfo info = reader.ReadBarcodes(barcodeImage)[0]; // return information about recognized AAMVA barcode return (AamvaBarcodeInfo)info; } } }
System.Object
 Vintasoft.Barcode.BarcodeSymbology
   Vintasoft.Barcode.SymbologySubsets.BarcodeSymbologySubset
     Vintasoft.Barcode.SymbologySubsets.AamvaBarcodeSymbology
Целевые платформы: .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5