Trouble with FOCUS_MODE_CONTINUOUS_PICTURE on Galaxy S5

前端 未结 1 1715
遥遥无期
遥遥无期 2021-01-02 23:04

I\'m working on an Android app that uses the camera to preview and take pictures. I use FOCUS_MODE_CONTINUOUS_PICTURE with the galaxy S4 and find that the focus

相关标签:
1条回答
  • 2021-01-02 23:29

    I too have experienced these same issues.

    The Galaxy S5, and possibly other devices, don't seem to have reliable behavior in continuous picture focus mode. This is very frustrating as a developer, when code works perfectly on most devices, but then along comes the S5 (a very popular device) and we look pretty bad.

    After much head scratching, I think I have a solution (more of a workaround) that is working well.

    1. set camera to FOCUS_MODE_CONTINUOUS_PICTURE
    2. in gesture handler for taking a photo (e.g. button tap, touch event), switch camera to FOCUS_MODE_AUTO, then call Camera.autoFocus() in a deferred manner

    this provides the nice continuous focus UI during photo preview, but takes the picture 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 give this a try and report back your results

    0 讨论(0)
提交回复
热议问题