2012-08-01 83 views
4

我想制作一个自定义相机应用程序我想让用户可以在此应用程序中选择焦点模式。Android相机触摸焦点

对焦模式是默认自动对焦。

如果我想将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); 
} 

回答

3

当你触摸屏幕上的点,你应该得到一个Camera.Area。如果当前对焦模式为FOCUS_MODE_AUTO,FOCUS_MODE_MACRO,FOCUS_MODE_CONTINUOUS_VIDEO或FOCUS_MODE_CONTINUOUS_PICTURE,则焦点区域才有效。那么你应该调用方法setFocusAreas来改变焦点。相机的视野从左上角(-1000,-1000)映射到右下角(1000,1000)。所以你必须做一个坐标转换。