Monday, April 16, 2012
Invoking and taking picture using Camera in Blackberry
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, 5);
BitmapField bitmapField = new BitmapField();
bitmapField.setBitmap(image);
this.add(bitmapField);
}
catch(Exception e)
{
Dialog.alert(e.toString());
}
}
}
return handled;
}
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment