Inheritance: System.Windows.DependencyObject, IDisposable
コード例 #1
0
        static void DeviceProperty_Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            // Get the sender
            CapPlayer typedSender = sender as CapPlayer;

            if (typedSender != null)
            {
                // Make sure that we are not in design mode
                if (System.ComponentModel.DesignerProperties.GetIsInDesignMode(typedSender))
                {
                    return;
                }

                // Unsubscribe from previous device
                CapDevice oldDevice = e.OldValue as CapDevice;
                if (oldDevice != null)
                {
                    // Clean up
                    typedSender.CleanUpDevice(oldDevice);
                }

                // Subscribe to new one
                CapDevice newDevice = e.NewValue as CapDevice;
                if (newDevice != null)
                {
                    // Subscribe
                    newDevice.NewBitmapReady += typedSender.device_OnNewBitmapReady;
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Cleans up a specific device
        /// </summary>
        /// <param name="device">Device to clean up</param>
        void CleanUpDevice(CapDevice device)
        {
            // Check if there even is a device
            if (device == null)
            {
                return;
            }

            // Stop
            device.Stop();

            // Unsubscribe
            device.NewBitmapReady -= device_OnNewBitmapReady;
        }
コード例 #3
0
        /// <summary>
        /// Invoked when a new bitmap is ready
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">EventArgs</param>
        void device_OnNewBitmapReady(object sender, EventArgs e)
        {
            // Create new binding for the framerate
            Binding b = new Binding();

            b.Source = Device;
            b.Path   = new PropertyPath(CapDevice.FramerateProperty);
            SetBinding(CapPlayer.FramerateProperty, b);

            // Get the sender
            CapDevice typedSender = sender as CapDevice;

            if (typedSender != null)
            {
                // Set the source of the image
                Source = typedSender.BitmapSource;
            }
        }
コード例 #4
0
ファイル: CapDevice.cs プロジェクト: Shujee/WebCam2
        /// <summary>
        /// Invoked when the MonikerString dependency property has changed
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">EventArgs</param>
        private static void MonikerString_Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            // Get typed sender
            CapDevice typedSender = sender as CapDevice;
            if (typedSender != null)
            {
                // Always stop the device
                typedSender.Stop();

                // Get the new value
                string newMonikerString = e.NewValue as string;

                // Check if we have a valid moniker string
                if (!string.IsNullOrEmpty(newMonikerString))
                {
                    // Initialize device
                    typedSender.InitializeDeviceForMoniker(newMonikerString);

                    // Start
                    typedSender.Start();
                }
            }
        }
コード例 #5
0
ファイル: CapPlayer.cs プロジェクト: ravidasghodse/genericva
        /// <summary>
        /// Cleans up a specific device
        /// </summary>
        /// <param name="device">Device to clean up</param>
        void CleanUpDevice(CapDevice device)
        {
            // Check if there even is a device
            if (device == null) return;

            // Stop
            device.Stop();

            // Unsubscribe
            device.NewBitmapReady -= device_OnNewBitmapReady;
        }
コード例 #6
0
        private void OnSelectedWebcamChanged()
        {
            if (SelectedWebcam == null)
            {
                SelectedWebcam = new CapDevice("");
            }

            SelectedWebcamPlayer.MonikerString = newMonikerString;
        }