-1

Is there a way I can show images such as gif, png, jpg, tiff from either a base64 string or byte array from memory without having to write them to disk?

Tsukasa
  • 6,342
  • 16
  • 64
  • 96
  • possible duplicate of [Creating WPF BitmapImage from MemoryStream png, gif](http://stackoverflow.com/questions/2097152/creating-wpf-bitmapimage-from-memorystream-png-gif) – Konrad Kokosa Dec 14 '13 at 02:24
  • You could let [ImageSourceConverter](http://msdn.microsoft.com/en-us/library/system.windows.media.imagesourceconverter.aspx) do the job. It supports more or less all possible conversions to ImageSource, including those from byte arrays that contain encoded image buffers. – Clemens Dec 14 '13 at 09:52

1 Answers1

2

There is no requirement that image source is path to local file. I.e. you can create BitmapSource from byte array (directly or read all bytes from a stream first) and use it.

MSDN sample from BitmapSource:

// Define parameters used to create the BitmapSource.
PixelFormat pf = PixelFormats.Bgr32;
int width = 200;
int height = 200;
int rawStride = (width * pf.BitsPerPixel + 7) / 8;

// Create a BitmapSource.
BitmapSource bitmap = BitmapSource.Create(width, height,
    96, 96, pf, null,
    new byte[rawStride * height], rawStride);

// Create an image element;
Image myImage = new Image() { Width = 200 };
// Set image source.
myImage.Source = bitmap;
Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179