Android的Zxing改变方向为纵向纵向、方向、Android、Zxing

2023-09-04 08:05:48 作者:其实丶我在隐身

我想读的几个问题,并张贴关于发行后旋转Zxing显示。 下面的说明之后,显示并旋转,但扫描仪的矩形 没有定位,它应(如可以看到附接在图像上)。

I'm trying to rotate Zxing display after reading a few questions and posts about the issue. After following the instructions, the display did rotate, but the rectangle of the scanner is not positioned as it should (as can be seen on the image attached).

这是我做了什么:

在CameraConfigurationManager:

in CameraConfigurationManager:

camera.setDisplayOrientation(90);

整理 Android 常见错误

在德codeHandler.java

in DecodeHandler.java

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;

在CameraManager.java:

in CameraManager.java:

rect.left = rect.left * cameraResolution.y / screenResolution.x;
rect.right = rect.right * cameraResolution.y / screenResolution.x;
rect.top = rect.top * cameraResolution.x / screenResolution.y;
rect.bottom = rect.bottom * cameraResolution.x / screenResolution.y;

推荐答案

很多挣扎后,我发现这个问题,我希望这将帮助别人的未来。

After a lot of struggling, I found the problem, and I hope it will help someone in the future.

initFromCameraParameters 的方法 CameraConfigurationManager 有一个假设,即扫描总是风景模式,并为此修复时,宽度LT;身高。 如果您按照问题的步骤,并删除此检查,它工作正常。

On initFromCameraParameters method in CameraConfigurationManager there is an assumption that the scan is ALWAYS in landscape mode, and therefor a fix when width < height. If You follow the steps in the question and remove this check, it works fine.