void FillCameraComboBox() { _CameraChoice.UpdateDeviceList(); this.CameraBox.Items.Clear(); string lastCam = Settings.Get <Settings>().Read(Settings.LAST_USED, Settings.CAMERA_DEVICE, string.Empty); int found = -1; int i = 0; foreach (var camera_device in _CameraChoice.Devices) { this.CameraBox.Items.Add(camera_device.Name); if (camera_device.ClassID.ToString() == lastCam) { found = i; } i++; } try { if (found != -1) { CameraBox.SelectedIndex = found; } } catch { } }
//启动摄像头 private void btnStartVideo_Click(object sender, EventArgs e) { try { //刷新摄像头 cameraChoice.UpdateDeviceList(); cameraControl.SetCamera(cameraChoice.Devices[0].Mon, null);//要先启动摄像头,不然接下来这句报错:camera is not created ResolutionList resolutions = Camera.GetResolutionList(cameraControl.Moniker); Resolution currentResolution = null; foreach (Resolution item in resolutions) { if (item.CompareTo(cameraControl.Resolution) == 0) { currentResolution = item; break; } } if (currentResolution == null) { currentResolution = resolutions[0]; } cameraControl.SetCamera(cameraChoice.Devices[0].Mon, currentResolution); this.btnStartVideo.Enabled = false; this.btnCloseVideo.Enabled = true; this.btnTake.Enabled = true; } catch (Exception ex) { MessageBox.Show("摄像头启动失败:" + ex.Message, "异常提示"); } }
private void FrmGetPicture_Load(object sender, EventArgs e) { _cameraChoice.UpdateDeviceList(); foreach (var item in _cameraChoice.Devices) { cboCameraList.Items.Add(item.Name); } if (cboCameraList.Items.Count > 0) { cboCameraList.SelectedIndex = 0; } try { List <string> devices = WIAScanner.GetDevices(); foreach (var item in devices) { cboScanner.Items.Add(item); } if (cboScanner.Items.Count > 0) { cboScanner.SelectedIndex = 0; } } catch (Exception ex) { WinInfoHelper.ShowInfoWindow(this, "扫描仪设备加载失败!" + ex.Message); log.Error("扫描仪设备加载失败:", ex); } }
private void FillCameraList() { if (log.IsInfoEnabled) { log.Info("Preparing to get list of all cameras"); } cbCameraList.Items.Clear(); try { _cameraChoice.UpdateDeviceList(); foreach (var camera_device in _cameraChoice.Devices) { cbCameraList.Items.Add(camera_device.Name); } } catch (Exception ex) { if (log.IsErrorEnabled) { log.Error("Failed to get camera list", ex); } LogWriteLn("Unable to get the list of attached web cams: " + ex.Message); } }
//启动摄像头 private void BtnStartVideo_Click(object sender, EventArgs e) { try { cameraChoice.UpdateDeviceList(); cameraControl.SetCamera(cameraChoice.Devices[0].Mon, null); ResolutionList resolutions = Camera.GetResolutionList(cameraControl.Moniker); Resolution resolution = null; foreach (Resolution item in resolutions) { if (item.CompareTo(cameraControl.Resolution) == 0) { resolution = item; break; } } if (resolution == null) { resolution = resolutions[0]; } cameraControl.SetCamera(cameraChoice.Devices[0].Mon, resolution); this.btnStartVideo.Enabled = false; this.btnCloseVideo.Enabled = true; this.btnTake.Enabled = true; } catch (Exception ex) { MessageBox.Show("启动摄像头发生异常:" + ex.Message, "启动失败"); } }
private void FillCameraList() { comboBoxCameraList.Items.Clear(); _CameraChoice.UpdateDeviceList(); foreach (var camera_device in _CameraChoice.Devices) { comboBoxCameraList.Items.Add(camera_device.Name); } }
private void FillCameraList() { cmbCameraList.Items.Clear(); _cameraChoice.UpdateDeviceList(); foreach (var cameraDevice in _cameraChoice.Devices) { cmbCameraList.Items.Add(cameraDevice.Name); } }
private void SetCameraControlSourceAndResolution(string camName, string res) { LogDebug(String.Format("Setting camera to {0} at res {1}", camName, res)); CameraChoice chooser = new CameraChoice(); chooser.UpdateDeviceList(); DsDevice chosenCam = chooser.GetCameraByName(camName); ResolutionList resolutions = Camera.GetResolutionList(chosenCam.Mon); Camera_NET.Resolution chosenRes = resolutions.Find(x => x.ToString() == res); camControl.SetCamera(chosenCam.Mon, chosenRes); }
private void FillCameraList() { comboBoxCameraList.Items.Clear(); cameraChoice.UpdateDeviceList(); foreach (var camera_device in cameraChoice.Devices) { comboBoxCameraList.Items.Add(camera_device.Name); } if (comboBoxCameraList.Items.Count > 0) { comboBoxCameraList.SelectedIndex = 0; } }
private void frm_camera_Load(object sender, EventArgs e) { CameraChoice _CameraChoice = new CameraChoice(); // Get List of devices (cameras) _CameraChoice.UpdateDeviceList(); // To get an example of camera and resolution change look at other code samples if (_CameraChoice.Devices.Count > 0) { // Device moniker. It's like device id or handle. // Run first camera if we have one var camera_moniker = _CameraChoice.Devices[0].Mon; // Set selected camera to camera control with default resolution imgVideo.SetCamera(camera_moniker, null); } }
private void FillCameraList() { try { comboBoxCameraList.Items.Clear(); _CameraChoice.UpdateDeviceList(); foreach (var camera_device in _CameraChoice.Devices) { comboBoxCameraList.Items.Add(camera_device.Name); } } catch (Exception ex) { MessageBox.Show("Please wait for the image to be loaded!", "Message"); } }
/// <summary> /// Constructor. /// </summary> public MainWindow() { InitializeComponent(); m_cameraChoice.UpdateDeviceList(); ResolutionList resolutions = Camera.GetResolutionList(m_cameraChoice.Devices[m_cameraIndex].Mon); Resolution max = null; // use the maximum resolution foreach (Resolution res in resolutions) { if (max == null) { max = res; continue; } if (res.Width > max.Width) { max = res; } } cameraControl.CameraControl.SetCamera(m_cameraChoice.Devices[m_cameraIndex].Mon, max); this.KeyDown += MainWindow_KeyDown; m_window.KeyDown += MainWindow_KeyDown; this.Closing += MainWindow_Closing; this.Loaded += MainWindow_Loaded; m_window.Visibility = Visibility.Hidden; m_timer.Tick += M_timer_Tick; m_timer.Interval = new TimeSpan(0, 0, 1); m_displayTimer.Tick += M_displayTimer_Tick; m_displayTimer.Interval = new TimeSpan(0, 0, 1); m_displayTimer.Start(); }
private void setmaxres(int CamIdx) { _CameraChoice.UpdateDeviceList(); SetCamera(_CameraChoice.Devices[CamIdx].Mon, new Resolution(wc.Resolution.Width, wc.Resolution.Height)); if (!cameraControl.CameraCreated) { return; } set_camera_par(CamIdx, wc); cameraControl.MixerEnabled = false; ResolutionList resolutions = Camera.GetResolutionList(cameraControl.Moniker); Resolution res = new Resolution(800, 600); foreach (var r in resolutions) { if (r.Width > res.Width) { res = r; } } }
public IHardwareProxy LoadFromHardwareId(string hardwareId) { if (string.IsNullOrEmpty(hardwareId)) { return(null); } string[] parts = hardwareId.Split("|".ToCharArray()); if (parts.Length < 2) { return(null); } Guid id = new Guid(parts[0]); string resstr = parts[1]; CameraChoice cams = new CameraChoice(); cams.UpdateDeviceList(); IMoniker moniker = null; foreach (var camera_device in cams.Devices) { if (camera_device.Mon != null) { Guid camid; camera_device.Mon.GetClassID(out camid); if (camid == id) { moniker = camera_device.Mon; break; } } } if (moniker == null) { return(null); } ResolutionList resolutions = Camera.GetResolutionList(moniker); if (resolutions == null) { return(null); } RotateFlipType rotation = RotateFlipType.RotateNoneFlipNone; if (parts.Length >= 3) { rotation = (RotateFlipType)Enum.Parse(typeof(RotateFlipType), parts[2], true); } for (int index = 0; index < resolutions.Count; index++) { if (resstr == resolutions[index].ToString()) { NetCameraProxy proxy = new NetCameraProxy(); proxy.SetCamera(moniker, resolutions[index]); proxy.Rotation = rotation; return(proxy); } } return(null); }
public MainWindow() { settings_Path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\PC Camera" + slash; string[] names = { "Time_Interval", "Images_Save_Location" }; string[] values = { time_interval.ToString(), img_path }; InitializeComponent(); // location + dir + @"PC Images\" + time + " PC.jpg" CameraChoice _CameraChoice = new CameraChoice(); CameraControl cam = new CameraControl(); _CameraChoice.UpdateDeviceList(); var moniker = _CameraChoice.Devices[0].Mon; ResolutionList resolutions = Camera.GetResolutionList(moniker); DirCheck(); //settings folder maker if (!Directory.Exists(settings_Path)) { Directory.CreateDirectory(settings_Path); } //logger = new Logger(location + current_dir + "log file.txt", current_time); //if setting file exists if (!File.Exists(settings_Path + settings_file_name)) { // Create a file to write to. JSONMaker maker = new JSONMaker(names.Length, names, values, settings_Path + settings_file_name); } //using (StreamReader sr = File.OpenText(settings_Path + settings_file_name)) { read = new Reader.Reader(settings_Path + settings_file_name); //string s = ""; //s = sr.ReadLine(); time_interval = Convert.ToInt32(read.ReturnValueOf("Time_Interval")); img_path = read.ReturnValueOf("Images_Save_Location"); time_out.Text += Convert.ToString(time_interval) + "\n"; time_out.Text += Convert.ToString(img_path) + "\n"; LogCheck(); } Res.Text += "Resolutions " + "\n"; logger.Information("Resolutions", current_time); foreach (Resolution r in resolutions) { Res.Text += Convert.ToString(r + "\n"); logger.Information(Convert.ToString(r), current_time); } cam.SetCamera(moniker, resolutions[0]); Res.Text += "Starting Camera" + "\n"; logger.Information("Starting Camera", current_time); var timer = new System.Timers.Timer { Interval = (1000 * 60) * time_interval }; //this will run the ontimed function when time is elapsed timer.Elapsed += ontimed; temp = "current mins are set to: "; Res.Text += temp + Convert.ToString(time_interval) + "\n"; logger.Information(temp + time_interval, current_time); //this starts the timer timer.Start(); void ontimed(object sender, System.Timers.ElapsedEventArgs e) { //the time at which the image got taken current_time = DateTime.Now.ToString("dddd dd MMMM yyyy hh.mm tt"); //the location at which the mage will be stored along with the generic location //it is used to store images according to each day current_dir = DateTime.Now.ToString("dddd dd MMMM yyyy") + "\\"; this.Dispatcher.Invoke(() => { try { DirCheck(); LogCheck(); user_image(current_time, current_dir); pc_img(current_time, current_dir); Log_info("Image captured at time ", current_time); if (check == true) { Log_mins("minutes updated to ", current_time, time_interval); temp = "current mins are set to: "; Res.Text += temp + Convert.ToString(time_interval) + "\n"; logger.Information(temp + time_interval, current_time); check = false; } timer.Interval = (1000 * 60) * time_interval; } catch (Exception ex) { time_out.Text += ex.ToString() + "\n"; logger.Error(ex, current_time); } }); } void pc_img(string time, string dir) { var image = ScreenCapture.CaptureDesktop(); image.Save(img_path + dir + @"PC Images\" + time + " PC.jpg", ImageFormat.Jpeg); { /* * System.Drawing.Rectangle bounds = Screen.GetBounds(System.Drawing.Point.Empty); * using (Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height)) * { * using (Graphics g = Graphics.FromImage(bitmap)) * { * g.CopyFromScreen(System.Drawing.Point.Empty, System.Drawing.Point.Empty, bounds.Size); * } * bitmap.Save("D:\\test.jpg", ImageFormat.Jpeg); * } */ } } void user_image(string time, string dir) { this.Dispatcher.Invoke(() => { try { image_taker(time, dir); } catch (Exception ex) { time_out.Text = ex.ToString(); } }); } void image_taker(string time, string dir) { try { //image taker // cam.SetCamera(moniker, resolutions[0]); cam.SnapshotSourceImage().Save(img_path + dir + @"User Images\" + time + " User.png"); // cam.Dispose(); } catch (Exception ex) { time_out.Text += ex.ToString() + "\n"; logger.Error(ex, current_time); } } void Log_info(string info, string time) { time_out.Text += info + time + "\n"; logger.Information(info, time); } void Log_mins(string info, string time, int mins) { time_out.Text += info + mins + "\n"; logger.Information(info + mins, time); } void DirCheck() { //checks for directories if (!Directory.Exists(img_path + current_dir + @"PC Images\")) { Directory.CreateDirectory(img_path + current_dir + @"PC Images\"); } if (!Directory.Exists(img_path + current_dir + @"User Images\")) { Directory.CreateDirectory(img_path + current_dir + @"User Images\"); } } void LogCheck() { //checks for the log file if (logger == null || !logger.Exists()) { logger = new Logger(img_path + current_dir + "log file.txt", current_time); } } }