Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WP7是否使用MVVM将StrokeCollection转换为PNG?_C#_Silverlight_Windows Phone 7_Mvvm_Windows Phone - Fatal编程技术网

C# WP7是否使用MVVM将StrokeCollection转换为PNG?

C# WP7是否使用MVVM将StrokeCollection转换为PNG?,c#,silverlight,windows-phone-7,mvvm,windows-phone,C#,Silverlight,Windows Phone 7,Mvvm,Windows Phone,我有一个InkPresenter绑定到MVVM模型中的StrokeCollection,我将其用于签名面板。在将数据发送回服务器之前,我想将StrokeCollection转换为PNG数据,以下是我的资料(我正在使用ImageTools库): 流总是充满了0,我觉得我错过了一些我没有想到的简单的东西。有什么想法吗?我认为问题在于渲染器在抓取UI之前没有时间更新UI。尝试将位图创建包装到Dispatcher.BeginInvoke调用 // Signature is a StrokesCollec

我有一个InkPresenter绑定到MVVM模型中的StrokeCollection,我将其用于签名面板。在将数据发送回服务器之前,我想将StrokeCollection转换为PNG数据,以下是我的资料(我正在使用ImageTools库):


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

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

// 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);
}