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);
}
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.
Open the Camera app and tap the Settings icon. Tap the switch next to Tracking auto-focus to turn it off.
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;
}
have you tried using setFocusAreas() to set the focusarea where user has touched ?
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