private static BufferedImage createThumb ( BufferedImage image , int thumbWidth , int thumbHeight ) { int imageWidth = image . getWidth ( null ) ; int imageHeight = image . getHeight ( null ) ; int [ ] size = getNewSize ( imageWidth , imageHeight , thumbWidth , thumbHeight ) ; if ( size [ 0 ] == imageWidth && size [ 1 ] == imageHeight ) { return image ; } BufferedImage thumbImage = new BufferedImage ( size [ 0 ] , size [ 1 ] , BufferedImage . TYPE_INT_RGB ) ; Graphics2D graphics2D = thumbImage . createGraphics ( ) ; graphics2D . setRenderingHint ( RenderingHints . KEY_INTERPOLATION , RenderingHints . VALUE_INTERPOLATION_BILINEAR ) ; graphics2D . drawImage ( image , 0 , 0 , thumbWidth , thumbHeight , null ) ; return thumbImage ; }
Creates a smaller version of an image or returns the original image if it was in the specified boundaries . The returned image keeps the ratio of the original image .