相机preVIEW上述透明图像图像、上述、透明、相机

2023-09-05 02:54:06 作者:成熟小男人

我想看到的图像在相机SurfaceView \ preVIEW顶部。 我怎么做?任何的例子吗?

I would like to see an image on top of Camera SurfaceView\preview. How do I do that? Any examples?

推荐答案

一个很好的例子中可以找到 ZXing 库,吧code扫描仪的应用程序。

A great example can be found in ZXing library, Barcode Scanner application.

他们所做的就是他们使用的FrameLayout SurfaceView 和他们的自定义 ViewfinderView 这样既 SurfaceView ViewfinderView 被覆盖全屏幕:

What they do is they use FrameLayout for SurfaceView and their custom ViewfinderView so that both SurfaceView and ViewfinderView are covering full screen:

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

请注意,在 FILL_PARENT layout_height layout_width 这两个观点。

Note the fill_parent values in layout_height and layout_width for both views.

然后他们绘制定制的事情ViewfinderView.onDraw()方法,只是对什么是正在显示相机preVIEW之上。

And then they draw custom things in ViewfinderView.onDraw() method, just on top of what is being displayed by camera preview.

如果你不想画任何东西,但只使用predefined图像,然后使用的ImageView ,而不是 ViewfinderView 。你可能会考虑调用 setAlpha 方法,使你的形象透明(如果绘制还不是透明的本身)。

If you don't want to draw anything, but just use predefined image, then use ImageView instead of ViewfinderView. You might consider calling setAlpha method to make your image transparent (if drawable wasn't already transparent by itself).

下面是吧code扫描仪的屏幕截图:

Here is a screenshot from Barcode Scanner: