How can i calculate the distance of object from camera in autofocus mode? I have tried using the Camera.Parameters.getFocusDistances(float[]) method, but it always returns the values .15, 1.2, and Infinity on my Galaxy S2. Any help will be appreciated. Here is the code i am using:-
..........
cam=Camera.open();
Camera.Parameters pa=cam.getParameters();
pa.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
cam.setParameters(pa);
cam.startPreview();
cam.autoFocus(this);
..........
@Override
public void onAutoFocus(boolean arg0, Camera arg1) {
// TODO Auto-generated method stub
float f[]=new float[3];
arg1.getParameters().getFocusDistances(f);
text.setText(""+f[1]); //Always returns 1.2
t2.setText(""+f[0]); //Always returns .15
t3.setText(""+f[2]); //Always returns Infinity
}
Is there any other way to accomplish this?