Created
April 11, 2012 12:39
-
-
Save voituk/2359091 to your computer and use it in GitHub Desktop.
Android: Load + resize image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
BitmapFactory.Options options = new BitmapFactory.Options() {{ | |
inJustDecodeBounds = true; | |
}}; | |
BitmapFactory.decodeStream(getContentResolver().openInputStream(imageUri), null, options); | |
final int wResample = (options.outWidth > profileThumb.getWidth()) ? options.outWidth / profileThumb.getWidth() : 1; | |
final int hResample = (options.outHeight > profileThumb.getHeight()) ? options.outHeight / profileThumb.getHeight() : 1; | |
Bitmap tinyBmp = BitmapFactory.decodeStream(getContentResolver().openInputStream(imageUri), null, new BitmapFactory.Options() {{ | |
inSampleSize = Math.max(1, Math.min(Math.max(wResample, hResample), 16)); | |
inPreferredConfig = Bitmap.Config.RGB_565; | |
inPurgeable = true; | |
inInputShareable = true; | |
}}); | |
profileThumb.setImageBitmap(tinyBmp);// ImageURI(imageFromGallery); // Let's allow android to handle decoding and etc | |
} catch (FileNotFoundException e) { | |
// this shouldn't happen. at least not very often | |
Looplr.reportException(e, "Error Loading profile picture"); | |
Log.e(TAG, "Error Loading profile picture"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment