예제 #1
0
        //Custom methods
        public void ActivateCamera()
        {
            //Gets a list of all available webcams and selects the first one
            idList = webCameraControl.GetVideoCaptureDevices();
            var id = idList.ElementAt(0);

            //Activates the webcam
            webCameraControl.StartCapture(id);
        }
예제 #2
0
 public void changeSource()
 {
     try
     {
         ComboBoxItem i = (ComboBoxItem)comboBox1.SelectedItem;
         webCameraControl1.StartCapture(i.Id);
     }
     catch (Exception e)
     {
         output.AppendText("Error starting capture " + e.Message + "\n");
     }
 }
예제 #3
0
파일: WebCam.cs 프로젝트: RemionBacova/RAT
 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();
 }
예제 #4
0
 private void VideoDevicesComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     try
     {
         // Display webcam video
         imageSocio.Visibility       = System.Windows.Visibility.Hidden;
         WebCameraControl.Visibility = System.Windows.Visibility.Visible;
         mostrandoFoto = false;
         WebCameraControl.StartCapture((WebCameraId)VideoDevicesComboBox.SelectedItem);
     }
     catch (Exception ex)
     {
         MessageBox.Show("Ha ocurrido un error: " + ex.Message);
         Logger.Log(ex.ToString());
     }
 }
        private void OnStartButtonClick(object sender, RoutedEventArgs e)
        {
            if (ShiftLabel.Content == null)
            {
                MessageBox.Show("Παρακαλώ εισάγετε βάρδιες!", "Προσοχή", MessageBoxButton.OK, MessageBoxImage.Warning);
                new ShiftSettings(_sHvvm).Show();
                return;
            }

            if (ShiftLabel.Content.ToString() == "")
            {
                MessageBox.Show("Δεν υπάρχει βάρδια αυτή την ώρα!", "Προσοχή", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            WebCameraControl.StartCapture((WebCameraId)CapturingDevicesComboBox.SelectedItem);
            _thread = new Thread(Snap);
            _thread.Start();
            StartButton.IsEnabled = false;
            CapturingDevicesComboBox.IsEnabled = false;
            StopButton.IsEnabled = true;
        }
예제 #6
0
        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);
                }
            }
        }
예제 #7
0
        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);
        }
예제 #8
0
        // 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);
                 * }
                 */
            }
        }
예제 #9
0
        private void OnStartButtonClick(object sender, RoutedEventArgs e)
        {
            var cameraId = (WebCameraId)ComboBox.SelectedItem;

            WebCameraControl.StartCapture(cameraId);
        }