Esempio n. 1
0
        protected override Java.Lang.Object DoInBackground(params Java.Lang.Object[] native_parms)
        {
            data = (int)native_parms[0];
            ImageView imageView;

            if (imageViewReference.TryGetTarget(out imageView))
            {
                var bitmap = ImageCache.DecodeSampledBitmapFromResource(imageView.Resources, data, widthRequest, heightRequest);
                if (cache != null)
                {
                    cache.Add(data.ToString(), bitmap);
                }
                return(bitmap);
            }
            return(null);
        }
Esempio n. 2
0
        private static void AddInBitmapOptions(BitmapFactory.Options options, ImageCache cache)
        {
            // inBitmap only works with mutable bitmaps, so force the decoder to
            // return mutable bitmaps.
            options.InMutable = true;

            if (cache != null)
            {
                // Try to find a bitmap to use for inBitmap.
                Bitmap inBitmap = cache.GetBitmapFromReusableSet(options);

                if (inBitmap != null)
                {
                    // If a suitable bitmap has been found, set it as the value of
                    // inBitmap.
                    options.InBitmap = inBitmap;
                }
            }
        }
Esempio n. 3
0
        public static Bitmap DecodeSampledBitmapFromFile(string filename, int reqWidth, int reqHeight, ImageCache cache)
        {
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.InJustDecodeBounds = true;
            BitmapFactory.DecodeFile(filename, options);

            AddInBitmapOptions(options, cache);

            options.InJustDecodeBounds = false;
            return(BitmapFactory.DecodeFile(filename, options));
        }
Esempio n. 4
0
 public BitmapWorkerTask(ImageView imageView, int widthRequest, int heightRequest, ImageCache cache = null)
 {
     imageViewReference = new WeakReference <ImageView>(imageView);
     this.cache         = cache;
     this.widthRequest  = widthRequest;
     this.heightRequest = heightRequest;
 }