簡體   English   中英

掃描時的條形碼位置

[英]Barcode location while scanning

我正在為我的應用程序使用RedLaser庫進行條形碼掃描(我相信它是基於Zxing構建的)。 一切正常,在掃描模式下,將掃描視圖中的所有條形碼,但我不希望這樣做,我只希望考慮在掃描區域中對齊的條形碼,而忽略其余區域。

redlaser示例應用程序之后,我在自己的應用程序中實現了該庫,在掃描活動的布局上有一個矩形,但是由於示例應用程序掃描並考慮了來自屏幕任何部分的條形碼,因此忽略了該矩形。

底線:我希望我的掃描活動比較當前檢測到的條形碼的位置,看看它是否在“掃描區域”的范圍內,如果不是,則不會被讀取。

條碼掃描

這是用於調整“掃描區域”的代碼:

     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
            }

抱歉,很長的帖子,但是我在這個問題上已經有一段時間了,我真的很困。

任何幫助表示贊賞!

設法在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
             }

        }

我仍在處理一些問題,但是現在已經回答了這個問題。 繼續前進,拍拍自己的后背。 :)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM