gpt4 book ai didi

java - 在 JMF 组件上绘画

转载 作者:行者123 更新时间:2023-11-30 05:16:01 25 4
gpt4 key购买 nike

我正在从网络摄像头捕获流,并想在视频图像上绘制一些内容。我尝试在下面的示例中,问题是无论我如何排列组件,另一个组件始终在后台。有办法解决这个问题吗?

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。

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();
}
}

关于java - 在 JMF 组件上绘画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1272018/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com