public static ImmutableTriple<Integer, Integer, Boolean> calculateScaledImageSizes(final int originalWidth, final int originalHeight, final int maxWidth, final int maxHeight, final int minWidth, final int minHeight) {

        int width = originalWidth;
        int height = originalHeight;
        final int realMaxWidth = maxWidth <= 0 ? width : maxWidth;
        final int realMaxHeight = maxHeight <= 0 ? height : maxHeight;
        final int realMinWidth = minWidth <= 0 ? width : minWidth;
        final int realMinHeight = minHeight <= 0 ? height : minHeight;
        final boolean imageTooLarge = width > realMaxWidth || height > realMaxHeight;
        final boolean imageTooSmall = width < realMinWidth || height < realMinHeight;

        if (!imageTooLarge && !imageTooSmall) {
            return new ImmutableTriple<>(width, height, false);
        }

        final double ratio = imageTooLarge ?
                Math.min((double) realMaxHeight / (double) height, (double) realMaxWidth / (double) width) :
                Math.max((double) realMinHeight / (double) height, (double) realMinWidth / (double) width) ;

        width = (int) Math.ceil(width * ratio);
        height = (int) Math.ceil(height * ratio);
        return new ImmutableTriple<>(width, height, true);
    }
Scales a bitmap to the given bounds if it is larger, otherwise returns the original bitmap (except when "force" is set to true)

@param image The bitmap to scale
@return BitmapDrawable The scaled image
main/src/main/java/cgeo/geocaching/utils/ImageUtils.java