IRandomAccessStream to Byte Array RRS feed

  • Question

  • How i can convert IRandomAccessStream to byte array in WinRT
    Tuesday, July 24, 2012 10:03 AM


  • here is using IBuffer (you must add System.Runtime.InteropServices.WindowsRuntime and System.IO namespaces)

    // This is where the byteArray to be stored.
    var bytes = new byte[myMemoryStream.Size];
    // This returns IAsyncOperationWithProgess, so you can add additional progress handling
    await myMemoryStream.ReadAsync(bytes.AsBuffer(), (uint)myMemoryStream.Size, Windows.Storage.Streams.InputStreamOptions.None);
    here is the code to convert with data reader:
    var reader = new DataReader(myMemoryStream.GetInputStreamAt(0));
    var bytes  = new byte[myMemoryStream.Size];
    await reader.LoadAsync((uint)myMemoryStream.Size);

    Can Bilgin
    Blog CompuSight

    • Edited by Can Bilgin Tuesday, July 24, 2012 11:08 AM additional info
    • Marked as answer by StezPet Wednesday, July 25, 2012 9:30 AM
    Tuesday, July 24, 2012 10:57 AM