Example #1
0
        public string findQrCodeText(com.google.zxing.Reader decoder, Bitmap bitmap)
        {
            var rgb    = new RGBLuminanceSource(bitmap, bitmap.Width, bitmap.Height);
            var hybrid = new com.google.zxing.common.HybridBinarizer(rgb);

            com.google.zxing.BinaryBitmap binBitmap = new com.google.zxing.BinaryBitmap(hybrid);
            string decodedString = decoder.decode(binBitmap, null).Text;

            return(decodedString);
        }
 private void ScanPreviewBuffer()
 {
     try
     {
         _photoCamera.GetPreviewBufferY(_luminance.PreviewBufferY);
         var binarizer = new HybridBinarizer(_luminance);
         var binBitmap = new BinaryBitmap(binarizer);
         var result = _reader.decode(binBitmap);
         Dispatcher.BeginInvoke(() => DisplayResult(result.Text));
     }
     catch
     {
     }
 }
Example #3
0
        private void ScanPreviewBuffer()
        {
            try
            {
                lblQR.Text = "No se detecta ningún código QR";
                _photoCamera.GetPreviewBufferY(_luminance.PreviewBufferY);
                var binarizer = new HybridBinarizer(_luminance);
                var binBitmap = new BinaryBitmap(binarizer);
                var result = _reader.decode(binBitmap);

                var scan = result.Text;
                lblQR.Text = "Escanea un código de Museos App";
                //System.Media.SystemSounds.Beep.Play();
                //System.Media.SystemSounds.Asterisk.Play();
                //SystemSounds.Beep.Play();
                /*Stream stream = TitleContainer.OpenStream("/Assets/cartel.mp3");
                SoundEffect effect = SoundEffect.FromStream(stream);
                FrameworkDispatcher.Update();
                effect.Play();*/
                //mediaElement.Play();

                var textId = scan.Remove(0, 42);
                System.Diagnostics.Debug.WriteLine("ID DEL TEXTO: " + textId);
                var textQR = scan.Remove(42, 1);
                System.Diagnostics.Debug.WriteLine("TEXTO DEL QR: " + textQR);

                if (textQR.Equals("http://museosapp.azurewebsites.net/Piezas/"))
                {
                    lblQR.Text = "Código QR correcto";
                    NavigationService.Navigate(new Uri("/InfoQR.xaml?id=" + textId, UriKind.Relative));
                    _timer.Stop();
                }

                Dispatcher.BeginInvoke(() => DisplayResult(result.Text));
            }
            catch
            {
            }            
        }
Example #4
0
 private void PumpYFrames()
 {
     byte[] array = new byte[307200];
     bool flag = false;
     while (this._pumpYFrames)
     {
         BarcodeScanner._pauseFramesEvent.WaitOne();
         if (this._isScanning)
         {
             try
             {
                 this._cam.GetPreviewBufferY(array);
                 flag = true;
             }
             catch
             {
                 flag = false;
             }
             if (flag)
             {
                 DateTime now = DateTime.Now;
                 RGBLuminanceSource rGBLuminanceSource = new RGBLuminanceSource(array, 640, 480, false);
                 if (this._scanType == CodeType.OneDCodes || this._scanType == CodeType.UPC || this._scanType == CodeType.ITF || this._scanType == CodeType.EAN || this._scanType == CodeType.Code128 || this._scanType == CodeType.Code39)
                 {
                     rGBLuminanceSource.rotateCounterClockwise();
                 }
                 HybridBinarizer binarizer = new HybridBinarizer(rGBLuminanceSource);
                 BinaryBitmap image = new BinaryBitmap(binarizer);
                 Reader reader = this.GetReader(this._scanType);
                 try
                 {
                     Result results = reader.decode(image, this._hintDictionary);
                     TimeSpan timeSpent = DateTime.Now.Subtract(now);
                     Deployment.Current.Dispatcher.BeginInvoke(delegate
                     {
                         this.ProcessScan(results, timeSpent, this.ScanType);
                         if (this.StopOnSuccess)
                         {
                             this.IsScanning = false;
                         }
                     }
                     );
                     BarcodeScanner._pauseFramesEvent.Set();
                 }
                 catch
                 {
                     BarcodeScanner._pauseFramesEvent.Set();
                 }
             }
         }
     }
 }
Example #5
0
 private void ScanPreviewBuffer()
 {
     try
     {
         _photoCamera.GetPreviewBufferY(_luminance.PreviewBufferY);
         var binarizer = new HybridBinarizer(_luminance);
         var binBitmap = new BinaryBitmap(binarizer);
         Result result = _reader.decode(binBitmap);
         if (result != null)
         {
             _timer.Stop();
             SetStillPicture();
             BarCodeRectSuccess();
             Dispatcher.BeginInvoke(() =>
             {
                 if (WebHelper.Instance.InternetIsAvailableNotify())
                 {
                     NavigationService.Navigate(new Uri("/BookDetailPanoramaPage.xaml?isbn=" + result.Text, UriKind.Relative));
                 }
                 else
                 {
                     if (NavigationService.CanGoBack)
                         NavigationService.GoBack();
                 }
             });
         }
         else
         {
             _photoCamera.Focus();
         }
     }
     catch
     {
     }
 }
Example #6
0
        private void Scan()
        {
            if (IsScanning && _initialized && _photoCamera != null && _luminanceSource != null && _reader != null)
            {
                try
                {
                    _photoCamera.GetPreviewBufferY(_luminanceSource.PreviewBufferY);
                    var binarizer = new HybridBinarizer(_luminanceSource);
                    var binaryBitmap = new BinaryBitmap(binarizer);
                    var result = _reader.decode(binaryBitmap, QRCodeHint);

                    StopScanning();
                    OnResult(result);
                }
                catch (ReaderException)
                {
                    // There was not a successful QR code read in the scan
                    // pass. Invoke and try again soon.
                    Dispatcher.BeginInvoke(Scan);
                }
                catch (Exception ex)
                {
                    OnError(ex);
                }
            }
        }
Example #7
0
        private void ScanPreviewBuffer()
        {
            try
            {
                _photoCamera.GetPreviewBufferY(_luminance.PreviewBufferY);
                var binarizer = new HybridBinarizer(_luminance);
                var binBitmap = new BinaryBitmap(binarizer);
            #if DEBUG
                var text = "http://localhost?h=foobarstore.com&p=255&id=1234";
            #else
                var result = _reader.decode(binBitmap);
                var text = result.Text;
            #endif
                Dispatcher.BeginInvoke(() => DisplayResult(text));

            }
            catch (Exception e)
            {
            }
        }
Example #8
0
        private string QRDecode(Bitmap image, Reader decoder)
        {
            /*
            MemoryStream ms = new MemoryStream();
            image.Save(ms,System.Drawing.Imaging.ImageFormat.Bmp);

            DataMatrix dmDecoder = new DataMatrix(ms.ToArray(), image.Width, image.Height, EncodingType.Binary);

            return dmDecoder.HexPbm;
             * */

            var rgb = new RGBLuminanceSource(image, image.Width, image.Height);
            var hybrid = new HybridBinarizer(rgb);

            BinaryBitmap binBitmap = new BinaryBitmap(hybrid);

            string sdecodedString = decoder.decode(binBitmap, null).Text;
            //Byte[] result = decoder.decode(binBitmap, null).;

            //return null;

            return sdecodedString;
        }
        private void ScanPreviewBuffer()
        {
            if (_guid != null)
            {
                _timer.Stop();

                SendImage();
            }

            try
            {
                _photoCamera.GetPreviewBufferY(_luminance.PreviewBufferY);
                var binarizer = new HybridBinarizer(_luminance);
                var binBitmap = new BinaryBitmap(binarizer);
                var result = _reader.decode(binBitmap);

                Dispatcher.BeginInvoke(() =>
                                           {
                                               _guid = result.Text;
                                           });
            }
            catch
            {

            }
        }
Example #10
0
        private void ScanPreviewBuffer()
        {
            if (NavigationService.CurrentSource == new Uri("/ScannerPage.xaml", UriKind.Relative))
            {
                try
                {
                    _photoCamera.GetPreviewBufferY(_luminance.PreviewBufferY);
                    var binarizer = new HybridBinarizer(_luminance);
                    var binBitmap = new BinaryBitmap(binarizer);
                    var result = _reader.decode(binBitmap);
                    Dispatcher.BeginInvoke(() => DisplayResult(result.Text));
                    // katsotaan miten käy
                    if (result.Text != null)
                    {
                        string kysymysID;
                        string viesti = result.Text;
                        int categoryIdIndex = viesti.IndexOf("kysymys") + 7;
                        kysymysID = viesti.Substring(categoryIdIndex);

                        Dispatcher.BeginInvoke(() => KysymysSaatu(kysymysID));
                    }
                }
                catch (Exception ex)
                {
                    //Dispatcher.BeginInvoke(() => NaytaException(ex.Message));
                }
            }
        }
Example #11
0
        private void ScanPreviewBuffer()
        {
            try
            {
                _cam.GetPreviewBufferY(_luminance.PreviewBufferY);
                var binarizer = new HybridBinarizer(_luminance);
                var binBitmap = new BinaryBitmap(binarizer);
                var result = _reader.decode(binBitmap);

                Dispatcher.BeginInvoke(() =>
                {
                    if(myPlayer.alive)
                    {
                        if (QRCodeManager.IsValidQRCode(result.Text) && (result.Text[0] != (myPlayer as QRPlayer).qrcode[0]))
                        {
                            if (!isKilling)
                            {
                                isKilling = true;
                                var dict = new Dictionary<string, object>();

                                dict["killer"] = myPlayer;
                                dict["victim_qrcode"] = result.Text;

                                Networking.Kill(dict, (o, e) =>
                                {
                                    if (!Networking.FailedRequest)
                                    {
                                        DisplayBonus_Green("+100");
                                    }
                                    else
                                    {
                                        switch (Networking.LastError)
                                        {
                                            case 404:
                                                DisplayMessage_Red("That player isn't playing this game!");
                                                break;
                                            case 409:
                                                DisplayMessage_Red("That player is already dead!");
                                                break;
                                            //case 410:
                                            //DisplayMessage_Red("You are dead!");
                                            //break;
                                            default:
                                                Dispatcher.BeginInvoke(() => MessageBox.Show(Networking.LastError.ToString()));
                                                break;
                                        }
                                    }
                                    isKilling = false;
                                });

                            }
                        }
                    }
                    else
                    {
                        if (QRCodeManager.IsValidQRCode(result.Text) && (result.Text[1] == 'E'))
                        {
                            //If the player isn't alive, they must scan their respawn code instead
                            Networking.Respawn(result.Text, myPlayer.id, null);
                        }
                        else
                            MessageBox.Show("Please scan your respawn code in order to continue playing the game", "You are dead!", MessageBoxButton.OK);
                    }
                });

                _cam.Focus();
            }
            catch
            {
            }
        }
Example #12
0
        private void Scan()
        {
            if (IsScanning && _initialized && _photoCamera != null && _luminanceSource != null && _reader != null)
            {
                try
                {
                    // 2-2-2012 - Rowdy.nl
                    // Focus the camera for better recognition of QR code's
                    if (_photoCamera.IsFocusSupported)
                        _photoCamera.Focus();
                    // End Rowdy.nl

                    _photoCamera.GetPreviewBufferY(_luminanceSource.PreviewBufferY);
                    var binarizer = new HybridBinarizer(_luminanceSource);
                    var binaryBitmap = new BinaryBitmap(binarizer);
                    var result = _reader.decode(binaryBitmap, QRCodeHint);

                    StopScanning();
                    OnResult(result);
                }
                catch (ReaderException)
                {
                    // There was not a successful QR code read in the scan
                    // pass. Invoke and try again soon.
                    Dispatcher.BeginInvoke(Scan);
                }
                catch (Exception ex)
                {
                    OnError(ex);
                }
            }
        }
Example #13
0
        private void ScanPreviewBuffer()
        {
            try
            {
                _cam.GetPreviewBufferY(_luminance.PreviewBufferY);
                var binarizer = new HybridBinarizer(_luminance);
                var binBitmap = new BinaryBitmap(binarizer);
                var result = _reader.decode(binBitmap);

                Dispatcher.BeginInvoke(() =>
                {
                    SuccessfulScan(result);
                });

                _cam.Focus();
            }
            catch
            {
            }
        }
        private void ScanPreviewBuffer()
        {
            try
            {
                _photoCamera.GetPreviewBufferY(_luminance.PreviewBufferY);
                var binarizer = new HybridBinarizer(_luminance);
                var binBitmap = new BinaryBitmap(binarizer);
                Result result = _reader.decode(binBitmap);
                if (result != null)
                {
                    _timer.Stop();
                    SetStillPicture();
                    BarCodeRectSuccess();
                    Dispatcher.BeginInvoke(() =>
                    {
                        //读取成功,结果存放在result.Text
                        NavigationService.Navigate(new Uri("/ScanResult.xaml?result=" + result.Text, UriKind.Relative));

                    });
                }
                else
                {
                    _photoCamera.Focus();
                }
            }
            catch
            {
            }
        }
Example #15
0
        private void ScanPreviewBuffer()
        {
            try
            {
                _photoCamera.GetPreviewBufferY(_luminance.PreviewBufferY);
                var binarizer = new HybridBinarizer(_luminance);
                var binBitmap = new BinaryBitmap(binarizer);
                Result result = _reader.decode(binBitmap);
                if (result != null)
                {
                    _timer.Stop();
                    SetStillPicture();
                    BarCodeRectSuccess();
                    Dispatcher.BeginInvoke(() =>
                    {
                        string destination = "/DrugResultPage.xaml";
                        Dictionary<string, string> dic = new Dictionary<string, string>();
                        dic.Add("code", result.Text);
                        PhoneApplicationService.Current.State["dic"] = dic;
                        destination += string.Format("?type={0}", "DrugCode");

                        //读取成功,结果存放在result.Text
                        NavigationService.Navigate(new Uri(destination, UriKind.Relative));

                    });
                }
                else
                {
                    _photoCamera.Focus();
                }
            }
            catch
            {
            }
        }
Example #16
0
        private void ScanPreviewBuffer()
        {
            string returnedString = null;

            photoCamera.GetPreviewBufferY(luminance.PreviewBufferY);
            var binarizer = new HybridBinarizer(luminance);
            var binBitmap = new BinaryBitmap(binarizer);
            var img = GetImage(luminance.PreviewBufferY);
            WP7BarcodeManager.ScanBarcode(img, result =>
                {
                    Debug.WriteLine(result.BarcodeImage);
                });
            
            try
            {                
                var result = ean13Reader.decode(binBitmap);
                returnedString = result.Text;
                Debug.WriteLine("EAN13  " + returnedString);
                return;
            }
            catch(Exception ex)
            {
            }

            try
            {
                var result = qrReader.decode(binBitmap);
                returnedString = result.Text;
                Debug.WriteLine("QR  " + returnedString);
                return;
            }
            catch (Exception ex)
            {
            }

            try
            {        
                var result = code39Reader.decode(binBitmap);
                returnedString = result.Text;
                Debug.WriteLine("CODE39  " + returnedString);
                return;
            }
            catch (Exception ex)
            {

            }
        }
Example #17
0
 private void ScanPreviewBuffer()
 {
     try
     {
         _photoCamera.GetPreviewBufferY(_luminance.PreviewBufferY);
         var binarizer = new HybridBinarizer(_luminance);
         var binBitmap = new BinaryBitmap(binarizer);
         Result result = _reader.decode(binBitmap);
         if (result != null)
         {
             _timer.Stop();
             SetStillPicture();
             BarCodeRectSuccess();
             BarCodeResult barCodeResult = new BarCodeResult(TaskResult.OK);
             barCodeResult.result = result.Text;
             Dispatcher.BeginInvoke(() =>
             {
                 this.result = barCodeResult;
                 if (this.NavigationService.CanGoBack)
                 {
                     this.NavigationService.GoBack();
                 }
             });
         }
         else
         {
             _photoCamera.Focus();
         }
     }
     catch
     {
         //do nothing
     }
 }
Example #18
-1
 /// Processes the specified bitmap.
 public string Process(Bitmap bitmap)
 {
     try
     {
         com.google.zxing.LuminanceSource source = new RGBLuminanceSource(bitmap, bitmap.Width, bitmap.Height);
         var binarizer = new HybridBinarizer(source);
         var binBitmap = new BinaryBitmap(binarizer);
         return reader.decode(binBitmap).Text;
     }
     catch
     {
         return string.Empty;
     }
 }