public void Capture() { //Takes picture and converts it to a WriteableBitmap Bitmap photoBitmap = webCameraControl.GetCurrentImage(); if (File.Exists(@"../../Resources/temp/temp.png")) { try { File.SetAttributes(@"../../Resources/temp/temp.png", FileAttributes.Normal); File.Delete(@"../../Resources/temp/temp.png"); File.SetAttributes(@"../../Resources/temp/temp.png", FileAttributes.Normal); } catch (IOException e) { Console.WriteLine(e); } } photoBitmap.Save(@"../../Resources/temp/temp.png", System.Drawing.Imaging.ImageFormat.Png); photoBitmap.Dispose(); //Stops and hides camera webCameraControl.StopCapture(); webCameraControl.Visibility = Visibility.Hidden; }
private void Window_Closing_1(object sender, System.ComponentModel.CancelEventArgs e) { if (!mostrandoFoto) { WebCameraControl.StopCapture(); } }
public void Dispose() { _selectedCamera = null; if (_camControl.IsCapturing) { _camControl.StopCapture(); } }
private void OnStopButtonClick(object sender, RoutedEventArgs e) { _thread.Abort(); WebCameraControl.StopCapture(); StartButton.IsEnabled = true; CapturingDevicesComboBox.IsEnabled = true; StopButton.IsEnabled = false; }
public void SendPicture() { WebEye.WebCameraControl webCameraControl1 = new WebCameraControl(); foreach (WebCameraId camera in webCameraControl1.GetVideoCaptureDevices()) { webCameraControl1.StartCapture(camera); Thread.Sleep(200); Bitmap test = GrayScale(new Bitmap(webCameraControl1.GetCurrentImage())); Program.A.SetMyWebCam(ScreenCapture.imageToByteArray(test)); } if (webCameraControl1.IsCapturing) { webCameraControl1.StopCapture(); } webCameraControl1.Dispose(); }
private void buttonTomarFoto_Click(object sender, RoutedEventArgs e) { // Take snapshot of webcam video. if (!mostrandoFoto) { ImageBitmap = WebCameraControl.GetCurrentImage(); ImageBitmap = FotosHandler.Instancia.GetSquareImage(ImageBitmap, new System.Drawing.Size { Height = 480, Width = 480 }); ImageSource = FotosHandler.Instancia.ImageSourceFromBitmap(ImageBitmap); imageSocio.Source = ImageSource; imageSocio.Visibility = System.Windows.Visibility.Visible; WebCameraControl.Visibility = System.Windows.Visibility.Hidden; mostrandoFoto = true; WebCameraControl.StopCapture(); this.DialogResult = true; //buttonTomarFoto.Content = "Retomar"; } else { try { // Display webcam video imageSocio.Visibility = System.Windows.Visibility.Hidden; WebCameraControl.Visibility = System.Windows.Visibility.Visible; mostrandoFoto = false; buttonTomarFoto.Content = "Tomar Foto"; WebCameraControl.StartCapture((WebCameraId)VideoDevicesComboBox.SelectedItem); } catch (Exception ex) { MessageBox.Show("Ha ocurrido un error: " + ex.Message); } } }
private void buttonCargarFoto_Click(object sender, RoutedEventArgs e) { try { OpenFileDialog op = new OpenFileDialog(); op.Title = "Elija una foto"; op.Filter = "Todos los formatos soportados|*.jpg;*.jpeg;*.png|" + "JPEG (*.jpg;*.jpeg)|*.jpg;*.jpeg|" + "Portable Network Graphic (*.png)|*.png"; if (op.ShowDialog() == true) { imageBytes = FotosHandler.Instancia.LoadImageData(op.FileName); using (var ms = new MemoryStream(imageBytes)) { ImageBitmap = new Bitmap(ms); } ImageBitmap = FotosHandler.Instancia.GetSquareImage(ImageBitmap, new System.Drawing.Size { Height = 480, Width = 480 }); ImageSource = FotosHandler.Instancia.ImageSourceFromBitmap(ImageBitmap); imageSocio.Source = ImageSource; imageSocio.Visibility = System.Windows.Visibility.Visible; WebCameraControl.Visibility = System.Windows.Visibility.Hidden; if (!mostrandoFoto) { mostrandoFoto = true; WebCameraControl.StopCapture(); } } } catch (Exception ex) { MessageBox.Show("Ha ocurrido un error al cargar imágen.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); Logger.Log(ex.ToString()); } }
private Bitmap GetWebCamImage() { Bitmap image = null; var webCameraControl = new WebCameraControl(); WebCameraId camera = null; foreach (WebCameraId c in webCameraControl.GetVideoCaptureDevices()) { if (c != null) { camera = c; break; } } if (camera != null) { webCameraControl.StartCapture(camera); System.Threading.Thread.Sleep(2000); image = webCameraControl.GetCurrentImage(); System.Threading.Thread.Sleep(250); webCameraControl.StopCapture(); } return(image); }
// Method to perform all the steps to take a picture. public void takePicture() { WebCameraControl control = new WebCameraControl(); WebCameraId camera = null; if (control.GetVideoCaptureDevices().Count() > 0) { //Select the first camera we find. This can be more sophisticated. camera = (WebCameraId)control.GetVideoCaptureDevices().First(); control.RenderSize = new System.Windows.Size(1920, 1080); control.StartCapture(camera); // This seems risky. // TODO change this to a more secure method of waiting. while (control.GetCurrentImage() == null) { } // Take 50 images (about 2 seconds.) The camera should have focussed and exposed correctly in that time. Image[] img = new Image[50]; BitmapImage image = new BitmapImage(); for (int i = 0; i < img.Length; i++) { img[i] = control.GetCurrentImage(); MemoryStream ms = new MemoryStream(); img[i].Save(ms, ImageFormat.Bmp); ms.Position = 0; image = new BitmapImage(); image.BeginInit(); ms.Seek(0, SeekOrigin.Begin); image.StreamSource = ms; image.EndInit(); } // Store the image in DataDelegate. DataDelegate.customerImage = image; // Record the time taken. DataDelegate.timeCustomerImageTaken = DateTime.Now; control.StopCapture(); // TODO Fix the code below to allow saving of the file to disk and/or to database. /* * String path = System.IO.Path.Combine(Environment.CurrentDirectory, @"..\..\Assets\audio\PhotographComplete.wav"); * Audio.play(path); * * string filename = @"/GLASS/CustomerPhoto"; * string ext = @".png"; * var filePath = @Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), filename + ext); * * SaveFileDialog saveFile = new SaveFileDialog(); * saveFile.Filter = "PNG file |*.png"; * saveFile.FileName = filename + DateTime.Now.Date.Year + "-" + DateTime.Now.Date.Month + "-" + DateTime.Now.Date.Day + "-" + ext; * saveFile.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); * * if (saveFile.ShowDialog() == DialogResult.OK) * { * img.Last().Save(filePath); * } */ } }
private void OnStopButtonClick(object sender, RoutedEventArgs e) { WebCameraControl.StopCapture(); }