I am capturing image and setting to image view. It works fine for me. But the problem is When I'm setting the image to an ImageView it is getting rotated. Any help is appreciated.
Asked
Active
Viewed 173 times
-1
-
1Can u post your code??\ – Vishal Vaishnav Aug 03 '17 at 07:14
-
See this url may help you... https://stackoverflow.com/questions/14066038/why-does-an-image-captured-using-camera-intent-gets-rotated-on-some-devices-on-a – Mohd Saquib Aug 03 '17 at 07:14
-
posting code will help. – Mohammed Farhan Aug 03 '17 at 07:16
2 Answers
2
Use this...
public static Bitmap changeOrientation(Bitmap bitmap, String imagePath) throws IOException {
ExifInterface ei = new ExifInterface(imagePath);
int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
return rotate(bitmap, 90);
case ExifInterface.ORIENTATION_ROTATE_180:
return rotate(bitmap, 180);
case ExifInterface.ORIENTATION_ROTATE_270:
return rotate(bitmap, 270);
case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
return flip(bitmap, true, false);
case ExifInterface.ORIENTATION_FLIP_VERTICAL:
return flip(bitmap, false, true);
default:
return bitmap;
}
}
public static Bitmap rotate(Bitmap bitmap, float degree) {
Matrix matrix = new Matrix();
matrix.postRotate(degree);
return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
}
public static Bitmap flip(Bitmap bitmap, boolean horizontal, boolean vertical) {
Matrix matrix = new Matrix();
matrix.preScale(horizontal ? -1 : 1, vertical ? -1 : 1);
return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
}

Mohd Saquib
- 580
- 4
- 14
-1
You can use compile 'com.kbeanie:multipicker:1.1.1@aar'
library for solving this problem

Pallavi Tapkir
- 781
- 7
- 28