List of all Iphone and Blackberry Development codes in a one click Iphone,objective C,xcode,blackberry Development,iOS Development

Tuesday, August 21, 2012

Automatically Taking Picture in Blackberry

The following code will automatically take pictures without any user interactions. It also displays the taken picture in the screen.

    private Field _videoField;
    private Player _player;
    private VideoControl _videoControl;
    byte[] image;

 try{
        _player = Manager.createPlayer( "capture://video??encoding=jpeg&width=240&height=240" );
        _player.realize();
        _player.prefetch();
        _videoControl = (VideoControl)_player.getControl("VideoControl");
        _player.start();               
        if (_videoControl != null){

            _videoField = (Field) _videoControl.initDisplayMode (GUIControl.USE_GUI_PRIMITIVE, "net.rim.device.api.ui.Field");
            _videoControl.setDisplayFullScreen(true);
            add(_videoField);
        }
    }
    catch(Exception e)
    {
       //show error
    }
         

         try {
                image = _videoControl.getSnapshot(null);
                 _player.close();
               
                EncodedImage bitmap = EncodedImage.createEncodedImage(image, 0, image.length); 
                BitmapField field1 = new BitmapField();
                field1.setImage(bitmap);
                add(field1);
            } catch (MediaException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }



        

1 comment: