private float[] calculateImageIndents(){
  mTempMatrix.reset();
  mTempMatrix.setRotate(-getCurrentAngle());
  float[] unrotatedImageCorners=Arrays.copyOf(mCurrentImageCorners,mCurrentImageCorners.length);
  float[] unrotatedCropBoundsCorners=RectUtils.getCornersFromRect(mCropRect);
  mTempMatrix.mapPoints(unrotatedImageCorners);
  mTempMatrix.mapPoints(unrotatedCropBoundsCorners);
  RectF unrotatedImageRect=RectUtils.trapToRect(unrotatedImageCorners);
  RectF unrotatedCropRect=RectUtils.trapToRect(unrotatedCropBoundsCorners);
  float deltaLeft=unrotatedImageRect.left - unrotatedCropRect.left;
  float deltaTop=unrotatedImageRect.top - unrotatedCropRect.top;
  float deltaRight=unrotatedImageRect.right - unrotatedCropRect.right;
  float deltaBottom=unrotatedImageRect.bottom - unrotatedCropRect.bottom;
  float indents[]=new float[4];
  indents[0]=(deltaLeft > 0) ? deltaLeft : 0;
  indents[1]=(deltaTop > 0) ? deltaTop : 0;
  indents[2]=(deltaRight < 0) ? deltaRight : 0;
  indents[3]=(deltaBottom < 0) ? deltaBottom : 0;
  mTempMatrix.reset();
  mTempMatrix.setRotate(getCurrentAngle());
  mTempMatrix.mapPoints(indents);
  return indents;
}

private float [ ] calculateImageIndents ( ) { mTempMatrix . reset ( ) ; mTempMatrix . setRotate ( - getCurrentAngle ( ) ) ; float [ ] unrotatedImageCorners = Arrays . copyOf ( mCurrentImageCorners , mCurrentImageCorners . length ) ; float [ ] unrotatedCropBoundsCorners = RectUtils . getCornersFromRect ( mCropRect ) ; mTempMatrix . mapPoints ( unrotatedImageCorners ) ; mTempMatrix . mapPoints ( unrotatedCropBoundsCorners ) ; RectF unrotatedImageRect = RectUtils . trapToRect ( unrotatedImageCorners ) ; RectF unrotatedCropRect = RectUtils . trapToRect ( unrotatedCropBoundsCorners ) ; float deltaLeft = unrotatedImageRect . left - unrotatedCropRect . left ; float deltaTop = unrotatedImageRect . top - unrotatedCropRect . top ; float deltaRight = unrotatedImageRect . right - unrotatedCropRect . right ; float deltaBottom = unrotatedImageRect . bottom - unrotatedCropRect . bottom ; float indents [ ] = new float [ 4 ] ; indents [ 0 ] = ( deltaLeft > 0 ) ? deltaLeft : 0 ; indents [ 1 ] = ( deltaTop > 0 ) ? deltaTop : 0 ; indents [ 2 ] = ( deltaRight < 0 ) ? deltaRight : 0 ; indents [ 3 ] = ( deltaBottom < 0 ) ? deltaBottom : 0 ; mTempMatrix . reset ( ) ; mTempMatrix . setRotate ( getCurrentAngle ( ) ) ; mTempMatrix . mapPoints ( indents ) ; return indents ; }
first , un - rotate image and crop rectangles ( make image rectangle axis - aligned ) . second , calculate deltas between those rectangles sides . third , depending on delta ( its sign ) put them or zero inside an array . fourth , using matrix , rotate back those points ( indents ) .
