Quantcast
Channel: Aspose.BarCode Product Family
Viewing all articles
Browse latest Browse all 333

Bar Code random numbers

$
0
0
Hello, We are using your bar code product Lic ver 3.0, the issue we are having when it reads bar code we see random numbers, also some of the tif file does not read. In the screen shot second part is bar code stating with 99 but first part (3141764) we are not sure where that came from. Sometimes it gives some random number our bar code starts with 99, Attach 2 screen shots examples. Here is the code we need your help. 

thanks
Solomon 
 

namespace BarcodeTester
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            var x = this.openFileDialog1.ShowDialog();
            if (x == System.Windows.Forms.DialogResult.OK)
            {
                this.textBox1.Text = this.openFileDialog1.FileName;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.dataGridView1.DataSource = GetDataTable();
            this.dataGridView1.Refresh();

            if (string.IsNullOrWhiteSpace(this.textBox1.Text))
            {
                MessageBox.Show("Enter File");
                this.textBox1.Focus();
                return;
            }

            if (!(File.Exists(this.textBox1.Text.Trim())))
            {
                MessageBox.Show("File not found");
                this.textBox1.Focus();
                return;
            }

            this.dataGridView1.DataSource = this.Process(this.textBox1.Text.Trim());
        }

        private static DataTable GetDataTable()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("Document #", typeof(int));
            dt.Columns.Add("BarCode");
            return dt;
        }

        public DataTable Process(string FilePath)
        {
            DataTable dt = GetDataTable();

            if (File.Exists(FilePath))
            {
                using (Image img = GetImage(FilePath))
                {
                    int totalFrame = img.GetFrameCount(FrameDimension.Page);

                    if (totalFrame > 0)
                    {
                        Aspose.BarCode.License license = new Aspose.BarCode.License();
                        license.SetLicense("Aspose.BarCode.lic");

                        string BarCodeReadType = ConfigurationManager.AppSettings["BarCodeReadType"];
                        string BarCodePrefix = ConfigurationManager.AppSettings["BarCodePrefix"];

                       // IEnumerable<RecognitionHints.Orientation> directions = Enum.GetValues(typeof(RecognitionHints.Orientation)).Cast<RecognitionHints.Orientation>();

                        int i = 0;
                        while (i < totalFrame)
                        {
                            DataRow dr = dt.NewRow();
                            dr[0] = i + 1;

                            // Set the active page and feed it to the BarCodeReader
                            img.SelectActiveFrame(FrameDimension.Page, i);

                            using (Bitmap page = new Bitmap(img))
                            {
                                List<string> bam = new List<string>();
                              //  int j = 0;
                             //   while ((j < directions.Count()))
                             //   {

                              
                                using (BarCodeReader reader = new BarCodeReader(page, (BarCodeReadType) Enum.Parse(typeof(BarCodeReadType), BarCodeReadType)))
                                {
                                   
                            
                                    reader.ImageBinarizationHints = RecognitionHints.ImageBinarization.MedianSmoothing;
                                  //  reader.OrientationHints = directions.ElementAt(j);
                                    

                                    while (reader.Read()) // && dr.IsNull("BarCode"))
                                    {
                                        bam.Add(reader.GetCodeText());
                                    }

                                    reader.Close();
                                }

                                //    j++;
                                //}

                                string s = null;
                                foreach (string s2 in bam)
                                {
                                    if (s != null)
                                        s += ',';
                                    s += s2;
                                }

                                dr["BarCode"] = s;
                            }

                            dt.Rows.Add(dr);
                            i++;
                        }
                    }
                }
            }

            return dt;
        }

        public Image GetImage(string filePath)
        {
            Image img = null;

            bool wait = false;
            while (img == null)
            {
                if (wait)
                    System.Threading.Thread.Sleep(1000);
                else
                    wait = true;

                try
                {
                    img = Image.FromFile(filePath);
                }
                catch { };
            }

            return img;
        }
    }
}


Viewing all articles
Browse latest Browse all 333

Latest Images

Trending Articles



Latest Images