优化代码

This commit is contained in:
2026-05-01 20:37:39 +08:00
parent db181d994a
commit 02cf10ab13
8 changed files with 23 additions and 20 deletions
@@ -272,21 +272,21 @@ namespace Ink_Canvas
/// - 显示通知
/// - 包含异常处理
/// </remarks>
private async Task PasteImageFromClipboard(Point? position = null)
private Task PasteImageFromClipboard(Point? position = null)
{
try
{
if (!Clipboard.ContainsImage())
{
ShowNotification("剪贴板中没有图片");
return;
return Task.CompletedTask;
}
var clipboardImage = Clipboard.GetImage();
if (clipboardImage == null)
{
ShowNotification("无法获取剪贴板图片");
return;
return Task.CompletedTask;
}
// 创建Image控件
@@ -383,6 +383,7 @@ namespace Ink_Canvas
ShowNotification($"粘贴图片失败: {ex.Message}");
LogHelper.WriteLogToFile($"粘贴图片失败: {ex.Message}", LogHelper.LogType.Error);
}
return Task.CompletedTask;
}
+6 -4
View File
@@ -496,7 +496,7 @@ namespace Ink_Canvas
/// 10. 提交历史记录
/// 11. 插入图片后切换到选择模式并刷新浮动栏高光显示
/// </remarks>
private async Task InsertScreenshotToCanvas(Bitmap bitmap)
private Task InsertScreenshotToCanvas(Bitmap bitmap)
{
try
{
@@ -504,7 +504,7 @@ namespace Ink_Canvas
if (bitmap == null || bitmap.Width <= 0 || bitmap.Height <= 0)
{
ShowNotification("无效的截图");
return;
return Task.CompletedTask;
}
// 将Bitmap转换为WPF BitmapSource
@@ -513,7 +513,7 @@ namespace Ink_Canvas
if (bitmapSource == null)
{
ShowNotification("转换截图失败");
return;
return Task.CompletedTask;
}
// 创建WPF Image控件
@@ -572,6 +572,7 @@ namespace Ink_Canvas
{
bitmap?.Dispose();
}
return Task.CompletedTask;
}
/// <summary>
@@ -591,7 +592,7 @@ namespace Ink_Canvas
/// 8. 提交历史记录
/// 9. 插入图片后切换到选择模式并刷新浮动栏高光显示
/// </remarks>
private async Task InsertBitmapSourceToCanvas(BitmapSource bitmapSource, string successMessage = "截图已插入到画布", string failureMessagePrefix = "插入截图失败")
private Task InsertBitmapSourceToCanvas(BitmapSource bitmapSource, string successMessage = "截图已插入到画布", string failureMessagePrefix = "插入截图失败")
{
try
{
@@ -647,6 +648,7 @@ namespace Ink_Canvas
ShowNotification($"{failureMessagePrefix}: {ex.Message}");
LogHelper.WriteLogToFile($"插入摄像头截图失败: {ex.Message}", LogHelper.LogType.Error);
}
return Task.CompletedTask;
}
/// <summary>
+1 -1
View File
@@ -592,7 +592,7 @@ namespace Ink_Canvas
{
// 先展开浮动栏,然后进入批注状态
// UnFoldFloatingBar 方法内部会根据设置自动进入批注模式
UnFoldFloatingBar(null);
_ = UnFoldFloatingBar(null);
}
else
{