public async void initialise() { // Disable transmit. transmit = false; // Get available resolutions. IReadOnlyList <Windows.Foundation.Size> available_res = PhotoCaptureDevice.GetAvailableCaptureResolutions(CameraSensorLocation.Back); int count = available_res.Count; // Make the resolution details public imheight = (int)available_res[count - 1].Height; imwidth = (int)available_res[count - 1].Width; // Allocate memory for the preview image variable preview_image = new int[imheight * imwidth]; // Open a new capture device asynchronously. cam_open_busy = true; _camera = await PhotoCaptureDevice.OpenAsync(CameraSensorLocation.Back, available_res[count - 1]); cam_open_busy = false; // Set the exposure time to 200ms // _camera.SetProperty(KnownCameraPhotoProperties.ExposureTime, 200000); // Create a new sequence _camsequence = _camera.CreateCaptureSequence(1); // Create a new memory stream. imstream = new MemoryStream(); _camsequence.Frames[0].CaptureStream = imstream.AsOutputStream(); // Wait for the camera to initialize. await _camera.PrepareCaptureSequenceAsync(_camsequence); }
public async Task InitializeAsync() { if (_isInitialized) { return; } IReadOnlyList<Size> availableCaptureResulotions = PhotoCaptureDevice.GetAvailableCaptureResolutions(CameraSensorLocation.Back); Device = await PhotoCaptureDevice.OpenAsync(CameraSensorLocation.Back, availableCaptureResulotions.First()); InitParameters(); Device.SetProperty(KnownCameraGeneralProperties.PlayShutterSoundOnCapture, true); _captureStream = new MemoryStream(); _captureSequence = Device.CreateCaptureSequence(1); _captureSequence.Frames[0].CaptureStream = _captureStream.AsOutputStream(); await Device.PrepareCaptureSequenceAsync(_captureSequence); CameraButtons.ShutterKeyHalfPressed += CameraButtons_ShutterKeyHalfPressed; CameraButtons.ShutterKeyPressed += CameraButtons_ShutterKeyPressed; CameraButtons.ShutterKeyReleased += CameraButtons_ShutterKeyReleased; _isInitialized = true; }
public async Task InitializeAsync() { if (_isInitialized) { return; } IReadOnlyList <Size> availableCaptureResulotions = PhotoCaptureDevice.GetAvailableCaptureResolutions(CameraSensorLocation.Back); Device = await PhotoCaptureDevice.OpenAsync(CameraSensorLocation.Back, availableCaptureResulotions.First()); InitParameters(); Device.SetProperty(KnownCameraGeneralProperties.PlayShutterSoundOnCapture, true); _captureStream = new MemoryStream(); _captureSequence = Device.CreateCaptureSequence(1); _captureSequence.Frames[0].CaptureStream = _captureStream.AsOutputStream(); await Device.PrepareCaptureSequenceAsync(_captureSequence); CameraButtons.ShutterKeyHalfPressed += CameraButtons_ShutterKeyHalfPressed; CameraButtons.ShutterKeyPressed += CameraButtons_ShutterKeyPressed; CameraButtons.ShutterKeyReleased += CameraButtons_ShutterKeyReleased; _isInitialized = true; }
/// <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(); }); } }
private async Task StartCapturingAsync() { CameraCaptureSequence sequence = device.CreateCaptureSequence(1); var memoryStream = new MemoryStream(); sequence.Frames[0].CaptureStream = memoryStream.AsOutputStream(); device.SetProperty(KnownCameraPhotoProperties.FlashMode, FlashState.Off); device.SetProperty(KnownCameraPhotoProperties.SceneMode, CameraSceneMode.Macro); await device.PrepareCaptureSequenceAsync(sequence); }
private void DestroyCam() { if (cam != null) { cam.Dispose(); cam = null; seq = null; } CameraButtons.ShutterKeyHalfPressed -= OnShutterHalfPress; CameraButtons.ShutterKeyPressed -= OnShutterFullPress; CameraButtons.ShutterKeyReleased -= OnShutterReleased; }
private async Task StartCapturingAsync() { CameraCaptureSequence sequence = PhotoCaptureDevice.CreateCaptureSequence(1); var memoryStream = new MemoryStream(); sequence.Frames[0].CaptureStream = memoryStream.AsOutputStream(); try { PhotoCaptureDevice.SetProperty(KnownCameraPhotoProperties.FlashMode, FlashState.Off); PhotoCaptureDevice.SetProperty(KnownCameraPhotoProperties.SceneMode, CameraSceneMode.Macro); } catch { // one or more properties not supported } await PhotoCaptureDevice.PrepareCaptureSequenceAsync(sequence); }
/// <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()); } }
private void cameraCaptureSequence_FrameAcquired(CameraCaptureSequence sender, FrameAcquiredEventArgs args) { FrameAcquired(args.Index); }
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; } }
public async Task PrepareCameraCaptureSequence() { this.cameraCaptureSequence = this.PhotoCaptureDevice.CreateCaptureSequence(1); this.cameraCaptureSequence.FrameAcquired += cameraCaptureSequence_FrameAcquired; await this.PhotoCaptureDevice.PrepareCaptureSequenceAsync(this.cameraCaptureSequence); }
private async void InitializeCameraAsync(CameraSensorLocation _sensor = CameraSensorLocation.Back) { SupportedResolutions = PhotoCaptureDevice.GetAvailableCaptureResolutions(_sensor).ToList(); CurrentResolution = SupportedResolutions[0]; cam = await PhotoCaptureDevice.OpenAsync(_sensor, CurrentResolution); // Enable shutter sound cam.SetProperty(KnownCameraGeneralProperties.PlayShutterSoundOnCapture, true); // Create capture sequence seq = cam.CreateCaptureSequence(1); // White balance IReadOnlyList<object> wbList = PhotoCaptureDevice.GetSupportedPropertyValues(_sensor, KnownCameraPhotoProperties.WhiteBalancePreset); SupportedWhiteBalances = new List<object>(); SupportedWhiteBalances.Add(ProCamConstraints.PROCAM_AUTO_WHITE_BALANCE); foreach (object rawValue in wbList) { SupportedWhiteBalances.Add((WhiteBalancePreset)(uint)rawValue); } OSD.WhiteBalanceOSD.SupportedWhiteBalances = SupportedWhiteBalances; OSD.WhiteBalanceOSD.CurrentWhiteBalanceIndex = 0; // EV SupportedEVValues = new List<int>(); CameraCapturePropertyRange evRange = PhotoCaptureDevice.GetSupportedPropertyRange(_sensor, KnownCameraPhotoProperties.ExposureCompensation); int minEV = (int)evRange.Min; int maxEV = (int)evRange.Max; for (int i = minEV; i <= maxEV; i++) { SupportedEVValues.Add(i); } EVDialer.SupportedValues = SupportedEVValues; // ISO SupportedISOValues = new List<uint>(); SupportedISOValues.Add(ProCamConstraints.PROCAM_AUTO_ISO); CameraCapturePropertyRange isoRange = PhotoCaptureDevice.GetSupportedPropertyRange(_sensor, KnownCameraPhotoProperties.Iso); var minISO = (uint)isoRange.Min; var maxISO = (uint)isoRange.Max; foreach(var fixture in _supportedISOFixtures) { if(fixture >= minISO && fixture <= maxISO) { SupportedISOValues.Add(fixture); } } ISODialer.SupportedValues = SupportedISOValues; // Flash IReadOnlyList<object> flashList = PhotoCaptureDevice.GetSupportedPropertyValues(_sensor, KnownCameraPhotoProperties.FlashMode); SupportedFlashModes = new List<FlashState>(); foreach (object rawValue in flashList) { SupportedFlashModes.Add((FlashState)(uint)rawValue); } // Resolution OSD.MainOSD.SupportedResolutions = SupportedResolutions; OSD.MainOSD.CurrentResolution = CurrentResolution; // Scene modes SupportedSceneModes = new List<CameraSceneMode>(); IReadOnlyList<object> sceneList = PhotoCaptureDevice.GetSupportedPropertyValues(_sensor, KnownCameraPhotoProperties.SceneMode); foreach (object rawValue in sceneList) { SupportedSceneModes.Add((CameraSceneMode)(uint)rawValue); } OSD.SceneOSD.SupportedSceneModes = SupportedSceneModes; OSD.SceneOSD.CurrentIndex = 0; // Focus assist IReadOnlyList<object> focusList = PhotoCaptureDevice.GetSupportedPropertyValues(_sensor, KnownCameraPhotoProperties.FocusIlluminationMode); SupportedFocusAssistModes = new List<FocusIlluminationMode>(); foreach (object rawValue in focusList) { SupportedFocusAssistModes.Add((FocusIlluminationMode)(uint)rawValue); } OSD.FocusAssistOSD.SupportedModes = SupportedFocusAssistModes; OSD.FocusAssistOSD.CurrentIndex = 0; // Enable shutter sound cam.SetProperty(KnownCameraGeneralProperties.PlayShutterSoundOnCapture, true); // Create capture sequence seq = cam.CreateCaptureSequence(1); // Set video brush source ViewfinderBrush.SetSource(cam); CorrectViewfinderOrientation(Orientation); // Show UI chrome HideLoadingView(); // Events CameraButtons.ShutterKeyHalfPressed += OnShutterHalfPress; CameraButtons.ShutterKeyPressed += OnShutterFullPress; CameraButtons.ShutterKeyReleased += OnShutterReleased; }