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]
# 1
I found an MSDN article, the one on the Sudoku application http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dntablet/html/tbconSudokuSampleFinal.asp , and it suggested using an integer array: int[] stroke = e.Stroke.GetPacketData(); You can then serialize this and do what you need to. Why isn't the Stroke object serializable again? Or why can't you serialize collections without saving out the format? Just wondering, still pretty new to this. Any further insight is greatly appreciated! Thanks!
rcurrie at 2007-10-8 > top of Msdn Tech,Software Development for Windows Vista,Notebook, Tablet PC, and UMPC Development...
# 2
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.
MichaelLatta at 2007-10-8 > top of Msdn Tech,Software Development for Windows Vista,Notebook, Tablet PC, and UMPC Development...
# 3

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?

rcurrie at 2007-10-8 > top of Msdn Tech,Software Development for Windows Vista,Notebook, Tablet PC, and UMPC Development...
# 4
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.
MichaelLatta at 2007-10-8 > top of Msdn Tech,Software Development for Windows Vista,Notebook, Tablet PC, and UMPC Development...
# 5

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!

rcurrie at 2007-10-8 > top of Msdn Tech,Software Development for Windows Vista,Notebook, Tablet PC, and UMPC Development...
# 6
I am not sure, since my use has been with WPF. If I run accross something I will post it.
MichaelLatta at 2007-10-8 > top of Msdn Tech,Software Development for Windows Vista,Notebook, Tablet PC, and UMPC Development...
# 7

Hi,

you can serialize an individual stroke by copying it into its own temporary Ink object. Then you can call Save() on that Ink object - see code below:

byte[] SaveSingleStroke(Stroke strokeToSave)
{
Ink tempInk = newInk();
Strokes strokesToSave = strokeToSave.Ink.CreateStrokes();
strokesToSave.Add(strokeToSave);
tempInk.AddStrokesAtRectangle(strokesToSave, strokesToSave.GetBoundingBox());
return tempInk.Save();
}

Thanks, Stefan Wick

StefanWick-MSFT at 2007-10-8 > top of Msdn Tech,Software Development for Windows Vista,Notebook, Tablet PC, and UMPC Development...
# 8

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. :)

rcurrie at 2007-10-8 > top of Msdn Tech,Software Development for Windows Vista,Notebook, Tablet PC, and UMPC Development...
# 9
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?
rcurrie at 2007-10-8 > top of Msdn Tech,Software Development for Windows Vista,Notebook, Tablet PC, and UMPC Development...
# 10

You can use the AddStrokesAtRectangle method to transfer a single stroke from one Ink object to another. This is the same approach I was using in the code snippet above.

Stefan Wick

StefanWick-MSFT at 2007-10-8 > top of Msdn Tech,Software Development for Windows Vista,Notebook, Tablet PC, and UMPC Development...
# 11
Thank you again Stefan!
rcurrie at 2007-10-8 > top of Msdn Tech,Software Development for Windows Vista,Notebook, Tablet PC, and UMPC Development...

Software Development for Windows Vista

Site Classified