zbar和阅读二维条码并不起作用

时间:2015-03-16 19:30:05

标签: android zbar-sdk zbar

我使用以下参数调整扫描仪

        scanner.setConfig(0, Config.X_DENSITY, 400);
    scanner.setConfig(0, Config.Y_DENSITY, 400);


    scanner.setConfig(Symbol.CODABAR , Config.ENABLE , 1) ;
    scanner.setConfig(Symbol.EAN8 , Config.ENABLE , 1) ;
    scanner.setConfig(Symbol.PARTIAL , Config.ENABLE , 1) ;
    scanner.setConfig(Symbol.UPCE , Config.ENABLE , 1) ;
    scanner.setConfig(Symbol.ISBN10 , Config.ENABLE , 1) ;
    scanner.setConfig(Symbol.UPCA , Config.ENABLE , 1) ;
    scanner.setConfig(Symbol.EAN13 , Config.ENABLE , 1) ;
    scanner.setConfig(Symbol.ISBN13 , Config.ENABLE , 1) ;
    Scanner. setConfig (Symbol.I25, Config. ENABLE, 1);
    scanner.setConfig(Symbol.DATABAR , Config.ENABLE , 1) ;
    scanner.setConfig(Symbol.CODE39 , Config.ENABLE , 1) ;
    scanner.setConfig(Symbol.PDF417 , Config.ENABLE , 1) ;
    scanner.setConfig(Symbol.QRCODE , Config.ENABLE , 1) ;
    scanner.setConfig(Symbol.CODE93 , Config.ENABLE , 1) ;
    scanner.setConfig(Symbol.CODE128 , Config.ENABLE , 1) ;

并使用

读取数据
 PreviewCallback previewCb = new PreviewCallback() {
    public void onPreviewFrame(byte[] data, Camera camera) {
        Camera.Parameters parameters = camera.getParameters();
        Size size = parameters.getPreviewSize();

        Image barcode = new Image(size.width, size.height, "Y800");
        barcode.setData(data);


        int result = scanner.scanImage(barcode);
        String Output = "";
        if (result != 0) {
            previewing = false;
            mCamera.setPreviewCallback(null);
            mCamera.stopPreview();

            SymbolSet syms = scanner.getResults();

            for (Symbol sym : syms) {
                Output = Output + sym.getData();
                barcodeScanned = true;
            }
            AlertDialog.Builder builder = new AlertDialog.Builder(context);
            builder.setMessage(Output)
                    .setCancelable(false)
                    .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            ReumePreview();
                        }
                    });
            AlertDialog alert = builder.create();
            alert.show();


        }

    }
};

但我无法阅读我使用以下样本测试的二维条形码

http://www.datalogic.com/upload/marketlit/demo/R44-2686A.pdf

任何想法如何让它发挥作用

1 个答案:

答案 0 :(得分:0)

将中断放入for循环

 PreviewCallback previewCb = new PreviewCallback() {
public void onPreviewFrame(byte[] data, Camera camera) {
    Camera.Parameters parameters = camera.getParameters();
    Size size = parameters.getPreviewSize();

    Image barcode = new Image(size.width, size.height, "Y800");
    barcode.setData(data);


    int result = scanner.scanImage(barcode);
    String Output = "";
    if (result != 0) {
        previewing = false;
        mCamera.setPreviewCallback(null);
        mCamera.stopPreview();

        SymbolSet syms = scanner.getResults();

        for (Symbol sym : syms) {
            Output = Output + sym.getData();
            barcodeScanned = true;
            break;
        }
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setMessage(Output)
                .setCancelable(false)
                .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        ReumePreview();
                    }
                });
        AlertDialog alert = builder.create();
        alert.show();


    }

}

};