将菜单添加到ZXings条形码扫描器,并挤压表面视图

时间:2012-10-12 12:27:20

标签: android zxing

Zxings barscanner app,我已经实现了它,作为一个图书馆项目,它的工作原理。

现在我要更改扫描的字段(目标字段)的大小(也完成)。 (虽然扫描区域保持不变,但这并不重要,因为焦点仍处于中心位置。)

但后来我需要在左侧插入一个菜单。这迫使我改变目标字段,这是它开始崩溃,如果我改变了surfaceview或viewFinderView的大小,如果我将它包装在相对视图中,它仍然只解码中心(原因)。我只是无法找到解决方案: - /

:我可以更改扫描应该发生的区域,但这只是可见的。实际扫描区域仍然是整个屏幕的中心,而不是移动的可见扫描区域的中心。

任何人都可以帮助我吗?

布局XML(插入菜单,不必要删除):

<SurfaceView
    android:id="@+id/preview_view"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />

<com.google.zxing.client.android.ViewfinderView
    android:layout_marginLeft="120dip"
    android:id="@+id/viewfinder_view"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/transparent" />

<LinearLayout
    android:id="@+id/buttonPanel"
    android:layout_width="120dip"
    android:layout_height="fill_parent"
    android:background="#000"
    android:orientation="vertical"
    android:paddingBottom="15dip"
    android:paddingTop="15dip" >

    <TextView 
        android:id="@+id/menuText"
        android:layout_weight="1"
        android:layout_width="90dip"
        android:layout_height="wrap_content"
        android:layout_marginLeft="15dip"
        android:text="@string/menu_title"/>
    <ImageView
        android:id="@+id/d1Button"
        android:layout_width="90dip"
        android:layout_height="wrap_content"
        android:layout_marginLeft="15dip"
        android:layout_weight="2"
        android:onClick="scanner1d"
        android:src="@drawable/d1image" />

    <ImageView
        android:id="@+id/d2Button"
        android:layout_width="90dip"
        android:layout_height="wrap_content"
        android:layout_marginLeft="15dip"
        android:layout_weight="2"
        android:onClick="scanner2d"
        android:src="@drawable/d2image" />
</LinearLayout>

<LinearLayout
    android:id="@+id/result_view"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/result_view"
    android:orientation="vertical"
    android:padding="4dip"
    android:visibility="gone" >

       **removed**
</LinearLayout>
   **removed**

左图:视图现在如何,项目放置在无法识别的位置。

右图:项目位于识别位置(如何检查目标区域未更改):

Image of view result found

对CameraManager的更改(挤压取景器):

public Rect getFramingRect() {
    // added
    int menuSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 
                    (float) 120, context.getResources().getDisplayMetrics());
    // end of added

    Point screenResolution = configManager.getScreenResolution();
    if (framingRect == null) {
        if (camera == null) {
            return null;
        }
        int width = screenResolution.x * 3 / 4;
        if (width < MIN_FRAME_WIDTH) {
            width = MIN_FRAME_WIDTH;
        } else if (width > MAX_FRAME_WIDTH) {
            width = MAX_FRAME_WIDTH;
        }
        int height = screenResolution.y * 3 / 4;
        if (height < MIN_FRAME_HEIGHT) {
            height = MIN_FRAME_HEIGHT;
        } else if (height > MAX_FRAME_HEIGHT) {
            height = MAX_FRAME_HEIGHT;
        }


        // added menu size for calculation

        int leftOffset = ((screenResolution.x -menuSize - width) / 2);
        int topOffset = (screenResolution.y - height) / 2;
        framingRect = new Rect(leftOffset, topOffset, leftOffset + width,
                topOffset + height);
        Log.d(TAG, "Calculated framing rect: " + framingRect);
    }
    return framingRect;
}

现在我把它全部带到了一个可以找到的小项目中 here(问题已修复,遗失了一篇文章)oct 18 10:14 CET

1 个答案:

答案 0 :(得分:1)

如果将surfaceview与viewfinderview一起挤压,它实际上会起作用。

虽然您必须考虑到图像被挤压,但目标矩形必须小得多。