private async Task startPreviewAsync() { try { mediaCapture = new MediaCapture(); await mediaCapture.InitializeAsync(settings); displayRequest = new DisplayRequest(); displayRequest.RequestActive(); DisplayInformation.AutoRotationPreferences = DisplayOrientations.Landscape; lowLagCapture = await mediaCapture.PrepareLowLagPhotoCaptureAsync(ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Bgra8)); } catch (UnauthorizedAccessException) { MainPage.ShowMessage("Unable to start"); return; } try { previewControl.Source = mediaCapture; await mediaCapture.StartPreviewAsync(); isPreviewing = true; } catch (System.IO.FileLoadException) { mediaCapture.CaptureDeviceExclusiveControlStatusChanged += MediaCapture_CaptureDeviceExclusiveControlStatusChanged; } }
/// <summary> /// Will capture a single image and store it in the baseline images list. Each image will be used to determine if we have an alert or not. /// </summary> private async void CaptureBaseLineImage() { try { lowLagCapture = await MediaCaptureElement.PrepareLowLagPhotoCaptureAsync(ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Bgra8)); CapturedPhoto capturedPhoto = await lowLagCapture.CaptureAsync(); SoftwareBitmap softwareBitmap = capturedPhoto.Frame.SoftwareBitmap; WriteableBitmap writeableBitmap = new WriteableBitmap(softwareBitmap.PixelWidth, softwareBitmap.PixelHeight); softwareBitmap.CopyToBuffer(writeableBitmap.PixelBuffer); byte[] imageBytes = new byte[4 * softwareBitmap.PixelWidth * softwareBitmap.PixelHeight]; softwareBitmap.CopyToBuffer(imageBytes.AsBuffer()); if (baselineImages.Count > 6) { baselineImages.Clear(); DisplayImages.Clear(); } baselineImages.Add(imageBytes); DisplayImages.Add(writeableBitmap); await lowLagCapture.FinishAsync(); } catch (Exception) { // Sometimes when you serial click the capture button we get an explosion... // Eat it and move on } }
private async void TakePhotoAsync() { mediaCapture = new MediaCapture(); await mediaCapture.InitializeAsync(); //mediaCapture.Failed += MediaCapture_Failed; // Prepare and capture photo // 캡쳐한 사진을 바로 XAML에서 보여줌 var lowLagCapture = await mediaCapture.PrepareLowLagPhotoCaptureAsync(ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Bgra8)); var capturedPhoto = await lowLagCapture.CaptureAsync(); var softwareBitmap = capturedPhoto.Frame.SoftwareBitmap; await lowLagCapture.FinishAsync(); //임시로 저장된 거를 XAML에서 표시 if (softwareBitmap.BitmapPixelFormat != BitmapPixelFormat.Bgra8 || softwareBitmap.BitmapAlphaMode == BitmapAlphaMode.Straight) { softwareBitmap = SoftwareBitmap.Convert(softwareBitmap, BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied); } var source = new SoftwareBitmapSource(); await source.SetBitmapAsync(softwareBitmap); // Set the source of the Image control imageControl.Source = source; }
//Takes iamge and creates a writableBitmap from result //NEW TO ME private async Task <WriteableBitmap> takeImage() { try { var capture = await mediaCapture.PrepareLowLagPhotoCaptureAsync(ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Bgra8)); var photo = await capture.CaptureAsync(); var softwareBitmap = photo.Frame.SoftwareBitmap; WriteableBitmap bitmap = new WriteableBitmap(softwareBitmap.PixelWidth, softwareBitmap.PixelHeight); softwareBitmap.CopyToBuffer(bitmap.PixelBuffer); await capture.FinishAsync(); return(bitmap); } catch (Exception e) { if (!cancelled) { await errorDialog(); } manager.navigateMain(typeof(FrameViewerPage)); } return(new WriteableBitmap(0, 0)); }
private async System.Threading.Tasks.Task <CapturedPhoto> CapturePreviewFrame() { var lowLagCapture = await mediaCapture.PrepareLowLagPhotoCaptureAsync(ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Bgra8)); var frame = await lowLagCapture.CaptureAsync(); await lowLagCapture.FinishAsync(); return(frame); }
private async void ScreenShot_Click(object sender, RoutedEventArgs e) { var lowLagCapture = await mediaCapture.PrepareLowLagPhotoCaptureAsync(ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Bgra8)); var capturedPhoto = await lowLagCapture.CaptureAsync(); var softwareBitmap = capturedPhoto.Frame.SoftwareBitmap; await lowLagCapture.FinishAsync(); }
/// <summary> /// Takes the camera output and displays the Clarifai predictions on the pane. /// </summary> /// <returns>a task</returns> private async Task RunPredictionsAndDisplayResponse() { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => { try { if (_predictionApi == null) { return; } LowLagPhotoCapture lowLagCapture = await _mediaCapture.PrepareLowLagPhotoCaptureAsync( ImageEncodingProperties.CreateUncompressed(MediaPixelFormat .Bgra8)); CapturedPhoto capturedPhoto = await lowLagCapture.CaptureAsync(); SoftwareBitmap softwareBitmap = capturedPhoto.Frame.SoftwareBitmap; byte[] data = await EncodedBytes(softwareBitmap, BitmapEncoder.JpegEncoderId); try { ConceptsTextBlock.Text = await _predictionApi .PredictConcepts(data, _selectedModel); } catch (Exception ex) { ShowMessageToUser("Error: " + ex.Message); } try { (double camWidth, double camHeight) = CameraOutputDimensions(); List <Rect> rects = await _predictionApi.PredictFaces(data, camWidth, camHeight); CameraGrid.Children.Clear(); foreach (Rect r in rects) { CameraGrid.Children.Add(CreateGuiRectangle(r, camWidth, camHeight)); } } catch (Exception ex) { ShowMessageToUser("Error: " + ex.Message); } await lowLagCapture.FinishAsync(); } catch (COMException) // This is thrown when application exits. { // No need to handle this since the application is exiting. } });
public async Task <SoftwareBitmap> GetImageAsync() { if (_photoCapture == null) { _photoCapture = await MediaCapture.PrepareLowLagPhotoCaptureAsync(ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Bgra8)); } var cc = await _photoCapture.CaptureAsync(); return(cc.Frame.SoftwareBitmap); }
private ImageEncodingProperties GetLowestFormat() { var format = ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Bgra8); var resolutions = _mediaCapture.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.Photo).ToList(); var resolutionObj = resolutions.Last(); var resolution = resolutionObj as VideoEncodingProperties; format.Height = resolution.Height; format.Width = resolution.Width; return(format); }
private async void Button_Click(object sender, RoutedEventArgs e) { var lowLagCapture = await mediaCapture.PrepareLowLagPhotoCaptureAsync(ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Bgra8)); var capturedPhoto = await lowLagCapture.CaptureAsync(); var softwareBitmap = capturedPhoto.Frame.SoftwareBitmap; softwareBitmap = SoftwareBitmap.Convert(softwareBitmap, BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied); var source = new SoftwareBitmapSource(); await source.SetBitmapAsync(softwareBitmap); VideoFrame videoFrame = VideoFrame.CreateWithSoftwareBitmap(softwareBitmap); ObtenerIdentidadONNX obtenerIdentidadONNX = new ObtenerIdentidadONNX(); var nombre = await obtenerIdentidadONNX.ObtenerIdentidadOnnX(videoFrame, _session); List <Empleados> EmpAutorizados = new List <Empleados>(); EmpAutorizados.Add(new Empleados() { Nombre = "Visco" }); EmpAutorizados.Add(new Empleados() { Nombre = "Reitano" }); var buscarEmpleado = EmpAutorizados.Find(x => x.Nombre == nombre); if (buscarEmpleado != null) { brush = new SolidColorBrush(Windows.UI.Colors.Green); } else { brush = new SolidColorBrush(Windows.UI.Colors.Red); nombre = "No Autorizado"; } if (nombre != "") { var iniciarFichajeController = new Controller.IniciarFichaje(); DateTime utcDate = DateTime.UtcNow; var fotosCapttupleLocal = await iniciarFichajeController.TomarFoto(source, utcDate.ToString(), nombre, softwareBitmap, brush); fotosCapttuple.Add(fotosCapttupleLocal); tuples.Add(new Tuple <FotosCapttuple>(fotosCapttupleLocal)); } await lowLagCapture.FinishAsync(); }
public async Task <Stream> TakeSnapshotAsync() { var encoding = ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Bgra8); var capture = await _mediaCapture.PrepareLowLagPhotoCaptureAsync(encoding); var photo = await capture.CaptureAsync(); var frame = photo.Frame; await capture.FinishAsync(); return(await this.WriteToStreamAsync(frame)); }
public async Task <object> CapturePictureAsync() { var encodingProperties = ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Bgra8); var lowLagCapture = await _mediaCapture.PrepareLowLagPhotoCaptureAsync(encodingProperties); var capturedPhoto = await lowLagCapture.CaptureAsync(); var softwareBitmap = capturedPhoto.Frame.SoftwareBitmap; await lowLagCapture.FinishAsync(); return(softwareBitmap); }
public async Task InitializeCameraAsync() { // Asynchronously initialize this instance. var mediaInitSettings = new MediaCaptureInitializationSettings { VideoDeviceId = this.DeviceId }; mediaInitSettings.StreamingCaptureMode = StreamingCaptureMode.Video; await _mediaCapture.InitializeAsync(mediaInitSettings); await this.SetCameraResolutionAsync(1280, 720); _lowLagCapture = await _mediaCapture.PrepareLowLagPhotoCaptureAsync(ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Bgra8)); }
public async Task CaptureToSoftwareBitmap() { //<SnippetCaptureToSoftwareBitmap> // Prepare and capture photo var lowLagCapture = await mediaCapture.PrepareLowLagPhotoCaptureAsync(ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Bgra8)); var capturedPhoto = await lowLagCapture.CaptureAsync(); var softwareBitmap = capturedPhoto.Frame.SoftwareBitmap; await lowLagCapture.FinishAsync(); //</SnippetCaptureToSoftwareBitmap> }
private async Task <SoftwareBitmap> TakePhotoFromCamera() { // Prepare and capture photo var properties = ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Bgra8); var lowLagCapture = await Capture.PrepareLowLagPhotoCaptureAsync(properties); var capturedPhoto = await lowLagCapture.CaptureAsync(); var softwareBitmap = capturedPhoto.Frame.SoftwareBitmap; await lowLagCapture.FinishAsync(); return(softwareBitmap); }
private async Task <SoftwareBitmap> CaptureImage() { await this.InitializeMediaCaptureIfNeeded(); var lowLagCapture = await mediaCapture.PrepareLowLagPhotoCaptureAsync( ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Bgra8)); var capturedPhoto = await lowLagCapture.CaptureAsync(); var softwareBitmap = capturedPhoto.Frame.SoftwareBitmap; await lowLagCapture.FinishAsync(); return(softwareBitmap); }
private async void Button_Click_2(object sender, RoutedEventArgs e) { AddLog("開始"); var lowLagCapture = await mediaCapture.PrepareLowLagPhotoCaptureAsync(ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Bgra8)); var capturedPhoto = await lowLagCapture.CaptureAsync(); var softwareBitmap = capturedPhoto.Frame.SoftwareBitmap; await lowLagCapture.FinishAsync(); using (IRandomAccessStream stream = new InMemoryRandomAccessStream()) { // Create the decoder from the stream BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream); // Get the SoftwareBitmap representation of the file softwareBitmap = await decoder.GetSoftwareBitmapAsync(); // Create an encoder with the desired format BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, stream); // Set the software bitmap encoder.SetSoftwareBitmap(softwareBitmap); await encoder.FlushAsync(); //ビットマップにして表示 System.IO.Stream stream2 = System.IO.WindowsRuntimeStreamExtensions.AsStream(stream); var img = System.Drawing.Bitmap.FromStream(stream2); //this.pictureBox1.Image = img; //img.Save(Environment.SpecialFolder.Desktop + @"\aaa.bmp"); AddLog("表示"); // 画面に表示 var a = System.Windows.Media.Imaging.BitmapFrame.Create(stream2, System.Windows.Media.Imaging.BitmapCreateOptions.None, System.Windows.Media.Imaging.BitmapCacheOption.OnLoad); PreviewFrameImage.Source = a; } AddLog("修了"); }
/// <summary> /// Updates photo capture in accordance with the current application parameters. /// </summary> /// <returns>Awaitable task.</returns> private async Task UpdatePhotoCaptureAsync() { bool needToUpdateAgain = false; Size resolution = this.FindHighestSupportedPhotoResolution(); ImageEncodingProperties encoding = ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Bgra8); encoding.Width = unchecked ((uint)resolution.Width); encoding.Height = unchecked ((uint)resolution.Height); try { await this.camera.InitializePhotoCaptureAsync( this.CaptureMode, new CaptureParameters { ImageEncoding = encoding, FlashMode = this.FlashMode }); } catch { // VPS may not be supported on the current device. if (this.CaptureMode == CaptureMode.Variable) { // Fall back to the LowLag photo capture. this.CaptureMode = CaptureMode.LowLag; needToUpdateAgain = true; // Show the error message to the user. DispatcherHelper.BeginInvokeOnUIThread(() => MessageBox.Show(AppResources.VpsNotSupportedMessage, AppResources.VpsNotSupportedCaption, MessageBoxButton.OK)); } else { throw; } } // Call this method again, if the VPS initialization failed, so we'll reinitialize LLPC. if (needToUpdateAgain) { await this.UpdatePhotoCaptureAsync(); } }
private async Task CapturePhotoAsync() { var lowlagCapture = await _mediaCapture.PrepareLowLagPhotoCaptureAsync(ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Bgra8)); var capturedPhoto = await lowlagCapture.CaptureAsync(); var softwareBitmap = capturedPhoto.Frame.SoftwareBitmap; var softwareBitmapSource = new SoftwareBitmapSource(); await softwareBitmapSource.SetBitmapAsync(SoftwareBitmap.Convert(softwareBitmap, BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied)); await lowlagCapture.FinishAsync(); _isPreviewing = false; /*var filename = "pb" + DateTime.Now.ToString("ssmmHHddMMyy") + ".bmp"; * var file = await savePicturesFolder.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting); * await _mediaCapture.CapturePhotoToStorageFileAsync(ImageEncodingProperties.CreateJpeg(), file); * * IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.Read); * BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream); * SoftwareBitmap softwareBitmap = await decoder.GetSoftwareBitmapAsync(); * SoftwareBitmapSource softwareBitmapSource = new SoftwareBitmapSource(); * await softwareBitmapSource.SetBitmapAsync(SoftwareBitmap.Convert(softwareBitmap, BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied));*/ activepicture.Source = softwareBitmapSource; images.Add(softwareBitmap); await CleanupCameraAsync(); if (picstaken < totpics) { picstaken++; activepicture = (Image)this.FindName("image" + picstaken.ToString()); await StartPreviewAsync(); } else { complete = true; StartButton.Visibility = Visibility.Visible; dispatchTimer.Stop(); mergePhotos(); } }
private async Task InitializeForLowLight() { _lowLightSupported = _mediaCapture.VideoDeviceController.AdvancedPhotoControl.SupportedModes.Contains(Windows.Media.Devices.AdvancedPhotoMode.LowLight); _mediaCapture.VideoDeviceController.DesiredOptimization = MediaCaptureOptimization.Quality; if (_lowLightSupported) { // Choose LowLight mode var settings = new AdvancedPhotoCaptureSettings { Mode = AdvancedPhotoMode.LowLight }; _mediaCapture.VideoDeviceController.AdvancedPhotoControl.Configure(settings); // Prepare for an advanced capture _advancedCapture = await _mediaCapture.PrepareAdvancedPhotoCaptureAsync(ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Nv12)); } }
public async void TakePhotoAsync() { mediaCapture = new MediaCapture(); await mediaCapture.InitializeAsync(); //mediaCapture.Failed += MediaCapture_Failed; // Prepare and capture photo var lowLagCapture = await mediaCapture.PrepareLowLagPhotoCaptureAsync(ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Bgra8)); var capturedPhoto = await lowLagCapture.CaptureAsync(); var softwareBitmap = capturedPhoto.Frame.SoftwareBitmap; await lowLagCapture.FinishAsync(); var myPictures = await Windows.Storage.StorageLibrary.GetLibraryAsync(Windows.Storage.KnownLibraryId.Pictures); StorageFile file = await myPictures.SaveFolder.CreateFileAsync("frontview.jpg", CreationCollisionOption.ReplaceExisting); using (var captureStream = new InMemoryRandomAccessStream()) { await mediaCapture.CapturePhotoToStreamAsync(ImageEncodingProperties.CreateJpeg(), captureStream); using (var fileStream = await file.OpenAsync(FileAccessMode.ReadWrite)) { var decoder = await BitmapDecoder.CreateAsync(captureStream); var encoder = await BitmapEncoder.CreateForTranscodingAsync(fileStream, decoder); var properties = new BitmapPropertySet { { "System.Photo.Orientation", new BitmapTypedValue(PhotoOrientation.Normal, PropertyType.UInt16) } }; await encoder.BitmapProperties.SetPropertiesAsync(properties); await encoder.FlushAsync(); } } }
private async void Capture_button_Click(object sender, RoutedEventArgs e) { _mediaCapture = new MediaCapture(); await _mediaCapture.InitializeAsync(); // Prepare and capture photo var lowLagCapture = await _mediaCapture.PrepareLowLagPhotoCaptureAsync(ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Bgra8)); var capturedPhoto = await lowLagCapture.CaptureAsync(); var softwareBitmap = capturedPhoto.Frame.SoftwareBitmap; await lowLagCapture.FinishAsync(); var myPictures = await Windows.Storage.StorageLibrary.GetLibraryAsync(Windows.Storage.KnownLibraryId.Pictures); StorageFile file = await myPictures.SaveFolder.CreateFileAsync("photo.jpg", CreationCollisionOption.GenerateUniqueName); using (var captureStream = new InMemoryRandomAccessStream()) { await _mediaCapture.CapturePhotoToStreamAsync(ImageEncodingProperties.CreateJpeg(), captureStream); using (var fileStream = await file.OpenAsync(FileAccessMode.ReadWrite)) { var decoder = await BitmapDecoder.CreateAsync(captureStream); var encoder = await BitmapEncoder.CreateForTranscodingAsync(fileStream, decoder); var properties = new BitmapPropertySet { { "System.Photo.Orientation", new BitmapTypedValue(PhotoOrientation.Normal, PropertyType.UInt16) } }; await encoder.BitmapProperties.SetPropertiesAsync(properties); await encoder.FlushAsync(); } } Comfirmation.Text = "Picture Saved!"; }
/// <summary> /// Captures a still image from the webcam as a bitmap, handing the result over to the supplied action delegate. /// </summary> /// <param name="capturedBitmapAction">A CapturedBitmapAction delegate to handle the captured image data.</param> public async void CaptureSoftwareBitmap(CapturedBitmapAction capturedBitmapAction) { if (isCapturing) { return; } isCapturing = true; var properties = ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Nv12); var lowLagCapture = await mediaCapture.PrepareLowLagPhotoCaptureAsync(properties); var capturedPhoto = await lowLagCapture.CaptureAsync(); var softwareBitmap = capturedPhoto.Frame.SoftwareBitmap; capturedBitmapAction(softwareBitmap); await lowLagCapture.FinishAsync(); isCapturing = false; }
private async void CaptureButton_Click(object sender, RoutedEventArgs e) { //Capturing the photo var capture = await mediaCapture.PrepareLowLagPhotoCaptureAsync(ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Bgra8)); var photo = await capture.CaptureAsync(); //Creating the bitmap var softwareBitmap = photo.Frame.SoftwareBitmap; await capture.FinishAsync(); //API call CognitiveServiceHelper.FetchApi(softwareBitmap); //Converting the bitmap var convertedSoftwareBitmap = SoftwareBitmap.Convert(softwareBitmap, BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied); //Creating a bitmap source to set to the image source var bitmapSource = new SoftwareBitmapSource(); await bitmapSource.SetBitmapAsync(convertedSoftwareBitmap); //Drawing the taken picture (without drawing the face rectangle on it, due to fail in the API call) Photo.Source = bitmapSource; //Setting the size of the wrapper grid element, so the popups size is the full view WrapperGrid.Width = Window.Current.Bounds.Width; WrapperGrid.Height = Window.Current.Bounds.Height; //Disabling capture button CaptureButton.IsEnabled = false; //Showing the popup ImagePopup.IsOpen = true; }
/// <summary> /// Initializes a new instance of the MediaCapture class setting a camera device. /// </summary> public async Task InitializeCameraAsync() { try { var devices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture); var device = devices[0]; _capture = new MediaCapture(); var settings = new MediaCaptureInitializationSettings { VideoDeviceId = device.Id }; await _capture.InitializeAsync(settings); _lowLagPhotoCapture = await _capture.PrepareLowLagPhotoCaptureAsync( ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Bgra8)); _capture.VideoDeviceController.Focus.TrySetAuto(true); } catch (Exception e) { await OnProcessNotice(e.ToString()); } }
private async void snapButton_Click(object sender, RoutedEventArgs e) { if ((String)snapButton.Content == "Discard") { PreviewControl.Visibility = Visibility.Visible; StillImage.Visibility = Visibility.Collapsed; snapButton.Content = "Capture"; } else { // Prepare and capture photo var lowLagCapture = await _mediaCapture.PrepareLowLagPhotoCaptureAsync(ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Bgra8)); var capturedPhoto = await lowLagCapture.CaptureAsync(); _softwareBitMap = capturedPhoto.Frame.SoftwareBitmap; await lowLagCapture.FinishAsync(); PreviewControl.Visibility = Visibility.Collapsed; StillImage.Visibility = Visibility.Visible; snapButton.Content = "Discard"; if (_softwareBitMap.BitmapPixelFormat != BitmapPixelFormat.Bgra8 || _softwareBitMap.BitmapAlphaMode == BitmapAlphaMode.Straight) { _softwareBitMap = SoftwareBitmap.Convert(_softwareBitMap, BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied); } var source = new SoftwareBitmapSource(); await source.SetBitmapAsync(_softwareBitMap); // Set the source of the Image control StillImage.Source = source; } }
private async void captureQr(object sender, object e) { try{ mediaCapture = new MediaCapture(); await mediaCapture.InitializeAsync(); // Prepare and capture photo var lowLagCapture = await mediaCapture.PrepareLowLagPhotoCaptureAsync(ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Bgra8)); var capturedPhoto = await lowLagCapture.CaptureAsync(); var softwareBitmap = capturedPhoto.Frame.SoftwareBitmap; BarcodeReader r = new BarcodeReader(); Result res = r.Decode(softwareBitmap); if (res != null) { Passagier passagier = ((App)Application.Current).Zetel.Passagier; if (res.Text == "admin") { Frame.Navigate(typeof(LoginPersoneel), null, new DrillInNavigationTransitionInfo()); } if (passagier.getCode() == res.Text) { Frame.Navigate(typeof(MainPage), null, new DrillInNavigationTransitionInfo()); } else { myStoryboard.Begin(); Melding.Text = "Verkeerde boarding pass"; } } await lowLagCapture.FinishAsync(); }catch (UnauthorizedAccessException ex) { Melding.Opacity = 1; Melding.Text = "Geen toegang tot webcam of microfoon kijk naar de readme"; } catch (Exception ex) { Console.Write(ex); } }
public async Task <SoftwareBitmap> CapturePhoto(MediaCapture mediaCapture) { using (var captureStream = new InMemoryRandomAccessStream()) { await mediaCapture.CapturePhotoToStreamAsync(ImageEncodingProperties.CreateBmp(), captureStream); var lowLagCapture = await mediaCapture.PrepareLowLagPhotoCaptureAsync(ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Bgra8)); var capturedPhoto = await lowLagCapture.CaptureAsync(); var softwareBitmap = capturedPhoto.Frame.SoftwareBitmap; await lowLagCapture.FinishAsync(); return(softwareBitmap); } }
/// <summary> /// Capture a Picture Method /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void CaptureToFile() { try { // Prepare and capture photo var lowLagCapture = await _mediaCapture.PrepareLowLagPhotoCaptureAsync(ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Bgra8)); var capturedPhoto = await lowLagCapture.CaptureAsync(); var softwareBitmap = capturedPhoto.Frame.SoftwareBitmap; await lowLagCapture.FinishAsync(); if (softwareBitmap.BitmapPixelFormat != BitmapPixelFormat.Bgra8 || softwareBitmap.BitmapAlphaMode == BitmapAlphaMode.Straight) { softwareBitmap = SoftwareBitmap.Convert(softwareBitmap, BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied); } var bitmapSource = new SoftwareBitmapSource(); await bitmapSource.SetBitmapAsync(softwareBitmap); captureImage.Source = bitmapSource; //to file saveFileCount++; fileNameWithType = saveFileCount.ToString() + " " + fileNameBox.Text + ".jpg"; var myPictures = await Windows.Storage.StorageLibrary.GetLibraryAsync(Windows.Storage.KnownLibraryId.Pictures); file = await myPictures.SaveFolder.CreateFileAsync(fileNameWithType, CreationCollisionOption.GenerateUniqueName); using (var captureStream = new InMemoryRandomAccessStream()) { await _mediaCapture.CapturePhotoToStreamAsync(ImageEncodingProperties.CreateJpeg(), captureStream); using (var fileStream = await file.OpenAsync(FileAccessMode.ReadWrite)) { var decoder = await BitmapDecoder.CreateAsync(captureStream); var encoder = await BitmapEncoder.CreateForTranscodingAsync(fileStream, decoder); var properties = new BitmapPropertySet { { "System.Photo.Orientation", new BitmapTypedValue(PhotoOrientation.Normal, PropertyType.UInt16) } }; await encoder.BitmapProperties.SetPropertiesAsync(properties); await encoder.FlushAsync(); } } } catch { } }//end CaptureToFile
public async Task <CapturedPhoto> TakeShot() { var mediaCapture = new MediaCapture(); try { await mediaCapture.InitializeAsync(); var lowLagCapture = await mediaCapture.PrepareLowLagPhotoCaptureAsync(ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Bgra8)); var capturedPhoto = await lowLagCapture.CaptureAsync(); await lowLagCapture.FinishAsync(); return(capturedPhoto); } catch (Exception) { throw; } }