private void OpenDevice(object o)
        {
            var deviceIndex = (int)o;

            try
            {
                var player = new VideoCaptureElement();
                player.BeginInit();
                player.VideoCaptureDevice = MultimediaUtil.VideoInputDevices[deviceIndex];
                player.VideoCaptureSource = MultimediaUtil.VideoInputDevices[deviceIndex].Name;
                //player.Width = 320;
                //player.DesiredPixelWidth = 320;
                //player.Height = 240;
                //player.DesiredPixelHeight = 240;
                //player.FPS = 30;
                player.EndInit();

                player.Play();
                IsPlaying   = true;
                _player     = player;
                HasChapters = false;
            }
            catch (Exception exc)
            {
                const string message = "Unable to load selected device.";
                Logger.Instance.Warn(message, exc);
                MessageBox.Show(message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            OnPropertyChanged("Media");
        }
Example #2
0
        private void StartCamera(ref VideoCaptureElement camera, int width, int height, int fps, int deviceIndex)
        {
            if (deviceIndex >= MultimediaUtil.VideoInputDevices.Length || deviceIndex < 0)
            {
                // Invalid device index should be ignored
                return;
            }

            // Initialize the element
            camera = new VideoCaptureElement
            {
                DesiredPixelWidth  = width,
                DesiredPixelHeight = height,
                FPS = fps,
                VideoCaptureDevice = MultimediaUtil.VideoInputDevices[deviceIndex]
            };

            camera.BeginInit();
            camera.EndInit();

            // Add the control to layout
            camera.Width  = CameraCanvas.Width;
            camera.Height = CameraCanvas.Height;
            CameraCanvas.Children.Add(camera);

            // start the camera stream
            camera.Play();
        }
Example #3
0
        private void initVideoElement()
        {
            PageControl.getGrid(Window.GetWindow(this)).Children.Remove(videoElement);
            videoElement = new VideoCaptureElement();
            videoElement.DesiredPixelWidth  = 1920;
            videoElement.DesiredPixelHeight = 1080;
            videoElement.LoadedBehavior     = WPFMediaKit.DirectShow.MediaPlayers.MediaState.Play;
            videoElement.FPS = 30;
            videoElement.RenderTransformOrigin = new Point(0.5, 0.5);
            videoElement.Margin = new Thickness(-423, 423, -423, 421);

            ScaleTransform videoElementScale = new ScaleTransform();

            videoElementScale.ScaleY = -1;
            RotateTransform videoElementRotate = new RotateTransform();

            videoElementRotate.Angle = 90;

            TransformGroup videoElementTransform = new TransformGroup();

            videoElementTransform.Children.Add(videoElementScale);
            videoElementTransform.Children.Add(videoElementRotate);

            PageControl.getGrid(Window.GetWindow(this)).Children.Add(videoElement);

            foreach (DsDevice div in DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice))
            {
                if (div.Name == "Microsoft LifeCam Studio")
                {
                    DsDevice device = div;
                    videoElement.VideoCaptureDevice = device;
                    videoElement.VideoCaptureSource = device.Name;
                }
            }
        }
Example #4
0
        public void SetCaptureDeviceWPFControl(VideoCaptureElement control)
        {
            this.Control = control;
            this.Control.VideoCaptureDevice = this.GetCaptureDevice();
            this.Control.Volume             = 0;

            MainWindowView view = MainWindowView.GetInstrance();

            view.CameraStartStopButtonText = "Freeze";
        }
Example #5
0
        public void StopCamera(ref VideoCaptureElement camera)
        {
            if (camera == null)
            {
                return;
            }

            camera.Stop();
            CameraCanvas.Children.Remove(camera);
            camera = null;
        }
 /// <summary>
 /// 设置视频属性
 /// </summary>
 /// <param name="videoCaptureElement">保存视频的控件</param>
 /// <param name="videoProcAmpProperty">VideoProcAmpProperty枚举,亮度、对比度等等</param>
 /// <param name="iVal">枚举的值</param>
 public static void SetVideoProcAmpProperty(this VideoCaptureElement videoCaptureElement, VideoProcAmpProperty videoProcAmpProperty, int iVal)
 {
     videoCaptureElement.SetVideoProcAmpProperty(videoProcAmpProperty, iVal);
 }
Example #7
0
 /// <summary>
 /// 饱和度设置
 /// </summary>
 /// <param name="captureElement"></param>
 /// <param name="iVal"></param>
 public static void SetHue(this VideoCaptureElement captureElement, int iVal)
 {
     captureElement.SetVideoProcAmpProperty(VideoProcAmpProperty.Hue, iVal);
 }
Example #8
0
 /// <summary>
 /// 对比设置
 /// </summary>
 /// <param name="captureElement"></param>
 /// <param name="iVal"></param>
 public static void SetContrast(this VideoCaptureElement captureElement, int iVal)
 {
     captureElement.SetVideoProcAmpProperty(VideoProcAmpProperty.Contrast, iVal);
 }
Example #9
0
 /// <summary>
 /// 亮度设置
 /// </summary>
 /// <param name="captureElement"></param>
 /// <param name="iVal"></param>
 public static void SetBrightness(this VideoCaptureElement captureElement, int iVal)
 {
     captureElement.SetVideoProcAmpProperty(VideoProcAmpProperty.Brightness, iVal);
 }