private ImageSize computeSizeToFit(float maxSide){
  if (0 == maxSide) {
    return new ImageSize(0,0);
  }
  ImageSize resized=new ImageSize(this);
  if ((this.mWidth > maxSide) || (this.mHeight > maxSide)) {
    double ratioX=maxSide / this.mWidth;
    double ratioY=maxSide / this.mHeight;
    double scale=Math.min(ratioX,ratioY);
    scale=1.0d / Integer.highestOneBit((int)Math.floor(1.0 / scale));
    resized.mWidth=(int)(Math.floor(resized.mWidth * scale / 2) * 2);
    resized.mHeight=(int)(Math.floor(resized.mHeight * scale / 2) * 2);
  }
  return resized;
}

private ImageSize computeSizeToFit ( float maxSide ) { if ( 0 == maxSide ) { return new ImageSize ( 0 , 0 ) ; } ImageSize resized = new ImageSize ( this ) ; if ( ( this . mWidth > maxSide ) || ( this . mHeight > maxSide ) ) { double ratioX = maxSide / this . mWidth ; double ratioY = maxSide / this . mHeight ; double scale = Math . min ( ratioX , ratioY ) ; scale = 1.0d / Integer . highestOneBit ( ( int ) Math . floor ( 1.0 / scale ) ) ; resized . mWidth = ( int ) ( Math . floor ( resized . mWidth * scale / 2 ) * 2 ) ; resized . mHeight = ( int ) ( Math . floor ( resized . mHeight * scale / 2 ) * 2 ) ; } return resized ; }
compute the image size to fit in a square .
