我的代码在捕获图像时设置自动对焦:
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
}
};
//自动对焦回调
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);
}
};
//开始抓图回调并保存图片...
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);
}
}
调用抓图:
autoFocus(_pfnAutoFocusCallback )
我使用代码预览但不显示框架:
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);
}
在捕获前预览相机相同的图像时如何启动自动对焦?
最佳答案
Continuous auto focus 似乎是热门答案。
link 1.
link 2.
以下代码段可能有效,如果无效,请引用以上链接:
//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);