【问题标题】:Barcode location while scanning扫描时的条形码位置
【发布时间】:2013-05-13 08:33:25
【问题描述】:

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

很抱歉,这篇文章很长,但我在这个问题上已经有一段时间了,我真的被卡住了。

感谢任何帮助!

【问题讨论】:

    标签: java android graphics barcode-scanner screen-capture


    【解决方案1】:

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

    我仍在处理一些问题,但这个问题现在已经得到解答。我要继续拍拍自己的后背。 :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-16
      • 1970-01-01
      • 1970-01-01
      • 2016-10-29
      • 2012-08-08
      • 1970-01-01
      • 1970-01-01
      • 2014-07-19
      相关资源
      最近更新 更多