java启动摄像头

hello__ 贡献于2013-04-02

作者 hello__  创建于2003-01-20 02:45:26   修改者hello__  修改于2003-01-20 02:45:26字数1624

文档摘要:java启动摄像头
关键词:

import java.awt.Component; import java.awt.Rectangle; import javax.media.CaptureDeviceInfo; import javax.media.CaptureDeviceManager; import javax.media.Manager; import javax.media.MediaLocator; import javax.media.Player; import javax.swing.Box; import javax.swing.JFrame; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; public class SampCam extends JFrame { /** * */ private static final long serialVersionUID = 1211056605389924001L; private static Player player = null; private CaptureDeviceInfo device = null; private MediaLocator locator = null; boolean proportion = true; String str1 = "vfw:Logitech USB Video Cam:0"; String str2 = "vfw:Microsoft WDM Image Capture (Win32):0"; Component component1; public SampCam() { super("ÉãÏñ»ú"); try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); // Óë²Ù×÷ϵͳ·ç¸ñÒ»Ö } catch (ClassNotFoundException e1) { e1.printStackTrace(); } catch (InstantiationException e1) { e1.printStackTrace(); } catch (IllegalAccessException e1) { e1.printStackTrace(); } catch (UnsupportedLookAndFeelException e1) { e1.printStackTrace(); } try { jbInit(); } catch (Exception e) { e.printStackTrace(); } } public static void main(String[] args) { new SampCam(); } private void jbInit() throws Exception { component1 = Box.createGlue(); // =====================³õʼ»¯É豸===================// component1.addNotify(); device = CaptureDeviceManager.getDevice(str2); locator = device.getLocator(); try { player = Manager.createRealizedPlayer(locator); player.start(); if ((component1 = player.getVisualComponent()) != null) { this.getContentPane().add(component1, "Center"); } } catch (Exception e) { e.printStackTrace(); } component1.setBounds(new Rectangle(0,0, 250, 280)); this.setSize(380, 300); this.setVisible(true); } }

下载文档到电脑,查找使用更方便

文档的实际排版效果,会与网站的显示效果略有不同!!

需要 2 金币 [ 分享文档获得金币 ] 1 人已下载

下载文档