我正在创建一个黑莓相机应用程序在这个应用程序我根据我的要求使用自动图像捕获功能。但还有一件事我会尝试,但到现在为止我没有成功。我尝试第二件事是当相机是运行它没有显示他在屏幕上捕获的任何东西,但捕获了那个特定的东西。我成功无法在屏幕上显示它但在那之后当我检查我的图片时它不会只绘制0 kb .jpeg文件是create.I try使用背景图像隐藏相机但没有效果。当相机运行时我想用其他图像覆盖我的屏幕不能理解我的相机已打开但是捕捉图像。 我正在阅读这段代码。
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;
}
}
}
请帮我完成我的项目。 在此先感谢