656863a7d0
* feat(docstring):添加docstring Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com> * fix(docstring):修复部分docstring格式错误 Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com> * fix(docstring):修复部分docstring Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com> * chore(Docstring):MW_* 前14 * chore(Docstring):MW_* part 2 * chore(Docstring):MW_* part 3 * chore:优化缩进 * fix: 修复数学计算中的潜在除零错误和数值稳定性问题 Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com> * chore:删除Rebase时多余的OOBE函数 * chore: 更新代码注释和文档格式 修复XML文档注释中的格式问题,统一使用<c>和<see>标签 更新ConfigHelper类的预留说明,明确未来扩展用途 优化TimerDisplayDate_Elapsed方法的注释,说明UI异步更新机制 合并重复的注释摘要行,提高文档可读性 添加形状识别功能的64位进程限制说明 修正视频呈现器设备选择逻辑的文档说明 * chore(IPPTLinkManager): 更新TryEndSlideShow方法的XML注释格式 * chore: 修正代码注释中的术语和格式问题 更新多个文件中的XML注释,统一使用<see langword="..."/>标记代替<c>...</c>标记 规范术语使用(如"延迟初始化"代替"懒惰初始化") 修正注释中的格式错误和补充说明 调整代码区域的注释对齐格式 --------- Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>
176 lines
6.2 KiB
C#
176 lines
6.2 KiB
C#
using System;
|
|
using System.Drawing;
|
|
using System.Drawing.Drawing2D;
|
|
using System.Drawing.Imaging;
|
|
using System.IO;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Ink_Canvas
|
|
{
|
|
public partial class MainWindow : Window
|
|
{
|
|
/// <summary>
|
|
/// 保存截图
|
|
/// </summary>
|
|
/// <param name="isHideNotification">是否隐藏通知</param>
|
|
/// <param name="fileName">文件名</param>
|
|
/// <remarks>
|
|
/// 该方法会:
|
|
/// 1. 根据设置确定保存路径
|
|
/// 2. 调用CaptureAndSaveScreenshot方法捕获并保存截图
|
|
/// 3. 如果设置了自动保存墨迹,调用SaveInkCanvasStrokes方法保存墨迹
|
|
/// </remarks>
|
|
private void SaveScreenShot(bool isHideNotification, string fileName = null)
|
|
{
|
|
var savePath = Settings.Automation.IsSaveScreenshotsInDateFolders
|
|
? GetDateFolderPath(fileName)
|
|
: GetDefaultFolderPath();
|
|
|
|
CaptureAndSaveScreenshot(savePath, isHideNotification);
|
|
|
|
if (Settings.Automation.IsAutoSaveStrokesAtScreenshot)
|
|
SaveInkCanvasStrokes(false);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 保存截图到桌面
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// 该方法会:
|
|
/// 1. 生成桌面路径和文件名
|
|
/// 2. 调用CaptureAndSaveScreenshot方法捕获并保存截图到桌面
|
|
/// 3. 如果设置了自动保存墨迹,调用SaveInkCanvasStrokes方法保存墨迹
|
|
/// </remarks>
|
|
internal void SaveScreenShotToDesktop()
|
|
{
|
|
var desktopPath = Path.Combine(
|
|
Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory),
|
|
$"{DateTime.Now:yyyy-MM-dd_HH-mm-ss}.png");
|
|
|
|
CaptureAndSaveScreenshot(desktopPath, false);
|
|
|
|
if (Settings.Automation.IsAutoSaveStrokesAtScreenshot)
|
|
SaveInkCanvasStrokes(false);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 提取公共的截图和保存逻辑
|
|
/// </summary>
|
|
/// <param name="savePath">保存路径</param>
|
|
/// <param name="isHideNotification">是否隐藏通知</param>
|
|
/// <remarks>
|
|
/// 该方法会:
|
|
/// 1. 获取虚拟屏幕边界
|
|
/// 2. 创建位图并设置高质量渲染
|
|
/// 3. 从屏幕复制内容到位图
|
|
/// 4. 确保保存目录存在
|
|
/// 5. 保存为PNG格式
|
|
/// 6. 如果不隐藏通知,显示保存成功通知
|
|
/// 7. 异步上传截图到Dlass
|
|
/// </remarks>
|
|
private void CaptureAndSaveScreenshot(string savePath, bool isHideNotification)
|
|
{
|
|
var rc = SystemInformation.VirtualScreen;
|
|
|
|
using (var bitmap = new Bitmap(rc.Width, rc.Height, PixelFormat.Format32bppArgb))
|
|
using (var memoryGraphics = Graphics.FromImage(bitmap))
|
|
{
|
|
// 设置高质量渲染
|
|
memoryGraphics.CompositingQuality = CompositingQuality.HighQuality;
|
|
memoryGraphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
|
memoryGraphics.SmoothingMode = SmoothingMode.HighQuality;
|
|
memoryGraphics.CompositingMode = CompositingMode.SourceOver;
|
|
|
|
memoryGraphics.CopyFromScreen(rc.X, rc.Y, 0, 0, rc.Size, CopyPixelOperation.SourceCopy);
|
|
|
|
// 确保目录存在
|
|
var directory = Path.GetDirectoryName(savePath);
|
|
if (!Directory.Exists(directory))
|
|
{
|
|
Directory.CreateDirectory(directory);
|
|
}
|
|
|
|
// 使用PNG格式保存,确保透明度信息不丢失
|
|
bitmap.Save(savePath, ImageFormat.Png);
|
|
}
|
|
|
|
if (!isHideNotification)
|
|
{
|
|
ShowNotification($"截图成功保存至 {savePath}");
|
|
}
|
|
_ = Task.Run(async () =>
|
|
{
|
|
try
|
|
{
|
|
var delayMinutes = Settings?.Dlass?.AutoUploadDelayMinutes ?? 0;
|
|
if (delayMinutes > 0)
|
|
{
|
|
await Task.Delay(TimeSpan.FromMinutes(delayMinutes));
|
|
}
|
|
|
|
await Helpers.DlassNoteUploader.UploadNoteFileAsync(savePath);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取日期文件夹路径
|
|
/// </summary>
|
|
/// <param name="fileName">文件名</param>
|
|
/// <returns>日期文件夹路径</returns>
|
|
/// <remarks>
|
|
/// 该方法会:
|
|
/// 1. 如果文件名为空,使用当前时间作为文件名
|
|
/// 2. 获取基础路径和日期文件夹名
|
|
/// 3. 组合路径并返回
|
|
/// </remarks>
|
|
private string GetDateFolderPath(string fileName)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(fileName))
|
|
{
|
|
fileName = DateTime.Now.ToString("HH-mm-ss");
|
|
}
|
|
|
|
var basePath = Settings.Automation.AutoSavedStrokesLocation;
|
|
var dateFolder = DateTime.Now.ToString("yyyyMMdd");
|
|
|
|
return Path.Combine(
|
|
basePath,
|
|
"Auto Saved - Screenshots",
|
|
dateFolder,
|
|
$"{fileName}.png");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取默认文件夹路径
|
|
/// </summary>
|
|
/// <returns>默认文件夹路径</returns>
|
|
/// <remarks>
|
|
/// 该方法会:
|
|
/// 1. 获取基础路径
|
|
/// 2. 组合截图文件夹路径
|
|
/// 3. 确保截图文件夹存在
|
|
/// 4. 生成文件名并组合完整路径返回
|
|
/// </remarks>
|
|
private string GetDefaultFolderPath()
|
|
{
|
|
var basePath = Settings.Automation.AutoSavedStrokesLocation;
|
|
var screenshotsFolder = Path.Combine(basePath, "Auto Saved - Screenshots");
|
|
|
|
if (!Directory.Exists(screenshotsFolder))
|
|
{
|
|
Directory.CreateDirectory(screenshotsFolder);
|
|
}
|
|
|
|
return Path.Combine(
|
|
screenshotsFolder,
|
|
$"{DateTime.Now:yyyy-MM-dd_HH-mm-ss}.png");
|
|
}
|
|
}
|
|
}
|