从 Web URI 获取 BitmapImage

发布于 2024-10-12 17:21:16 字数 217 浏览 7 评论 0原文

我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情未る 2024-10-19 17:21:16

为了使用 StreamBitmapImage 提供内容,您可以使用默认构造函数创建一个实例,然后调用 SetSource 传递流:-

  var bi = new BitmapImage();
  bi.SetSource(myStream);

不过我认为你可能在这里重新发明轮子。看一下下面的链接:-

保持低调(LowProfileImageLoader 通过加载帮助 Windows Phone 7 UI 线程保持响应背景图像

In order to use a Stream to provide the content for a BitmapImage you create an instance using the default constructor then call SetSource passing the stream:-

  var bi = new BitmapImage();
  bi.SetSource(myStream);

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

拒绝两难 2024-10-19 17:21:16

您仍在使用 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文