code: public static Bitmap toBitmap(Uri uri, Integer maxWidth, Integer maxHeight) {
  		try {
  			Context context = AbstractApplication.get();
  
  			// First decode with inJustDecodeBounds=true to check dimensions
  			Options options = new Options();
  			options.inJustDecodeBounds = true;
  			InputStream openInputStream = context.getContentResolver().openInputStream(uri);
  			BitmapFactory.decodeStream(openInputStream, null, options);
  			openInputStream.close();
  
  			// Calculate inSampleSize
  			if ((maxWidth != null) && (maxHeight != null)) {
  				float scale = Math.min(maxWidth.floatValue() / options.outWidth, maxHeight.floatValue()
  					/ options.outHeight);
  				options.inSampleSize = Math.round(1 / scale);
  			}
  
  			// Decode bitmap with inSampleSize set
  			openInputStream = context.getContentResolver().openInputStream(uri);
  			options.inJustDecodeBounds = false;
  			Bitmap result = BitmapFactory.decodeStream(openInputStream, null, options);
  			openInputStream.close();
  			return result;
  		} catch (Exception e) {
  			LOGGER.error(e.getMessage(), e);
  			return null;
  		}
  	}
docs: Gets a {@link Bitmap} from a {@link Uri}. Resizes the image to a determined width and height.
  
  @param uri The {@link Uri} from which the image is obtained.
  @param maxWidth The maximum width of the image used to scale it. If null, the image won't be scaled
  @param maxHeight The maximum height of the image used to scale it. If null, the image won't be scaled
  @return {@link Bitmap} The resized image.