public void TakeScreenshot() { if (Screen.AllScreens != null) { foreach (var screen in _displayHandler.Get().Where(d => d.Selected)) { var left = screen.X; var top = screen.Y; var width = screen.Width; var height = screen.Height; using (var bitmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)) { using (var bmpGraphics = Graphics.FromImage(bitmap)) { bmpGraphics.CopyFromScreen(left, top, 0, 0, new Size(width, height)); Messenger.Default?.Send(new ScreenShotTakenMessage(screen.FriendlyName, bitmap)); //TODO:https://stackoverflow.com/questions/1546091/wpf-createbitmapsourcefromhbitmap-memory-leak } } } } else { _logger.Warn("There are no screens to take screenshot from."); } }
public SettingsViewModel(ISettingsHandler settingsHandler, IDisplayHandler displayHandler, IOpenFileDialog openFileDialog) { _settingsHandler = settingsHandler ?? throw new ArgumentException("Parameter cannot be null", nameof(settingsHandler)); _displayHandler = displayHandler ?? throw new ArgumentException("Parameter cannot be null", nameof(displayHandler)); _openFileDialog = openFileDialog ?? throw new ArgumentException("Parameter cannot be null", nameof(openFileDialog)); _checkInterval = settingsHandler.GetCheckInterval(); _autoStart = settingsHandler.GetAutoStart(); _attachLastFileFromLocation = settingsHandler.GetAttachLastFileFromLocation(); _lastFileToAttachLocation = settingsHandler.GetLastFileToAttachLocation(); var displays = _displayHandler.Get().Select(d => new DisplayViewModel(d, SaveDisplaySettings)); _displays = new ObservableCollection <DisplayViewModel>(displays); _isExpanded = settingsHandler.GetSettingsIsExpanded(); }