public async void SaveScreenshot(ClipboardContents clipboard = ClipboardContents.URL, bool openURL = false) { int shotNumber = 0; Directory.CreateDirectory("Screenshots"); string path = Path.Combine(Application.StartupPath, "Screenshots", "photovs_screenshot_" + shotNumber.ToString().PadLeft(3, '0') + ".png"); while (File.Exists(path)) { shotNumber++; path = Path.Combine(Application.StartupPath, "Screenshots", "photovs_screenshot_" + shotNumber.ToString().PadLeft(3, '0') + ".png"); } using (FileStream fs = new FileStream(path, FileMode.Create)) { Console.WriteLine("Copied to clipboard and saved screenshot to ", path); renderTarget2.SaveAsPng(fs, GAME_WIDTH, GAME_HEIGHT); } using (MemoryStream mem = new MemoryStream()) { // save game screenshot to memory renderTarget2.SaveAsPng(mem, GAME_WIDTH, GAME_HEIGHT); using (var w = new WebClient()) { // upload to Imgur // oh yeah, you all can see this too. oh well. string clientID = "36e2260c96b7e67"; w.Headers.Add("Authorization", "Client-ID " + clientID); var values = new NameValueCollection { { "image", Convert.ToBase64String(mem.GetBuffer()) } }; byte[] response = w.UploadValues("https://api.imgur.com/3/upload.xml", values); // parse through XML and get a link back using (MemoryStream res = new MemoryStream(response)) { var xml = XDocument.Load(res); var data = xml.Descendants("data"); foreach (var d in data) { var val = d.Element("link").Value; if (clipboard == ClipboardContents.Image) { Clipboard.SetImage(System.Drawing.Image.FromFile(path)); } else { Clipboard.SetText(val); } Console.WriteLine($"Screenshot uploaded to {val}"); // send to discord using (WebClient client = new WebClient()) { HttpResponseMessage resp = await new HttpClient().PostAsync("https://discordapp.com/api/webhooks/482641656361910272/ZKZfPujN8SfUBznuwqLUu_HJ2o-58ws_r5Whd3bcOalT2woGmjMTYAbwK7zuqFXY0rIl", new StringContent("{\"embeds\":[{\"image\":{\"url\":\"" + val + "\"}}]}", Encoding.UTF8, "application/json")); //Console.WriteLine(resp.ToString()); Console.WriteLine("Screenshot posted in PhotoVs Discord"); } if (openURL) { try { Process.Start(val); } catch (System.ComponentModel.Win32Exception) { Process.Start("IExplore.exe", val); } } } } } } }