开发者

Silverlight: Setting an Image source to MemoryStream

开发者 https://www.devze.com 2023-03-20 17:14 出处:网络
My application receives ajpe开发者_运维问答g file as a MemoryStream from a webservice. I need assign the image to image.Source. How can this be done?In here it is described:

My application receives a jpe开发者_运维问答g file as a MemoryStream from a webservice. I need assign the image to image.Source. How can this be done?


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消