How Do I Create a System.Windows.Media.ImageSource

2020-06-23 07:25发布

问题:

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?

回答1:

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