Take and save the image when you click

I am creating an Android application that uses user-captured images as part of a larger process. So far, my XML layout has a SurfaceView and Button inside a RelativeLayout. I managed to get a camera preview on SurfaceView, but I was stuck on how to take a picture and save it when the user clicks a button.

My class file looks something like a demo of the CameraPreview API: http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/CameraPreview.html

Ideally, when the button is pressed, the camera should autofocus, click on the picture (with a delicate sound), save it to /data/data/app_package_structure/files/file_name.jpg , and then open the toast to tell the user that their image has been saved.

Any help is much appreciated :)

+10
android camera
Apr 26 '10 at 11:52
source share
2 answers

I think CommonsWare has already answered most of this question, but it might work for auto focus and shutter sound. This is an assumption since I am not on a machine where I can compile / test it all.

In your push-button control code, I believe you should call (possibly by sending messages)

 camera.autoFocus(new Camera.AutoFocusCallback() { Camera.ShutterCallback shutterCallback = new Camera.ShutterCallback() { public void onShutter() { // Play your sound here. } }; public void onAutoFocus(boolean success, Camera camera) { camera.takePicture(shutterCallback, null, photoCallback); } }); 

where camera is your camera object, and photoCallback matches the CommonsWare example.

What exactly are you stuck with?

Oh, and don't forget to add the <uses-feature> android.hardware.camera.autofocus . :)

+12
May 04 '10 at 18:00
source share

Here is an example application that handles the Take-a-picture-and-save-it part. Autofocusing, clicking, Toast and saving to a local file file storage and SD card remain as exercises for the student. :-)

+9
Apr 26 '10 at 12:53 on
source share



All Articles