Created
February 25, 2014 10:46
-
-
Save blaswan/9206716 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
public static Bitmap getScaledBitmapFromUri(Context context, Uri uri) { | |
InputStream inputStream; | |
try { | |
inputStream = context.getContentResolver().openInputStream(uri); | |
BitmapFactory.Options options = new BitmapFactory.Options(); | |
options.inJustDecodeBounds = true; | |
BitmapFactory.decodeStream(inputStream, null, options); | |
inputStream.close(); | |
int width = options.outWidth; | |
int scaleFactor = width / SCALED_WIDTH; | |
Bitmap bitmap; | |
inputStream = context.getContentResolver().openInputStream(uri); | |
options = new BitmapFactory.Options(); | |
options.inSampleSize = scaleFactor; | |
bitmap = BitmapFactory.decodeStream(inputStream, null, options); | |
inputStream.close(); | |
return bitmap; | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment