How to autofocus Android camera automatically?

后端 未结 6 1645
执念已碎
执念已碎 2020-12-02 14:12

I want to autofocus Android camera as soon as camera holds still. Im looking for tutorials or samples how to do it or at least small sample that shows what classes I can use

6条回答
  •  情深已故
    2020-12-02 15:03

    Try to use Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO or Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE. See below:

    Camera.Parameters params = camera.getParameters();
    if (params.getSupportedFocusModes().contains(
        Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO)) {
      params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
    }
    camera.setParameters(params);
    

    It's important to test whether the phone is supporting your chosen mode before attempting to use it, otherwise setParameters() will throw a runtime exception. (Edit code now working properly)

提交回复
热议问题