可以从ushort数组创建一个BitmapImage吗?如果是这样,又是如何做到的呢?
在我创建Bitmap的那一刻,将它转换成Bitmap数组并显示它,但这太慢了,我需要不断地更新图像(实时视频馈送),而每一帧都是由UI studders创建的,这使得我的应用程序在视频运行时非常慢。所以我需要尽快把我的ushort[]装进BitmapImage
谢谢你,伊蒙
发布于 2011-03-22 02:49:51
假设您正在处理0和255之间的值,您可以将其转换为字节数组,然后将其加载到MemoryStream中
// Please note that with values higher than 255 the program will throw an exception
checked
{
ushort[] values = { 200, 100, 30/*, 256*/ };
var bytes = (from value in values
select (byte)value).ToArray();
// Taken from: http://stackoverflow.com/questions/5346727/wpf-convert-memory-stream-to-bitmapimage
using (var stream = new MemoryStream(data))
{
var bitmap = new BitmapImage();
bitmap.BeginInit();
bitmap.StreamSource = stream;
bitmap.CacheOption = BitmapCacheOption.OnLoad;
bitmap.EndInit();
bitmap.Freeze();
}
}发布于 2011-03-22 02:28:50
here您有一个如何通过MemoryStream获取BitmapImage的示例,这可能会对您有所帮助
您可以使用BitConverter将ushorts转换为用于输入到MemoryStream的字节
https://stackoverflow.com/questions/5381890
复制相似问题