In my custom camera, I need to save the orientation for a captured image. This code works perfectly for other android versions. But its not working in 6.0.1. The result which am getting is wrong after saving the attributes to image file.
try {
exif = new ExifInterface(pictureFile.getAbsolutePath());
exif.setAttribute(ExifInterface.TAG_ORIENTATION, "" + orientation);
exif.saveAttributes();
} catch (IOException e) {
e.printStackTrace();
}
Try this for saving the orientation of different angles for captured Images :-
Options options = new Options();
// downsizing image as it throws OutOfMemory Exception for larger
// images
options.inSampleSize = 8;
ExifInterface exif;
try {
exif = new ExifInterface(fileUri.getPath());
int orientation = exif.getAttributeInt(
ExifInterface.TAG_ORIENTATION, 0);
Log.d("EXIF", "Exif: " + orientation);
Matrix matrix = new Matrix();
if (orientation == 6) {
matrix.postRotate(90);
Log.d("EXIF", "Exif: " + orientation);
} else if (orientation == 3) {
matrix.postRotate(180);
Log.d("EXIF", "Exif: " + orientation);
} else if (orientation == 8) {
matrix.postRotate(270);
Log.d("EXIF", "Exif: " + orientation);
}
myBitmap = BitmapFactory.decodeFile(path_img, options);
myBitmap = Bitmap.createBitmap(myBitmap, 0, 0,
myBitmap.getWidth(), myBitmap.getHeight(), matrix,
true);
} catch (Exception e) {
}
The other solutions are rewriting the image instead of manipulating the EXIF information. I would suggest to do it like you tried just with the correct constants:
try {
exif = new ExifInterface(pictureFile.getAbsolutePath());
exif.setAttribute(ExifInterface.TAG_ORIENTATION,
Integer.toString(ExifInterface.ORIENTATION_ROTATE_90));
exif.saveAttributes();
} catch (IOException e) {
e.printStackTrace();
}
Based on the sourcecode you need to use one of these values:
ExifInterface.ORIENTATION_UNDEFINED
ExifInterface.ORIENTATION_NORMAL
ExifInterface.ORIENTATION_FLIP_HORIZONTAL
ExifInterface.ORIENTATION_ROTATE_180
ExifInterface.ORIENTATION_FLIP_VERTICAL
ExifInterface.ORIENTATION_TRANSPOSE
ExifInterface.ORIENTATION_ROTATE_90
ExifInterface.ORIENTATION_TRANSVERSE
ExifInterface.ORIENTATION_ROTATE_270
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With