improve:墨迹平滑

This commit is contained in:
2025-07-26 19:03:07 +08:00
parent ecfe05139e
commit 04b2663183
10 changed files with 1085 additions and 34 deletions
@@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Ink;
@@ -587,18 +588,27 @@ namespace Ink_Canvas {
// 检查原始笔画是否仍然存在于画布中
if (inkCanvas.Strokes.Contains(e.Stroke))
{
var advancedSmoothing = new Helpers.AdvancedBezierSmoothing
// 使用新的异步墨迹平滑管理器
if (Settings.Canvas.UseAsyncInkSmoothing && _inkSmoothingManager != null)
{
};
// 异步处理
_ = ProcessStrokeAsync(e.Stroke);
}
else
{
// 同步处理(向后兼容)
var smoothedStroke = _inkSmoothingManager?.SmoothStroke(e.Stroke) ?? e.Stroke;
var smoothedStroke = advancedSmoothing.SmoothStroke(e.Stroke);
// 替换原始笔画
SetNewBackupOfStroke();
_currentCommitType = CommitReason.ShapeRecognition;
inkCanvas.Strokes.Remove(e.Stroke);
inkCanvas.Strokes.Add(smoothedStroke);
_currentCommitType = CommitReason.UserInput;
if (smoothedStroke != e.Stroke)
{
// 替换原始笔画
SetNewBackupOfStroke();
_currentCommitType = CommitReason.ShapeRecognition;
inkCanvas.Strokes.Remove(e.Stroke);
inkCanvas.Strokes.Add(smoothedStroke);
_currentCommitType = CommitReason.UserInput;
}
}
}
}
catch (Exception ex)
@@ -613,6 +623,32 @@ namespace Ink_Canvas {
}
}
/// <summary>
/// 异步处理笔画平滑
/// </summary>
private async Task ProcessStrokeAsync(Stroke originalStroke)
{
try
{
await _inkSmoothingManager.SmoothStrokeAsync(originalStroke, (original, smoothed) =>
{
// 在UI线程上执行笔画替换
if (inkCanvas.Strokes.Contains(original) && smoothed != original)
{
SetNewBackupOfStroke();
_currentCommitType = CommitReason.ShapeRecognition;
inkCanvas.Strokes.Remove(original);
inkCanvas.Strokes.Add(smoothed);
_currentCommitType = CommitReason.UserInput;
}
});
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"异步墨迹平滑失败: {ex.Message}");
}
}
// New method: Checks if a stroke is potentially a straight line
private bool IsPotentialStraightLine(Stroke stroke) {
// 确保有足够的点来进行线条分析