private static int getResizedDimension ( int maxPrimary , int maxSecondary , int actualPrimary , int actualSecondary , ScaleType scaleType ) { // If no dominant value at all, just return the actual. if ( ( maxPrimary == 0 ) && ( maxSecondary == 0 ) ) { return actualPrimary ; } // If ScaleType.FIT_XY fill the whole rectangle, ignore ratio. if ( scaleType == ScaleType . FIT_XY ) { if ( maxPrimary == 0 ) { return actualPrimary ; } return maxPrimary ; } // If primary is unspecified, scale primary to match secondary's scaling ratio. if ( maxPrimary == 0 ) { double ratio = ( double ) maxSecondary / ( double ) actualSecondary ; return ( int ) ( actualPrimary * ratio ) ; } if ( maxSecondary == 0 ) { return maxPrimary ; } double ratio = ( double ) actualSecondary / ( double ) actualPrimary ; int resized = maxPrimary ; // If ScaleType.CENTER_CROP fill the whole rectangle, preserve aspect ratio. if ( scaleType == ScaleType . CENTER_CROP ) { if ( ( resized * ratio ) < maxSecondary ) { resized = ( int ) ( maxSecondary / ratio ) ; } return resized ; } if ( ( resized * ratio ) > maxSecondary ) { resized = ( int ) ( maxSecondary / ratio ) ; } return resized ; }
Scales one side of a rectangle to fit aspect ratio .