Example #1
0
        /// <summary>
        /// Shows the form for webcam selection.
        /// </summary>
        /// <returns>
        /// The selected webcam.
        /// </returns>
        public static ImageCaptureDevice SelectWebcam()
        {
            ReadOnlyCollection <ImageCaptureDevice> devices = ImageCaptureDeviceConfiguration.GetCaptureDevices();

            if (devices.Count == 0)
            {
                throw new Exception("Webcam is not found.");
            }
            if (devices.Count == 1)
            {
                return(devices[0]);
            }

            // create webcam selection dialog
            using (WebcamSelectionForm dialog = new WebcamSelectionForm())
            {
                // disable changing of the capturing image format
                dialog.CanSelectFormat = false;

                // if webcam is selected
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    return(dialog.SelectedWebcam);
                }

                return(null);
            }
        }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WebcamSelectionForm"/> class.
        /// </summary>
        public WebcamSelectionForm()
        {
            InitializeComponent();

            ReadOnlyCollection <ImageCaptureDevice> devices = ImageCaptureDeviceConfiguration.GetCaptureDevices();

            foreach (ImageCaptureDevice device in devices)
            {
                devicesComboBox.Items.Add(device);
            }

            if (devices.Count > 0)
            {
                devicesComboBox.SelectedIndex = 0;
            }
        }