Android通过触摸设置手动对焦
我将通过打开相机来设置我的Android应用程序,并通过触摸相机中的点来启用手动对焦。相机可以重新聚焦到我指向屏幕的地方。请告诉我应该从哪一部分开始进行修改 下面是我的代码:Android通过触摸设置手动对焦,android,android-camera,Android,Android Camera,我将通过打开相机来设置我的Android应用程序,并通过触摸相机中的点来启用手动对焦。相机可以重新聚焦到我指向屏幕的地方。请告诉我应该从哪一部分开始进行修改 下面是我的代码: public void takePhoto(File photoFile, String workerName, int width, int height, int quality) { if (getAutoFocusStatus()){ camera.autoFocus(new AutoFoc
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);
}
这里的关键是调用camera.autoFocus(autoFocusCallBack)和after
我们聚焦方法autofocusCallback.onAutoFocus(布尔成功,
摄像头(摄像头)-调用摄像头。拍摄照片
(Camera.ShutterCallback快门,Camera.PictureCallback原始,
Camera.PictureCallback(jpeg)
请参阅更多:
或
在“曲面更改”和“预览前”,可以使用“自动聚焦”
自动设置焦距,然后启动的设置
预览,然后自动聚焦显示的内容
信用证:您是否尝试过使用setFocusAreas()设置用户触摸过的焦点区域?虽然这个答案没有显示如何在单个区域聚焦,但它确实有助于显示如何准确聚焦相机 这就是我所做的。这可以在我的设备(HTC的Droid DNA)上运行,它是在Android Studio中构建的 在
OnSurfaceChanged()
和OnSurfaceCreated()
中,我都有以下代码:
(mCamera
是我的私人Camera
对象)
在构造函数中,必须放置
setFocusable(true);
setFocusableInTouchMode(true);
这将允许您接收焦点事件。至于抓到他们
public boolean onTouchEvent(MotionEvent event){
if(event.getAction() == MotionEvent.ACTION_DOWN){
Log.d("down", "focusing now");
mCamera.autoFocus(null);
}
return true;
}
因此,如果我添加用于触摸屏幕的事件arg,然后再次调用自动对焦,这就解决了我的问题?我相信您需要的是所谓的辅助对焦,手动对焦是不可能的:(几年前)在我看来,这个答案并不能解决这个问题,它只是设置了自动对焦(null)。它不会将相机聚焦在选定的点上。你是对的。最重要的是,这个摄像头API现在已经从API 21中去除了润滑油。这对我在KitKat的工作是有效的,如果你有棒棒糖,它可能无法与新的摄像头API一起工作
setFocusable(true);
setFocusableInTouchMode(true);
public boolean onTouchEvent(MotionEvent event){
if(event.getAction() == MotionEvent.ACTION_DOWN){
Log.d("down", "focusing now");
mCamera.autoFocus(null);
}
return true;
}