2013-05-13 53 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 
      } 

     } 

我還在上幾個問題的工作,但這個問題現在回答。要繼續前進,讓自己在背後輕拍一下。 :)