如果我有一个IRandomAccessStream对象,我该如何创建一个IBuffer对象?
答案 0 :(得分:6)
我找到的最简单方法是通过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);
}