InkCanvas 上的重做功能
Redo functionality on InkCanvas
我正在使用 windows 10 build 14939 中的 InkCanvas
和 InkToolBar
来捕获用户墨迹笔划。
我想用 Undo/Redo 做一个自定义按钮,但是我无法创建以下按钮:
private static InkStroke CreateStroke(List<InkPoint> redoInkPoints) {
var strokeBuilder = new InkStrokeBuilder();
Matrix3x2 matr = new Matrix3x2();
return strokeBuilder.CreateStrokeFromInkPoints(redoInkPoints, matr);
}
然而 visual studio 对
的 matr 变量的抱怨
'Argment type 'System.Numerics.Matrix3x2' is not assignable to parameter type 'Windows.Foundation.Numerics.Matrix3x2'
即使我的代码中没有任何地方引用 windows.foundation.numerics.matrix3x2.
有人知道我如何使用 CreateStrokeFromInkPoints
吗?
根据您的代码,我认为这里的问题是您在表示单位矩阵的 InkStrokeBuilder.CreateStrokeFromInkPoints method. While using Matrix3x2 matr = new Matrix3x2();
, you are creating a zero matrix. It would collapse all your points into a singularity, which is not a valid value here. To fix this issue, you may use System.Numerics.Matrix3x2.Identity 属性 中使用了错误的矩阵。以下是一个简单的示例:
XAML:
<StackPanel>
<InkCanvas x:Name="inkCanvas" Width="500" Height="200" />
<Button Click="Button_Click">Add a stroke</Button>
</StackPanel>
代码隐藏:
private void Button_Click(object sender, RoutedEventArgs e)
{
List<InkPoint> inkPoints = new List<InkPoint> { new InkPoint(new Point(10, 10), 0.5f), new InkPoint(new Point(100, 100), 0.5f) };
InkStroke stroke = CreateStroke(inkPoints);
inkCanvas.InkPresenter.StrokeContainer.AddStroke(stroke);
}
private static InkStroke CreateStroke(List<InkPoint> redoInkPoints)
{
var strokeBuilder = new InkStrokeBuilder();
System.Numerics.Matrix3x2 matr = System.Numerics.Matrix3x2.Identity;
return strokeBuilder.CreateStrokeFromInkPoints(redoInkPoints, matr);
}
我正在使用 windows 10 build 14939 中的 InkCanvas
和 InkToolBar
来捕获用户墨迹笔划。
我想用 Undo/Redo 做一个自定义按钮,但是我无法创建以下按钮:
private static InkStroke CreateStroke(List<InkPoint> redoInkPoints) {
var strokeBuilder = new InkStrokeBuilder();
Matrix3x2 matr = new Matrix3x2();
return strokeBuilder.CreateStrokeFromInkPoints(redoInkPoints, matr);
}
然而 visual studio 对
的 matr 变量的抱怨'Argment type 'System.Numerics.Matrix3x2' is not assignable to parameter type 'Windows.Foundation.Numerics.Matrix3x2'
即使我的代码中没有任何地方引用 windows.foundation.numerics.matrix3x2.
有人知道我如何使用 CreateStrokeFromInkPoints
吗?
根据您的代码,我认为这里的问题是您在表示单位矩阵的 InkStrokeBuilder.CreateStrokeFromInkPoints method. While using Matrix3x2 matr = new Matrix3x2();
, you are creating a zero matrix. It would collapse all your points into a singularity, which is not a valid value here. To fix this issue, you may use System.Numerics.Matrix3x2.Identity 属性 中使用了错误的矩阵。以下是一个简单的示例:
XAML:
<StackPanel>
<InkCanvas x:Name="inkCanvas" Width="500" Height="200" />
<Button Click="Button_Click">Add a stroke</Button>
</StackPanel>
代码隐藏:
private void Button_Click(object sender, RoutedEventArgs e)
{
List<InkPoint> inkPoints = new List<InkPoint> { new InkPoint(new Point(10, 10), 0.5f), new InkPoint(new Point(100, 100), 0.5f) };
InkStroke stroke = CreateStroke(inkPoints);
inkCanvas.InkPresenter.StrokeContainer.AddStroke(stroke);
}
private static InkStroke CreateStroke(List<InkPoint> redoInkPoints)
{
var strokeBuilder = new InkStrokeBuilder();
System.Numerics.Matrix3x2 matr = System.Numerics.Matrix3x2.Identity;
return strokeBuilder.CreateStrokeFromInkPoints(redoInkPoints, matr);
}