public static Bitmap rotateBitmapIfNeededAndCompressIfTold(final Context context,final Uri uri,final String source,final boolean shouldCompress){
  if (!(source.equals("Camera") || (source.equals("Gallery")))) {
    return null;
  }
  Bitmap bm=null;
  String tempPath;
  if (source.equals("Gallery")) {
    tempPath=getPath(context,uri);
  }
 else {
    final File f=new File(uri.getPath());
    tempPath=getPath(context,uri);
  }
  final BitmapFactory.Options btmapOptions=new BitmapFactory.Options();
  bm=BitmapFactory.decodeFile(tempPath,btmapOptions);
  if (shouldCompress) {
    bm=compressManageAspect(400,400,bm);
  }
  if (source.equals("Gallery")) {
    if (PhotoUtils.getOrientation(context,uri) != 0) {
      final Matrix matrix=new Matrix();
      matrix.postRotate(PhotoUtils.getOrientation(context,uri));
      final Bitmap rotatedBm=Bitmap.createBitmap(bm,0,0,bm.getWidth(),bm.getHeight(),matrix,true);
      return rotatedBm;
    }
 else {
      return bm;
    }
  }
 else {
    return bm;
  }
}

public static Bitmap rotateBitmapIfNeededAndCompressIfTold ( final Context context , final Uri uri , final String source , final boolean shouldCompress ) { if ( ! ( source . equals ( "Camera" ) || ( source . equals ( "Gallery" ) ) ) ) { return null ; } Bitmap bm = null ; String tempPath ; if ( source . equals ( "Gallery" ) ) { tempPath = getPath ( context , uri ) ; } else { final File f = new File ( uri . getPath ( ) ) ; tempPath = getPath ( context , uri ) ; } final BitmapFactory . Options btmapOptions = new BitmapFactory . Options ( ) ; bm = BitmapFactory . decodeFile ( tempPath , btmapOptions ) ; if ( shouldCompress ) { bm = compressManageAspect ( 400 , 400 , bm ) ; } if ( source . equals ( "Gallery" ) ) { if ( PhotoUtils . getOrientation ( context , uri ) != 0 ) { final Matrix matrix = new Matrix ( ) ; matrix . postRotate ( PhotoUtils . getOrientation ( context , uri ) ) ; final Bitmap rotatedBm = Bitmap . createBitmap ( bm , 0 , 0 , bm . getWidth ( ) , bm . getHeight ( ) , matrix , true ) ; return rotatedBm ; } else { return bm ; } } else { return bm ; } }
rotate the bitmap and / or compress
