从 Web URI 获取 BitmapImage
我的 Windows Phone 应用程序中有几个绑定到 uri 的图像,这会导致下载所有图像时 UI 威胁被阻止。我无法在不同的线程上创建 bitmapImage 实例,因为我会收到“无效的跨线程操作”异常。
我尝试使用 WebClient 下载图像,但没有接受 BitmapImage 流的构造函数。
有没有想过如何在后台完成下载图像?
谢谢阿米特
I have in my Windows Phone app several images that are binded to uri's this causes the UI threa to get blocked when all the images are downloaded. I cant create a bitmapImage instance on a different thread because I would get an "Invalid cross thread operation" exeption.
I tried downloading the image using a WebClient but there is no constructor that accepts a stream for BitmapImage.
Any thought as to how I can accomplish downloading images in the background?
thanks
Amit
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了使用
Stream
为BitmapImage
提供内容,您可以使用默认构造函数创建一个实例,然后调用SetSource
传递流:-不过我认为你可能在这里重新发明轮子。看一下下面的链接:-
保持低调(LowProfileImageLoader 通过加载帮助 Windows Phone 7 UI 线程保持响应背景图像
In order to use a
Stream
to provide the content for aBitmapImage
you create an instance using the default constructor then callSetSource
passing the stream:-However I think you may be re-inventing the wheel here. Take a look the link below:-
Keep a low profile (LowProfileImageLoader helps the Windows Phone 7 UI thread stay responsive by loading images in the background
您仍在使用 WebClient 的 UI 线程上。如果您继续采用这种方法,您还可以考虑 HttpWebRequest。这是一个工作示例,包括无效跨线程访问异常的解决方案。
WebClient、HttpWebRequest 和 UI 线程在 Windows Phone 7 上
You're still on the UI thread using WebClient. If you continue with that approach, you can also consider HttpWebRequest. Here's a working sample including resolution for the invalid cross-thread access exception.
WebClient, HttpWebRequest and the UI Thread on Windows Phone 7