Skip to content
This repository was archived by the owner on Jun 16, 2023. It is now read-only.

Conversation

@Chimaa123
Copy link

@Chimaa123 Chimaa123 commented Nov 6, 2019

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

OS Implemented
Android

Checklist
I have tested this on a device and a simulator

if (Build.VERSION.SDK_INT >= 21) {
CameraManager manager = (CameraManager) mThemedReactContext.getSystemService(Context.CAMERA_SERVICE);
try {
String cameraId = manager.getCameraIdList()[0];
Copy link
Contributor

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?

Copy link
Author

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();
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Author

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

@cristianoccazinsp
Copy link
Contributor

Do you know what devices this happens with? I've never seen this reported so far, but since I'm using skipProcessing: true and fixOrientation: false I wouldn't know if I have actually faced this problem at all. Most likely because the image resizing library already handles EXIF data and rotates it accordingly.

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.

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
Copy link
Contributor

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.

Copy link
Author

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

@Chimaa123 Chimaa123 changed the title Fix camera orientation of some hardware and emulator which gives wron… WIP Fix camera orientation of some hardware and emulator which gives wron… Nov 7, 2019
@Chimaa123 Chimaa123 changed the title WIP Fix camera orientation of some hardware and emulator which gives wron… Fix taken picture is not rotated upright to device orientation in some device and emulator Nov 7, 2019

mOrientation = Constants.ORIENTATION_AUTO;
mCallback.onPictureTaken(data, displayOrientationToOrientationEnum(mDeviceOrientation));
mCallback.onPictureTaken(data, displayOrientationToOrientationEnum(mDeviceOrientation), 0);
Copy link
Contributor

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.

Copy link
Author

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
@cristianoccazinsp
Copy link
Contributor

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?

@Chimaa123
Copy link
Author

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?

This issue is occured in really rare device such as 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.

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.

@fabOnReact
Copy link
Contributor

I believe that you need to rebase and resolve those conflicts.

Copy link
Collaborator

@sibelius sibelius left a 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?

@Kuhne1
Copy link

Kuhne1 commented Mar 18, 2020

Tested on MI 9 SE
MIUI V11.0.2
React-Native 61.5

The image is saved upside down when using the mirror option. (Same as on master branch)
It is fine on all other android devices I have tested on.

@fabOnReact fabOnReact mentioned this pull request Mar 20, 2020
5 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants