WP7 convert StrokeCollection to PNG with MVVM?

I have InkPresenter related to the StrokeCollection in the MVVM model that I use for the signature panel. Before sending the data back to the server, I want to convert the StrokeCollection data to PNG, this is what I have (I use the ImageTools library):

// Signature is a StrokesCollection var bounds = Signature.GetBounds(); var inkSignature = new InkPresenter {Height = bounds.Height, Width = bounds.Width, Strokes = Signature}; var wbBitmap = new WriteableBitmap(inkSignature, null); var myImage = wbBitmap.ToImage(); byte[] by = null; MemoryStream stream = null; using (stream = new MemoryStream()) { PngEncoder png = new PngEncoder(); png.Encode(myImage, stream); } 

The stream is always just full 0, I feel that I am missing something really simple that I did not think about. Any ideas?

+4
source share
1 answer

I think the problem is that the renderer does not have time to update the interface before you capture it. Try wrapping the creation of a bitmap with a call to Dispatcher.BeginInvoke.

+1
source

All Articles