Пример #1
0
        private static byte[] ReadBytesFromUri(Android.Net.Uri uri, Context context)
        {
            var stream          = context.ContentResolver.OpenInputStream(uri);
            var byteArrayStream = new Java.IO.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();

            if (bytes.Length > (int)Common.CoreConstants.ImageSizeLimit)
            {
                return(null);
            }

            return(bytes);
        }
Пример #2
0
 public static byte[] toByteArray(this Java.IO.ByteArrayOutputStream stream)
 {
     return(stream.ToByteArray());
 }