解码图像上的多个条形码

时间:2014-01-13 06:59:13

标签: 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));
    Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object> ();
        hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
       MultiFormatReader mreader = new MultiFormatReader();
 GenericMultipleBarcodeReader multireader = new GenericMultipleBarcodeReader(mreader);
        try {
             Result[] result = multireader.decodeMultiple(bitmap,hints);

                 for(Result kp : result)
                 {

                     tv2.append(kp.getText());
                     tv2.append("\n");
                 }




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


    }

0 个答案:

没有答案