mirror of
https://github.com/osukey/osukey.git
synced 2025-07-03 01:09:57 +09:00
Introduce ScreenshotManager class
This commit is contained in:
50
osu.Game/Graphics/ScreenshotManager.cs
Normal file
50
osu.Game/Graphics/ScreenshotManager.cs
Normal file
@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Configuration;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Game.Configuration;
|
||||
|
||||
namespace osu.Game.Graphics
|
||||
{
|
||||
public class ScreenshotManager : Drawable
|
||||
{
|
||||
private Bindable<ScreenshotFormat> screenshotFormat;
|
||||
private GameHost host;
|
||||
private Storage storage;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(GameHost host, OsuConfigManager config, Storage storage)
|
||||
{
|
||||
this.host = host;
|
||||
this.storage = storage.GetStorageForDirectory(@"screenshots");
|
||||
|
||||
screenshotFormat = config.GetBindable<ScreenshotFormat>(OsuSetting.ScreenshotFormat);
|
||||
}
|
||||
|
||||
public void TakeScreenshot()
|
||||
{
|
||||
host.TakeScreenshot(screenshotBitmap =>
|
||||
{
|
||||
var stream = storage.GetStream($"{DateTime.Now:yyyyMMddTHHmmss}.{screenshotFormat.ToString().ToLower()}", FileAccess.Write);
|
||||
|
||||
switch (screenshotFormat.Value)
|
||||
{
|
||||
case ScreenshotFormat.Bmp:
|
||||
screenshotBitmap.Save(stream, ImageFormat.Bmp);
|
||||
break;
|
||||
case ScreenshotFormat.Png:
|
||||
screenshotBitmap.Save(stream, ImageFormat.Png);
|
||||
break;
|
||||
case ScreenshotFormat.Jpg:
|
||||
screenshotBitmap.Save(stream, ImageFormat.Jpeg);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(screenshotFormat));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user