private static Bitmap LoadBitmap(CaptureMode captureMode, ScreenDisplayItem screen = null) { var capture = new ScreenTools(); var bounds = new Rectangle(); var img = capture.Screen(ref bounds, captureMode, screen); img = new Bitmap(img, new Size(img.Width / 20, img.Height / 20)); return(img); }
public SolidColorBrush LoadAverageColor(CaptureMode captureMode, ScreenDisplayItem screen = null) { var img = LoadBitmap(captureMode, screen); var background = GetDominantColor(img); Debug.Print(background.ToString()); var brush = new SolidColorBrush(background) { Brightness = 1f }; return(brush); }
public static Bitmap CaptureSpecificScreen(ScreenDisplayItem screenDisplayItem) { if (screenDisplayItem?.Screen != null) { var bmp = new Bitmap(screenDisplayItem.Screen.Bounds.Width, screenDisplayItem.Screen.Bounds.Height); // Draw the screenshot into our bitmap. using (var g = Graphics.FromImage(bmp)) { g.CopyFromScreen(screenDisplayItem.Screen.Bounds.Left, screenDisplayItem.Screen.Bounds.Top, 0, 0, bmp.Size); } return(bmp); } return(null); }
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); }
public BitmapImage LoadScreen(CaptureMode captureMode, ScreenDisplayItem screen = null) { var img = LoadBitmap(captureMode, screen); return(ToBitmapImage(img)); }