I am implementing an image upload function to use the mobile phone camera. It is working fine, but the photos are always rotated wrong.
I did read about using the php function exif_read_data. I found codes how to use it and how to change the orientation and how to save it again. Now my problem is (using Android) that the exif_read_data array does not contain any "Orientation", so I am not able to change the orientation. I can not find any hints or posts about this problem. Why is my orientation not stored in this array?
Thanks for any help
I ran into a similar problem a few weeks ago, the only solution I found was to rotate the image accordingly before setting it up on the View. No need to touch stuff related to orientation. Once I used this function, I uploaded my image to Firebase and everything was cool.
public static Bitmap rotateBitmap(Bitmap sourceBitmap, float angle) {
Matrix matrix = new Matrix();
matrix.postRotate(angle);
return Bitmap.createBitmap(sourceBitmap, 0, 0, sourceBitmap.getWidth(), sourceBitmap.getHeight(), matrix, true);
}
Use this function to set it to your ImageView in this case:
if (requestCode == Constants.REQUEST_CODE_CAMERA_PHOTO) {
imgURL = data.getData();
try {
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), imgURL);
bitmap = rotateBitmap(bitmap, -90);
ivProfile.setImageBitmap(bitmap);
}
I hope this helps.