简体   繁体   English

Android Zxing扫描仪无法在纵向模式下扫描条形码

[英]Android Zxing scanner fail scanning barcode in portrait mode

I am trying to make Zxing to scan barcode in portrait mode. 我正在尝试使Zxing以纵向模式扫描条形码。 The following is what I found and it worked in scanning QRcode. 以下是我发现的内容,它可用于扫描QRcode。 However, it DOES NOT scan 1D type code(Barcode for example). 但是,它不扫描一维类型代码(例如条形码)。 In the code, I think the image has been transformed for 90 degree. 在代码中,我认为图像已转换90度。

However, When I scan the barcode(like http://en.wikipedia.org/wiki/File:UPC-A-036000291452.png ), device must be turned to landscape mode and not on portrait mode. 但是,当我扫描条形码时(例如http://en.wikipedia.org/wiki/File:UPC-A-036000291452.png ),必须将设备转到横向模式而不是纵向模式。 Or the scanner will never actually find anything.... 否则扫描仪将永远找不到任何东西。

Is there something I am missing, or I have to do some extra effort to transform the cam somewhere else? 是否有我缺少的东西,或者我需要付出额外的努力才能将凸轮转换到其他地方?

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

1, manifest.xml, you need to make CaptureActivity portrait. 1,manifest.xml,需要制作CaptureActivity肖像。

2, DecodeHandler.java, rotate data before buildLuminanceSource, it works because in YCbCr_420_SP and YCbCr_422_SP, the Y channel is planar and appears first 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() need to be modified. 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, set camera orientation to portrait in setDesiredCameraParameters() use 4,CameraConfigurationManager.java,在setDesiredCameraParameters()中将相机方向设置为纵向


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

and in getCameraResolution(), you need to swap x and y, because camera preview size is something like 480*320, other than 320*480. 并且在getCameraResolution()中,您需要交换x和y,因为相机预览大小类似于320 * 480,而不是480 * 320。


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

Just rotate the preview bytes you get from the camera preview. 只需旋转从摄像机预览中获得的预览字节即可。 Use the function you have written in the 2nd point of your's. 使用您在第二点编写的功能。 There is no need to do point 1, 3, 4 or 5. 无需执行第1、3、4或5点。

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

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