Esempio n. 1
0
        public void StartWebCam()
        {
            _captureSource = new CaptureSource();
            _captureSource.CaptureImageCompleted += new EventHandler<CaptureImageCompletedEventArgs>(_captureSource_CaptureImageCompleted);
            _captureSource.VideoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice();

            try
            {
                // Start capturing
                if (_captureSource.State != CaptureState.Started)
                {
                    // Create video brush and fill the WebcamVideo rectangle with it
                    var vidBrush = new VideoBrush();
                    vidBrush.Stretch = Stretch.Uniform;
                    vidBrush.SetSource(_captureSource);
                    WebcamVideo.Fill = vidBrush;

                    // Ask user for permission and start the capturing
                    if (CaptureDeviceConfiguration.RequestDeviceAccess())
                    {
                        _captureSource.Start();
                    }
                }
            }
            catch (InvalidOperationException)
            {
                InfoTextBox.Text = "Web Cam already started - if not, I can't find it...";
            }
            catch (Exception)
            {
                InfoTextBox.Text = "Could not start web cam, do you have one?";
            }
        }
Esempio n. 2
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            CaptureSource captureSource = new CaptureSource();

            // obtenemos el medio de video que esta por defecto para grabar y lo guardamos en una variable
            var vcd = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice();

            // le indicamos al capture source por medio de cuál video puede grabar
            captureSource.VideoCaptureDevice = vcd;

            // le pasamos a la brocha que está en el xaml el medio de video
            BrochaVideo.SetSource(captureSource);

            // iniciamos el medio de video
            captureSource.Start();
        }
        public void InitializeVideoRecorder()
        {
            try
            {
                //fileName = string.Format(@"\Purposecode\Video{0}.mp4", DateTime.Now.ToString("yyyyMMddHHmmss"));
                fileName = string.Format("Video{0}.mp4", DateTime.Now.ToString("yyyyMMddHHmmss"));

                if (captureSource == null)
                {
                    // Create the VideoRecorder objects.
                    captureSource = new CaptureSource();
                    fileSink = new FileSink();

                    videoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice();

                    // Add eventhandlers for captureSource.
                    captureSource.CaptureFailed += new EventHandler<ExceptionRoutedEventArgs>(OnCaptureFailed);

                    // Initialize the camera if it exists on the device.
                    if (videoCaptureDevice != null)
                    {
                        // Create the VideoBrush for the viewfinder.
                        videoRecorderBrush = new VideoBrush();
                        videoRecorderBrush.SetSource(captureSource);

                        // Display the viewfinder image on the rectangle.
                        viewfinderRectangle.Fill = videoRecorderBrush;
                        StopPlaybackRecording.IsEnabled = false;
                        // Start video capture and display it on the viewfinder.
                        captureSource.Start();

                        // Set the button state and the message.
                        UpdateUI(ButtonState.Initialized, "Tap record to start recording...");
                    }
                    else
                    {
                        // Disable buttons when the camera is not supported by the device.
                        UpdateUI(ButtonState.CameraNotSupported, "Camera is not supported..");
                    }
                }

            }
            catch (Exception ex)
            {
                var test = ex.Message;
            }
        } //InitializeVideoRecorder()
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            if (captureSource == null)
            {
                captureSource = new CaptureSource();
                captureSource.CaptureImageCompleted += captureSource_CaptureImageCompleted;

                fileSink = new FileSink();
                videoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice();

                if (videoCaptureDevice != null)
                {
                    videoBrush.SetSource(captureSource);
                    videoBrush.RelativeTransform = new CompositeTransform() { CenterX = 0.5, CenterY = 0.5, Rotation = 90 };
                    captureSource.Start();
                }
            }
        }
Esempio n. 5
0
        public Webcam(String name, VideoCaptureDevice cam)
        {
            this.camera = cam;
            this.src = new CaptureSource();
            this.lastImageTaken = DateTime.Now;
            this.nextImgName = "";
            this.nextImgNum = 0;

            try
            {

                // if we found a camera and successfully connected
                if (camera != null)
                {

                    // set the camera to its maximum resolution (allow choice in future?)
                    camera.DesiredFormat = (from VideoFormat f in camera.SupportedFormats
                                       orderby f.PixelWidth * f.PixelHeight descending
                                       select f).FirstOrDefault<VideoFormat>();

                    // reset the preview source
                    CaptureSource source = new CaptureSource();

                    // set the global CaptureSource to the selected camera
                    source.VideoCaptureDevice = camera;
                    source.AudioCaptureDevice = null;

                    // set the callback function for this camera's async capture
                    source.CaptureImageCompleted += new EventHandler<CaptureImageCompletedEventArgs>(_src_srcImageCompleted);

                    this.src = source;
                    src.Start();
                }

            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);
                throw new Exception("Prepare source failed: " + ex.ToString());
            }
        }
Esempio n. 6
0
        private void InitializeVideoRecorder()
        {
            if (_captureSource == null)
            {
                _captureSource = new CaptureSource();
                _fileSink = new FileSink();

                _videoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice();
                _captureSource.CaptureFailed += OnCaptureSourceOnCaptureFailed;
                _captureSource.CaptureImageCompleted += CaptureSourceOnCaptureImageCompleted;

                if (_videoCaptureDevice != null)
                {
                    _videoBrush = new VideoBrush();
                    _videoBrush.SetSource(_captureSource);

                    ViewFinderRectangle.Fill = _videoBrush;
                    _captureSource.Start();
                }
            }
        }
        public void InitializeVideoRecorder()
        {
            if (_captureSource == null)
            {
                // Create the VideoRecorder objects.
                _captureSource = new CaptureSource();
                _fileSink = new FileSink();

                _videoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice();

                // Add eventhandlers for captureSource.
                _captureSource.CaptureFailed += OnCaptureFailed;

                // Initialize the camera if it exists on the phone.
                if (_videoCaptureDevice != null)
                {
                    // Create the VideoBrush for the viewfinder.
                    _videoRecorderBrush = new VideoBrush();
                    _videoRecorderBrush.SetSource(_captureSource);

                    // Display the viewfinder image on the rectangle.
                    viewfinderRectangle.Fill = _videoRecorderBrush;

                    // Start video capture and display it on the viewfinder.
                    _captureSource.Start();

                    // Set the button state and the message.
                    UpdateUI(ButtonState.Initialized, "Tap record to start recording...");
                }
                else
                {
                    // Disable buttons when the camera is not supported by the phone.
                    UpdateUI(ButtonState.NoChange, "Camera Not Supported.");
                }
            }
        }
Esempio n. 8
0
        private void WebcamBtn_Click_1(object sender, RoutedEventArgs e)
        {
            if (CaptureDeviceConfiguration.AllowedDeviceAccess ||
                CaptureDeviceConfiguration.RequestDeviceAccess())
            {
                var camera = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice();

                if (camera != null)
                {
                    camera.DesiredFormat = (from VideoFormat f in camera.SupportedFormats
                                            orderby f.PixelWidth*f.PixelHeight descending
                                            select f)
                                            .FirstOrDefault<VideoFormat>() ?? camera.DesiredFormat;

                    _source = new CaptureSource();
                    _source.VideoCaptureDevice = camera;

                    var videoBrush = new VideoBrush();
                    videoBrush.Stretch = Stretch.Uniform;
                    videoBrush.SetSource(_source);

                    PresentationSurface.Fill = videoBrush;

                    _source.CaptureImageCompleted += (s, ea) =>
                                                         {
                                                             if (ea.Result != null)
                                                                 _images.Add(ea.Result);
                                                         };

                    _source.Start();

                    //foreach (VideoFormat format in camera.SupportedFormats)
                    //    Debug.WriteLine(
                    //        format.PixelWidth + "x" +
                    //        format.PixelHeight + " at " +
                    //        format.FramesPerSecond + " fps " +
                    //        format.PixelFormat.ToString());
                }
            }
        }
Esempio n. 9
0
        void loadCamera()
        {
            capcam = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice();
            capcam.DesiredFormat = capcam.SupportedFormats.First(f => f.PixelWidth == w);

            captureSource = new CaptureSource();
            captureSource.VideoCaptureDevice = capcam;
            if (captureSource.State != CaptureState.Started)
                captureSource.Start();

            sink = new FrameVideoSink();
            sink.CaptureSource = captureSource;
            sink.OnFrameReady += sink_OnFrameReady;
            sink.Enabled = true;

            viewfinderBrush.SetSource(captureSource);
            viewfinderBrush.Stretch = Stretch.Fill;

            phocam = new PhotoCamera();
        }
Esempio n. 10
0
        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            capcam = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice();
            capcam.DesiredFormat = capcam.SupportedFormats.First(f => f.PixelWidth == w);

            captureSource = new CaptureSource();
            captureSource.VideoCaptureDevice = capcam;
            captureSource.Start();

            sink = new FrameVideoSink();
            sink.CaptureSource = captureSource;
            sink.OnFrameReady += sink_OnFrameReady;
            sink.Enabled = true;

            viewfinderBrush.SetSource(captureSource);
            viewfinderBrush.Stretch = Stretch.Fill;

            renderBmp = new WriteableBitmap(w, h);
            renderBrush.ImageSource = renderBmp;

            phocam = new PhotoCamera();

            detector = new ColorDetector(w, h);
        }
Esempio n. 11
0
        void InitializeVideoRecorder(Rectangle viewfinderRectangle)
        {
            if (captureSource == null)
              {
            // Create the VideoRecorder objects.
            captureSource = new CaptureSource();
            fileSink = new FileSink();

            videoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice();

            // Add eventhandlers for captureSource.
            captureSource.CaptureFailed += new EventHandler<ExceptionRoutedEventArgs>(OnCaptureFailed);

            // Initialize the camera if it exists on the device.
            if (videoCaptureDevice != null)
            {
              // Create the VideoBrush for the viewfinder.
              videoRecorderBrush = new VideoBrush();
              videoRecorderBrush.SetSource(captureSource);

              // Display the viewfinder image on the rectangle.
              viewfinderRectangle.Fill = videoRecorderBrush;

              // Start video capture and display it on the viewfinder.
              captureSource.Start();
            }
            else
            {
              // A camera is not supported on this device
            }
              }
        }
        private void StartCapture(VideoCaptureDevice videoDevice)
        {
            if (videoRecorder == null || videoRecorder.State != CaptureState.Started)
            {
                videoRecorder = new CaptureSource
                {
                    VideoCaptureDevice = videoDevice,
                    AudioCaptureDevice = CaptureDeviceConfiguration.GetDefaultAudioCaptureDevice()
                };

                var brush = new VideoBrush();
                brush.SetSource(videoRecorder);
                videoContainer.Fill = brush;

                fileWriter = new FileSink
                {
                    CaptureSource = videoRecorder,
                    IsolatedStorageFileName = "video-recording.mp4",
                };

                videoRecorder.Start();
            }
        }
        public void InitializeVideoRecorder()
        {
            if (captureSource == null)
            {
                // Create the VideoRecorder objects.
                captureSource = new CaptureSource();
                fileSink = new FileSink();

                videoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice();

                // Add eventhandlers for captureSource.
                captureSource.CaptureFailed += new EventHandler<ExceptionRoutedEventArgs>(OnCaptureFailed);

                // Initialize the camera if it exists on the device.
                if (videoCaptureDevice != null)
                {
                    // Create the VideoBrush for the viewfinder.
                    videoRecorderBrush = new VideoBrush();
                    videoRecorderBrush.SetSource(captureSource);

                    // Display the viewfinder image on the rectangle.
                    viewfinderRectangle.Fill = videoRecorderBrush;

                    // Start video capture and display it on the viewfinder.
                    captureSource.Start();

                    // Set the button state and the message.
                    UpdateUI(ButtonState.Initialized, "Tap record to start recording...");
                }
                else
                {
                    // Disable buttons when the camera is not supported by the device.
                    UpdateUI(ButtonState.CameraNotSupported, "A camera is not supported on this device.");
                }
            }
        }
Esempio n. 14
0
        /// <summary>
        /// Create camera recorder and fill brush
        /// </summary>
        private void createCamera(string name = null)
        {
            source = new CaptureSource();
            source.CaptureImageCompleted += triggerCaptureImage;
            camera = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice();

            if (camera != null)
            {
                var supported = camera.SupportedFormats.Where(item => item.PixelFormat == PixelFormatType.Format32bppArgb).OrderBy(item => item.PixelWidth);
                source.VideoCaptureDevice.DesiredFormat = supported.ElementAt(0);

                if (videoSink != null)
                {
                    videoSink.IsolatedStorageFileName = name != null ? name : null;
                    videoSink.CaptureSource = name != null ? source : null;
                }

                VideoBrush = null;

                VideoBrush = new VideoBrush();
                VideoBrush.SetSource(source);
                VideoBrush.Stretch = Stretch.UniformToFill;

                source.Start();
            }
            OnPropertyChanged("IsSupported");
            OnPropertyChanged("IsCameraEnabled");
            OnPropertyChanged("IsShotEnabled");
        }
Esempio n. 15
0
        void StartRecording()
        {
            try
            {
                if (!_isRecording)
                {
                    _source = new CaptureSource();
                    if ((CaptureDeviceConfiguration.AllowedDeviceAccess | CaptureDeviceConfiguration.RequestDeviceAccess()) & (_source.State == CaptureState.Stopped))
                    {

                        _sink = new MemoryAudioSink();

                        AudioFormat desiredAudioFormat = null;
                        foreach (AudioFormat audioFormat in _source.AudioCaptureDevice.SupportedFormats)
                        {
                            if (audioFormat.SamplesPerSecond == 8000 && audioFormat.BitsPerSample == 16 && audioFormat.Channels == 1 && audioFormat.WaveFormat == WaveFormatType.Pcm)
                            {
                                desiredAudioFormat = audioFormat;
                            }
                        }

                        if (desiredAudioFormat == null)
                        {
                            ShowMessageBox("Your sound device may not found or in use also please make sure that it's support (16 bits,8000 samples,1 channel) please tell your system administrator about this problem!");
                            return;
                        }

                        _sink.OnBufferFulfill += new EventHandler(SendVoiceBuffer);
                        _source.AudioCaptureDevice.DesiredFormat = desiredAudioFormat;
                        _sink.CaptureSource = _source;
                        _source.Start();
                        _isRecording = true;
                    }

                }
            }
            catch (Exception ex)
            {
                ShowMessageBox("Your sound device may in use! " + ex.Message);
            }
        }
Esempio n. 16
0
        private void cw1_Closed(object sender, EventArgs e)
        {
            
            if ((sender as ChildWindow1).DialogResult == false)
            {
                Application.Current.MainWindow.Close();
            }
            else
            {

                if (source != null)
                {
                    source.Stop();
                }

                source = new CaptureSource();
                source.VideoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice();
                source.AudioCaptureDevice = CaptureDeviceConfiguration.GetDefaultAudioCaptureDevice();
                VideoBrush video = new VideoBrush();
                ///////////////////
                tchc = new ChatConnect();
                //////////////////////////
                tchc.obj = SynchronizationContext.Current;
                AudioFormat desiredAudioFormat = null;
                try
                {
                    foreach (AudioFormat audioFormat in source.AudioCaptureDevice.SupportedFormats)
                    {
                        if (audioFormat.SamplesPerSecond == 8000 && audioFormat.BitsPerSample == 16 && audioFormat.Channels == 1 && audioFormat.WaveFormat == WaveFormatType.Pcm)
                        {
                            desiredAudioFormat = audioFormat;
                        }
                    }
                }
                catch { }

                if (desiredAudioFormat == null)
                {
                    MessageBox.Show("Ошибка: микрофон отсутствует или не поддерживает требуемый аудиоформат!");
                }
                else                
                source.AudioCaptureDevice.DesiredFormat = desiredAudioFormat;
                
                
                
                ///////////////////////////

                video.SetSource(source);
                


                msv = new MemoryStreamVideoSink();

                msv.CaptureSource = source;
                msv.mediaElement1 = mediaElement1;

                msv.ac = new AudioConnect();
                msv.ac.obj = SynchronizationContext.Current;
                msv.ac._source = source;
                msv.ac.mediaElement1 = mediaElement1;
                msv.tchc = tchc;
                tchc.In=MyIn;
                tchc.Out = MyOut;

                try
                {
                    if (CaptureDeviceConfiguration.AllowedDeviceAccess || CaptureDeviceConfiguration.RequestDeviceAccess())
                    {
                        msv.Login = (sender as ChildWindow1).textBox1.Text;
                        MyLogin.Text = (sender as ChildWindow1).textBox1.Text;
                        msv.Conncet((sender as ChildWindow1).textBox2.Text, (sender as ChildWindow1));
                        source.Start();
                        ecran.Fill = video;
                        state = true;
                    }
                }
                catch (Exception eee)
                {
                    MessageBox.Show(eee.Message);
                }




                
            }

        }
 void SetMode(Mode m, bool force = false)
 {
     if (m_mode == m && !force)
     {
         return;
     }
     if(m_mode != Mode.Disconnected)
     {
         m_previousMode = m_mode;
     }
     m_mode = m;
     if (m != Mode.Disconnected)
     {
         screenshotButton.IsEnabled = true;
         uploadButton.IsEnabled = true;
         webcamButton.IsEnabled = (CaptureDeviceConfiguration.AllowedDeviceAccess || CaptureDeviceConfiguration.RequestDeviceAccess()) && CaptureDeviceConfiguration.GetAvailableVideoCaptureDevices().Count > 0;
     }
     else
     {
         screenshotButton.IsEnabled = false;
         uploadButton.IsEnabled = false;
         webcamButton.IsEnabled = false;
         SetCurrentFrame(m_garbageFrame, null);
         reasonIcon.Source = Resources["GoIcon"] as BitmapImage;
     }
     if (m == Mode.Screenshot)
     {
         TakeScreenshot();
     }
     if (m == Mode.Webcam)
     {
         webcamControlPanel.Visibility = System.Windows.Visibility.Visible;
         webcamButton.Visibility = System.Windows.Visibility.Collapsed;
         m_source = new CaptureSource();
         m_source.VideoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice();
         VideoBrush brush = new VideoBrush();
         brush.Stretch = Stretch.Uniform;
         brush.SetSource(m_source);
         currentFrame.Fill = brush;
         m_source.CaptureImageCompleted += new EventHandler<CaptureImageCompletedEventArgs>(source_CaptureImageCompleted);
         if (CaptureDeviceConfiguration.AllowedDeviceAccess || CaptureDeviceConfiguration.RequestDeviceAccess())
         {
             m_source.Start();
         }
     }
     else
     {
         webcamControlPanel.Visibility = System.Windows.Visibility.Collapsed;
         webcamButton.Visibility = System.Windows.Visibility.Visible;
     }
 }
Esempio n. 18
0
        private void RequestVideoDevice()
        {
            if (CaptureDeviceConfiguration.RequestDeviceAccess())
            {
                if (_capture == null)
                {

                    VideoCaptureDevice webcam = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice();
                    _capture = new CaptureSource();
                    _capture.VideoCaptureDevice = webcam;

                    if (_cameraBrush == null)
                    {
                        _cameraBrush = new VideoBrush();

                    }

                    _cameraBrush.SetSource(_capture);
                    _cameraBrush.Stretch = Stretch.UniformToFill;

                    _capture.Start();
                    Messenger.Default.Send<bool>(true, MessageTypes.CameraCapturing);

                }
                else
                {
                    if (_capture.State == CaptureState.Started)
                    {
                        _capture.Stop();
                        Messenger.Default.Send<bool>(false, MessageTypes.CameraCapturing);
                        State = "DefaultState";
                    }
                    else
                    {
                        Messenger.Default.Send<bool>(true, MessageTypes.CameraCapturing);
                        _capture.Start();

                    }
                }
            }
        }
Esempio n. 19
0
        public void start()
        {
            if (captureSource == null)
            {
                // Create the VideoRecorder objects.
                captureSource = new CaptureSource();
                fileSink = new FileSink();

                videoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice();

                // Add eventhandlers for captureSource.
                captureSource.CaptureFailed += new EventHandler<ExceptionRoutedEventArgs>(OnCaptureFailed);

                // Initialize the camera if it exists on the device.
                if (videoCaptureDevice != null)
                {
                    // Create the VideoBrush for the viewfinder.
                    videoRecorderBrush = new VideoBrush();
                    videoRecorderBrush.SetSource(captureSource);
                    videoRecorderBrush.RelativeTransform = new CompositeTransform() { CenterX = 0.5, CenterY = 0.5, Rotation = 90 };
                    viewfinderRectangle.Fill = videoRecorderBrush;

                    // Start video capture and display it on the viewfinder.
                    captureSource.Start();
                    System.Diagnostics.Debug.WriteLine("Started");
                    _isRunning = true;
                }

            }
        }
        /// <summary>
        /// Initializes VideoRecorder
        /// </summary>
        public void InitializeVideoRecorder()
        {
            if (captureSource == null)
            {
                captureSource = new CaptureSource();
                fileSink = new FileSink();
                videoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice();

                if (videoCaptureDevice != null)
                {
                    videoRecorderBrush = new VideoBrush();
                    videoRecorderBrush.SetSource(captureSource);
                    viewfinderRectangle.Fill = videoRecorderBrush;
                    captureSource.Start();
                    this.UpdateUI(VideoState.Initialized);
                }
                else
                {
                    this.UpdateUI(VideoState.CameraNotSupported);
                }
            }
        }
Esempio n. 21
0
        private void InitializeVideoRecorder()
        {
            if (captureSource == null)
            {
                captureSource = new CaptureSource();
                fileSink = new FileSink();

                var devices = CaptureDeviceConfiguration.GetAvailableVideoCaptureDevices();
                captureSource.VideoCaptureDevice = devices[0];
                captureSource.CaptureFailed += captureSource_CaptureFailed;

                if (videoCaptureDevice != null)
                {
                    videoRecorderBrush = new VideoBrush();
                    videoRecorderBrush.SetSource(captureSource);

                    ViewfinderRectangle.Fill = videoRecorderBrush;
                    captureSource.Start();
                }
            }
        }