简体   繁体   English

在Nexus 5x上以纵向反转图像

[英]Reverse image on Nexus 5x in portrait

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 . 我一直在研究一个过时的Zxing库版本的旧项目,需要更新以修复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设备上解码条形码的问题,我们的EAN-13条形码似乎在旋转,如下图所示。

Nexus 5X Nexus 5X

Nexus 5X

Android 6.0 device Android 6.0设备

Android 6.0设备

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. Nexus 5X的主摄像头具有不寻常的方向 - 根据Android兼容性要求,传感器长边必须与设备的长边对齐,这意味着传感器可以是横向或反向横向。 Most Android devices have a landscape-oriented sensor, but the 5X is reverse-landscape. 大多数Android设备都有面向横向的传感器,但5X是反向横向的。

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) 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). 对于旧的相机API,它应该为所有类型的设备(手机和平板电脑),传感器方向和相机面板(正面或背面)设置正确的方向。

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). 正如您所指出的那样,JPEG方向也必须设置,但这一直是一个要求,因此更少的应用程序错误(因为即使UI是强制横向的,手机也经常保持随机方向)。

The camera2 API is intentionally more user-friendly here - if you use a SurfaceView, the API ensures the preview is correctly oriented. camera2 API在这里有意更加用户友好 - 如果您使用SurfaceView,API可确保预览正确定向。 We can't unfortunately fix the old API to do this for you. 我们不能不幸地修复旧API来为您执行此操作。

Basically, if you use Camera2 API you shouldn't see that behavior. 基本上,如果您使用Camera2 API,您不应该看到该行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM