1

我正在开发一个应用程序,它可以预览设备的摄像头并分析该提要。我可以创建相机预览,但无法让相机自动调整焦点。

我知道底层硬件可以执行自动对焦,因为本机 BlackBerry 相机应用程序通过在拍照前自动对焦图像来响应“拍照”媒体键。

但是,我不是在尝试拍照,而是在尝试连续扫描输入提要中的条形码。

这是我的代码:

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);

我已经在运行 OS5 的 BlackBerry Storm 9500 和 Bold 9700 上进行了测试。

4

2 回答 2

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.");
        }
      }

这个对我有用 !!!

于 2011-12-05T21:10:10.667 回答
1

在 OS5 中对焦相机的唯一方法是使用 VideoControl.getSnapshot()。没有其他办法。

于 2011-12-13T15:52:34.503 回答