Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Portait photos rotated 90deg in crop view on Samsung device #4

Open
magdini opened this issue May 2, 2017 · 14 comments
Open

Portait photos rotated 90deg in crop view on Samsung device #4

magdini opened this issue May 2, 2017 · 14 comments

Comments

@magdini
Copy link

magdini commented May 2, 2017

When loading InstaCropperView with an image from Samsung device (s6 edge+ in my case) the image shows up rotated 90deg.

@yasharpm
Copy link
Owner

yasharpm commented May 5, 2017

I discovered this bug and fixed it a while ago. Maybe sync with the latest version and check again?

@magdini
Copy link
Author

magdini commented May 5, 2017

im using the this in gradle: com.yashoid:instacropper:1.0.5 like in the readme, is there a newer version?

@yasharpm
Copy link
Owner

yasharpm commented May 5, 2017

No there is no newer version. This is a real bug.

How does it work in these 3 cases:

  • You take a photo while the device is landscape
  • You pick a photo from pictures and not camera
  • You pick a camera photo which is landscape

@magdini
Copy link
Author

magdini commented May 5, 2017

You take a photo while the device is landscape

Displays correctly. (if taken in portrait, picture is rotated -90deg)

You pick a photo from pictures and not camera

Displays correctly for pictures taken in landscape. Pictures taken in Portrait is rotated -90deg (counter clockwise)

You pick a camera photo which is landscape

Displays correctly.

@johnernest02
Copy link

Any solutions for this?

@yasharpm
Copy link
Owner

I will fix it as soon as I get a time to myself again! I'm gonna need someone to test it for me because I do not have the device to test. It is working fine on my device (Pixel).

Is anyone willing to communicate with me more closely so that he/she can test it as I try to fix?

@magdini
Copy link
Author

magdini commented May 15, 2017

I can help you test it since its rotated on my device

@yasharpm
Copy link
Owner

I think I managed to fix it. Please check and let me know. Thanks. New version is 1.0.6

@magdini
Copy link
Author

magdini commented May 20, 2017

I am still having the rotation problems with 1.0.6 . I will give you a link to a photo that has the rotation problem (its taken in portrait on samsung s6 edge+) so its easier for you to test it:
https://goo.gl/photos/2LrthiKx7zE1WDM5A

When i load this image into the cropper its shown rotated -90 degrees.

I load it just like this from the gallery picker:

public void startGalleryIntent() {
        Intent galleryIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
        if (galleryIntent.resolveActivity(getActivity().getPackageManager()) != null) {
            startActivityForResult(galleryIntent, REQUEST_GALLERY);
        }
    }

public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode != RESULT_OK) {
            //TODO: Show some error somewhere
            return;
        }
        // GALLERY PICKER RESULT
        else if (requestCode == REQUEST_GALLERY && resultCode == RESULT_OK) {
            Uri photoUri = data.getData();
            ((NewPostActivity) getActivity()).startCropFragment(photoUri);
        }
    }

And init the cropper with this:

mCropView.setImageUri(photoUri);
mCropView.setRatios(1,1,1);
mCropView.setBackgroundColor(getResources().getColor(R.color.colorDarkGray));

@yasharpm
Copy link
Owner

The photo is turned. Even my computer opens it turned. I looked it up and it seems like it is a manufacturer bug. Also follow the code.google.com link in the comment for further information.

I have added code that tries to read the orientation data prom the image file itself. But if it isn't present in the image file there is nothing possible to be done on the code side.

You probably need to add a rotate button and pass the rotated image URI to InstaCropper view again.

@yasharpm
Copy link
Owner

Just realized your image is valid. Orientation data exists on it. Windows showed it rotated but Photoshop opens is correctly. I'm gonna try fixing further.

@magdini
Copy link
Author

magdini commented May 21, 2017

Nice to hear that the image has the data needed! I see it rotated correctly in most places like google photos (web+app), gallery picker, windows image viewer etc. Its good to hear that data is in the image so there is no need for hardcoding manufacturer+phone models for rotation :)

@robsred
Copy link

robsred commented Jun 7, 2017

Hello! Has there been any progress regarding this issue? Thanks

@robsred
Copy link

robsred commented Jun 12, 2017

Hello! After coming across the issue quite a few times in other devices (i.e LG G4), I took a better look at the code and realised that the problem lies within the MakeDrawableTask.java class at the following line of the getRotation(uri, context) method:

ei = new ExifInterface(uri.toString());

which resolves for devices running up to Marshmallow. I couldn't reproduce the issue with newer OS versions such as Nougat, but it kept appearing to older ones. Long story short, just change the above line to:

ei = new ExifInterface(uri.getPath());

as the .toString() call generates a path prefixed with "file://" and that doesn't seem to be agreeable with the path's resolution in this case. Furthermore, using only the path-based constructor of the ExifInterface class seems to work for all OS versions and devices; so no real need for the version-check IF.

P.S Don't forget to also handle the onBackPressed in you cropping activity - in conjunction with the above - if you are allowing the original image to be fed as a result without 'cropping'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants