问题描述
我在黑莓新。我现在创建应用我的要求是,当相机自动调用一个画面capture.Is可以在黑莓。
我用这code每一件事情的工作,但不能捕捉到的画面自动请建议我改变我的code它在我的应用工作。
公共类测试扩展MainScreen实现FileSystemJournalListener {
长_lastUSN;
ButtonField字段btnTakePhoto;
串capturedImgPath =;
VideoControl对视频监控;
定时器objTimer;
Player播放器;
公开测试()
{
超();
btnTakePhoto =新ButtonField字段(拍照,ButtonField.VCENTER | ButtonField.BOTTOM);
btnTakePhoto.setChangeListener(TakePictureListener);
HorizontalFieldManager HFM =新HorizontalFieldManager();
hfm.add(btnTakePhoto);
加(HFM); 的System.out.println(内部构造);
。UiApplication.getUiApplication()addFileSystemJournalListener(本);
_lastUSN = FileSystemJournal.getNextUSN();
this.setTitle(摄像机班);
} FieldChangeListener TakePictureListener =新FieldChangeListener(){ 公共无效fieldChanged(场场,诠释上下文){
的System.out.println(内部fieldChanged);
doTakePicture();
}
};
公共无效doTakePicture(){
尝试
{ 的System.out.println(内部doTakePicture);
Invoke.invokeApplication(Invoke.APP_TYPE_CAMERA,新CameraArguments());
玩家= javax.microedition.media.Manager.createPlayer(捕获://视频);
player.realize(); 视频监控=(VideoControl对)player.getControl(VideoControl对);
player.start();
如果(视频监控!= NULL)
{
现场videoField =(场)videoControl.initDisplayMode(VideoControl.USE_GUI_PRIMITIVEnet.rim.device.api.ui.Field);
videoControl.setDisplayFullScreen(真);
videoControl.setVisible(真);
加(videoField);
//的System.out.println(视频监控==+视频监控);
//字符串IMAGETYPE =编码= JPEG和放大器; WIDTH = 1024&安培; HEIGHT = 768安培;质量=罚款;
//
//字节[] =快照videoControl.getSnapshot(IMAGETYPE);
//位图图像= Bitmap.createBitmapFromBytes(快照,0,snapshot.length,5);
//的System.out.println(快照==+快照);
//的System.out.println(形象==+图像);
// BitmapField bitmapField =新BitmapField();
// bitmapField.setBitmap(图片);
// this.add(bitmapField);
//如果(videoField!= NULL)
// {
//添加(videoField);
//
//} } } 赶上(异常前)
{
的System.out.println(除息); }
} 公共布尔invokeAction(INT行动)
{
的System.out.println(行动==+动作);
布尔处理= super.invokeAction(动作);
//处理= TRUE;
的System.out.println(处理==+处理);
的System.out.println(内部调用相机); 如果(!处理)
{
的System.out.println(内部首先如果博客);
如果(动作== ACTION_INVOKE)
{
的System.out.println(内部其次如果博客);
尝试
{
的System.out.println(如果调用操作的博客);
的System.out.println(videoControl11 ==+视频监控);
字符串IMAGETYPE =编码= JPEG和放大器; WIDTH = 1024&安培; HEIGHT = 768安培;质量=罚款;
字节[] =快照videoControl.getSnapshot(IMAGETYPE);
位图图像= Bitmap.createBitmapFromBytes(快照,0,snapshot.length,5);
的System.out.println(快照==+快照);
的System.out.println(形象==+图像);
BitmapField bitmapField =新BitmapField();
bitmapField.setBitmap(图片);
this.add(bitmapField);
}
赶上(例外五)
{
Dialog.alert(e.toString());
}
}
}
返回处理;
} 公共无效fileJournalChanged()
{
的System.out.println(内部fileJournalChanged);
长nextUSN = FileSystemJournal.getNextUSN();
弦乐味精= NULL;
字符串路径= NULL;
为(长lookUSN = nextUSN - 1; lookUSN> = _lastUSN和放大器;&安培;味精== NULL; --lookUSN)
{
FileSystemJournalEntry进入= FileSystemJournal.getEntry(lookUSN); 如果(入门== NULL)
{
打破;
} PATH = entry.getPath();
的System.out.println(路径==+路径); 如果(路径!= NULL)
{
如果(path.endsWith(PNG)|| path.endsWith(JPG)|| path.endsWith(BMP)|| path.endsWith(GIF)){
开关(entry.getEvent())
{
案例FileSystemJournalEntry.FILE_ADDED:
的System.out.println(内部FILE_ADDED);
味精=添加文件。
打破; 案例FileSystemJournalEntry.FILE_DELETED:
的System.out.println(内部FILE_DELETED);
味精=文件已被删除。
打破;
}
}
}
}
_lastUSN = nextUSN; 如果(MSG!= NULL)
{
Dialog.alert(MSG);
capturedImgPath =路径;
closeCamera();
}
}
私人无效closeCamera()
{
INT menuOrder = 6;
的System.out.println(内部关闭相机);
EventInjector.invokeEvent(新EventInjector.Key codeEvent的(EventInjector.Key codeEvent.KEY_DOWN,(炭)Keypad.KEY_MENU,KeypadListener.STATUS_NOT_FROM_KEYPAD,0));
EventInjector.invokeEvent(新EventInjector.TrackwheelEvent(EventInjector.TrackwheelEvent.THUMB_ROLL_DOWN,menuOrder,KeypadListener.STATUS_NOT_FROM_KEYPAD));
EventInjector.invokeEvent(新EventInjector.TrackwheelEvent(EventInjector.TrackwheelEvent.THUMB_CLICK,1,KeypadListener.STATUS_NOT_FROM_KEYPAD));
Dialog.alert(拍摄图像的路径为+ capturedImgPath);
}}
您使用的是传统的方法来拍照。这就是为什么你不应该使用它:
- 因为你退出你的应用程序调用外部应用程序(相机应用)。
- 因为你没有在相机设置控制。
- 由于FileJournalListener code,你贴出来,这是发表在其教程中的code RIM,给出了一些操作系统和模拟器(事件到达以不同的顺序,或不能在到达所有,多个事件的问题图像保存,等等)。
- 因为没有办法关闭相机应用,你必须求助于哈克键注射法。
所以,现在,对于操作系统> 4.6,可以使用MMAPI把你的应用程序内的快照。这是推荐的方法和你不应该使用您发布,除非你是编程的传统操作系统之一。检查<一href=\"http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/1089414/How_To_-_Take_a_snapshot_using_the_built-in_camera_of_a_BlackBerry_smartphone.html?nodeid=1443849&vernum=0\"相对=nofollow>本教程。另外,从5.0起,可以使用AMMAPI控制一些相机设置。 并非所有的控制措施,但最基本的(变焦,对焦,闪光灯等)在最新的操作系统的支持。检查包含在最新的BlackBerry JDE VideoRecordingDemo样本。
I am new in blackberry. i create Application now my requirement is when camera is invoke automatic a picture is capture.Is it possible in blackberry.i am using this code every thing work but not capture picture automatic please suggest what i change on my code it's work on my Application.
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");
}
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");
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);
videoControl.setVisible(true);
add(videoField);
// System.out.println("videoControl=="+videoControl);
// String imagetype = "encoding=jpeg&width=1024&height=768&quality=fine";
//
// byte[] snapshot = videoControl.getSnapshot(imagetype);
// Bitmap image = Bitmap.createBitmapFromBytes(snapshot, 0, snapshot.length, 5);
// System.out.println("snapshot=="+snapshot);
// System.out.println("image=="+image);
// BitmapField bitmapField = new BitmapField();
// bitmapField.setBitmap(image);
// this.add(bitmapField);
// if(videoField != null)
// {
// add(videoField);
//
// }
}
}
catch(Exception ex)
{
System.out.println(ex);
}
}
public boolean invokeAction(int action)
{
System.out.println("Action=="+action);
boolean handled = super.invokeAction(action);
//handled=true;
System.out.println("handled=="+handled);
System.out.println("Inside Invoke Camera");
if(!handled)
{
System.out.println("Inside First If Blog");
if(action == ACTION_INVOKE)
{
System.out.println("Inside Second If Blog");
try
{
System.out.println("If Blog of invoke Action");
System.out.println("videoControl11=="+videoControl);
String imagetype = "encoding=jpeg&width=1024&height=768&quality=fine";
byte[] snapshot = videoControl.getSnapshot(imagetype);
Bitmap image = Bitmap.createBitmapFromBytes(snapshot, 0, snapshot.length, 5);
System.out.println("snapshot=="+snapshot);
System.out.println("image=="+image);
BitmapField bitmapField = new BitmapField();
bitmapField.setBitmap(image);
this.add(bitmapField);
}
catch(Exception e)
{
Dialog.alert(e.toString());
}
}
}
return handled;
}
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);
}
}
You are using a legacy approach to take pictures. This is why you shouldn't use it:
- Because you are exiting your application to call an external application (the camera app).
- Because you don't have control over the camera settings.
- Because the FileJournalListener code that you posted, which is the code RIM published in its tutorial, gives problems on some OSes and simulators (events arriving in a different order or not arriving at all, multiple events on image save, etc).
- Because there is no way to close the camera app and you have to resort to the hacky key injection method.
So now, for OSes > 4.6, you can use MMAPI to take snapshot inside your app. This is the recommended method and you should not use the one you posted unless you are programming for legacy OSes. Check this tutorial. Also, from 5.0 onwards you can use AMMAPI to control some camera settings. Not all controls are implemented, but most basic ones (zoom, focus, flash, etc) are supported in the latest OSes. Check the VideoRecordingDemo sample included in the latest BlackBerry JDE.
这篇关于是否有可能在黑莓捕捉到的图像自动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!