Android uses camera to realize the problem of staying in the preview interface after taking photos

camera realizes the code of taking photos:

     * Start taking photos
    public void startCapture() {
        if (null != camera) {
            camera.takePicture(null, null, pictureCallback);

    private final Camera.PictureCallback pictureCallback = new Camera.PictureCallback() {

        public void onPictureTaken(byte[] data, Camera camera) {
            if (data != null) {
                //Analyze and generate pictures returned by camera
                try {
                    File dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
                    if (!dir.exists()) {
                    File mCaptureFile = new File(dir, System.currentTimeMillis() + ".jpg");
                    FileOutputStream fos = new FileOutputStream(mCaptureFile);
                    Toast.makeText(surfaceView.getContext(), "Photo success", Toast.LENGTH_SHORT).show();
                } catch (Exception e) {
                    Toast.makeText(surfaceView.getContext(), "Failed to save photo", Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(surfaceView.getContext(), "Photo taking failed, please try again", Toast.LENGTH_SHORT).show();

When running, we will find that a problem is to stay in the preview interface after taking pictures. At this time, if you don't record, there is no problem. But if you are recording and stay in the current interface, is it embarrassing? After a search, you only need to reset the camera parameters to realize no preview after taking pictures. Is it cool that the recording has been going on

Camera.Parameters params = camera.getParameters();


Tags: SurfaceView

Posted on Sun, 12 Jan 2020 10:52:23 -0500 by nutshell