This section includes two parts. One is C# class code for Code 39 reading from image and the other is VB.NET class code for Code 39 reading from image. And we take local image file as image source in the two examples. Certainly, you are able to load an image source in bitmap or stream form. Furthermore, the way of bar code recognition in C# & VB.NET is user-defined, including scanning a target barcode symbol and scanning all barcode types from loaded image file. Please note, reading the color barcode is also supported.
C# Class Code: Read Code 39 1D Barcode
From the following Visual C# class coding examples, we tell how to detect and read Code 39 linear barcode from a local image file. And Code 39 is the target barcode type. More APIs can also be found in the following demo codes.
public void ScanCode39FromFile(string filename) { // Code 39 detecting and reading from a local image file in C#.NET class. BarcodeResult[] results = BarCodeScanner.Scan(filename, BarCodeType.Code39); // Code 39 detecting and reading from a Bitmap or Stream of image in C#.NET class. // 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); } }
// Used to improve barcode scanner accuracy when there's only one Code 39 on image. Bitmap bmp = new Bitmap("YourImagePath"); BarcodeResult barcode = BarCodeScanner.ScanSingle(bmp); Console.WriteLine("barcode data:{0}.", barcode.Data);
VB.NET Class Code: Read Code 39 1D Barcode
Similarly, the first Visual Basic class coding example tells how to detect and recognize all barcode types from an image file on your local disk. Besides Code 39, other barcode symbols on the image will be decoded and output. VB.NET APIs for barcodes decoding from bitmap and stream of image are also provided in this demo code. Moreover, you can learn how to improve barcode reading accuracy when your image source only includes one Code 39 barcode.
Public Sub ScanAllFromFile(ByVal filename As String) ' Detect and recognize all barcode types from a local image file in VB.NET class. Dim results() As BarcodeResult = BarCodeScanner.Scan(filename) ' Detect and decode all barcode types from Bitmap or Stream of image in VB.NET class. ' 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
' Used to improve barcode scanner accuracy when there's only one Code 39 on image. Dim bmp As Bitmap = New Bitmap("YourImagePath") Dim barcode As BarcodeResult = BarCodeScanner.ScanSingle(bmp) Console.WriteLine("barcode data:{0}.", barcode.Data)