16

I need to convert a Stream into an IRandomAccessStream (in order to create a BitmapDecoder). I tried casting and searching for built-in methods for that in BitmapDecoder but couldn't find any.

So how do I do that?

ispiro
  • 26,556
  • 38
  • 136
  • 291
  • can you show what code you have or have tried ..this should not be that difficult but it would be nice to see what you have written code wise to see where you have went wrong – MethodMan Oct 19 '15 at 18:11
  • 1
    Possible duplicate of [Is there a way to convert a System.IO.Stream to a Windows.Storage.Streams.IRandomAccessStream?](http://stackoverflow.com/questions/7669311/is-there-a-way-to-convert-a-system-io-stream-to-a-windows-storage-streams-irando) – MethodMan Oct 19 '15 at 18:14
  • @ispiro Your post is a bit old. This `MSDN` [link](https://learn.microsoft.com/en-us/dotnet/standard/io/how-to-convert-between-dotnet-streams-and-winrt-streams) should also help – nam Mar 29 '19 at 18:24

2 Answers2

45

There is an extension method for that:

Stream stream = GetSomeStream();
IRandomAccessStream randomAccessStream = stream.AsRandomAccessStream();

Just make sure that you have using System.IO at the top of your code file.

Kevin Gosse
  • 38,392
  • 3
  • 78
  • 94
0

in Visual Basic Method like this...

Dim inputfile As Streams.IRandomAccessStream = System.IO.WindowsRuntimeStreamExtensions.AsRandomAccessStream(stm)
KimKulling
  • 2,654
  • 1
  • 15
  • 26