private void QRWorkerMethod(object sender, CertificateScanner.WaiteWindow.WaitWindowEventArgs e) { try { var sourceimg = (Bitmap)e.Arguments[0]; ContrastStretch filter = new ContrastStretch(); sourceimg = filter.Apply(sourceimg); sourceimg = filter.Apply(sourceimg); sourceimg = filter.Apply(sourceimg); Median f1 = new Median(); sourceimg = f1.Apply(sourceimg); sourceimg = f1.Apply(sourceimg); sourceimg = f1.Apply(sourceimg); Blur filter2 = new Blur(); sourceimg = filter2.Apply(sourceimg); sourceimg = filter2.Apply(sourceimg); //sourceimg.Save("d:\\tst.jpg", ImageFormat.Jpeg); //System.Diagnostics.Process.Start("d:\\tst.jpg"); com.google.zxing.LuminanceSource source = new RGBLuminanceSource(sourceimg, sourceimg.Width, sourceimg.Height); com.google.zxing.Binarizer binarizer = new com.google.zxing.common.HybridBinarizer(source); com.google.zxing.qrcode.QRCodeReader reader = new com.google.zxing.qrcode.QRCodeReader(); var result = reader.decode(new com.google.zxing.BinaryBitmap(binarizer)); e.Result = result.Text; } catch (Exception ex) { e.Result = "12323123213123"; this.Warn(ex, this.Messages("qrFail")); } }
void captureSource_CaptureImageCompleted(object sender, CaptureImageCompletedEventArgs e) { com.google.zxing.qrcode.QRCodeReader qrRead = new com.google.zxing.qrcode.QRCodeReader(); //This is like a platform neutral way of identifying colors in an image RGBLuminanceSource luminiance = new RGBLuminanceSource(e.Result, e.Result.PixelWidth, e.Result.PixelHeight); //The next 2 things are used to change color to black and white to be read by the reader com.google.zxing.common.HybridBinarizer binarizer = new com.google.zxing.common.HybridBinarizer(luminiance); com.google.zxing.BinaryBitmap binBitmap = new com.google.zxing.BinaryBitmap(binarizer); com.google.zxing.Result results = default(com.google.zxing.Result); try { //barcode found results = qrRead.decode(binBitmap); capturedBarcodes.Items.Insert(0, new ScannedImage(results.Text, e.Result)); capturedBarcodes.SelectedIndex = 0; mediaElement1.Stop(); mediaElement1.Play(); ImageBrush brush = new ImageBrush(); brush.ImageSource = e.Result; capturedImage.Fill = brush; } catch (com.google.zxing.ReaderException) { //no barcode found if (captureSource.State == CaptureState.Started) { captureSource.CaptureImageAsync(); } } catch (Exception ex) { MessageBox.Show(ex.Message); StartButton_Click(this, new RoutedEventArgs()); } try { BarcodeRead(this, new CustomEventHandler() { Barcode = results.Text }); } catch (Exception) { //no javascript event attached } }