Created
June 18, 2018 09:31
-
-
Save yehorhromadskyi/b1b0046058a5f4079097c226ebc5fe8f to your computer and use it in GitHub Desktop.
Android.Net.Uri to byte array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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