我使用此代码从Internet获取图像
var image = new BitmapImage();
image.BeginInit();
image.CacheOption = BitmapCacheOption.OnLoad;
image.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
image.UriSource = new Uri(url, UriKind.Absolute);
image.EndInit();
RSSImage.Source = image;有时没有图像。
这似乎是由于超时等原因造成的。
无论如何,我使用了一些异步。及时获取图像的方法?
有什么线索吗?
发布于 2012-11-16 19:56:27
异步加载镜像(C# 5.0和.NET Framework4.5):
using (var client = new WebClient()) {
var bytes = await client.DownloadDataTaskAsync(url);
var image = new BitmapImage();
image.BeginInit();
image.CacheOption = BitmapCacheOption.OnLoad;
image.StreamSource = new MemoryStream(bytes);
image.EndInit();
RSSImage.Source = image;
}https://stackoverflow.com/questions/13415471
复制相似问题