2024-05-01 18:23:32 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Drawing.Imaging;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
|
|
|
|
|
namespace Ink_Canvas {
|
|
|
|
|
public partial class MainWindow : Window {
|
|
|
|
|
private void SaveScreenShot(bool isHideNotification, string fileName = null) {
|
2024-06-05 20:25:26 +08:00
|
|
|
|
var rc = System.Windows.Forms.SystemInformation.VirtualScreen;
|
|
|
|
|
var bitmap = new System.Drawing.Bitmap(rc.Width, rc.Height, PixelFormat.Format32bppArgb);
|
2024-05-01 18:23:32 +08:00
|
|
|
|
|
2024-06-05 20:25:26 +08:00
|
|
|
|
using (var memoryGrahics = System.Drawing.Graphics.FromImage(bitmap)) {
|
2024-05-01 18:23:32 +08:00
|
|
|
|
memoryGrahics.CopyFromScreen(rc.X, rc.Y, 0, 0, rc.Size, System.Drawing.CopyPixelOperation.SourceCopy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Settings.Automation.IsSaveScreenshotsInDateFolders) {
|
|
|
|
|
if (string.IsNullOrWhiteSpace(fileName)) fileName = DateTime.Now.ToString("HH-mm-ss");
|
2024-06-05 20:25:26 +08:00
|
|
|
|
var savePath = Settings.Automation.AutoSavedStrokesLocation +
|
|
|
|
|
@"\Auto Saved - Screenshots\{DateTime.Now.Date:yyyyMMdd}\{fileName}.png";
|
|
|
|
|
if (!Directory.Exists(Path.GetDirectoryName(savePath)))
|
2024-05-01 18:23:32 +08:00
|
|
|
|
Directory.CreateDirectory(Path.GetDirectoryName(savePath));
|
|
|
|
|
bitmap.Save(savePath, ImageFormat.Png);
|
2024-06-05 20:25:26 +08:00
|
|
|
|
if (!isHideNotification) ShowNotification("截图成功保存至 " + savePath);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
var savePath = Settings.Automation.AutoSavedStrokesLocation + @"\Auto Saved - Screenshots";
|
|
|
|
|
if (!Directory.Exists(savePath)) Directory.CreateDirectory(savePath);
|
2024-05-01 18:23:32 +08:00
|
|
|
|
bitmap.Save(savePath + @"\" + DateTime.Now.ToString("u").Replace(':', '-') + ".png", ImageFormat.Png);
|
2024-06-05 20:25:26 +08:00
|
|
|
|
if (!isHideNotification)
|
|
|
|
|
ShowNotification("截图成功保存至 " + savePath + @"\" + DateTime.Now.ToString("u").Replace(':', '-') +
|
|
|
|
|
".png");
|
2024-05-01 18:23:32 +08:00
|
|
|
|
}
|
2024-06-05 20:25:26 +08:00
|
|
|
|
|
2024-05-01 18:23:32 +08:00
|
|
|
|
if (Settings.Automation.IsAutoSaveStrokesAtScreenshot) SaveInkCanvasStrokes(false, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SaveScreenShotToDesktop() {
|
2024-06-05 20:25:26 +08:00
|
|
|
|
var rc = System.Windows.Forms.SystemInformation.VirtualScreen;
|
|
|
|
|
var bitmap = new System.Drawing.Bitmap(rc.Width, rc.Height, PixelFormat.Format32bppArgb);
|
2024-05-01 18:23:32 +08:00
|
|
|
|
|
2024-06-05 20:25:26 +08:00
|
|
|
|
using (var memoryGrahics = System.Drawing.Graphics.FromImage(bitmap)) {
|
2024-05-01 18:23:32 +08:00
|
|
|
|
memoryGrahics.CopyFromScreen(rc.X, rc.Y, 0, 0, rc.Size, System.Drawing.CopyPixelOperation.SourceCopy);
|
|
|
|
|
}
|
2024-06-05 20:25:26 +08:00
|
|
|
|
|
|
|
|
|
var savePath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
|
2024-05-01 18:23:32 +08:00
|
|
|
|
bitmap.Save(savePath + @"\" + DateTime.Now.ToString("u").Replace(':', '-') + ".png", ImageFormat.Png);
|
|
|
|
|
ShowNotification("截图成功保存至【桌面" + @"\" + DateTime.Now.ToString("u").Replace(':', '-') + ".png】");
|
|
|
|
|
if (Settings.Automation.IsAutoSaveStrokesAtScreenshot) SaveInkCanvasStrokes(false, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-05 20:25:26 +08:00
|
|
|
|
}
|