/// <summary>Takes a screenshot of the entire map, activated via keypress.</summary> private void TakeScreenshotViaKeypress() { string screenshotName = SaveGame.FilterFileName((string)(NetFieldBase <string, NetString>)Game1.player.name) + "_" + DateTime.UtcNow.Month + "-" + DateTime.UtcNow.Day.ToString() + "-" + DateTime.UtcNow.Year.ToString() + "_" + (int)DateTime.UtcNow.TimeOfDay.TotalMilliseconds; string mapScreenshot = Game1.game1.takeMapScreenshot(Config.TakeScreenshotKeyZoomLevel, screenshotName); Game1.addHUDMessage(new HUDMessage(mapScreenshot, 6)); Game1.playSound("cameraNoise"); if (Config.FolderDestinationForKeypressScreenshots != "default") { MoveKeypressScreenshotToCorrectFolder(screenshotName); } }
private void Input_ButtonPressed(object sender, StardewModdingAPI.Events.ButtonPressedEventArgs e) { if (Config.EnableMod && e.Button == Config.ScreenshotKey) { Monitor.Log("Saving screenshot"); var screenshot_name = string.Concat(new string[] { SaveGame.FilterFileName(Game1.player.Name), "_", DateTime.UtcNow.Month.ToString(), "-", DateTime.UtcNow.Day.ToString(), "-", DateTime.UtcNow.Year.ToString(), "_", ((int)DateTime.UtcNow.TimeOfDay.TotalMilliseconds).ToString(), ".png" }); if (!Directory.Exists(Config.ScreenshotFolder)) { Directory.CreateDirectory(Config.ScreenshotFolder); } var width = Game1.graphics.GraphicsDevice.PresentationParameters.BackBufferWidth; var height = Game1.graphics.GraphicsDevice.PresentationParameters.BackBufferHeight; Color[] data = new Color[width * height]; Game1.graphics.GraphicsDevice.GetBackBufferData(data); for (int i = 0; i < data.Length; i++) { data[i].A = 255; } Texture2D tex = new Texture2D(Game1.graphics.GraphicsDevice, width, height); tex.SetData(data); Stream stream = File.Create(Path.Combine(Config.ScreenshotFolder, screenshot_name)); tex.SaveAsPng(stream, width, height); stream.Close(); if (Config.Message.Length > 0) { Game1.addHUDMessage(new HUDMessage(string.Format(Config.Message, Path.Combine(Environment.CurrentDirectory, Config.ScreenshotFolder, screenshot_name)))); } } }