鼠标滞后与触摸屏连接,几乎没有滞后没有



我有一个触摸屏(如果重要的话,LG 23ET83V(,我想为我3岁的女儿写一个非常基本的油漆应用程序:没有她不关心的豪华工具的广泛工具调色板(我不喜欢Tuxpaint(。只是简单的绘画。我的动力到此为止。

但通过下面的代码,我观察到了以下奇怪的行为:

  1. 在目标机器(Windows 10 Pro,2014年左右的6核AMD(上,当我用手指作画时,我的手指位置后面有一个小的绘画滞后(约0.5秒?(。只有在我的手指休息后,绘图位置才能赶上我手指的位置。

  2. 当我用鼠标画画时,较长的动作会产生令人印象深刻的滞后(约2-4秒!(。如果我停止鼠标移动,绘图位置最终会跟上。与触摸控制器在项目符号1中移动我的手指时相比,鼠标生成的mouse_MOVE事件的比率似乎并不高。

  3. 当我断开屏幕触摸控制器的USB电缆时,鼠标滞后几乎消失了。嗯,它仍然很明显,但可以接受(比如~0.25s(

  4. 当我在开发机器上用鼠标画画时(英特尔Q6600四核从2008年左右开始(,我看不到任何鼠标滞后。

如果是硬件或驱动程序相关,我可能运气不好。但在我看来,Windows似乎试图通过平均几个连续的鼠标位置来平滑触摸运动。如果这是真的,我可以控制平均值吗?关于问题的原因还有其他想法吗?

PS:当我在出现上述问题的机器上使用MS Paint时,我看不到任何滞后。所以这个问题一定是由一些与C#相关或与我使用API的特定方式相关的东西引起的

public partial class MainWindow : Window
{
WriteableBitmap bitmap;
public MainWindow()
{
InitializeComponent();
// create bitmap the size of whole screen
int bitmapWidth = Convert.ToInt32(SystemParameters.PrimaryScreenWidth);
int bitmapHeight = Convert.ToInt32(SystemParameters.PrimaryScreenHeight);
bitmap = new WriteableBitmap(bitmapWidth, bitmapHeight, 96, 96, PixelFormats.Bgra32, null);
canvasImage.Source = bitmap;
}
void plot(int x, int y, uint value)
{
// just draw one pixel for barebones testing
uint[] valueArray = new uint[1];
valueArray[0] = value;
bitmap.WritePixels(new Int32Rect(0, 0, 1, 1), valueArray, 4, x, y);
}
Point previousPosition;
void imageMouseMove(object sender, MouseEventArgs e)
{
Point currentPosition = e.GetPosition(canvasImage);
if (e.LeftButton == MouseButtonState.Pressed)
{
int x2 = (int)Math.Floor(currentPosition.X * canvasImage.Source.Width / canvasImage.ActualWidth);
int y2 = (int)Math.Floor(currentPosition.Y * canvasImage.Source.Height / canvasImage.ActualHeight);
int x1 = (int)Math.Floor(previousPosition.X * canvasImage.Source.Width / canvasImage.ActualWidth);
int y1 = (int)Math.Floor(previousPosition.Y * canvasImage.Source.Height / canvasImage.ActualHeight);
plot(x2,y2, 0xFF800000);
}
previousPosition = currentPosition;
}
void button1_Click(object sender, RoutedEventArgs e)
{
Close();
}
}

标记:

<?xml version="1.0" encoding="utf-8"?>
<Window
x:Class="Paintuition.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Paintuition"
ResizeMode="NoResize"
WindowState="Maximized"
WindowStyle="None">
<Grid>
<Image
x:Name="canvasImage"
MouseMove="imageMouseMove" />
<Button
Content="X"
x:Name="button1"
Click="button1_Click"
Background="Red"
BorderBrush="#FFFFBFBF"
FontFamily="Arial"
Foreground="White"
FontWeight="ExtraBold"
FontSize="54"
Width="66"
Height="65"
Grid.Column="0"
Grid.Row="0"
HorizontalAlignment="Right"
VerticalAlignment="Top"
Margin="0,42,34,0" />
</Grid>
</Window>

可惜没有人知道这个问题的原因。虽然我没有真正的解决方案,但我使用了以下变通方法(为了让任何想和我做同样事情的人都受益,比如为小孩子画画(:

我现在求助于Gimp,它允许许多或多或少对儿童友好的定制:

  1. 主工具箱可以隐藏除画笔和橡皮擦之外的所有工具
  2. 设置在色轮上的"color"可固定工具栏对儿童非常友好,否则使用相同的工具栏可以访问带有一些彩虹颜色的自定义调色板,甚至对儿童更友好;将浮动工具栏调整为合理大小
  3. 我唯一使用的另一个工具栏是笔刷工具栏,在那里我删除了除最基本的圆形高斯笔刷外的所有笔刷(奇怪的是,其他笔刷只能在文件系统中删除(
  4. 以全屏模式启动应用程序

不幸的是,即使在这种简单的设置中,仍然有一些手柄/菜单/手势会给摇晃的孩子的手指带来意想不到的效果,例如,取消固定/移动工具栏、交换前景色/背景色等。但它至少与小孩子的绘图程序一样接近。

相关内容

最新更新