From 5361f8ae6f418a353d0fcba8a7c031a6f719989a Mon Sep 17 00:00:00 2001 From: CJKmkp <2564608840@qq.com> Date: Sat, 13 Sep 2025 21:38:03 +0800 Subject: [PATCH] =?UTF-8?q?improve:=E5=A2=A8=E8=BF=B9=E5=BB=B6=E8=BF=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Ink Canvas/App.xaml.cs | 4 +- Ink Canvas/Helpers/CameraService.cs | 2 +- Ink Canvas/Helpers/InkSmoothingConfig.cs | 32 ++++++++------ Ink Canvas/Helpers/MultiTouchInput.cs | 39 ++++++++++++++++-- Ink Canvas/MainWindow.xaml | 6 +-- Ink Canvas/MainWindow_cs/MW_ImageInsert.cs | 22 +++++----- Ink Canvas/MainWindow_cs/MW_TouchEvents.cs | 5 +-- Ink Canvas/MainWindow_cs/MW_TrayIcon.cs | 2 +- .../Windows/ScreenshotSelectorWindow.xaml.cs | 12 +++--- ...vasForClass.csproj.AssemblyReference.cache | Bin 38181 -> 38044 bytes 10 files changed, 79 insertions(+), 45 deletions(-) diff --git a/Ink Canvas/App.xaml.cs b/Ink Canvas/App.xaml.cs index 9a4cc745..d465f03d 100644 --- a/Ink Canvas/App.xaml.cs +++ b/Ink Canvas/App.xaml.cs @@ -299,12 +299,12 @@ namespace Ink_Canvas try { // 获取主窗口实例并清理PowerPoint进程守护 - var mainWindow = Application.Current.MainWindow as MainWindow; + var mainWindow = Current.MainWindow as MainWindow; if (mainWindow != null) { // 通过反射调用StopPowerPointProcessMonitoring方法 var method = mainWindow.GetType().GetMethod("StopPowerPointProcessMonitoring", - System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); + BindingFlags.NonPublic | BindingFlags.Instance); method?.Invoke(mainWindow, null); WriteCrashLog("PowerPoint进程守护已在系统关机时清理"); diff --git a/Ink Canvas/Helpers/CameraService.cs b/Ink Canvas/Helpers/CameraService.cs index 0dfc7f15..da9430dc 100644 --- a/Ink Canvas/Helpers/CameraService.cs +++ b/Ink Canvas/Helpers/CameraService.cs @@ -194,7 +194,7 @@ namespace Ink_Canvas.Helpers break; } - var bitmapSource = System.Windows.Media.Imaging.BitmapSource.Create( + var bitmapSource = BitmapSource.Create( bitmapData.Width, bitmapData.Height, _currentFrame.HorizontalResolution, diff --git a/Ink Canvas/Helpers/InkSmoothingConfig.cs b/Ink Canvas/Helpers/InkSmoothingConfig.cs index dea1df70..6cb996bb 100644 --- a/Ink Canvas/Helpers/InkSmoothingConfig.cs +++ b/Ink Canvas/Helpers/InkSmoothingConfig.cs @@ -71,37 +71,43 @@ namespace Ink_Canvas.Helpers } /// - /// 应用质量设置 + /// 应用质量设置 /// public void ApplyQualitySettings() { switch (Quality) { case SmoothingQuality.Performance: - SmoothingStrength = 0.2; - ResampleInterval = 4.0; - InterpolationSteps = 6; + SmoothingStrength = 0.15; + ResampleInterval = 5.0; + InterpolationSteps = 4; UseAdaptiveInterpolation = false; - CurveTension = 0.2; + CurveTension = 0.15; MaxConcurrentTasks = Math.Max(1, Environment.ProcessorCount / 2); + UseHardwareAcceleration = true; + UseAsyncProcessing = true; break; case SmoothingQuality.Balanced: - SmoothingStrength = 0.4; - ResampleInterval = 2.5; - InterpolationSteps = 12; + SmoothingStrength = 0.3; + ResampleInterval = 3.0; + InterpolationSteps = 8; UseAdaptiveInterpolation = true; - CurveTension = 0.3; + CurveTension = 0.25; MaxConcurrentTasks = Environment.ProcessorCount; + UseHardwareAcceleration = true; + UseAsyncProcessing = true; break; case SmoothingQuality.Quality: - SmoothingStrength = 0.6; - ResampleInterval = 1.5; - InterpolationSteps = 20; + SmoothingStrength = 0.5; + ResampleInterval = 2.0; + InterpolationSteps = 15; UseAdaptiveInterpolation = true; - CurveTension = 0.4; + CurveTension = 0.35; MaxConcurrentTasks = Environment.ProcessorCount; + UseHardwareAcceleration = true; + UseAsyncProcessing = true; break; } } diff --git a/Ink Canvas/Helpers/MultiTouchInput.cs b/Ink Canvas/Helpers/MultiTouchInput.cs index d9554d19..9764d2ca 100644 --- a/Ink Canvas/Helpers/MultiTouchInput.cs +++ b/Ink Canvas/Helpers/MultiTouchInput.cs @@ -25,10 +25,14 @@ namespace Ink_Canvas.Helpers } /// - /// 用于显示笔迹的类 + /// 用于显示笔迹的类 /// public class StrokeVisual : DrawingVisual { + private bool _needsRedraw = true; + private int _lastPointCount = 0; + private const int REDRAW_THRESHOLD = 3; + /// /// 创建显示笔迹的类 /// @@ -49,15 +53,20 @@ namespace Ink_Canvas.Helpers public StrokeVisual(DrawingAttributes drawingAttributes) { _drawingAttributes = drawingAttributes; + + // 启用硬件加速 + RenderOptions.SetBitmapScalingMode(this, BitmapScalingMode.HighQuality); + RenderOptions.SetEdgeMode(this, EdgeMode.Aliased); + RenderOptions.SetCachingHint(this, CachingHint.Cache); } /// - /// 设置或获取显示的笔迹 + /// 设置或获取显示的笔迹 /// public Stroke Stroke { set; get; } /// - /// 在笔迹中添加点 + /// 在笔迹中添加点 /// /// public void Add(StylusPoint point) @@ -66,28 +75,50 @@ namespace Ink_Canvas.Helpers { var collection = new StylusPointCollection { point }; Stroke = new Stroke(collection) { DrawingAttributes = _drawingAttributes }; + _lastPointCount = 1; } else { Stroke.StylusPoints.Add(point); + _lastPointCount++; } + + // 标记需要重绘 + _needsRedraw = true; } /// - /// 重新画出笔迹 + /// 重新画出笔迹 /// public void Redraw() { + if (!_needsRedraw || Stroke == null) return; + + if (_lastPointCount % REDRAW_THRESHOLD != 0 && _lastPointCount > REDRAW_THRESHOLD) + { + return; + } + try { using (var dc = RenderOpen()) { Stroke.Draw(dc); } + _needsRedraw = false; } catch { } } + /// + /// 强制重绘 + /// + public void ForceRedraw() + { + _needsRedraw = true; + Redraw(); + } + private readonly DrawingAttributes _drawingAttributes; public static implicit operator Stroke(StrokeVisual v) diff --git a/Ink Canvas/MainWindow.xaml b/Ink Canvas/MainWindow.xaml index 2c0d6d80..187411e7 100644 --- a/Ink Canvas/MainWindow.xaml +++ b/Ink Canvas/MainWindow.xaml @@ -291,7 +291,7 @@ - + - +