I have a problem converting byte array to InMemoryRandomAccessStream
or IRandomAccessStream
in windows 8?
This is my code, but It doesn't work :
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 I created the RandomAccessStreamReference
and set the requst datapack in order to share the image to 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);
}
There's no exception but I can't use the result image byte array
I think there's an error when converting byte[]
to InMemoryRandomAccessStream
, but it doesn't throw an exception.
Anybody know how to implement it?
if anyone knows how to convert the byte array to IRandomAccessStream
, it's also appreciated