Jeff Bootsholz
Jeff Bootsholz

Reputation: 3068

Android Camera Touch Focus

I am trying to make a custom camera application I want to let the users can choose the focus mode in this application.

The focus mode is auto focus on default .

if I want to set the cameraView to be clickable such that when I touch one point onto the screen, the focus of the camera is on that point? how can be start with? the 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);
}

Upvotes: 4

Views: 4054

Answers (1)

yushulx
yushulx

Reputation: 12140

When you touch a point on the screen, you should get a Camera.Area. Focus area only has effect if the current focus mode is FOCUS_MODE_AUTO, FOCUS_MODE_MACRO, FOCUS_MODE_CONTINUOUS_VIDEO, or FOCUS_MODE_CONTINUOUS_PICTURE. Then you should call the method setFocusAreas to trgigger focus. The camera's field of view is mapped from top-left corner(-1000, -1000) to bottom-right corner(1000, 1000). So you have to make a coordinate conversion.

Upvotes: 4

Related Questions