about 9 years ago
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
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);
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)