简体   繁体   English

WP7 使用 MVVM 将 StrokeCollection 转换为 PNG?

[英]WP7 convert StrokeCollection to PNG with MVVM?

I have an InkPresenter bound to a StrokeCollection in an MVVM model that I'm using for a signature panel.我有一个 InkPresenter 绑定到我用于签名面板的 MVVM model 中的 StrokeCollection。 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):在我将数据发送回服务器之前,我想将 StrokeCollection 转换为 PNG 数据,这就是我所拥有的(我正在使用 ImageTools 库):

// 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 filled with 0's, I feel like I'm missing something really simple that I haven't thought of. stream 总是用 0 填充,我觉得我错过了一些我没有想到的非常简单的东西。 Any ideas?有任何想法吗?

I think the issue is that the renderer doesn't have time to update the UI before you grab it.我认为问题在于渲染器在您抓取它之前没有时间更新 UI。 Try wrapping the bitmap creation to a Dispatcher.BeginInvoke call.尝试将 bitmap 创建包装到 Dispatcher.BeginInvoke 调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM