Whenever i try to capture photo in my custom camera i am not able to detect its orientation. Captured image stored in sd card and then i retrieve for preview i use ExifInterface for orientation but orientation of image always in ExifInterface.ORIENTATION_NORMAL mode whether i captured it landscape or portrait. I have tried all the things but doesn't find Any solution.
Matrix mat = new Matrix();
ExifInterface exif = new ExifInterface(path);
String orientstring = exif.getAttribute(ExifInterface.TAG_ORIENTATION);
int orientation = orientstring != null ? Integer.parseInt(orientstring) : ExifInterface.ORIENTATION_NORMAL;
int rotateangle = 0;
if (orientation == ExifInterface.ORIENTATION_NORMAL){
rotateangle = 90;
}
if(orientation == ExifInterface.ORIENTATION_ROTATE_90)
rotateangle = 90;
if(orientation == ExifInterface.ORIENTATION_ROTATE_180)
rotateangle = 180;
if(orientation == ExifInterface.ORIENTATION_ROTATE_270)
rotateangle = 270;
mat.setRotate(rotateangle, (float) bitmap.getWidth() / 2, (float) bitmap.getHeight() / 2);
File f = new File(path);
Bitmap bmpPic = BitmapFactory.decodeStream(new FileInputStream(f), null, null);
int widthBmp=bmpPic.getWidth();
int heightBmp=bmpPic.getHeight();
if (heightBmp < widthBmp){
bitmap = Bitmap.createBitmap(bmpPic, 0, 0, bmpPic.getWidth(), bmpPic.getHeight(), mat, true);
}
return bitmap;
Thanks for Help in advance.