2012-08-01 118 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)。所以你必須做一個座標轉換。