I've been working on an old project with an outdated Zxing library version that needed to be updated to fix the reverse image bug 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);
}
I'm now facing an issue decoding the barcode on our Nexus 5X device where our EAN-13 barcode seems to be rotated as you can see in the images below.
Nexus 5X
Android 6.0 device
That's a known issue, which is reported on the tracker.
Status: Won't Fix (Intended Behavior)
The main camera of the Nexus 5X has an unusual orientation - by Android compatibility requirements the sensor long edge has to align with the long edge of the device, which means the sensor is oriented either landscape or reverse-landscape. Most Android devices have a landscape-oriented sensor, but the 5X is reverse-landscape.
Since most devices are identical, many apps do not correctly check for the sensor orientation and apply the right adjustments. If you more or less copy-paste the sample code here:
http://developer.android.com/reference/android/hardware/Camera.html#setDisplayOrientation(int)
for the old camera API, it should set the correct orientation for all types of devices (phones and tablets), sensor orientations, and camera facings (front or back).
As you've noted, the JPEG orientation also has to be set, but this has always been a requirement, so fewer apps get this wrong (since phones are often held at random orientations even if the UI is forced-landscape).
The camera2 API is intentionally more user-friendly here - if you use a SurfaceView, the API ensures the preview is correctly oriented. We can't unfortunately fix the old API to do this for you.
Basically, if you use Camera2 API you shouldn't see that behavior.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With