预览相机时如何显示自动对焦?

时间:2014-06-03 03:18:52

标签: android android-camera

我的代码在捕获图像时设置自动对焦:

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);
            }

如何在拍摄之前预览相机相同的图像时启动自动对焦? enter image description here

1 个答案:

答案 0 :(得分:9)

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);