Reputation: 59
I need to transmit throught the net complex object System.Windows.Ink.StrokeCollection
. How can I serialize it? This type do not implements ISerializable
interface. I am using System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
for serializing.
I already thinking about XML serialization of open field of my strokes collection and transmiting this XML as common string, but it will create a greater load on the network and affect the overall performance.
Is there any way to serialize my collection to a byte array to transmit it?
Upvotes: 0
Views: 1055
Reputation: 10865
The StrokeCollection has a Save(Stream) method which Saves the StrokeCollection to the specified Stream.
Here is a way of serializing StrokeCollection
var memoryStream = new MemoryStream();
using (memoryStream)
{
StrokeCollection strokeCollection; //Your stroke collection ommitted the declaration
strokeCollection.Save(ms);
ms.Position = 0;
}
Now when you want to deserialize it back you can pass the MemoryStream to the constructor of the StrokeCollection.
More can be found here. That's how I would do it.
Upvotes: 3