问题描述
我想在Camera SurfaceView \preview顶部看到一个图像。
我如何做到这一点?任何示例?
I would like to see an image on top of Camera SurfaceView\preview.How do I do that? Any examples?
推荐答案
一个很好的示例可以在 library,应用程序。
A great example can be found in ZXing library, Barcode Scanner application.
他们使用 FrameLayout
$ c> 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>
请注意<$ c中的 fill_parent
$ c> layout_height 和 layout_width
。
Note the fill_parent
values in layout_height
and layout_width
for both views.
方法,只是在相机预览显示的顶部。
And then they draw custom things in ViewfinderView.onDraw()
method, just on top of what is being displayed by camera preview.
如果你不想绘制任何东西,而是使用预定义的图像,那么使用 ImageView
code> ViewfinderView 。您可以考虑调用 setAlpha
方法使图像透明(如果drawable本身不是透明的)。
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).
以下是条码扫描器的屏幕截图:
Here is a screenshot from Barcode Scanner:
img src =https://i.stack.imgur.com/CQ9Dq.pngalt =输入图片说明here>>
这篇关于相机预览与上面的透明图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!