private void ScanPreviewBuffer() { if (_photoCamera == null) { return; } if (!_initialized) { return; } try { _photoCamera.GetPreviewBufferY(_luminance.PreviewBufferY); var binarizer = new com.google.zxing.common.HybridBinarizer(_luminance); var binBitmap = new BinaryBitmap(binarizer); var result = _reader.decode(binBitmap); OnDecodingCompleted(result); } catch (Exception) { // If decoding fails it will throw a ReaderException // and we're not interested in doing anything with it } }
//takes the video input and creates a bitmap of the image BinaryBitmap GetBitmapFromVideo(PhotoCamera cam) { BinaryBitmap binaryBitmap = null; try { // Update buffer size var pixelWidth = (int)_cam.PreviewResolution.Width; var pixelHeight = (int)_cam.PreviewResolution.Height; if (_buffer == null || _buffer.Length != (pixelWidth * pixelHeight)) { _buffer = new byte[pixelWidth * pixelHeight]; } _cam.GetPreviewBufferY(_buffer); var luminance = new RGBLuminanceSource(_buffer, pixelWidth, pixelHeight, true); var binarizer = new com.google.zxing.common.HybridBinarizer(luminance); binaryBitmap = new BinaryBitmap(binarizer); } catch { } return binaryBitmap; }
protected void btnDecode_Click(object sender, EventArgs e) { if (Convert.ToString(Session["isDefaultImage"]) == "IsDefault") { lblErrorDecode.Text = "Upload QR Code First!"; lblErrorDecode.ForeColor = System.Drawing.Color.Red; return; } property.path = Server.MapPath("~/Images/QR_Codes/" + "img.bmp"); System.Drawing.Image image = System.Drawing.Image.FromStream(new MemoryStream(File.ReadAllBytes(property.path))); Bitmap bitMap = new Bitmap(image); try { com.google.zxing.LuminanceSource source = new RGBLuminanceSource(bitMap, bitMap.Width, bitMap.Height); var binarizer = new com.google.zxing.common.HybridBinarizer(source); var binBitmap = new com.google.zxing.BinaryBitmap(binarizer); QRCodeReader qrCodeReader = new QRCodeReader(); com.google.zxing.Result str = qrCodeReader.decode(binBitmap); txtDecodedOriginalInfo.Text = str.ToString(); lblErrorDecode.Text = "Successfully Decoded!"; lblErrorDecode.ForeColor = System.Drawing.Color.Green; } catch { } }
BinaryBitmap GetBitmapFromVideo(PhotoCamera cam) { BinaryBitmap binaryBitmap = null; try { // Update buffer size var pixelWidth = (int)_cam.PreviewResolution.Width; var pixelHeight = (int)_cam.PreviewResolution.Height; if (_buffer == null || _buffer.Length != (pixelWidth * pixelHeight)) { _buffer = new byte[pixelWidth * pixelHeight]; } _cam.GetPreviewBufferY(_buffer); var luminance = new RGBLuminanceSource(_buffer, pixelWidth, pixelHeight, true); var binarizer = new com.google.zxing.common.HybridBinarizer(luminance); binaryBitmap = new BinaryBitmap(binarizer); } catch { } return(binaryBitmap); }
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 } }
private bool TryToRecognize(WriteableBitmap wb, Reader reader, Dictionary<object, object> zxhints, out string output) { bool res = false; output = null; try { var luminiance = new RGBLuminanceSource(wb, wb.PixelWidth, wb.PixelHeight); var binarizer = new com.google.zxing.common.HybridBinarizer(luminiance); var binBitmap = new com.google.zxing.BinaryBitmap(binarizer); // recognize var results = reader.decode(binBitmap, zxhints); // exception will be thrown if reader cannot decode image. output = results.Text; res = true; } catch {} return res; }
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")); } }
private void ScanPreviewBuffer() { if (_photoCamera == null) return; if (!_initialized) return; try { _photoCamera.GetPreviewBufferY(_luminance.PreviewBufferY); var binarizer = new com.google.zxing.common.HybridBinarizer(_luminance); var binBitmap = new BinaryBitmap(binarizer); var result = _reader.decode(binBitmap); OnDecodingCompleted(result); } catch (Exception) { // If decoding fails it will throw a ReaderException // and we're not interested in doing anything with it } }
private void ProcessImage(BarcodeCaptureResult captureResults) { captureResults.State = CaptureState.Processing; try { bool bIsReady = captureResults.isReadyForProcessing.WaitOne(3000); if (!bIsReady) { captureResults.State = CaptureState.UnknownError; captureResults.ErrorMessage = "Error: Timeout waiting for images to be processed. Please try again or send issue report using app bar."; return; } if (captureResults.VGABarcodeImage != null) { var wb = captureResults.VGABarcodeImage; //Code from: btnReadTag_Click in "SLZXingQRSample\SLZXingQRSample\SLZXingSample\MainPage.xaml.vb" var qrRead = new com.google.zxing.oned.MultiFormatUPCEANReader(zxingHints); ; // new com.google.zxing.qrcode.QRCodeReader(); var luminiance = new RGBLuminanceSource(wb, 640, 480); var binarizer = new com.google.zxing.common.HybridBinarizer(luminiance); var binBitmap = new com.google.zxing.BinaryBitmap(binarizer); var results = qrRead.decode(binBitmap, zxingHints); //NOTE: will throw exception if cannot decode image. captureResults.BarcodeText = results.Text; captureResults.State = CaptureState.Success; BarcodeCaptured.Invoke(captureResults); //captureResults.ProcessValue(); } else { captureResults.State = CaptureState.UnknownError; captureResults.ErrorMessage = "Cannot process image: invalid or null BitmapImage."; } } catch (Exception ex) { captureResults.ExceptionThrown = ex; if (ex is com.google.zxing.ReaderException) { captureResults.ErrorMessage = "Error: Cannot decode barcode image. Please make sure scan mode is correct and try again."; captureResults.State = CaptureState.ScanFailed; } else { Debug.WriteLine("Error: " + ex.ToString()); captureResults.ErrorMessage = String.Format("Barcode Library Processing Error: {0}\r\n{1}", ex.GetType(), ex.Message); captureResults.State = CaptureState.UnknownError; } } finally { lock (_resultTaskLock) { _resultTask = null; } } }
/// <summary> /// This code should be run on a background thread to prevent UI lockup issues. /// For information about background threads see http://msdn.microsoft.com/en-us/library/ff967560(VS.92).aspx#BKMK_Background /// </summary> private static void ProcessImage() { LastCaptureResults.State = CaptureState.Processing; try { bool bIsReady = LastCaptureResults.isReadyForProcessing.WaitOne(3000); if (!bIsReady) { LastCaptureResults.State = CaptureState.UnknownError; LastCaptureResults.ErrorMessage = "Error: Timeout waiting for images to be processed. Please try again or send issue report using app bar."; return; } StartProgress(); if (LastCaptureResults.BarcodeImage != null) { var wb = LastCaptureResults.VGABarcodeImage; //Code from: btnReadTag_Click in "SLZXingQRSample\SLZXingQRSample\SLZXingSample\MainPage.xaml.vb" var qrRead = GetReader(); // new com.google.zxing.qrcode.QRCodeReader(); var luminiance = new RGBLuminanceSource(wb, wb.PixelWidth, wb.PixelHeight); var binarizer = new com.google.zxing.common.HybridBinarizer(luminiance); var binBitmap = new com.google.zxing.BinaryBitmap(binarizer); var results = qrRead.decode(binBitmap, zxingHints); //NOTE: will throw exception if cannot decode image. LastCaptureResults.BarcodeText = results.Text; LastCaptureResults.State = CaptureState.Success; LastCaptureResults.ProcessValue(); } else { LastCaptureResults.State = CaptureState.UnknownError; LastCaptureResults.ErrorMessage = "Cannot process image: invalid or null BitmapImage."; } } catch (Exception ex) { LastCaptureResults.ExceptionThrown = ex; if (ex is com.google.zxing.ReaderException) { LastCaptureResults.ErrorMessage = "Error: Cannot decode barcode image. Please make sure scan mode is correct and try again."; LastCaptureResults.State = CaptureState.ScanFailed; } else { Debug.WriteLine("Error: " + ex.ToString()); LastCaptureResults.ErrorMessage = String.Format("Barcode Library Processing Error: {0}\r\n{1}", ex.GetType(), ex.Message); LastCaptureResults.State = CaptureState.UnknownError; } } finally { ExecuteCallback(); } }