VintaSoft Barcode .NET SDK v11.0
In This Topic
    Read barcodes from System.Drawing.Bitmap object
    In This Topic

    Example: Here is an example that shows how to read barcodes from System.Drawing.Bitmap object.

    Public Shared Sub ReadBarcodesFromImage(barcodeImage As Image)
            ' create barcode reader
            Using reader As New BarcodeReader()
                    ' specify that reader must search for Code39, Code39Extended,
                    ' Code128, SSCC18 and DataMatrix barcodes
                    reader.Settings.ScanBarcodeTypes = BarcodeType.Code39 Or BarcodeType.Code128 Or BarcodeType.DataMatrix
                    reader.Settings.ScanBarcodeSubsets.Add(BarcodeSymbologySubsets.Code39Extended)
                    reader.Settings.ScanBarcodeSubsets.Add(BarcodeSymbologySubsets.SSCC18)
    
                    ' specify that reader must search for horizontal and vertical barcodes only
                    reader.Settings.ScanDirection = ScanDirection.Horizontal Or ScanDirection.Vertical
    
                    ' use Automatic Recognition
                    reader.Settings.AutomaticRecognition = True
    
                    ' read barcodes from image
                    Dim infos As IBarcodeInfo() = reader.ReadBarcodes(barcodeImage)
    
                    ' if barcodes are not detected
                    If infos.Length = 0 Then
                            Console.WriteLine("No barcodes found.")
                    Else
                            ' if barcodes are detected
                            ' get information about extracted barcodes
    
                            Console.WriteLine(String.Format("{0} barcodes found:", infos.Length))
                            Console.WriteLine()
                            For i As Integer = 0 To infos.Length - 1
                                    Dim info As IBarcodeInfo = infos(i)
                                    Console.WriteLine(String.Format("[{0}:{1}]", i + 1, info.BarcodeType))
                                    Console.WriteLine(String.Format("Value:      {0}", info.Value))
                                    Console.WriteLine(String.Format("Region:     {0}", info.Region))
                                    Console.WriteLine()
                            Next
                    End If
            End Using
    End Sub
                  
    
    // The project, which uses this code, must have references to the following assemblies:
    // - Vintasoft.Barcode
    
    /// <summary>
    /// Reads barcode from an image.
    /// </summary>
    /// <param name="barcodeImage">An image with barcodes.</param>
    public static void ReadBarcodesFromImage(System.Drawing.Image barcodeImage)
    {
        // create barcode reader
        using (Vintasoft.Barcode.BarcodeReader reader = new Vintasoft.Barcode.BarcodeReader())
        {
            // specify that reader must search for Code39, Code39Extended,
            // Code128, SSCC18 and DataMatrix barcodes
            reader.Settings.ScanBarcodeTypes =
                Vintasoft.Barcode.BarcodeType.Code39 |
                Vintasoft.Barcode.BarcodeType.Code128 |
                Vintasoft.Barcode.BarcodeType.DataMatrix;
            reader.Settings.ScanBarcodeSubsets.Add(Vintasoft.Barcode.SymbologySubsets.BarcodeSymbologySubsets.Code39Extended);
            reader.Settings.ScanBarcodeSubsets.Add(Vintasoft.Barcode.SymbologySubsets.BarcodeSymbologySubsets.SSCC18);
    
            // specify that reader must search for horizontal and vertical barcodes only
            reader.Settings.ScanDirection = Vintasoft.Barcode.ScanDirection.Horizontal | Vintasoft.Barcode.ScanDirection.Vertical;
    
            // use Automatic Recognition
            reader.Settings.AutomaticRecognition = true;
    
            // read barcodes from image
            Vintasoft.Barcode.IBarcodeInfo[] infos = reader.ReadBarcodes(barcodeImage);
    
            // if barcodes are not detected
            if (infos.Length == 0)
            {
                System.Console.WriteLine("No barcodes found.");
            }
            // if barcodes are detected
            else
            {
                // get information about extracted barcodes
    
                System.Console.WriteLine(string.Format("{0} barcodes found:", infos.Length));
                System.Console.WriteLine();
                for (int i = 0; i < infos.Length; i++)
                {
                    Vintasoft.Barcode.IBarcodeInfo info = infos[i];
                    System.Console.WriteLine(string.Format("[{0}:{1}]", i + 1, info.BarcodeType));
                    System.Console.WriteLine(string.Format("Value:      {0}", info.Value));
                    System.Console.WriteLine(string.Format("Region:     {0}", info.Region));
                    System.Console.WriteLine();
                }
            }
        }
    }