【问题标题】:Android Zxing scanner fail scanning barcode in portrait modeAndroid Zxing 扫描仪在纵向模式下扫描条码失败
【发布时间】:2013-07-09 06:18:28
【问题描述】:

我正在尝试让 Zxing 以纵向模式扫描条形码。以下是我发现的,它适用于扫描二维码。但是,它不扫描一维类型代码(例如条形码)。在代码中,我认为图像已经转换了 90 度。

但是,当我扫描条形码时(如http://en.wikipedia.org/wiki/File:UPC-A-036000291452.png),设备必须切换到横向模式而不是纵向模式。否则扫描仪将永远找不到任何东西......

是我遗漏了什么,还是我必须做一些额外的努力才能将凸轮转换到其他地方?

(来自https://code.google.com/p/zxing/issues/detail?id=178

1、manifest.xml,需要制作CaptureActivity头像。

2、DecodeHandler.java,在buildLuminanceSource之前旋转数据,因为在YCbCr_420_SP和YCbCr_422_SP中,Y通道是平面的,首先出现


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];

3、CameraManager.java、getFramingRectInPreview()需要修改。


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;

4、CameraConfigurationManager.java,在setDesiredCameraParameters()使用中设置相机方向为纵向


parameters.set("orientation", "portrait");

在 getCameraResolution() 中,您需要交换 x 和 y,因为相机预览大小类似于 480*320,而不是 320*480。


int tmp = cameraResolution.x;
cameraResolution.x = cameraResolution.y;
cameraResolution.y = tmp;
return cameraResolution;

【问题讨论】:

    标签: android camera android-camera barcode zxing


    【解决方案1】:

    只需旋转从相机预览中获得的预览字节。使用您在第二点中编写的功能。第 1、3、4 或 5 点无需执行。

    【讨论】: