Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Preview picture after capture, before save

Tags:

android

I got a full camera app up and running, but I'd like to have the captured picture show on the screen before saving them (they're not going to the gallery). I've googled extensively and I can't find anything on the topic. I also have no idea how to start, so any advice or links to relevant information I didn't find would be wonderful. Thanks!

like image 998
SirNick92 Avatar asked Feb 15 '15 02:02

SirNick92


People also ask

How do you open camera through intent and display captured image?

This is done as follows: Intent camera_intent = new Intent(MediaStore. ACTION_IMAGE_CAPTURE); startActivityForResult(camera_intent, pic_id); Now use the onActivityResult() method to get the result, here is the captured image.

Which method of the camera class display the preview of the image captured?

SurfaceView. This class is used to present a live camera preview to the user. MediaRecorder.

How do you get an image from a camera or a gallery and save it in Android?

Run the application on an Android phone. Selecting "Take photo" will open your camera. Finally, the image clicked will be displayed in the ImageView. Selecting "Choose from Gallery" will open your gallery (note that the image captured earlier has been added to the phone gallery).


1 Answers

First of all, I'm assuming you are using the original Camera APIs, not Camera2. That functionality is really built into the preview capturing, so I'm assuming your code is just clearing the preview too quickly.

After calling Camera.startPreview() to render the live preview on the active surface, at some point Camera.takePicture() is called to trigger the image capture and the result is returned to the PictureCallback. As soon as the image is captured, the camera preview surface is frozen on that frame until it is restarted. So as long as you don't call Camera.startPreview() again inside of onPictureTaken() to restart that process, the SurfaceView will remain frozen on the frame you want the user to see already.

Then if they want to save, you can write the JPEG data to disk, and if not toss away the data.

like image 52
devunwired Avatar answered Sep 25 '22 14:09

devunwired