c# - How to convert byte array to InMemoryRandomAccessStream or IRandomAccessStream in windows 8 -


now i've had problem how convert byte array inmemoryrandomaccessstream or irandomaccessstream in windows 8?

this code, did't work, refer following code

internal static async task<inmemoryrandomaccessstream> convertto(byte[] arr) {     inmemoryrandomaccessstream randomaccessstream = new inmemoryrandomaccessstream();     stream stream = randomaccessstream.asstream();     await stream.writeasync(arr, 0, arr.length);     await stream.flushasync();      return randomaccessstream; } 

and create randomaccessstreamreference , set requst datapack in order share image other app

    private static async void ondeferredimagestreamrequestedhandler(dataproviderrequest request)     {         dataproviderdeferral deferral = request.getdeferral();         inmemoryrandomaccessstream stream = await convertto(arr);         randomaccessstreamreference referencestream =                     randomaccessstreamreference.createfromstream(stream);         request.setdata(referencestream);     } 

but result can't share image byte array other app, code have problem? in opinion, error occurs when convert byte[] inmemoryrandomaccessstream, did't throw exception.

anybody know how it? , if can convert byte array irandomaccessstream, same can me. or error in code?

add using statement @ top of document.

using system.runtime.interopservices.windowsruntime; internal static async task<inmemoryrandomaccessstream> convertto(byte[] arr) {     inmemoryrandomaccessstream randomaccessstream = new inmemoryrandomaccessstream();     await randomaccessstream.writeasync(arr.asbuffer());     randomaccessstream.seek(0); // sure.                     // don't think need flush here, if doesn't work, give try.     return randomaccessstream; } 

Comments