您正在使用相机应用程序,这对您的目的不利。因为您不能在相机应用程序上叠加任何对象。您只能从中获取图像。因此,您必须创建内置相机应用程序并将其用于您的目的。我举了一个使用内置摄像头的例子。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<SurfaceView android:id="@+id/CameraView" android:layout_width="fill_parent"
android:layout_height="fill_parent"></SurfaceView>
</LinearLayout>
现在创建像这样实现 SurfaceHolder.Callback 的活动
import android.app.Activity;
import android.os.Bundle;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
public class SnapShot extends Activity implements SurfaceHolder.Callback {
SurfaceView cameraView;
SurfaceHolder surfaceHolder;
Camera camera;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
cameraView = (SurfaceView) this.findViewById(R.id.CameraView);
surfaceHolder = cameraView.getHolder();
surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
surfaceHolder.addCallback(this);
}
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
}
public void surfaceCreated(SurfaceHolder holder) {
camera = Camera.open();
try
{
camera.setPreviewDisplay(holder);
}
catch (IOException exception)
{
camera.release();
}
camera.startPreview();
}
public void surfaceDestroyed(SurfaceHolder holder) {
}
}