public static BitmapSampled cropBitmap(Context context,Uri loadedImageUri,float[] points,int degreesRotated,int orgWidth,int orgHeight,boolean fixAspectRatio,int aspectRatioX,int aspectRatioY,int reqWidth,int reqHeight){
  int sampleMulti=1;
  while (true) {
    try {
      return cropBitmap(context,loadedImageUri,points,degreesRotated,orgWidth,orgHeight,fixAspectRatio,aspectRatioX,aspectRatioY,reqWidth,reqHeight,sampleMulti);
    }
 catch (    OutOfMemoryError e) {
      sampleMulti*=2;
      if (sampleMulti > 16) {
        throw new RuntimeException("Failed to handle OOM by sampling (" + sampleMulti + "): "+ loadedImageUri+ "\r\n"+ e.getMessage(),e);
      }
    }
  }
}

public static BitmapSampled cropBitmap ( Context context , Uri loadedImageUri , float [ ] points , int degreesRotated , int orgWidth , int orgHeight , boolean fixAspectRatio , int aspectRatioX , int aspectRatioY , int reqWidth , int reqHeight ) { int sampleMulti = 1 ; while ( true ) { try { return cropBitmap ( context , loadedImageUri , points , degreesRotated , orgWidth , orgHeight , fixAspectRatio , aspectRatioX , aspectRatioY , reqWidth , reqHeight , sampleMulti ) ; } catch ( OutOfMemoryError e ) { sampleMulti *= 2 ; if ( sampleMulti > 16 ) { throw new RuntimeException ( "Failed to handle OOM by sampling (" + sampleMulti + "): " + loadedImageUri + "\r\n" + e . getMessage ( ) , e ) ; } } } }
crop image bitmap from uri by decoding it with specific width and height to down - sample if required . < br > additionally if oom is thrown try to increase the sampling ( 2 , 4 , 8 ) .
