Is there a way to convert a System.IO.Stream to a Windows.Storage.Streams.IRandomAccessStream?

后端 未结 7 949
暖寄归人
暖寄归人 2020-11-30 00:42

In Windows 8; I would like to pass the contents of a MemoryStream to a class that accepts a parameter of type Windows.Storage.Streams.IRandomAccessStream. Is there any way t

7条回答
  •  难免孤独
    2020-11-30 00:56

    None of the above works for me today (maybe some API changes since the answers were posted). The only way that works is

    IRandomAccessStream inMemoryStream = new InMemoryRandomAccessStream();
    using (var inputStream = stream.AsInputStream())
    {
        await RandomAccessStream.CopyAsync(inputStream, inMemoryStream);
    }
    inMemoryStream.Seek(0);
    

提交回复
热议问题