void cameraCaptureControlUC_EmailDecoded(object sender, UserControls.CameraClickedEventArgs e) { if (e.EncodedData != null) { txtResult.Text = e.EncodedData; } }
private async void CaptureBarcodeFromCamera(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)) { var properties = captureMgr.VideoDeviceController.GetMediaStreamProperties(MediaStreamType.Photo) as VideoEncodingProperties; wrb = new WriteableBitmap((int)properties.Width, (int)properties.Height); wrb.SetSource(fileStream); //wrb = await Windows.UI.Xaml.Media.Imaging.BitmapFactory.New(1, 1).FromStream(fileStream); } br = new BarcodeReader { AutoRotate = true, Options = new DecodingOptions { PossibleFormats = new BarcodeFormat[] { BarcodeFormat.CODE_39, BarcodeFormat.QR_CODE, BarcodeFormat.PDF_417 }, TryHarder = true, PureBarcode = false } }; res = br.Decode(wrb); if (res != null) { BarcodeContent = res.Text; CameraClickedEventArgs cameraArgs = new CameraClickedEventArgs { EncodedData = this.BarcodeContent }; if (this.EmailDecoded != null) { EmailDecoded(this, cameraArgs); } } timer.Change(4000, Timeout.Infinite); }); } catch (Exception ex) { dialog = new MessageDialog("Error: " + ex.Message); dialog.ShowAsync(); } }