Problem with FOCUS_MODE_CONTINUOUS_PICTURE on Galaxy S5

I am working on an Android application that uses the camera for preview and shooting. I use FOCUS_MODE_CONTINUOUS_PICTURE with Galaxy S4 and find that focusing works very well.

However, in the S5 galaxy, FOCUS_MODE_CONTINUOUS_PICTURE rarely ever finds focus properly. The camera will approach focus, but then increase focus again.

Does anyone have an idea why FOCUS_MODE_CONTINUOUS_PICTURE works so badly on S5, or can anyone confirm if they have the same problem?

+5
source share
1 answer

I also experienced the same problems.

The Galaxy S5 and perhaps other devices do not seem to have reliable continuous focus behavior. This is very unpleasant as a developer, when the code works fine on most devices, but then comes S5 (a very popular device), and we look pretty bad.

After a big head scratch, I think I have a solution (a more workaround) that works well.

  • set the camera to FOCUS_MODE_CONTINUOUS_PICTURE
  • in the gesture handler to take a photo (for example, pressing a button, touch event), switch the camera to FOCUS_MODE_AUTO, then release Camera.autoFocus () in deferred mode

This provides a nice, consistent UI focus while previewing photos, but makes the image in reliable auto focus mode.

Here is the code:

  protected void onTakePicture() { // mCamera is the Camera object // mAutoFocusCallback is a Camera.AutoFocusCallback handler try { // determine current focus mode Camera.Parameters params = mCamera.getParameters(); if (params.getFocusMode().equals(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) { mCamera.cancelAutoFocus(); // cancels continuous focus List<String> lModes = params.getSupportedFocusModes(); if (lModes != null) { if (lModes.contains(Camera.Parameters.FOCUS_MODE_AUTO)) { params.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO); // auto-focus mode if supported mCamera.setParameters(params); // set parameters on device } } // start an auto-focus after a slight (100ms) delay new Handler().postDelayed(new Runnable() { public void run() { mCamera.autoFocus(mAutoFocusCallback); // auto-focus now } }, 100); return; } mCamera.autoFocus(mAutoFocusCallback); // do the focus, callback is mAutoFocusCallback } catch (Exception e) { Log.e("myApp", e.getMessage()); } } 

please try and report your results

+10
source

Source: https://habr.com/ru/post/1200383/


All Articles