public CapturePhotoToStorageFileAsync ( [ type, [ file ) : IAsyncAction | ||
type | [ | |
file | [ | |
return | IAsyncAction |
internal async void btnTakePhoto_Click(Object sender, Windows.UI.Xaml.RoutedEventArgs e) { try { ShowStatusMessage("Taking photo"); EnableButton(false, "TakePhoto"); m_photoStorageFile = await Windows.Storage.KnownFolders.PicturesLibrary.CreateFileAsync(PHOTO_FILE_NAME, Windows.Storage.CreationCollisionOption.GenerateUniqueName); ShowStatusMessage("Create photo file successful"); ImageEncodingProperties imageProperties = ImageEncodingProperties.CreateJpeg(); await m_mediaCaptureMgr.CapturePhotoToStorageFileAsync(imageProperties, m_photoStorageFile); EnableButton(true, "TakePhoto"); ShowStatusMessage("Photo taken"); var photoStream = await m_photoStorageFile.OpenAsync(Windows.Storage.FileAccessMode.Read); ShowStatusMessage("File open successful"); var bmpimg = new BitmapImage(); bmpimg.SetSource(photoStream); imageElement1.Source = bmpimg; ShowStatusMessage(this.m_photoStorageFile.Path); } catch (Exception exception) { ShowExceptionMessage(exception); EnableButton(true, "TakePhoto"); } }
async private void CapturePhoto_Click(object sender, RoutedEventArgs e) { ImageEncodingProperties imgFormat = ImageEncodingProperties.CreateJpeg(); StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync( "TestPhoto.jpg", CreationCollisionOption.GenerateUniqueName); await captureManager.CapturePhotoToStorageFileAsync(imgFormat, file); BitmapImage bmpImage = new BitmapImage(new Uri(file.Path)); if (i == 0) { imagePreivew.Source = bmpImage; i++; } else if (i == 1) { imagePreivew2.Source = bmpImage; i++; } else if (i == 2) { imagePreivew3.Source = bmpImage; i++; } else { imagePreivew.Source = bmpImage; i = 1; } }
async private void btnTakePhoto_Click(object sender, RoutedEventArgs e) { ImageEncodingProperties imgFormat = ImageEncodingProperties.CreateJpeg(); // TODO: If option replace existing is selected then the replacement // doesnt work StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync( "photo.jpg", CreationCollisionOption.GenerateUniqueName); await _captureManager.CapturePhotoToStorageFileAsync(imgFormat, file); ImageBrush imageBrush = new ImageBrush(); BitmapImage biCapturedPhoto = new BitmapImage(); biCapturedPhoto.UriSource = new Uri(file.Path, UriKind.RelativeOrAbsolute); imageBrush.ImageSource = biCapturedPhoto; if (PocketPaintApplication.GetInstance().isLoadPictureClicked) { RectangleGeometry myRectangleGeometry = new RectangleGeometry(); myRectangleGeometry.Rect = new Rect(new Point(0, 0), new Point(Window.Current.Bounds.Height, Window.Current.Bounds.Width)); RotateTransform rotate = new RotateTransform(); TransformGroup transformGroup = new TransformGroup(); Path _path = new Path(); // HACK: Is needed to align the captured photo. if (isBackCameraActive) { rotate.Angle = 90; transformGroup.Children.Add(rotate); Canvas.SetLeft(_path, PocketPaintApplication.GetInstance().PaintingAreaCanvas.Width); } else { rotate.Angle = -90; Canvas.SetTop(_path, PocketPaintApplication.GetInstance().PaintingAreaCanvas.Height); transformGroup.Children.Add(rotate); } _path.Fill = imageBrush; _path.Stroke = PocketPaintApplication.GetInstance().PaintData.strokeColorSelected; _path.RenderTransform = transformGroup; _path.Data = myRectangleGeometry; PocketPaintApplication.GetInstance().PaintingAreaCanvas.Children.Clear(); PocketPaintApplication.GetInstance().PaintingAreaCanvas.Children.Add(_path); CommandManager.GetInstance().CommitCommand(new LoadPictureCommand(_path)); } else { PocketPaintApplication.GetInstance().ImportImageSelectionControl.imageSourceOfRectangleToDraw = imageBrush; PocketPaintApplication.GetInstance().PaintingAreaView.changeBackgroundColorAndOpacityOfPaintingAreaCanvas(Colors.Black, 0.5); } closePhoneControl(sender, e); }
private async void StartButton_Click(object sender, RoutedEventArgs e) { var mediaCapture = new MediaCapture(); await mediaCapture.InitializeAsync(); var imageEncodingProperties = ImageEncodingProperties.CreateJpeg(); var desiredName = string.Format("TEST_{0}_{1}.jpg", DateTime.Now.ToString("yyMMdd_HHmmss"), 1); var storageFile = await KnownFolders.CameraRoll.CreateFileAsync(desiredName, CreationCollisionOption.GenerateUniqueName); await mediaCapture.CapturePhotoToStorageFileAsync(imageEncodingProperties, storageFile); }
internal async void btnTakePhoto_Click(Object sender, Windows.UI.Xaml.RoutedEventArgs e) { try { ShowStatusMessage("Taking photo"); btnTakePhoto1.IsEnabled = false; if (!m_mediaCaptureMgr.MediaCaptureSettings.ConcurrentRecordAndPhotoSupported) { //if camera does not support record and Takephoto at the same time //disable Record button when taking photo btnStartStopRecord1.IsEnabled = false; } m_photoStorageFile = await Windows.Storage.KnownFolders.PicturesLibrary.CreateFileAsync(PHOTO_FILE_NAME, Windows.Storage.CreationCollisionOption.GenerateUniqueName); ShowStatusMessage("Create photo file successful"); ImageEncodingProperties imageProperties = ImageEncodingProperties.CreateJpeg(); await m_mediaCaptureMgr.CapturePhotoToStorageFileAsync(imageProperties, m_photoStorageFile); btnTakePhoto1.IsEnabled = true; ShowStatusMessage("Photo taken"); if (!m_mediaCaptureMgr.MediaCaptureSettings.ConcurrentRecordAndPhotoSupported) { //if camera does not support record and Takephoto at the same time //enable Record button after taking photo btnStartStopRecord1.IsEnabled = true; } var photoStream = await m_photoStorageFile.OpenAsync(Windows.Storage.FileAccessMode.Read); ShowStatusMessage("File open successful"); var bmpimg = new BitmapImage(); bmpimg.SetSource(photoStream); imageElement1.Source = bmpimg; ShowStatusMessage(this.m_photoStorageFile.Path); } catch (Exception exception) { ShowExceptionMessage(exception); btnTakePhoto1.IsEnabled = true; } }
async private void CapturePhoto_Click(object sender, RoutedEventArgs e) { ImageEncodingProperties imgFormat = ImageEncodingProperties.CreateJpeg(); // create storage file in local app storage StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync( "TestPhoto.jpg", CreationCollisionOption.GenerateUniqueName); // take photo await captureManager.CapturePhotoToStorageFileAsync(imgFormat, file); // Get photo as a BitmapImage BitmapImage bmpImage = new BitmapImage(new Uri(file.Path)); // imagePreview is a <Image> object defined in XAML imagePreview.Source = bmpImage; }
public static async Task<StorageFile> TakeWebCamPictureAndReturnFile(bool takeSilentPicture) { StorageFile file; if (takeSilentPicture) { var takePhotoManager = new MediaCapture(); await takePhotoManager.InitializeAsync(); var imgFormat = ImageEncodingProperties.CreateJpeg(); file = await ApplicationData.Current.TemporaryFolder.CreateFileAsync("CameraPhoto.jpg", CreationCollisionOption.ReplaceExisting); await takePhotoManager.CapturePhotoToStorageFileAsync(imgFormat, file); } else { var dialog = new CameraCaptureUI(); dialog.PhotoSettings.AllowCropping = false; dialog.PhotoSettings.MaxResolution = CameraCaptureUIMaxPhotoResolution.HighestAvailable; file = await dialog.CaptureFileAsync(CameraCaptureUIMode.Photo); } return file; }
private static async Task<StorageFile> StorageFileFromCamera() { var filename = String.Format("{0}.jpg", Guid.NewGuid().ToString()); var file = await ApplicationData.Current.LocalFolder.CreateFileAsync( filename, CreationCollisionOption.ReplaceExisting); var encoding = ImageEncodingProperties.CreateJpeg(); var capture = new MediaCapture(); await capture.InitializeAsync(); await capture.CapturePhotoToStorageFileAsync(encoding, file); return file; }
private async void ButtonPhotoClicked(object sender, RoutedEventArgs e) { var _MediaCapture = new MediaCapture(); await _MediaCapture.InitializeAsync(); var _Name = Guid.NewGuid().ToString(); var _Opt = CreationCollisionOption.ReplaceExisting; var _File = await ApplicationData.Current.LocalFolder.CreateFileAsync(_Name, _Opt); var _ImageFormat = ImageEncodingProperties.CreatePng(); await _MediaCapture.CapturePhotoToStorageFileAsync(_ImageFormat, _File); var _BitmapImage = new BitmapImage(new Uri(_File.Path)); canvasInteraction.DrawImage(new Point(0.1, 0.1), new Size(0.1, 0.1), _BitmapImage); using (var inputStream = await _File.OpenSequentialReadAsync()) { var readStream = inputStream.AsStreamForRead(); var buffer = new byte[readStream.Length]; await readStream.ReadAsync(buffer, 0, buffer.Length); Object image = new { img = "data:image/png;base64," + Convert.ToBase64String(buffer), x = 0.1, y = 0.1, w = 0.1, h = 0.1 }; lio.send("image", image, false); } }