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); //} } }
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_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"); } }