0

到目前为止,我有:

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

然后我想我能以某种方式从 img 获得 BitmapSource 吗?如果这是完全错误的,请随时纠正我。

4

2 回答 2

0

尝试使用BitmapSource.Create()。但是您需要先创建托盘:

var colors = new List<Color>();
colors.Add(Colors.Red);
colors.Add(Colors.Blue);
colors.Add(Colors.Green);
var palette = new BitmapPalette(colors);
于 2014-09-02T15:20:18.673 回答
0

得到了最简单的解决方案:

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

尚未对其进行测试,但我的代码取自:这里

于 2014-09-02T15:33:20.323 回答