【问题标题】:How to decorate the camer preview during barcode scanning?扫码时如何修饰摄像头预览?
【发布时间】:2019-11-13 13:28:31
【问题描述】:

我想创建一个条码扫描器活动,我发现了这个不错的教程: http://www.devexchanges.info/2016/10/reading-barcodeqr-code-using-mobile.html

如何用检测到的区域(点或矩形)装饰预览图像。

【问题讨论】:

    标签: android barcode-scanner android-vision


    【解决方案1】:

    在您的SurfaceView 上放置另一个透明视图并在其上进行绘制。两种视图都将松散耦合,因此需要一些数学运算才能正确匹配装饰与相机输出。

    所以在你的activity_main.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="16dp">
    
        <SurfaceView
            android:id="@+id/surface_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true" />
    
        <com.yourApp.YourDecoratorView
            android:id="@+id/decorator_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true" />
        ...
    </RelativeLayout> 
    

    然后,创建一个自定义视图:

    class YourDecoratorView @JvmOverloads constructor(
        context: Context,
        attrs: AttributeSet? = null,
        defStyleAttr: Int = 0
    ) : View(context, attrs, defStyleAttr) {
    
        ... initializing code
    
        override fun onDraw(canvas: Canvas?) {
            super.onDraw(canvas)
    
            // your code
            canvas?.drawLine(0f, 0f, 0f, paint)
        }
    }
    

    如果您只想显示静态视觉效果,请使用ImageView 而不是自定义视图并创建您想要的drawable。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-06-17
      • 1970-01-01
      • 2015-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多