improve:截图
This commit is contained in:
@@ -100,6 +100,46 @@ namespace Ink_Canvas
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 直接全屏截图并插入到画布
|
||||||
|
private async Task CaptureFullScreenAndInsert()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// 隐藏主窗口以避免截图包含窗口本身
|
||||||
|
var originalVisibility = Visibility;
|
||||||
|
Visibility = Visibility.Hidden;
|
||||||
|
|
||||||
|
// 等待窗口隐藏
|
||||||
|
await Task.Delay(200);
|
||||||
|
|
||||||
|
// 获取虚拟屏幕边界
|
||||||
|
var virtualScreen = SystemInformation.VirtualScreen;
|
||||||
|
var fullScreenArea = new Rectangle(virtualScreen.X, virtualScreen.Y, virtualScreen.Width, virtualScreen.Height);
|
||||||
|
|
||||||
|
// 截取全屏
|
||||||
|
using (var fullScreenBitmap = CaptureScreenArea(fullScreenArea))
|
||||||
|
{
|
||||||
|
if (fullScreenBitmap != null)
|
||||||
|
{
|
||||||
|
// 将截图转换为WPF Image并插入到画布
|
||||||
|
await InsertScreenshotToCanvas(fullScreenBitmap);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ShowNotification("全屏截图失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 恢复窗口显示
|
||||||
|
Visibility = originalVisibility;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
ShowNotification($"全屏截图失败: {ex.Message}");
|
||||||
|
Visibility = Visibility.Visible;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 显示截图区域选择器
|
// 显示截图区域选择器
|
||||||
private async Task<ScreenshotResult?> ShowScreenshotSelector()
|
private async Task<ScreenshotResult?> ShowScreenshotSelector()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -117,6 +117,15 @@
|
|||||||
BorderThickness="0"
|
BorderThickness="0"
|
||||||
FontWeight="Medium"
|
FontWeight="Medium"
|
||||||
Click="FreehandModeButton_Click" />
|
Click="FreehandModeButton_Click" />
|
||||||
|
<Button Name="FullScreenButton"
|
||||||
|
Content="全屏截图"
|
||||||
|
Margin="4,0"
|
||||||
|
Padding="12,6"
|
||||||
|
Background="#7c3aed"
|
||||||
|
Foreground="White"
|
||||||
|
BorderThickness="0"
|
||||||
|
FontWeight="Medium"
|
||||||
|
Click="FullScreenButton_Click" />
|
||||||
|
|
||||||
<!-- 分隔线 -->
|
<!-- 分隔线 -->
|
||||||
<Separator Style="{StaticResource {x:Static ToolBar.SeparatorStyleKey}}"
|
<Separator Style="{StaticResource {x:Static ToolBar.SeparatorStyleKey}}"
|
||||||
|
|||||||
@@ -146,6 +146,7 @@ namespace Ink_Canvas
|
|||||||
_isFreehandMode = false;
|
_isFreehandMode = false;
|
||||||
RectangleModeButton.Background = new SolidColorBrush(Color.FromRgb(37, 99, 235)); // 蓝色
|
RectangleModeButton.Background = new SolidColorBrush(Color.FromRgb(37, 99, 235)); // 蓝色
|
||||||
FreehandModeButton.Background = new SolidColorBrush(Color.FromRgb(107, 114, 128)); // 灰色
|
FreehandModeButton.Background = new SolidColorBrush(Color.FromRgb(107, 114, 128)); // 灰色
|
||||||
|
FullScreenButton.Background = new SolidColorBrush(Color.FromRgb(107, 114, 128)); // 灰色
|
||||||
HintText.Text = "拖拽鼠标选择矩形区域";
|
HintText.Text = "拖拽鼠标选择矩形区域";
|
||||||
HintText.Visibility = Visibility.Visible;
|
HintText.Visibility = Visibility.Visible;
|
||||||
}
|
}
|
||||||
@@ -158,10 +159,26 @@ namespace Ink_Canvas
|
|||||||
_isFreehandMode = true;
|
_isFreehandMode = true;
|
||||||
FreehandModeButton.Background = new SolidColorBrush(Color.FromRgb(37, 99, 235)); // 蓝色
|
FreehandModeButton.Background = new SolidColorBrush(Color.FromRgb(37, 99, 235)); // 蓝色
|
||||||
RectangleModeButton.Background = new SolidColorBrush(Color.FromRgb(107, 114, 128)); // 灰色
|
RectangleModeButton.Background = new SolidColorBrush(Color.FromRgb(107, 114, 128)); // 灰色
|
||||||
|
FullScreenButton.Background = new SolidColorBrush(Color.FromRgb(107, 114, 128)); // 灰色
|
||||||
HintText.Text = "按住鼠标左键绘制任意形状,松开直接截图";
|
HintText.Text = "按住鼠标左键绘制任意形状,松开直接截图";
|
||||||
HintText.Visibility = Visibility.Visible;
|
HintText.Visibility = Visibility.Visible;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void FullScreenButton_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
// 重置所有选择状态
|
||||||
|
ResetSelectionState();
|
||||||
|
|
||||||
|
// 设置全屏截图模式
|
||||||
|
_isFreehandMode = false;
|
||||||
|
FullScreenButton.Background = new SolidColorBrush(Color.FromRgb(37, 99, 235)); // 蓝色
|
||||||
|
RectangleModeButton.Background = new SolidColorBrush(Color.FromRgb(107, 114, 128)); // 灰色
|
||||||
|
FreehandModeButton.Background = new SolidColorBrush(Color.FromRgb(107, 114, 128)); // 灰色
|
||||||
|
|
||||||
|
// 直接执行全屏截图
|
||||||
|
PerformFullScreenCapture();
|
||||||
|
}
|
||||||
|
|
||||||
private void ConfirmButton_Click(object sender, RoutedEventArgs e)
|
private void ConfirmButton_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
// 在自由绘制模式下,确认按钮不执行任何操作
|
// 在自由绘制模式下,确认按钮不执行任何操作
|
||||||
@@ -786,6 +803,30 @@ namespace Ink_Canvas
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void PerformFullScreenCapture()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// 获取虚拟屏幕边界
|
||||||
|
var virtualScreen = SystemInformation.VirtualScreen;
|
||||||
|
|
||||||
|
// 设置全屏截图区域
|
||||||
|
SelectedArea = new DrawingRectangle(virtualScreen.X, virtualScreen.Y, virtualScreen.Width, virtualScreen.Height);
|
||||||
|
SelectedPath = null; // 全屏截图不需要路径
|
||||||
|
|
||||||
|
// 直接关闭窗口并返回结果
|
||||||
|
DialogResult = true;
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
// 如果全屏截图失败,记录错误并关闭窗口
|
||||||
|
System.Diagnostics.Debug.WriteLine($"全屏截图失败: {ex.Message}");
|
||||||
|
DialogResult = false;
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void ResetSelectionState()
|
private void ResetSelectionState()
|
||||||
{
|
{
|
||||||
// 重置所有选择相关的状态
|
// 重置所有选择相关的状态
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user