示例#1
0
        public OpenDeviceForm(Size size)
        {
            InitializeComponent();

            IEnumerable <DeviceInfo> devicesInfos = new FilterInfoCollection(FilterCategory.VideoInputDevice)
                                                    .OfType <FilterInfo>()
                                                    .Select(f => new DeviceInfo()
            {
                Name = f.Name, Device = new VideoCaptureDevice(f.MonikerString)
            })
                                                    .Where(devInfo => devInfo.Device.VideoCapabilities != null && devInfo.Device.VideoCapabilities.Any())
                                                    .ToArray();

            cbDevice.DisplayMember = "Name";

            foreach (DeviceInfo deviceInfo in devicesInfos)
            {
                cbDevice.Items.Add(deviceInfo);
            }

            if (devicesInfos.Count() > 0)
            {
                cbDevice.SelectedIndex = 0;
            }
        }