Nexus 5x reverse image in portrait

I was working on an old project with an outdated version of the Zxing library, which needed to be updated to fix the reverse image error on the Nexus 5x . I managed to update the library, but only portrait mode should be supported.

if (orientation == Configuration.ORIENTATION_LANDSCAPE) { source = activity.getCameraManager().buildLuminanceSource(data, width, height); } else { byte[] rotatedData = new byte[data.length]; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) rotatedData[x * height + height - y - 1] = data[x + y * width]; } int tmp = width; width = height; height = tmp; data = rotatedData; source = activity.getCameraManager().buildLuminanceSource(data, width, height); } 

Now I am faced with the problem of decoding the barcode on our Nexus 5X device, where our EAN-13 barcode seems to rotate, as you can see in the images below.

Nexus 5X

Nexus 5X

Android 6.0

Android 6.0 device

+5
source share
1 answer

This is a known issue that is reported on the tracker .

Status: will not be fixed (alleged behavior)

The main camera of the Nexus 5X has an unusual orientation - according to the requirements of compatibility with Android, the long edge of the sensor should coincide with the long edge of the device, which means that the sensor is oriented both to the landscape and the reverse landscape. Most Android devices have a landscape sensor, but the 5X has a reverse landscape.

Since most devices are identical, many applications incorrectly check the orientation of the sensor and apply the correct settings. If you more or less copy the sample code here:

http://developer.android.com/reference/android/hardware/Camera.html#setDisplayOrientation(int)

for the old camera API, it must set the correct orientation for all types of devices (phones and tablets), the orientation of the sensor and the camera lining (front or rear).

As you already noted, the JPEG orientation should also be set, but this has always been a requirement, so fewer applications are becoming erroneous (since phones are often held in random orientations, even if the user interface is forced),

The camera2 API is intentionally more user-friendly here - if you use SurfaceView, the API ensures that the preview is correctly oriented. Unfortunately, we cannot fix the old API to do this for you.

Basically, if you use the Camera2 API , you should not see this behavior.

+2
source

Source: https://habr.com/ru/post/1267272/


All Articles