android-crop
android-crop copied to clipboard
Image cropped is rotated.
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
I have the same issue
I also have the same issue
Same issue here
+1
+1
I tried the fix referenced but I got horrible quality output image.
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.
Thanks @apinder. I'll take a proper look at this one (and the PRs) when I'm back at work in the new year.
Any news here?
+1
+1
+1
This might do it: https://github.com/jdamcd/android-crop/tree/exif-same-uri
Does not work for me. Tried on LG G3 Lolipop and a samsung phone android 4.4.4. Behaviour is the same:
- original image is taken by internal camera, and it is rotated, but includes exif rotation info.
- image is correctly shown in the crop activity.
- 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.
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;
}
}
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
any solution yet ?
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.
I think it's an issue of ImageView#setImageURI
. That function doesn't consider exif of the image. Please refer to this solution.
Is there any solution already? I am not able to make it work both same and different source and destination URIs.
@Moretax What's your problem? My solution is change ImageView#setImageURI
to something as is mentioned in this post.
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 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.
At the end... is there a solution?
Anyone tried JohnWowUs's fixed? Anything managed to fix that issue?
I was having the same error, but I started to receive the cropped image with "Uri image = Crop.getOutput(intent);" and this worked.
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!
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.
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(...);
I am facing the same issue on Samsung Tab E but not on Nexus 5 emulator :( don't know what to do
@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.
I have forked this and implemented the fix along with added a specify min size Please see here
is there any solution yet?
Same here +1 solution?
+1
@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?