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

后端 未结 7 948
暖寄归人
暖寄归人 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 01:03

    This code snippet turns a stream (stream) into an InMemoryRandomAccessStream (ims) which implement IRandomAccessStream. The trick is that CopyTo has to be called on a background thread.

            InMemoryRandomAccessStream ims = new InMemoryRandomAccessStream();
            var imsWriter = ims.OpenWrite();
            await Task.Factory.StartNew(() => stream.CopyTo(imsWriter));
    

提交回复
热议问题