ZXing使用IntentIntegrator启动BarcodeScanner纵向布局

时间:2012-04-04 15:45:20

标签: android google-play zxing

我想在纵向布局中启动BarcodeScanner(因为我的整个应用程序是纵向布局)。 我也想知道,是否有可能从Google Play一次安装两个应用程序(您在清单文件中添加某种依赖关系到Barcode Scanner - 我在我的应用程序中使用它 - 以及Google Play自动安装条形码扫描器和我的应用程序一起)

感谢。

3 个答案:

答案 0 :(得分:2)

如果您需要在Portrait中进行条形码扫描,我建议您将ZXing库合并到您的应用程序中并进行适当的更改,以使其在纵向模式下工作。

在此处抓取源代码:zxing

您正在寻找库中的Android示例代码以及core.jar文件,以便进行条形码扫描。

有关如何使其在Portrait中工作的说明,请按照以下步骤操作:Issue 178 - zxing - Running ZXing in Portrait

我强烈建议阅读该主题以获取有关更改的背景信息,但以下是它的基础知识:

  
      
  1. 为了使画面以纵向方式工作,请为活动设置纵向(例如在清单中),然后配置相机:使用   camera.setDisplayOrientation(90)in   CameraConfigurationManager.setDesiredCameraParameters(相机相机)。   但请注意:

         
        
    • setDisplayOrientation(int)需要Android 2.2
    •   
    • setDisplayOrientation(int)不影响在PreviewCallback.onPreviewFrame中传递的字节数组的顺序。 (请参阅JavaDoc for   其他信息)
    •   
  2.   
  3. 由于预览帧始终处于“横向”状态,因此我们需要旋转它们。我使用了注释#c11提供的顺时针旋转。不要忘记   旋转后交换宽度和高度参数。   DecodeHandler.java,在buildLuminanceSource之前旋转数据   decode(byte [] data,int width,int height)

    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; // Here we are swapping, that's the difference to #11
    width = height;
    height = tmp;
    
  4.   
  5. 我还按照#c11的建议修改了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;
    
  6.   

zxing库很容易适应您的应用程序,使其更加流畅和集成的用户体验。强烈推荐。

答案 1 :(得分:0)

条形码扫描仪不支持纵向布局,因此您无法做到这一点。 (Barcode Scanner+可以,但您不能依赖于正在安装的内容。)没有办法强制另一个应用程序从Market安装,没有。

答案 2 :(得分:0)

您好按照以下步骤解决我试过的Zxing条码扫描仪的肖像问题,它运行正常....

有4个相关文件:

1, manifest.xml, you need to make CaptureActivity portrait.

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;