private void CamTracer_Load(object sender, EventArgs e) { lock (_modelSync) { LoadState(); updateColorPanels(); } methodBox.SelectedIndex = _method; thresholdField.Value = (decimal)_threshold; thresholdBar.Value = (int)(_threshold * 255); alphaField.Value = (decimal)_alpha; alphaBar.Value = (int)(_alpha * 255); colorAlphaField.Value = (decimal)_colorAlpha; colorAlphaBar.Value = (int)(_colorAlpha * 255); string name = "Camera #0"; string[] names = SelectCameraDialog.GetNames(); if (null != names && names.Length > 0) { if (_cameraIndex < 0 || _cameraIndex >= names.Length) { _cameraIndex = 0; } name = names[_cameraIndex]; } else { _cameraIndex = 0; } capture_Init(_cameraIndex, name); }
#pragma warning restore CS0197 private void changeCameraBtn_Click(object sender, EventArgs e) { SelectCameraDialog dlg = new SelectCameraDialog(_cameraIndex); if (DialogResult.OK == dlg.ShowDialog(this)) { capture_Init(dlg.CameraIndex, dlg.CameraName); } }
private void capture_Init(int cameraIndex, string cameraName) { Cursor current = Cursor.Current; Cursor.Current = Cursors.WaitCursor; capture_Close(); if (!capture_Open(cameraIndex, cameraName)) { string[] names = SelectCameraDialog.GetNames(); bool failure = true; if (null != names && names.Length > 0) { int index = cameraIndex + 1; while (index != cameraIndex) { if (index >= names.Length) { index = 0; continue; } if (capture_Open(index, names[index])) { failure = false; break; } index++; } } if (failure) { MessageBox.Show(this, "Unable to connect to a camera, the application will be closed.", "CamTracer Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Close(); } } Cursor.Current = current; }