在 JMF 组件上绘画
我正在从网络摄像头捕获流,并想在视频图像上绘制一些内容。 我尝试在下面的示例中,问题是无论我如何排列组件,另一个组件始终在后台。 有办法解决这个问题吗?
public class SwingCapture extends JPanel {
private static final long serialVersionUID = -1284686239737730338L;
private static Player player = null;
public static final int WIDTH = 640;
public static final int HEIGHT = 480;
private MediaLocator ml = null;
public SwingCapture()
{
setLayout(null);
setSize(WIDTH, HEIGHT);
ml = new MediaLocator("vfw:Microsoft WDM Image Capture (Win32):0");
try {
player = Manager.createRealizedPlayer(ml);
player.start();
Component comp = null;
if ((comp = player.getVisualComponent()) != null) {
add(comp);
comp.setBounds(0, 0, 640, 480);
}
add(Canvas.getInstance());
Canvas.getInstance().setBounds(0, 0, 640, 480);
}
catch (Exception e)
{
e.printStackTrace();
}
}
public static void playerclose() {
player.close();
player.deallocate();
}
}
I'm capturing the Stream from a webcam and would like to draw something on top of the video image. I try that in the example below, the problem is that the other component is always in the background no matter how I arrange the components.
Is there a way do solve this?
public class SwingCapture extends JPanel {
private static final long serialVersionUID = -1284686239737730338L;
private static Player player = null;
public static final int WIDTH = 640;
public static final int HEIGHT = 480;
private MediaLocator ml = null;
public SwingCapture()
{
setLayout(null);
setSize(WIDTH, HEIGHT);
ml = new MediaLocator("vfw:Microsoft WDM Image Capture (Win32):0");
try {
player = Manager.createRealizedPlayer(ml);
player.start();
Component comp = null;
if ((comp = player.getVisualComponent()) != null) {
add(comp);
comp.setBounds(0, 0, 640, 480);
}
add(Canvas.getInstance());
Canvas.getInstance().setBounds(0, 0, 640, 480);
}
catch (Exception e)
{
e.printStackTrace();
}
}
public static void playerclose() {
player.close();
player.deallocate();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经解决了这个问题。 我使用了 Manager.setHint(Manager.LIGHTWEIGHT_RENDERER, true);
和一个 JLayerPane。
I have solved the problem. I used a Manager.setHint(Manager.LIGHTWEIGHT_RENDERER, true);
and a JLayerPane.