我怎样才能转换Windows.Storage.Streams.IRandomAccessStream为System.IO.Stream?
我正在使用一个接受System.IO.Stream作为输入的 C# 库,但是当我在 Metro 中打开文件时,我得到Windows.Storage.Streams.IRandomAccessStream.
我怎样才能转换Windows.Storage.Streams.IRandomAccessStream为System.IO.Stream?
我正在使用一个接受System.IO.Stream作为输入的 C# 库,但是当我在 Metro 中打开文件时,我得到Windows.Storage.Streams.IRandomAccessStream.
最简单的方法是调用AsStream.
您可以转换Windows.Storage.Streams.IRandomAccessStream为 a byte[],然后再转换byte[]为System.IO.Stream.
来自 IRandomAccessStream 的字节 []
var file = await new FileOpenPicker().PickSingleFileAsync();
var fStream = await file.OpenAsync(FileAccessMode.Read);
var reader = new DataReader(fStream.GetInputStreamAt(0));
var bytes = new byte[fStream.Size];
await reader.LoadAsync((uint)fStream.Size);
reader.ReadBytes(bytes);
从字节流[]
var stream = new MemoryStream(bytes);