-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Fix taken picture is not rotated upright to device orientation in some device and emulator #2569
base: master
Are you sure you want to change the base?
Conversation
| if (Build.VERSION.SDK_INT >= 21) { | ||
| CameraManager manager = (CameraManager) mThemedReactContext.getSystemService(Context.CAMERA_SERVICE); | ||
| try { | ||
| String cameraId = manager.getCameraIdList()[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure this won't cause issues? Always getting the first available camera? What if the picture was taking with the front camera?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is nice catch. I will update the code.
| int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, | ||
| ExifInterface.ORIENTATION_UNDEFINED); | ||
|
|
||
| int cameraOrientation = getCameraOrientation(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are getting the camera orientation after the picture has been taken in an async task. The phone might have been rotated by now to another position. Have you tried what happens in such case? You will probably be using a rotation that's different than what the picture was taken with. You may need to do this on the picture captured events of each camera implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can probably already get the camera orientation from each Camera implementation from these lines. The implementation will already handle getting the orientation from the right camera.
https://github.com/react-native-community/react-native-camera/blob/master/android/src/main/java/com/google/android/cameraview/Camera1.java#L768
https://github.com/react-native-community/react-native-camera/blob/master/android/src/main/java/com/google/android/cameraview/Camera2.java#L693
So rather than getting the camera orientation after the picture has been taken and the image is getting processed, you may be able to get it right before the capture event from those lines, and pass it down to the async task. What do you think? That would ensure you always get the orientation from the right camera, at the right time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pushed new commit. Please, check this out
|
Do you know what devices this happens with? I've never seen this reported so far, but since I'm using I really thought EXIF would be enough to fix any orientation issues, have you found any phone that does not use EXIF and also takes pictures rotated? I'm curious to test this, but need the specific device so I can inquire the users using it to see if they had issues. |
android/.classpath
Outdated
| @@ -0,0 +1,6 @@ | |||
| <?xml version="1.0" encoding="UTF-8"?> | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably don't want to include eclipse files in your commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this issue occures very rare with specific devices in our customers.
Such as 57513 OPPO CPH1853 android 8.1.0, samsung SM-T295 android 9, OPPO CPH1911 android 9, samsung SM-A750GN android 9, OnePlus ONEPLUS A5010 android 9, LG K10 android 5.1.1 and also emulators whichs android below android 5.1.1
|
|
||
| mOrientation = Constants.ORIENTATION_AUTO; | ||
| mCallback.onPictureTaken(data, displayOrientationToOrientationEnum(mDeviceOrientation)); | ||
| mCallback.onPictureTaken(data, displayOrientationToOrientationEnum(mDeviceOrientation), 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Camera1 implementation doesn't have the orientation value? Why the hard-coded 0? I believe Camera1 has getCameraOrientation to get it's currently selected camera orientation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. That was nice catch. I didn't recognize there was getCameraOrientation function. I have just checked there is no mCameraOrientation member variable, and I thought which is why the cameramanager doesn't suppout <21 android versions. Anyway, I pushed new commit. Pls check it.
…g camera orientation and taken image is rotated 90 degrees. Fix: pass cameraOrientation from Camera instance to ResolveTakenPictureAsyncTask fix getcameraorientation() function in camera1 revert .settings, .classpath, .project file revert classpath
|
Changes look good! Although I don't have time right now to actually run/test it. Have you confirmed it fixes the issues you were seeing with those devices? Most importantly, any breaking change for devices that reports the right exif data? |
6a6045f to
5da376d
Compare
This issue is occured in really rare device such as OPPO CPH1853 android 8.1.0 I 've tested it on LG K10, and android emulators. LG K10 is the only one device which shows this issue. I will monitor other devices from customers data. |
|
I believe that you need to rebase and resolve those conflicts. |
sibelius
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have tests for this?
|
Tested on MI 9 SE The image is saved upside down when using the mirror option. (Same as on master branch) |
Camera sensor orientation doesn't match device native orientation, the image taken by that camera should be rotated upright to device. But some of my clients send us 90 degrees rotated image even if we set up fixOrientation true.
This situation occurs very rare and it depends on hardware camera sensor orientation. I listed devices in which this situation occurs.
57513 OPPO CPH1853 android 8.1.0
samsung SM-T295 android 9
OPPO CPH1911 android 9
samsung SM-A750GN android 9
OnePlus ONEPLUS A5010 android 9
LG K10 android 5.1.1 and android emulators also
I' ve tested this change on LG K10 android 5.1.1 and android emulators. App works properly after this change.
Compatibility
Checklist
I have tested this on a device and a simulator