public void Closethis() { try { timer.Dispose(); CameraClickedEventArgs cameraArgs = new CameraClickedEventArgs { EncodedData = "http://abc.de", Image = wrb }; if (this.EmailDecoded != null) { EmailDecoded(this, cameraArgs); } } catch (Exception ex) { } }
/// <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); } res = br.Decode(wrb); if (res != null) { CameraClickedEventArgs cameraArgs = null; timer.Dispose(); await captureMgr.StopPreviewAsync(); QrCodeContent = res.Text; cameraArgs = new CameraClickedEventArgs { EncodedData = this.QrCodeContent, Image = wrb }; if (this.EmailDecoded != null) { EmailDecoded(this, cameraArgs); } } else { _failCount++; if (_failCount > 50) { Closethis(); } else { timer.Change(750, Timeout.Infinite); } } }); } catch (Exception ex) { dialog = new MessageDialog("Error: " + ex.Message); dialog.ShowAsync(); } }