如何在相机应用程序中添加矩形叠加层? [英] How to add a rectangular overlay in a camera application?

查看:67
本文介绍了如何在相机应用程序中添加矩形叠加层?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在相机预览中添加矩形叠加层(应该更像是矩形框)?我的应用程序包含一个按钮,单击该按钮即可打开相机. 我需要在该相机预览中使用叠加层.

How do I add a rectangular overlay (which should be more like a rectangular frame) in the camera preview? My application consists of a button that opens the camera upon clicking. I need the overlay in that camera preview.

java文件的代码为:

The code for the java file is:

    public class MainActivity extends Activity {
     Button b;
     Intent i;
     Bitmap bmp;
     final static int cameraData = 0;

     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);
         b = (Button) findViewById(R.id.button);
         InputStream is = getResources().openRawResource(R.drawable.ic_launcher);
         bmp = BitmapFactory.decodeStream(is);
         b.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
            // TODO Auto-generated method stub
            i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            startActivityForResult(i, cameraData);

        }
    });
 }
}

布局文件如下:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" >

<TextView
    android:id="@+id/text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_gravity="center"
    android:text="click to take photo" />

<Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="click"
    android:layout_gravity="center" />

</LinearLayout>

推荐答案

您必须通过扩展SurfaceView类来创建自己的预览.

You have to create your own Preview by extending the SurfaceView class.

请参阅下面的链接,对您有帮助.

See below link which helps you.

自定义相机android

将带有SurfaceView的FrameLayout用作子项,并根据需要进行自定义

Take FrameLayout with SurfaceView as child.and customise as per your needs

这篇关于如何在相机应用程序中添加矩形叠加层?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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