使用VideoControl.getSnapshot()方法拍照时遇到问题。它总是抛出异常:不支持getSnapshot。我正在使用JRE 5.0.0与Eclipse和BlackBerry®Java®SDK5.0插件。
我首先要使用命令System.getProperty(“video.snapshot.encodings”)列出所选Blackberry SmartPhone支持的编码(粗体9700),然后从列表中选择一个编码并将其作为getSnapshot参数传递
我已经在几个Blackberry上测试了同样的异常。
部分代码:
mPlayer = Manager.createPlayer("capture://video?encoding=video/3gpp");
mPlayer.realize();
mPlayer = Manager.createPlayer("capture://video?encoding=video/3gpp");
mPlayer.start();
videoControl = (VideoControl)mPlayer.getControl("VideoControl");
Field cameraView = (Field) videoControl.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE, "net.rim.device.api.ui.Field");
Thread.sleep(1000);
UiApplication.getUiApplication().pushScreen(new TempScreen(cameraView));
byte[] snapShot = videoControl.getSnapshot("encoding=jpeg&width=480&height=360&quality=superfine");
Bitmap image = Bitmap.createBitmapFromBytes(snapShot, 0, snapShot.length, 1);
UiApplication.getUiApplication().pushScreen(new TempScreen(image));
}catch (MediaException e){
UiApplication.getUiApplication().pushScreen(new TempScreen("Exception: " + e.getMessage())); }
catch (IOException e){
UiApplication.getUiApplication().pushScreen(new TempScreen("IO Exception: " + e.getMessage()));
}
catch (InterruptedException e){UiApplication.getUiApplication().pushScreen(new TempScreen("Interrupted Exception: "+ e.getMessage()));}
答案 0 :(得分:3)
在一年半以上的时间里,我的回答并不确定,但可能会有用。
您可以尝试使用Thread.sleep(1000);在getSnapshot()调用之前。 问题可能与这个事实有关:“在调用getSnapShot()之前,取景器必须在屏幕上显示。”
因此,如果您在
UiApplication.getUiApplication().pushScreen(new TempScreen(cameraView));之后立即致电getSnapshot 相机没有为下一次拍摄做好准备。
您是否确定您的设备上完全支持getSnapshot()API?尽管API定义了这种方法,但有些制造商可能不支持它。您是否在测试getSnapshot()的同一设备上运行了System.getProperty(“video.snapshot.encodings”)?
答案 1 :(得分:0)
Player _p;
VideoControl _vc ;
RecordControl _rc ;
String PATH;
FileConnection fileconn;
Object canvas= new Object();
public static boolean SdcardAvailabulity() {
String root = null;
Enumeration e = FileSystemRegistry.listRoots();
while (e.hasMoreElements()) {
root = (String) e.nextElement();
if( root.equalsIgnoreCase("sdcard/") ) {
return true;
}else if( root.equalsIgnoreCase("store/") ) {
return false;
}
}
class MySDListener implements FileSystemListener {
public void rootChanged(int state, String rootName) {
if( state == ROOT_ADDED ) {
if( rootName.equalsIgnoreCase("sdcard/") ) {
}
} else if( state == ROOT_REMOVED ) {
}
}
}
return true;
}
protected boolean invokeAction(int action){
boolean handled = super.invokeAction(action);
if(SdcardAvailabulity()){
PATH = System.getProperty("fileconn.dir.memorycard.videos")+"Video_"+System.currentTimeMillis()+".3gpp";//here "str" having the current Date and Time;
} else {
PATH = System.getProperty("fileconn.dir.videos")+"Video_"+System.currentTimeMillis()+".3gpp";
}
if(!handled){
if(action == ACTION_INVOKE){
try{
if(_p!=null)
_p.close();
}catch(Exception e){
}
}
}
return handled;
}
public MyScreen(){
setTitle("Video recording demo");
ButtonField AddPhoto = new ButtonField("push",ButtonField.FOCUSABLE | ButtonField.FIELD_HCENTER | ButtonField.FIELD_VCENTER | DrawStyle.HCENTER | ButtonField.NEVER_DIRTY | Field.USE_ALL_WIDTH);
FieldChangeListener PhotoListener = new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
ButtonField Button = (ButtonField) field;
if (Button.getLabel().equals("push")){
}
}
};
AddPhoto.setChangeListener(PhotoListener);
add(AddPhoto);
}
}