/// <summary> /// Captures Active Window and draws cursor if the option is set in WorkflowConfig /// </summary> /// <param name="WorkflowConfig">Optios for Active Window</param> /// <returns></returns> public static Image CaptureWithGDI2(Workflow WorkflowConfig) { DebugHelper.WriteLine("Capturing with GDI"); Image tempImage = null; Screenshot.DrawCursor = WorkflowConfig.DrawCursor; if (WorkflowConfig.ActiveWindowClearBackground) { tempImage = Screenshot.CaptureActiveWindowTransparent(); } else { tempImage = Screenshot.CaptureActiveWindow(); } return(tempImage); }
private void GlobalHotkeyServiceOnHotkeyPress(Hotkey hotkey) { try { if (_currentlyRunningGame == null && _settings.OnlyGameScreenshots) { return; } Bitmap bitmap; string region; if (hotkey == _settings.CaptureFullscreenHotkey) { bitmap = Screenshot.CaptureFullscreen(); region = "fullscreen"; } else if (hotkey == _settings.CaptureActiveMonitorHotkey) { bitmap = Screenshot.CaptureActiveMonitor(); region = "active monitor"; } else if (hotkey == _settings.CaptureActiveWindowHotkey) { bitmap = Screenshot.CaptureActiveWindow(); region = "active window"; } else { _logger.Error($"Unknown hotkey: {hotkey.DebugString()}"); return; } if (bitmap == null) { _logger.Error($"Unable to capture {region} with hotkey {hotkey.DebugString()}"); return; } var fileName = DateTime.Now.ToString("yyyy-MM-ddThh-mm-ss"); var folder = _currentlyRunningGame == null ? _settings.ScreenshotsPath : Path.Combine(_settings.ScreenshotsPath, _currentlyRunningGame.GameId); if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } var path = Path.Combine(folder, fileName + ".png"); bitmap.Save(path, ImageFormat.Png); //bitmap.Dispose(); _playniteAPI.Notifications.Add(new NotificationMessage(fileName, $"Saved new screenshot to {path}", NotificationType.Info, () => { try { Process.Start(path); } catch (Exception inner) { _logger.Error(inner, $"Exception while opening {path}"); } })); } catch (Exception e) { _logger.Error(e, $"Exception while handling hotkey {hotkey.DebugString()}\n"); } }