private static BitmapSampled cropBitmap(Context context,Uri loadedImageUri,float[] points,int degreesRotated,boolean fixAspectRatio,int aspectRatioX,int aspectRatioY,int sampleMulti,Rect rect,int width,int height){
  Bitmap result=null;
  int sampleSize;
  try {
    BitmapFactory.Options options=new BitmapFactory.Options();
    options.inSampleSize=sampleSize=sampleMulti * calculateInSampleSizeByReqestedSize(rect.width(),rect.height(),width,height);
    Bitmap fullBitmap=decodeImage(context.getContentResolver(),loadedImageUri,options);
    if (fullBitmap != null) {
      try {
        float[] points2=new float[points.length];
        System.arraycopy(points,0,points2,0,points.length);
        for (int i=0; i < points2.length; i++) {
          points2[i]=points2[i] / options.inSampleSize;
        }
        result=cropBitmap(fullBitmap,points2,degreesRotated,fixAspectRatio,aspectRatioX,aspectRatioY);
      }
  finally {
        if (result != fullBitmap) {
          fullBitmap.recycle();
        }
      }
    }
  }
 catch (  OutOfMemoryError e) {
    if (result != null) {
      result.recycle();
    }
    throw e;
  }
catch (  Exception e) {
    throw new RuntimeException("Failed to load sampled bitmap: " + loadedImageUri + "\r\n"+ e.getMessage(),e);
  }
  return new BitmapSampled(result,sampleSize);
}

private static BitmapSampled cropBitmap ( Context context , Uri loadedImageUri , float [ ] points , int degreesRotated , boolean fixAspectRatio , int aspectRatioX , int aspectRatioY , int sampleMulti , Rect rect , int width , int height ) { Bitmap result = null ; int sampleSize ; try { BitmapFactory . Options options = new BitmapFactory . Options ( ) ; options . inSampleSize = sampleSize = sampleMulti * calculateInSampleSizeByReqestedSize ( rect . width ( ) , rect . height ( ) , width , height ) ; Bitmap fullBitmap = decodeImage ( context . getContentResolver ( ) , loadedImageUri , options ) ; if ( fullBitmap != null ) { try { float [ ] points2 = new float [ points . length ] ; System . arraycopy ( points , 0 , points2 , 0 , points . length ) ; for ( int i = 0 ; i < points2 . length ; i ++ ) { points2 [ i ] = points2 [ i ] / options . inSampleSize ; } result = cropBitmap ( fullBitmap , points2 , degreesRotated , fixAspectRatio , aspectRatioX , aspectRatioY ) ; } finally { if ( result != fullBitmap ) { fullBitmap . recycle ( ) ; } } } } catch ( OutOfMemoryError e ) { if ( result != null ) { result . recycle ( ) ; } throw e ; } catch ( Exception e ) { throw new RuntimeException ( "Failed to load sampled bitmap: " + loadedImageUri + "\r\n" + e . getMessage ( ) , e ) ; } return new BitmapSampled ( result , sampleSize ) ; }
crop bitmap by fully loading the original and then cropping it , fallback in case cropping region failed .
