0

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

Image And Details In Database

How the image is being displayed in the Navigation Drawer

This image was taken in Portrait Orientation. Not landscape.

How the image is being rendered to the Navigation Drawer

** 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.

javacoder123
  • 193
  • 3
  • 17
  • How did you go about solving this? Did you rotate prior to uploading to Firebase? – njho Mar 27 '18 at 00:46
  • I solved this by using an ExifInterface and changing some code around to suit my situation. I will upload the code as an answer so you can view it. – javacoder123 Mar 29 '18 at 14:44
  • I did rotate prior to upload using an ExifInterface. – javacoder123 Mar 29 '18 at 14:57
  • Any issues with memory usage, or slow performance doing it on device? I heart it might be easier to do it on server due to device performance – njho Mar 29 '18 at 19:14
  • I would say a slight delay between the user selecting the image and it is displayed on the fragment. However, I wouldn't say it's a major issue – javacoder123 Mar 30 '18 at 09:19
  • Awesome, thanks man. Any chance you can upload that code. Feel free to contact me. I think my info is on my SO profile too – njho Mar 30 '18 at 19:11
  • How did you solve ? – Abu Saeed Jan 15 '22 at 17:25

0 Answers0