在流中保存和加载 Ink Canvas StrokeCollection [英] Save and load Ink Canvas StrokeCollection to/from stream
问题描述
我正在尝试在 WPF 中序列化墨水画布.所以我使用 StrokeCollection.Save
将笔画保存到 MemoryStream
.但是,当我尝试将流加载到 InkCanvas
中时,我收到一个 ArgumentException
说明ISF 数据的长度必须大于零."
这是代码示例:
I'm trying to serialize an ink canvas in WPF. So I'm using StrokeCollection.Save
to save the strokes to a MemoryStream
. But when I try to load the stream into the InkCanvas
I get an ArgumentException
stating "The length of the ISF data must be greater than zero."
Here's the code sample:
using (MemoryStream ms = new MemoryStream())
{
inkcanvas.Strokes.Save(ms);
inkcanvas.Strokes = new System.Windows.Ink.StrokeCollection(ms);
}
我在这里遗漏了什么?
推荐答案
您是否检查了 Position
你的流?
Did you check the Position
of the your stream?
我认为将笔画保存到其中后,它会指向它的结尾.
尝试将位置重置为第一个字符,如下所示:
I think that after saving the stroke into it it will point to the end of it.
Try to reset the position to the first character, like this:
using (MemoryStream ms = new MemoryStream())
{
inkcanvas.Strokes.Save(ms);
ms.Position = 0;
inkcanvas.Strokes = new System.Windows.Ink.StrokeCollection(ms);
}
这篇关于在流中保存和加载 Ink Canvas StrokeCollection的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!