feat(app): 初始化自动关机工具首个版本
实现基于 WPF 的 AutoShutdown 主界面,支持关机、重启、睡眠、休眠、唤醒、锁屏和注销等电源任务。 支持指定时间和倒计时计划、执行前提醒、系统关机撤销、Windows 唤醒任务、托盘运行、自定义图标以及 OmniNotify 通知适配。 修复关闭到托盘时的运行提醒,并支持单击托盘图标打开或收起主界面。 补充 README、发布配置和 win-x64 Release 输出要求。 Release: win-x64
This commit is contained in:
33
Services/ScreenshotService.cs
Normal file
33
Services/ScreenshotService.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
#if DEBUG
|
||||
using System.IO;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
|
||||
namespace AutoShutdown.Services;
|
||||
|
||||
internal static class ScreenshotService
|
||||
{
|
||||
public static string Capture(Window window, string? requestedPath = null)
|
||||
{
|
||||
var path = string.IsNullOrWhiteSpace(requestedPath)
|
||||
? Path.Combine(AppContext.BaseDirectory, "Screenshots", $"ui-{DateTime.Now:yyyyMMdd-HHmmss}.png")
|
||||
: Path.GetFullPath(requestedPath);
|
||||
|
||||
var directory = Path.GetDirectoryName(path) ?? AppContext.BaseDirectory;
|
||||
Directory.CreateDirectory(directory);
|
||||
|
||||
var visual = (FrameworkElement)window.Content;
|
||||
var width = Math.Max(1, (int)Math.Ceiling(visual.ActualWidth));
|
||||
var height = Math.Max(1, (int)Math.Ceiling(visual.ActualHeight));
|
||||
var target = new RenderTargetBitmap(width, height, 96, 96, PixelFormats.Pbgra32);
|
||||
target.Render(visual);
|
||||
|
||||
var encoder = new PngBitmapEncoder();
|
||||
encoder.Frames.Add(BitmapFrame.Create(target));
|
||||
using var stream = File.Create(path);
|
||||
encoder.Save(stream);
|
||||
return path;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user