@@ -205,7 +205,26 @@ public static BufferedImage cropAndScale(BufferedImage source,double ratio, doub
205205 resultGraphics .dispose ();
206206 return scaledImage .getSubimage (0 , 0 , (int )(w *cropWidth ),(int )(h *cropHeight ));
207207 }
208-
208+
209+ public static BufferedImage cropAndScale (BufferedImage source ,double ratio , int maxWidth , int maxHeight ) {
210+ int w = source .getWidth ();
211+ int h = source .getHeight ();
212+ BufferedImage scaledImage = getCompatibleImage (w , h , source );
213+ Graphics2D resultGraphics = scaledImage .createGraphics ();
214+ resultGraphics .setRenderingHint (RenderingHints .KEY_INTERPOLATION ,
215+ RenderingHints .VALUE_INTERPOLATION_BICUBIC );
216+ resultGraphics .drawImage (source , 0 , 0 , w , h , null );
217+ resultGraphics .dispose ();
218+ if (maxWidth != -1 && w > maxWidth ){
219+ w = maxWidth ;
220+ }
221+ if (maxHeight != -1 && h > maxHeight ){
222+ h = maxHeight ;
223+ }
224+ return scaledImage .getSubimage (0 , 0 , w ,h );
225+ }
226+
227+
209228 private static BufferedImage getCompatibleImage (int w , int h , BufferedImage source ) {
210229 BufferedImage bimage = null ;
211230 try {
0 commit comments