improve:墨迹延迟

This commit is contained in:
2025-09-13 21:38:03 +08:00
parent ec3bcddc9d
commit 5361f8ae6f
10 changed files with 79 additions and 45 deletions
+11 -11
View File
@@ -28,9 +28,9 @@ namespace Ink_Canvas
public Rectangle Area;
public List<Point> Path;
public Bitmap CameraImage;
public System.Windows.Media.Imaging.BitmapSource CameraBitmapSource;
public BitmapSource CameraBitmapSource;
public ScreenshotResult(Rectangle area, List<Point> path = null, Bitmap cameraImage = null, System.Windows.Media.Imaging.BitmapSource cameraBitmapSource = null)
public ScreenshotResult(Rectangle area, List<Point> path = null, Bitmap cameraImage = null, BitmapSource cameraBitmapSource = null)
{
Area = area;
Path = path;
@@ -327,7 +327,7 @@ namespace Ink_Canvas
}
// 将BitmapSource插入到画布(用于摄像头截图)
private async Task InsertBitmapSourceToCanvas(System.Windows.Media.Imaging.BitmapSource bitmapSource)
private async Task InsertBitmapSourceToCanvas(BitmapSource bitmapSource)
{
try
{
@@ -614,20 +614,20 @@ namespace Ink_Canvas
switch (bitmap.PixelFormat)
{
case PixelFormat.Format24bppRgb:
wpfPixelFormat = System.Windows.Media.PixelFormats.Bgr24;
wpfPixelFormat = PixelFormats.Bgr24;
break;
case PixelFormat.Format32bppArgb:
wpfPixelFormat = System.Windows.Media.PixelFormats.Bgra32;
wpfPixelFormat = PixelFormats.Bgra32;
break;
case PixelFormat.Format32bppRgb:
wpfPixelFormat = System.Windows.Media.PixelFormats.Bgr32;
wpfPixelFormat = PixelFormats.Bgr32;
break;
default:
wpfPixelFormat = System.Windows.Media.PixelFormats.Bgr24;
wpfPixelFormat = PixelFormats.Bgr24;
break;
}
var bitmapSource = System.Windows.Media.Imaging.BitmapSource.Create(
var bitmapSource = BitmapSource.Create(
bitmapData.Width,
bitmapData.Height,
bitmap.HorizontalResolution,
@@ -722,7 +722,7 @@ namespace Ink_Canvas
return null;
// 使用最基础的方法:直接保存为PNG然后加载
var tempFile = System.IO.Path.GetTempFileName() + ".png";
var tempFile = Path.GetTempFileName() + ".png";
try
{
@@ -742,9 +742,9 @@ namespace Ink_Canvas
// 清理临时文件
try
{
if (System.IO.File.Exists(tempFile))
if (File.Exists(tempFile))
{
System.IO.File.Delete(tempFile);
File.Delete(tempFile);
}
}
catch (Exception deleteEx)
+1 -4
View File
@@ -337,14 +337,11 @@ namespace Ink_Canvas
{
try
{
var stroke = GetStrokeVisual(e.StylusDevice.Id).Stroke;
// 正常模式:添加到画布并参与墨迹纠正
// 墨迹渐隐功能现在在 StrokeCollected 事件中统一处理所有输入方式
inkCanvas.Strokes.Add(stroke);
await Task.Delay(5); // 避免渲染墨迹完成前预览墨迹被删除导致墨迹闪烁
await Task.Delay(5);
inkCanvas.Children.Remove(GetVisualCanvas(e.StylusDevice.Id));
inkCanvas_StrokeCollected(inkCanvas,
+1 -1
View File
@@ -222,7 +222,7 @@ namespace Ink_Canvas
var menuItem = sender as MenuItem;
if (menuItem != null)
{
var headerPanel = menuItem.Header as iNKORE.UI.WPF.Modern.Controls.SimpleStackPanel;
var headerPanel = menuItem.Header as SimpleStackPanel;
if (headerPanel != null)
{
var textBlock = headerPanel.Children[0] as TextBlock;