How to Serialize individual Ink Strokes?
Hello,
I am just wondering how to serialize individual ink strokes. When I attempt to I catch an exception stating that the Ink.Stroke object is non-serializable. I would love to not have to save the Ink object and serialize the entire thing, but instead simple grab a single stroke and serialize it. Does anyone have any information that may help with this?
Thanks again!
[399 byte] By [
rcurrie] at [2007-12-24]
There is actually a cleaner solution. Look on StrokeCollection for something like Load or Save. I do not have VS accessible at the moment, but you can place a stroke in a StrokeCollection and serialize that in standard stoke format that would be readable by any of the ink enabled applications, then do the reverse to get a stroke collection back. If you need to also serialize the ink analysis data that gets a bit more complex but still doable. I will try to get around to a post about that, but no promises.
What I have been doing is saving the Ink data into InkSerializedFormat: Ink.Save(). And then using that with an ink overlay to by deleting all the strokes and then inkOverlay.Ink.Load(...) my serialized byte[] from the .Save() method above. For the majority of the time the collections are identical except that I am adding a stroke one at a time. Thus with this method I am basically serializing the entire Ink data collection for each stroke. Thus why i was wondering if I could do one at a time. I am still trying the .GetPacketData() approach, but am running into a few road blocks, mainly that I have to include a TabletPropertyDescriptionCollection with each Stroke that I get packet data from. Thank you for the response, i will check it out!
By the way, how do I get access to the StrokeCollection object? Sorry for the basic question. Is this incorporated into WPF or the TabletPC SDK v1.7?
You can listen for the stroke added event and place the stroke in a StrokeCollection you create that has only that stroke, then serialize that data to get just one stroke at a time. Then you deserliaize the stroke collection and move the stroke to the InkCanvas for display. I am using this method with WCF peer channel to get strokes shared between a collection of applications all acting as a colaborative white board.
Thanks for the continued help! The StrokeCollection is only available in C# 3.0 in the System.Windows.Ink namespace correct? I'm curently simply running with C# 2.0 and the TabletPC SDK v1.7, Microsoft.Ink. Is there any way to accomplish the same thing using this setup?
Thanks again!
Thanks for the code. I tried using the GetPacketData() method above, but TabeltPropertyDescriptionCollection is also a non serializable object.
I had done something similar to above with the Ink data, so looks like I'll be doing that. Thanks again. :)
Now that we have an Ink object with just one stroke, how do we transfer that stroke to an already existing Ink object hat has strokes? I'm running into a few issues and was just wondering if there was something straightforward that I'm simply missing?