How to get a stream from a byte array in a windows8 store app

前端 未结 3 938
南旧
南旧 2021-01-16 01:02

I have been trying get a stream from a byte array in metro style app using the following code.

InMemoryRandomAccessStream memoryStream = new InMemoryRandomAc         


        
3条回答
  •  滥情空心
    2021-01-16 01:45

    You can use the DataWriter and DataReader classes. For example ...

    // put bytes into the stream
    var ms = new InMemoryRandomAccessStream();
    var dw = new Windows.Storage.Streams.DataWriter(ms);
    dw.WriteBytes(new byte[] { 0x00, 0x01, 0x02 });
    await dw.StoreAsync();
    
    // read them out
    ms.Seek(0);
    byte[] ob = new byte[ms.Size];
    var dr = new Windows.Storage.Streams.DataReader(ms);
    await dr.LoadAsync((uint)ms.Size);
    dr.ReadBytes(ob);
    

提交回复
热议问题