public static int [ ] getNewSize ( int width , int height , int maxWidth , int maxHeight ) { if ( width <= maxWidth && height <= maxHeight ) { return new int [ ] { width , height } ; } double thumbRatio = ( double ) maxWidth / ( double ) maxHeight ; double imageRatio = ( double ) width / ( double ) height ; if ( thumbRatio < imageRatio ) { maxHeight = ( int ) ( maxWidth / imageRatio ) ; } else { maxWidth = ( int ) ( maxHeight * imageRatio ) ; } return new int [ ] { maxWidth , maxHeight } ; }
Calculates new size of an image with the specified max borders keeping the ratio between height and width of the image .