Zxing Android app does not handle camera display orientation correctly

1,042 views
Skip to first unread message

Eino-Ville Talvala

unread,
Jul 17, 2015, 4:28:52 PM7/17/15
to zx...@googlegroups.com
Hi,

Currently, it seems that the Android barcode scanning app doesn't check the sensor orientation of the camera it runs on. This can lead the camera preview being upside down on devices where the sensor is 180-rotated from the more-common orientation.

The Android device requirements mandate that the long side of the sensor is aligned with the long side of the device, so a landscape app (like barcode scanner) is generally aligned with the sensor. However, the device still has two orientations for the sensor, and apps are expected to check for this when setting up their camera parameters.

The Android docs contain boilerplate to implement this:
http://developer.android.com/reference/android/hardware/Camera.html#setDisplayOrientation(int)

We're now seeing a device or two with reports of rotated preview from the Zxing barcode scanner, so hopefully you can add this support soon!

Thanks,

Eino-Ville Talvala

Sean Owen

unread,
Jul 18, 2015, 4:10:58 PM7/18/15
to zx...@googlegroups.com, etal...@google.com
It only supports landscape -- not reverse landscape. But I think it's correct AFAIK. If you have a suggested change please open a PR.

Eino-Ville Talvala

unread,
Jul 21, 2015, 2:55:12 PM7/21/15
to zx...@googlegroups.com, etal...@google.com
On Saturday, July 18, 2015 at 1:10:58 PM UTC-7, Sean Owen wrote:
> It only supports landscape -- not reverse landscape. But I think it's correct AFAIK. If you have a suggested change please open a PR.

No, the issue is that the sensor is not guaranteed by Android to be aligned with landscape orientation. It may also be in reverse landscape, and the old Android camera API requires applications to explicitly account for this, by calling setDisplayOrientation() with the right rotation amount.

Since most devices have their sensor aligned with landscape and not reverse landscape, and the camera API display orientation defaults to 0, it's easy to miss this requirement.

It'll be a while before I'd have time to write up a PR for you; this is mostly a heads-up that you may get user reports of this issue soon, as devices that have sensors in reverse landscape are starting to appear.

The Nexus 6 has a reverse-landscape sensor for its front camera, for example, but since the barcode scanner uses the rear camera, you haven't run into it yet.

Sean Owen

unread,
Jul 24, 2015, 2:45:19 AM7/24/15
to zxing, etal...@google.com, etal...@google.com
I remember dealing with this a long time ago, and understand that the sensor can be mounted in different orientations. The BS+ app deals with front/back and all 4 orientations. It's been a while since I looked at it though. I thought the defaults were such that the image data was always consistent with a certain orientation by default, but would not be surprised to hear that's not right. If you have a draft PR to look at at some point I can triangulate against what I did in BS+ and try to figure it out.

Eino-Ville Talvala

unread,
Aug 21, 2015, 1:49:34 PM8/21/15
to zxing, etal...@google.com
Unfortunately, I probably won't have a chance to write a PR any time soon (witness the month it's taken me to reply this time), but the boilerplate code at
http://developer.android.com/reference/android/hardware/Camera.html#setDisplayOrientation(int)
should be fairly easy to adapt to your needs.

Alan Newberger

unread,
Oct 26, 2015, 1:44:35 PM10/26/15
to zxing, etal...@google.com
Reply all
Reply to author
Forward
0 new messages