I have a SurfaceView
that is being used to draw images, and I would like to overlay them onto a live-feed from the phone\'s camera.
Currently, the
I have had success with the following approach.
First make a layout xml file that looks something like this (note the order of the two views):
OverlayView
is a subclass of SurfaceView
with the drawing and animation thread implementations. The other SurfaceView will be the surface that handles the Camera preview. Inside of onCreate
you should set up your views like this:
mView = (OverlayView)this.findViewById(R.id.overlay);
mView.getHolder().setFormat(PixelFormat.TRANSLUCENT);
mSurfaceView = (SurfaceView)this.findViewById(R.id.surface);
mSurfaceHolder = mSurfaceView.getHolder();
mSurfaceHolder.addCallback(this);
mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
You should add a SurfaceHolder.Callback
implementation to the SurfaceHolder
of mView
that handles the animation thread. An example of implementing this within the subclass and using animation/drawing threads can be found in the old LunarLander example here:
http://developer.android.com/resources/samples/LunarLander/src/com/example/android/lunarlander/LunarView.html
Besides that you set up the camera SurfaceView the same way as this example: http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/CameraPreview.html