问题
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.
回答1:
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);
回答2:
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
来源:https://stackoverflow.com/questions/25626770/is-it-possible-to-convert-a-byte-to-a-bitmapsource