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
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;
}
Comments
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: