i want to save a Stroke in a memorystream
for this purpose is used BinaryFormatter but when i try to serialize Stroke i get a error that i can’t serialize Stroke
is there any way to save a Stroke in a memorystream or serialize Stroke?
here is one part of my code
int size = inkCanvas1.Strokes.Count();
IFormatter formatter = new BinaryFormatter();
MemoryStream stream = new MemoryStream();
if (size != 0)
{
try
{
formatter.Serialize(stream, inkCanvas1.Strokes[size - 1]);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
thanks.
The reason that this doesn’t work is that
StrokeCollectiondoesn’t have theSerializableAttributeapplied.But you can use the
StrokeCollection.Savemethod for this.And then when you need the
StrokeCollectionagain, you can use the constructor that accepts aStream.