繁体   English   中英

通过ushort创建一个BitmapImage []

[英]Create a BitmapImage from ushort[]

是否可以从ushort数组创建BitmapImage? 如果可以,怎么办?

在我创建位图的那一刻,将其转换为位图数组并显示它,但这太慢了,我需要不断更新图像(实时视频提要),同时在创建每个帧的UI钉时,视频运行时,我的应用程序运行非常缓慢。 所以我需要尽快将ushort []放入BitmapImage中

谢谢,Eamonn

这里有一个如何通过MemoryStream获取BitmapImage的示例,这可能对您有帮助

您可以使用BitConverter将Ushort转换为字节以输入到MemoryStream

假设您正在使用0255之间的值,则可以将其转换为字节数组,然后将其加载到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();
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM