bertsir / zBarLibary

🔥 zbar扫描快,zxing可以生成和识别本地,So,我就把他们结合在了一起,这样Android二维码(条形码)功能就更便捷了
MIT License
776 stars 160 forks source link

关于部分手机使用zbar在扫描空白处识别出条码的问题 #67

Open longforus opened 5 years ago

longforus commented 5 years ago

我自己的项目直接使用的zbar,部分手机(包括小米max2s,小米8)在扫描空白时,也会不时的识别出条码,试了up主的库后,发现没有这个问题,参照up主的zbar扫描配置,修改后,问题得到了解决,希望能帮到有同样问题的人,感谢up主的优秀分享. 配置代码如下:


    public String decodeBarcode(Bitmap barcodeBmp) throws Exception {
        int width = barcodeBmp.getWidth();
        int height = barcodeBmp.getHeight();
        int[] pixels = new int[width * height];
        barcodeBmp.getPixels(pixels, 0, width, 0, 0, width, height);
        Image barcode = new Image(width, height, "RGB4");
        barcode.setData(pixels);
        ImageScanner reader = new ImageScanner();
        reader.setConfig(Symbol.NONE, Config.ENABLE, 0);
        reader.setConfig(Symbol.CODE128, Config.ENABLE, 1);
        reader.setConfig(Symbol.CODE39, Config.ENABLE, 1);
        reader.setConfig(Symbol.EAN13, Config.ENABLE, 1);
        reader.setConfig(Symbol.EAN8, Config.ENABLE, 1);
        reader.setConfig(Symbol.UPCA, Config.ENABLE, 1);
        reader.setConfig(Symbol.UPCE, Config.ENABLE, 1);
        reader.setConfig(Symbol.UPCE, Config.ENABLE, 1);
        int result = reader.scanImage(barcode.convert("Y800"));
        String qrCodeString = null;
        if (result != 0) {
            SymbolSet syms = reader.getResults();
            for (Symbol sym : syms) {
                qrCodeString = sym.getData();
            }
        }
        return qrCodeString;
    }
bertsir commented 5 years ago

@longforus 在不指定识别类型的情况下,特别是扫描屏幕或者类似网格的图案,会被误识别成某一类条形码或者二维码,所以指定后会有所好转。

XinYiWorld commented 4 years ago

我自己的项目直接使用的zbar,部分手机(包括小米max2s,小米8)在扫描空白时,也会不时的识别出条码,试了up主的库后,发现没有这个问题,参照up主的zbar扫描配置,修改后,问题得到了解决,希望能帮到有同样问题的人,感谢up主的优秀分享. 配置代码如下:

    public String decodeBarcode(Bitmap barcodeBmp) throws Exception {
        int width = barcodeBmp.getWidth();
        int height = barcodeBmp.getHeight();
        int[] pixels = new int[width * height];
        barcodeBmp.getPixels(pixels, 0, width, 0, 0, width, height);
        Image barcode = new Image(width, height, "RGB4");
        barcode.setData(pixels);
        ImageScanner reader = new ImageScanner();
        reader.setConfig(Symbol.NONE, Config.ENABLE, 0);
        reader.setConfig(Symbol.CODE128, Config.ENABLE, 1);
        reader.setConfig(Symbol.CODE39, Config.ENABLE, 1);
        reader.setConfig(Symbol.EAN13, Config.ENABLE, 1);
        reader.setConfig(Symbol.EAN8, Config.ENABLE, 1);
        reader.setConfig(Symbol.UPCA, Config.ENABLE, 1);
        reader.setConfig(Symbol.UPCE, Config.ENABLE, 1);
        reader.setConfig(Symbol.UPCE, Config.ENABLE, 1);
        int result = reader.scanImage(barcode.convert("Y800"));
        String qrCodeString = null;
        if (result != 0) {
            SymbolSet syms = reader.getResults();
            for (Symbol sym : syms) {
                qrCodeString = sym.getData();
            }
        }
        return qrCodeString;
    }

我的代码就是这么写的,选择全部扫描类型,扫描还是会返回一串数字。