// Set the recording state: display the video on the viewfinder. private void StartVideoPreview() { ThreadPool.QueueUserWorkItem(state => { Thread.Sleep(100); Deployment.Current.Dispatcher.BeginInvoke(() => { try { // Display the video on the viewfinder. if (_captureSource.VideoCaptureDevice != null && _captureSource.State == CaptureState.Stopped) { // Add _captureSource to videoBrush. //ViewfinderBrush = new VideoBrush(); //ViewfinderBrush.Transform = new CompositeTransform { CenterX = 0.5, CenterY = 0.5 }; ViewfinderBrush.SetSource(_captureSource); // Add videoBrush to the visual tree. //Viewfinder.Fill = ViewfinderBrush; _captureSource.Start(); // Set the button states and the message. UpdateUI(ButtonState.Ready, AppResources.ReadyToRecord); } } // If preview fails, display an error. catch (Exception e) { DebugText.Text = AppResources.Error.ToUpperInvariant() + ": " + e.Message; } }); }); }
private void Initialize() { // Initialize camera var rotation = App.Camera.SensorLocation == CameraSensorLocation.Back ? App.Camera.SensorRotationInDegrees : -App.Camera.SensorRotationInDegrees; ViewfinderBrush.SetSource(App.Camera); ViewfinderBrushTransform.Rotation = rotation; // Setup image processing pipeline _source = new CameraPreviewImageSource(App.Camera); _rotationFilter = new RotationFilter(rotation); _chromaKeyFilter = new ChromaKeyFilter(); _filters = new List <IFilter> { _rotationFilter, _chromaKeyFilter }; _effect = new FilterEffect(_source) { Filters = _filters }; _bitmap = new WriteableBitmap((int)App.Camera.PreviewResolution.Width, (int)App.Camera.PreviewResolution.Height); _renderer = new WriteableBitmapRenderer(_effect, _bitmap, OutputOption.Stretch); FilteredImage.Source = _bitmap; _color = Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF); ColorBorder.Background = new SolidColorBrush(_color); // Start rendering timer _timer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(10) }; _timer.Tick += DispatcherTimer_Tick; _timer.Start(); _initialized = true; }
public CameraPage() { InitializeComponent(); CameraButtons.ShutterKeyPressed += OnButtonFullPress; if (PhotoCamera.IsCameraTypeSupported(CameraType.Primary)) { myCam = new PhotoCamera(CameraType.Primary); ViewfinderCanvas.Height = myCam.Resolution.Height; ViewfinderCanvas.Width = myCam.Resolution.Width; ViewfinderBrush.SetSource(myCam); //myCam.Initialized += cam_Initialized; myCam.CaptureCompleted += myCam_CaptureCompleted; } else { MessageBox.Show("A Camera is not available on this device.", "Error!", MessageBoxButton.OK); } }
public void InitializeVideoRecorder() { if (_captureSource == null) { // Create the VideoRecorder objects. _captureSource = new CaptureSource(); _captureSource.VideoCaptureDevice.DesiredFormat = GetDesiredFormat(); _fileSink = new FileSink(); _videoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice(); // Add eventhandlers for _captureSource. _captureSource.CaptureFailed += OnCaptureFailed; _captureSource.CaptureImageCompleted += OnThumbCompleted; // Initialize the camera if it exists on the device. if (_videoCaptureDevice != null) { // Create the VideoBrush for the viewfinder. //ViewfinderBrush = new VideoBrush(); //ViewfinderBrush.Transform = new CompositeTransform{CenterX = 0.5, CenterY = 0.5}; ViewfinderBrush.SetSource(_captureSource); // Display the viewfinder image on the rectangle. Viewfinder.Fill = ViewfinderBrush; // Start video capture and display it on the viewfinder. _captureSource.Start(); // Set the button state and the message. UpdateUI(ButtonState.Initialized, AppResources.TapRecordToStartRecording); } else { // Disable buttons when the camera is not supported by the device. UpdateUI(ButtonState.CameraNotSupported, AppResources.ACameraIsNotSupportedOnThisDevice); } } }
private void SetCameraType(CameraType cameraType) { _camera = new PhotoCamera(CurrentCameraMode = cameraType); switch (cameraType) { case CameraType.FrontFacing: ViewfinderBrush.RelativeTransform = new CompositeTransform { CenterX = 0.5, CenterY = 0.5, Rotation = -90 }; break; case CameraType.Primary: ViewfinderBrush.RelativeTransform = new CompositeTransform { CenterX = 0.5, CenterY = 0.5, Rotation = 90 }; break; } ViewfinderBrush.SetSource(_camera); }