private Bitmap getBitmapFromUri(Uri uri) {
Bitmap bitmap = null;
try {
BitmapFactory.Options options = new BitmapFactory.Options();
int picWidth = options.outWidth;
int picHeight = options.outHeight;
WindowManager windowManager = getWindowManager();
Display display = windowManager.getDefaultDisplay();
int screenWidth = display.getWidth();
int screenHeight = display.getHeight();
options.inSampleSize = 1;
if (picWidth > picHeight) {
if (picWidth > screenWidth)
options.inSampleSize = picWidth / screenWidth;
} else {
if (picHeight > screenHeight)
options.inSampleSize = picHeight / screenHeight;
}
options.inJustDecodeBounds = false;
bitmap = BitmapFactory.decodeStream(getContentResolver()
.openInputStream(uri), null, options);
} catch (Exception e) {
e.printStackTrace();
return null;
}
return bitmap;
}