<commit_before>// MvxAndroidLocalFileImageLoader.cs
// (c) Copyright Cirrious Ltd. http://www.cirrious.com
// MvvmCross is licensed using Microsoft Public License (Ms-PL)
// Contributions and inspirations noted in readme.md and license.txt
// 
// Project Lead - Stuart Lodge, @slodge, <EMAIL>

using Android.Graphics;
using Cirrious.CrossCore.Interfaces.IoC;
using Cirrious.MvvmCross.Plugins.File;

namespace Cirrious.MvvmCross.Plugins.DownloadCache.Droid
{
    public class MvxAndroidLocalFileImageLoader
        : IMvxLocalFileImageLoader<Bitmap>
          
    {
        #region IMvxLocalFileImageLoader<UIImage> Members

        public MvxImage<Bitmap> Load(string localPath, bool shouldCache)
        {
            var bitmap = LoadBitmap(localPath, shouldCache);
            return new MvxAndroidImage(bitmap);
        }

        private Bitmap LoadBitmap(string localPath, bool shouldCache)
        {
            var fileStore = Mvx.Resolve<IMvxFileStore>();
            byte[] contents;
            if (!fileStore.TryReadBinaryFile(localPath, out contents))
                return null;

            var image = BitmapFactory.DecodeByteArray(contents, 0, contents.Length);
            return image;
        }

        #endregion
    }
}<commit_msg>Big leak fix copied across from vnext<commit_after>// MvxAndroidLocalFileImageLoader.cs
// (c) Copyright Cirrious Ltd. http://www.cirrious.com
// MvvmCross is licensed using Microsoft Public License (Ms-PL)
// Contributions and inspirations noted in readme.md and license.txt
// 
// Project Lead - Stuart Lodge, @slodge, <EMAIL>

using Android.Graphics;
using Cirrious.CrossCore.Interfaces.IoC;
using Cirrious.MvvmCross.Plugins.File;

namespace Cirrious.MvvmCross.Plugins.DownloadCache.Droid
{
    public class MvxAndroidLocalFileImageLoader
        : IMvxLocalFileImageLoader<Bitmap>
          
    {
        #region IMvxLocalFileImageLoader<UIImage> Members

        public MvxImage<Bitmap> Load(string localPath, bool shouldCache)
        {
            var bitmap = LoadBitmap(localPath, shouldCache);
            return new MvxAndroidImage(bitmap);
        }

        private Bitmap LoadBitmap(string localPath, bool shouldCache)
        {
            var fileStore = Mvx.Resolve<IMvxFileStore>();
            byte[] contents;
            if (!fileStore.TryReadBinaryFile(localPath, out contents))
                return null;

			// the InPurgeable option is very important for Droid memory management.
			// see 
			var options = new BitmapFactory.Options () { InPurgeable = true };
            var image = BitmapFactory.DecodeByteArray(contents, 0, contents.Length, options);
            return image;
        }

        #endregion
    }
}
{'fraction_non_alphanumeric': 0.0843819393042191, 'fraction_numerical': 0.0007401924500370096, 'mean_word_length': 2.733425414364641, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2282870', 'n_tokens_mistral': 781, 'n_tokens_neox': 732, 'n_words': 188}