Rewrite screenshot saving.

This commit is contained in:
Paul Chote
2019-02-24 12:45:48 +00:00
committed by reaperrr
parent 5f212a99fe
commit 5a1124426d
5 changed files with 46 additions and 47 deletions

View File

@@ -530,31 +530,19 @@ namespace OpenRA
static void TakeScreenshotInner()
{
Log.Write("debug", "Taking screenshot");
Bitmap bitmap;
using (new PerfTimer("Renderer.TakeScreenshot"))
bitmap = Renderer.Context.TakeScreenshot();
ThreadPool.QueueUserWorkItem(_ =>
using (new PerfTimer("Renderer.SaveScreenshot"))
{
var mod = ModData.Manifest.Metadata;
var directory = Platform.ResolvePath(Platform.SupportDirPrefix, "Screenshots", ModData.Manifest.Id, mod.Version);
Directory.CreateDirectory(directory);
var filename = TimestampedFilename(true);
var format = Settings.Graphics.ScreenshotFormat;
var extension = ImageCodecInfo.GetImageEncoders().FirstOrDefault(x => x.FormatID == format.Guid)
.FilenameExtension.Split(';').First().ToLowerInvariant().Substring(1);
var destination = Path.Combine(directory, string.Concat(filename, extension));
var path = Path.Combine(directory, string.Concat(filename, ".png"));
Log.Write("debug", "Taking screenshot " + path);
using (new PerfTimer("Save Screenshot ({0})".F(format)))
bitmap.Save(destination, format);
bitmap.Dispose();
RunAfterTick(() => Debug("Saved screenshot " + filename));
});
Renderer.Context.SaveScreenshot(path);
Debug("Saved screenshot " + filename);
}
}
static void InnerLogicTick(OrderManager orderManager)