如何从IRandomAccessStream获取IBuffer
本文关键字:获取 IBuffer IRandomAccessStream | 更新日期: 2024-11-07 11:33:41
如果我有一个IRandomAccessStream对象,如何创建一个IBuffer对象?
我发现最简单的方法是通过MemoryStream.GetWindowsRuntimeBuffer:
IRandomAccessStream stream = ...;
using (var memoryStream = new MemoryStream())
{
memoryStream.Capacity = (int)stream.Size;
var ibuffer = memoryStream.GetWindowsRuntimeBuffer();
await stream.ReadAsync(ibuffer, (uint)stream.Size, InputStreamOptions.None).AsTask().ConfigureAwait(false);
}