Java調用網路攝影機截圖

來源:互聯網
上載者:User

標籤:

Java調用網路攝影機

最近有個需要通過java調用網路攝影機,並的需求,在網上找了下資料,大部分是用一個叫jmf的庫,但是jmf已經幾百年沒有更新,用起來各種問題。後來又找了個叫fmj的庫,說是jmf的替代品,但是資料太少,不知道怎麼下手。
又在網上找了下搜尋找到了一個開源項目webcam-capture,真心不錯。基本的樣本比較齊全,上手快。
webcam-capture項目地址: https://github.com/sarxos/webcam-capture
使用webcam-capture寫了個的小demo,代碼如下:

public class CaptureDemo{    private static int    num    = 0;    public static void main(String[] args) throws IOException    {        final Webcam webcam = Webcam.getDefault();        webcam.setViewSize(WebcamResolution.VGA.getSize());        WebcamPanel panel = new WebcamPanel(webcam);        panel.setFPSDisplayed(true);        panel.setDisplayDebugInfo(true);        panel.setImageSizeDisplayed(true);        panel.setMirrored(true);        final JFrame window = new JFrame("網路攝影機");        window.addWindowListener(new WindowAdapter() {            @Override            public void windowClosed(WindowEvent e)            {                webcam.close();                window.dispose();            }        });        // window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);        final JButton button = new JButton("");        window.add(panel, BorderLayout.CENTER);        window.add(button, BorderLayout.SOUTH);        window.setResizable(true);        window.pack();        window.setVisible(true);        button.addActionListener(new ActionListener() {            public void actionPerformed(ActionEvent e)            {                button.setEnabled(false);                String fileName = "D://" + num;                WebcamUtils.capture(webcam, fileName, ImageUtils.FORMAT_PNG);                SwingUtilities.invokeLater(new Runnable() {                    @Override                    public void run()                    {                        JOptionPane.showMessageDialog(null, "成功");                        button.setEnabled(true);                        num++;                        return;                    }                });            }        });    }}

 

Java調用網路攝影機

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.