I am trying to display the camera preview with an image overlay and have a button at the bottom to take the picture. I pretty much copied the API from CameraPreview and added an addcontentview which seems to work pretty well for adding an xml file which acts as my overlay. (Except that it has to be in landscape mode so I need to figure out how to either rotate all my stuff through code or, easier for me, just make sideways images :-P)
My problem is that I just can't figure out how to get my button to work correctly.
All I want to do is use the image as the background for my next activity. Anyway, this is what I've got.
public class CameraPreview extends Activity {
private Preview mPreview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
mPreview = new Preview(this);
setContentView(mPreview);
LayoutInflater inflater = getLayoutInflater();
getWindow().addContentView(inflater.inflate(R.layout.overlay, null), new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.FILL_PARENT));
}
}
// ----------------------------------------------------------------------
class Preview extends SurfaceView implements SurfaceHolder.Callback {
SurfaceHolder mHolder;
Camera mCamera;
Preview(Context context) {
super(context);
mHolder = getHolder();
mHolder.addCallback(this);
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
public void surfaceCreated(SurfaceHolder holder) {
mCamera = Camera.open();
try {
mCamera.setPreviewDisplay(holder);
} catch (IOException exception) {
mCamera.release();
mCamera = null;
}
}
public void surfaceDestroyed(SurfaceHolder holder) {
mCamera.stopPreview();
mCamera.release();
mCamera = null;
}
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
Camera.Parameters parameters = mCamera.getParameters();
parameters.setPreviewSize(w, h);
mCamera.setParameters(parameters);
mCamera.startPreview();
}
}
I just can't figure out where to put in my button, what to type or anything. I'm assuming its something like camera.takepicture but I can't get it to work.
Oh yea, I've spent about half the day on this one area so if you could super simplify it for me, my fried mind would appreciate it. :)