2011-12-05 82 views
1

我正在開發一個應用程序,它會預覽設備的攝像頭並分析該提要。 我可以創建相機預覽,但無法讓相機自動調整焦點。是否可以使用BlackBerry OS5 API對相機進行對焦?

我知道底層硬件可能會執行自動對焦,因爲原生黑莓相機應用程序通過在拍照之前自動聚焦圖像來響應「拍照」媒體鍵。

但是,我不想拍照,我試圖連續掃描條形碼的輸入源。

這裏是我的代碼:

Player _player = Manager.createPlayer("capture://video"); 
_player.realize(); 
_player.start(); 
_vc = (VideoControl) _player.getControl("VideoControl"); 

//this is added to the screen 
_viewFinder = (Field) _vc.initDisplayMode(
    VideoControl.USE_GUI_PRIMITIVE, "net.rim.device.api.ui.Field"); 

FocusControl focusControl = (FocusControl) _player.getControl("javax.microedition.amms.control.camera.FocusControl"); 

//this has no effect 
focusControl.setFocus(FocusControl.AUTO); 

我已經在黑莓Storm 9500和9700都運行OS5測試。

回答

1

在OS5中將相機對焦的唯一方法是使用VideoControl.getSnapshot()。沒有其他辦法。

2

試試這個

this.player = Manager.createPlayer("capture://video"); 
this.player.realize(); 
this.videoControl = ((VideoControl)this.player.getControl("VideoControl")); 
this.field = ((Field)this.videoControl.initDisplayMode(0, "net.rim.device.api.ui.Field")); 
this.videoControl.setVisible(true); 
this.player.start(); 
try { 
     //get focuscontrol 
     FocusControl focusControl = (FocusControl)getCurrentObject().player.getControl("javax.microedition.amms.control.camera.FocusControl"); 
     if (focusControl == null) { 
      //no focus control 
     Log.Debug("Focus control not available."); 
     } else { 
     if (focusControl.isMacroSupported()) { 
      //setting macro 
      Log.Debug("Setting macro mode."); 
      focusControl.setMacro(true); 
     } else { 
      //no macro 
      Log.Debug("Macro mode not supported."); 
     } 
     if (focusControl.isAutoFocusSupported()) { 
      //setting autofocus 
      Log.Debug("Using autofocus."); 
      focusControl.setFocus(-1000); 
     } else { 
      //no autofocus 
      Log.Debug("Autofocus not supported."); 
     } 
     } 

這對我的作品!

+1

-1000是FocusControl.AUTO的常量值(http://www.blackberry.com/developers/docs/5.0.0api/constant-values.html#javax.microedition.amms.control.camera.FocusControl。 AUTO),所以我認爲這就是我已經得到的。 – donturner

+0

這是什麼設備爲你工作? – donturner

+0

它適用於所有帶自動對焦功能的手機。像9700等。我的懷疑是關於你初始化代碼的方式。嘗試編輯的代碼。 – rfsk2010

相關問題