Exemple #1
0
        /// <summary>
        /// Take a picture
        /// </summary>
        public void TakePictures()
        {
            Stream video;

            Device.StartCaptureContinuous();
            while (IsRunning)
            {
                try
                {
                    video = Device.CaptureContinuous();
                    Bitmap   myBitmap = new Bitmap(video);
                    Graphics g        = Graphics.FromImage(myBitmap);
                    g.DrawString(DateTime.Now.AddHours(Timezone).ToString("yyyy-MM-dd HH:mm:ss"), new Font("Tahoma", 20), Brushes.White, new PointF(0, 0));
                    using (var ms = new MemoryStream())
                    {
                        myBitmap.Save(ms, ImageFormat.Jpeg);
                        LastImage = ms.ToArray();
                    }

                    NewImageReady?.Invoke(this, new NewImageReadyEventArgs(LastImage));
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"{ex}");
                    Thread.Sleep(1000);
                }
            }

            Device.StopCaptureContinuous();
        }
Exemple #2
0
 /// <summary>
 /// Stop the device capturing and reset
 /// </summary>
 public void StopCapture()
 {
     if (_device.IsCapturing)
     {
         _tokenSource.Cancel();
         _tokenSource = new CancellationTokenSource();
         _device.StopCaptureContinuous();
     }
 }