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)

View File

@@ -61,7 +61,7 @@ namespace OpenRA
IShader CreateShader(string name);
void EnableScissor(int left, int top, int width, int height);
void DisableScissor();
Bitmap TakeScreenshot();
void SaveScreenshot(string path);
void Present();
void DrawPrimitives(PrimitiveType pt, int firstVertex, int numVertices);
void Clear();

View File

@@ -11,7 +11,6 @@
using System;
using System.Collections.Generic;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using OpenRA.Graphics;
@@ -166,8 +165,6 @@ namespace OpenRA
public string Language = "english";
public string DefaultLanguage = "english";
public ImageFormat ScreenshotFormat = ImageFormat.Png;
}
public class SoundSettings