private void initCropWindow(){
  float leftLimit=Math.max(BitmapUtils.getRectLeft(mBoundsPoints),0);
  float topLimit=Math.max(BitmapUtils.getRectTop(mBoundsPoints),0);
  float rightLimit=Math.min(BitmapUtils.getRectRight(mBoundsPoints),getWidth());
  float bottomLimit=Math.min(BitmapUtils.getRectBottom(mBoundsPoints),getHeight());
  if (rightLimit <= leftLimit || bottomLimit <= topLimit) {
    return;
  }
  RectF rect=new RectF();
  initializedCropWindow=true;
  float horizontalPadding=mInitialCropWindowPaddingRatio * (rightLimit - leftLimit);
  float verticalPadding=mInitialCropWindowPaddingRatio * (bottomLimit - topLimit);
  if (mInitialCropWindowRect.width() > 0 && mInitialCropWindowRect.height() > 0) {
    rect.left=leftLimit + mInitialCropWindowRect.left / mCropWindowHandler.getScaleFactorWidth();
    rect.top=topLimit + mInitialCropWindowRect.top / mCropWindowHandler.getScaleFactorHeight();
    rect.right=rect.left + mInitialCropWindowRect.width() / mCropWindowHandler.getScaleFactorWidth();
    rect.bottom=rect.top + mInitialCropWindowRect.height() / mCropWindowHandler.getScaleFactorHeight();
    rect.left=Math.max(leftLimit,rect.left);
    rect.top=Math.max(topLimit,rect.top);
    rect.right=Math.min(rightLimit,rect.right);
    rect.bottom=Math.min(bottomLimit,rect.bottom);
  }
 else   if (mFixAspectRatio && rightLimit > leftLimit && bottomLimit > topLimit) {
    float bitmapAspectRatio=(rightLimit - leftLimit) / (bottomLimit - topLimit);
    if (bitmapAspectRatio > mTargetAspectRatio) {
      rect.top=topLimit + verticalPadding;
      rect.bottom=bottomLimit - verticalPadding;
      float centerX=getWidth() / 2f;
      mTargetAspectRatio=(float)mAspectRatioX / mAspectRatioY;
      float cropWidth=Math.max(mCropWindowHandler.getMinCropWidth(),rect.height() * mTargetAspectRatio);
      float halfCropWidth=cropWidth / 2f;
      rect.left=centerX - halfCropWidth;
      rect.right=centerX + halfCropWidth;
    }
 else {
      rect.left=leftLimit + horizontalPadding;
      rect.right=rightLimit - horizontalPadding;
      float centerY=getHeight() / 2f;
      float cropHeight=Math.max(mCropWindowHandler.getMinCropHeight(),rect.width() / mTargetAspectRatio);
      float halfCropHeight=cropHeight / 2f;
      rect.top=centerY - halfCropHeight;
      rect.bottom=centerY + halfCropHeight;
    }
  }
 else {
    rect.left=leftLimit + horizontalPadding;
    rect.top=topLimit + verticalPadding;
    rect.right=rightLimit - horizontalPadding;
    rect.bottom=bottomLimit - verticalPadding;
  }
  fixCropWindowRectByRules(rect);
  mCropWindowHandler.setRect(rect);
}

private void initCropWindow ( ) { float leftLimit = Math . max ( BitmapUtils . getRectLeft ( mBoundsPoints ) , 0 ) ; float topLimit = Math . max ( BitmapUtils . getRectTop ( mBoundsPoints ) , 0 ) ; float rightLimit = Math . min ( BitmapUtils . getRectRight ( mBoundsPoints ) , getWidth ( ) ) ; float bottomLimit = Math . min ( BitmapUtils . getRectBottom ( mBoundsPoints ) , getHeight ( ) ) ; if ( rightLimit <= leftLimit || bottomLimit <= topLimit ) { return ; } RectF rect = new RectF ( ) ; initializedCropWindow = true ; float horizontalPadding = mInitialCropWindowPaddingRatio * ( rightLimit - leftLimit ) ; float verticalPadding = mInitialCropWindowPaddingRatio * ( bottomLimit - topLimit ) ; if ( mInitialCropWindowRect . width ( ) > 0 && mInitialCropWindowRect . height ( ) > 0 ) { rect . left = leftLimit + mInitialCropWindowRect . left / mCropWindowHandler . getScaleFactorWidth ( ) ; rect . top = topLimit + mInitialCropWindowRect . top / mCropWindowHandler . getScaleFactorHeight ( ) ; rect . right = rect . left + mInitialCropWindowRect . width ( ) / mCropWindowHandler . getScaleFactorWidth ( ) ; rect . bottom = rect . top + mInitialCropWindowRect . height ( ) / mCropWindowHandler . getScaleFactorHeight ( ) ; rect . left = Math . max ( leftLimit , rect . left ) ; rect . top = Math . max ( topLimit , rect . top ) ; rect . right = Math . min ( rightLimit , rect . right ) ; rect . bottom = Math . min ( bottomLimit , rect . bottom ) ; } else if ( mFixAspectRatio && rightLimit > leftLimit && bottomLimit > topLimit ) { float bitmapAspectRatio = ( rightLimit - leftLimit ) / ( bottomLimit - topLimit ) ; if ( bitmapAspectRatio > mTargetAspectRatio ) { rect . top = topLimit + verticalPadding ; rect . bottom = bottomLimit - verticalPadding ; float centerX = getWidth ( ) / 2f ; mTargetAspectRatio = ( float ) mAspectRatioX / mAspectRatioY ; float cropWidth = Math . max ( mCropWindowHandler . getMinCropWidth ( ) , rect . height ( ) * mTargetAspectRatio ) ; float halfCropWidth = cropWidth / 2f ; rect . left = centerX - halfCropWidth ; rect . right = centerX + halfCropWidth ; } else { rect . left = leftLimit + horizontalPadding ; rect . right = rightLimit - horizontalPadding ; float centerY = getHeight ( ) / 2f ; float cropHeight = Math . max ( mCropWindowHandler . getMinCropHeight ( ) , rect . width ( ) / mTargetAspectRatio ) ; float halfCropHeight = cropHeight / 2f ; rect . top = centerY - halfCropHeight ; rect . bottom = centerY + halfCropHeight ; } } else { rect . left = leftLimit + horizontalPadding ; rect . top = topLimit + verticalPadding ; rect . right = rightLimit - horizontalPadding ; rect . bottom = bottomLimit - verticalPadding ; } fixCropWindowRectByRules ( rect ) ; mCropWindowHandler . setRect ( rect ) ; }
set the initial crop window size and position . this is dependent on the size and position of the image being cropped .
