简体   繁体   English

是否可以使用BlackBerry OS5 API聚焦相机?

[英]Is it possible to focus the camera using the BlackBerry OS5 API?

I am developing an app which takes a preview of the device's camera and analyses that feed. 我正在开发一个应用程序,它可以预览设备的相机并分析这些信息。 I can create the camera preview, but cannot get the camera to adjust its focus automatically. 我可以创建相机预览,但无法让相机自动调整焦距。

I know that the underlying hardware is possible of performing an auto focus because the native BlackBerry camera app responds to the 'take photo' media key by auto focussing the image prior to taking the photo. 我知道底层硬件可以执行自动对焦,因为本机BlackBerry相机应用程序通过在拍照前自动对焦图像来响应“拍照”媒体键。

However, I'm not trying to take a photo, I'm trying to continuously scan the input feed for a barcode. 但是,我不打算拍照,我正在尝试连续扫描条形码的输入源。

Here's my code: 这是我的代码:

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

I have tested on BlackBerry Storm 9500 and Bold 9700 both running OS5. 我已经测试了黑莓Storm 9500和Bold 9700都运行OS5。

Try this 尝试这个

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

It works for me !!! 这个对我有用 !!!

The only way to focus the camera in OS5 is to use VideoControl.getSnapshot(). 在OS5中聚焦相机的唯一方法是使用VideoControl.getSnapshot()。 There is no other way. 没有其他办法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM