保存并将InkCanvas中的笔划加载到变量

时间:2017-11-15 13:07:53

标签: c# uwp

我需要将InkCanvas的所有笔划保存在变量(不是文件)中,然后在用户需要时将其加载到InkCanvas中。问题是每次我尝试加载笔划时都会收到未知错误。

这是我用来加载它们的代码:

            foreach (InkStroke stroke in StrokesList)
        {
            var strokeBuilder = new InkStrokeBuilder();
            strokeBuilder.SetDefaultDrawingAttributes(stroke.DrawingAttributes);
            System.Numerics.Matrix3x2 matr = stroke.PointTransform;
            IReadOnlyList<InkPoint> inkPoints = stroke.GetInkPoints();
            InkStroke stk = strokeBuilder.CreateStrokeFromInkPoints(inkPoints, matr);
            InkCanvas.InkPresenter.StrokeContainer.AddStroke(stk);
        }

我也试过了InkCanvas.InkPresenter.StrokeContainer.AddStrokes(StrokesList);,但它无效

编辑:我正在保存这样的笔画:IReadOnlyList<InkStroke> StrokesList = inkCanvas.InkPresenter.StrokeContainer.GetStrokes();

1 个答案:

答案 0 :(得分:1)

如果您只需要存储然后恢复笔画,我建议您使用StrokeContainer.SaveAsyncInMemoryRandomAccessStream,然后只需加载StrokeContainer.LoadAsync