Skip to content
This repository has been archived by the owner on Jan 7, 2023. It is now read-only.

Image cropped is rotated. #46

Open
maxouille opened this issue Sep 10, 2014 · 36 comments
Open

Image cropped is rotated. #46

maxouille opened this issue Sep 10, 2014 · 36 comments
Labels

Comments

@maxouille
Copy link

Hi !

I found your lib and it's a very good work. Thank you very much.

However, i have a little problem. When my image is cropped, result picture is rotated (90 on the right).

Is a known issue or it's just me ?

Thx :p

@akohout
Copy link

akohout commented Sep 22, 2014

I have the same issue

@anxiaoyi
Copy link

I also have the same issue

@ghost
Copy link

ghost commented Oct 23, 2014

Same issue here

@baba43
Copy link

baba43 commented Oct 29, 2014

+1

1 similar comment
@brandon515
Copy link

+1

@HughJeffner
Copy link

I tried the fix referenced but I got horrible quality output image.

@apinder
Copy link

apinder commented Dec 4, 2014

It should use the Exif orientation tag to orientate the image correctly. If you're viewing the cropped image later on you'll need to use the ExifInterface and rotate the image accordingly. The image is more than likely rotated by the camera rather than android-crop.

However, if you use the same input URI as the output URI the Exif orientation data will not get copied, the only solution to this is it to use a different URI for the output URI than the input. I've raised an issue here regarding this, it should be a simple fix but as the project is built with Gradle + Android Tools it's hard for me to do the fix without first learning a new IDE and build tool.

@jdamcd
Copy link
Owner

jdamcd commented Dec 26, 2014

Thanks @apinder. I'll take a proper look at this one (and the PRs) when I'm back at work in the new year.

@akohout
Copy link

akohout commented Jan 6, 2015

Any news here?

@jdamcd jdamcd added the bug label Jan 9, 2015
@naixx
Copy link

naixx commented Jan 19, 2015

+1

2 similar comments
@zplesac
Copy link

zplesac commented Jan 19, 2015

+1

@rawGH
Copy link

rawGH commented Jan 21, 2015

+1

@jdamcd
Copy link
Owner

jdamcd commented Feb 13, 2015

@rawGH
Copy link

rawGH commented Feb 22, 2015

Does not work for me. Tried on LG G3 Lolipop and a samsung phone android 4.4.4.
Behaviour is the same:

  1. original image is taken by internal camera, and it is rotated, but includes exif rotation info.
  2. image is correctly shown in the crop activity.
  3. image is stored after cropping.

Resulting image has no exif data and is incorrectly rotated.

Edit: input and output URIs are different.

Edit2:
I was hacking the code too much so I deleted everything and made a new project with android studio, clean crop lib download.
The difference is that now the images are not shown correctly even in the crop activity. Lolipop LG G3.

@andhie
Copy link

andhie commented Apr 15, 2015

In CropUtil#getExifRotation and CropUtil#saveExifRotation is poorly named, causing a bug where wrong exif value is saved. i dont think its appropriate to call the result of getExifRotation as exifRotation as its actually the photo rotation in degrees. When you call the saveExifRotation and pass in the rotation (in degrees) it save the wrong value. It needs to be translated back into the correct exif values (0, 1, 3, 6, 8)

public static boolean saveExifRotation(File file, int exifRotation) {
    if (file == null) return false;
    try {
        ExifInterface exifDest = new ExifInterface(file.getAbsolutePath());
        int exifValue;
        switch (exifRotation) {
            case 0:
                exifValue = ExifInterface.ORIENTATION_NORMAL;
                break;
            case 90:
                exifValue = ExifInterface.ORIENTATION_ROTATE_90;
                break;
            case 180:
                exifValue = ExifInterface.ORIENTATION_ROTATE_180;
                break;
            case 270:
                exifValue = ExifInterface.ORIENTATION_ROTATE_270;
                break;
            default:
                exifValue = ExifInterface.ORIENTATION_UNDEFINED;
                break;
        }
        exifDest.setAttribute(ExifInterface.TAG_ORIENTATION, String.valueOf(exifValue));
        exifDest.saveAttributes();
        return true;
    } catch (IOException e) {
        Log.e("Error saving Exif rotation data", e);
        return false;
    }
}

@mafiu
Copy link

mafiu commented Apr 19, 2015

My behavior is the same as described by @rawGH I try a lot of things but nothing works. I'm using a Samgung Galaxy S4 with Android 5.0.2

@naveenchoudhary947
Copy link

any solution yet ?

@kazemimehdi
Copy link

I solved this issue temporarily with using landscape screen orientation for CropImageActivity.
However, this is a frustrating bug. I hope android-crop contributors consider it.

@misaka-10032
Copy link

I think it's an issue of ImageView#setImageURI. That function doesn't consider exif of the image. Please refer to this solution.

@Moretax
Copy link

Moretax commented Jun 2, 2015

Is there any solution already? I am not able to make it work both same and different source and destination URIs.

@misaka-10032
Copy link

@Moretax What's your problem? My solution is change ImageView#setImageURI to something as is mentioned in this post.

@Moretax
Copy link

Moretax commented Jun 3, 2015

The problem with this approach is that I always get 0 in this line:

exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);

Either portrait and landscape.

@misaka-10032
Copy link

@Moretax Then it should be. I tested on Nexus 5 and Samsung Note 3, they both work fine. Nexus 5 seems to always take a picture without orientation, while samsung sometimes have an orientation and sometimes doesn't. I've read some part of the code and find that the cropped image have copied the exif from the photo that has been taken. It seems to be ok. I don't know your phone model and the exact scenario that makes you feel like it's rotated. I'm not a maintainer; I just use this library and think it works just fine.

@ivanviragine
Copy link

At the end... is there a solution?

@fabdarice
Copy link

Anyone tried JohnWowUs's fixed? Anything managed to fix that issue?

@rodolfopc
Copy link

I was having the same error, but I started to receive the cropped image with "Uri image = Crop.getOutput(intent);" and this worked.

@davidesoldan
Copy link

It seem to me that android-crop clears the exif IfD1 information tags (thumbnail information tags). This shouldn't be a problem because we are not working with a thumbnail but only with a part of the original image. Actually trying to open the cropped image with gimp or other tools all works fine.
Maybe it could be a problem with android image view? If you try to load the cropped image into the image view with a library like Picasso, the cropped image is displayed correctly!

@stevyhacker
Copy link

I have this issue only on samsung phones when taking pictures from the front camera, I added the exif orientation fix it works for the back camera images but not for the ones taken with the front camera. Also images from the gallery work fine, and on other phones it works properly.

@gentooise
Copy link

Same issue here, simply solved by performing rotation before starting crop activity:

        // Crop does not return proper exif info
        // Need to rotate before cropping, saving to another temp file
        Uri imageUri = ...;
        Bitmap bm = getBitmapFromUri(imageUri, ...);
        int rotation = getRotation(imageUri, ...);
        bm = rotate(bm, rotation);

        Uri source = saveBitmap(bm, getTempFile(...), ...);
        Uri destination = Uri.fromFile(getTempFile(...));

        Crop.of(source, destination).asSquare().start(...);

@leo9223
Copy link

leo9223 commented May 11, 2016

I am facing the same issue on Samsung Tab E but not on Nexus 5 emulator :( don't know what to do

@stevyhacker
Copy link

@leo9223 you can try to have different code for samsung devices and the others, for example if device is from samsung rotate the picture and if it isn't go straight to cropping.

@Lawgrin
Copy link

Lawgrin commented May 11, 2016

I have forked this and implemented the fix along with added a specify min size
Please see here

@alicansoysal
Copy link

is there any solution yet?

@alikamts
Copy link

alikamts commented Jun 8, 2016

Same here +1 solution?

@sideprojecteu
Copy link

+1

@thameemulansari
Copy link

@jdamcd @Lawgrin any update on the rotation fix ?

#221

Please advise . Looking for the fix to retain orientation in android?

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

No branches or pull requests