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, n...

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() { @Override 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()) { dir.mkdirs(); } File mCaptureFile = new File(dir, System.currentTimeMillis() + ".jpg"); FileOutputStream fos = new FileOutputStream(mCaptureFile); fos.write(data); fos.close(); Toast.makeText(surfaceView.getContext(), "Photo success", Toast.LENGTH_SHORT).show(); } catch (Exception e) { e.printStackTrace(); 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(); params.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO); camera.setParameters(params);

12 January 2020, 10:52 | Views: 6113

Add new comment

For adding a comment, please log in
or create account

0 comments