I have an instance of a System.Drawing.Bitmap
and would like to make it available to my WPF app in the form of a System.Windows.Media.Imaging.BitmapImage
.
What would be the best approach for this?
How about loading it from MemoryStream?
using(MemoryStream memory = new MemoryStream())
{
bitmap.Save(memory, ImageFormat.Png);
memory.Position = 0;
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.StreamSource = memory;
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
bitmapImage.EndInit();
}