gpt4 book ai didi

android - 上面有透明图像的相机预览

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:02:18 24 4
gpt4 key购买 nike

我想在 Camera SurfaceView\preview 上看到一张图片。我怎么做?有例子吗?

最佳答案

可以在 ZXing 中找到一个很好的例子图书馆,Barcode Scanner申请。

他们所做的是为 SurfaceView 和他们的自定义 ViewfinderView 使用 FrameLayout 以便 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>

请注意两个 View 的 layout_heightlayout_width 中的 fill_parent 值。

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

如果您不想绘制任何东西,而只想使用预定义的图像,则使用 ImageView 而不是 ViewfinderView。您可能会考虑调用 setAlpha 方法来使您的图像透明(如果可绘制对象本身还不是透明的)。


这是条形码扫描器的屏幕截图:

enter image description here

关于android - 上面有透明图像的相机预览,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6181165/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com