开发者

WP7 convert StrokeCollection to PNG with MVVM?

开发者 https://www.devze.com 2023-03-16 12:12 出处:网络
I have an InkPresenter bound to a StrokeCollection in an MVVM model that I\'m using for a signature panel. Before I send the data back to the server I want to convert the StrokeCollection to PNG data,

I have an InkPresenter bound to a StrokeCollection in an MVVM model that I'm using for a signature panel. Before I send the data back to the server I want to convert the StrokeCollection to PNG data, here is what I have (I'm using 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.Enco开发者_如何转开发de(myImage, stream);
}

The stream is always just filled with 0's, I feel like I'm missing something really simple that I haven't thought of. Any ideas?


I think the issue is that the renderer doesn't have time to update the UI before you grab it. Try wrapping the bitmap creation to a Dispatcher.BeginInvoke call.

0

精彩评论

暂无评论...
验证码 换一张
取 消