Nexus 5x captured image is inverted
When taking a picture using a Nexus 5x the picture is inverted (upside down) I was looking for a fix regarding this issue here since it's Google sample :)
Are you using this sample's source code to take the picture?
Yes I am.
It looks like doing :
CameraManager manager = (CameraManager) getContext().getSystemService(Context.CAMERA_SERVICE);
CameraCharacteristics cameraCharacteristics = manager.getCameraCharacteristics("" + mCameraDevice.getId());
int rotation = cameraCharacteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, rotation);
instead of :
int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, ORIENTATIONS.get(rotation));
fixes the issue (at least on Nexus 5 and Nexus 5x)
Do you want me to submit a PR with this ?
@keyboardsurfer @yaraki any progress on this ? I can't figure out how to do this right. I'm getting problem on Galaxy S6 which has inverted (upside down) Front facing camera picture... :(
Hi, @gbero .
Please use the formula below instead of ORIENTATIONS.get(rotation).
private int getOrientation(int rotation) {
return (ORIENTATIONS.get(rotation) + mSensorOrientation + 270) % 360;
}
I'm applying this change to the sample soon.
EDIT: mSensorOrientation is a field assigned from characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION) in setUpCameraOutputs.
Hi @yaraki,
I've tested your
private int getOrientation(int rotation) { return (ORIENTATIONS.get(rotation) + mSensorOrientation + 270) % 360; }
method and its not working on Nexus 5x on Back camera. Image is still rotated in final output. If you take portrait image it will save it rotated for 90 degrees. On the other side @gbero 's solution works perfectly on Nexus 5X.
@yaraki @keyboardsurfer I'm getting complaints from users with Nexus 6 that FFC picture is inverted and can't figure out how to handle it. Could Google come up with a sample tested on at least devices like N5, N5x, N6 and N6p both front and rear camera ?
Any update here?
Any news on this front? Having the same issue.
I think I fixed this issue but I'm not 100% sure if this is the best fix. I got the sensor orientation from the camera characteristics and then I just added an ExifInterface with the desired fixed orientation for the image file. Like this:
Integer sensorOrientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION); if (sensorOrientation != null) { switch (sensorOrientation) { case 90: exif.setAttribute(ExifInterface.TAG_ORIENTATION, String.valueOf(ExifInterface.ORIENTATION_ROTATE_90)); break; case 180: exif.setAttribute(ExifInterface.TAG_ORIENTATION, String.valueOf(ExifInterface.ORIENTATION_ROTATE_180)); break; case 270: exif.setAttribute(ExifInterface.TAG_ORIENTATION, String.valueOf(ExifInterface.ORIENTATION_ROTATE_270)); break; } exif.saveAttributes();
How to rotate for video capture?
Is there a solution for video preview? Cant find anything to solve it.
Still with this fix. I have an issues with it. On the Phone the Images looks fine. But when I send them with email to my PC. (In preview they still look fine.) Once it's on my pc , it's rotated -90. From 3 phones that I have LGG4, Samsung J7 and Sony Experia (something). Only works on the LGG4 ( and it takes 16:9 images , others take 4:3).
I don't think its Windows fault, because when I capture the image and save it. Then load it on a ImageView , its rotated.
The pictures are not being saved ?
Same for me, it is working fine on Pixel, Oppo, Micromax, Gionee but is rotated -90 degree on Samsung, can any one suggest a fix .. please
I have the same problem. The picture in preview mode is rotated -90. I could not find how to fix this except for checking if it's Samsung phone and then rotating the picture my self. I thought that this Camera 2 api's should be much easier to use, but they introduce so many problems that you did not had with Camera 1. And what is worse, there is no real feedback or solution for this problem, in like one year now, with so many people complaining.
Can somebody tell, How to calculate JPEG_ORIENTATION for front camera? I used (ORIENTATIONS.get(rotation) + mSensorOrientation + 270) % 360; for back camera. which is working just fine.
Not Working for Front Camera.Tested on S5(Samsung).
This sample has been migrated to a new location where we can accept Pull Requests (check README for more information).
As recommended by GitHub, we are closing all issues and pull requests now that this older repo will be archived.
If you still see this issue in the updated repo, please reopen the issue/PR there. Thank you!
This sample has been migrated to a new location where we can accept Pull Requests (check README for more information).
As recommended by GitHub, we are closing all issues and pull requests now that this older repo will be archived.
If you still see this issue in the updated repo, please reopen the issue/PR there. Thank you!