0

私はzxingコアを使用しており、写真を撮るAndroidアプリと統合しています。RGBLuminanceSource にビットマップ画像を入力しています。しかし、毎回 NOTFoundException が発生します。インテントまたは CaptureActivity を介して zxing バーコード スキャナーと統合したくありません。これがコードです。

       Map<DecodeHintType,Object> HINTS;
       Map<DecodeHintType,Object> HINTS_PURE;
       HINTS = new EnumMap<DecodeHintType,Object>(DecodeHintType.class);
       HINTS.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
       HINTS.put(DecodeHintType.POSSIBLE_FORMATS, EnumSet.allOf(BarcodeFormat.class));
       HINTS_PURE = new EnumMap<DecodeHintType,Object>(HINTS);
       HINTS_PURE.put(DecodeHintType.PURE_BARCODE, Boolean.TRUE);
       ImageView mImg;

       if (requestCode == SCANNER_REQUEST_CODE && resultCode == RESULT_OK) {  
          // Bitmap bMap = (Bitmap) data.getExtras().get("data");

        Bitmap bMap=BitmapFactory.decodeStream(getContentResolver().openInputStream(outputFileUri));


            // creating binary bitmap from source image


           int length=bMap.getWidth()*bMap.getHeight()*10;
           int[] intArray = new int[bMap.getWidth()*bMap.getHeight()]; 
           bMap.getPixels(intArray, 0, bMap.getWidth(), 0, 0, bMap.getWidth(),                bMap.getHeight());

           //test view to display captured image 
           mImg = (ImageView) findViewById(R.id.imageView);
           mImg.setImageBitmap(bMap);


           // zxing decoding of bitmap image
           Reader reader = new MultiFormatReader();
           String msg=bMap.getWidth()+" * "+bMap.getHeight();
           Log.e("DEBUGGG", msg);
           LuminanceSource source = new RGBLuminanceSource(bMap.getWidth(), bMap.getHeight(),intArray);


           BinaryBitmap bitmap = new BinaryBitmap(new GlobalHistogramBinarizer(source));


           Collection<Result> results = new ArrayList<Result>(1);
           ReaderException savedException = null;



           try {
                  // Look for multiple barcodes
                  MultipleBarcodeReader multiReader = new GenericMultipleBarcodeReader(reader);

                  Result[] theResults = multiReader.decodeMultiple(bitmap, HINTS);
                  if (theResults != null) {
                    results.addAll(Arrays.asList(theResults));
                  }
                } catch (ReaderException re) {
                    re.printStackTrace();
                  savedException = re;
                  re.printStackTrace();
                }


                if (results.isEmpty()) {
                    try {
                      // Look for pure barcode
                      Result theResult = reader.decode(bitmap, HINTS_PURE);
                      if (theResult != null) {
                        results.add(theResult);
                      }
                    } catch (ReaderException re) {
                      savedException = re;
                      re.printStackTrace();

                    }
                  }

                  if (results.isEmpty()) {
                    try {
                      // Look for normal barcode in photo
                      Result theResult = reader.decode(bitmap, HINTS);
                      if (theResult != null) {
                        results.add(theResult);
                      }
                    } catch (ReaderException re) {
                      savedException = re;
                      re.printStackTrace();
                    }
                  }

                  if (results.isEmpty()) {
                    try {
                      // Try again with other binarizer
                      BinaryBitmap hybridBitmap = new BinaryBitmap(new HybridBinarizer(source));
                      Result theResult = reader.decode(hybridBitmap, HINTS);
                      if (theResult != null) {
                        results.add(theResult);
                      }
                    } catch (ReaderException re) {
                      savedException = re;
                      re.printStackTrace();
                    }
                  }
                String barcoderesult="";
                  for (Result result : results) {
                      barcoderesult=barcoderesult+result.getText();
                      Log.e("Debugger","code:  " +result.getText() );
                    }

                //result is empty and notfound exception in logs
4

2 に答える 2

0

はい、一般的には問題なくデコードされます。最も可能性の高い答えは、この特定の画像がスキャンされないということです。影のないものを試してみてください。画像を正しく解析していない可能性もあります。他の画像を試して確認する

于 2013-04-03T09:52:05.730 に答える
0

bitmap.config を使用して入力ストリームから RGB でビットマップを作成する必要がありました。

于 2013-04-03T13:55:22.763 に答える