安卓相机触摸对焦

4

我正在尝试制作一个自定义相机应用程序,我希望用户可以在此应用程序中选择对焦模式。

默认情况下,对焦模式是自动对焦。

如果我想将cameraView设置为可点击,使得当我触摸屏幕上的某一点时,相机的对焦点在该点上,我应该从哪里开始呢?以下是我的代码:

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);
}
1个回答

4
当您触摸屏幕上的某一点时,应该获得相机区域。只有当当前对焦模式为FOCUS_MODE_AUTO、FOCUS_MODE_MACRO、FOCUS_MODE_CONTINUOUS_VIDEO或FOCUS_MODE_CONTINUOUS_PICTURE时,对焦区域才有效。然后,您应该调用setFocusAreas方法来触发对焦。相机的视野从左上角(-1000,-1000)映射到右下角(1000,1000)。因此,您需要进行坐标转换。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接