0

我正在为我的应用程序使用 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
            }

对不起,很长的帖子,但我已经在这个问题上待了一段时间,我真的被困住了。

任何帮助表示赞赏!

4

1 回答 1

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
             }

        }

我仍在研究一些问题,但这个问题现在得到了回答。我要继续拍拍自己的后背。:)

于 2013-05-14T10:03:34.140 回答