public async Task CaptureAsync() { // Status prüfen if (!_isInitialized) { return; } if (_isCapturing) { return; } _isCapturing = true; // Fokus prüfen if (!_isFocused) { await AutoFocusAsync(); } // Bild aufnehmen await _captureSequence.StartCaptureAsync(); // Aufgenommene Bytes in Eigenschaft speichern ImageBytes = _captureStream.ToArray(); SendPhotoCaptured(); // CaptureStream zurücksetzen für nächste Aufnahme _captureStream = new MemoryStream(); _captureSequence.Frames[0].CaptureStream = _captureStream.AsOutputStream(); _isCapturing = false; _isFocused = false; }
/// <summary> /// Captures a photo. Photo data is stored to ImageStream, and /// application is navigated to the preview page after capturing. /// </summary> private async Task Capture() { bool goToPreview = false; MemoryStream photoStream = new MemoryStream(); MemoryStream thumbnailStream = new MemoryStream(); if (!_capturing) { _capturing = true; CameraCaptureSequence sequence = _photoCaptureDevice.CreateCaptureSequence(1); sequence.Frames[0].CaptureStream = photoStream.AsOutputStream(); sequence.Frames[0].ThumbnailStream = thumbnailStream.AsOutputStream(); await _photoCaptureDevice.PrepareCaptureSequenceAsync(sequence); await sequence.StartCaptureAsync(); _capturing = false; goToPreview = true; } _photoCaptureDevice.SetProperty( KnownCameraPhotoProperties.LockedAutoFocusParameters, AutoFocusParameters.None); if (goToPreview) { NokiaImaginHelper.PreparePhoto(photoStream, thumbnailStream); NavigationService.Navigate(new Uri(String.Format("/FilterPreviewPage.xaml?index={0}&shouldCrop={1}", _dateIndex, _sizeMode), UriKind.Relative)); } }
//private void FrameAcquiredEvent(CameraCaptureSequence sequence, FrameAcquiredEventArgs e) //{ //RESTAPI.RESTAPIHandler.upload_image(sequence.Frames[0].CaptureStream); //} /// <summary> /// Added by Pat: Capture a sequence of photos. /// </summary> private async Task CapturePhotoSequence() { if (_capturing) { MessageBox.Show("Already capturing photos?"); return; } while (_capturing_sequence) { _capturing = true; MemoryStream stream = new MemoryStream(); // This API is a stub for what we want to do in the future -- the only valid value // for the sequence is 1. So we just keep taking a series of 1-picture sequences CameraCaptureSequence sequence = _dataContext.Device.CreateCaptureSequence(1); sequence.Frames[0].CaptureStream = stream.AsOutputStream(); await _dataContext.Device.PrepareCaptureSequenceAsync(sequence); await sequence.StartCaptureAsync(); stream.Seek(0, SeekOrigin.Begin); RESTAPI.RESTAPIHandler.upload_image(_dataContext.UploadUrl.Url, stream); //await Task.Delay(1000); } _capturing = false; }
/// <summary> /// Captures a photo. Photo data is stored to DataContext.ImageStream, and application /// is navigated to the preview page after capturing. /// </summary> private async Task Capture() { try { bool goToPreview = false; var selfieBitmap = new BitmapImage(); if (!_capturing) { _capturing = true; var stream = new MemoryStream(); CameraCaptureSequence sequence = PhotoCaptureDevice.CreateCaptureSequence(1); sequence.Frames[0].CaptureStream = stream.AsOutputStream(); await PhotoCaptureDevice.PrepareCaptureSequenceAsync(sequence); await sequence.StartCaptureAsync(); selfieBitmap = new BitmapImage(); selfieBitmap.SetSource(stream); _capturing = false; // Defer navigation as it will release the camera device and the // following Device calls must still work. goToPreview = true; } _manuallyFocused = false; if (PhotoCaptureDevice.IsFocusRegionSupported(PhotoCaptureDevice.SensorLocation)) { PhotoCaptureDevice.FocusRegion = null; } FocusIndicator.SetValue(VisibilityProperty, Visibility.Collapsed); PhotoCaptureDevice.SetProperty(KnownCameraPhotoProperties.LockedAutoFocusParameters, AutoFocusParameters.None); if (goToPreview) { NavigateService.NavigateTo(typeof(PreviewSelfiePage), NavigationParameter.Normal, selfieBitmap); } } catch (Exception e) { Deployment.Current.Dispatcher.BeginInvoke(() => { new CustomMessageDialog( AppMessages.CapturePhotoVideoFailed_Title, String.Format(AppMessages.CapturePhotoVideoFailed, e.Message), App.AppInformation, MessageDialogButtons.Ok).ShowDialog(); }); } }
public async void capture(bool get_preview, bool register) { if (get_preview == true) { _camera.GetPreviewBufferArgb(preview_image); } // Take a picture. Flag busy meanwhile. cam_busy = true; // If register mode is enabled, sleep for 500ms. if (register == true) { await System.Threading.Tasks.Task.Delay(500); } await _camsequence.StartCaptureAsync(); cam_busy = false; transmit = true; imstream.Seek(0, SeekOrigin.Begin); }
/// <summary> /// Captures a photo. Photo data is stored to DataContext.ImageStream, and application /// is navigated to the preview page after capturing. /// </summary> private async Task Capture() { bool goToPreview = false; if (!_capturing) { _capturing = true; MemoryStream stream = new MemoryStream(); CameraCaptureSequence sequence = _dataContext.Device.CreateCaptureSequence(1); sequence.Frames[0].CaptureStream = stream.AsOutputStream(); await _dataContext.Device.PrepareCaptureSequenceAsync(sequence); await sequence.StartCaptureAsync(); _dataContext.ImageStream = stream; _capturing = false; // Defer navigation as it will release the camera device and the // following Device calls must still work. goToPreview = true; } _manuallyFocused = false; if (PhotoCaptureDevice.IsFocusRegionSupported(_dataContext.Device.SensorLocation)) { _dataContext.Device.FocusRegion = null; } FocusIndicator.SetValue(Canvas.VisibilityProperty, Visibility.Collapsed); _dataContext.Device.SetProperty(KnownCameraPhotoProperties.LockedAutoFocusParameters, AutoFocusParameters.None); if (goToPreview) { NavigationService.Navigate(new Uri("/PreviewPage.xaml", UriKind.Relative)); } }
/// <summary> /// Captures a photo. Photo data is stored to ImageStream, and /// application is navigated to the preview page after capturing. /// </summary> private async Task Capture() { bool goToPreview = false; if (!_capturing) { _capturing = true; DataContext dataContext = FilterEffects.DataContext.Singleton; // Reset the streams dataContext.ImageStream.Seek(0, SeekOrigin.Begin); dataContext.ThumbStream.Seek(0, SeekOrigin.Begin); CameraCaptureSequence sequence = _photoCaptureDevice.CreateCaptureSequence(1); sequence.Frames[0].CaptureStream = dataContext.ImageStream.AsOutputStream(); sequence.Frames[0].ThumbnailStream = dataContext.ThumbStream.AsOutputStream(); await _photoCaptureDevice.PrepareCaptureSequenceAsync(sequence); await sequence.StartCaptureAsync(); // Get the storyboard from application resources Storyboard sb = (Storyboard)Resources["CaptureAnimation"]; sb.Begin(); _capturing = false; goToPreview = true; } _photoCaptureDevice.SetProperty( KnownCameraPhotoProperties.LockedAutoFocusParameters, AutoFocusParameters.None); if (goToPreview) { NavigationService.Navigate(new Uri("/FilterPreviewPage.xaml", UriKind.Relative)); } }
private async void CapturePhoto() { try { CameraCaptureSequence sequence = captureDevice.CreateCaptureSequence(1); captureDevice.SetProperty(KnownCameraGeneralProperties.AutoFocusRange, AutoFocusRange.Infinity); captureDevice.SetProperty(KnownCameraGeneralProperties.PlayShutterSoundOnCapture, true); //captureDevice.SetProperty(KnownCameraPhotoProperties.FlashMode, FlashState.On); MemoryStream captureStream1 = new MemoryStream(); sequence.Frames[0].CaptureStream = captureStream1.AsOutputStream(); await captureDevice.PrepareCaptureSequenceAsync(sequence); await sequence.StartCaptureAsync(); captureStream1.Seek(0, SeekOrigin.Begin); MediaLibrary library = new MediaLibrary(); string filename = "IMG_" + saveCounter; Picture pic1 = library.SavePictureToCameraRoll(filename, captureStream1); //Save picture in cameraroll //Update Background Cameraroll Button BitmapImage bitImage = new BitmapImage(); bitImage.SetSource(pic1.GetThumbnail()); ImageBrush imgButton = new ImageBrush(); imgButton.ImageSource = bitImage; CameraRollButton.Background = imgButton; saveCounter++; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
public async Task <Stream> CaptureAsync(bool focusBeforeCapture = true) { ThrowIfDisposed(); if (!_inited) { throw new InvalidOperationException("not inited"); } if (_capturing) { throw new InvalidOperationException("is already capturing"); } MemoryStream stream = null; _capturing = true; try { CameraCaptureSequence seq = _device.CreateCaptureSequence(1); stream = new MemoryStream(); seq.Frames[0].CaptureStream = stream.AsOutputStream(); await _device.PrepareCaptureSequenceAsync(seq); ThrowIfDisposed(); if (focusBeforeCapture) { await FocusAsyncInternal(); // focus before capture } ThrowIfDisposed(); #region Wait for auto focus hack if (_focusing) { await AwaitWhenNotFocusing(); ThrowIfDisposed(); } #endregion // Wait for auto focus hack await seq.StartCaptureAsync(); } catch (ObjectDisposedException) { throw new CardCaptureDeviceDisposedException(); } catch (Exception ex) { ThrowExceptionOrDisposed(new CaptureFailedException(ex.Message), false); } finally { _capturing = false; } ThrowIfDisposed(); return(stream); }
private async void TakeSnapShot() { lock (_lockObject) { _cameraInUse = true; TakingPictureText = AppResources.TakingPictureText; } try { CameraCaptureSequence seq = _cameraCaptureDevice.CreateCaptureSequence(1); if (!FrontCamera) { if (FlashOn) { _cameraCaptureDevice.SetProperty(KnownCameraPhotoProperties.FlashMode, FlashState.On); } else { _cameraCaptureDevice.SetProperty(KnownCameraPhotoProperties.FlashMode, FlashState.Off); } } if (SoundOn) { _cameraCaptureDevice.SetProperty(KnownCameraGeneralProperties.PlayShutterSoundOnCapture, true); } else { _cameraCaptureDevice.SetProperty(KnownCameraGeneralProperties.PlayShutterSoundOnCapture, false); } await _cameraCaptureDevice.SetCaptureResolutionAsync(SelectedResolution.CameraResolution); MemoryStream stream = new MemoryStream(); seq.Frames[0].CaptureStream = stream.AsOutputStream(); if (FocusOn) { await _cameraCaptureDevice.FocusAsync(); } await _cameraCaptureDevice.PrepareCaptureSequenceAsync(seq); await seq.StartCaptureAsync(); int countOfPictures = _mediaLibrary.SavedPictures.Count(); //Not sure what this is, but we need it to save to library stream.Seek(0, SeekOrigin.Begin); _mediaLibrary.SavePictureToCameraRoll("spycam" + countOfPictures, stream); stream.Position = 0; var imageSource = new BitmapImage(); imageSource.SetSource(stream); SetCenterXAndCenterY(imageSource); LastPictureTaken = imageSource; } catch (Exception ex) { } lock (_lockObject) { _cameraInUse = false; PictureCount = PictureCount + 1; TakingPictureText = string.Empty; } }