Beispiel #1
0
        protected override byte[] ReadClear(string filename)
        {
            if (filename == null)
            {
                throw new ArgumentNullException(nameof(filename));
            }

            byte[] file = null;
            if (base.Exists(filename))
            {
                file = base.ReadClear(filename);
            }
            else
            {
                using (var input = GetAsset(filename))
                {
                    if (input != null)
                    {
                        file = NetworkUtils.StreamToByteArray(input);
                    }
                }
            }

            if (file == null)
            {
                int resource = ResourceFromFileName(filename);
                if (resource > 0)
                {
                    var stream = _resources.OpenRawResource(resource);
                    file = NetworkUtils.StreamToByteArray(stream);
                }
            }

            if (file == null)
            {
                throw new FileNotFoundException("File not found.", filename);
            }

            return(file);
        }
Beispiel #2
0
        protected override byte[] ReadClear(string filename)
        {
            if (filename == null)
            {
                throw new ArgumentNullException(nameof(filename));
            }
            if (filename == string.Empty)
            {
                throw new ArgumentException(nameof(filename));
            }

            if (!filename.StartsWith("/"))
            {
                using (var input = GetAsset(filename))
                {
                    if (input != null)
                    {
                        using (var output = new MemoryStream())
                        {
                            input.CopyTo(output);
                            return(RemoveBOM(output.ToArray()));
                        }
                    }
                }
                int resource = ResourceFromFileName(filename);
                if (resource > 0)
                {
                    var stream = _resources.OpenRawResource(resource);
                    return(RemoveBOM(NetworkUtils.StreamToByteArray(stream)));
                }
            }

            if (base.Exists(filename))
            {
                return(RemoveBOM(base.ReadClear(filename)));
            }
            throw new FileNotFoundException("File not found.", filename);
        }
Beispiel #3
0
 public static Bitmap GetDrawable(Android.Content.Res.Resources res, int id)
 {
     return(BitmapFactory.DecodeStream(res.OpenRawResource(id)));
 }