Android:想要在相机预览上添加轮廓叠加层

Mik*_*sen 3 camera android android-camera

我想知道如何在相机预览上放置一个轮廓.到目前为止,我已经有以下示例工作,它只是预览相机.

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

我正在尝试进行相机预览,我在其中显示了一个轮廓,以便使用应用程序的人知道应该拍摄照片的位置,然后点击一个按钮,拍摄照片,当然没有剪影在图片里.

如何才能做到这一点?我似乎找不到任何关于如何在纹理视图上放置叠加层的示例.

Mik*_* M. 10

使用的例子TextureView文档你联系,我们只需创建一个布局XML文件来保存我们TextureView和叠加ImageViewFrameLayout.然后,我们调用ActivitysetContentView()方法与此布局的资源ID,而不是动态创建TextureView的例子.

布局文件,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>
Run Code Online (Sandbox Code Playgroud)

样本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.

    ...
}
Run Code Online (Sandbox Code Playgroud)

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

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