【问题标题】:Taking Snapshots from a Webcam using JMF使用 JMF 从网络摄像头拍摄快照
【发布时间】:2012-05-16 04:28:45
【问题描述】:

我想通过 java 从网络摄像头拍摄快照。我跟着this question 到达了这个example。但是下面一行出现了一个空指针异常-

Buffer buf = frameGrabber.grabFrame();
Image img = (new BufferToImage((VideoFormat) buf.getFormat())
                .createImage(buf));
        buffImg = new BufferedImage(img.getWidth(this), img.getHeight(this),
                BufferedImage.TYPE_INT_RGB);

通过调试器,我观察到缓冲区实际上并不包含数据。于是我就去创建frameGrabber。

frameGrabber = (FrameGrabbingControl) player
                .getControl("javax.media.control.FrameGrabbingControl");

这段代码有问题吗?因为 JMFStudio 在我的机器上运行良好,但代码无法访问它。谢谢。

【问题讨论】:

  • “来自下一行的异常” 我数了 3 行。为了尽快获得更好的帮助,请发布 SSCCE 和堆栈跟踪。

标签: java jmf


【解决方案1】:

我找到了解决方案。 JMF 需要时间进行初始化。在示例中,我们必须切换一条线。把

new Timer(3000, this).start();

在try catch下面。

整个区块如下所示。

        try {
            player = Manager.createRealizedPlayer(cdi.getLocator());
            player.start();
        } catch (NoPlayerException e) {
            e.printStackTrace();
        } catch (CannotRealizeException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
            new Timer(3000, this).start();
        // Grab a frame from the capture device
        frameGrabber = (FrameGrabbingControl) player
                .getControl("javax.media.control.FrameGrabbingControl");

【讨论】:

    猜你喜欢
    • 2017-12-25
    • 2010-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多