public static float [ ] imageSize ( float picWidth , float picHeight , float scaleFactor , int width , int height , int percent ) { float bitmapWidth = picWidth * scaleFactor ; float bitmapHeight = picHeight * scaleFactor ; float aspectRatio = picWidth / picHeight ; if ( width != 0 && height != 0 ) { // both width and height set, override any other setting bitmapWidth = width ; bitmapHeight = height ; } else if ( width == 0 && height != 0 ) { // only width set, calculate from aspect ratio bitmapWidth = height * aspectRatio ; bitmapHeight = height ; } else if ( width != 0 && height == 0 ) { // only height set, calculate from aspect ratio bitmapHeight = width / aspectRatio ; bitmapWidth = width ; } if ( percent != 100 ) { bitmapWidth *= percent / 100f ; bitmapHeight *= percent / 100f ; } return new float [ ] { bitmapWidth , bitmapHeight } ; }
Given the original image size as well as width height percent parameters can compute the final image size .