android-crop icon indicating copy to clipboard operation
android-crop copied to clipboard

Image cropped is rotated.

Open maxouille opened this issue 10 years ago • 36 comments

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

maxouille avatar Sep 10 '14 16:09 maxouille

I have the same issue

akohout avatar Sep 22 '14 12:09 akohout

I also have the same issue

anxiaoyi avatar Oct 22 '14 13:10 anxiaoyi

Same issue here

ghost avatar Oct 23 '14 02:10 ghost

+1

baba43 avatar Oct 29 '14 09:10 baba43

+1

brandon515 avatar Nov 08 '14 04:11 brandon515

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

HughJeffner avatar Dec 02 '14 19:12 HughJeffner

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.

apinder avatar Dec 04 '14 18:12 apinder

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

jdamcd avatar Dec 26 '14 14:12 jdamcd

Any news here?

akohout avatar Jan 06 '15 09:01 akohout

+1

naixx avatar Jan 19 '15 04:01 naixx

+1

zplesac avatar Jan 19 '15 10:01 zplesac

+1

rawGH avatar Jan 21 '15 21:01 rawGH

This might do it: https://github.com/jdamcd/android-crop/tree/exif-same-uri

jdamcd avatar Feb 13 '15 14:02 jdamcd

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.

rawGH avatar Feb 22 '15 11:02 rawGH

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;
    }
}

andhie avatar Apr 15 '15 04:04 andhie

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

mafiu avatar Apr 19 '15 01:04 mafiu

any solution yet ?

naveenchoudhary947 avatar Apr 21 '15 10:04 naveenchoudhary947

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.

kazemimehdi avatar May 15 '15 06:05 kazemimehdi

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

misaka-10032 avatar May 27 '15 04:05 misaka-10032

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

Moretax avatar Jun 02 '15 16:06 Moretax

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

misaka-10032 avatar Jun 03 '15 14:06 misaka-10032

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

exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);

Either portrait and landscape.

Moretax avatar Jun 03 '15 16:06 Moretax

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

misaka-10032 avatar Jun 04 '15 14:06 misaka-10032

At the end... is there a solution?

ivanviragine avatar Jul 08 '15 19:07 ivanviragine

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

fabdarice avatar Aug 21 '15 23:08 fabdarice

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

rodolfopc avatar Oct 03 '15 11:10 rodolfopc

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!

davidesoldan avatar Dec 15 '15 15:12 davidesoldan

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.

stevyhacker avatar Feb 10 '16 14:02 stevyhacker

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(...);

gentooise avatar Mar 25 '16 18:03 gentooise

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

leo9223 avatar May 11 '16 06:05 leo9223

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

stevyhacker avatar May 11 '16 07:05 stevyhacker

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

Lawgrin avatar May 11 '16 09:05 Lawgrin

is there any solution yet?

alicansoysal avatar May 18 '16 08:05 alicansoysal

Same here +1 solution?

alikamts avatar Jun 08 '16 04:06 alikamts

+1

sideprojecteu avatar Jun 11 '16 15:06 sideprojecteu

@jdamcd @Lawgrin any update on the rotation fix ?

https://github.com/jdamcd/android-crop/pull/221

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

thameemulansari avatar Dec 28 '16 14:12 thameemulansari