void cameraCaptureControlUC_EmailDecoded(object sender, UserControls.CameraClickedEventArgs e)
 {
     if (e.EncodedData != null)
     {
         txtResult.Text = e.EncodedData;
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Method to handle the Click event of the Capture Code button
        /// </summary>
        /// <param name="sender">Sender of the Event</param>
        /// <param name="e">Arguments of the event</param>
        private async void CaptureQRCodeFromCamera(object data)
        {
            MessageDialog dialog = new MessageDialog(string.Empty);

            try
            {
                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() =>
                {
                    if (!isCameraFound)
                    {
                        return;
                    }

                    ImageEncodingProperties imgFormat = ImageEncodingProperties.CreateJpeg();
                    // create storage file in local app storage
                    StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync(
                        "temp.jpg",
                        CreationCollisionOption.GenerateUniqueName);
                    // take photo
                    await captureMgr.CapturePhotoToStorageFileAsync(imgFormat, file);
                    // Get photo as a BitmapImage
                    BitmapImage bmpImage   = new BitmapImage(new Uri(file.Path));
                    bmpImage.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
                    using (IRandomAccessStream fileStream = await file.OpenAsync(FileAccessMode.Read))
                    {
                        wrb = await Windows.UI.Xaml.Media.Imaging.BitmapFactory.New(1, 1).FromStream(fileStream);
                    }
                    br = new BarcodeReader {
                        PossibleFormats = new BarcodeFormat[] { BarcodeFormat.QR_CODE }
                    };
                    res = br.Decode(wrb);
                    CameraClickedEventArgs cameraArgs = null;
                    if (res != null)
                    {
                        QrCodeContent = res.Text;
                        cameraArgs    = new CameraClickedEventArgs {
                            EncodedData = this.QrCodeContent
                        };
                        if (this.EmailDecoded != null)
                        {
                            EmailDecoded(this, cameraArgs);
                        }
                    }

                    timer.Change(4000, Timeout.Infinite);
                });
            }

            catch (Exception ex)
            {
                dialog = new MessageDialog("Error: " + ex.Message);
                dialog.ShowAsync();
            }
        }