Reputation: 13165
I am taking a picture using a custom front camera in android, but saving the image in the wrong orientation. Can anybody tell me how to avoid this or how to rotate the image and save it in the media store in android? Can anybody provide an example?
Thanks
Upvotes: 2
Views: 3947
Reputation: 33792
You should get the orientation from the EXIF data, like so:
ExifInterface exif = new ExifInterface(sourceFileName); //Since API Level 5
String exifOrientation = exif.getAttribute(ExifInterface.TAG_ORIENTATION);
Similarly, you should use setAttribute()
to change the orientation.
Upvotes: 0
Reputation: 36035
To rotate the image:
Bitmap bmp = getOriginalBitmap();
Matrix rotateMatrix = new Matrix();
rotateMatrix.postRotate(degreeToRotate);
Bitmap rotatedBitmap = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), rotateMatrix, false);
Then you should be able to save it like so:
MediaStore.Images.Media.insertImage(getContentResolver(), rotatedBitmap, "My bitmap", "My rotated bitmap");
Upvotes: 6