Amit Raz
Amit Raz

Reputation: 5536

get BitmapImage from Web URI

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

Upvotes: 1

Views: 978

Answers (2)

Mick N
Mick N

Reputation: 14882

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

Upvotes: 0

AnthonyWJones
AnthonyWJones

Reputation: 189525

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

Upvotes: 2

Related Questions