public async Task <StorageFile> CapturePhotoAsync() { if (_mediaCapture == null) { return(null); } var stream = new InMemoryRandomAccessStream(); await _mediaCapture.CapturePhotoToStreamAsync(ImageEncodingProperties.CreateJpeg(), stream); try { var filename = "adventure_" + DateTime.Now.ToString("HHmmss_MMddyyyy") + ".jpg"; var file = await(await AdventureObjectStorageHelper.GetDataSaveFolder()).CreateFileAsync(filename, CreationCollisionOption.GenerateUniqueName); using (var outputStream = await file.OpenAsync(FileAccessMode.ReadWrite)) { var decoder = await BitmapDecoder.CreateAsync(stream); var encoder = await BitmapEncoder.CreateForTranscodingAsync(outputStream, decoder); var photoOrientation = ConvertOrientationToPhotoOrientation(GetCameraOrientation()); var properties = new BitmapPropertySet { { "System.Photo.Orientation", new BitmapTypedValue(photoOrientation, Windows.Foundation.PropertyType.UInt16) } }; await encoder.BitmapProperties.SetPropertiesAsync(properties); await encoder.FlushAsync(); } stream.Dispose(); PictureCaptured?.Invoke(this, new PictureCapturedEventArgs() { File = file }); return(file); } catch (Exception ex) { stream.Dispose(); return(null); } }
public void RaisePictureCaptured(IRandomAccessStream stream) => PictureCaptured?.Invoke(this, new PictureCapturedEventArgs(stream));