【问题标题】:WP7 convert StrokeCollection to PNG with MVVM?WP7 使用 MVVM 将 StrokeCollection 转换为 PNG?
【发布时间】:2011-09-24 12:35:59
【问题描述】:

我有一个 InkPresenter 绑定到我用于签名面板的 MVVM 模型中的 StrokeCollection。在将数据发送回服务器之前,我想将 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);
}

流总是用 0 填充,我觉得我错过了一些我没有想到的非常简单的东西。有什么想法吗?

【问题讨论】:

    标签: c# silverlight windows-phone-7 mvvm windows-phone


    【解决方案1】:

    我认为问题在于渲染器在您抓取它之前没有时间更新 UI。尝试将位图创建包装到 Dispatcher.BeginInvoke 调用中。

    【讨论】:

      猜你喜欢
      • 2012-05-31
      • 2011-06-11
      • 2021-06-15
      • 2020-06-14
      • 2013-12-27
      • 2017-09-01
      • 2011-02-21
      • 2011-04-26
      • 2013-06-05
      相关资源
      最近更新 更多