My code set auto focus when capture Image:
ShutterCallback _pfnShutterCallback = new ShutterCallback() {
@Override
public void onShutter() {
// TODO Auto-generated method stub
}
};
PictureCallback _pfnRawPictureCallback = new PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
// TODO Auto-generated method stub
}
};
// Auto focus call back
private AutoFocusCallback _pfnAutoFocusCallback = new AutoFocusCallback() {
@Override
public void onAutoFocus(boolean success, Camera camera) {
// TODO Auto-generated method stub
camera.autoFocus(null);
camera.takePicture(_pfnShutterCallback, _pfnRawPictureCallback,
mPicture);
}
};
//Start capture Picture Call back and save image...
private PictureCallback mPicture = new PictureCallback() {
public void onPictureTaken(byte[] data, Camera camera) {
new SavePhotoTask().execute(data);
camera.startPreview();
}
};
public void autoFocus(AutoFocusCallback autoFocusCallback) {
if (Utilities.hasFeatureAutoFocus(E028.this)) {
mCamera.cancelAutoFocus();
mCamera.autoFocus(autoFocusCallback);
}
else
{
playSound();
mCamera.takePicture(null, null, mPicture);
}
}
Call capture image: autoFocus(_pfnAutoFocusCallback )
I use code preview but don't display frame:
Camera.Parameters parameters = mCamera.getParameters();
List<String> focusModes = parameters.getSupportedFocusModes();
if (focusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE))
{
parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
mCamera.setParameters(parameters);
}
How start auto focus when preview camera the same image before capture?
Continuous auto focus seems to be the hot answer.
link 1. link 2.
The following snippet may work, if not, please reference the above links:
//set camera to continually auto-focus
Camera.Parameters params = c.getParameters();
if (params.getSupportedFocusModes().contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) {
params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
} else {
//Choose another supported mode
}
c.setParameters(params);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With