gpt4 book ai didi

android - ZXings barcodescanner添加Menu,并挤压surfaceview

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:48:26 25 4
gpt4 key购买 nike

Zxings barscanner 应用程序,我已经将它实现为一个库项目,并且可以正常工作。

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

但后来我需要在左侧插入一个菜单。这迫使我更改目标字段,这就是它开始崩溃的原因,如果我更改 surfaceview 或 viewFinderView 的大小,并且如果我将它包装在相对 View 中,它仍然只解码中心(原因)。我就是想不出解决办法:-/

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

谁能帮帮我?

布局 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**

左图: View 现在的样子,项目放置在未被识别的地方。

右图:Item放置在被识别的地方(我如何检查目标区域没有改变):

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 (问题已解决,缺少一个库)10 月 18 日 10:14 CET

最佳答案

如果您同时挤压表面 View 和取景器 View ,它实际上会起作用。

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

关于android - ZXings barcodescanner添加Menu,并挤压surfaceview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12859066/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com