Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to rotate the image in Android?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 149
    Comment on it

    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

    1. Bitmap bitmapImage;
    2. File fpath;
    3. String root=Environment.getExternalStorageDirectory().toString();
    4. fpath = new File(root+"/myImage.jpeg");

    Step 2:- Using ExifInterface to rotate the image.

    1. String path=fpath.getAbsolutePath();
    2. int rotate=0;
    3. ExifInterface exifInterface;
    4. int eOrientation=0;
    5. try
    6. {
    7. exifInterface = new ExifInterface(path);
    8. eOrientation=exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION,ExifInterface.ORIENTATION_NORMAL);
    9. }
    10. catch (IOException e)
    11. {
    12. e.printStackTrace();
    13. }
    14. switch (eOrientation )
    15. {
    16. case ExifInterface.ORIENTATION_ROTATE_270:
    17. rotate = 270;
    18. break;
    19. case ExifInterface.ORIENTATION_ROTATE_180:
    20. rotate = 180;
    21. break;
    22. case ExifInterface.ORIENTATION_ROTATE_90:
    23. rotate = 90;
    24. break;
    25. }
    26. Matrix matrix = new Matrix();
    27. matrix.postRotate(rotate);
    28. File image = new File(path);
    29. BitmapFactory.Options bmOptions = new BitmapFactory.Options();
    30. Bitmap bitmap = BitmapFactory.decodeFile(image.getAbsolutePath(),bmOptions);
    31. bitmapImage=Bitmap.createBitmap(bitmap,0,0,bitmap.getWidth(),bitmap.getHeight(),matrix,true);

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: