static void ZXing_Test_Single(string file, ZXing.Multi.GenericMultipleBarcodeReader multiBarcodeReader)
        {
            Bitmap          bitmap = (Bitmap)Image.FromFile(file);
            LuminanceSource source = new BitmapLuminanceSource(bitmap);

            ZXing.BinaryBitmap bBitmap = new ZXing.BinaryBitmap(new HybridBinarizer(source));
            Stopwatch          swZXing = Stopwatch.StartNew();

            ZXing.Result[] zResults = multiBarcodeReader.decodeMultiple(bBitmap);
            swZXing.Stop();

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

            if (zResults != null)
            {
                //foreach (ZXing.Result zResult in zResults)
                //{
                //    Console.WriteLine("ZXing result: " + zResult.Text);
                //}
            }
        }
예제 #2
0
 private void Scan(object sender, EventArgs e)
 {
     using (System.IO.Stream stream = webRes.GetResponseStream())
     {
         Bitmap            img    = new Bitmap(Image.FromStream(stream));
         MultiFormatReader reader = new MultiFormatReader();
         ZXing.Multi.GenericMultipleBarcodeReader barcodeReader = new ZXing.Multi.GenericMultipleBarcodeReader(reader);
         if (img != null)
         {
             pictureBox1.Image = img;
             LuminanceSource source       = new BitmapLuminanceSource(img);
             BinaryBitmap    binaryBitmap = new BinaryBitmap(new ZXing.Common.HybridBinarizer(source));
             Result[]        results      = barcodeReader.decodeMultiple(binaryBitmap);
             if (results != null)
             {
                 timer.Stop();
                 foreach (Result result in results)
                 {
                     //firstly upload img.
                     //Because that server communication with algorithm after getting projectInfo
                     //sync not async
                     UploadProImg(img);                             //upload project img
                     Thread.Sleep(500);                             //process wait 500, socket sync is stupid
                     string identifyResult = UploadProInfo(result); //prase project info and upload
                     MessageBox.Show(identifyResult);
                 }
             }
         }
     }
 }
        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");
            }
        }
        static void ZXing_Test(string directory)
        {
            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);
                Bitmap             bitmap   = (Bitmap)Image.FromFile(file);
                LuminanceSource    source   = new BitmapLuminanceSource(bitmap);
                ZXing.BinaryBitmap bBitmap  = new ZXing.BinaryBitmap(new HybridBinarizer(source));
                Stopwatch          swZXing  = Stopwatch.StartNew();
                ZXing.Result[]     zResults = multiBarcodeReader.decodeMultiple(bBitmap);
                swZXing.Stop();

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

                if (zResults != null)
                {
                    //foreach (ZXing.Result zResult in zResults)
                    //{
                    //    Console.WriteLine("ZXing result: " + zResult.Text);
                    //}
                }

                Console.WriteLine("\n");
            }
        }