Пример #1
0
        public Bitmap Screen(ref Rectangle bounds, CaptureMode captureMode, ScreenDisplayItem screen = null)
        {
            // Capture a new screenshot.
            //

            if (captureMode == CaptureMode.AllScreens)
            {
                _newBitmap = CaptureScreen.CaptureAllScreens();
            }
            else if (captureMode == CaptureMode.ActiveScreen)
            {
                _newBitmap = CaptureScreen.CaptureDesktopWithCursor();
            }
            else if (captureMode == CaptureMode.SpecificScreen)
            {
                _newBitmap = CaptureScreen.CaptureSpecificScreen(screen);
            }

            if (_newBitmap == null)
            {
                _newBitmap = new Bitmap(10, 10);
            }
            // If we have a previous screenshot, only send back
            //    a subset that is the minimum rectangular area
            //    that encompasses all the changed pixels.
            //
            if (_prevBitmap != null)
            {
                // Get the bounding box.
                //
                bounds = GetBoundingBoxForChanges();
                if (bounds == Rectangle.Empty)
                {
                    // Nothing has changed.
                    //
                    return(null);
                }

                // Get the minimum rectangular area
                //
                var diff = new Bitmap(bounds.Width, bounds.Height);
                var g    = Graphics.FromImage(diff);
                g.DrawImage(_newBitmap, 0, 0, bounds, GraphicsUnit.Pixel);
                g.Dispose();

                // Set the current bitmap as the previous to prepare
                //    for the next screen capture.
                //
                _prevBitmap = _newBitmap;

                return(diff);
            }
            // We don't have a previous screen capture. Therefore
            //    we need to send back the whole screen this time.
            //
            // Set the previous bitmap to the current to prepare
            //    for the next screen capture.
            //
            _prevBitmap = _newBitmap;

            // Create a bounding rectangle.
            //
            bounds = new Rectangle(0, 0, _newBitmap.Width, _newBitmap.Height);

            return(_newBitmap);
        }
Пример #2
0
 public List <ScreenDisplayItem> LoadScreens()
 {
     return(CaptureScreen.LoadScreens());
 }