public static float scaleToFitTargetSize(int[] dimensions,int targetWidth,int targetHeight){
  if (dimensions.length < 2 || dimensions[0] <= 0 || dimensions[1] <= 0) {
    throw new IllegalArgumentException("Expected dimensions to have length >= 2 && dimensions[0] > 0 && " + "dimensions[1] > 0");
  }
  float scale=Math.max((float)targetWidth / dimensions[0],(float)targetHeight / dimensions[1]);
  dimensions[0]*=scale;
  dimensions[1]*=scale;
  return scale;
}

public static float scaleToFitTargetSize ( int [ ] dimensions , int targetWidth , int targetHeight ) { if ( dimensions . length < 2 || dimensions [ 0 ] <= 0 || dimensions [ 1 ] <= 0 ) { throw new IllegalArgumentException ( "Expected dimensions to have length >= 2 && dimensions[0] > 0 && " + "dimensions[1] > 0" ) ; } float scale = Math . max ( ( float ) targetWidth / dimensions [ 0 ] , ( float ) targetHeight / dimensions [ 1 ] ) ; dimensions [ 0 ] *= scale ; dimensions [ 1 ] *= scale ; return scale ; }
scales the provided dimension such that it is just large enough to fit the target width and height .
