Example #1
0
        private void InitializeCamera()
        {
            // すべてのキャプチャデバイスを取得
            VideoCapture capture = new VideoCapture();
            List<CaptureDevice> devices = capture.Devices;

            if (devices != null)
            {
                int selected = 0;
                if (devices.Count > 1)
                {
                    var names = from c in devices
                                select c.Name;
                    var form = new CameraSelectorForm(names.ToArray());
                    form.ShowDialog();
                    selected = form.SelectedIndex;
                }
                camera = devices[selected];
                camera.Activate();
                bmp = new Bitmap(camera.DeviceWidth, camera.DeviceHeight);
                this.Text = camera.Name;
            }
            else
            {
                MessageBox.Show("キャプチャデバイスが見つかりませんでした", "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Environment.Exit(-1);
            }
        }