yasharpm / InstaCropper

A View for cropping images that is similar to Instagram's crop which allows a range of aspect ratios instead of a solid ratio. Also an Activity for cropping is included.
377 stars 44 forks source link

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

Open magdini opened 7 years ago

magdini commented 7 years ago

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

yasharpm commented 7 years ago

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

magdini commented 7 years ago

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

yasharpm commented 7 years ago

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

How does it work in these 3 cases:

magdini commented 7 years ago

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 commented 7 years ago

Any solutions for this?

yasharpm commented 7 years ago

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 commented 7 years ago

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

yasharpm commented 7 years ago

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

magdini commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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

robsred commented 7 years ago

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