If you are looking to rotate an image that is selected image from device then please go through the following steps:-
Step 1:-  select image from gallery to which requires rotation
 Bitmap bitmapImage; 
 File fpath;    
 String root=Environment.getExternalStorageDirectory().toString();              
 fpath = new File(root+"/myImage.jpeg");
Step 2:-  Using ExifInterface to rotate the image.     
    String path=fpath.getAbsolutePath();
    int rotate=0;
    ExifInterface exifInterface;
    int eOrientation=0;
    try
      {
      exifInterface = new ExifInterface(path);
      eOrientation=exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION,ExifInterface.ORIENTATION_NORMAL);
       }
    catch (IOException e)
      {
       e.printStackTrace();
      }
    switch (eOrientation )
     {
      case ExifInterface.ORIENTATION_ROTATE_270:
      rotate = 270;
      break;
      case ExifInterface.ORIENTATION_ROTATE_180:
      rotate = 180;
      break;
      case ExifInterface.ORIENTATION_ROTATE_90:
      rotate = 90;
      break;
     }
    Matrix matrix = new Matrix();
    matrix.postRotate(rotate);
    File image = new File(path);
    BitmapFactory.Options bmOptions = new BitmapFactory.Options();
    Bitmap bitmap = BitmapFactory.decodeFile(image.getAbsolutePath(),bmOptions);
    bitmapImage=Bitmap.createBitmap(bitmap,0,0,bitmap.getWidth(),bitmap.getHeight(),matrix,true);
                       
                    
0 Comment(s)