Windows Phone 7 - set the image source to a stream in memory

Is it possible to set image source in WP7 to stream? Usually I use BitmapImage for this in Silverlight, but I do not see this option in WP7. Here is 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 receive the image - if there is another way to get closer to the problem, I am open to suggestions.

+3
source share
3 answers

Yes, use this code:

var bi = new BitmapImage();
bi.SetSource(stream);
myImage.Source = bi;
+21
source

In the case of WritableBitmap, you can use:

        WriteableBitmap wbmp = new WriteableBitmap(1000, 1000);
        Extensions.LoadJpeg(wbmp, stream);
        Image img = new Image();
        img.Source = wbmp;
+5
source

Try this one

<Image Name="Img" Stretch="UniformToFill" />

var bitImg= new BitmapImage();
bitImg.SetSource(stream);  // stream is Stream type
Img.Source = bitImg;
0
source

Source: https://habr.com/ru/post/1784329/


All Articles