Android ZXing二维码识别优化方法

zxing源码中找到
com.google.zxing.client.android.ViewfinderView

修改识别框代码如下:
        //添加一个增量优化识别效率
        int delta = (int) (frame.width() * 0.15);

        // Draw the exterior (i.e. outside the framing rect) darkened
        paint.setColor(resultBitmap != null ? resultColor : maskColor);
        canvas.drawRect(0, 0, width, frame.top + delta, paint);
        canvas.drawRect(0, frame.top + delta, frame.left + delta, frame.bottom - delta + 1, paint);
        canvas.drawRect(frame.right - delta + 1, frame.top + delta, width, frame.bottom - delta + 1, paint);
        canvas.drawRect(0, frame.bottom - delta + 1, width, height, paint);
原理:其实是将用户所看到的识别框缩小(小于zxing实际识别框大小,亲测可有效提高识别效率)

你可能感兴趣的:(Android)