在 JMF 组件上绘画

发布于 2024-07-30 11:59:22 字数 1021 浏览 4 评论 0原文

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

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无敌元气妹 2024-08-06 11:59:22

我已经解决了这个问题。 我使用了 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();
 }
}

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();
 }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文