Our barcode recognition dll for C# and VB.NET provides professional APIs for reading EAN-13 barcode from three forms of images, namely bitmap, stream and string. And the supportive image formats are bmp, gif, jpeg/jpg, png, and tiff/tif. Furthermore, C# and VB.NET developers are entitled to define the target barcode type as EAN-13 with specific APIs, please see details in the demo code below.
In the following parts, you will get Visual C# and Visual Basic demo codes for scanning EAN-13 barcodes from image files. The first C# demo code is used to define EAN-13 as the target barcode and only this barcode type will be decoded. If there are other barcode types besides EAN-13 on your image source and are needed to be recognized, the second VB.NET demo is helpful which illustrates how to read all barcode types from image source.
C# Demo for EAN-13 Recognition
public void ScanEAN13FromFile(string filename) { // Define EAN-13 as target barcode and decode all of them from image source. BarcodeResult[] results = BarCodeScanner.Scan(filename, BarCodeType.EAN13); // Use APIs below to decode EAN-13 from images in Bitmap and Stream forms. // public static BarcodeResult[] Scan(Bitmap bitmap, BarCodeType barType); // public static BarcodeResult[] Scan(Stream stream, BarCodeType barType); foreach (BarcodeResult result in results) { Console.WriteLine(result.BarType.ToString() + "-" + result.Data); } }
// If your image only has one EAN-13, please try this way to improve barcode decoder accuracy. Bitmap bmp = new Bitmap("YourImagePath"); BarcodeResult barcode = BarCodeScanner.ScanSingle(bmp); Console.WriteLine("barcode data:{0}.", barcode.Data);
VB.NET Demo for EAN-13 Recognition
Public Sub ScanAllFromFile(ByVal filename As String) ' Used to recognize all barcode types from image source in string form. Dim results() As BarcodeResult = BarCodeScanner.Scan(filename) ' Use APIs below to read all barcode types from images in Bitmap and Stream forms. ' public static BarcodeResult[] Scan(Bitmap bitmap) ' public static BarcodeResult[] Scan(Stream stream) Dim result As BarcodeResult For Each result In results Console.WriteLine(result.BarType.ToString() + "-" + result.Data) Next End Sub
' If your image only has one EAN-13, please try this way to improve barcode decoder accuracy. Dim bmp As Bitmap = New Bitmap("YourImagePath") Dim barcode As BarcodeResult = BarCodeScanner.ScanSingle(bmp) Console.WriteLine("barcode data:{0}.", barcode.Data)
For more information about C# and VB.NET barcode scanning, please refer to online tutorials: .NET Barcode Reader DLL: C# Guide and .NET Barcode Reader DLL: VB.NET Guide. Currently, recognizing EAN-13 barcode from PDF document is supported as well. If you want to do this, please firstly render PDF document pages into image files by using pqScan PDF to Image Converter SDK and then load them into C#/VB.NET barcode reading project.