相机预览,上方有透明图像

问题描述

| 我想在Camera SurfaceView \\ preview顶部看到图像。 我怎么做?有什么例子吗?     

解决方法

        在ZXing库的Barcode Scanner应用程序中可以找到一个很好的例子。 他们所做的是将ѭ0用作
SurfaceView
,并将其自定义
ViewfinderView
用作
SurfaceView
ViewfinderView
覆盖全屏:
<FrameLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"
             android:layout_width=\"fill_parent\"
             android:layout_height=\"fill_parent\">

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

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

</FrameLayout>
注意两个视图的views7ѭ和
layout_width
中的
fill_parent
值。 然后,它们以
ViewfinderView.onDraw()
方法绘制自定义内容,位于相机预览显示的内容之上。 如果您不想绘制任何东西,而只是使用预定义的图像,则使用
ImageView
代替
ViewfinderView
。您可以考虑调用
setAlpha
方法来使图像透明(如果drawable本身还不透明)。 这是条形码扫描仪的屏幕截图: