如何增加zxing的扫描区域大小

时间:2013-12-05 11:09:38

标签: android android-camera android-canvas zxing qr-code

所有人目前正​​在尝试从我的应用程序扫描qr代码,并且我使用了zxing库并且它运行良好而且我的问题出在我的galaxy s4 mobile中,扫描区域非常小enter image description here

请帮帮我

提前致谢

5 个答案:

答案 0 :(得分:8)

我知道这太晚了,但对其他人有所帮助 只需转到相机管理器类并粘贴此代码替换给定方法 它适用于所有类型的屏幕

    public Rect getFramingRect() {
    if (framingRect == null) {
    if (camera == null) {
    return null;
    }
    Point screenResolution = configManager.getScreenResolution();
    int width = screenResolution.x * 3 / 4;

    int height = screenResolution.y * 3 / 4;
    Log.v("Framing rect is : ", "width is "+width+"   and height is "+height);
    int leftOffset = (screenResolution.x - width) / 2;
    int topOffset = (screenResolution.y - height) / 2;
    framingRect = new Rect(leftOffset, topOffset, leftOffset + width, topOffset + height);
    Log.d(TAG, "Calculated framing rect: " + framingRect);
    }
    return framingRect;
   }

答案 1 :(得分:2)

CameraManager类有两个定义为MIN_FRAME_WIDTHMIN_FRAME_HEIGHT的常量。你应该根据需要修改它们,一切都应该有效:

private static final int MIN_FRAME_WIDTH = 240;  // (your desired value here)
private static final int MIN_FRAME_HEIGHT = 240; // (your desired value here)

答案 2 :(得分:2)

public Rect getFramingRect() {
if (framingRect == null) {
  if (camera == null) {
    return null;
  }
  Point screenResolution = configManager.getScreenResolution();
        int screenx = screenResolution.x;
        int screeny = screenResolution.y;
        int width, height, left, top;
        if (screenx > screeny) {
            width = (int) (screenx * 12.5 / 100);
            height = (int) (screeny * 25 / 100);
            left = (int) screenx * 83 / 100;
            top = (int) screeny * 75 / 100;
        } else {
            left = (int) (screenx * 12.5 / 100);
            top = (int) (screeny * 25 / 100);
            width = (int) screenx * 83 / 100;
            height = (int) screeny * 75 / 100;
        }
  framingRect = new Rect(left,top, width, height);

  Log.d(TAG, "Calculated framing rect: " + framingRect);
}
return framingRect;
}

替换CameraManager.java文件中的上述代码 这对我有用,试试这个

答案 3 :(得分:1)

如果你是从另一个Android应用程序调用它,请为此使用意图附加SCAN_WIDTH和SCAN_HEIGHT。

如果您正在使用phonegap-plugin-barcodescanner(3.0.0或更高版本),那么传递相同的意图,如xxxxx.scan(onSuccessFunc,onFailFunc,{SCAN_HEIGHT:111,SCAN_WIDTH:222})将产生相同的意图结果。 111是高度,222是宽度。

答案 4 :(得分:0)

如果您使用的是 ZxingScannerView,您可以覆盖 createViewFinderView() 并通过 viewFinderView 增加或减少框架矩形大小,如下所示:

scannerView = object : ZXingScannerView(requireContext()) {
    override fun createViewFinderView(context: Context?): IViewFinder {
         val viewfinderView = super.createViewFinderView(context)
         viewfinderView.setViewFinderOffset(-90) // increase size of framing rectangle
         return viewfinderView;
       }
    }
yourLayour.addView(scannerView)
scannerView.startCamera()