移动视觉api不会检测条形码

时间:2017-10-27 10:02:40

标签: java android barcode-scanner

我尝试使用移动视觉api来阅读条形码。但它只给出了他们拥有的官方样本QR码的结果。如何阅读1D条形码? 我的代码:

if(checkIsOperational()) {
        Bitmap myBitmap = BitmapFactory.decodeResource(
                getApplicationContext().getResources(),
                R.drawable.barcode);
        Log.d("BarcodeActivity","bitmap: "+myBitmap);
        Frame frame = new Frame.Builder().setBitmap(myBitmap).build();
        SparseArray<Barcode> barcodes = mDetector.detect(frame);
        Log.d("BarcodeActivity","barcodes.size: "+barcodes.size());
        if(barcodes.size()>0) {
            Barcode thisCode = barcodes.valueAt(0);
            resultText.setText(thisCode.rawValue);
        }else {
            Toast.makeText(this,"Not detected",Toast.LENGTH_SHORT).show();
        }
    }



private boolean checkIsOperational() {
    if(!mDetector.isOperational()){
        resultText.setText("Could not set up the detector!");
        return false;
    }
    return true;
}

0 个答案:

没有答案