none
Convert an image containing barcode to numbers RRS feed

  • Question

  • Convert an image containing  Barcode code 128 to numbers or string

    Extract barcode values from images containing bar code 

    Thursday, November 9, 2017 12:47 AM

Answers

  • Here's a really nice library for deciphering data from barcodes that you may want to try:

    http://www.keepdynamic.com/dotnet-barcode-reader/

    Very cheap too!

    [EDIT]

    Perhaps a better solution however: http://www.bardecode.com/en1/reading-barcodes-in-vbnet/

    This link explains very clearly how to add a reference to the dll and gives an example on how to program it after:

    ' Copied from site - just to clarify, you must download and add the reference from the site for this to work.
    Dim barcode As SoftekBarcodeLib3.BarcodeReader
    
            Try
                barcode = New SoftekBarcodeLib3.BarcodeReader("\path\to\the\sdk\installation\folder")
            Catch ex As System.DllNotFoundException
                MessageBox.Show("Could not locate the Softek Barcode Reader SDK Installation Folder")
                Return
            End Try
    
            barcode.MultipleRead = True
    
            Dim nBarCodes As Integer
    
            nBarCodes = barcode.ScanBarCode("somefile.tif")
    
            Dim i As Integer
    
            For i = 1 To nBarCodes
                MessageBox.Show("Found barcode with value " & barcode.GetBarString(i))
            Next

    This will almost certainly be useful to you.

    Hope this helps :)


    PS: Regrading the safety of the file, I scanned it and it appears to be safe, however use with caution and at your own risk!
    • Edited by Lucy Qu Thursday, November 9, 2017 2:03 AM
    • Marked as answer by ahmeddc Thursday, November 9, 2017 7:29 AM
    Thursday, November 9, 2017 1:58 AM
  • Hi ahmeddc,

    Read barcode data from barcode images is fairly simple with Free Spire.Barcode library. You can get Free Spire.Barcode dll from NuGet and then reference the following code, the code is in C# but I think you can manage to convert it to vb. I've already tried the code and it worked well.

    using System;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using Spire.Barcode;
    
    namespace ScanBarcode
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void btnLoadImage_Click(object sender, EventArgs e)
            {
                Image image = Image.FromFile("1156069.png");
                pictureBox1.Image = image;
            }
    
            private void btnReadData_Click(object sender, EventArgs e)
            {
                Bitmap bitmap = new Bitmap(pictureBox1.Image);
                string[] datas = BarcodeScanner.Scan(bitmap, BarCodeType.Code128);
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < datas.Length; i++)
                {
                    sb.Append(datas[i]);
                }
                String s = sb.ToString();
    
                textBox1.Text = s;
            }
        }
    }
    

    Screenshot:

    

    Hope it's helpful to you.

    • Marked as answer by ahmeddc Thursday, November 9, 2017 7:29 AM
    Thursday, November 9, 2017 2:32 AM
  • Hi ahmeddc,

    Firstly please install Spire.Barcode dll from Manage Nugets packages..., and then try the following code:

     Dim fileName As String = "D:\Picture\8.png"
            Dim datas As String() = BarcodeScanner.Scan(fileName, BarCodeType.Code128)
            For Each data As String In datas
                Console.WriteLine(data)
            Next

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by ahmeddc Thursday, November 9, 2017 7:29 AM
    Thursday, November 9, 2017 5:55 AM
    Moderator

All replies

  • Hi

    Check out THIS link which may help.


    Regards Les, Livingston, Scotland

    • Proposed as answer by Frank L. Smith Thursday, November 9, 2017 1:52 AM
    Thursday, November 9, 2017 1:17 AM
  • Hi

    Check out THIS link which may help.


    Regards Les, Livingston, Scotland

    I tried before asking the question but the program does not do this code with me
    Thursday, November 9, 2017 1:53 AM
  • Here's a really nice library for deciphering data from barcodes that you may want to try:

    http://www.keepdynamic.com/dotnet-barcode-reader/

    Very cheap too!

    [EDIT]

    Perhaps a better solution however: http://www.bardecode.com/en1/reading-barcodes-in-vbnet/

    This link explains very clearly how to add a reference to the dll and gives an example on how to program it after:

    ' Copied from site - just to clarify, you must download and add the reference from the site for this to work.
    Dim barcode As SoftekBarcodeLib3.BarcodeReader
    
            Try
                barcode = New SoftekBarcodeLib3.BarcodeReader("\path\to\the\sdk\installation\folder")
            Catch ex As System.DllNotFoundException
                MessageBox.Show("Could not locate the Softek Barcode Reader SDK Installation Folder")
                Return
            End Try
    
            barcode.MultipleRead = True
    
            Dim nBarCodes As Integer
    
            nBarCodes = barcode.ScanBarCode("somefile.tif")
    
            Dim i As Integer
    
            For i = 1 To nBarCodes
                MessageBox.Show("Found barcode with value " & barcode.GetBarString(i))
            Next

    This will almost certainly be useful to you.

    Hope this helps :)


    PS: Regrading the safety of the file, I scanned it and it appears to be safe, however use with caution and at your own risk!
    • Edited by Lucy Qu Thursday, November 9, 2017 2:03 AM
    • Marked as answer by ahmeddc Thursday, November 9, 2017 7:29 AM
    Thursday, November 9, 2017 1:58 AM
  • You can use  free Spire.Barcode to read the data from barcode image using the following code

    string barcodeData = BarcodeScanner.ScanOne("picPath");



    Thursday, November 9, 2017 2:12 AM
  • Hi ahmeddc,

    Read barcode data from barcode images is fairly simple with Free Spire.Barcode library. You can get Free Spire.Barcode dll from NuGet and then reference the following code, the code is in C# but I think you can manage to convert it to vb. I've already tried the code and it worked well.

    using System;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using Spire.Barcode;
    
    namespace ScanBarcode
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void btnLoadImage_Click(object sender, EventArgs e)
            {
                Image image = Image.FromFile("1156069.png");
                pictureBox1.Image = image;
            }
    
            private void btnReadData_Click(object sender, EventArgs e)
            {
                Bitmap bitmap = new Bitmap(pictureBox1.Image);
                string[] datas = BarcodeScanner.Scan(bitmap, BarCodeType.Code128);
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < datas.Length; i++)
                {
                    sb.Append(datas[i]);
                }
                String s = sb.ToString();
    
                textBox1.Text = s;
            }
        }
    }
    

    Screenshot:

    

    Hope it's helpful to you.

    • Marked as answer by ahmeddc Thursday, November 9, 2017 7:29 AM
    Thursday, November 9, 2017 2:32 AM
  • Hi ahmeddc,

    Firstly please install Spire.Barcode dll from Manage Nugets packages..., and then try the following code:

     Dim fileName As String = "D:\Picture\8.png"
            Dim datas As String() = BarcodeScanner.Scan(fileName, BarCodeType.Code128)
            For Each data As String In datas
                Console.WriteLine(data)
            Next

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by ahmeddc Thursday, November 9, 2017 7:29 AM
    Thursday, November 9, 2017 5:55 AM
    Moderator