0

My application receives a jpeg file as a MemoryStream from a webservice. I need assign the image to image.Source. How can this be done?

2 Answers 2

1

In here it is described:

void proxy_GetImageCompleted(object sender, GetImageCompletedEventArgs e)
{
    MemoryStream stream = new MemoryStream(e.Result);
    BitmapImage b = new BitmapImage();
    b.SetSource(stream);
    imgImage.Source = b;
}
Sign up to request clarification or add additional context in comments.

Comments

1

The System.Windows.Controls.Image.Source property is of type System.Windows.Media.ImageSource A System.Windows.Media.Imaging.BitmapImage is derived from ImageSource.

And BitmapImage has a SetSource(Stream streamsource) method.

So with the following code you can add an image from a stream:

Stream inStream = [your MemoryStream];

BitmapImage tempImage = new BitmapImage();
tempImage.SetSource(inStream);

YourControlsImage.Source = tempImage;

MSDN links:

Image.Source Property

BitmapSource.SetSource Method

BitmapImage Class

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.