-4

我是一名黑莓开发人员,我创建了一个黑莓相机应用程序。但是我点击时拍照是否可以在没有任何用户交互的情况下拍照。这对我的应用程序是必需的。请建议我并将代码发送给我,我正在经历这个过程。

   public void doTakePicture(){
    try
    {

        System.out.println("Inside doTakePicture");
      Invoke.invokeApplication(Invoke.APP_TYPE_CAMERA,new CameraArguments());
      player = javax.microedition.media.Manager.createPlayer("capture://video");
      player.realize();
      player.start();
      videoControl = (VideoControl) player.getControl("VideoControl");

      if(videoControl!=null)
      {
          Field videoField = (Field) videoControl.initDisplayMode (VideoControl.USE_GUI_PRIMITIVE, "net.rim.device.api.ui.Field");
          videoControl.setDisplayFullScreen(true);
          videoControl.setVisible(true);
          System.out.println("videoControl=="+videoControl);
          if(videoField != null)
          {
              add(videoField);
          }

      } 


    }



catch(Exception ex)
 {
    System.out.println(ex);

 }
}

public boolean invokeAction(int action) { System.out.println("Action=="+action); 布尔处理 = super.invokeAction(action);

System.out.println("handled=="+handled);
System.out.println("Inside Invoke Camera");

if(handled==false)
{
    System.out.println("Inside First If Blog"); 
    if(action == ACTION_INVOKE)
    {   
        System.out.println("Inside Second If Blog");
        try
        {    
            System.out.println("If Blog of invoke Action");


            System.out.println("videoControl11=="+videoControl);
            byte[] snapshot = videoControl.getSnapshot(null);
            System.out.println("snapshot=="+snapshot);
        }
        catch(Exception e)
        {
            Dialog.alert(e.toString());
        }
    }
}           
return handled;                

}

使用此代码我想尝试在调用相机但不自动拍照时自动拍照,我在这里得到一个空值 byte[] snapshot = videoControl.getSnapshot(null); 请帮助我在哪里犯错。
提前致谢

4

1 回答 1

3

您需要从应用程序中实例化相机,而不是调用默认相机应用程序。完成此操作后,您可以通过调用以编程方式拍摄照片VideoControl.getSnapshot。例子:

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

//this will take a photo
byte[] snapshot = videoControl.getSnapshot("encoding=jpeg&width=640&height=480&quality=superfine");
于 2012-04-14T21:28:27.090 回答