【问题标题】:Camera preview with a transparent image above上面带有透明图像的相机预览
【发布时间】:2011-05-30 22:13:04
【问题描述】:

我想在 Camera SurfaceView\preview 上查看图像。 我怎么做?有什么例子吗?

【问题讨论】:

    标签: android camera preview


    【解决方案1】:

    可以在ZXing 库、Barcode Scanner 应用程序中找到一个很好的示例。

    他们所做的是将FrameLayout 用于SurfaceView 和他们的自定义ViewfinderView,以便SurfaceViewViewfinderView 都覆盖全屏:

    <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>
    

    注意两个视图的layout_heightlayout_width 中的fill_parent 值。

    然后他们在ViewfinderView.onDraw() 方法中绘制自定义内容,就在相机预览显示的内容之上。

    如果您不想绘制任何内容,而只想使用预定义的图像,请使用ImageView 而不是ViewfinderView。您可以考虑调用setAlpha 方法使您的图像透明(如果drawable 本身还不是透明的)。


    这是条码扫描仪的截图:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多