解码从手机图库中挑选的图像上的多个条形码

时间:2014-01-04 13:51:53

标签: android

我正在尝试解码从图库中挑选的图像上找到的多个条形码, 但它没有返回有关条形码的任何数据。这是我的代码片段.... 以下代码从库中选择图像并尝试解码它们。 请建议我能够成功完成我的要求的最佳方式。

public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
    if (requestCode == SELECT_PICTURE) {
        Uri selectedImageUri = data.getData();
        selectedImagePath = getPath(selectedImageUri);
        Bitmap bMap = BitmapFactory.decodeFile(selectedImagePath);
        LuminanceSource source = new RGBLuminanceSource(bMap);
        BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
        Reader reader = new MultiFormatReader();
        try {
             Result result = reader.decode(bitmap);
             Global.text = result.getText(); 
                byte[] rawBytes = result.getRawBytes(); 
                BarcodeFormat format = result.getBarcodeFormat(); 
                ResultPoint[] points = result.getResultPoints();
                tv1.setText(Global.text);
                tv2.setText("FORMAT: " + format);

        } catch (NotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ChecksumException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (FormatException e) {
            // TODO Auto-generated catch block
    e.printStackTrace();


        }   


    }
}

0 个答案:

没有答案