【问题标题】:Crop overlay to mark the scan field裁剪覆盖以标记扫描字段
【发布时间】:2019-09-21 23:36:10
【问题描述】:

我在我们的 Xamarin 应用程序中实现了条码扫描器。为了实现扫描仪,我遵循了本教程:https://www.c-sharpcorner.com/article/xamarin-android-qr-code-reader-by-mobile-camera/

所以,我有一个 SurfaceView、一个 CameraSource 和一个 BarcodeDetector。现在我想裁剪相机预览以说明我们必须扫描的条形码所在的扫描仪,因为我们可能拥有多个条形码的来源。

我认为这将适用于简单裁剪视图(或类似的东西),但我不知道如何实现它。 在这里找到的所有解决方案都不起作用,或者我遗漏了一些东西。

【问题讨论】:

    标签: c# xamarin.android surfaceview crop barcode-scanner


    【解决方案1】:

    你想像这个 GIF 一样实现它吗?

    如果是这样,您可以通过ZXing.Net.Mobile 实现它 https://github.com/Redth/ZXing.Net.Mobile

    这是我的演示 https://github.com/851265601/Scanebarcode

    更新:如果您仍想使用自爆链接之类的解决方案

    https://www.c-sharpcorner.com/article/xamarin-android-qr-code-reader-by-mobile-camera/

    我像下面的代码一样更改了布局。我使用了FramLayoutSurfaceView 被其他布局覆盖,就像LinearLayoutrelativelayout 一样

    <FrameLayout 
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
    >
    <SurfaceView
                android:id="@+id/cameraView"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_centerInParent="true" />
    <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    >
    <RelativeLayout
        android:background="#953399ff"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="330dp"
        android:orientation="horizontal">
        <RelativeLayout
            android:background="#953399ff"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1" />
        <RelativeLayout
            android:id="@+id/rlscan"
            android:layout_width="220dp"
            android:layout_height="fill_parent">
    
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_alignParentTop="true"
                android:src="@drawable/area_above_left" />
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_alignParentTop="true"
                android:src="@drawable/area_above_right" />
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_alignParentLeft="true"
                android:src="@drawable/area_below_left" />
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_alignParentRight="true"
                android:src="@drawable/area_below_right" />
        </RelativeLayout>
        <RelativeLayout
            android:background="#953399ff"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1" />
    </LinearLayout>
    <RelativeLayout
        android:background="#953399ff"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1">
        <TextView
            android:layout_centerInParent="true"
            android:gravity="center_horizontal"
            android:id="@+id/txtResult"
            android:layout_below="@+id/cameraView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Please focus Camera to QR Code"
            android:textSize="10sp"
            android:layout_marginTop="20dp" />
      </RelativeLayout>
      </LinearLayout>
    </FrameLayout>
    

    【讨论】:

    • 没错。这就是我要的。但问题是,我们不想使用 Zxing.Net.Mobile,因为扫描结果不是很好。
    • @r3d007,如果你还想用Google Play Services - Vision ,我根据你的需要写一个新的布局(我更新了我的答案,你可以参考一下),这个布局可以达到效果,我的手机VPN已过期,无法连接google,无法为您测试。
    猜你喜欢
    • 2013-09-13
    • 2013-07-19
    • 2014-10-12
    • 2019-12-20
    • 2022-11-08
    • 2023-03-24
    • 1970-01-01
    • 2016-03-16
    • 1970-01-01
    相关资源
    最近更新 更多