コード例 #1
0
        static void Dynamsoft_Barcode_Reader_Test_Single(string file, Dynamsoft.Barcode.BarcodeReader reader)
        {
            Bitmap barcodeBitmap = (Bitmap)Image.FromFile(file);

            try
            {
                Stopwatch    swDBR   = Stopwatch.StartNew();
                TextResult[] results = reader.DecodeBitmap(barcodeBitmap, "");
                swDBR.Stop();

                if (results != null)
                {
                    //Console.WriteLine("DBR\t time: " + swDBR.Elapsed.TotalMilliseconds + "ms" + ",\t result count: " + results.Length);
                    Console.WriteLine("{0, -10}{1, -20}{2, -20}", "DBR", "time: " + swDBR.Elapsed.TotalMilliseconds + "ms", " result count: " + results.Length);
                }
                else
                {
                    //Console.WriteLine("DBR\t time: " + swDBR.Elapsed.TotalMilliseconds + "ms" + ",\t result count: failed");
                    Console.WriteLine("{0, -10}{1, -20}{2, -20}", "DBR", "time: " + swDBR.Elapsed.TotalMilliseconds + "ms", " result count: failed");
                }

                if (results != null)
                {
                    //foreach (TextResult result in results)
                    //{
                    //    Console.WriteLine(result.BarcodeFormat);
                    //    Console.WriteLine(result.BarcodeText);
                    //}
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
コード例 #2
0
 private void btnRead_Click(object sender, EventArgs e)
 {
     if (imageViewer.Image != null)
     {
         //Rectangle rect = new Rectangle();
         BarcodeReader reader = new Dynamsoft.Barcode.BarcodeReader();
         try
         {
             ReaderOptions ro = new ReaderOptions();
             ro.BarcodeFormats           = GetFormats();
             ro.MaxBarcodesToReadPerPage = int.Parse(tbMaximumNum.Text);
             reader.ReaderOptions        = ro;
             reader.LicenseKeys          = "<Input your license key here>";
             DateTime        beforeRead  = DateTime.Now;
             BarcodeResult[] barcodes    = reader.DecodeFile(filePath);
             DateTime        afterRead   = DateTime.Now;
             int             timeElapsed = (afterRead - beforeRead).Milliseconds;
             ShowBarcodeResults(barcodes, timeElapsed);
         }
         catch (Exception exp)
         {
             MessageBox.Show(exp.Message, "Barcode Reader Demo", MessageBoxButtons.OK);
         }
         finally
         {
             reader.Dispose();
         }
     }
 }
コード例 #3
0
        static void Dynamsoft_Barcode_Reader_Test(string directory)
        {
            Dynamsoft.Barcode.BarcodeReader reader = new Dynamsoft.Barcode.BarcodeReader();
            reader.LicenseKeys = "t0068NQAAAJx5X8TaH/zQIy0Mm3HHIypzFTL+DQTIQah1eCiNcZygsi6sFa0cZiJVv+rRTyU29TpFsLA6hWiz+GAlQlGrRRg=";

            string[] files = Directory.GetFiles(directory);
            foreach (string file in files)
            {
                Console.WriteLine(file);
                Bitmap barcodeBitmap = (Bitmap)Image.FromFile(file);
                try
                {
                    Stopwatch    swDBR   = Stopwatch.StartNew();
                    TextResult[] results = reader.DecodeBitmap(barcodeBitmap, "");
                    swDBR.Stop();

                    if (results != null)
                    {
                        Console.WriteLine("DBR time: " + swDBR.Elapsed.TotalMilliseconds + "ms" + ", result count: " + results.Length);
                    }
                    else
                    {
                        Console.WriteLine("DBR time: " + swDBR.Elapsed.TotalMilliseconds + "ms" + ", result count: failed");
                    }

                    if (results != null)
                    {
                        //foreach (TextResult result in results)
                        //{
                        //    Console.WriteLine(result.BarcodeFormat);
                        //    Console.WriteLine(result.BarcodeText);
                        //}
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }

                Console.WriteLine("\n");
            }
        }
コード例 #4
0
        static void ZXing_DBR_Test(string directory)
        {
            Dynamsoft.Barcode.BarcodeReader reader = new Dynamsoft.Barcode.BarcodeReader();
            reader.LicenseKeys = "t0068NQAAAJx5X8TaH/zQIy0Mm3HHIypzFTL+DQTIQah1eCiNcZygsi6sFa0cZiJVv+rRTyU29TpFsLA6hWiz+GAlQlGrRRg=";

            ZXing.MultiFormatReader multiFormatReader = new ZXing.MultiFormatReader();
            ZXing.Multi.GenericMultipleBarcodeReader multiBarcodeReader = new ZXing.Multi.GenericMultipleBarcodeReader(multiFormatReader);

            string[] files = Directory.GetFiles(directory);
            foreach (string file in files)
            {
                Console.WriteLine(file);
                Console.BackgroundColor = ConsoleColor.Blue;
                ZXing_Test_Single(file, multiBarcodeReader);
                Console.ResetColor();

                Console.BackgroundColor = ConsoleColor.Red;
                Dynamsoft_Barcode_Reader_Test_Single(file, reader);
                Console.ResetColor();
                Console.WriteLine("\n");
            }
        }
コード例 #5
0
 private void btnRead_Click(object sender, EventArgs e)
 {
     if (imageViewer.Image != null)
     {
         //Rectangle rect = new Rectangle();
         BarcodeReader reader = new Dynamsoft.Barcode.BarcodeReader();
         try
         {
             ReaderOptions ro = new ReaderOptions();
             ro.BarcodeFormats = GetFormats();
             ro.MaxBarcodesToReadPerPage = int.Parse(tbMaximumNum.Text);
             reader.ReaderOptions = ro;
             reader.LicenseKeys = "<Input your license key here>";
             DateTime beforeRead = DateTime.Now;
             BarcodeResult[] barcodes = reader.DecodeFile(filePath);
             DateTime afterRead = DateTime.Now;
             int timeElapsed = (afterRead - beforeRead).Milliseconds;
             ShowBarcodeResults(barcodes, timeElapsed);
         }
         catch (Exception exp)
         {
             MessageBox.Show(exp.Message, "Barcode Reader Demo", MessageBoxButtons.OK);
         }
         finally
         {
             reader.Dispose();
         }
     }
 }
コード例 #6
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (m_ImageCore.ImageBuffer.CurrentImageIndexInBuffer < 0)
            {
                MessageBox.Show("Please load an image before reading barcode!", "Index out of bounds", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            try
            {
                Dynamsoft.Barcode.BarcodeReader reader = new Dynamsoft.Barcode.BarcodeReader();
                reader.LicenseKeys = m_StrProductKey;
                reader.ReaderOptions.MaxBarcodesToReadPerPage = int.Parse(tbxMaxNum.Text);
                this.textBox1.Text = "";
                switch (cbxFormat.SelectedIndex)
                {
                case 0:
                    break;

                case 1:
                    reader.ReaderOptions.BarcodeFormats = Dynamsoft.Barcode.BarcodeFormat.OneD;
                    break;

                case 2:
                    reader.ReaderOptions.BarcodeFormats = Dynamsoft.Barcode.BarcodeFormat.CODE_39;
                    break;

                case 3:
                    reader.ReaderOptions.BarcodeFormats = Dynamsoft.Barcode.BarcodeFormat.CODE_128;
                    break;

                case 4:
                    reader.ReaderOptions.BarcodeFormats = Dynamsoft.Barcode.BarcodeFormat.CODE_93;
                    break;

                case 5:
                    reader.ReaderOptions.BarcodeFormats = Dynamsoft.Barcode.BarcodeFormat.CODABAR;
                    break;

                case 6:
                    reader.ReaderOptions.BarcodeFormats = Dynamsoft.Barcode.BarcodeFormat.ITF;
                    break;

                case 7:
                    reader.ReaderOptions.BarcodeFormats = Dynamsoft.Barcode.BarcodeFormat.EAN_13;
                    break;

                case 8:
                    reader.ReaderOptions.BarcodeFormats = Dynamsoft.Barcode.BarcodeFormat.EAN_8;
                    break;

                case 9:
                    reader.ReaderOptions.BarcodeFormats = Dynamsoft.Barcode.BarcodeFormat.UPC_A;
                    break;

                case 10:
                    reader.ReaderOptions.BarcodeFormats = Dynamsoft.Barcode.BarcodeFormat.UPC_E;
                    break;

                case 11:
                    reader.ReaderOptions.BarcodeFormats = Dynamsoft.Barcode.BarcodeFormat.PDF417;
                    break;

                case 12:
                    reader.ReaderOptions.BarcodeFormats = Dynamsoft.Barcode.BarcodeFormat.QR_CODE;
                    break;

                case 13:
                    reader.ReaderOptions.BarcodeFormats = Dynamsoft.Barcode.BarcodeFormat.DATAMATRIX;
                    break;

                case 14:
                    reader.ReaderOptions.BarcodeFormats = Dynamsoft.Barcode.BarcodeFormat.INDUSTRIAL_25;
                    break;
                }
                this.textBox1.Text = "Recognizing...";
                BarcodeResult[] aryResult = null;
                Rectangle       rect      = dsViewer1.GetSelectionRect(m_ImageCore.ImageBuffer.CurrentImageIndexInBuffer);
                if (rect == Rectangle.Empty)
                {
                    int iWidth  = m_ImageCore.ImageBuffer.GetBitmap(m_ImageCore.ImageBuffer.CurrentImageIndexInBuffer).Width;
                    int iHeight = m_ImageCore.ImageBuffer.GetBitmap(m_ImageCore.ImageBuffer.CurrentImageIndexInBuffer).Height;
                    rect = new Rectangle(0, 0, iWidth, iHeight);
                }
                reader.AddRegion(rect.Left, rect.Top, rect.Right, rect.Bottom, false);
                aryResult = reader.DecodeBitmap((Bitmap)(m_ImageCore.ImageBuffer.GetBitmap(m_ImageCore.ImageBuffer.CurrentImageIndexInBuffer)));

                StringBuilder strText = new StringBuilder();
                if (aryResult == null)
                {
                    this.textBox1.Text = "The barcode for selected format is not found.\r\n";
                }
                else
                {
                    strText.AppendFormat(aryResult.Length + " total barcode" + (aryResult.Length == 1 ? "" : "s") + " found.\r\n");
                    for (int i = 0; i < aryResult.Length; i++)
                    {
                        BarcodeResult objResult = aryResult[i];
                        strText.AppendFormat("      Result " + (i + 1) + "\r\n");
                        strText.AppendFormat("      BarcodeFormat: " + objResult.BarcodeFormat.ToString() + "\r\n");
                        strText.AppendFormat("      Text read:{0}\r\n", objResult.BarcodeText);
                    }
                    this.textBox1.Text = strText.ToString();
                }
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message, "Decoding error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.textBox1.Text = "";
            }
        }