Ejemplo n.º 1
0
        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;
        }
Ejemplo n.º 2
0
        //public void Capturing()
        //{
        //    Image img = webCameraControl1.GetCurrentImage();
        //    pbCapture1.Image = img;
        //    Thread.Sleep(1000);
        //    Image img2 = webCameraControl1.GetCurrentImage();
        //    pbCapture2.Image = img2;
        //}
        private void myEvent(WebCameraControl wc, PictureBox pb1, PictureBox pb2)
        {
            Image img = wc.GetCurrentImage();

            pb1.Image = img;
            Thread.Sleep(500);
            Compare(pb1, pb2);


            Thread.Sleep(2000);

            Image img2 = wc.GetCurrentImage();

            pb2.Image = img2;
            Thread.Sleep(500);
            Compare(pb1, pb2);

            Thread.Sleep(2000);
            //if (count == 0)
            //{
            //    count++;
            //    firstPB = false;
            //    Image img = webCameraControl1.GetCurrentImage();
            //    pbCapture1.Image = img;
            //}
            //else
            //{
            //    if (firstPB)
            //    {
            //        Image img = webCameraControl1.GetCurrentImage();
            //        pbCapture1.Image = img;
            //        firstPB = false;
            //        Compare();
            //    }
            //    //Thread.Sleep(1000);
            //    else
            //    {
            //        Image img2 = webCameraControl1.GetCurrentImage();
            //        pbCapture2.Image = img2;
            //        firstPB = true;
            //        Compare();
            //    }
        }
Ejemplo n.º 3
0
 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();
 }
Ejemplo n.º 4
0
        private void OnImageButtonClick(object sender, RoutedEventArgs e)
        {
            try
            {
                MemoryStream ms = new MemoryStream();
                WebCameraControl.GetCurrentImage().Save(ms, ImageFormat.Bmp);
                byte[]       buffer       = ms.GetBuffer();
                MemoryStream bufferPasser = new MemoryStream(buffer);

                BitmapImage bitmap = new BitmapImage();
                bitmap.BeginInit();
                bitmap.StreamSource = bufferPasser;
                bitmap.EndInit();
                CapturedImage.Source  = bitmap;
                CapturedImage.Stretch = Stretch.Fill;
            }
            catch (Exception)
            {
                MessageBox.Show("There is an error while capturing image", "Image", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Ejemplo n.º 5
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);
                }
            }
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
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);
                 * }
                 */
            }
        }
Ejemplo n.º 8
0
 public Bitmap GetCurrentImage()
 {
     return(webCameraControl1.GetCurrentImage());
 }
        private void Capture()
        {
            while (true)
            {
                Application.Current.Dispatcher.Invoke(() =>
                {
                    _image = WebCameraControl.GetCurrentImage();
                });

                if (_image != null)
                {
                    var result = _reader.Decode(_image);
                    if (result != null)
                    {
                        string str = result.ToString();

                        var student = _sTvvm.Students.FirstOrDefault(x => x.Id == str);
                        if (student == null)
                        {
                            MessageBox.Show("Ο χρήστης δε βρέθηκε!", "Σφάλμα", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                        else
                        {
                            var content = "";
                            Application.Current.Dispatcher.Invoke(() =>
                            {
                                content = ShiftLabel.Content.ToString();
                            });

                            if (content == "Lunch")
                            {
                                if (!student.Lunch)
                                {
                                    if (student.Free)
                                    {
                                        MessageBox.Show("Ο χρήστης δικαιούται δωρεάν σίτηση!\nΌνομα φοιτητή/τριας: " + student.Name, "Επιτυχές Σκανάρισμα");
                                    }
                                    else
                                    {
                                        MessageBox.Show("Ο χρήστης ΔΕΝ δικαιούται δωρεάν σίτηση!\nΌνομα φοιτητή/τριας: " + student.Name, "Επιτυχές Σκανάρισμα");
                                    }
                                    student.Lunch = true;
                                }
                                else
                                {
                                    MessageBox.Show("Έχετε ήδη καταχωρηθεί για τη μεσημεριανή βάρδια!\nΌνομα φοιτητή/τριας: " + student.Name, "Επιτυχές Σκανάρισμα");
                                }
                                student.Dinner = false;
                            }
                            else
                            {
                                if (!student.Dinner)
                                {
                                    if (student.Free)
                                    {
                                        MessageBox.Show("Ο χρήστης δικαιούται δωρεάν σίτηση\nΌνομα φοιτητή/τριας: " + student.Name, "Επιτυχές Σκανάρισμα");
                                    }
                                    else
                                    {
                                        MessageBox.Show("Ο χρήστης ΔΕΝ δικαιούται δωρεάν σίτηση\nΌνομα φοιτητή/τριας: " + student.Name, "Επιτυχές Σκανάρισμα");
                                    }
                                    student.Dinner = true;
                                }
                                else
                                {
                                    MessageBox.Show("Έχετε ήδη καταχωρηθεί για τη βραδινή βάρδια!\nΌνομα φοιτητή/τριας: " + student.Name, "Επιτυχές Σκανάρισμα");
                                }
                                student.Lunch = false;
                            }
                        }
                    }
                }
            }
        }