public bool ToggleMode(IMode mode) { Mode newMode = (Mode)Modes.Keys.First(m => m.Text == mode.Text); dev.DesiredFrameRate = newMode.Capabilities.MaxFrameRate; dev.DesiredFrameSize = newMode.Capabilities.FrameSize; if (dev.IsRunning) { new Thread(() => { dev.SignalToStop(); dev.WaitForStop(); dev.Start(); }).Start(); } foreach (var m in Modes.Keys) { // notify that all modes are off, except the new one ModeStateChanged(m, m == newMode); } Settings["SelectedMode"] = mode.Text; return(true); }
private void StartStop_button_Click(object sender, EventArgs e) { if (!StartClickState) { // start camera stream videoSource = new VideoCaptureDevice(videoDevice[Device_listBox.SelectedIndex].MonikerString); videoSource.NewFrame += new NewFrameEventHandler(stream); videoSource.Start(); StartStop_button.Text = "Stop scan"; StartClickState = true; } else { if (videoSource != null) { // stop camera stream videoSource.SignalToStop(); videoSource.WaitForStop(); StartClickState = false; StartStop_button.Text = "Start scan"; Stream_pictureBox.Image = null; QrDecode_textBox.Text = null; } } }
private void videoCaptureBtn_Click(object sender, EventArgs e) { if (videoCaptureBtn.Checked) { if ((!transmitter.IsRunning) && (!receiver.IsRunning)) { vDevice.SignalToStop(); videoCaptureBtn.Checked = false; transmitterBtn.Enabled = false; receiverBtn.Enabled = receiverExists; settingsBtn.Enabled = false; settingsBtn.Enabled = !transmitter.IsRunning && ((receiver == null) || (!receiver.IsRunning)); } else { MessageBox.Show("Stop transmitter or/and receiver first", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { vDevice.Start(); videoCaptureBtn.Checked = true; transmitterBtn.Enabled = true; receiverBtn.Enabled = receiverExists; settingsBtn.Enabled = false; } }
private void PBCerrar_Click(object sender, EventArgs e) { try { FuenteDeVideo.SignalToStop(); } catch { }; Close(); }
byte[] image_array; //array is sending in network #endregion /// <summary> /// Connect/disconnect with camera /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button_connect_camera_Click(object sender, EventArgs e) { if (flag_connect_camera) { if (!(videoSourse == null)) { if (videoSourse.IsRunning) { videoSourse.SignalToStop(); videoSourse = null; } } flag_connect_camera = false; button_connect_camera.Text = "Connect"; radioButton_date_image.Enabled = true; radioButton_date_point.Enabled = true; } else { VideoCaptureDeviceForm vcdForm = new VideoCaptureDeviceForm(); if (vcdForm.ShowDialog() == DialogResult.OK) { videoSourse = vcdForm.VideoDevice; } videoSourse.NewFrame += new NewFrameEventHandler(video_NewFrame); videoSourse.Start(); flag_connect_camera = true; button_connect_camera.Text = "Disconnect"; radioButton_date_image.Enabled = false; radioButton_date_point.Enabled = false; } }
private void CaptureSelect_SelectionChanged(object sender, SelectionChangedEventArgs e) { int itemselected = CaptureSelect.SelectedIndex; if (itemselected == 0) { if (videoBaseCam != null && videoBaseCam.IsRunning) { videoBaseCam.SignalToStop(); } if (videoHeadCam != null && videoHeadCam.IsRunning) { videoHeadCam.SignalToStop(); } isrunning = false; SelectedVideoMode = 0; CapturedImageBox.Source = new BitmapImage(new Uri("/Resources/testcard.png", UriKind.Relative)); } if (itemselected == 1) { videoBaseCam.Start(); isrunning = true; SelectedVideoMode = 1; } if (itemselected == 2) { videoHeadCam.Start(); isrunning = true; SelectedVideoMode = 2; } }
private void button2_Click(object sender, EventArgs e) { if (streamLocCam.Checked == true) { if (button2.Text == "Start Camera") { kamera = new VideoCaptureDevice(webCams[comboBox1.SelectedIndex].MonikerString); kamera.NewFrame += new NewFrameEventHandler(video_NewFrame); kamera.Start(); button2.Text = "Stop Camera"; } else { kamera.SignalToStop(); kamera = null; button2.Text = "Start Camera"; } } else { if (button2.Text == "Start Camera") { stream = new MJPEGStream("http://" + inputIP.Text + "/video"); stream.NewFrame += new NewFrameEventHandler(video_NewFrame); stream.Start(); button2.Text = "Stop Camera"; } else { stream.SignalToStop(); stream = null; button2.Text = "Start Camera"; } } }
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e) { button1.Enabled = false; button3.Enabled = false; button4.Enabled = false; foreach (FilterInfo aa in videoDevices) { if (aa.Name == comboBox2.SelectedItem) { if (videoSource != null) { videoSource.SignalToStop(); if (FileWriter.IsOpen) { FileWriter.Close(); } button1.Text = "start"; button4.Text = "start record"; record = 0; button4.Enabled = false; button3.Enabled = false; } videoSource = new VideoCaptureDevice(aa.MonikerString); ca = videoSource.VideoCapabilities; comboBox1.Items.Clear(); foreach (VideoCapabilities a in ca) { comboBox1.Items.Add(a.FrameSize); } videoSource.NewFrame += new NewFrameEventHandler(video_NewFrame); break; } } }
//private void Button_Click(object sender, RoutedEventArgs e) private void StartScanning() { try { if ((videoSource == null) || (!videoSource.IsRunning)) { // front camera #if DEBUG int ind = 0; #else int ind = 1; #endif videoSource = new VideoCaptureDevice(videoDevices[ind].MonikerString); videoSource.VideoResolution = videoSource.VideoCapabilities.Last(); videoSource.ProvideSnapshots = true; qrwm.StepSize = videoSource.SnapshotCapabilities.Length; qrwm.FrameStart(true); videoSource.SetCameraProperty(CameraControlProperty.Focus, 100, CameraControlFlags.Auto); videoSource.SetCameraProperty(CameraControlProperty.Exposure, -5, CameraControlFlags.Auto); videoSource.Start(); } else { qrwm.FrameStart(false); videoSource.SignalToStop(); } } catch (Exception ex) { Console.WriteLine(ex.Message); } }
// try to set video-source, set event-handler private void selectCameraSource(int index, int resolution) { if (videoSource != null && videoSource.IsRunning) { videoSource.SignalToStop(); videoSource = null; } videoSource = new VideoCaptureDevice(videosources[index].MonikerString); ((ToolStripMenuItem)camSourceToolStripMenuItem.DropDownItems[index]).Checked = true; try { int i; if (videoSource.VideoCapabilities.Length > 0) { for (i = 0; i < videoSource.VideoCapabilities.Length; i++) { if (videoSource.VideoCapabilities[i].FrameSize.Width == resolution) { break; } } videoSource.VideoResolution = videoSource.VideoCapabilities[i]; } } catch { } videoSource.NewFrame += new AForge.Video.NewFrameEventHandler(videoSource_NewFrame); videoSource.Start(); }
private void Form2_FormClosing(object sender, FormClosingEventArgs e) { try { if (videoCaptureDevice.IsRunning) { videoCaptureDevice.SignalToStop(); // wait ~ 3 seconds for (int i = 0; i < 30; i++) { if (!videoCaptureDevice.IsRunning) { break; } System.Threading.Thread.Sleep(100); } if (videoCaptureDevice.IsRunning) { videoCaptureDevice.Stop(); } } } catch { } }
private void tomar_foto_button_Click(object sender, EventArgs e) { var button = (Button)sender; try { SaveFileDialog sf = new SaveFileDialog(); sf.Filter = "Imagenes JPG | *.jpg"; //sf.FileName = @"C:\Users\User\Documents\Visual Studio 2015\Projects\Sporting_Gym\Sporting_Gym\Img\Clientes\" + // apellido_paterno_textBox.Text + nombre_textBox.Text + DateTime.Now.ToString("dd-mm-yyyy") + ".jpg"; Bitmap img = videoSourcePlayer1.GetCurrentVideoFrame(); //img.Save(sf.FileName, System.Drawing.Imaging.ImageFormat.Jpeg); //img.Dispose(); FuenteDeVideo.SignalToStop(); FuenteDeVideo = null; //Image myimage = new Bitmap(sf.FileName); myimage = img; videoSourcePlayer1.BackgroundImage = myimage; encendido = false; } catch (Exception ex) { MessageBox.Show("Error en tomar foto"); } }
//FOTOS private void encender_button_Click(object sender, EventArgs e) { try { if (encendido == false) { FuenteDeVideo = new VideoCaptureDevice(dispositivos[dispositivos_comboBox.SelectedIndex].MonikerString); videoSourcePlayer1.VideoSource = FuenteDeVideo; videoSourcePlayer1.Start(); encendido = true; } else { FuenteDeVideo.SignalToStop(); FuenteDeVideo = null; encendido = false; } } catch (Exception ex) { MessageBox.Show("Error en la camara"); videoSourcePlayer1.SignalToStop(); videoSourcePlayer1 = null; FuenteDeVideo = null; } }
private void CaptureButton_Click(object sender, EventArgs e) { if (videoSource != null) { if (videoSource.IsRunning) { videoSource.SignalToStop(); videoSource.WaitForStop(); CaptureBox.Invoke( new Action( delegate { CaptureBox.Image = null; CaptureBox.Invalidate(); })); CaptureButton.Name = "Start"; } else { videoSource.NewFrame += videoSource_NewFrame; videoSource.Start(); CaptureButton.Name = "Stop"; } SnapshotButton.Enabled = videoSource.IsRunning; RecordButton.Enabled = videoSource.IsRunning; } }
static void Main() { try { var appSettings = new AppSettingsReader(); var barcodeReader = new BarcodeReader(); var outputPath = (string)appSettings.GetValue("PictureOutputPath", typeof(string)); var startTime = DateTime.Now; var timeOut = (int)appSettings.GetValue("ScanTimeOut", typeof(int)); var cameraID = 0; var capDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); if (capDevices.Count == 0) { Console.WriteLine("No camera is available."); return; } var capture = new VideoCaptureDevice(capDevices[0].MonikerString); var max = capture.VideoCapabilities[0]; foreach (var res in capture.VideoCapabilities) { if (res.FrameSize.Width > max.FrameSize.Width) { max = res; } } capture.VideoResolution = max; capture.NewFrame += (sender, args) => { var image = (Bitmap)args.Frame.Clone(); var qrInfo = barcodeReader.Decode(image); if (!string.IsNullOrEmpty(qrInfo?.Text)) { Console.WriteLine(qrInfo?.Text); image.Save(outputPath); capture.SignalToStop(); } if (DateTime.Now >= startTime.AddMilliseconds(timeOut)) { Console.WriteLine("Timeout reached with no QR code detected"); image.Save(outputPath); capture.SignalToStop(); } }; //Console.WriteLine("Starting video capture"); capture.Start(); capture.WaitForStop(); //Console.Read(); } catch (Exception ex) { Console.WriteLine("Error occured when running camera test."); } }
public void StopRunningVideo() { if (_videoSource != null && _videoSource.IsRunning) { _videoSource.SignalToStop(); } _isStarted = false; }
private void Form1_FormClosing(object sender, FormClosingEventArgs e) { if (newVideo.IsRunning) { newVideo.SignalToStop(); newVideo.WaitForStop(); } }
private void Registro_Cliente_FormClosed(object sender, FormClosedEventArgs e) { if (FuenteDeVideo != null) { FuenteDeVideo.SignalToStop(); FuenteDeVideo = null; } }
private void button2_Click(object sender, EventArgs e) { if (Finalvideo.IsRunning) { Finalvideo.SignalToStop(); Finalvideo.WaitForStop(); } }
private void button2_Click(object sender, EventArgs e) { if (FinalVideo != null) { FinalVideo.SignalToStop(); FinalVideo.WaitForStop(); } }
protected override void OnFormClosing(FormClosingEventArgs e) { if (videoSource != null && videoSource.IsRunning) { videoSource.SignalToStop(); pictureBox1.Invoke(new Action(delegate { pictureBox1.Image = null; pictureBox1.Invalidate(); })); videoSource = null; } }
public void Close() { if (_Webcam != null) { _Webcam.SignalToStop(); _Webcam.NewFrame -= new NewFrameEventHandler(OnFrame); } }
private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { if (videoSource != null) { // stop the video source videoSource.SignalToStop(); } }
private void Form1_FormClosing(object sender, FormClosingEventArgs e) { if (FinalFrame != null) { FinalFrame.SignalToStop(); FinalFrame.WaitForStop(); } }
private void button1_Click(object sender, EventArgs e) { FinalFrame.SignalToStop(); FinalFrame.Stop(); FinalFrame = new VideoCaptureDevice(CaptureDevice[comboBox1.SelectedIndex].MonikerString); FinalFrame.NewFrame += new NewFrameEventHandler(FinalFrame_NewFrame); FinalFrame.Start(); }
///////////////////// Buraya kadar ////////////////////////////////////////// private void Form1_FormClosed(object sender, FormClosedEventArgs e) { //Webcam beim Schließen des Programms wieder freigeben if (FinalVideoSource != null && FinalVideoSource.IsRunning) { FinalVideoSource.SignalToStop(); FinalVideoSource = null; } }
private void PictureOff() { if (videoSource != null && videoSource.IsRunning) { videoSource.Stop(); videoSource.SignalToStop(); videoSource = null; } }
public override void StopLiveView() { lock (_lock) { _captureDevice.SignalToStop(); _captureDevice.WaitForStop(); _operationInProgress = false; _processLiveView = false; } }
void MainForm_close(object e, FormClosingEventArgs arg) { if (videoSource != null) { if (videoSource.IsRunning) { videoSource.SignalToStop(); // Arrète le flux video avant la fermeture du programme } } }
private void video_NewPreviewFrame(object sender, NewFrameEventArgs eventArgs) { bitmap = (Bitmap)eventArgs.Frame.Clone(); bitmap.Save(stream, ImageFormat.Jpeg); if (bitmap != null) { videoSource.SignalToStop(); } }