这是我的问题:我想创建一个特定的组件与相机和一个图像代表覆盖VideoControl的视图的目标。如何创建包含VideoControl和图像的自定义字段?
首先我想在带有标题栏的MainScreen中显示相机。
这里是我的代码:
public class ScanScreen extends MainScreen {
private ScanScreen()
{
super();
this.vfm = new VerticalFieldManager(Field.FIELD_VCENTER);
this.controller = new ScanController(this);
//Initialize the player.
try
{
this.player = javax.microedition.media.Manager.createPlayer("capture://video?encoding=jpeg&width=1024&height=768");
this.player.realize();
this.player.prefetch();
this.videoControl = (VideoControl) this.player.getControl("VideoControl");
if(this.videoControl != null)
{
// Initialize the field where the content of the camera shall be displayed.
Field videoField = (Field) this.videoControl.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE, "net.rim.device.api.ui.Field");
// Display the video control.
this.videoControl.setDisplayFullScreen(true);
this.videoControl.setVisible(true);
// Start the player.
this.player.start();
// Add the video field to the main screen.
if(videoField != null)
{
this.vfm.add(videoField);
}
else
{
LabelField sorry = new LabelField("Sorry, we cannot use camera right now.");
this.vfm.add(sorry);
}
}
}
catch(Exception e)
{
Dialog.alert(e.toString());
}
// TODO : the camera is hiding the title bar
this.setTitle("Title");
this.add(this.vfm);
}
}
的第一个问题是,VideoContol的观点是躲在我的标题栏。我该如何解决这个问题?
第二件事:我有一个特定的矩形图像,代表具有透明度的目标,我希望在VideoControl的视图上显示目标。
我第一次尝试创建一个扩展Field的新类,返回此图像的尺寸并使图像显示在paint方法中(此类为“mypackage.CameraField”)。然后我尝试在initDisplayMode中用我的新类“mypackage.CameraField”的名称实例化我的VideoField;但创建的视频字段为空。
那么,是否有解决方案来创建这种行为?我正在考虑在“Multimedia”文件夹中的本机应用程序“Video Camera”,该文件夹在屏幕的特定区域中显示VideoControl。
谢谢。
以下是RIM的官方答案:http://tiny.cc/m00wn – obo 2011-03-30 21:24:23