1

我正在这个应用程序中创建一个黑莓相机应用程序我正在根据我的要求使用自动图像捕捉功能。但是我会在这里尝试一件事,但直到现在我还没有成功。我尝试第二件事是当相机运行时不显示他在屏幕上捕捉到的任何东西,但捕捉到那个特定的东西。我成功了,无法在屏幕上显示它,但在那之后,当我检查我的图片时,它不仅绘制了 0 kb .jpeg 文件。我尝试隐藏相机使用背景图像但无效。意味着当相机运行时,我想用其他图像覆盖我的屏幕,无法理解我的相机已打开但捕获图像。我正在浏览这段代码。

    public class ImageCaptureDemo extends UiApplication
{
public static void main(String[] args)
{
    ImageCaptureDemo app = new ImageCaptureDemo();
    app.enterEventDispatcher();

}

public ImageCaptureDemo()
{
    pushScreen(new ImageCaptureDemoScreen());

}



class ImageCaptureDemoScreen extends MainScreen
{   
    Timer timer ;
    Player _p;
    VideoControl _videoControl; 
    Bitmap back_ground=Bitmap.getBitmapResource("loadingImage.png");
    Field videoField=null;
    public ImageCaptureDemoScreen()
    {

        super();
        setTitle("Main Screen BackGround");

    try 
        {






            _p = javax.microedition.media.Manager.createPlayer("capture://video?encoding=jpeg&width=240&height=160");
            _p.realize();
            _p.prefetch();
            _videoControl = (VideoControl) _p.getControl("VideoControl");




            if (_videoControl != null)
            {

                 videoField = (Field) _videoControl.initDisplayMode (VideoControl.USE_GUI_PRIMITIVE, "net.rim.device.api.ui.Field");




               HorizontalFieldManager H=new HorizontalFieldManager()
               {
                   public void paint(Graphics graphics) {
                         //Draw the background image and then call paint.
                     graphics.clear();
                     graphics.drawBitmap(0, 0,480, 240, back_ground, 0, 0);
                     super.paint(graphics);

                 }            



                 protected void sublayout( int maxWidth, int maxHeight)
                  {
                  int width = 240;//240
                  int height = 180;//180
                  super.sublayout( width, height);
                  setExtent( width, height);
                  }


               };


               if(videoField != null)
               {
                     H.add(this.videoField);
                     add(H);
                     System.out.println("VideoField===="+videoField);
               }










                _p.start();


                System.out.println("VideoField"+videoField);


            } 
        }
        catch(Exception e)
        {

            Dialog.alert(e.toString());
        }




        timer = new Timer();
        timer.schedule(new CountDown(), 2000);


    }



    public class CountDown extends TimerTask {
      public void run() {
         DismissThread dThread = new DismissThread();



      }
   }
 public void dismiss() {
      timer.cancel();
     invokeAction(ACTION_INVOKE);


    _videoControl.setVisible(false);

   }
   public class DismissThread implements Runnable {
          public void run() {

             dismiss();
          }
       }





    protected boolean invokeAction(int action)
    {


        boolean handled = super.invokeAction(action); 


        if(!handled)
        {
            if(action == ACTION_INVOKE)
            {   
                try
                {   
                    String encoding1 = "encoding=jpeg&width=640&height=480&quality=normal";


                    byte[] rawImage = _videoControl.getSnapshot(encoding1);  

                    System.out.println("byte[]=="+rawImage);

                    FileConnection conn = (FileConnection)Connector.open("file:///SDCard/BlackBerry/pictures/"+System.currentTimeMillis()+".jpeg", Connector.READ_WRITE);
                    conn.create();
                    OutputStream out = conn.openOutputStream();
                    out.write(rawImage);
                    out.flush();
                    out.close();
                    conn.close();



                }
                catch(Exception e)
                {
                    _p.close();
                    Dialog.alert(e.toString());
                }
            }
        }           
        return handled;                
    }





}   
}

请帮助我,这对我的项目是必要的。提前致谢

4

0 回答 0