2013-05-13 104 views
0

我正在使用我的应用程序用于条形码扫描的RedLaser库(我相信这是建立在Zxing上的)。一切工作正常,而在扫描模式下,任何扫描视图内的条形码都会被扫描,但我不希望这样,我只需要考虑在扫描区域对齐的条形码,其余部分将被忽略。扫描时的条形码位置

redlaser示例应用程序,之后我在自己的应用程序中实现了该库,在扫描活动的布局上有一个矩形,但忽略了这一点,因为来自屏幕任何部分的条形码都被扫描并考虑在内由示例应用程序。

底线:我希望我的扫描活动能够比较当前检测到的条形码的位置,看它是否在“扫描区域”的范围内,如果不在则不会被读取。

barcode scanning

下面是“扫描区域”的调整代码:

 viewfinderView = findViewById(R.id.view_finder); 
     LayoutParams params = new LayoutParams((int)(mDisplay.getWidth() * .75f), 
       (int)(mDisplay.getHeight() * .33f)); 
     params.gravity = Gravity.CENTER; 
     viewfinderView.setLayoutParams(params); 

下面的代码没有做任何事情,我只是写它来举例说明如何一切正常(因为我没有Redlaser库的源文件),就像条形码位置一样。

  Set<BarcodeResult> allResults = (Set<BarcodeResult>) scanStatus.get(Status.STATUS_FOUND_BARCODES); 
      for(BarcodeResult s : allResults) 
      { 
       ArrayList<PointF> barcodelocation = s.barcodeLocation; 
       float x = barcodelocation.get(0).x; 
       float y = barcodelocation.get(0).y; 
//there will be 4 points to each scanned barcode => 8 float's/barcode 
      } 

很抱歉的长期职位,但我一直在这个问题上,而现在,我真的卡住。

任何帮助表示赞赏!

回答

0

设法找到对的RedLaser网站的解决方案:在打开视图成一个矩形,然后与使用.contain比较条码位置:

Rect scanningArea = new Rect(viewfinderView.getLeft(), viewfinderView.getTop(), viewfinderView.getRight(), viewfinderView.getBottom()); 
if(latestResult.iterator().hasNext()) 
     { 

      boolean isInside = true; 
      ArrayList<PointF> barcodelocation = latestResult.iterator().next().barcodeLocation; 
      for (int i = 0; i < barcodelocation.size(); i++) 
      { 
       int x = (int) barcodelocation.get(i).x; 
       int y = (int) barcodelocation.get(i).y; 
       if (!scanningArea.contains(x, y)) 
       { 
        isInside = false; 
       } 
      } 
      if (isInside) 
      { 
      //do stuff here 
      } 

     } 

我还在上几个问题的工作,但这个问题现在回答。要继续前进,让自己在背后轻拍一下。 :)