improve:截图及浮动栏及代码优化

This commit is contained in:
2025-08-31 09:54:13 +08:00
parent 33948c604c
commit 9bb00489fe
57 changed files with 887 additions and 413 deletions
+11 -11
View File
@@ -1,8 +1,3 @@
using Hardcodet.Wpf.TaskbarNotification;
using Ink_Canvas.Helpers;
using iNKORE.UI.WPF.Modern.Controls;
using Microsoft.Win32;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
@@ -18,6 +13,11 @@ using System.Windows;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Threading;
using Hardcodet.Wpf.TaskbarNotification;
using Ink_Canvas.Helpers;
using iNKORE.UI.WPF.Modern.Controls;
using Microsoft.Win32;
using Newtonsoft.Json;
using Application = System.Windows.Application;
using MessageBox = System.Windows.MessageBox;
using Timer = System.Threading.Timer;
@@ -353,18 +353,18 @@ namespace Ink_Canvas
{
return $"{timeSpan.Days}天 {timeSpan.Hours}小时 {timeSpan.Minutes}分钟";
}
else if (timeSpan.TotalHours >= 1)
if (timeSpan.TotalHours >= 1)
{
return $"{timeSpan.Hours}小时 {timeSpan.Minutes}分钟";
}
else if (timeSpan.TotalMinutes >= 1)
if (timeSpan.TotalMinutes >= 1)
{
return $"{timeSpan.Minutes}分钟 {timeSpan.Seconds}秒";
}
else
{
return $"{timeSpan.Seconds}秒";
}
return $"{timeSpan.Seconds}秒";
}
// 新增:记录崩溃日志
@@ -4,10 +4,10 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Threading;
using System.Windows;
namespace Ink_Canvas.Helpers
{
+7 -9
View File
@@ -1,5 +1,3 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
@@ -17,6 +15,8 @@ using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace Ink_Canvas.Helpers
{
@@ -1361,16 +1361,14 @@ namespace Ink_Canvas.Helpers
if (oldProcessId > 0 && !string.IsNullOrEmpty(extractPath) && !string.IsNullOrEmpty(targetPath))
{
LogHelper.WriteLogToFile($"AutoUpdate | 参数验证通过,启动更新任务");
LogHelper.WriteLogToFile("AutoUpdate | 参数验证通过,启动更新任务");
// 启动更新任务
Task.Run(async () => await PerformUpdate(oldProcessId, extractPath, targetPath, isSilence));
return true; // 返回true表示是更新模式
}
else
{
LogHelper.WriteLogToFile($"AutoUpdate | 参数验证失败 - 老进程ID: {oldProcessId}, 解压路径: {extractPath}, 目标路径: {targetPath}", LogHelper.LogType.Error);
return false;
}
LogHelper.WriteLogToFile($"AutoUpdate | 参数验证失败 - 老进程ID: {oldProcessId}, 解压路径: {extractPath}, 目标路径: {targetPath}", LogHelper.LogType.Error);
return false;
}
return false; // 返回false表示不是更新模式
}
@@ -1483,7 +1481,7 @@ namespace Ink_Canvas.Helpers
}
// 删除ZIP文件
string zipFile = Path.Combine(updatesFolderPath, $"InkCanvasForClass.CE.*.zip");
string zipFile = Path.Combine(updatesFolderPath, "InkCanvasForClass.CE.*.zip");
string[] zipFiles = Directory.GetFiles(updatesFolderPath, "InkCanvasForClass.CE.*.zip");
foreach (string zip in zipFiles)
{
+1 -1
View File
@@ -1,4 +1,3 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
@@ -6,6 +5,7 @@ using System.Linq;
using System.Reflection;
using System.Security.Cryptography;
using System.Text;
using Newtonsoft.Json;
namespace Ink_Canvas.Helpers
{
+7 -6
View File
@@ -1,8 +1,9 @@
using System;
using System.Collections.Generic;
using System.Windows.Input;
using System.IO;
using System.Reflection;
using System.Text;
using System.Windows.Input;
using Newtonsoft.Json;
using NHotkey.Wpf;
@@ -16,7 +17,7 @@ namespace Ink_Canvas.Helpers
#region Private Fields
private readonly Dictionary<string, HotkeyInfo> _registeredHotkeys;
private readonly MainWindow _mainWindow;
private bool _isDisposed = false;
private bool _isDisposed;
private bool _hotkeysShouldBeRegistered = true; // 启动时注册热键
// 配置文件路径
@@ -180,7 +181,7 @@ namespace Ink_Canvas.Helpers
}
// 读取配置文件内容
string jsonContent = File.ReadAllText(HotkeyConfigFile, System.Text.Encoding.UTF8);
string jsonContent = File.ReadAllText(HotkeyConfigFile, Encoding.UTF8);
if (string.IsNullOrEmpty(jsonContent))
{
LogHelper.WriteLogToFile("快捷键配置文件为空", LogHelper.LogType.Warning);
@@ -509,7 +510,7 @@ namespace Ink_Canvas.Helpers
}
// 读取配置文件内容
string jsonContent = File.ReadAllText(HotkeyConfigFile, System.Text.Encoding.UTF8);
string jsonContent = File.ReadAllText(HotkeyConfigFile, Encoding.UTF8);
if (string.IsNullOrEmpty(jsonContent))
{
LogHelper.WriteLogToFile("快捷键配置文件为空", LogHelper.LogType.Warning);
@@ -607,7 +608,7 @@ namespace Ink_Canvas.Helpers
string jsonContent = JsonConvert.SerializeObject(config, settings);
// 直接写入原文件,覆盖原有内容
File.WriteAllText(HotkeyConfigFile, jsonContent, System.Text.Encoding.UTF8);
File.WriteAllText(HotkeyConfigFile, jsonContent, Encoding.UTF8);
LogHelper.WriteLogToFile($"快捷键配置已保存到: {HotkeyConfigFile}", LogHelper.LogType.Event);
return true;
@@ -714,7 +715,7 @@ namespace Ink_Canvas.Helpers
var getLeftMethod = canvasType.GetMethod("GetLeft", BindingFlags.Public | BindingFlags.Static);
if (getLeftMethod != null)
{
var leftPosition = getLeftMethod.Invoke(null, new object[] { floatingbarSelectionBG });
var leftPosition = getLeftMethod.Invoke(null, new[] { floatingbarSelectionBG });
if (leftPosition != null)
{
var position = Convert.ToDouble(leftPosition);
+4 -4
View File
@@ -1,13 +1,13 @@
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Media.Animation;
using System.Windows.Threading;
using System.Windows.Ink;
using System.Windows.Controls;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Threading;
namespace Ink_Canvas.Helpers
{
@@ -20,7 +20,7 @@ namespace Ink_Canvas.Helpers
/// <summary>
/// 是否启用墨迹渐隐功能
/// </summary>
public bool IsEnabled { get; set; } = false;
public bool IsEnabled { get; set; }
/// <summary>
/// 墨迹渐隐时间(毫秒)
+3 -2
View File
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
namespace Ink_Canvas.Helpers
{
@@ -63,7 +64,7 @@ namespace Ink_Canvas.Helpers
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"加载平滑配置失败: {ex.Message}");
Debug.WriteLine($"加载平滑配置失败: {ex.Message}");
}
return config;
@@ -124,7 +125,7 @@ namespace Ink_Canvas.Helpers
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"保存平滑配置失败: {ex.Message}");
Debug.WriteLine($"保存平滑配置失败: {ex.Message}");
}
}
+3 -3
View File
@@ -1,9 +1,9 @@
using Microsoft.Office.Interop.PowerPoint;
using System;
using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
using System.Windows.Ink;
using Microsoft.Office.Interop.PowerPoint;
namespace Ink_Canvas.Helpers
{
@@ -23,7 +23,7 @@ namespace Ink_Canvas.Helpers
private int _maxSlides = 100;
private string _currentPresentationId = "";
private readonly object _lockObject = new object();
private bool _disposed = false;
private bool _disposed;
// 墨迹锁定机制,防止翻页时的墨迹冲突
private DateTime _inkLockUntil = DateTime.MinValue;
+7 -9
View File
@@ -1,5 +1,4 @@
using Microsoft.Office.Interop.PowerPoint;
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
@@ -8,6 +7,7 @@ using System.Text;
using System.Threading;
using System.Timers;
using System.Windows.Threading;
using Microsoft.Office.Interop.PowerPoint;
using Application = System.Windows.Application;
using Timer = System.Timers.Timer;
@@ -101,9 +101,9 @@ namespace Ink_Canvas.Helpers
private int _wpsProcessCheckCount;
private WpsWindowInfo _lastForegroundWpsWindow;
private DateTime _lastWindowCheckTime = DateTime.MinValue;
private bool _lastSlideShowState = false;
private bool _lastSlideShowState;
private readonly object _lockObject = new object();
private bool _disposed = false;
private bool _disposed;
#endregion
#region Constructor & Initialization
@@ -888,11 +888,9 @@ namespace Ink_Canvas.Helpers
LogHelper.WriteLogToFile("成功显示幻灯片导航(PowerPoint模式)", LogHelper.LogType.Event);
return true;
}
else
{
LogHelper.WriteLogToFile("SlideNavigation对象为空,可能是WPS不支持此功能", LogHelper.LogType.Warning);
return false;
}
LogHelper.WriteLogToFile("SlideNavigation对象为空,可能是WPS不支持此功能", LogHelper.LogType.Warning);
return false;
}
catch (COMException comEx)
{
@@ -1,9 +1,9 @@
using iNKORE.UI.WPF.Modern.Controls;
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using iNKORE.UI.WPF.Modern.Controls;
namespace Ink_Canvas.Helpers.Plugins.BuiltIn.SuperLauncher
{
@@ -1,5 +1,3 @@
using Microsoft.Win32;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
@@ -10,6 +8,8 @@ using System.Windows;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Microsoft.Win32;
using Newtonsoft.Json;
namespace Ink_Canvas.Helpers.Plugins.BuiltIn.SuperLauncher
{
@@ -1,10 +1,10 @@
using Ink_Canvas.Windows;
using Microsoft.Win32;
using System;
using System.ComponentModel;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using Ink_Canvas.Windows;
using Microsoft.Win32;
namespace Ink_Canvas.Helpers.Plugins.BuiltIn.SuperLauncher
{
@@ -1,5 +1,3 @@
using Ink_Canvas.Helpers.Plugins.BuiltIn.SuperLauncher;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
@@ -7,6 +5,8 @@ using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using Ink_Canvas.Helpers.Plugins.BuiltIn.SuperLauncher;
using Newtonsoft.Json;
namespace Ink_Canvas.Helpers.Plugins.BuiltIn
{
@@ -1,8 +1,8 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Newtonsoft.Json;
namespace Ink_Canvas.Helpers.Plugins
{
@@ -46,17 +46,15 @@ namespace Ink_Canvas.Helpers.Plugins
{
return typedValue;
}
else
// 尝试类型转换
try
{
// 尝试类型转换
try
{
return (T)Convert.ChangeType(value, typeof(T));
}
catch
{
return defaultValue;
}
return (T)Convert.ChangeType(value, typeof(T));
}
catch
{
return defaultValue;
}
}
}
+2 -2
View File
@@ -1,5 +1,3 @@
using Ink_Canvas.Windows;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
@@ -10,6 +8,8 @@ using System.Security.Cryptography;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using Ink_Canvas.Windows;
using Newtonsoft.Json;
using Timer = System.Timers.Timer;
namespace Ink_Canvas.Helpers.Plugins
@@ -1,9 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Linq;
namespace Ink_Canvas.Helpers.Plugins
{
+2 -2
View File
@@ -1,8 +1,8 @@
using Microsoft.Win32;
using System;
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using Microsoft.Win32;
namespace Ink_Canvas.Helpers
{
+8 -8
View File
@@ -1,9 +1,3 @@
using Ink_Canvas.Helpers;
using Ink_Canvas.Helpers.Plugins;
using Ink_Canvas.Windows;
using iNKORE.UI.WPF.Modern;
using iNKORE.UI.WPF.Modern.Controls;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@@ -22,6 +16,12 @@ using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Threading;
using Ink_Canvas.Helpers;
using Ink_Canvas.Helpers.Plugins;
using Ink_Canvas.Windows;
using iNKORE.UI.WPF.Modern;
using iNKORE.UI.WPF.Modern.Controls;
using Microsoft.Win32;
using Application = System.Windows.Application;
using Brushes = System.Windows.Media.Brushes;
using Button = System.Windows.Controls.Button;
@@ -1689,7 +1689,7 @@ namespace Ink_Canvas
// 添加定时器来维护置顶状态
private DispatcherTimer topmostMaintenanceTimer;
private bool isTopmostMaintenanceEnabled = false;
private bool isTopmostMaintenanceEnabled;
private void ApplyNoFocusMode()
{
@@ -1753,7 +1753,7 @@ namespace Ink_Canvas
// 注意:这里不直接设置Topmost,让其他代码根据模式决定
// 添加调试日志
LogHelper.WriteLogToFile($"应用窗口置顶: 取消置顶", LogHelper.LogType.Trace);
LogHelper.WriteLogToFile("应用窗口置顶: 取消置顶", LogHelper.LogType.Trace);
}
}
catch (Exception ex)
+7 -7
View File
@@ -1,6 +1,4 @@
using Ink_Canvas.Helpers;
using iNKORE.UI.WPF.Modern;
using System;
using System;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
@@ -8,6 +6,8 @@ using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using Ink_Canvas.Helpers;
using iNKORE.UI.WPF.Modern;
namespace Ink_Canvas
{
@@ -263,10 +263,10 @@ namespace Ink_Canvas
{
var dops = Settings.PowerPointSettings.PPTButtonsDisplayOption.ToString();
var dopsc = dops.ToCharArray();
if (dopsc[0] == '2' && isDisplayingOrHidingBlackboard == false) AnimationsHelper.ShowWithFadeIn(LeftBottomPanelForPPTNavigation);
if (dopsc[1] == '2' && isDisplayingOrHidingBlackboard == false) AnimationsHelper.ShowWithFadeIn(RightBottomPanelForPPTNavigation);
if (dopsc[2] == '2' && isDisplayingOrHidingBlackboard == false) AnimationsHelper.ShowWithFadeIn(LeftSidePanelForPPTNavigation);
if (dopsc[3] == '2' && isDisplayingOrHidingBlackboard == false) AnimationsHelper.ShowWithFadeIn(RightSidePanelForPPTNavigation);
if (dopsc[0] == '2' && !isDisplayingOrHidingBlackboard) AnimationsHelper.ShowWithFadeIn(LeftBottomPanelForPPTNavigation);
if (dopsc[1] == '2' && !isDisplayingOrHidingBlackboard) AnimationsHelper.ShowWithFadeIn(RightBottomPanelForPPTNavigation);
if (dopsc[2] == '2' && !isDisplayingOrHidingBlackboard) AnimationsHelper.ShowWithFadeIn(LeftSidePanelForPPTNavigation);
if (dopsc[3] == '2' && !isDisplayingOrHidingBlackboard) AnimationsHelper.ShowWithFadeIn(RightSidePanelForPPTNavigation);
}
if (BtnPPTSlideShowEnd.Visibility == Visibility.Visible)
+2 -2
View File
@@ -1,6 +1,6 @@
using IWshRuntimeLibrary;
using System;
using System;
using System.Windows;
using IWshRuntimeLibrary;
using Application = System.Windows.Forms.Application;
using File = System.IO.File;
+3 -3
View File
@@ -1,8 +1,8 @@
using iNKORE.UI.WPF.Modern;
using Microsoft.Win32;
using System;
using System;
using System.Windows;
using System.Windows.Media;
using iNKORE.UI.WPF.Modern;
using Microsoft.Win32;
using Application = System.Windows.Application;
namespace Ink_Canvas
+2 -2
View File
@@ -1,5 +1,4 @@
using Ink_Canvas.Helpers;
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;
@@ -7,6 +6,7 @@ using System.Windows;
using System.Windows.Controls;
using System.Windows.Ink;
using System.Windows.Media;
using Ink_Canvas.Helpers;
namespace Ink_Canvas
{
+3 -3
View File
@@ -1,5 +1,4 @@
using Ink_Canvas.Helpers;
using System;
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
@@ -7,6 +6,7 @@ using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Ink_Canvas.Helpers;
namespace Ink_Canvas
{
@@ -766,7 +766,7 @@ namespace Ink_Canvas
{
PenIcon_Click(null, null);
SymbolIconDelete_MouseUp(null, null);
if (Settings.Canvas.ClearCanvasAndClearTimeMachine == false) timeMachine.ClearStrokeHistory();
if (!Settings.Canvas.ClearCanvasAndClearTimeMachine) timeMachine.ClearStrokeHistory();
// 根据设置决定是否清空图片
if (Settings.Canvas.ClearCanvasAlsoClearImages)
+18 -11
View File
@@ -1,19 +1,26 @@
using Ink_Canvas.Helpers;
using System;
using System;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Forms;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Media;
using System.Windows.Threading;
using Ink_Canvas.Helpers;
using Clipboard = System.Windows.Clipboard;
using ContextMenu = System.Windows.Controls.ContextMenu;
using Cursors = System.Windows.Input.Cursors;
using MenuItem = System.Windows.Controls.MenuItem;
namespace Ink_Canvas
{
public partial class MainWindow : Window
{
private bool isClipboardMonitoringEnabled = false;
private BitmapSource lastClipboardImage = null;
private bool isClipboardMonitoringEnabled;
private BitmapSource lastClipboardImage;
// 初始化剪贴板监控
private void InitializeClipboardMonitoring()
@@ -92,7 +99,7 @@ namespace Ink_Canvas
// 显示菜单
contextMenu.IsOpen = true;
contextMenu.PlacementTarget = inkCanvas;
contextMenu.Placement = System.Windows.Controls.Primitives.PlacementMode.MousePoint;
contextMenu.Placement = PlacementMode.MousePoint;
}
catch (Exception ex)
{
@@ -124,7 +131,7 @@ namespace Ink_Canvas
Source = clipboardImage,
Width = clipboardImage.PixelWidth,
Height = clipboardImage.PixelHeight,
Stretch = System.Windows.Media.Stretch.Fill
Stretch = Stretch.Fill
};
// 生成唯一名称
@@ -192,7 +199,7 @@ namespace Ink_Canvas
// 设置光标
elementForEvents.Cursor = Cursors.Hand;
}
}), System.Windows.Threading.DispatcherPriority.Loaded);
}), DispatcherPriority.Loaded);
};
// 提交到历史记录
@@ -272,13 +279,13 @@ namespace Ink_Canvas
{
public static event Action ClipboardUpdate;
private static System.Windows.Forms.Timer clipboardTimer;
private static Timer clipboardTimer;
private static string lastClipboardText = "";
private static bool lastHadImage = false;
private static bool lastHadImage;
static ClipboardNotification()
{
clipboardTimer = new System.Windows.Forms.Timer();
clipboardTimer = new Timer();
clipboardTimer.Interval = 500; // 每500ms检查一次
clipboardTimer.Tick += CheckClipboard;
clipboardTimer.Start();
+2 -2
View File
@@ -1,5 +1,4 @@
using Ink_Canvas.Helpers;
using System;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Windows;
@@ -9,6 +8,7 @@ using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using Ink_Canvas.Helpers;
namespace Ink_Canvas
{
+26 -26
View File
@@ -1,15 +1,17 @@
using Microsoft.Win32;
using System;
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Threading;
using Ink_Canvas.Helpers;
using System.Windows.Input;
using System.Linq;
using System.Windows.Ink;
using Microsoft.Win32;
namespace Ink_Canvas
{
@@ -17,7 +19,7 @@ namespace Ink_Canvas
{
// 当前选中的可操作元素
private FrameworkElement currentSelectedElement;
private bool isDragging = false;
private bool isDragging;
private Point dragStartPoint;
#region Image
@@ -62,7 +64,7 @@ namespace Ink_Canvas
BindElementEvents(image);
LogHelper.WriteLogToFile($"图片插入完成: {image.Name}");
}), System.Windows.Threading.DispatcherPriority.Loaded);
}), DispatcherPriority.Loaded);
};
timeMachine.CommitElementInsertHistory(image);
@@ -396,7 +398,7 @@ namespace Ink_Canvas
}
// 保存初始变换状态用于历史记录
var initialTransform = transformGroup.Clone() as TransformGroup;
var initialTransform = transformGroup.Clone();
// 创建新的 TransformGroup 并添加 MatrixTransform
var newTransformGroup = new TransformGroup();
@@ -719,7 +721,7 @@ namespace Ink_Canvas
catch (Exception ex)
{
// 记录错误但不中断程序
System.Diagnostics.Debug.WriteLine($"旋转图片时发生错误: {ex.Message}");
Debug.WriteLine($"旋转图片时发生错误: {ex.Message}");
}
}
@@ -740,7 +742,7 @@ namespace Ink_Canvas
Width = image.Width,
Height = image.Height,
Stretch = image.Stretch,
RenderTransform = image.RenderTransform?.Clone() as Transform
RenderTransform = image.RenderTransform?.Clone()
};
// 设置位置,稍微偏移以避免重叠
@@ -790,7 +792,7 @@ namespace Ink_Canvas
Width = image.Width,
Height = image.Height,
Stretch = image.Stretch,
RenderTransform = image.RenderTransform?.Clone() as Transform
RenderTransform = image.RenderTransform?.Clone()
};
// 设置位置,稍微偏移以避免重叠
@@ -809,7 +811,7 @@ namespace Ink_Canvas
catch (Exception ex)
{
// 记录错误但不中断程序
System.Diagnostics.Debug.WriteLine($"克隆图片到新页面时发生错误: {ex.Message}");
Debug.WriteLine($"克隆图片到新页面时发生错误: {ex.Message}");
}
}
@@ -862,7 +864,7 @@ namespace Ink_Canvas
catch (Exception ex)
{
// 记录错误但不中断程序
System.Diagnostics.Debug.WriteLine($"缩放图片时发生错误: {ex.Message}");
Debug.WriteLine($"缩放图片时发生错误: {ex.Message}");
}
}
@@ -888,7 +890,7 @@ namespace Ink_Canvas
catch (Exception ex)
{
// 记录错误但不中断程序
System.Diagnostics.Debug.WriteLine($"删除图片时发生错误: {ex.Message}");
Debug.WriteLine($"删除图片时发生错误: {ex.Message}");
}
}
@@ -907,7 +909,7 @@ namespace Ink_Canvas
Dispatcher.BeginInvoke(new Action(() =>
{
CenterAndScaleElement(element);
}), System.Windows.Threading.DispatcherPriority.Loaded);
}), DispatcherPriority.Loaded);
};
return;
}
@@ -919,8 +921,8 @@ namespace Ink_Canvas
// 如果画布尺寸为0,使用窗口尺寸作为备选
if (canvasWidth <= 0 || canvasHeight <= 0)
{
canvasWidth = this.ActualWidth;
canvasHeight = this.ActualHeight;
canvasWidth = ActualWidth;
canvasHeight = ActualHeight;
}
// 如果仍然为0,使用屏幕尺寸
@@ -1058,11 +1060,9 @@ namespace Ink_Canvas
return new Rect(left, top, width, height);
}
}
else
{
// 没有变换时直接使用位置和大小
return new Rect(left, top, width, height);
}
// 没有变换时直接使用位置和大小
return new Rect(left, top, width, height);
}
catch (Exception ex)
{
@@ -1165,7 +1165,7 @@ namespace Ink_Canvas
UpdateImageSelectionToolbarPosition(currentSelectedElement);
}
LogHelper.WriteLogToFile($"图片左旋转完成");
LogHelper.WriteLogToFile("图片左旋转完成");
}
}
catch (Exception ex)
@@ -1189,7 +1189,7 @@ namespace Ink_Canvas
UpdateImageSelectionToolbarPosition(currentSelectedElement);
}
LogHelper.WriteLogToFile($"图片右旋转完成");
LogHelper.WriteLogToFile("图片右旋转完成");
}
}
catch (Exception ex)
@@ -1214,7 +1214,7 @@ namespace Ink_Canvas
UpdateImageSelectionToolbarPosition(currentSelectedElement);
}
LogHelper.WriteLogToFile($"图片缩放减小完成");
LogHelper.WriteLogToFile("图片缩放减小完成");
}
}
catch (Exception ex)
@@ -1239,7 +1239,7 @@ namespace Ink_Canvas
UpdateImageSelectionToolbarPosition(currentSelectedElement);
}
LogHelper.WriteLogToFile($"图片缩放增大完成");
LogHelper.WriteLogToFile("图片缩放增大完成");
}
}
catch (Exception ex)
+2 -2
View File
@@ -1,5 +1,4 @@
using Ink_Canvas.Helpers;
using System;
using System;
using System.Diagnostics;
using System.Linq;
using System.Windows;
@@ -7,6 +6,7 @@ using System.Windows.Controls;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using Ink_Canvas.Helpers;
namespace Ink_Canvas
{
+41 -16
View File
@@ -1,5 +1,3 @@
using Ink_Canvas.Helpers;
using iNKORE.UI.WPF.Modern;
using System;
using System.Diagnostics;
using System.Threading;
@@ -13,6 +11,8 @@ using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using Ink_Canvas.Helpers;
using iNKORE.UI.WPF.Modern;
using Application = System.Windows.Application;
using Button = System.Windows.Controls.Button;
using Cursors = System.Windows.Input.Cursors;
@@ -641,6 +641,9 @@ namespace Ink_Canvas
ICCWaterMarkWhite.Visibility = Visibility.Visible;
ICCWaterMarkDark.Visibility = Visibility.Collapsed;
}
// 新增:确保在白板模式下基础浮动栏被隐藏
ViewboxFloatingBar.Visibility = Visibility.Collapsed;
}
else
{
@@ -651,10 +654,10 @@ namespace Ink_Canvas
{
var dops = Settings.PowerPointSettings.PPTButtonsDisplayOption.ToString();
var dopsc = dops.ToCharArray();
if (dopsc[0] == '2' && isDisplayingOrHidingBlackboard == false) AnimationsHelper.ShowWithFadeIn(LeftBottomPanelForPPTNavigation);
if (dopsc[1] == '2' && isDisplayingOrHidingBlackboard == false) AnimationsHelper.ShowWithFadeIn(RightBottomPanelForPPTNavigation);
if (dopsc[2] == '2' && isDisplayingOrHidingBlackboard == false) AnimationsHelper.ShowWithFadeIn(LeftSidePanelForPPTNavigation);
if (dopsc[3] == '2' && isDisplayingOrHidingBlackboard == false) AnimationsHelper.ShowWithFadeIn(RightSidePanelForPPTNavigation);
if (dopsc[0] == '2' && !isDisplayingOrHidingBlackboard) AnimationsHelper.ShowWithFadeIn(LeftBottomPanelForPPTNavigation);
if (dopsc[1] == '2' && !isDisplayingOrHidingBlackboard) AnimationsHelper.ShowWithFadeIn(RightBottomPanelForPPTNavigation);
if (dopsc[2] == '2' && !isDisplayingOrHidingBlackboard) AnimationsHelper.ShowWithFadeIn(LeftSidePanelForPPTNavigation);
if (dopsc[3] == '2' && !isDisplayingOrHidingBlackboard) AnimationsHelper.ShowWithFadeIn(RightSidePanelForPPTNavigation);
}
// 修复PPT放映时点击白板按钮后翻页按钮不显示的问题
if (BtnPPTSlideShowEnd.Visibility == Visibility.Visible)
@@ -693,6 +696,9 @@ namespace Ink_Canvas
BlackBoardWaterMark.Visibility = Visibility.Collapsed;
ICCWaterMarkDark.Visibility = Visibility.Collapsed;
ICCWaterMarkWhite.Visibility = Visibility.Collapsed;
// 新增:退出白板模式时恢复基础浮动栏的显示
ViewboxFloatingBar.Visibility = Visibility.Visible;
}
BtnSwitch_Click(BtnSwitch, null);
@@ -1295,7 +1301,7 @@ namespace Ink_Canvas
if (MarginFromEdge == 60) MarginFromEdge = 55;
await Dispatcher.InvokeAsync(() =>
{
if (Topmost == false)
if (!Topmost)
MarginFromEdge = -60;
else
ViewboxFloatingBar.Visibility = Visibility.Visible;
@@ -1337,7 +1343,7 @@ namespace Ink_Canvas
pos.X = (screenWidth - floatingBarWidth) / 2;
if (PosXCaculatedWithTaskbarHeight == false)
if (!PosXCaculatedWithTaskbarHeight)
{
// 如果任务栏高度为0(隐藏状态),则使用固定边距
if (toolbarHeight == 0)
@@ -1405,7 +1411,7 @@ namespace Ink_Canvas
await Dispatcher.InvokeAsync(() =>
{
ViewboxFloatingBar.Margin = new Thickness(pos.X, pos.Y, -2000, -200);
if (Topmost == false) ViewboxFloatingBar.Visibility = Visibility.Hidden;
if (!Topmost) ViewboxFloatingBar.Visibility = Visibility.Hidden;
});
}
@@ -2560,6 +2566,9 @@ namespace Ink_Canvas
ClearStrokes(true);
RestoreStrokes(true);
// 新增:在屏幕模式下恢复基础浮动栏的显示
ViewboxFloatingBar.Visibility = Visibility.Visible;
if (BtnSwitchTheme.Content.ToString() == "浅色")
{
BtnSwitch.Content = "黑板";
@@ -2598,6 +2607,9 @@ namespace Ink_Canvas
// PPT墨迹和白板墨迹应该分别管理,不应该互相影响
RestoreStrokes();
// 新增:在白板模式下隐藏基础浮动栏
ViewboxFloatingBar.Visibility = Visibility.Collapsed;
BtnSwitch.Content = "屏幕";
if (BtnSwitchTheme.Content.ToString() == "浅色")
{
@@ -2737,11 +2749,23 @@ namespace Ink_Canvas
StackPanelCanvasControls.Visibility = Visibility.Collapsed;
CheckEnableTwoFingerGestureBtnVisibility(false);
HideSubPanels("cursor");
// 新增:在屏幕模式下显示基础浮动栏
if (currentMode == 0)
{
ViewboxFloatingBar.Visibility = Visibility.Visible;
}
}
else
{
AnimationsHelper.ShowWithSlideFromLeftAndFade(StackPanelCanvasControls);
CheckEnableTwoFingerGestureBtnVisibility(true);
// 新增:在批注模式下显示基础浮动栏
if (currentMode == 0)
{
ViewboxFloatingBar.Visibility = Visibility.Visible;
}
}
}
@@ -3224,26 +3248,27 @@ namespace Ink_Canvas
{
return "select";
}
else if (inkCanvas.EditingMode == InkCanvasEditingMode.Ink)
if (inkCanvas.EditingMode == InkCanvasEditingMode.Ink)
{
// 检查是否是荧光笔模式
if (drawingAttributes != null && drawingAttributes.IsHighlighter)
{
return "color";
}
else
{
return "pen";
}
return "pen";
}
else if (inkCanvas.EditingMode == InkCanvasEditingMode.EraseByPoint)
if (inkCanvas.EditingMode == InkCanvasEditingMode.EraseByPoint)
{
// 检查是面积擦还是线擦
if (Eraser_Icon != null && Eraser_Icon.Visibility == Visibility.Visible)
{
return "eraser";
}
else if (EraserByStrokes_Icon != null && EraserByStrokes_Icon.Visibility == Visibility.Visible)
if (EraserByStrokes_Icon != null && EraserByStrokes_Icon.Visibility == Visibility.Visible)
{
return "eraserByStrokes";
}
+18 -13
View File
@@ -1,4 +1,3 @@
using Ink_Canvas.Helpers;
using System;
using System.Collections.Generic;
using System.Drawing;
@@ -11,8 +10,14 @@ using System.Windows.Controls;
using System.Windows.Forms;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Threading;
using Ink_Canvas.Helpers;
using Application = System.Windows.Application;
using Color = System.Drawing.Color;
using Cursors = System.Windows.Input.Cursors;
using Image = System.Windows.Controls.Image;
using PixelFormat = System.Drawing.Imaging.PixelFormat;
using Point = System.Windows.Point;
using Size = System.Drawing.Size;
namespace Ink_Canvas
@@ -21,9 +26,9 @@ namespace Ink_Canvas
public struct ScreenshotResult
{
public Rectangle Area;
public List<System.Windows.Point> Path;
public List<Point> Path;
public ScreenshotResult(Rectangle area, List<System.Windows.Point> path = null)
public ScreenshotResult(Rectangle area, List<Point> path = null)
{
Area = area;
Path = path;
@@ -172,7 +177,7 @@ namespace Ink_Canvas
var bitmapSource = ConvertBitmapToBitmapSource(bitmap);
// 创建WPF Image控件
var image = new System.Windows.Controls.Image
var image = new Image
{
Source = bitmapSource,
Stretch = Stretch.Uniform
@@ -202,7 +207,7 @@ namespace Ink_Canvas
CenterAndScaleScreenshot(image);
// 绑定事件处理器
BindScreenshotEvents(image);
}), System.Windows.Threading.DispatcherPriority.Loaded);
}), DispatcherPriority.Loaded);
};
// 添加到画布
@@ -221,7 +226,7 @@ namespace Ink_Canvas
}
// 初始化截图的TransformGroup
private void InitializeScreenshotTransform(System.Windows.Controls.Image image)
private void InitializeScreenshotTransform(Image image)
{
var transformGroup = new TransformGroup();
transformGroup.Children.Add(new ScaleTransform(1, 1));
@@ -231,7 +236,7 @@ namespace Ink_Canvas
}
// 绑定截图事件处理器
private void BindScreenshotEvents(System.Windows.Controls.Image image)
private void BindScreenshotEvents(Image image)
{
// 鼠标事件
image.MouseLeftButtonDown += Element_MouseLeftButtonDown;
@@ -245,7 +250,7 @@ namespace Ink_Canvas
image.ManipulationCompleted += Element_ManipulationCompleted;
// 设置光标
image.Cursor = System.Windows.Input.Cursors.Hand;
image.Cursor = Cursors.Hand;
// 禁用InkCanvas对截图的选择处理
image.IsHitTestVisible = true;
@@ -253,7 +258,7 @@ namespace Ink_Canvas
}
// 专门为截图优化的居中缩放方法
private void CenterAndScaleScreenshot(System.Windows.Controls.Image image)
private void CenterAndScaleScreenshot(Image image)
{
try
{
@@ -270,8 +275,8 @@ namespace Ink_Canvas
// 如果画布尺寸为0,使用窗口尺寸作为备选
if (canvasWidth <= 0 || canvasHeight <= 0)
{
canvasWidth = this.ActualWidth;
canvasHeight = this.ActualHeight;
canvasWidth = ActualWidth;
canvasHeight = ActualHeight;
}
// 如果仍然为0,使用屏幕尺寸
@@ -338,7 +343,7 @@ namespace Ink_Canvas
}
// 应用形状遮罩到截图
private Bitmap ApplyShapeMask(Bitmap bitmap, List<System.Windows.Point> path, Rectangle area)
private Bitmap ApplyShapeMask(Bitmap bitmap, List<Point> path, Rectangle area)
{
try
{
@@ -360,7 +365,7 @@ namespace Ink_Canvas
using (var resultGraphics = Graphics.FromImage(resultBitmap))
{
// 清除位图,设置为完全透明
resultGraphics.Clear(System.Drawing.Color.Transparent);
resultGraphics.Clear(Color.Transparent);
// 设置高质量渲染
resultGraphics.SmoothingMode = SmoothingMode.AntiAlias;
+2 -2
View File
@@ -1,8 +1,8 @@
using Ink_Canvas.Helpers;
using System;
using System;
using System.Linq;
using System.Threading;
using System.Windows;
using Ink_Canvas.Helpers;
namespace Ink_Canvas
{
+5 -5
View File
@@ -1,8 +1,4 @@
using Ink_Canvas.Helpers;
using iNKORE.UI.WPF.Modern;
using Microsoft.Office.Core;
using Microsoft.Office.Interop.PowerPoint;
using System;
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
@@ -12,6 +8,10 @@ using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
using System.Windows.Threading;
using Ink_Canvas.Helpers;
using iNKORE.UI.WPF.Modern;
using Microsoft.Office.Core;
using Microsoft.Office.Interop.PowerPoint;
using Application = System.Windows.Application;
using File = System.IO.File;
using MessageBox = System.Windows.MessageBox;
+2 -2
View File
@@ -1,10 +1,10 @@
using Ink_Canvas.Helpers;
using System.Collections.ObjectModel;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Ink;
using System.Windows.Input;
using Ink_Canvas.Helpers;
namespace Ink_Canvas
{
+32 -25
View File
@@ -1,15 +1,22 @@
using Ink_Canvas.Helpers;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.IO.Compression;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Forms;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Ink_Canvas.Helpers;
using Newtonsoft.Json;
using Color = System.Drawing.Color;
using File = System.IO.File;
using Image = System.Windows.Controls.Image;
using OpenFileDialog = Microsoft.Win32.OpenFileDialog;
namespace Ink_Canvas
@@ -150,7 +157,7 @@ namespace Ink_Canvas
catch (Exception ex)
{
ShowNotification("墨迹保存失败");
LogHelper.WriteLogToFile("墨迹保存失败 | " + ex.ToString(), LogHelper.LogType.Error);
LogHelper.WriteLogToFile("墨迹保存失败 | " + ex, LogHelper.LogType.Error);
}
}
@@ -191,7 +198,7 @@ namespace Ink_Canvas
// 保存元数据信息
string metadataFile = Path.Combine(tempDir, "metadata.txt");
using (var writer = new StreamWriter(metadataFile, false, System.Text.Encoding.UTF8))
using (var writer = new StreamWriter(metadataFile, false, Encoding.UTF8))
{
writer.WriteLine($"保存时间: {DateTime.Now:yyyy-MM-dd HH:mm:ss}");
writer.WriteLine($"总页数: {allPageStrokes.Count}");
@@ -219,7 +226,7 @@ namespace Ink_Canvas
File.Delete(zipFileName);
// 使用System.IO.Compression.FileSystem来创建ZIP
System.IO.Compression.ZipFile.CreateFromDirectory(tempDir, zipFileName);
ZipFile.CreateFromDirectory(tempDir, zipFileName);
if (newNotice) ShowNotification($"多页面墨迹成功保存至压缩包 {zipFileName}");
}
@@ -233,13 +240,13 @@ namespace Ink_Canvas
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"清理临时目录失败: {ex.ToString()}", LogHelper.LogType.Warning);
LogHelper.WriteLogToFile($"清理临时目录失败: {ex}", LogHelper.LogType.Warning);
}
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"保存多页面墨迹压缩包失败: {ex.ToString()}", LogHelper.LogType.Error);
LogHelper.WriteLogToFile($"保存多页面墨迹压缩包失败: {ex}", LogHelper.LogType.Error);
throw;
}
}
@@ -250,16 +257,16 @@ namespace Ink_Canvas
private void SaveSinglePageStrokesAsImage(string savePathWithName, bool newNotice)
{
// 全页面保存模式 - 保存整个墨迹页面的图像
var bitmap = new System.Drawing.Bitmap(
(int)System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width,
(int)System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height);
var bitmap = new Bitmap(
Screen.PrimaryScreen.Bounds.Width,
Screen.PrimaryScreen.Bounds.Height);
using (var g = System.Drawing.Graphics.FromImage(bitmap))
using (var g = Graphics.FromImage(bitmap))
{
// 创建黑色或透明背景
System.Drawing.Color bgColor = Settings.Canvas.UsingWhiteboard
? System.Drawing.Color.White
: System.Drawing.Color.FromArgb(22, 41, 36); // 黑板背景色
Color bgColor = Settings.Canvas.UsingWhiteboard
? Color.White
: Color.FromArgb(22, 41, 36); // 黑板背景色
g.Clear(bgColor);
// 将InkCanvas墨迹渲染到Visual
@@ -287,7 +294,7 @@ namespace Ink_Canvas
{
encoder.Save(ms);
ms.Seek(0, SeekOrigin.Begin);
var imgBitmap = new System.Drawing.Bitmap(ms);
var imgBitmap = new Bitmap(ms);
// 将生成的墨迹图像绘制到屏幕截图上
// 居中绘制,确保墨迹位于屏幕中央
@@ -297,7 +304,7 @@ namespace Ink_Canvas
// 保存为PNG
string imagePathWithName = Path.ChangeExtension(savePathWithName, "png");
bitmap.Save(imagePathWithName, System.Drawing.Imaging.ImageFormat.Png);
bitmap.Save(imagePathWithName, ImageFormat.Png);
// 仍然保存墨迹文件以兼容旧版本
var fs = new FileStream(savePathWithName, FileMode.Create);
@@ -337,7 +344,7 @@ namespace Ink_Canvas
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"保存页面图像失败: {ex.ToString()}", LogHelper.LogType.Error);
LogHelper.WriteLogToFile($"保存页面图像失败: {ex}", LogHelper.LogType.Error);
throw;
}
}
@@ -376,7 +383,7 @@ namespace Ink_Canvas
catch (Exception ex)
{
ShowNotification("墨迹打开失败");
LogHelper.WriteLogToFile($"墨迹打开失败: {ex.ToString()}", LogHelper.LogType.Error);
LogHelper.WriteLogToFile($"墨迹打开失败: {ex}", LogHelper.LogType.Error);
}
}
@@ -394,7 +401,7 @@ namespace Ink_Canvas
try
{
// 解压ZIP文件
System.IO.Compression.ZipFile.ExtractToDirectory(zipFilePath, tempDir);
ZipFile.ExtractToDirectory(zipFilePath, tempDir);
// 读取元数据文件
string metadataFile = Path.Combine(tempDir, "metadata.txt");
@@ -447,13 +454,13 @@ namespace Ink_Canvas
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"清理临时目录失败: {ex.ToString()}", LogHelper.LogType.Warning);
LogHelper.WriteLogToFile($"清理临时目录失败: {ex}", LogHelper.LogType.Warning);
}
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"打开ICC压缩包失败: {ex.ToString()}", LogHelper.LogType.Error);
LogHelper.WriteLogToFile($"打开ICC压缩包失败: {ex}", LogHelper.LogType.Error);
throw;
}
}
@@ -465,7 +472,7 @@ namespace Ink_Canvas
{
var metadata = new Dictionary<string, string>();
using (var reader = new StreamReader(metadataPath, System.Text.Encoding.UTF8))
using (var reader = new StreamReader(metadataPath, Encoding.UTF8))
{
string line;
while ((line = reader.ReadLine()) != null)
@@ -556,7 +563,7 @@ namespace Ink_Canvas
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"恢复PPT墨迹失败: {ex.ToString()}", LogHelper.LogType.Error);
LogHelper.WriteLogToFile($"恢复PPT墨迹失败: {ex}", LogHelper.LogType.Error);
throw;
}
}
@@ -609,7 +616,7 @@ namespace Ink_Canvas
{
// 创建历史记录
var history = new TimeMachineHistory(strokes, TimeMachineHistoryType.UserInput, false);
TimeMachineHistories[pageNumber] = new TimeMachineHistory[] { history };
TimeMachineHistories[pageNumber] = new[] { history };
}
}
}
@@ -628,7 +635,7 @@ namespace Ink_Canvas
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"恢复白板墨迹失败: {ex.ToString()}", LogHelper.LogType.Error);
LogHelper.WriteLogToFile($"恢复白板墨迹失败: {ex}", LogHelper.LogType.Error);
throw;
}
}
+5 -4
View File
@@ -1,5 +1,6 @@
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
using System.Windows;
@@ -42,10 +43,10 @@ namespace Ink_Canvas
using (var memoryGraphics = Graphics.FromImage(bitmap))
{
// 设置高质量渲染
memoryGraphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
memoryGraphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
memoryGraphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
memoryGraphics.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;
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);
@@ -1,13 +1,13 @@
using iNKORE.UI.WPF.Modern.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using iNKORE.UI.WPF.Modern.Controls;
using Point = System.Windows.Point;
using System.Linq;
namespace Ink_Canvas
{
@@ -308,7 +308,7 @@ namespace Ink_Canvas
// 检查是否有图片元素被选中
var selectedElements = inkCanvas.GetSelectedElements();
bool hasImageElement = selectedElements.Any(element => element is System.Windows.Controls.Image);
bool hasImageElement = selectedElements.Any(element => element is Image);
// 如果有图片元素被选中,不显示选择框
if (hasImageElement)
@@ -551,11 +551,9 @@ namespace Ink_Canvas
return new Rect(left, top, width, height);
}
}
else
{
// 没有变换时直接使用位置和大小
return new Rect(left, top, width, height);
}
// 没有变换时直接使用位置和大小
return new Rect(left, top, width, height);
}
return new Rect(0, 0, 0, 0);
+6 -5
View File
@@ -1,7 +1,3 @@
using Hardcodet.Wpf.TaskbarNotification;
using Ink_Canvas.Helpers;
using Newtonsoft.Json;
using OSVersionExtension;
using System;
using System.Diagnostics;
using System.IO;
@@ -13,6 +9,11 @@ using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Threading;
using Hardcodet.Wpf.TaskbarNotification;
using Ink_Canvas.Helpers;
using Newtonsoft.Json;
using OSVersionExtension;
using Application = System.Windows.Application;
using CheckBox = System.Windows.Controls.CheckBox;
using ComboBox = System.Windows.Controls.ComboBox;
@@ -2709,7 +2710,7 @@ namespace Ink_Canvas
{
LogHelper.WriteLogToFile($"重新计算高光位置和浮动栏位置失败: {ex.Message}", LogHelper.LogType.Error);
}
}), System.Windows.Threading.DispatcherPriority.Loaded);
}), DispatcherPriority.Loaded);
}
catch (Exception ex)
{
@@ -1,8 +1,4 @@
using Hardcodet.Wpf.TaskbarNotification;
using Ink_Canvas.Helpers;
using Newtonsoft.Json;
using OSVersionExtension;
using System;
using System;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
@@ -10,6 +6,10 @@ using System.Windows.Ink;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Hardcodet.Wpf.TaskbarNotification;
using Ink_Canvas.Helpers;
using Newtonsoft.Json;
using OSVersionExtension;
using File = System.IO.File;
using OperatingSystem = OSVersionExtension.OperatingSystem;
+13 -15
View File
@@ -1,6 +1,4 @@
using Ink_Canvas.Helpers;
using iNKORE.UI.WPF.Modern.Controls;
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;
@@ -10,6 +8,8 @@ using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using Ink_Canvas.Helpers;
using iNKORE.UI.WPF.Modern.Controls;
using MessageBox = System.Windows.MessageBox;
using Point = System.Windows.Point;
@@ -499,20 +499,18 @@ namespace Ink_Canvas
catch { }
return;
}
else
// 其他情况正常删除临时笔画
try
{
// 其他情况正常删除临时笔画
try
{
inkCanvas.Strokes.Remove(lastTempStroke);
inkCanvas.Strokes.Remove(lastTempStrokeCollection);
}
catch
{
Trace.WriteLine("lastTempStrokeCollection failed.");
}
return;
inkCanvas.Strokes.Remove(lastTempStroke);
inkCanvas.Strokes.Remove(lastTempStrokeCollection);
}
catch
{
Trace.WriteLine("lastTempStrokeCollection failed.");
}
return;
}
// 修复:双曲线绘制时,第二笔应该基于第一笔的起点,而不是触摸实时位置
@@ -1,5 +1,4 @@
using Ink_Canvas.Helpers;
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
@@ -9,6 +8,7 @@ using System.Windows.Controls;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using Ink_Canvas.Helpers;
using Point = System.Windows.Point;
namespace Ink_Canvas
+2 -2
View File
@@ -1,5 +1,4 @@
using Ink_Canvas.Helpers;
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows;
@@ -7,6 +6,7 @@ using System.Windows.Controls;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using Ink_Canvas.Helpers;
namespace Ink_Canvas
{
+2 -2
View File
@@ -1,5 +1,4 @@
using Ink_Canvas.Helpers;
using System;
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
@@ -12,6 +11,7 @@ using System.Threading.Tasks;
using System.Timers;
using System.Windows;
using System.Windows.Controls;
using Ink_Canvas.Helpers;
namespace Ink_Canvas
{
+5 -4
View File
@@ -1,4 +1,3 @@
using Ink_Canvas.Helpers;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -8,6 +7,8 @@ using System.Windows.Controls;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Threading;
using Ink_Canvas.Helpers;
using Point = System.Windows.Point;
namespace Ink_Canvas
@@ -398,10 +399,10 @@ namespace Ink_Canvas
private InkCanvasEditingMode palmEraserLastEditingMode = InkCanvasEditingMode.Ink;
private bool palmEraserLastIsHighlighter;
private bool palmEraserWasEnabledBeforeMultiTouch;
private bool palmEraserTouchDownHandled = false; // 新增:标记手掌擦触摸按下是否已处理
private bool palmEraserTouchDownHandled; // 新增:标记手掌擦触摸按下是否已处理
private DateTime palmEraserActivationTime; // 新增:记录手掌擦激活时间
private const int PALM_ERASER_TIMEOUT_MS = 3000; // 修改:减少手掌擦超时时间(3秒)
private System.Windows.Threading.DispatcherTimer palmEraserRecoveryTimer; // 新增:手掌擦恢复定时器
private DispatcherTimer palmEraserRecoveryTimer; // 新增:手掌擦恢复定时器
private HashSet<int> palmEraserTouchIds = new HashSet<int>(); // 新增:记录参与手掌擦的触摸点ID
private void inkCanvas_PreviewTouchDown(object sender, TouchEventArgs e)
@@ -983,7 +984,7 @@ namespace Ink_Canvas
{
if (palmEraserRecoveryTimer == null)
{
palmEraserRecoveryTimer = new System.Windows.Threading.DispatcherTimer();
palmEraserRecoveryTimer = new DispatcherTimer();
palmEraserRecoveryTimer.Interval = TimeSpan.FromMilliseconds(1000); // 每秒检查一次
palmEraserRecoveryTimer.Tick += PalmEraserRecoveryTimer_Tick;
}
+4 -4
View File
@@ -1,12 +1,12 @@
using Hardcodet.Wpf.TaskbarNotification;
using Ink_Canvas.Helpers;
using iNKORE.UI.WPF.Modern.Controls;
using System;
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Forms;
using System.Windows.Interop;
using Hardcodet.Wpf.TaskbarNotification;
using Ink_Canvas.Helpers;
using iNKORE.UI.WPF.Modern.Controls;
using Application = System.Windows.Application;
using ContextMenu = System.Windows.Controls.ContextMenu;
using MenuItem = System.Windows.Controls.MenuItem;
+7 -7
View File
@@ -1,7 +1,7 @@
using Newtonsoft.Json;
using System;
using System;
using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json;
namespace Ink_Canvas
{
@@ -93,11 +93,11 @@ namespace Ink_Canvas
[JsonProperty("clearCanvasAlsoClearImages")]
public bool ClearCanvasAlsoClearImages { get; set; } = true;
[JsonProperty("showCircleCenter")]
public bool ShowCircleCenter { get; set; } = false;
public bool ShowCircleCenter { get; set; }
// 墨迹渐隐功能设置
[JsonProperty("enableInkFade")]
public bool EnableInkFade { get; set; } = false; // 是否启用墨迹渐隐功能
public bool EnableInkFade { get; set; } // 是否启用墨迹渐隐功能
[JsonProperty("inkFadeTime")]
public int InkFadeTime { get; set; } = 3000; // 墨迹渐隐时间(毫秒)
@@ -152,7 +152,7 @@ namespace Ink_Canvas
[JsonProperty("skippedVersion")]
public string SkippedVersion { get; set; } = "";
[JsonProperty("isEnableNibMode")]
public bool IsEnableNibMode { get; set; } = false;
public bool IsEnableNibMode { get; set; }
[JsonProperty("isFoldAtStartup")]
public bool IsFoldAtStartup { get; set; }
[JsonProperty("crashAction")]
@@ -225,10 +225,10 @@ namespace Ink_Canvas
public bool IsShowClearAndMouseButton { get; set; } = true;
[JsonProperty("eraserDisplayOption")]
public int EraserDisplayOption { get; set; } = 0;
public int EraserDisplayOption { get; set; }
[JsonProperty("isShowQuickColorPalette")]
public bool IsShowQuickColorPalette { get; set; } = false;
public bool IsShowQuickColorPalette { get; set; }
[JsonProperty("quickColorPaletteDisplayMode")]
public int QuickColorPaletteDisplayMode { get; set; } = 1;
@@ -1,8 +1,8 @@
using Microsoft.Win32;
using System;
using System.IO;
using System.Windows;
using System.Windows.Media.Imaging;
using Microsoft.Win32;
namespace Ink_Canvas
{
@@ -1,8 +1,8 @@
using Microsoft.Win32;
using System;
using System.IO;
using System.Windows;
using System.Windows.Media.Imaging;
using Microsoft.Win32;
namespace Ink_Canvas
{
@@ -1,6 +1,4 @@
using Ink_Canvas.Helpers;
using iNKORE.UI.WPF.Modern.Controls;
using System;
using System;
using System.ComponentModel;
using System.Media;
using System.Timers;
@@ -9,6 +7,7 @@ using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;
using Ink_Canvas.Helpers;
using Application = System.Windows.Application;
using MouseEventArgs = System.Windows.Input.MouseEventArgs;
using Timer = System.Timers.Timer;
@@ -92,7 +91,7 @@ namespace Ink_Canvas
private void Grid_MouseUp(object sender, MouseButtonEventArgs e)
{
if (isTimerRunning) return;
if (ProcessBarTime.Visibility == Visibility.Visible && isTimerRunning == false)
if (ProcessBarTime.Visibility == Visibility.Visible && !isTimerRunning)
{
ProcessBarTime.Visibility = Visibility.Collapsed;
GridAdjustHour.Visibility = Visibility.Visible;
@@ -1,7 +1,4 @@
using Ink_Canvas.Helpers;
using iNKORE.UI.WPF.Modern.Controls;
using MdXaml;
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@@ -13,6 +10,9 @@ using System.Windows;
using System.Windows.Controls;
using System.Windows.Interop;
using System.Windows.Media;
using Ink_Canvas.Helpers;
using iNKORE.UI.WPF.Modern.Controls;
using MdXaml;
namespace Ink_Canvas
{
@@ -1,4 +1,3 @@
using Ink_Canvas.Helpers;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@@ -8,6 +7,8 @@ using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Ink_Canvas.Helpers;
// Added for OrderByDescending
namespace Ink_Canvas
+5 -4
View File
@@ -2,6 +2,7 @@ using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
namespace Ink_Canvas.Windows
{
@@ -79,20 +80,20 @@ namespace Ink_Canvas.Windows
if (_currentKey == Key.None)
{
CurrentHotkeyTextBlock.Text = "未设置";
CurrentHotkeyTextBlock.Foreground = System.Windows.Media.Brushes.Gray;
CurrentHotkeyTextBlock.Foreground = Brushes.Gray;
}
else
{
var modifiersText = _currentModifiers == ModifierKeys.None ? "" : $"{_currentModifiers}+";
CurrentHotkeyTextBlock.Text = $"{modifiersText}{_currentKey}";
CurrentHotkeyTextBlock.Foreground = System.Windows.Media.Brushes.Black;
CurrentHotkeyTextBlock.Foreground = Brushes.Black;
}
}
private void StartHotkeyCapture()
{
BtnSetHotkey.Content = "请按键...";
BtnSetHotkey.Background = System.Windows.Media.Brushes.Orange;
BtnSetHotkey.Background = Brushes.Orange;
// 设置焦点以捕获键盘事件
Focus();
@@ -105,7 +106,7 @@ namespace Ink_Canvas.Windows
private void StopHotkeyCapture()
{
BtnSetHotkey.Content = "设置";
BtnSetHotkey.Background = System.Windows.Media.Brushes.DodgerBlue;
BtnSetHotkey.Background = Brushes.DodgerBlue;
// 移除键盘事件处理器
KeyDown -= HotkeyItem_KeyDown;
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Ink_Canvas.Helpers;
@@ -324,11 +326,11 @@ namespace Ink_Canvas.Windows
// 立即保存到配置文件
_hotkeyManager.SaveHotkeysToSettings();
LogHelper.WriteLogToFile($"已保存快捷键配置");
LogHelper.WriteLogToFile("已保存快捷键配置");
// 更新UI显示
LoadCurrentHotkeys();
LogHelper.WriteLogToFile($"已更新UI显示");
LogHelper.WriteLogToFile("已更新UI显示");
LogHelper.WriteLogToFile($"快捷键 {hotkeyName} 已更新为 {modifiers}+{key} 并保存", LogHelper.LogType.Event);
}
@@ -403,7 +405,7 @@ namespace Ink_Canvas.Windows
{
// 通过反射访问主窗口的penType字段
var penTypeField = _mainWindow.GetType().GetField("penType",
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
BindingFlags.NonPublic | BindingFlags.Instance);
if (penTypeField != null)
{
@@ -411,7 +413,7 @@ namespace Ink_Canvas.Windows
// 调用CheckPenTypeUIState方法更新UI状态
var checkPenTypeMethod = _mainWindow.GetType().GetMethod("CheckPenTypeUIState",
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
BindingFlags.NonPublic | BindingFlags.Instance);
if (checkPenTypeMethod != null)
{
@@ -436,7 +438,7 @@ namespace Ink_Canvas.Windows
{
// 通过反射访问主窗口的设置面板
var settingsBorder = _mainWindow.GetType().GetField("BorderSettings",
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)?.GetValue(_mainWindow) as System.Windows.Controls.Border;
BindingFlags.NonPublic | BindingFlags.Instance)?.GetValue(_mainWindow) as Border;
if (settingsBorder != null)
{
@@ -445,7 +447,7 @@ namespace Ink_Canvas.Windows
// 隐藏设置蒙版
var settingsMask = _mainWindow.GetType().GetField("BorderSettingsMask",
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)?.GetValue(_mainWindow) as System.Windows.Controls.Border;
BindingFlags.NonPublic | BindingFlags.Instance)?.GetValue(_mainWindow) as Border;
if (settingsMask != null)
{
@@ -467,7 +469,7 @@ namespace Ink_Canvas.Windows
{
// 通过反射访问主窗口的设置面板
var settingsBorder = _mainWindow.GetType().GetField("BorderSettings",
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)?.GetValue(_mainWindow) as System.Windows.Controls.Border;
BindingFlags.NonPublic | BindingFlags.Instance)?.GetValue(_mainWindow) as Border;
if (settingsBorder != null)
{
@@ -476,7 +478,7 @@ namespace Ink_Canvas.Windows
// 显示设置蒙版
var settingsMask = _mainWindow.GetType().GetField("BorderSettingsMask",
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)?.GetValue(_mainWindow) as System.Windows.Controls.Border;
BindingFlags.NonPublic | BindingFlags.Instance)?.GetValue(_mainWindow) as Border;
if (settingsMask != null)
{
+2 -2
View File
@@ -1,7 +1,7 @@
using Ink_Canvas.Helpers;
using System.ComponentModel;
using System.ComponentModel;
using System.IO;
using System.Windows;
using Ink_Canvas.Helpers;
namespace Ink_Canvas
{
@@ -1,7 +1,6 @@
using Ink_Canvas.Helpers;
using iNKORE.UI.WPF.Modern.Controls;
using System.Windows;
using System.Windows;
using System.Windows.Input;
using Ink_Canvas.Helpers;
namespace Ink_Canvas
{
@@ -1,9 +1,3 @@
using Ink_Canvas.Helpers;
using Ink_Canvas.Helpers.Plugins;
using Ink_Canvas.Helpers.Plugins.BuiltIn;
using Ink_Canvas.Helpers.Plugins.BuiltIn.SuperLauncher;
using iNKORE.UI.WPF.Modern.Controls;
using Microsoft.Win32;
using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
@@ -12,6 +6,12 @@ using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Threading;
using Ink_Canvas.Helpers;
using Ink_Canvas.Helpers.Plugins;
using Ink_Canvas.Helpers.Plugins.BuiltIn;
using Ink_Canvas.Helpers.Plugins.BuiltIn.SuperLauncher;
using iNKORE.UI.WPF.Modern.Controls;
using Microsoft.Win32;
using MessageBox = System.Windows.MessageBox;
namespace Ink_Canvas.Windows
+5 -6
View File
@@ -1,7 +1,4 @@
using Ink_Canvas.Helpers;
using iNKORE.UI.WPF.Modern.Controls;
using Microsoft.VisualBasic;
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
@@ -11,6 +8,8 @@ using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Ink_Canvas.Helpers;
using Microsoft.VisualBasic;
using MessageBox = iNKORE.UI.WPF.Modern.Controls.MessageBox;
namespace Ink_Canvas
@@ -24,7 +23,7 @@ namespace Ink_Canvas
{
InitializeComponent();
AnimationsHelper.ShowWithSlideFromBottomAndFade(this, 0.25);
BorderBtnHelp.Visibility = settings.RandSettings.DisplayRandWindowNamesInputBtn == false ? Visibility.Collapsed : Visibility.Visible;
BorderBtnHelp.Visibility = !settings.RandSettings.DisplayRandWindowNamesInputBtn ? Visibility.Collapsed : Visibility.Visible;
RandMaxPeopleOneTime = settings.RandSettings.RandWindowOnceMaxStudents;
RandDoneAutoCloseWaitTime = (int)settings.RandSettings.RandWindowOnceCloseLatency * 1000;
@@ -69,7 +68,7 @@ namespace Ink_Canvas
isAutoClose = IsAutoClose;
PeopleControlPane.Opacity = 0.4;
PeopleControlPane.IsHitTestVisible = false;
BorderBtnHelp.Visibility = settings.RandSettings.DisplayRandWindowNamesInputBtn == false ? Visibility.Collapsed : Visibility.Visible;
BorderBtnHelp.Visibility = !settings.RandSettings.DisplayRandWindowNamesInputBtn ? Visibility.Collapsed : Visibility.Visible;
RandMaxPeopleOneTime = settings.RandSettings.RandWindowOnceMaxStudents;
RandDoneAutoCloseWaitTime = (int)settings.RandSettings.RandWindowOnceCloseLatency * 1000;
+124 -38
View File
@@ -20,71 +20,157 @@
Fill="Black"
Opacity="0.3" />
<!-- 透明选择区域遮罩 - 使用正确的几何体操作 -->
<Rectangle Name="TransparentSelectionMask"
Fill="Black"
Opacity="0.3"
Visibility="Collapsed">
<Rectangle.Clip>
<CombinedGeometry GeometryCombineMode="Exclude">
<CombinedGeometry.Geometry1>
<RectangleGeometry Rect="0,0,10000,10000" />
</CombinedGeometry.Geometry1>
<CombinedGeometry.Geometry2>
<RectangleGeometry x:Name="SelectionClipGeometry" Rect="0,0,0,0" />
</CombinedGeometry.Geometry2>
</CombinedGeometry>
</Rectangle.Clip>
</Rectangle>
<!-- 选择区域容器 -->
<Canvas Name="SelectionCanvas">
<Canvas Name="SelectionCanvas" Panel.ZIndex="1000">
<!-- 矩形选择模式 -->
<Rectangle Name="SelectionRectangle"
Stroke="Red"
StrokeThickness="2"
Stroke="White"
StrokeThickness="1"
Fill="Transparent"
Visibility="Collapsed" />
<!-- 任意形状选择模式 -->
<Path Name="SelectionPath"
Stroke="Red"
StrokeThickness="2"
Stroke="White"
StrokeThickness="1"
Fill="Transparent"
Visibility="Collapsed" />
<!-- 控制点容器 -->
<Canvas Name="ControlPointsCanvas" Visibility="Collapsed" Panel.ZIndex="1002">
<!-- 四个角控制点 -->
<Ellipse Name="TopLeftControl" Width="8" Height="8" Fill="White" Stroke="White" StrokeThickness="1" Cursor="SizeNWSE" />
<Ellipse Name="TopRightControl" Width="8" Height="8" Fill="White" Stroke="White" StrokeThickness="1" Cursor="SizeNESW" />
<Ellipse Name="BottomLeftControl" Width="8" Height="8" Fill="White" Stroke="White" StrokeThickness="1" Cursor="SizeNESW" />
<Ellipse Name="BottomRightControl" Width="8" Height="8" Fill="White" Stroke="White" StrokeThickness="1" Cursor="SizeNWSE" />
<!-- 四个边控制点 -->
<Ellipse Name="TopControl" Width="8" Height="8" Fill="White" Stroke="White" StrokeThickness="1" Cursor="SizeNS" />
<Ellipse Name="BottomControl" Width="8" Height="8" Fill="White" Stroke="White" StrokeThickness="1" Cursor="SizeNS" />
<Ellipse Name="LeftControl" Width="8" Height="8" Fill="White" Stroke="White" StrokeThickness="1" Cursor="SizeWE" />
<Ellipse Name="RightControl" Width="8" Height="8" Fill="White" Stroke="White" StrokeThickness="1" Cursor="SizeWE" />
</Canvas>
<!-- 尺寸信息显示 -->
<Border Name="SizeInfoBorder"
Background="Black"
Opacity="0.8"
CornerRadius="3"
Background="#1a1a1a"
Opacity="0.9"
CornerRadius="4"
Padding="8,4"
Visibility="Collapsed">
<TextBlock Name="SizeInfoText"
Foreground="White"
FontSize="12"
FontWeight="Medium"
Text="0 x 0" />
</Border>
</Canvas>
<!-- 模式切换按钮 -->
<StackPanel Orientation="Horizontal"
HorizontalAlignment="Center"
VerticalAlignment="Top"
Margin="0,100,0,0">
<Button Name="RectangleModeButton"
Content="矩形模式"
Margin="5,0"
Padding="10,5"
Background="#2563eb"
Foreground="White"
BorderThickness="0"
Click="RectangleModeButton_Click" />
<Button Name="FreehandModeButton"
Content="自由绘制"
Margin="5,0"
Padding="10,5"
Background="#6b7280"
Foreground="White"
BorderThickness="0"
Click="FreehandModeButton_Click" />
</StackPanel>
<!-- 提示文字 -->
<Border Background="Black"
Opacity="0.8"
CornerRadius="5"
Padding="15,8"
<!-- 顶部工具栏 -->
<Border Background="#1a1a1a"
Opacity="0.95"
CornerRadius="8"
Padding="12,8"
HorizontalAlignment="Center"
VerticalAlignment="Top"
Margin="0,150,0,0">
Margin="0,20,0,0"
Panel.ZIndex="1000">
<StackPanel Orientation="Horizontal">
<!-- 模式切换按钮 -->
<Button Name="RectangleModeButton"
Content="矩形模式"
Margin="4,0"
Padding="12,6"
Background="#2563eb"
Foreground="White"
BorderThickness="0"
FontWeight="Medium"
Click="RectangleModeButton_Click" />
<Button Name="FreehandModeButton"
Content="自由绘制"
Margin="4,0"
Padding="12,6"
Background="#6b7280"
Foreground="White"
BorderThickness="0"
FontWeight="Medium"
Click="FreehandModeButton_Click" />
<!-- 分隔线 -->
<Separator Style="{StaticResource {x:Static ToolBar.SeparatorStyleKey}}"
Margin="8,0"
Background="#404040" />
<!-- 操作按钮 -->
<Button Name="ConfirmButton"
Content="确认截图"
Margin="4,0"
Padding="12,6"
Background="#059669"
Foreground="White"
BorderThickness="0"
FontWeight="Medium"
Click="ConfirmButton_Click" />
<Button Name="CancelButton"
Content="取消"
Margin="4,0"
Padding="12,6"
Background="#dc2626"
Foreground="White"
BorderThickness="0"
FontWeight="Medium"
Click="CancelButton_Click" />
</StackPanel>
</Border>
<!-- 提示文字 -->
<Border Background="#1a1a1a"
Opacity="0.9"
CornerRadius="6"
Padding="16,10"
HorizontalAlignment="Center"
VerticalAlignment="Top"
Margin="0,80,0,0"
Panel.ZIndex="1000">
<TextBlock Name="HintText"
Text="拖拽鼠标选择矩形区域,或使用自由绘制模式"
Foreground="White"
FontSize="16" />
FontSize="14"
FontWeight="Medium" />
</Border>
<!-- 调整模式提示 -->
<Border Name="AdjustModeHint"
Background="#1a1a1a"
Opacity="0.9"
CornerRadius="6"
Padding="16,10"
HorizontalAlignment="Center"
VerticalAlignment="Bottom"
Margin="0,0,0,20"
Visibility="Collapsed"
Panel.ZIndex="1000">
<TextBlock Text="拖拽控制点调整选择区域,或拖拽边框移动位置"
Foreground="White"
FontSize="14"
FontWeight="Medium" />
</Border>
</Grid>
</Window>
@@ -1,25 +1,43 @@
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Shapes;
using System.Windows.Threading;
using Brushes = System.Windows.Media.Brushes;
using Color = System.Windows.Media.Color;
using DrawingRectangle = System.Drawing.Rectangle;
// 为了避免命名冲突,使用别名
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
using MouseEventArgs = System.Windows.Input.MouseEventArgs;
using WpfCanvas = System.Windows.Controls.Canvas;
namespace Ink_Canvas
{
public partial class ScreenshotSelectorWindow : Window
{
private bool _isSelecting = false;
private bool _isFreehandMode = false;
private bool _isSelecting;
private bool _isFreehandMode;
private bool _isAdjusting;
private bool _isMoving;
private Point _startPoint;
private Point _currentPoint;
private Point _lastMousePosition;
private List<Point> _freehandPoints;
private Polyline _freehandPolyline;
private Rect _currentSelection;
private ControlPointType _activeControlPoint = ControlPointType.None;
// 控制点类型枚举
private enum ControlPointType
{
None,
TopLeft, TopRight, BottomLeft, BottomRight,
Top, Bottom, Left, Right,
Move
}
public DrawingRectangle? SelectedArea { get; private set; }
public List<Point> SelectedPath { get; private set; }
@@ -34,8 +52,11 @@ namespace Ink_Canvas
// 初始化自由绘制模式
InitializeFreehandMode();
// 绑定控制点事件
BindControlPointEvents();
// 隐藏提示文字的定时器
var timer = new System.Windows.Threading.DispatcherTimer();
var timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromSeconds(5);
timer.Tick += (s, e) =>
{
@@ -50,17 +71,41 @@ namespace Ink_Canvas
_freehandPoints = new List<Point>();
_freehandPolyline = new Polyline
{
Stroke = Brushes.Red,
StrokeThickness = 2,
Stroke = Brushes.White,
StrokeThickness = 1,
Fill = Brushes.Transparent
};
SelectionCanvas.Children.Add(_freehandPolyline);
}
private void BindControlPointEvents()
{
// 绑定所有控制点的鼠标事件
var controlPoints = new[]
{
TopLeftControl, TopRightControl, BottomLeftControl, BottomRightControl,
TopControl, BottomControl, LeftControl, RightControl
};
foreach (var control in controlPoints)
{
control.MouseLeftButtonDown += ControlPoint_MouseLeftButtonDown;
control.MouseLeftButtonUp += ControlPoint_MouseLeftButtonUp;
control.MouseMove += ControlPoint_MouseMove;
// 确保控制点能够接收鼠标事件
control.IsHitTestVisible = true;
control.Focusable = false;
// 设置控制点的Z-index,确保它们在最上层
WpfCanvas.SetZIndex(control, 1003);
}
}
private void SetupFullScreenOverlay()
{
// 获取所有屏幕的虚拟屏幕边界
var virtualScreen = System.Windows.Forms.SystemInformation.VirtualScreen;
var virtualScreen = SystemInformation.VirtualScreen;
// 转换为WPF坐标系统
var dpiScale = GetDpiScale();
@@ -85,11 +130,11 @@ namespace Ink_Canvas
{
if (e.Key == Key.Escape)
{
// 取消截图
SelectedArea = null;
SelectedPath = null;
DialogResult = false;
Close();
CancelSelection();
}
else if (e.Key == Key.Enter)
{
ConfirmSelection();
}
}
@@ -103,8 +148,15 @@ namespace Ink_Canvas
// 清除自由绘制的内容
_freehandPoints.Clear();
_freehandPolyline.Points.Clear();
_freehandPolyline.Visibility = Visibility.Collapsed;
SelectionPath.Visibility = Visibility.Collapsed;
SelectionRectangle.Visibility = Visibility.Collapsed;
ControlPointsCanvas.Visibility = Visibility.Collapsed;
SizeInfoBorder.Visibility = Visibility.Collapsed;
// 重置遮罩
TransparentSelectionMask.Visibility = Visibility.Collapsed;
OverlayRectangle.Visibility = Visibility.Visible;
}
private void FreehandModeButton_Click(object sender, RoutedEventArgs e)
@@ -112,16 +164,57 @@ namespace Ink_Canvas
_isFreehandMode = true;
FreehandModeButton.Background = new SolidColorBrush(Color.FromRgb(37, 99, 235)); // 蓝色
RectangleModeButton.Background = new SolidColorBrush(Color.FromRgb(107, 114, 128)); // 灰色
HintText.Text = "按住鼠标左键绘制任意形状,松开完成";
HintText.Text = "按住鼠标左键绘制任意形状,松开直接截图";
// 清除矩形选择的内容
SelectionRectangle.Visibility = Visibility.Collapsed;
ControlPointsCanvas.Visibility = Visibility.Collapsed;
SizeInfoBorder.Visibility = Visibility.Collapsed;
_freehandPolyline.Visibility = Visibility.Collapsed;
_freehandPoints.Clear();
_freehandPolyline.Points.Clear();
// 重置遮罩
TransparentSelectionMask.Visibility = Visibility.Collapsed;
OverlayRectangle.Visibility = Visibility.Visible;
}
private void ConfirmButton_Click(object sender, RoutedEventArgs e)
{
// 在自由绘制模式下,确认按钮不执行任何操作
if (_isFreehandMode)
{
return;
}
ConfirmSelection();
}
private void CancelButton_Click(object sender, RoutedEventArgs e)
{
CancelSelection();
}
private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
// 检查是否点击了UI元素,如果是则不处理选择
var hitElement = e.Source as FrameworkElement;
if (hitElement != null && (
hitElement is Ellipse ||
hitElement is System.Windows.Controls.Button ||
hitElement is Border ||
hitElement is TextBlock ||
hitElement is StackPanel ||
hitElement is Separator ||
hitElement.Name == "SizeInfoBorder" ||
hitElement.Name == "HintText" ||
hitElement.Name == "AdjustModeHint"))
{
return;
}
if (_isAdjusting) return; // 如果正在调整,忽略新的选择
_isSelecting = true;
_startPoint = e.GetPosition(this);
_currentPoint = _startPoint;
@@ -131,11 +224,14 @@ namespace Ink_Canvas
if (_isFreehandMode)
{
// 自由绘制模式
// 自由绘制模式:开始绘制
_freehandPoints.Clear();
_freehandPolyline.Points.Clear();
_freehandPoints.Add(_startPoint);
_freehandPolyline.Points.Add(_startPoint);
// 确保自由绘制路径可见
_freehandPolyline.Visibility = Visibility.Visible;
}
else
{
@@ -164,6 +260,9 @@ namespace Ink_Canvas
// 自由绘制模式:添加点到路径
_freehandPoints.Add(_currentPoint);
_freehandPolyline.Points.Add(_currentPoint);
// 确保自由绘制路径可见
_freehandPolyline.Visibility = Visibility.Visible;
}
else
{
@@ -182,16 +281,16 @@ namespace Ink_Canvas
if (_isFreehandMode)
{
// 自由绘制模式:完成路径
if (_freehandPoints.Count > 3) // 至少需要3个点形成有效路径
// 自由绘制模式:一笔完成,直接截图
if (_freehandPoints.Count > 3) // 确保有足够的点
{
// 创建路径的副本,避免修改原始列表
var pathPoints = new List<Point>(_freehandPoints);
// 确保路径闭合(如果最后一个点不是起始点,则添加起始点)
if (pathPoints.Count > 0 &&
(Math.Abs(pathPoints[pathPoints.Count - 1].X - _startPoint.X) > 1 ||
Math.Abs(pathPoints[pathPoints.Count - 1].Y - _startPoint.Y) > 1))
(Math.Abs(pathPoints[pathPoints.Count - 1].X - _startPoint.X) > 15 ||
Math.Abs(pathPoints[pathPoints.Count - 1].Y - _startPoint.Y) > 15))
{
pathPoints.Add(_startPoint);
}
@@ -204,42 +303,41 @@ namespace Ink_Canvas
// 计算边界矩形用于截图
var bounds = CalculatePathBounds(optimizedPath);
var dpiScale = GetDpiScale();
var virtualScreen = System.Windows.Forms.SystemInformation.VirtualScreen;
// 确保边界矩形有效
if (bounds.Width > 1 && bounds.Height > 1)
{
var dpiScale = GetDpiScale();
var virtualScreen = SystemInformation.VirtualScreen;
int screenX = (int)((bounds.X * dpiScale) + virtualScreen.Left);
int screenY = (int)((bounds.Y * dpiScale) + virtualScreen.Top);
int screenWidth = (int)(bounds.Width * dpiScale);
int screenHeight = (int)(bounds.Height * dpiScale);
int screenX = (int)((bounds.X * dpiScale) + virtualScreen.Left);
int screenY = (int)((bounds.Y * dpiScale) + virtualScreen.Top);
int screenWidth = (int)(bounds.Width * dpiScale);
int screenHeight = (int)(bounds.Height * dpiScale);
SelectedArea = new DrawingRectangle(screenX, screenY, screenWidth, screenHeight);
DialogResult = true;
}
else
{
SelectedArea = null;
SelectedPath = null;
DialogResult = false;
SelectedArea = new DrawingRectangle(screenX, screenY, screenWidth, screenHeight);
DialogResult = true;
Close();
return;
}
}
// 如果自由绘制失败,清除路径并继续
_freehandPoints.Clear();
_freehandPolyline.Points.Clear();
_freehandPolyline.Visibility = Visibility.Collapsed;
return;
}
else
{
// 矩形模式
// 矩形模式:进入调整模式
var rect = GetSelectionRectangle();
if (rect.Width > 5 && rect.Height > 5) // 最小尺寸检查
{
// 转换为屏幕坐标,考虑DPI缩放
var dpiScale = GetDpiScale();
var virtualScreen = System.Windows.Forms.SystemInformation.VirtualScreen;
// 计算实际屏幕坐标
int screenX = (int)((rect.X * dpiScale) + virtualScreen.Left);
int screenY = (int)((rect.Y * dpiScale) + virtualScreen.Top);
int screenWidth = (int)(rect.Width * dpiScale);
int screenHeight = (int)(rect.Height * dpiScale);
SelectedArea = new DrawingRectangle(screenX, screenY, screenWidth, screenHeight);
DialogResult = true;
_currentSelection = rect;
_isAdjusting = true;
ShowControlPoints();
AdjustModeHint.Visibility = Visibility.Visible;
}
else
{
@@ -248,10 +346,160 @@ namespace Ink_Canvas
}
}
Close();
if (!_isAdjusting)
{
Close();
}
}
}
private void ControlPoint_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (!_isAdjusting) return;
_isMoving = true;
_lastMousePosition = e.GetPosition(this);
// 确定当前控制点类型
var ellipse = sender as Ellipse;
if (ellipse == TopLeftControl) _activeControlPoint = ControlPointType.TopLeft;
else if (ellipse == TopRightControl) _activeControlPoint = ControlPointType.TopRight;
else if (ellipse == BottomLeftControl) _activeControlPoint = ControlPointType.BottomLeft;
else if (ellipse == BottomRightControl) _activeControlPoint = ControlPointType.BottomRight;
else if (ellipse == TopControl) _activeControlPoint = ControlPointType.Top;
else if (ellipse == BottomControl) _activeControlPoint = ControlPointType.Bottom;
else if (ellipse == LeftControl) _activeControlPoint = ControlPointType.Left;
else if (ellipse == RightControl) _activeControlPoint = ControlPointType.Right;
// 捕获鼠标到控制点本身,而不是整个窗口
ellipse?.CaptureMouse();
e.Handled = true;
}
private void ControlPoint_MouseMove(object sender, MouseEventArgs e)
{
if (!_isAdjusting || !_isMoving || _activeControlPoint == ControlPointType.None) return;
try
{
var currentPosition = e.GetPosition(this);
var delta = currentPosition - _lastMousePosition;
// 根据控制点类型调整选择区域
AdjustSelection(delta);
_lastMousePosition = currentPosition;
e.Handled = true;
}
catch (Exception)
{
// 如果出现异常,停止移动
_isMoving = false;
_activeControlPoint = ControlPointType.None;
var ellipse = sender as Ellipse;
ellipse?.ReleaseMouseCapture();
}
}
private void ControlPoint_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
if (_isMoving)
{
_isMoving = false;
_activeControlPoint = ControlPointType.None;
var ellipse = sender as Ellipse;
ellipse?.ReleaseMouseCapture();
e.Handled = true;
}
}
private void AdjustSelection(Vector delta)
{
var newRect = _currentSelection;
switch (_activeControlPoint)
{
case ControlPointType.TopLeft:
newRect.X += delta.X;
newRect.Y += delta.Y;
newRect.Width -= delta.X;
newRect.Height -= delta.Y;
break;
case ControlPointType.TopRight:
newRect.Y += delta.Y;
newRect.Width += delta.X;
newRect.Height -= delta.Y;
break;
case ControlPointType.BottomLeft:
newRect.X += delta.X;
newRect.Width -= delta.X;
newRect.Height += delta.Y;
break;
case ControlPointType.BottomRight:
newRect.Width += delta.X;
newRect.Height += delta.Y;
break;
case ControlPointType.Top:
newRect.Y += delta.Y;
newRect.Height -= delta.Y;
break;
case ControlPointType.Bottom:
newRect.Height += delta.Y;
break;
case ControlPointType.Left:
newRect.X += delta.X;
newRect.Width -= delta.X;
break;
case ControlPointType.Right:
newRect.Width += delta.X;
break;
}
// 确保最小尺寸
if (newRect.Width >= 10 && newRect.Height >= 10)
{
_currentSelection = newRect;
UpdateSelectionDisplay();
}
}
private void ShowControlPoints()
{
ControlPointsCanvas.Visibility = Visibility.Visible;
UpdateControlPointsPosition();
}
private void UpdateControlPointsPosition()
{
var rect = _currentSelection;
// 更新角控制点位置
WpfCanvas.SetLeft(TopLeftControl, rect.Left - 4);
WpfCanvas.SetTop(TopLeftControl, rect.Top - 4);
WpfCanvas.SetLeft(TopRightControl, rect.Right - 4);
WpfCanvas.SetTop(TopRightControl, rect.Top - 4);
WpfCanvas.SetLeft(BottomLeftControl, rect.Left - 4);
WpfCanvas.SetTop(BottomLeftControl, rect.Bottom - 4);
WpfCanvas.SetLeft(BottomRightControl, rect.Right - 4);
WpfCanvas.SetTop(BottomRightControl, rect.Bottom - 4);
// 更新边控制点位置
WpfCanvas.SetLeft(TopControl, rect.Left + rect.Width / 2 - 4);
WpfCanvas.SetTop(TopControl, rect.Top - 4);
WpfCanvas.SetLeft(BottomControl, rect.Left + rect.Width / 2 - 4);
WpfCanvas.SetTop(BottomControl, rect.Bottom - 4);
WpfCanvas.SetLeft(LeftControl, rect.Left - 4);
WpfCanvas.SetTop(LeftControl, rect.Top + rect.Height / 2 - 4);
WpfCanvas.SetLeft(RightControl, rect.Right - 4);
WpfCanvas.SetTop(RightControl, rect.Top + rect.Height / 2 - 4);
}
private void UpdateSelection()
{
var rect = GetSelectionRectangle();
@@ -262,6 +510,56 @@ namespace Ink_Canvas
SelectionRectangle.Width = rect.Width;
SelectionRectangle.Height = rect.Height;
// 更新透明选择区域遮罩
UpdateTransparentSelectionMask(rect);
// 更新尺寸信息
SizeInfoText.Text = $"{(int)rect.Width} x {(int)rect.Height}";
WpfCanvas.SetLeft(SizeInfoBorder, rect.X);
WpfCanvas.SetTop(SizeInfoBorder, rect.Y - 30);
// 确保尺寸信息不超出屏幕
if (WpfCanvas.GetTop(SizeInfoBorder) < 0)
{
WpfCanvas.SetTop(SizeInfoBorder, rect.Y + rect.Height + 5);
}
}
private void UpdateTransparentSelectionMask(Rect selectionRect)
{
try
{
// 更新选择区域的几何体
SelectionClipGeometry.Rect = selectionRect;
// 显示透明遮罩,隐藏原始遮罩
TransparentSelectionMask.Visibility = Visibility.Visible;
OverlayRectangle.Visibility = Visibility.Collapsed;
}
catch (Exception ex)
{
// 如果几何体操作失败,回退到原始遮罩
TransparentSelectionMask.Visibility = Visibility.Collapsed;
OverlayRectangle.Visibility = Visibility.Visible;
}
}
private void UpdateSelectionDisplay()
{
var rect = _currentSelection;
// 更新选择矩形
WpfCanvas.SetLeft(SelectionRectangle, rect.X);
WpfCanvas.SetTop(SelectionRectangle, rect.Y);
SelectionRectangle.Width = rect.Width;
SelectionRectangle.Height = rect.Height;
// 更新透明选择区域遮罩
UpdateTransparentSelectionMask(rect);
// 更新控制点位置
UpdateControlPointsPosition();
// 更新尺寸信息
SizeInfoText.Text = $"{(int)rect.Width} x {(int)rect.Height}";
WpfCanvas.SetLeft(SizeInfoBorder, rect.X);
@@ -284,6 +582,40 @@ namespace Ink_Canvas
return new Rect(x, y, width, height);
}
private void ConfirmSelection()
{
// 在自由绘制模式下,不执行确认操作
if (_isFreehandMode)
{
return;
}
if (_isAdjusting)
{
// 转换为屏幕坐标,考虑DPI缩放
var dpiScale = GetDpiScale();
var virtualScreen = SystemInformation.VirtualScreen;
// 计算实际屏幕坐标
int screenX = (int)((_currentSelection.X * dpiScale) + virtualScreen.Left);
int screenY = (int)((_currentSelection.Y * dpiScale) + virtualScreen.Top);
int screenWidth = (int)(_currentSelection.Width * dpiScale);
int screenHeight = (int)(_currentSelection.Height * dpiScale);
SelectedArea = new DrawingRectangle(screenX, screenY, screenWidth, screenHeight);
DialogResult = true;
}
Close();
}
private void CancelSelection()
{
SelectedArea = null;
SelectedPath = null;
DialogResult = false;
Close();
}
private Rect CalculatePathBounds(List<Point> points)
{
if (points == null || points.Count == 0)
@@ -305,54 +637,70 @@ namespace Ink_Canvas
return new Rect(minX, minY, maxX - minX, maxY - minY);
}
// 优化路径:移除重复点和过于接近的点,提高路径质量
private List<Point> OptimizePath(List<Point> originalPath)
private List<Point> OptimizePath(List<Point> points)
{
if (originalPath == null || originalPath.Count < 3)
return originalPath;
if (points == null || points.Count < 3)
return points;
var optimizedPath = new List<Point>();
const double minDistance = 2.0; // 最小距离阈值
var optimized = new List<Point>();
optimized.Add(points[0]);
// 添加第一个点
optimizedPath.Add(originalPath[0]);
for (int i = 1; i < originalPath.Count - 1; i++)
for (int i = 1; i < points.Count - 1; i++)
{
var currentPoint = originalPath[i];
var optimizedPoint = optimizedPath[optimizedPath.Count - 1];
var prev = points[i - 1];
var current = points[i];
var next = points[i + 1];
// 计算与上一个优化点的距离
double distance = Math.Sqrt(
Math.Pow(currentPoint.X - optimizedPoint.X, 2) +
Math.Pow(currentPoint.Y - optimizedPoint.Y, 2));
// 计算当前点到前后两点连线的距离
var distance = DistanceToLine(current, prev, next);
// 如果距离足够大,则添加这个点
if (distance >= minDistance)
// 如果距离大于阈值,保留这个点
if (distance > 2.0)
{
optimizedPath.Add(currentPoint);
optimized.Add(current);
}
}
// 添加最后一个点(如果与上一个点距离足够)
var lastPoint = originalPath[originalPath.Count - 1];
var lastOptimizedPoint = optimizedPath[optimizedPath.Count - 1];
double finalDistance = Math.Sqrt(
Math.Pow(lastPoint.X - lastOptimizedPoint.X, 2) +
Math.Pow(lastPoint.Y - lastOptimizedPoint.Y, 2));
optimized.Add(points[points.Count - 1]);
return optimized;
}
if (finalDistance >= minDistance)
private double DistanceToLine(Point point, Point lineStart, Point lineEnd)
{
var A = point.X - lineStart.X;
var B = point.Y - lineStart.Y;
var C = lineEnd.X - lineStart.X;
var D = lineEnd.Y - lineStart.Y;
var dot = A * C + B * D;
var lenSq = C * C + D * D;
if (lenSq == 0) return Math.Sqrt(A * A + B * B);
var param = dot / lenSq;
double xx, yy;
if (param < 0)
{
optimizedPath.Add(lastPoint);
xx = lineStart.X;
yy = lineStart.Y;
}
else if (param > 1)
{
xx = lineEnd.X;
yy = lineEnd.Y;
}
else
{
xx = lineStart.X + param * C;
yy = lineStart.Y + param * D;
}
// 确保路径至少有3个点
if (optimizedPath.Count < 3)
{
return originalPath;
}
var dx = point.X - xx;
var dy = point.Y - yy;
return optimizedPath;
return Math.Sqrt(dx * dx + dy * dy);
}
}
}