Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Blackberry 调用快照方法时获取空值_Blackberry_Blackberry Simulator_Blackberry Eclipse Plugin - Fatal编程技术网

Blackberry 调用快照方法时获取空值

Blackberry 调用快照方法时获取空值,blackberry,blackberry-simulator,blackberry-eclipse-plugin,Blackberry,Blackberry Simulator,Blackberry Eclipse Plugin,我已经创建了一个黑莓相机应用程序。 在这个应用程序中,我尝试在调用相机时自动拍照。 我的相机已被调用,但不会自动拍照。 我遵循这个准则 public class Test extends MainScreen implements FileSystemJournalListener { long _lastUSN; ButtonField btnTakePhoto; String capturedImgPath = ""; VideoControl videoC

我已经创建了一个黑莓相机应用程序。 在这个应用程序中,我尝试在调用相机时自动拍照。 我的相机已被调用,但不会自动拍照。 我遵循这个准则

public class Test extends MainScreen  implements FileSystemJournalListener {
    long _lastUSN;
    ButtonField btnTakePhoto;
    String capturedImgPath = "";
    VideoControl videoControl;
    Timer objTimer;
   Player player;


    public Test()
    {
        super();
        btnTakePhoto    =   new ButtonField("Take Picture",ButtonField.VCENTER|ButtonField.BOTTOM);
        btnTakePhoto.setChangeListener(TakePictureListener);

        HorizontalFieldManager hfm=new HorizontalFieldManager();    
        hfm.add(btnTakePhoto);
        add(hfm);

        System.out.println("Inside Construct");
        UiApplication.getUiApplication().addFileSystemJournalListener(this);
        _lastUSN = FileSystemJournal.getNextUSN();
        this.setTitle("Camera Class");


    }

    public void backGroundPaint(Graphics g)
    {
        System.out.println("Inside backGroundPaint");
        g.setBackgroundColor(Color.PINK);
        g.clear();

    }

    FieldChangeListener TakePictureListener = new FieldChangeListener(){

        public void fieldChanged(Field field, int context) {
            System.out.println("Inside fieldChanged");
            doTakePicture();
        }
    };
    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??encoding=jpeg&width=240&height=240");
          player.realize();
          videoControl = (VideoControl) player.getControl("VideoControl");

          player.start();



          if(videoControl!=null)
          {
              Field videoField = (Field) videoControl.initDisplayMode (VideoControl.USE_GUI_PRIMITIVE, "net.rim.device.api.ui.Field");


              videoControl.setDisplayFullScreen(true);
              add((Field) videoControl);
              videoControl.setVisible(true);



          }



        }



    catch(Exception ex)
     {
        System.out.println(ex);
        Dialog.alert(toString());

     }
    }

    public void invokeAction()
    {

         doTakePicture();

            System.out.println("Inside Invoke Action");
            try {
                byte[] snapshot = videoControl.getSnapshot(null);
                //player.close();
                System.out.println("snapshot=="+snapshot);
                EncodedImage bitmap=EncodedImage.createEncodedImage(snapshot, 0, snapshot.length);
                System.out.println("bitmap=="+bitmap);
                BitmapField field1 = new BitmapField(); 
                System.out.println("field1=="+field1);
                 field1.setImage(bitmap); 
                 add(field1);
            } catch (MediaException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }



}  



    public void fileJournalChanged() 
    {

    System.out.println("Inside fileJournalChanged");
        long nextUSN = FileSystemJournal.getNextUSN();
        String msg = null;
        String path = null;
        for (long lookUSN = nextUSN - 1; lookUSN >= _lastUSN && msg == null; --lookUSN) 
        {
            FileSystemJournalEntry entry = FileSystemJournal.getEntry(lookUSN);

            if (entry == null) 
            { 
                break;
            }

             path = entry.getPath();
             System.out.println("Path=="+path);

            if (path != null)               
            {
             if (path.endsWith("png") || path.endsWith("jpg") || path.endsWith("bmp") || path.endsWith("gif") ){    
                switch (entry.getEvent()) 
                {


                    case FileSystemJournalEntry.FILE_ADDED:
                        System.out.println("Inside FILE_ADDED");
                        msg = "File was added.";
                        break;

                    case FileSystemJournalEntry.FILE_DELETED:
                        System.out.println("Inside FILE_DELETED");
                        msg = "File was deleted.";
                        break;
                }
             } 
            }
        }
        _lastUSN = nextUSN;

        if ( msg != null ) 
        {
            Dialog.alert(msg);
            capturedImgPath =   path;
            closeCamera();
        }
    }
   private void closeCamera()
    {
        int menuOrder =6;
        System.out.println("Inside Close Camera");
        EventInjector.invokeEvent(new EventInjector.KeyCodeEvent(EventInjector.KeyCodeEvent.KEY_DOWN, (char)Keypad.KEY_MENU, KeypadListener.STATUS_NOT_FROM_KEYPAD, 0));
        EventInjector.invokeEvent(new EventInjector.TrackwheelEvent(EventInjector.TrackwheelEvent.THUMB_ROLL_DOWN, menuOrder, KeypadListener.STATUS_NOT_FROM_KEYPAD));
        EventInjector.invokeEvent(new EventInjector.TrackwheelEvent(EventInjector.TrackwheelEvent.THUMB_CLICK, 1, KeypadListener.STATUS_NOT_FROM_KEYPAD));
        Dialog.alert("The captured Image path is "+capturedImgPath);
   }



}
试试这个代码

import javax.microedition.media.Player;
import javax.microedition.media.control.VideoControl;

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.container.MainScreen;

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
{   
    Player _p;
    VideoControl _videoControl;    

    public ImageCaptureDemoScreen()
    {
        try 
        {
            _p = javax.microedition.media.Manager.createPlayer("capture://video?encoding=jpeg&width=1024&height=768");
            _p.realize();
            _videoControl = (VideoControl) _p.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);
                _p.start();

                /*EnhancedFocusControl efc = (EnhancedFocusControl)p.getControl("net.rim.device.api.amms.control.camera.EnhancedFocusControl");
                efc.startAutoFocus();*/

                if(videoField != null)
                {
                    add(videoField);
                }
            } 
        }
        catch(Exception e)
        {
            Dialog.alert(e.toString());
        }
    }

    protected boolean invokeAction(int action)
    {
        boolean handled = super.invokeAction(action); 

        if(!handled)
        {
            if(action == ACTION_INVOKE)
            {   
                try
                {                      
                    byte[] rawImage = _videoControl.getSnapshot(null);  
                    Bitmap image = Bitmap.createBitmapFromBytes(rawImage, 0, rawImage.length, 100);
                    BitmapField bitmapField = new BitmapField();
                    bitmapField.setBitmap(image);
                    this.add(bitmapField);


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

}

通过您的代码后,第一次单击时不会调用相机,当我回来时,相机会调用捕获图片,但不会保存。更改消息是give。请告诉我哪里出错。在此之后-videoControl=(videoControl)player.getControl(“videoControl”);开始播放器-播放器。开始();。然后是videoControl.setDisplayFullScreen(真);添加(视频控制)@User1337883 Friend signare我正在使用你的代码,我有一个例外,所以请帮助我。Friend's你有明确的确切的我想做什么。这是我的应用程序所必需的。我做每件事,如果你想看到我发送给你整个代码,但请尝试解决我的问题。是的,我尝试了,但没有任何效果。