Reputation: 12216
Is it possible to set the source of an image in WP7 to a stream? Normally I'd use BitmapImage to do this in Silverlight but I don't see that option in WP7. Here's my code:
var request = WebRequest.CreateHttp("http://10.1.1.1/image.jpg");
request.Credentials = new NetworkCredential("user", "password");
request.BeginGetResponse(result =>
{
var response = request.EndGetResponse(result);
var stream = response.GetResponseStream();
// myImage.Source = ??
}, null);
The reason I ask is because I need to provide credentials to get the image - if there's another way to approach the problem I'm open to suggestions.
Upvotes: 3
Views: 8706
Reputation: 6178
Try this one
<Image Name="Img" Stretch="UniformToFill" />
var bitImg= new BitmapImage();
bitImg.SetSource(stream); // stream is Stream type
Img.Source = bitImg;
Upvotes: 0
Reputation: 1130
In case WritableBitmap you can use:
WriteableBitmap wbmp = new WriteableBitmap(1000, 1000);
Extensions.LoadJpeg(wbmp, stream);
Image img = new Image();
img.Source = wbmp;
Upvotes: 5
Reputation: 14882
Yes, use this code:
var bi = new BitmapImage();
bi.SetSource(stream);
myImage.Source = bi;
Upvotes: 21