Get Imagesource from Memorystream in c# wpf

kartal picture kartal · Jul 5, 2011 · Viewed 27.9k times · Source

How can I get ImageSource from MemoryStream in WPF using c# ? or convert MemoryStream to ImageSource to display it as image in wpf ?

Answer

Darin Dimitrov picture Darin Dimitrov · Jul 5, 2011
using (MemoryStream memoryStream = ...)
{
    var imageSource = new BitmapImage();
    imageSource.BeginInit();
    imageSource.StreamSource = memoryStream;
    imageSource.EndInit();

    // Assign the Source property of your image
    image.Source = imageSource;
}