在JMF组件上绘画 [英] Painting over JMF component
本文介绍了在JMF组件上绘画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在从网络摄像头捕捉Stream,并希望在视频图像上绘制一些内容。我尝试在下面的例子中,问题是无论我如何安排组件,其他组件总是在后台。
有没有办法解决这个问题?
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();
}
}
推荐答案
我解决了这个问题。我使用了Manager.setHint(Manager.LIGHTWEIGHT_RENDERER,true);
和一个JLayerPane。
I have solved the problem. I used a Manager.setHint(Manager.LIGHTWEIGHT_RENDERER, true); and a JLayerPane.
public class SwingCapture extends JPanel {
private static final long serialVersionUID = -1284686239737730338L;
public static Player player = null;
public static final int WIDTH = 640;
public static final int HEIGHT = 480;
public MediaLocator ml = null;
public SwingCapture() {
setLayout(null);
setSize(WIDTH, HEIGHT);
JLayeredPane jLP = new JLayeredPane();
jLP.setBounds(0,0,800,600);
ml = new MediaLocator("vfw:Microsoft WDM Image Capture (Win32):0");
try {
Manager.setHint(Manager.LIGHTWEIGHT_RENDERER, true);
player = Manager.createRealizedPlayer(ml);
player.start();
jLP.add(Canvas.getInstance());
Canvas.getInstance().setBounds(0, 0, 200, 200);
Component comp = null;
if ((comp = player.getVisualComponent()) != null) {
jLP.add(comp, -1);
comp.setBounds(0, 0, 640, 480);
}
add(jLP);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void playerclose()
{
player.close();
player.deallocate();
}
}
这篇关于在JMF组件上绘画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文