예제 #1
0
        public Bitmap DecodeSampledBitmapFromUri(ContentResolver contentResolver, Uri uri, ISetImageSize imageSize, Bitmap fallback)
        {
            Stream input;

            try
            {
                input = contentResolver.OpenInputStream(uri);
            }
            catch (Exception)
            {
                return(fallback);
            }

            var options = new BitmapFactory.Options {
                InJustDecodeBounds = true
            };

            BitmapFactory.DecodeStream(input, null, options);
            input.Close();
            options.InSampleSize       = CalculateInSampleSize(options, imageSize.Width, imageSize.Height);
            options.InMutable          = true;
            options.InJustDecodeBounds = false;
            input = contentResolver.OpenInputStream(uri);
            var bitmap = BitmapFactory.DecodeStream(input, null, options);

            input.Close();
            return(bitmap);
        }
예제 #2
0
        public static Bitmap DecodeSampledBitmapFromResource(Resources res, int resId, ISetImageSize imageSizer)
        {
            var options = new BitmapFactory.Options {
                InJustDecodeBounds = true
            };

            BitmapFactory.DecodeResource(res, resId, options);

            options.InSampleSize = CalculateInSampleSize(options, imageSizer.Width, imageSizer.Height);

            options.InJustDecodeBounds = false;
            return(BitmapFactory.DecodeResource(res, resId, options));
        }