我有一个 PNG 文件存储在我的云中的 blob 存储中,我想下载它并在 WPF 中将其渲染在屏幕上。
我知道调度程序和冻结,但没有任何作用。我不断收到有关“另一个线程拥有它”的错误。
这是我所拥有的:
var decoder = GetDecoder("http://address/image.png");
Dispatcher.Invoke(DispatcherPriority.Send, new Action<BitmapFrame>(SetImage), decoder.Frames[0]);
public void SetImage(BitmapFrame source)
{
var bitmapFrame = BitmapFrame.Create(source); //ERROR HERE!!!!!!!!
LazyImage.Source = bitmapFrame;
}
private BitmapDecoder GetDecoder(object uri)
{
var extension = System.IO.Path.GetExtension((string)uri);
BitmapDecoder decoder = null;
if (extension.ToLower() == ".png")
decoder = BitmapDecoder.Create(new Uri((string)uri, UriKind.Absolute), BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad);
return decoder;
}
如果我尝试冻结 Frame[0],我会收到一个异常,提示该 Frame 无法冻结。也是由返回的解码器BitmapDecoder.Create
is not a PngBitmapDecoder
but a LateBoundBitmapDecoder
我真的不知道如何有效地使用它。
简而言之:尝试将结果包装成WriteableBitmap
.
故事很长,有代码。 http://modosansreves-coding.blogspot.com/2011/12/jpegbitmapencoder-and-tlp-finally-got.html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)