Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android setting manual focus by touching

I am going to set the my Android App by opening the camera and enable manual focus by touching the point in to camera. The camera can refocus to the point where I have pointed on to the screen. Would you please tell me the methodology or which component should I start with to modify ?

Below is my code:

public void takePhoto(File photoFile, String workerName, int width, int height, int quality) {
    if (getAutoFocusStatus()){
        camera.autoFocus(new AutoFocusCallback() {
            @Override
            public void onAutoFocus(boolean success, Camera camera) {
                camera.takePicture(shutterCallback, rawCallback, jpegCallback);
            }
        }); 
    }else{
        camera.takePicture(shutterCallback, rawCallback, jpegCallback);
    }

this.photoFile = photoFile;
this.workerName = workerName;
this.imageOutputWidth = width;
this.imageOutputHeight = height;
}

public void takePhoto(File photoFile, int width, int height, int quality) {
takePhoto(photoFile, null, width, height, quality);
}
like image 890
Raju yourPepe Avatar asked Oct 12 '12 01:10

Raju yourPepe


People also ask

How do I manually adjust the focus on my Android camera?

Go to the manual mode of your smartphone camera and look for the MF icon to manually focus your smartphone camera. Tap the figure, and the function gets active. A slider appears on your screen, which allows you to focus manually.

How do I stop my phone camera from auto focusing?

Open the Camera app and tap the Settings icon. Tap the switch next to Tracking auto-focus to turn it off.


2 Answers

Though this answer does not show how to focus in on a single area, it is definitely useful in showing how exactly to focus the camera to begin with.

Here is what i have done. This works on my device (Droid DNA by HTC), built in Android Studio

In both OnSurfaceChanged() and OnSurfaceCreated(), I have the following code: (mCamera is my private Camera object)

        mCamera.stopPreview();
        Camera.Parameters p = mCamera.getParameters();
        p.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);

        mCamera.setParameters(p);
        mCamera.setPreviewDisplay(surfaceHolder);
        mCamera.startPreview();
        mCamera.autoFocus(null);

In the constructor, you must place

        setFocusable(true);
        setFocusableInTouchMode(true);

This will allow you to receive focus events. As for capturing them...

 public boolean onTouchEvent(MotionEvent event){
    if(event.getAction() == MotionEvent.ACTION_DOWN){
        Log.d("down", "focusing now");

        mCamera.autoFocus(null); 
    }

    return true;
}
like image 172
Nlinscott Avatar answered Sep 27 '22 18:09

Nlinscott


have you tried using setFocusAreas() to set the focusarea where user has touched ?

like image 25
mchouhan_google Avatar answered Sep 27 '22 18:09

mchouhan_google