public static int[] scaleDownInside(int inWidth,int inHeight,int maxWidth,int maxHeight){
  int scaledWidth;
  int scaledHeight;
  if (inWidth <= maxWidth && inHeight <= maxHeight) {
    scaledWidth=inWidth;
    scaledHeight=inHeight;
  }
 else {
    double widthRatio=(double)inWidth / (double)maxWidth;
    double heightRatio=(double)inHeight / (double)maxHeight;
    if (widthRatio > heightRatio) {
      scaledWidth=maxWidth;
      scaledHeight=(int)Math.round((double)inHeight / widthRatio);
    }
 else {
      scaledHeight=maxHeight;
      scaledWidth=(int)Math.round((double)inWidth / heightRatio);
    }
  }
  return new int[]{scaledWidth,scaledHeight};
}

public static int [ ] scaleDownInside ( int inWidth , int inHeight , int maxWidth , int maxHeight ) { int scaledWidth ; int scaledHeight ; if ( inWidth <= maxWidth && inHeight <= maxHeight ) { scaledWidth = inWidth ; scaledHeight = inHeight ; } else { double widthRatio = ( double ) inWidth / ( double ) maxWidth ; double heightRatio = ( double ) inHeight / ( double ) maxHeight ; if ( widthRatio > heightRatio ) { scaledWidth = maxWidth ; scaledHeight = ( int ) Math . round ( ( double ) inHeight / widthRatio ) ; } else { scaledHeight = maxHeight ; scaledWidth = ( int ) Math . round ( ( double ) inWidth / heightRatio ) ; } } return new int [ ] { scaledWidth , scaledHeight } ; }
returns int [ ] { scaledwidth , scaledheight } for dimensions that fit within the given maxwidth , maxheight at the given inwidth , inheight aspect ratio . if the in dimensions fit fully inside the max dimensions , no scaling is applied . otherwise , at least one scaled dimension is set to a max dimension , and the other scaled dimension is scaled to fit .
