Beispiel #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();
        }
Beispiel #2
0
        /// <summary>
        /// Open device connection and start capturing if it is not already.
        /// </summary>
        public void StartCapture()
        {
            // check if the connection is already open, multiple connections to the same video device are not supported.
            if (!_device.IsOpen)
            {
                _device.StartCaptureContinuous();
            }

            // check if the device is already capturing, multiple captures on the same video device are not supported.
            if (!_device.IsCapturing)
            {
                new Thread(() => { _device.CaptureContinuous(_tokenSource.Token); }).Start();
            }
        }