Exemplo n.º 1
0
        // Collect supported video and snapshot sizes
        private void EnumeratedSupportedFrameSizes(VideoCaptureDevice videoDevice)
        {
            this.Cursor = Cursors.WaitCursor;

            videoResolutionsCombo.Items.Clear( );
            snapshotResolutionsCombo.Items.Clear( );
            videoInputsCombo.Items.Clear( );

            videoCapabilitiesDictionary.Clear( );
            snapshotCapabilitiesDictionary.Clear( );

            try
            {
                // collect video capabilities
                VideoCapabilities[] videoCapabilities = videoDevice.GetVideoCapabilities();
                int videoResolutionIndex = 0;

                foreach (VideoCapabilities capabilty in videoCapabilities)
                {
                    string item = string.Format(CultureInfo.InvariantCulture,
                                                "{0} x {1}", capabilty.FrameSize.Width, capabilty.FrameSize.Height);

                    if (!videoResolutionsCombo.Items.Contains(item))
                    {
                        if (captureSize == capabilty.FrameSize)
                        {
                            videoResolutionIndex = videoResolutionsCombo.Items.Count;
                        }

                        videoResolutionsCombo.Items.Add(item);
                    }

                    if (!videoCapabilitiesDictionary.ContainsKey(item))
                    {
                        videoCapabilitiesDictionary.Add(item, capabilty);
                    }
                }

                if (videoCapabilities.Length == 0)
                {
                    videoResolutionsCombo.Items.Add("Not supported");
                }

                videoResolutionsCombo.SelectedIndex = videoResolutionIndex;


                if (configureSnapshots)
                {
                    // collect snapshot capabilities
                    VideoCapabilities[] snapshotCapabilities = videoDevice.GetSnapshotCapabilities();
                    int snapshotResolutionIndex = 0;

                    foreach (VideoCapabilities capabilty in snapshotCapabilities)
                    {
                        string item = string.Format(CultureInfo.InvariantCulture,
                                                    "{0} x {1}", capabilty.FrameSize.Width, capabilty.FrameSize.Height);

                        if (!snapshotResolutionsCombo.Items.Contains(item))
                        {
                            if (snapshotSize == capabilty.FrameSize)
                            {
                                snapshotResolutionIndex = snapshotResolutionsCombo.Items.Count;
                            }

                            snapshotResolutionsCombo.Items.Add(item);
                            snapshotCapabilitiesDictionary.Add(item, capabilty);
                        }
                    }

                    if (snapshotCapabilities.Length == 0)
                    {
                        snapshotResolutionsCombo.Items.Add("Not supported");
                    }

                    snapshotResolutionsCombo.SelectedIndex = snapshotResolutionIndex;
                }

                // get video inputs
                availableVideoInputs = videoDevice.GetAvailableCrossbarVideoInputs();
                int videoInputIndex = 0;

                foreach (VideoInput input in availableVideoInputs)
                {
                    string item = string.Format(CultureInfo.InvariantCulture, "{0}: {1}", input.Index, input.Type);

                    if ((input.Index == VideoInput.Index) && (input.Type == VideoInput.Type))
                    {
                        videoInputIndex = videoInputsCombo.Items.Count;
                    }

                    videoInputsCombo.Items.Add(item);
                }

                if (availableVideoInputs.Length == 0)
                {
                    videoInputsCombo.Items.Add("Not supported");
                }

                videoInputsCombo.SelectedIndex = videoInputIndex;
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }