question: private static Bitmap cropForRotatedImage ( Bitmap bitmap , float [ ] points , Rect rect , int degreesRotated , boolean fixAspectRatio , int aspectRatioX , int aspectRatioY ) { if ( degreesRotated % 90 != 0 ) { int adjLeft = 0 , adjTop = 0 , width = 0 , height = 0 ; double rads = Math . toRadians ( degreesRotated ) ; int compareTo = degreesRotated < 90 || ( degreesRotated > 180 && degreesRotated < 270 ) ? rect . left : rect . right ; for ( int i = 0 ; i < points . length ; i += 2 ) { if ( points [ i ] >= compareTo - 1 && points [ i ] <= compareTo + 1 ) { adjLeft = ( int ) Math . abs ( Math . sin ( rads ) * ( rect . bottom - points [ i + 1 ] ) ) ; adjTop = ( int ) Math . abs ( Math . cos ( rads ) * ( points [ i + 1 ] - rect . top ) ) ; width = ( int ) Math . abs ( ( points [ i + 1 ] - rect . top ) / Math . sin ( rads ) ) ; height = ( int ) Math . abs ( ( rect . bottom - points [ i + 1 ] ) / Math . cos ( rads ) ) ; break ; } } rect . set ( adjLeft , adjTop , adjLeft + width , adjTop + height ) ; if ( fixAspectRatio ) { fixRectForAspectRatio ( rect , aspectRatioX , aspectRatioY ) ; } Bitmap bitmapTmp = bitmap ; bitmap = Bitmap . createBitmap ( bitmap , rect . left , rect . top , rect . width ( ) , rect . height ( ) ) ; bitmapTmp . recycle ( ) ; } return bitmap ; }
target:  Special crop of bitmap rotated by not stright angle, in this case the original crop bitmap contains parts beyond the required crop area, this method crops the already cropped and rotated bitmap to the final rectangle.<br> Note: rotating by 0, 90, 180 or 270 degrees doesn't require extra cropping.