feat: add include-ink toggle for area screenshot selector

This commit is contained in:
tayasui rainnya!
2026-04-09 12:54:31 +08:00
parent 057fb35d00
commit 8b2bc352a6
4 changed files with 284 additions and 15 deletions
@@ -36,6 +36,13 @@
</Rectangle.Clip>
</Rectangle>
<!-- 墨迹预览层(用于“包含墨迹”预览) -->
<Image Name="InkPreviewImage"
Stretch="Fill"
IsHitTestVisible="False"
Visibility="Collapsed"
Panel.ZIndex="950" />
<!-- 选择区域容器 -->
<Canvas Name="SelectionCanvas" Panel.ZIndex="1000">
<!-- 矩形选择模式 -->
@@ -141,6 +148,17 @@
Background="#404040" />
<!-- 操作按钮 -->
<CheckBox Name="IncludeInkCheckBox"
Content="包含墨迹"
Margin="4,0"
VerticalAlignment="Center"
Foreground="White"
Checked="IncludeInkCheckBox_Checked"
Unchecked="IncludeInkCheckBox_Unchecked" />
<Rectangle Width="1"
Height="20"
Fill="#404040"
Margin="8,0" />
<Button Name="ConfirmButton"
Content="确认截图"
Margin="4,0"
@@ -7,6 +7,7 @@ using System.Windows.Controls;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Threading;
using Brushes = System.Windows.Media.Brushes;
@@ -37,6 +38,7 @@ namespace Ink_Canvas
private Bitmap _capturedCameraImage = null;
private DateTime _lastBlankClickTime = DateTime.MinValue;
private WpfPoint _lastBlankClickPosition;
private readonly BitmapSource _inkOverlayPreview;
private const int DoubleClickTimeThresholdMs = 300; // 双击判定时间阈值(常见范围 200~500ms)
private const double DoubleClickDistanceThresholdPx = 12; // 双击判定位置阈值(像素)
@@ -55,9 +57,11 @@ namespace Ink_Canvas
public Bitmap CameraImage { get; private set; }
public System.Windows.Media.Imaging.BitmapSource CameraBitmapSource { get; private set; }
public bool ShouldAddToWhiteboard { get; private set; }
public bool IncludeInkInScreenshot { get; private set; }
public ScreenshotSelectorWindow()
public ScreenshotSelectorWindow(BitmapSource inkOverlayPreview = null)
{
_inkOverlayPreview = inkOverlayPreview;
InitializeComponent();
// 设置窗口覆盖所有屏幕
@@ -71,6 +75,7 @@ namespace Ink_Canvas
// 初始化按钮状态
InitializeButtonStates();
InitializeInkPreview();
// 初始化摄像头服务
InitializeCameraService();
@@ -106,6 +111,44 @@ namespace Ink_Canvas
CameraModeButton.Background = new SolidColorBrush(Color.FromRgb(107, 114, 128)); // 灰色
}
private void InitializeInkPreview()
{
IncludeInkInScreenshot = false;
IncludeInkCheckBox.IsChecked = false;
if (_inkOverlayPreview != null)
{
InkPreviewImage.Source = _inkOverlayPreview;
}
else
{
IncludeInkCheckBox.IsEnabled = false;
IncludeInkCheckBox.Opacity = 0.6;
IncludeInkCheckBox.ToolTip = "当前无可预览墨迹";
}
UpdateInkPreviewVisibility();
}
private void IncludeInkCheckBox_Checked(object sender, RoutedEventArgs e)
{
IncludeInkInScreenshot = true;
UpdateInkPreviewVisibility();
}
private void IncludeInkCheckBox_Unchecked(object sender, RoutedEventArgs e)
{
IncludeInkInScreenshot = false;
UpdateInkPreviewVisibility();
}
private void UpdateInkPreviewVisibility()
{
InkPreviewImage.Visibility = IncludeInkInScreenshot && _inkOverlayPreview != null
? Visibility.Visible
: Visibility.Collapsed;
}
private void InitializeCameraService()
{
try
@@ -370,6 +413,7 @@ namespace Ink_Canvas
RectangleModeButton.Background = new SolidColorBrush(Color.FromRgb(37, 99, 235)); // 蓝色
FreehandModeButton.Background = new SolidColorBrush(Color.FromRgb(107, 114, 128)); // 灰色
FullScreenButton.Background = new SolidColorBrush(Color.FromRgb(107, 114, 128)); // 灰色
IncludeInkCheckBox.IsEnabled = _inkOverlayPreview != null;
HintText.Text = "拖拽鼠标选择矩形区域";
HintTextBorder.Visibility = Visibility.Visible;
}
@@ -383,6 +427,7 @@ namespace Ink_Canvas
FreehandModeButton.Background = new SolidColorBrush(Color.FromRgb(37, 99, 235)); // 蓝色
RectangleModeButton.Background = new SolidColorBrush(Color.FromRgb(107, 114, 128)); // 灰色
FullScreenButton.Background = new SolidColorBrush(Color.FromRgb(107, 114, 128)); // 灰色
IncludeInkCheckBox.IsEnabled = _inkOverlayPreview != null;
HintText.Text = "按住鼠标左键自由绘制,松开后可继续调整或重新绘制,确认后再截图";
HintTextBorder.Visibility = Visibility.Visible;
}
@@ -402,6 +447,7 @@ namespace Ink_Canvas
// 隐藏摄像头预览
CameraPreviewBorder.Visibility = Visibility.Collapsed;
IncludeInkCheckBox.IsEnabled = _inkOverlayPreview != null;
// 直接执行全屏截图
PerformFullScreenCapture();
@@ -426,6 +472,8 @@ namespace Ink_Canvas
CameraPreviewBorder.Visibility = Visibility.Visible;
HintText.Text = "摄像头预览模式,点击确认截图按钮进行截图";
HintTextBorder.Visibility = Visibility.Visible;
IncludeInkCheckBox.IsEnabled = false;
IncludeInkCheckBox.IsChecked = false;
// 启动摄像头预览
if (_cameraService != null && _cameraService.HasAvailableCameras())
@@ -491,6 +539,7 @@ namespace Ink_Canvas
private void ConfirmButton_Click(object sender, RoutedEventArgs e)
{
ShouldAddToWhiteboard = false;
IncludeInkInScreenshot = IncludeInkCheckBox.IsChecked == true;
// 在自由绘制模式下,按当前自由选区执行确认
if (_isFreehandMode)
@@ -512,6 +561,7 @@ namespace Ink_Canvas
private void AddToWhiteboardButton_Click(object sender, RoutedEventArgs e)
{
ShouldAddToWhiteboard = true;
IncludeInkInScreenshot = IncludeInkCheckBox.IsChecked == true;
// 在自由绘制模式下,按当前自由选区执行确认
if (_isFreehandMode)
@@ -1178,6 +1228,7 @@ namespace Ink_Canvas
SelectedPath = null;
CameraImage = null;
ShouldAddToWhiteboard = false;
IncludeInkInScreenshot = false;
DialogResult = false;
Close();
}