feat: 浮动栏截图修改为选区截图,添加“添加到白板”按钮 (#377)
* 调整截图按钮默认行为为选区/白板全屏 * 截图选择器新增添加到白板按钮并支持新建白板页插入 * 修复添加到白板不生效:改为剪贴板复制粘贴插入 * 修复添加到白板截图时序:先截到内存再进白板 * Fix screenshot insert flow honoring add-to-whiteboard option * Refine screenshot selector freehand confirm and blank double-click full select * Fix freehand whiteboard insert alpha transparency * Fix screenshot insert notification text for whiteboard flow * Adjust screenshot selection: right-click/double-click full-select and keep selector on single click * Show unmasked freehand selection area like rectangle mode * Remove freehand cutout mask rendering from screenshot selector * Restore freehand selected-area unmask behavior in selector
This commit is contained in:
@@ -6,6 +6,7 @@ using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Forms;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Ink;
|
||||
using Ink_Canvas.Helpers;
|
||||
|
||||
@@ -159,6 +160,160 @@ namespace Ink_Canvas
|
||||
SaveInkCanvasStrokes(false);
|
||||
}
|
||||
|
||||
internal async Task SaveAreaScreenShotToDesktop()
|
||||
{
|
||||
try
|
||||
{
|
||||
var originalVisibility = Visibility;
|
||||
Visibility = Visibility.Hidden;
|
||||
await Task.Delay(200);
|
||||
|
||||
var screenshotResult = await ShowScreenshotSelector();
|
||||
Visibility = originalVisibility;
|
||||
|
||||
if (!screenshotResult.HasValue)
|
||||
{
|
||||
ShowNotification("截图已取消");
|
||||
return;
|
||||
}
|
||||
|
||||
if (screenshotResult.Value.AddToWhiteboard)
|
||||
{
|
||||
await AddScreenshotToNewWhiteboardPage(screenshotResult.Value);
|
||||
return;
|
||||
}
|
||||
|
||||
if (screenshotResult.Value.Area.Width <= 0 || screenshotResult.Value.Area.Height <= 0)
|
||||
{
|
||||
ShowNotification("未选择有效截图区域");
|
||||
return;
|
||||
}
|
||||
|
||||
var desktopPath = Path.Combine(
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory),
|
||||
$"{DateTime.Now:yyyy-MM-dd_HH-mm-ss}.png");
|
||||
|
||||
using (var originalBitmap = CaptureScreenArea(screenshotResult.Value.Area))
|
||||
{
|
||||
if (originalBitmap == null)
|
||||
{
|
||||
ShowNotification("截图失败");
|
||||
return;
|
||||
}
|
||||
|
||||
Bitmap finalBitmap = originalBitmap;
|
||||
bool needDisposeFinalBitmap = false;
|
||||
|
||||
try
|
||||
{
|
||||
if (screenshotResult.Value.Path != null && screenshotResult.Value.Path.Count > 0)
|
||||
{
|
||||
finalBitmap = ApplyShapeMask(originalBitmap, screenshotResult.Value.Path, screenshotResult.Value.Area);
|
||||
needDisposeFinalBitmap = true;
|
||||
}
|
||||
|
||||
var directory = Path.GetDirectoryName(desktopPath);
|
||||
if (!Directory.Exists(directory))
|
||||
{
|
||||
Directory.CreateDirectory(directory);
|
||||
}
|
||||
|
||||
finalBitmap.Save(desktopPath, ImageFormat.Png);
|
||||
ShowNotification($"截图成功保存至 {desktopPath}");
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (needDisposeFinalBitmap && finalBitmap != originalBitmap)
|
||||
{
|
||||
finalBitmap.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Settings.Automation.IsAutoSaveStrokesAtScreenshot)
|
||||
SaveInkCanvasStrokes(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Visibility = Visibility.Visible;
|
||||
ShowNotification($"截图失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
private async Task AddScreenshotToNewWhiteboardPage(ScreenshotResult screenshotResult)
|
||||
{
|
||||
// 先在当前场景准备截图数据,再进白板,避免误截到白板页面
|
||||
BitmapSource bitmapSourceForClipboard = null;
|
||||
|
||||
// 摄像头截图(BitmapSource)
|
||||
if (screenshotResult.CameraBitmapSource != null)
|
||||
{
|
||||
bitmapSourceForClipboard = screenshotResult.CameraBitmapSource;
|
||||
}
|
||||
// 摄像头截图(Bitmap)
|
||||
else if (screenshotResult.CameraImage != null)
|
||||
{
|
||||
bitmapSourceForClipboard = ConvertBitmapToBitmapSource(screenshotResult.CameraImage);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (screenshotResult.Area.Width <= 0 || screenshotResult.Area.Height <= 0)
|
||||
{
|
||||
ShowNotification("未选择有效截图区域");
|
||||
return;
|
||||
}
|
||||
|
||||
using (var originalBitmap = CaptureScreenArea(screenshotResult.Area))
|
||||
{
|
||||
if (originalBitmap == null)
|
||||
{
|
||||
ShowNotification("截图失败");
|
||||
return;
|
||||
}
|
||||
|
||||
Bitmap finalBitmap = originalBitmap;
|
||||
bool needDisposeFinalBitmap = false;
|
||||
|
||||
try
|
||||
{
|
||||
if (screenshotResult.Path != null && screenshotResult.Path.Count > 0)
|
||||
{
|
||||
finalBitmap = ApplyShapeMask(originalBitmap, screenshotResult.Path, screenshotResult.Area);
|
||||
needDisposeFinalBitmap = true;
|
||||
}
|
||||
|
||||
bitmapSourceForClipboard = ConvertBitmapToBitmapSource(finalBitmap);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (needDisposeFinalBitmap && finalBitmap != originalBitmap)
|
||||
{
|
||||
finalBitmap.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (bitmapSourceForClipboard == null)
|
||||
{
|
||||
ShowNotification("截图转换失败");
|
||||
return;
|
||||
}
|
||||
|
||||
// 图像已拷贝到内存后再进入白板
|
||||
bitmapSourceForClipboard.Freeze();
|
||||
|
||||
if (currentMode != 1)
|
||||
{
|
||||
SwitchToBoardMode();
|
||||
await Task.Delay(150);
|
||||
}
|
||||
|
||||
BtnWhiteBoardAdd_Click(null, EventArgs.Empty);
|
||||
|
||||
await InsertBitmapSourceToCanvas(bitmapSourceForClipboard);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 提取公共的截图和保存逻辑
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user