Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How display auto focus when preview camera?

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? enter image description here

like image 523
D T Avatar asked Jan 11 '23 11:01

D T


1 Answers

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);
like image 90
Ryhan Avatar answered Jan 24 '23 10:01

Ryhan