I want to draw something with my wacom graphic tablet on a canvas. I've written some code and I can draw very well with the mouse. However, with the wacom graphic tablet, it only works sometimes and slower. The problem is the OnMouseDown event which is only detected after a considerable time delay.
Here is my code:
public partial class MainWindow : Window
{
private Polyline myPolyline;
private Boolean isMouseDown;
public MainWindow()
{
InitializeComponent();
}
private void OnMouseDown(object sender, MouseButtonEventArgs e)
{
isMouseDown = true;
Point p = e.GetPosition(mycanvas);
myPolyline = new Polyline();
myPolyline.Stroke = System.Windows.Media.Brushes.SlateGray;
myPolyline.StrokeThickness = 2;
myPolyline.FillRule = FillRule.EvenOdd;
PointCollection myPointCollection = new PointCollection();
myPointCollection.Add(p);
myPolyline.Points = myPointCollection;
mycanvas.Children.Add(myPolyline);
}
private void OnMouseUp(object sender, MouseButtonEventArgs e)
{
isMouseDown = false;
}
private void OnMouseMove(object sender, MouseEventArgs e)
{
Point p = e.GetPosition(mycanvas);
if (!isMouseDown)
{
return;
}
myPolyline.Points.Add(p);
}
}
And here is the xaml
<Window x:Class="WpfApp1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp1"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<StackPanel>
<Canvas Background="Azure" x:Name="mycanvas" Width="800" Height="450" MouseDown="OnMouseDown" MouseUp="OnMouseUp" MouseMove="OnMouseMove" ></Canvas>
</StackPanel>
Your code is using MouseButtonEventArgs and MouseEventArgs instead of the Wacom-specific event argument types.
You can try to replace your existing mouse event handlers with the API provided by Wacom.
Wacom provides dedicated APIs on several platforms that allow you to directly access Wacom tablets.
For example, on Windows, you can use the Ink API provided by Wacom to access Wacom graphics tablets.
This API provides all events and data related to Wacom tablets. Using the Ink API can help you respond to Wacom tablet events faster and use more precise data to control the brush.
Maybe you can refer to this link.