如何在没有用户互动的情况下从黑莓手机拍照?

时间:2012-04-14 05:20:05

标签: blackberry blackberry-simulator blackberry-eclipse-plugin

我是Blackberry Developer,我创建了一个黑莓相机应用程序。            但是当我点击时我拍照是可以在没有任何用户交互的情况下拍照。这对我的应用来说是必要的。                       请建议我并将代码发给我,我正在完成这个过程。

   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( “行动==” +动作);     boolean handling = 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); 请帮助我在哪里弄错了。
                            在此先感谢

1 个答案:

答案 0 :(得分: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");