0

So far I have:

using (MemoryStream ms = new MemoryStream(imageData))
{
     Bitmap img = (Bitmap)Image.FromStream(ms);
}

And then I would imagine I would be able to get a BitmapSource from img somehow? If this is totally wrong please feel free to correct me.

JKennedy
  • 18,150
  • 17
  • 114
  • 198

2 Answers2

0

Try using BitmapSource.Create(). But you need to create pallete first:

var colors = new List<Color>();
colors.Add(Colors.Red);
colors.Add(Colors.Blue);
colors.Add(Colors.Green);
var palette = new BitmapPalette(colors);
dee-see
  • 23,668
  • 5
  • 58
  • 91
Eldar Dordzhiev
  • 5,105
  • 2
  • 22
  • 26
0

Got the easiest solution:

using (MemoryStream ms = new MemoryStream(imageData))
{
    BitmapDecoder bitmapDecoder = BitmapDecoder.Create(ms, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad);
    BitmapSource photo = new WriteableBitmap(bitmapDecoder.Frames.Single());
}

Haven't tested it yet but my code was taken from: Here

JKennedy
  • 18,150
  • 17
  • 114
  • 198