Skip to content

Instantly share code, notes, and snippets.

@yehorhromadskyi
Created June 18, 2018 09:31
Show Gist options
  • Save yehorhromadskyi/b1b0046058a5f4079097c226ebc5fe8f to your computer and use it in GitHub Desktop.
Save yehorhromadskyi/b1b0046058a5f4079097c226ebc5fe8f to your computer and use it in GitHub Desktop.
Android.Net.Uri to byte array
private byte[] ReadBytes(Android.Net.Uri uri)
{
var stream = ContentResolver.OpenInputStream(uri);
var byteArrayStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int i = Java.Lang.Integer.MaxValue;
while ((i = stream.Read(buffer, 0, buffer.Length)) > 0)
{
byteArrayStream.Write(buffer, 0, i);
}
var bytes = byteArrayStream.ToByteArray();
return bytes;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment