在不同尺寸的 inkcanvas 之间复制墨迹笔划
Copying ink strokes between inkcanvas with different sizes
我正在尝试在不同的 inkcanvas 之间复制笔迹。
到目前为止,这就是我的尝试。
///Getting strokes from the first inkcanvas
public StrokeCollection MyStrokes;
MyStrokes = BigInkCanvas.Strokes;
///Trying to restore the strokes on the other inkcanvas
SmallerInkCanvas.Strokes = MyStrokes
这就是我得到的
Result
有没有办法“调整”墨迹笔划,使其适合较小的 inkcanvas
您可以对其应用变换矩阵以缩放到新的 canvas' 边界矩形。
假设您有一个 500x250 像素 canvas。并且您希望缩放到 400x150 矩阵。
该变换在 x 轴上为 100px,在 y 轴上为 100px。
如果我们认为这是一个比例尺,它会小 20% 和 60%。
如果我们将其转换为矩阵,那么我们应该能够将该矩阵应用于笔划以缩放它们 using their PointTransform
property.(UWP) or it's .Transform()
method (WPF)
(float x, float y) originalCanvas = (500f, 250f);
(float x, float y) desiredCanvas = (400f, 150f);
(float xScale, float yScale) GetScale((float x, float y) originalSize, (float x, float y) desiredSize)
{
float xScale = (originalSize.x - desiredSize.x) / originalSize.x;
float yScale = (originalSize.y - desiredSize.y) / originalSize.y;
return (1f - xScale, 1f - yScale);
}
var scale = GetScale(originalCanvas, desiredCanvas);
// Should return (0.8, 0.6)
// uwp
var matrix = Matrix3x2.CreateScale(scale.xScale, scale.yScale, new Vector2(0, 0));
// Wpf
var matrix = Matrix.Identity.Scale(scale.xScale, scale.yScale);
// Transform the strokes
foreach(var stroke in MyStrokes)
{
// Uwp
stroke.PointTransform = matrix;
// Wpf
stroke.Transform(matrix, false);
}
SmallerInkCanvas.Strokes = MyStrokes
免责声明:未测试,在手机上编写
我正在尝试在不同的 inkcanvas 之间复制笔迹。
到目前为止,这就是我的尝试。
///Getting strokes from the first inkcanvas
public StrokeCollection MyStrokes;
MyStrokes = BigInkCanvas.Strokes;
///Trying to restore the strokes on the other inkcanvas
SmallerInkCanvas.Strokes = MyStrokes
这就是我得到的
Result
有没有办法“调整”墨迹笔划,使其适合较小的 inkcanvas
您可以对其应用变换矩阵以缩放到新的 canvas' 边界矩形。
假设您有一个 500x250 像素 canvas。并且您希望缩放到 400x150 矩阵。
该变换在 x 轴上为 100px,在 y 轴上为 100px。
如果我们认为这是一个比例尺,它会小 20% 和 60%。
如果我们将其转换为矩阵,那么我们应该能够将该矩阵应用于笔划以缩放它们 using their PointTransform
property.(UWP) or it's .Transform()
method (WPF)
(float x, float y) originalCanvas = (500f, 250f);
(float x, float y) desiredCanvas = (400f, 150f);
(float xScale, float yScale) GetScale((float x, float y) originalSize, (float x, float y) desiredSize)
{
float xScale = (originalSize.x - desiredSize.x) / originalSize.x;
float yScale = (originalSize.y - desiredSize.y) / originalSize.y;
return (1f - xScale, 1f - yScale);
}
var scale = GetScale(originalCanvas, desiredCanvas);
// Should return (0.8, 0.6)
// uwp
var matrix = Matrix3x2.CreateScale(scale.xScale, scale.yScale, new Vector2(0, 0));
// Wpf
var matrix = Matrix.Identity.Scale(scale.xScale, scale.yScale);
// Transform the strokes
foreach(var stroke in MyStrokes)
{
// Uwp
stroke.PointTransform = matrix;
// Wpf
stroke.Transform(matrix, false);
}
SmallerInkCanvas.Strokes = MyStrokes
免责声明:未测试,在手机上编写