Android:想要在Camera预览上放置轮廓叠加 [英] Android: Want to put an silhouette overlay on a Camera preview

查看:137
本文介绍了Android:想要在Camera预览上放置轮廓叠加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何在摄像机预览上放置一个轮廓.到目前为止,我已经有了以下示例,该示例仅预览了Camera.

I'd like to know how I can put a silhouette on top of a camera preview. So far i've got the following example working, which just previews the Camera.

http://developer.android.com/reference/android/view/TextureView.html

我正在尝试进行Camera预览,在其中显示一个剪影,以便使用该应用的人可以了解应该在哪里拍摄图片,然后单击一个按钮即可拍摄照片,而无需图片中的轮廓.

I'm trying to have a Camera preview, where I got a silhouette shown so the person using the app gets an idea of where the picture should be taken, and then a button that when clicked, takes the picture, without the silhouette of course in the picture.

这怎么办?我似乎找不到任何有关如何在纹理视图上放置覆盖的示例.

How can this be done? I can't seem to find any examples of how to put an overlay on top of a texture view.

推荐答案

使用 TextureView文档,我们只需创建一个布局XML文件即可将我们的TextureViewImageView覆盖在FrameLayout中.然后,我们使用此布局的资源ID调用ActivitysetContentView()方法,而不是示例中动态创建的TextureView.

Using the example in the TextureView docs you've linked, we simply create a layout XML file to hold our TextureView and overlay ImageView in a FrameLayout. We then call the Activity's setContentView() method with this layout's Resource ID, instead of the dynamically-created TextureView in the example.

布局文件main.xml:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextureView android:id="@+id/texture_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <ImageView android:id="@+id/image_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#00000000"
        android:src="@drawable/ic_launcher" />

</FrameLayout>

和示例Activity:

public class LiveCameraActivity extends Activity
    implements TextureView.SurfaceTextureListener {

    private Camera mCamera;
    private TextureView mTextureView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        mTextureView = (TextureView) findViewById(R.id.texture_view);
        mTextureView.setSurfaceTextureListener(this);
    }

    // The TextureView.SurfaceTextureListener methods
    // are the same as shown in the example.

    ...
}

布局中的叠加层ImageView使用默认的启动器图标作为其源图像,因为它具有透明性,至少在我的IDE中如此.稍后您将用您的轮廓替换此图像.在TextureView之后列出的ImageView将出现在它的顶部,因为View相对于它们的z顺序是按照其在布局中列出的顺序绘制的,第一个View列在底部;即在z轴上距离您最远的地方.

The overlay ImageView in the layout uses the default launcher icon as its source image, as it has transparency, at least on my IDE. You would later replace this image with your silhouette. The ImageView, being listed after the TextureView, will appear on top of it, because Views are drawn with respect to their z-order in the same order they're listed in the layout, with the first View listed being on the bottom; i.e., the farthest away from you on the z-axis.

Activity中,我们只是将布局作为内容View加载,并获得对在那里创建的TextureView的引用.其他一切都一样.

In the Activity, we're just loading the layout as the content View, and getting a reference to the TextureView created there. Everything else is the same.

这篇关于Android:想要在Camera预览上放置轮廓叠加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆