When I am uploading an image to Firebase Storage It saves In the wrong orientation. I upload an image which has been taken in portrait orientation but it is being displayed in landscape orientation and always to the left.
When the user is uploading an image from the gallery on their phone I want it to retain the orientation that the image was taken in. I have looked at using an ExifInterface but that hasn't worked and I've also tried using Picasso.
To display images at the moment I am using Picasso.
Picasso.get().load(profileImage).resize(350, 350).transform(new CircleTransformation()).into(profileImageUri);
My question is, How can I maintain the Images orientation that the image was taken in and display it to the user?
Here is my Code thus far:
// uupload users profile image
uploadProfileImage.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
// intent to gallery area
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image/*");
startActivityForResult(intent, GALLERY_INTENT);
}
});
return view;
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
final FirebaseUser user = auth.getCurrentUser();
if (requestCode == GALLERY_INTENT && resultCode == RESULT_OK)
{
progressDialog.setMessage("Uploading Image Please Wait...");
progressDialog.show();
final Uri uri = data.getData();
final StorageReference filePath = storageReference.child("Images").child(user.getUid()).child(uri.getLastPathSegment());
this.filePath = filePath;
// Put the file in the Firebase Storage Area
filePath.putFile(uri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>()
{
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot)
{
progressDialog.dismiss();
Toast.makeText(getActivity(), "Uploaded Successfully!", Toast.LENGTH_SHORT).show();
Uri downloadUri = taskSnapshot.getDownloadUrl();
// Saving the URL under the "Users" table, under the "Users ID" In the Firebase Database to later retrieve it
myRef.child("Users").child(user.getUid()).child("profileImage").setValue(downloadUri.toString());
}
}).addOnFailureListener(new OnFailureListener()
{
@Override
public void onFailure(@NonNull Exception e)
{
progressDialog.dismiss();
Toast.makeText(getActivity(), "Failed To Upload!", Toast.LENGTH_SHORT).show();
}
});
}
}
How the image is being stored in the Firebase Storage Area
How the image is being displayed in the Navigation Drawer
This image was taken in Portrait Orientation. Not landscape.
** EDIT **
This image is different as other questions state to use picasso and use rotate function but that is not a going to work for my problem as I have a variable upload for an image. Additionally, my solution, the answer I will upload works for fragments and other solutions only work for activities. My code works well and can upload to firebase with the correct orientation.