question: public static Bitmap scaleAndCenterCropBitmap ( Bitmap source , int newHeight , int newWidth ) { if ( source == null ) { return null ; } int sourceWidth = source . getWidth ( ) ; int sourceHeight = source . getHeight ( ) ; float xScale = ( float ) newWidth / sourceWidth ; float yScale = ( float ) newHeight / sourceHeight ; float scale = Math . max ( xScale , yScale ) ; float scaledWidth = scale * sourceWidth ; float scaledHeight = scale * sourceHeight ; float left = ( newWidth - scaledWidth ) / 2 ; float top = ( newHeight - scaledHeight ) / 2 ; RectF targetRect = new RectF ( left , top , left + scaledWidth , top + scaledHeight ) ; Bitmap destination = Bitmap . createBitmap ( newWidth , newHeight , source . getConfig ( ) ) ; Canvas canvas = new Canvas ( destination ) ; canvas . drawBitmap ( source , null , targetRect , null ) ; return destination ; }
target:  Scale and center-crop a bitmap to fit the given dimensions.