我正在尝试让 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;