Android Camera: fixed lens focus

Zeb picture Zeb · Jan 25, 2015 · Viewed 7.7k times · Source

I'm developing an Android application with a camera-related functionality feature.

First of all, I read a lot of stuff on SO, XDA and so on, then please don't redirect me to other useless posts.

I am trying to implement something like a "fixed focus mode", so that:

  1. I start my application with FOCUS_MODE_AUTO (or something else);
  2. bring into focus an object at an arbitrary distance;
  3. fix the current focus;
  4. move the camera on another object at a different distance which is out of focus.

I tried different solutions, i.e.:

  • mCamera.cancelAutoFocus() in the AutoFocusCallback to prevent the adjustment of the focus;
  • set a FocusArea: new Camera.Area(new Rect(-50, -50, 50, 50), 1000) to fix the focus on the current area.

I'm targeting API 20 and I'm working on a Samsung Galaxy S5. On this device, the supported focus modes are: - auto - infinity - macro - continuous-video - continuous-picture

The suggestion that I found more frequently is to recompile Android...

Answer

Raanan picture Raanan · Feb 3, 2015

"AUTO" mode doesn't mean that the camera continuously focuses - just that when you call the autoFocus command the focus is done automatically with no indication on what result you expect not like "Macro" or "Infinity".

http://developer.android.com/reference/android/hardware/Camera.html#autoFocus(android.hardware.Camera.AutoFocusCallback)

So if you don't have a loop that calls the autoFocus (as many examples do or call it again in the Callback) your focus should stay after it runs once.