How Do I Create a System.Windows.Media.ImageSource From a Byte Array?

Giffyguy picture Giffyguy · Jul 24, 2009 · Viewed 10.2k times · Source

How do I create a System.Windows.Media.ImageSource from a byte array?

I have a byte array, containing the exact and complete file contents of a TIFF image file. I need to display this on the screen, and I have no idea where to even start.

Supposedly, it can be done (according to my boss, our dev team has done it in the past, but nobody remembers how).

Has anyone here ever done something like this before?

Answer

Lars Truijens picture Lars Truijens · Jul 24, 2009
BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.StreamSource = new MemoryStream(ByteArray);
bi.EndInit();

Also see Load a WPF BitmapImage from a System.Drawing.Bitmap and Using Image control in WPF to display System.Drawing.Bitmap